1LDAP_SEARCH(3) Library Functions Manual LDAP_SEARCH(3)
2
3
4
6 ldap_search, ldap_search_s, ldap_search_st - Perform an LDAP search
7 operation
8
10 OpenLDAP LDAP (libldap, -lldap)
11
13 #include <sys/time.h> /* for struct timeval definition */
14 #include <ldap.h>
15
16 int ldap_search(ld, base, scope, filter, attrs, attrsonly)
17 LDAP *ld;
18 char *base;
19 int scope;
20 char *filter, *attrs[];
21 int attrsonly;
22
23 int ldap_search_s(ld, base, scope, filter, attrs, attrsonly, res)
24 LDAP *ld;
25 char *base;
26 int scope;
27 char *filter, *attrs[]
28 int attrsonly;
29 LDAPMessage **res;
30
31 int ldap_search_st(ld, base, scope, filter, attrs, attrsonly, timeout, res)
32 LDAP *ld;
33 char *base;
34 int scope;
35 char *filter, *attrs[]
36 int attrsonly;
37 struct timeval *timeout;
38 LDAPMessage **res;
39
41 These routines are used to perform LDAP search operations.
42 ldap_search_s() does the search synchronously (i.e., not returning
43 until the operation completes). ldap_search_st() does the same, but
44 allows a timeout to be specified. ldap_search() is the asynchronous
45 version, initiating the search and returning the message id of the
46 operation it initiated. Base is the DN of the entry at which to start
47 the search. Scope is the scope of the search and should be one of
48 LDAP_SCOPE_BASE, to search the object itself, LDAP_SCOPE_ONELEVEL, to
49 search the object's immediate children, or LDAP_SCOPE_SUBTREE, to
50 search the object and all its descendants.
51
52 Filter is a string representation of the filter to apply in the search.
53 Simple filters can be specified as (attributetype=attributevalue).
54 More complex filters are specified using a prefix notation according to
55 the following BNF:
56
57 <filter> ::= '(' <filtercomp> ')'
58 <filtercomp> ::= <and> | <or> | <not> | <simple>
59 <and> ::= '&' <filterlist>
60 <or> ::= '|' <filterlist>
61 <not> ::= '!' <filter>
62 <filterlist> ::= <filter> | <filter> <filterlist>
63 <simple> ::= <attributetype> <filtertype> <attributevalue>
64 <filtertype> ::= '=' | '~=' | '<=' | '>='
65
66 The '~=' construct is used to specify approximate matching. The repre‐
67 sentation for <attributetype> and <attributevalue> are as described in
68 RFC 2254. In addition, <attributevalue> can be a single * to achieve
69 an attribute existence test, or can contain text and *'s interspersed
70 to achieve substring matching.
71
72 For example, the filter "(mail=*)" will find any entries that have a
73 mail attribute. The filter "(mail=*@terminator.rs.itd.umich.edu)" will
74 find any entries that have a mail attribute ending in the specified
75 string. To put parentheses in a filter, escape them with a backslash
76 '\' character. See RFC 2254 for a more complete description of allow‐
77 able filters.
78
79 Attrs is a null-terminated array of attribute types to return from
80 entries that match filter. If NULL is specified, the return of all
81 user attributes is requested. The type "*" (LDAP_ALL_USER_ATTRIBUTES)
82 may be used to request all user attributes to be returned. The type
83 "+"(LDAP_ALL_OPERATIONAL_ATTRIBUTES) may be used to request all opera‐
84 tional attributes to be returned. To request no attributes, the type
85 "1.1" (LDAP_NO_ATTRS) should be listed by itself.
86
87 Attrsonly should be set to 1 if only attribute types are wanted. It
88 should be set to 0 if both attributes types and attribute values are
89 wanted.
90
92 ldap_search_s() and ldap_search_st() will return the LDAP error code
93 resulting from the search operation. See ldap_error(3) for details.
94 ldap_search() returns -1 in case of trouble.
95
97 Note that both read and list functionality are subsumed by these rou‐
98 tines, by using a filter like "(objectclass=*)" and a scope of
99 LDAP_SCOPE_BASE (to emulate read) or LDAP_SCOPE_ONELEVEL (to emulate
100 list).
101
102 These routines may dynamically allocate memory. The caller is respon‐
103 sible for freeing such memory using supplied deallocation routines.
104 Return values are contained in <ldap.h>.
105
107 ldap(3), ldap_result(3), ldap_error(3)
108
110 OpenLDAP is developed and maintained by The OpenLDAP Project
111 (http://www.openldap.org/). OpenLDAP is derived from University of
112 Michigan LDAP 3.3 Release.
113
114
115
116OpenLDAP 2.3.34 2007/2/16 LDAP_SEARCH(3)