#include <lber.h> #include <ldap.h>int ldap_search(LDAP
ld, char
base, int scope, char
filter, char
attrs[], int attrsonly);
int ldap_search_s(LDAP
ld, char
base, int scope, char
filter, char
attrs[], int attrsonly, LDAPMessage
res);
int ldap_search_st(LDAP
ld, char
base, int scope, char
filter, char
attrs[], int attrsonly, struct timeval
timeout, LDAPMessage
res);
(cn=John Doe)In this example, the attribute type is ``cn'' (common name), the operator is ``='', and the attribute value is ``John Doe''. This filter will retrieve all entries having a common name equal to ``John Doe''.
The following filter retrieves all entries with a surname beginning with ``S'':
(sn=SSimple filters can be combined to form complex filters. A prefix notation is used. In the following example, the filter retrieves entries whose common name attribute is either ``John Doe'' or ``Jane Doe'':)
(|(cn=John Doe) (cn=Jane Doe))The ``|'' notation represents OR: ``&'' can be used to represent AND, and ``!'' to represent NOT.
For further details of search filters, refer to RFC 1960.
attrs is a null-terminated array of attribute types to return from entries that match filter. If NULL is specified, all attributes will be returned. For example, to return only the fax and home telephone number attributes for an entry:
charattrsonly is a Boolean that should be set to 0 if both attributes types and attribute values are wanted, and to non-zero if only attribute types are wanted.my_attrs = {"facsimileTelephoneNumber", "homePhone", NULL};
For ldap_search_s and ldap_search_st, the res parameter gives the location into which the result of the function call will be placed, if successful. The result will be one or more messages in a chain. Use ldap_first_entry(3ldap) to obtain the first of these messages, then ldap_next_entry(3ldap) to step through the chain. Examine the contents of individual messages with ldap_first_attribute(3ldap) and ldap_next_attribute(3ldap). For the asynchronous variant, ldap_search, call ldap_result(3ldap) to obtain the results.
For ldap_search_st, the timeout parameter refers to a struct timeval, which gives a timeout period in seconds and microseconds.