Running the slapd Server - Page 9
February 15, 2002
Before we start the slapd server (the LDAP server),
we need some sample data that we can feed to the directory:
dn: o=myorg, c=US
o: myorg
dn: mail=richardc@xyz.com, o=myorg, c=US
cn: Richard Collins
mail: richardc@xyz.com
locality: Birmingham
description: Linux enthusiast
telephonenumber: 3283-3920392-32932
objectclass: top
objectclass: person
dn: mail=hrawat@hrawat.com, o=myorg, c=US
cn: Harish Rawat
mail: harawat@hrawat.com
locality: San Mateo
description: Java coder
telephonenumber: 870-28912-221
objectclass: top
objectclass: person
We need to save this file in a convenient location, say in
/home/ldaptest/myaddrdir.ldif. This file is in the LDIF format
and needs to be converted into the format of the back-end
database and inserted into the directory's datastore. Before this
is done, we need to keep the slapd.conf configuration file handy;
we could save it as /home/ldaptest/myslapd.conf:
/usr/local/sbin/ldif2ldbm -i /home/ldaptest/myaddrdir.ldif
-f /home/ldaptest/myslapd.conf
The -f /home/ldaptest/myslapd.conf option says that
the configuration file to be used is
/home/ldaptest/myslapd.conf and -i
/home/ldaptest/myaddrdir.ldif advises the program to
insert the LDIF file into the database.
To start up the server on the local machine at port number 9009
using the configuration file /home/ldaptest/myslapd.conf:
/usr/local/libexec/slapd localhost -p 9009 -f /home/ldaptest/myslapd.conf
-d 5
We use the argument -d 5 to start the server in the debug mode
(at level 5) so that we get to see what the server is doing. Note
that if we do not specify the -p option, the server is started to
listen on port 389, which is the standard LDAP port. If we do not
have root privileges on the machine we attempt to start slapd on,
we need to change the port to a number greater than 1024.
Testing the Installation
We can test our installation using a Netscape Communicator
browser. To do this start the address book and change the
settings so that it can search data in our newly set up directory
server. From File menu, choose New Directory and fill in the
details of the new directory server (in this case, the server
name is localhost and port number is 9009) and also
the search prefix (o=myorg, c=us in this case). Now
typing the name attribute of an entry, say Richard, in the Search
for names containing field should return the entry from the
server.
Another way to do this would be to use the command line utility
ldapsearch, which comes with OpenLDAP itself:
/usr/local/bin/ldapsearch -h localhost -p 9009 -b 'o=myorg, c=us'
'cn=*Richard*'
This should return the entry corresponding to
Richard in the directory. The -b flag is to indicate
the DN to be used as a suffix. The actual search criteria is
cn=*Richard*, that is look for all entries which
have a common name with the sub-string Richard.
We could use other command line utilities that come with OpenLDAP
like ldapadd, ldapmodify, and
ldapdelete to add, modify, and delete entries
respectively.
LDAP Support in PHP
PHP's support for LDAP is explicitly meant to provide client
access to back-end LDAP directory servers, so that applications
built upon PHP as a server-side scripting language can work with
the data in these directories.
An example is a web-based e-mail client (such as Yahoo Mail or
Hotmail) that could be implemented using PHP. The users of this
e-mail service may need to access their address books to search
for entries which they can transparently add to their To: or Cc:
fields, and also update their address books. The actual address
book could reside on an LDAP server and PHP's LDAP client API
could be used to talk to the directory server to provide
transparent access to the address book.
PHP is capable of generating HTML, especially forms that can be
used to enter data and search criteria. This feature could be
used to interact with the LDAP server, thus providing a front-end
(which can be dynamically generated) to the LDAP server in the
back-end.
Installing and Configuring an LDAP Server - Page 8
Professional PHP4 Programming
The PHP LDAP API - Page 10
|