5. Testing the LDAP directory

5.1. Performing a search

To perform a search and find all entries just do the following LDAP query:


	ldapsearch -x -h localhost -b "dc=example,dc=com" "(objectClass=*)"

This must return some result else you have miss something during the previous chapter.

To test more the SQL backend you can run the following test suite. All test are done in LDIFF format.

Something great is that you can create flat LDAP structure like in this test or more complex structure as tree.

If you have the error message: "ldap_sasl_bind(SIMPLE): Can't contact LDAP server (-1)", this means that your ldap server is not runnning or not listening on default port 389.

5.2. Creating entry

To create some new entries just copy the following LDIFF code into a file


	dn: cn=Test Entry,dc=example,dc=com
	objectClass: inetOrgPerson
	cn: Test Entry
	sn: Entry
	givenName: Test


and run the following command:


	ldapadd -x -h localhost -D "cn=root,dc=example,dc=com" -w secret -f file

Note that it assume that your LDAP server is running on localhost.

5.3. Adding/Deleting/Modifying entry attribute

To modify, delete and set attributes of the new entries just copy the following LDIFF code into a file


	dn: cn=Test Entry,dc=example,dc=com
	changetype: modify
	add: telephoneNumber
	telephoneNumber: 123-4567
	telephoneNumber: 765-4321

	dn: cn=Test Entry,dc=example,dc=com
	changetype: modify
	delete: telephoneNumber
	telephoneNumber: 123-4567

	dn: cn=Test Entry,dc=example,dc=com
	changetype: modify
	replace: telephoneNumber
	telephoneNumber: 4321-765

and run command:


	ldapmodify -x -h localhost -D "cn=root,dc=example,dc=com" -w secret -f file

Note that it assume that your LDAP server is on localhost.

5.4. Performing a search

To perform a search and find all entries just do the following LDAP query:


	ldapsearch -x -h localhost -b "dc=example,dc=com" "(objectClass=*)"

or just under the inetOrgPerson objectClass with cn begining with letter M:


	ldapsearch -x -h localhost -b "dc=example,dc=com" "(&(objectClass=inetOrgPerson) (cn=M*))"

5.5. Deleting entry

To delete an entry just copy get the dn entry and run the following command:

	ldapdelete -x -h localhost -D "cn=root,dc=example,dc=com" -w secret "cn=Test Entry,dc=example,dc=com"

5.6. Troubleshooting

If your LDAP servers crash you may want to enable debuging output for slapd. To do that you just have to edit /etc/syslog.conf and add the following line:

local4.*                                                  /var/log/ldap

(separators are tabulation, but spaces may work).

After that you have to restart syslog (on SlackWare: /etc/rc.d/rc.syslog restart) then tail the /var/log/ldap to see what's happen when you start slapd.Do not use this on production server you may slow down it dramatically !