LDAP
Installation
apt-get install slapdapt-get install ldap-utils
apt-get install ldapvi
Status/start/stop LDAP service
systemctl status slapdsystemctl start slapd
systemctl stop slapd
Configuration
After the packages are installed und slapd is started it is possible to make a first connection test:ldapsearch -H ldap://127.0.0.1 -x -LLL -b "" -s base +
This command outputs the RootDSE (directory system [agent] entry). By the way scope base is required here otherwise ldapsearch will not return data. The "+" sign means that operational attributes are displayed that normally are hidden.
If this works one can test ldapvi. Ldapvi is a vi based tool to watch, modify and delete LDAP data.
ldapvi -h ldap://127.0.0.1 --bind simple -b "" -s base '(objectclass=*)' +
ldapvi -h ldap://127.0.0.1 --bind simple --discover
The local host address can be omitted:
ldapvi -h ldap:// --bind simple -b "" -s base '(objectclass=*)' +
Here are explicit commands to get naming contexts and configuration context:
ldapsearch -H ldap:// -x -s base -b "" -LLL "namingContexts"
ldapsearch -H ldap:// -x -s base -b "" -LLL "configContext"
Here are two commands to access the config DN:
ldapsearch -H ldapi:// -Y EXTERNAL -b "cn=config" -LLL -Q
ldapvi -h ldapi:// -Y EXTERNAL -b "cn=config"
Here is a different URL used. "ldapi" indicates that a unix socket should be used to access the ldapserver with unix sockets the LDAP server is able to identify the user (root of course). The EXTERNAL mechanism utilizes authentication services provided by lower level network services (unix domain sockets).
Command to explore the default domain context:
ldapvi -h ldapi:// -Y EXTERNAL -b "dc=nodomain"
Root Password for the config tree
Create a password hash with slappasswd. Enter the new passwort in the config tree with:ldapvi -h ldapi:// -Y EXTERNAL -b "cn=config"
Search for "cn=admin,cn=config". Add or update attribute olcRootPW with the result of slappasswd.
After that it is possible to access the ldap config tree with simple bind (password authentication):
ldapvi -h ldap:// -D "cn=admin,cn=config" -b "cn=config"
Add Schema
Enter the following commands:ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /etc/ldap/schema/core.ldif
ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /etc/ldap/schema/cosine.ldif
ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /etc/ldap/schema/inetorgperson.ldif
ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /etc/ldap/schema/inetorgperson.ldif
ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /etc/ldap/schema/nis.ldif
It seems this schemata are already known by Debians LDAP server.
Object classes
To get a list of all defined object classes one can enter this command:
ldapsearch -H ldap:// -D "cn=admin,cn=config" -W -s base -b "cn=subschema" objectclasses
Rename domain
Openldap was intialized with a domain name (cn=nodomain) which ist not favorable. It can be displayed with this command:ldapsearch -H ldap:// -D "cn=admin,dc=nodomain" -W -b dc=nodomain -s sub
I was able to delete the manager object within the "nodmain" sub tree but I was not able to delete the domain node itself. I tried it with this commands:
ldapdelete -H ldap:// -D "cn=admin,dc=nodomain" -W dc=nodomain
Or this one. Ldapmodify with an LDIF file:
version: 1 # to apply these changes using ldapvi, run: # ldapvi --ldapmodify -h ldap:// ,ldapvi-lamobo-11313.ldif dn: dc=nodomain changetype: delete
ldapmodify -H ldap:// -D "cn=admin,dc=nodomain" -W -f ,ldapvi-lamobo-11313.ldif
Here is an explanation why I was not successful.
Next I renamed the suffix as explained here:
olcRootDN: cn=admin,dc=bd,dc=local
olcSuffix: dc=bd,dc=local
I added the top level nodes for my new domain with the following LDIF file:
dn: dc=bd,dc=local changetype: add objectClass: top objectClass: dcObject objectClass: organization o: bd.local dc: bd dn: cn=admin,dc=bd,dc=local changetype: add objectClass: simpleSecurityObject objectClass: organizationalRole cn: admin description: LDAP administrator
ldapmodify -x -W -D cn=admin,dc=bd,dc=local -H ldapi:/// -f slapd_setup_basic.ldif
After that it is able to access the new DIT with:
ldapvi -h ldap:// -D "cn=admin,dc=bd,dc=local" -b "dc=bd,dc=local"
Add groupOfEntries class
With this class it is possible to create empty groups. The standard object classes for groups groupOfNames and groupOfUniqueNames can't do that.dn: cn=groupofentries,cn=schema,cn=config objectClass: olcSchemaConfig cn:groupofentries olcobjectclasses:( 1.2.826.0.1.3458854.2.1.1.1 NAME 'groupOfEntries' SUP top STRUCTURAL MUST ( cn ) MAY ( member $ businessCategory $ seeAlso $ owner $ ou $ o $ description ))
ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /tmp/groupOfEntries.ldif
Overlay memberof
The memberof overlay adds automatically the memberOf attribut to users that are members of a groupOfEntries.dn: cn=module,cn=config
cn: module
objectClass: olcModuleList
olcModuleLoad: memberof
olcModulePath: /usr/lib/ldap
dn: olcOverlay=memberof,olcDatabase={1}mdb,cn=config
changetype: add
objectClass: olcOverlayConfig
objectClass: olcMemberOf
olcOverlay: memberof
olcMemberOfGroupOC: groupOfEntries
olcMemberOfMemberAD: member
olcMemberOfMemberOfAD: memberOf
ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /tmp/memberOf.ldif
Groups and Users
Now we can add some groups and users.dn: ou=groups,dc=bd,dc=local changetype: add objectClass: top objectClass: organizationalUnit ou: groups dn: cn=admins,ou=groups,dc=bd,dc=local changetype: add objectClass: top objectClass: groupOfEntries dn: cn=users,ou=groups,dc=bd,dc=local changetype: add objectClass: top objectClass: groupOfEntries dn: ou=people,dc=bd,dc=local changetype: add objectClass: top objectClass: organizationalUnit ou: people dn: cn=bdonauba,ou=people,dc=bd,dc=local changetype: add objectClass: top objectClass: person sn: MyName
ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /tmp/groupUsers.ldif
Attention! The memberOf attribute is operational so one has to use the plus sign with ldapsearch or ldapvi to see it.
Unix Attributes
Of course we want to use openldap as directory for users und groups. To do so we have to enhance the groups with the posixGroup class. For the posixGroup class the gidNumber attribute is mandatory.cn=admins,ou=groups,dc=bd,dc=local cn: admins gidNumber: 10001 objectClass: groupOfEntries objectClass: posixGroup objectClass: top
At the moment this is not possible because both groupOfEntries and possixGroup are of type structural, so we change the type of possixGroup to auxiliary.
olcObjectClasses: {2}( 1.3.6.1.1.1.2.2 NAME 'posixGroup' DESC 'Abstraction of a group of accounts' SUP top AUXILIARY MUST ( cn $ gidNumber ) MAY ( userPassword $ memberUid $ description ) )
After this change one can add the posixGroup object class.
Now we can define our first user account.
cn=bdonauba,ou=people,dc=bd,dc=local
sn: Donaubauer
cn: bdonauba
gidNumber: 10001
homeDirectory: /home/bdonauba
loginShell: /bin/bash
objectClass: person
objectClass: posixAccount
objectClass: top
uid: bdonauba
uidNumber: 10001
sn: Donaubauer
cn: bdonauba
gidNumber: 10001
homeDirectory: /home/bdonauba
loginShell: /bin/bash
objectClass: person
objectClass: posixAccount
objectClass: top
uid: bdonauba
uidNumber: 10001
slapcat -F /etc/ldap/slapd.d/ -H ldap://
dn: dc=bd,dc=l