Lightweight Directory Access Protocol (LDAP) is a means of serving data on individuals, system users, network devices and systems over the network for e-mail clients, applications requiring authentication or information. Using the LDAP server configuration example on this page will enable you to create an address book server for email clients. We have many useful links for other LDAP deployments. LDAP can also be distributed in a hierarchical fashion but my examples refer to a single LDAP server. This tutorial will cover the setup and configuration of an LDAP server on Linux, the loading of data and use. Once configured, I recommend "gq" as an admin tool. (Note: Red Hat no longer ship with gq.
Simply put, this tutorial will enable you to create an LDAP server to which your e-mail clients (Outlook, Netscape, etc) can connect with their address books. It will allow one to search the LDAP database for people's e-mail addresses which are then pulled into the address list. Try it out with Netscape on our LDAP site ldap.yo-linux.com for a demo. Cool eh! You can also try out authentication by pointing your application to authenticate at ldap.yo-linux.com.
![]() |
LDAP Tutorial Table of Contents:
|
|
Related YoLinux LDAP Tutorials: °Apache Web Site Authentication
Free Information Technology Magazine Subscriptions and Document Downloads |
Try Mozilla email client with ldap server ldap.yo-linux.com:
Tips:
Note on email clients: For other e-mail clients such as Outlook, see the University of Alabama (UAB) LDAP client tutorial. Note that Outlook Express and Outlook 2000 are configured differently than Outlook 2000 professional. For MS/Windows users I have found that the Qualcom Eudora mail client to be the most advanced at supporting LDAP functionality and searches. Also see the Megawebhost.com LDAP E-Mail Client Configuration tutorial More on LDAP: LDAP data entries are organized in a "Directory Information Tree" (DIT) which may be divided among servers defined by their organizational association. When a request is made to an LDAP server and the information is not available locally, LDAP can use it's referral capability to seek this data from the other servers in the tree structure. In this way a global network of LDAP servers appear as a single server. This tutorial covers the use of a single LDAP server. LDAP data can support more than address directory services. It can act as a DNS and propagate data to other servers. It supports a client server protocol to supply data for authentication (passwords) in support of apache, squid, sendmail, NFS/NIS, PAM, POP, IMAP or any client written to support the LDAP protocol. In this way one database can hold all of the login/authentication information for a unified login across the enterprise. The OpenLDAP server software includes two daemon server services:
There are a plethora of Linux e-mail clients which claim to support LDAP. I have had my best luck with Netscape 4.7x. Microsoft Outlook will support LDAP searches for an individual name or partial string. For the MS/Windows platform, Eudora seems to support LDAP the best by allowing very sophisticated queries. The Linux "Balsa" e-mail client supports LDAP but it downloads the entire address book with no search filters. This can be cumbersome if the LDAP address book has a large number of entries. (They obviously tested with a small address book). One can perform the same search in Netscape by entering a "*" to download everything. Most email clients support a search for email address containing "@" to get all email addresses. The e-mail client has to be configured to point to the LDAP server (i.e. ldap.your-domain.org) and must be given a "root" in the directory tree from which to begin searches. From this information the e-mail client can search the LDAP server for e-mail addresses which can be pulled down to the local client. Note that Microsoft Outlook Express and Outlook 2000 are configured differently than Outlook 2000 professional. For MS/Windows use the Qualcom Eudora mail client as it seems to be the most advanced at supporting LDAP functionality and searches. LDAP e-Mail Clients:
The following steps will lead to an operational OpenLDAP 2.x server:
(This will result in an operational LDAP server with data.) OpenLDAP 2.x (shipped with Red Hat 7.1-9.0, Fedora Core): download and use the following two sample files:
Note for Fedora Core 3: (OpenLDAP 2.2.13) Add the statement "allow bind_v2" after the schema "include" directives in the file /etc/openldap/slapd.conf if you wish to allow the use of older clients. Then execute the following commands as root:
Test with an email client:
Install the aWebDap CGI executable to provide a user web front-end for search and updates. [Demo]
If you wish to add a second domain try this file: fraternity.ldif
Read the rest of this tutorial to see what it all means!
To run a more complex example with an extended schema to optimally support MS/Outlook and Netscape Communicator see the YoLinux GILSE tutorial and example. If you are going to configure LDAP for your office, you will eventually want to follow this guide.
LDAP uses an object oriented approach to data and data modeling which includes object definitions (collection of data attributes and rules) and object inheritance.
The statements which describe the object classes and attributes are different in Open LDAP versions 1.2 and 2.x. Unless you require a unique custom configuration it is easiest to use the pre-defined object inetOrgPerson (RFC 2798) included with OpenLDAP 2.x or to define an new object which inherits the inetOrgPerson object schema. Each LDAP data entry has a "Distinguished Name" (DN) by which it is identified. Each component of the DN is called a "Relative Distinguished Name" (RDN). Operations against the LDAP data include adding, deleting, modifying and querying based on a query filter. |
| LDAP Configuration/Operation: |
slapd.conf:
The main difference between OpenLDAP Versions 1.2 and 2.x is in the object and attribute definitions. OpenLDAP 2.x objects and attributes use OID's while version 1.2 does not. The slapd and database directives are close to being the same with minor enhancements in version 2.x.
Password Encryption and Security: See the OpenLDAP password FAQ
To secure the LDAP database see the YoLinux LDAP Password Protection and Authentication Tutorial
To create a custom data object by extending the inetOrgPerson object
see the new LDAP Object/Attribute definition tutorial
The following LDIF example uses the inetOrgPerson object model:
dn: o=domain-name - Define the LDAP root
objectClass: top
objectClass: organization
o: domain-name
description: Full Company Name
dn: cn=AdminManager,o=domain-name - Data entries for the system administrator for the domain as defined in the file: slapd.conf
objectClass: organizationalRole
cn: AdminManager
description: LDAP Directory Administrator
dn: cn=Larry Fine,o=domain-name - Great for address book support. For LDAP login authentication server support only, you may want to use the attribute uid, mail or employeeNumber.
cn: Larry Fine - Yes it is mentioned in the dn statement but it is repeated here
objectClass: top - These objectclass statements MUST go here for Open LDAP
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
mail: LFine@isp.com
givenname: Larry
sn: Fine
postalAddress: 14 Cherry St.
l: Dallas
st: TX
postalCode: 76888
telephoneNumber: (800)555-1212
seeAlso: dc=www,dc=domain-name,dc=org - Correct method: DN must be previously defined in order to reference it. i.e. dn: dc=www,dc=domain-name,dc=org
XX Wrong Way! XX seeAlso: http://www.domain-name.org/~larry/ - OpenLDAP object inetOrgPerson expects a DN and this entry cannot be added directly so DO NOT ADD THIS LINE!!!
jpegPhoto: < file:///path/to/file.jpeg - JPEG photo from file.
OR
jpegPhoto: < http://domain/path/to/file.jpeg - It's in the documentation but I never got it to work.
...
..
|
For a full list of allowable attributes see:
The LDIF example above corresponds to the following slapd.conf entries for OpenLDAP 2.x:
database ldbm - Define the database to be used by LDAP. Each database definition begins with a database statement.
[Tutorial Update]: This tutorial defines ldbm to be the database. (RH 6-9 default) Many are now recomending bdb. FC-3 defaults to bdb.
suffix "o=domain-name"
[Tutorial Update]: As of OpenLDAP 2.1.13, only one suffix is supported per database. Previously this example showed two suffixes defined.
rootdn "cn=AdminManager,o=domain-name"
rootpw super-secret-password
directory /var/lib/ldap/domain-directory
defaultaccess read
schemacheck on
lastmod on
index cn,sn,st pres,eq,sub
|
An alternate style for a base "dn":
dc=domain-name,dc=org
|
----------------------------------------
| |
c=us c=jp (Use suffix: c=jp,dc=domain-name,dc=org if placed on a separate server)
| |
------------------- ------------------
| | | | | |
ou=accounting ou=sales ou=research ou=accounting ou=sales ou=research
|
dn: dc=ldap,dc=domain-name,dc=org - First define the LDAP domain
objectClass: top
objectClass: dcObject
objectClass: organization
dc: domain-name
o: domain-name
description: Full Company Name Domain
|
Note: As of OpenLDAP 2.1.2.13, the default configuration will allow only one suffix to be defined for each bdb database. The C preprocessor directive #define BDB_MULTIPLE_SUFFIXES (file: servers/slapd/back-bdb/init.c) may be used if you want to compile in multiple suffix support. If you use it, subtree indexing will slow down by factor of 2. The use of suffixAlias is no longer supported by default in version 2.1.13.
For more inetOrgPerson data schema info see:
inetOrgPerson object attributes:
|
Helpful LDIF links:
Notes:
Note that some of the attribute names have changed:
| Communicator ldif attribute | Mapping for Open LDAP |
| modifytimestamp | Drop this piece of data from ldif file.
Generated upon creation |
| xmozillanickname | Added attribute nickname |
| xmozillausehtmlmail | Added attribute usehtmlmail |
| givenname | Added attribute givenname |
| streetaddress | Used existing attribute "postalAddress" instead |
| countryname | Drop or use existing attribute "c" instead. (Note: "c" not part of inetOrgPerson object. Schema must be extended to use it.) |
| xmozillauseconferenceserver | Dropped this piece of data. |
| pagerphone | Used existing attribute "pager" instead |
| cellphone | Used existing attribute "mobile" instead |
| homeurl | Used existing attribute "seeAlso" instead. Must first define as a DN and then refer to DN. |
| xmozillaanyphone | Dropped this piece of redundant data. |
For more LDIF info see:
To stop the slapd LDAP daemon: /etc/rc.d/init.d/ldap stop
Note: Edit configuration files first and then start the system.
ldapadd -f input-def.ldif -xv -D "cn=AdminManager,o=domain-name" -W
Generating an LDAP database from an LDIF file:
slapadd -l input-def.ldif -cv
I like to use this method for debugging an LDIF file as it generated
good error messages. The LDAP server (slapd) MUST NOT be running
when using this command.
ldapadd -cv -D "cn=AdminManager, o=domain-name.org" -W < input-def.ldif
The program will prompt for the password specified by the "rootpw" statement in the slapd.conf file. (As defined by the option -W)
ldapsearch -vLx -b "o=domain-name" "(objectclass=*)"
or
ldapsearch -vLx -h 127.0.0.1 -b "o=domain-name" "(objectclass=*)"
Stooges example: ldapsearch -vLx -h 127.0.0.1 -b "o=stooges" "(sn=Fine)"
The addition of the "-x" argument enables simple authentication
(you are asked for the password specified as rootpw defined in the file
/etc/openldap/slapd.conf) instead of SASL.
OpenLDAP 1.2
ldapsearch -L -b "cn=AdminManager, o=domain-name" "(objectclass=*)"
or
ldapsearch -h "ldap.domain-name" -L -b "o=domain-name" "(sn=Fine)"
Test LDAP with Your Netscape Browser: Use an LDAP enabled browser with an appropriate URL:
ldap://ldap.yo-linux.com/cn=Larry Fine,ou=MemberGroupA,o=stoogesThis method will display directory information in the Netscape browser. MS/Windows Explorer will defer the information to the MS/Outlook address book for display and data transfer.
For more on LDAP URL's see RFC 2255: The LDAP URL Format.
Test LDAP with an E-mail client: The true test is of course is with an e-mail client. See the list of clients and links to configuration notes at the top of this page.
Netscape Messenger 4.5+:
user_pref("ldap_2.servers.domain-name.attributes.ou", "Attribute-Display-Name:LDAP-Database-Attribute");
user_pref("ldap_2.servers.domain-name.filter1", "(&(objectclass=LDAP-Object-Schema-Name)(LDAP-Database-Attribute=%s))");
pref("ldap_2.servers.domain-name.maxHits", 400);
|
Example - Allow a search by State:
user_pref("ldap_2.servers.Stooges.attributes.ou", "State:st");
user_pref("ldap_2.servers.Stooges.filter1", "(&(objectclass=inetOrgPerson)(st=%s))");
|
| Performance considerations: |
For large LDAP databases one should index the searchable item. This will create an additional index file but will greatly enhance the speed of a search. This will not be effective unless the index is defined before data is entered into the database. Applying an index to a field after the database is created is useless.
Add an index to an LDAP data field by defining it in the file: /etc/openldap/slapd.conf
OpenLDAP 2.x
index sn,postalcode pres,eq,sub |
| LDAP Qualifier | Description |
|---|---|
| pres | Is the search attribute present as any value in the LDAP directory. Return all that have an entry. i.e. (st=*) returns all entries with a state entry regardless of the entry |
| eq | Does the search string exactly match the attribute in the LDAP directory. |
| sub | Does the search string match a substring of the attribute in the LDAP directory. i.e. (sn=*nderso*) or (sn=*anderson*) |
| none | No index generated. Items like JPEG photo are not searchable items anyway. |
| approx | Is the search string approximately equal to attribute based on a "metaphonic" algorithm. Not permitted in OpenLDAP. |
OpenLDAP 1.2
index sn,postalcode |
To apply an index after a database has been created, dump the data and reload the data with LDAP restarted with the index defined.
Also see the command slapindex which can re-generate an LDAP database index. (Must stop the slapd server first as it acts directly against the database.)
Add a cache definition in the file: /etc/openldap/slapd.conf
The following cache directives apply only to LDBM (default database) and must
follow the "database ldbm" statement.
cachesize 5000 - Size of in-memory cache used by LDBM dbcachesize 1000000 - Cache size in bytes associated with index file opened by the system |
It is recommended that the dbcachesize be set to the size of the largest index files.
Also see the OpenLDAP.org Performance Tuning FAQ
| Backup LDAP database: |
Backup LDAP database with the following command: OpenLDAP 2.x
/usr/sbin/slapcat -v -n 1 -l /opt/BACKUP/ldap.ldif
/usr/sbin/ldbmcat -n /var/lib/ldap/id2entry.gdbm > /opt/BACKUP/ldap.ldif
/usr/sbin/ldbmcat -n /var/lib/ldap/id2entry.dbb > /opt/BACKUP/ldap.ldif
Note that this backup may not be suitable for re-loading. The order is random if it has been modified. The object definition for the domain itself must be the first definition. If it is not then move it there manually so that it can reload successfully.
Using LDAP slapd slapcat method: slapcat -v -n 2 -l delta.ldif
Also see: Scripts and software tools to convert LDIF files to the useful ".csv" backup form. - (Some helpful tools I wrote)
| Adding an entry to an existing LDAP directory: |
File: schemp.ldif
dn: cn=Schemp Anderson,ou=MemberGroupB,o=stooges ou: MemberGroupB o: stooges cn: Schemp Anderson objectClass: top objectClass: person objectClass: organizationalPerson objectClass: inetOrgPerson givenName: Schemp sn: Anderson uid: schemp homePostalAddress: 20 Cherry Ln.$Plano TX 78888 pager: 800-555-1320 title: Development Engineer facsimileTelephoneNumber: 800-555-3320 mail: SAnderson@isp.com homePhone: 800-555-1320 telephoneNumber: (800)555-1220 mobile: 800-555-1320 postalAddress: 20 Fitzhugh Ave. l: Dallas st: TX postalCode: 76888 |
Command: ldapadd -f schemp.ldif -h 127.0.0.1 -xv -D "cn=StoogeAdmin,o=stooges" -W
| Notes: LDAP on Red Hat/Fedora Core distribution: |
SLAPD_OPTIONS="-d 3" (RH 6.x OpenLDAP 1.2)
SLAPD_OPTIONS="-d 32 -d 64 -d 256" Extreme level of debugging. Leave blank for defaults. Default is 256. (RH 7.1 OpenLDAP 2.0)
OpenLDAP 1.2:
[Potential Pitfall]: PAM misconfiguration:
ALL:ALLThis set-up will deny everyone including localhost!!!
Be sure to at least add the following to: /etc/hosts.allow
ALL:127.0.0.1
[Potential Pitfall]: Ipchains/Iptables misconfiguration:
iptables -F OR ipchains -F
[Potential Pitfall]: LDAP won't start
slaptest: sql_select option missing slaptest: auxpropfunc error no mechanism available ldap: succeeded slapd[4200]: sql_select option missing slapd[4200]: auxpropfunc error no mechanism available |
[Potential Pitfall]: Directory access
[Potential Pitfall]: Can't access LDAP server with client
Note for Fedora Core 3: (OpenLDAP 2.2.13) Add the statement "allow bind_v2" after the schema "include" directives in the file /etc/openldap/slapd.conf if you wish to allow the use of older clients.
Debugging tips: To take a peak inside the database:
strings /var/lib/ldap/id2entry.gdbm | more
| OpenLDAP Man Pages: |
Open LDAP UNIX commands:
Configuration files:
Support programs/conversions:
LDAP processes/daemons:
LDAP Software development SDK man pages and RFC's
| The Berkely BDB database: |
The back-bdb is now the new preferred database format and the old back-ldbm code has been removed from OpenLDAP.
The Berkely database software tools have names which are Linux distribution dependant:
Example database recovery:
bdb(o=megacorp.com): PANIC: fatal region error detected; run recovery bdb_db_open: dbenv_open failed: DB_RUNRECOVERY: Fatal error, run database recovery (-30978) backend_startup: bi_db_open failed! (-30978) |
db_recover: PANIC: fatal region error detected; run recovery
db_recover: PANIC: fatal region error detected; run recovery
db_recover: DB_ENV->open: DB_RUNRECOVERY: Fatal error, run database recovery
|
Links:
| YoLinux.com LDAP Tutorials: |
| LDAP Links: |
Public LDAP Servers on the Internet: Check out and try out other LDAP installations.
LDAP Desktop Admin tools and Clients:
LDAP Web Clients:
LDAP Clients: (authentication)
OpenLDAP.org web site:
LDAP - Information links:
Netscape Roaming:
LDAP - Schema links:
Also see RFC 2256 (User Schema for use with LDAPv3).LDAP - Developer resources:
LDAP - Commercial Products:
Books: |
![]() |
"Understanding And Deploying LDAP Directory Services",
by Timothy A. Howes,Phd, Mark C. Smith and Gordon S. Good, ISBN 0672323168, Addison-Wesley Pub Co Second edition. It is general in nature but complete in that it covers all concepts in depth. It is a good book for those wanting to understand everything about LDAP, schema development and its' capabilities. |
|
![]() |
"Understanding And Deploying LDAP Directory Services",
by Timothy A. Howes,Phd, Mark C. Smith and Gordon S. Good, ISBN 1-57870-070-1, MacMillan Technical Publishing First edition out of print. (Used only) See second edition above. This is the largest LDAP book I own. It is general in nature but complete in that it covers all concepts in depth. It is NOT a good programmers reference but it is good for those wanting to understand everything about LDAP, schema development and its' capabilities. Netscape centric. |
|
![]() |
"Programming Directory-Enabled Applications with Lightweight Directory
Access Protocol"
by Timothy A. Howes,Phd and Mark C. Smith ISBN 1-57870-000-0, MacMillan Technical Publishing Excellent programmers reference for those using the LDAP C language API. Also covers search filters and LDAP URL's. The OpenLDAP source code is so poorly commented that I found this book often was the only source for an explanation of what was happening in the code. |
|
![]() |
"Implementing LDAP",
Mark Wilcok ISBN 1-861002-21-1, WROK Press This book covers all aspects of LDAP from LDIF to the LDAP SDK in C, PERL and JAVA. It has a strong Netscape Directory server bias. |
|
![]() |
"LDAP System Administration",
Gerald Carter ISBN 1565924916, O'Reilly & Associates This book covers the use of OpenLDAP and the integration of services. |
|
![]() |
"LDAP Programming, Management and Integration",
Clayton Donley ISBN 1930110405, Manning Publications; 1st edition This book covers LDAP administration as well as introductory information. It covers the directory services markup language (DSML), PERL LDAP module as well as JAVA JNDI. |
|
![]() |
"Understanding LDAP" - IBM-Redbooks
Heinz Johner, Larry Brown, Franz-Stefan Hinner, Wolfgang Reis, Johan Westman IBM Redbook #SG24-4986-00 A reference to ldap, available as PDF as well. This book has a bias towards IBM's E-network LDAP Directory server. Tight, terse, but covers everything. |
|
![]() |
"LDAP Implementation Cookbook"
IBM Redbook #SG24-5110-00 |
|
Return to http://YoLinux.com for more Linux links, information and tutorials
Return to YoLinux Tutorial Index Feedback Form Copyright © 2000, 2001, 2002, 2003, 2004, 2006 by Greg Ippolito |