ldap

OpenLDAP Lightweight Directory Access Protocol API

LIBRARY

OpenLDAP LDAP (libldap, -lldap)

#include

The Lightweight Directory Access Protocol (LDAP) (RFC 4510) provides access to X.500 directory services. These services may be stand-alone or part of a distributed directory service. This client API supports LDAP over TCP (RFC 4511), LDAP over TLS/SSL, and LDAP over IPC (UNIX domain sockets). This API supports SASL (RFC 4513) and Start TLS (RFC 4513) as well as a number of protocol extensions. This API is loosely based upon IETF/LDAPEXT C LDAP API draft specification, a (orphaned) work in progress.

includes a stand-alone server in slapd(8), various LDAP clients, and an LDAP client library used to provide programmatic access to the LDAP protocol. This is an overview of the LDAP library routines.

Both synchronous and asynchronous APIs are provided. Also included are various routines to parse the results returned from these routines. These routines are found in the -lldap library.

The basic interaction is as follows.

  1. A session handle is created using ldap_initialize and set the protocol version to 3 by calling ldap_set_option.
  2. The underlying session is established first operation is issued. This would generally be a Start TLS or Bind operation, or a Search operation to read attributes of the Root DSE.
  3. A Start TLS operation is performed by calling ldap_start_tls_s.
  4. A LDAP bind operation is performed by calling ldap_sasl_bind or one of its friends.
  5. A Search operation is performed by calling ldap_search_ext_s or one of its friends.

Subsequently, additional operations are performed by calling one of the synchronous or asynchronous routines (e.g., ldap_compare_ext_s or ldap_compare_ext followed by ldap_result). Results returned from these routines are interpreted by calling the LDAP parsing routines such as ldap_parse_result. The LDAP association and underlying connection is terminated by calling ldap_unbind_ext. Errors can be interpreted by calling ldap_err2string.

LDAP versions

This library supports version 3 of the Lightweight Directory Access Protocol (LDAPv3) as defined in RFC 4510. It also supports a variant of version 2 of LDAP as defined by U-Mich LDAP and, to some degree, RFC 1777. Version 2 (all vari- ants) are considered obsolete. Version 3 should be used instead.

For backwards compatibility reasons, the library defaults to version 2. Hence, all new applications (and all actively maintained applications) should use ldap_set_option to select version 3. The library manual pages assume version 3 has been selected.

INPUT and OUTPUT PARAMETERS

All character string input/output is expected to be/is UTF-8 encoded Unicode (version 3.2).

Distinguished names (DN) (and relative distinguished names (RDN) to be passed to the LDAP routines should conform to RFC 4514 UTF-8 string representation.

Search filters to be passed to the search routines are to be constructed by hand and should conform to RFC 4515 UTF-8 string representation.

LDAP URLs to be passed to routines are expected to conform to RFC 4516 format. The ldap_url routines can be used to work with LDAP URLs.

LDAP controls to be passed to routines can be manipulated using the ldap_controls routines.

DISPLAYING RESULTS

Results obtained from the search routines can be output by hand, by calling ldap_first_entry and ldap_next_entry to step through the entries returned, ldap_first_attribute and ldap_next_attribute to step through an entry's attributes, and ldap_get_values to retrieve a given attribute's values. Attribute values may or may not be displayable.

UTILITY ROUTINES

Also provided are various utility routines. The ldap_sort routines are used to sort the entries and values returned via the ldap search routines.

DEPRECATED INTERFACES

A number of interfaces are now considered deprecated. For instance, ldap_add is deprecated in favor of ldap_add_ext. Deprecated interfaces generally remain in the library. The macro LDAP_DEPRECATED can be defined to a non-zero value (e.g., -DLDAP_DEPRECATED=1) when compiling program designed to use deprecated interfaces. It is recom- mended that developers writing new programs, or updating old programs, avoid use of deprecated interfaces. Over time, it is expected that documentation (and, eventually, support) for deprecated interfaces to be eliminated.

BER LIBRARY

Also included in the distribution is a set of lightweight Basic Encoding Rules routines. These routines are used by the LDAP library routines to encode and decode LDAP protocol elements using the (slightly simplified) Basic Encoding Rules defined by LDAP. They are not normally used directly by an LDAP application program except in the handling of controls and extended operations. The routines provide a printf and scanf-like interface, as well as lower-level access. These routines are discussed in lber-decode, lber-encode, lber-memory(3), and lber-types(3). INDEX
ldap_initialize initialize the LDAP library without opening a connection to a server
ldap_result wait for the result from an asynchronous operation
ldap_abandon_ext abandon (abort) an asynchronous operation
ldap_add_ext asynchronously add an entry
ldap_add_ext_s synchronously add an entry
ldap_sasl_bind asynchronously bind to the directory
ldap_sasl_bind_s synchronously bind to the directory
ldap_unbind_ext synchronously unbind from the LDAP server and close the connection ldap_unbind and ldap_unbind_s are equivalent to ldap_unbind_ext
ldap_memfree dispose of memory allocated by LDAP routines.
ldap_compare_ext asynchronously compare to a directory entry
ldap_compare_ext_s synchronously compare to a directory entry
ldap_delete_ext asynchronously delete an entry
ldap_delete_ext_s synchronously delete an entry
ld_errno LDAP error indication
ldap_errlist list of LDAP errors and their meanings
ldap_err2string convert LDAP error indication to a string
ldap_extended_operation asynchronously perform an arbitrary extended operation
ldap_extended_operation_s synchronously perform an arbitrary extended operation
ldap_first_attribute return first attribute name in an entry
ldap_next_attribute return next attribute name in an entry
ldap_first_entry return first entry in a chain of search results
ldap_next_entry return next entry in a chain of search results
ldap_count_entries return number of entries in a search result
ldap_get_dn extract the DN from an entry
ldap_get_values_len return an attribute's values with lengths
ldap_value_free_len free memory allocated by ldap_get_values_len
ldap_count_values_len return number of values
ldap_modify_ext asynchronously modify an entry
ldap_modify_ext_s synchronously modify an entry
ldap_mods_free free array of pointers to mod structures used by ldap_modify_ext
ldap_rename asynchronously rename an entry
ldap_rename_s synchronously rename an entry
ldap_msgfree free results allocated by ldap_result
ldap_msgtype return the message type of a message from ldap_result
ldap_msgid return the message id of a message from ldap_result
ldap_search_ext asynchronously search the directory
ldap_search_ext_s synchronously search the directory
ldap_is_ldap_url check a URL string to see if it is an LDAP URL
ldap_url_parse break up an LDAP URL string into its components
ldap_sort_entries sort a list of search results
ldap_sort_values sort a list of attribute values
ldap_sort_strcasecmp case insensitive string comparison
SEE ALSO ldap.conf(5), slapd(8), draft-ietf-ldapext-ldap-c-api-xx.txt

Acknowledgements

OpenLDAP Software is developed and maintained by The OpenLDAP Project . OpenLDAP Software is derived from University of Michigan LDAP 3.3 Release. These API manual pages are loosely based upon descriptions provided in the IETF/LDAPEXT C LDAP API Internet Draft, a (orphaned) work in progress.


slapd

Stand-alone LDAP Daemon

/usr/libexec/slapd [-4|-6] [-T {acl|a[dd]|auth|c[at]| d[n]|i[ndex]|p[asswd]|s[chema]|t[est]}] [-d debug-level] [-f slapd-config-file] [-F slapd-config-directory] [-h URLs] [-n service-name] [-s syslog-level] [-l syslog-local-user] [-o option[=value]] [-r directory] [-u user] [-g group] [-c cookie] Slapd is the stand-alone LDAP daemon. It listens for LDAP connections on any number of ports (default 389), responding to the LDAP operations it receives over these connections. typically invoked at boot time, usually out of /etc/rc.local. Upon startup, forks and disassociates itself from the invoking tty.

If configured in the config file (or config directory), outputs its process ID (see getpid(2)) to a .pid file, as well as the command line options during invocation to an .args file (see slapd.conf(5)).

See the "OpenLDAP Administrator's Guide" for more details on slapd.

-4 Listen on IPv4 addresses only.
-6 Listen on IPv6 addresses only.
-T tool Run in Tool mode. The tool argument selects whether to run as slapadd, slapcat, slapdn, slapindex, slappasswd, slapschema, or slaptest (slapacl and slapauth need the entire acl and auth option value to be spelled out, as a is reserved to slapadd). This option should be the first option specified when it is used; any remaining options will be interpreted by the corresponding slap tool program, according to the respective man pages. Note that these tool programs will usually be symbolic links to slapd. This option is provided for situations where symbolic links are not provided or not usable.
-d debug-level Turn on debugging as defined by debug-level. If this option is specified, even with a zero argument, slapd will not fork or disassociate from the invoking terminal. Some general operation and status messages are printed for any value of debug-level. debug-level is taken as a bit string, with each bit corresponding to a different kind of debugging information. See for details. Comma-separated arrays of friendly names can be speci- fied to select debugging output of the corresponding debugging information. All the names recognized by the loglevel directive described in slapd.conf(5) are supported. If debug-level is ?, a list of installed debug- levels is printed, and slapd exits. Remember that if you turn on packet logging, packets containing bind passwords will be output, so if you redi- rect the log to a logfile, that file should be read-protected.
-s syslog-lev This option tells slapd at what debug-level debugging statements should be logged to the syslog(8) facility. The value syslog-level can be set to any value or combination allowed by the -d switch. Slapd logs all messages selected by syslog-leveli at the syslog(3) severity debug-level DEBUG, on the unit specified with -l.
-n service-name Specifies the service name for logging and other purposes. Defaults to basename of argv[0], i.e.: "slapd".
-l syslog-local-user Selects the local user of the syslog(8) facility. Value can be LOCAL0, through LOCAL7, as well as USER and DAE- MON. The default is LOCAL4. However, this option is only permitted on systems that support local users with the syslog(8) facility. Logging to syslog(8) occurs at the "DEBUG" severity debug-level.
-f slapd-config-file Specifies the slapd configuration file. The default is /etc/openldap/slapd.conf.
-F slapd-config-directory Specifies the slapd configuration directory. The default is /etc/openldap/slapd.d. If both -f and -F are speci- fied, the config file will be read and converted to config directory format and written to the specified direc- tory. If neither option is specified, slapd will attempt to read the default config directory before trying to use the default config file. If a valid config directory exists then the default config file is ignored. All of the slap tools that use the config options observe this same behavior.
-h URLlist slapd will by default serve ldap:/// (LDAP over TCP on all interfaces on default LDAP port). That is, it will bind using INADDR_ANY and port 389. The -h option may be used to specify LDAP (and other scheme) URLs to serve. For example, if slapd is given -h "ldap://127.0.0.1:9009/ ldaps:/// ldapi:///", it will listen on 127.0.0.1:9009 for LDAP, 0.0.0.0:636 for LDAP over TLS, and LDAP over IPC (Unix domain sockets). Host 0.0.0.0 represents INADDR_ANY (any interface). A space separated list of URLs is expected. The URLs should be of the LDAP, LDAPS, or LDAPI schemes, and generally without a DN or other optional parameters (excepting as discussed below). Sup- port for the latter two schemes depends on selected configuration options. Hosts may be specified by name or IPv4 and IPv6 address formats. Ports, if specified, must be numeric. The default ldap:// port is 389 and the default ldaps:// port is 636. For LDAP over IPC, name is the name of the socket, and no port is required, nor allowed; note that directory separators must be URL-encoded, like any other characters that are special to URLs; so the socket /usr/local/var/ldapi must be specified as ldapi://%2Fusr%2Flocal%2Fvar%2Fldapi The default location for the IPC socket is /var/db/openldap/run/ldapi The listener permissions are indicated by "x-mod=-rwxrwxrwx", "x-mod=0777" or "x-mod=777", where any of the "rwx" can be "-" to suppress the related permission, while any of the "7" can be any legal octal digit, accord- ing to chmod(1). The listeners can take advantage of the "x-mod" extension to apply rough limitations to opera- tions, e.g. allow read operations ("r", which applies to search and compare), write operations ("w", which applies to add, delete, modify and modrdn), and execute operations ("x", which means bind is required). "User" permissions apply to authenticated users, while "other" apply to anonymous users; "group" permissions are ignored. For example, "ldap:///????x-mod=-rw-------" means that read and write is only allowed for authenti- cated connections, and bind is required for all operations. This feature is experimental, and requires to be manually enabled at configure time.
-r directory Specifies a directory to become the root directory. slapd will change the current working directory to this directory and then chroot(2) to this directory. This is done after opening listeners but before reading any configuration file or initializing any backend. When used as a security mechanism, it should be used in con- junction with -u and -g options.
-u user slapd will run slapd with the specified user name or id, and that user's supplementary group access list as set with initgroups(3). The group ID is also changed to this user's gid, unless the -g option is used to override. Note when used with -r, slapd will use the user database in the change root environment. Note that on some systems, running as a non-privileged user will prevent passwd back-ends from accessing the encrypted passwords. Note also that any shell back-ends will run as the specified non-privileged user.
-g group slapd will run with the specified group name or id. Note when used with -r, slapd will use the group database in the change root environment.
-c cookie This option provides a cookie for the syncrepl replication consumer. The cookie is a comma separated list of name=value pairs. Currently supported syncrepl cookie fields are rid, sid, and csn. rid identifies a replica- tion thread within the consumer server and is used to find the syncrepl specification in slapd.conf(5) or slapd-config(5) having the matching replication identifier in its definition. The rid must be provided in order for any other specified values to be used. sid is the server id in a multi-master/mirror-mode configuration. csn is the commit sequence number received by a previous synchronization and represents the state of the con- sumer replica content which the syncrepl engine will synchronize to the current provider content. In case of mirror-mode or multi-master replication agreement, multiple csn values, semicolon separated, can appear. Use only the rid part to force a full reload.
-o option[=value] This option provides a generic means to specify options without the need to reserve a separate letter for them. It supports the following options: slp={on|off|slp-attrs} When SLP support is compiled into slapd, disable it (off), enable it by registering at SLP DAs without specific SLP attributes (on), or with specific SLP attributes slp-attrs that must be an SLP attribute list definition according to the SLP standard. For example, "slp=(tree=production),(server-type=OpenLDAP),(server-version=2.4.15)" registers at SLP DAs with the three SLP attributes tree, server-type and server-version that have the values given above. This allows to specifically query the SLP DAs for LDAP servers holding the production tree in case multi- ple trees are available.
EXAMPLES To start slapd and have it fork and detach from the terminal and start serving the LDAP databases defined in the default config file
/usr/libexec/slapd
To start slapd with an alternate configuration file, and turn on voluminous debugging which will be printed on standard error, type:
/usr/libexec/slapd -f /var/tmp/slapd.conf -d 255
To test whether the configuration file is correct or not, type:
/usr/libexec/slapd -Tt
SEE ldap(3), slapd.conf(5), slapd-config(5), slapd.access(5), slapacl(8), slapadd(8), slapauth(8), slapcat(8), slapdn(8), slapindex(8), slappasswd(8), slapschema(8), slaptest(8). "OpenLDAP Administrator's Guide" (http://www.OpenLDAP.org/doc/admin/)