ldap_search_s

Synchronously searches the directory.

LDAP Version:v2 or higher
Library:*ldapsdk.*
NDS Version:7.xx or higher
Platform:NLM, Windows (NT, 95, 98, 2000, XP, Vista 32-bit and 64-bit ), Linux (32-bit and 64-bit), Solaris, AIX, and HP-UX

Syntax

  #include <ldap.h>
  
  int ldap_search_s (
     LDAP           *ld,
     const char     *base,
     int             scope,
     const char     *filter,
     char          **attrs,
     int             attrsonly,
     LDAPMessage   **res);
  
  

Parameters

ld

(IN) Points to the handle for the LDAP session.

base

(IN) Points to the distinguished name of the entry from which to start the search.

scope

(IN) Specifies the scope of the search and uses one of the following flags:

  • LDAP_SCOPE_BASE (0x00)—searches the entry specified by the base parameter.

  • LDAP_SCOPE_ONELEVEL (0x01)—searches the immediate subordinates of the entry specified by the base parameter.

  • LDAP_SCOPE_SUBTREE (0x02)—searches the entire subtree starting with the entry specified by the base parameter.

filter

(IN) Points to a search filter.

If NULL is passed, a default filter ("objectclass=*") is used, a filter which matches all entries in the directory. Using a NULL filter is not recommended for subtree searches on trees that potentially have hundreds of thousands of entries.

Simple filters take the form of strings: attribute name=attribute value. For more complex filters, see Using Search Filters.

attrs

(IN) Points to a NULL-terminated array of strings indicating which attributes to return with each matching entry. To return only entry names (and no attributes), set the first, and only string in the array, to LDAP_NO_ATTRS. To return all attributes, set this parameter to NULL.

For example, to return the cn, surname, and givenName attributes, declare attrs as: char* attrs[]={"cn", "surname", "givenName", NULL};

attrsonly

(IN) Specifies whether to return just attributes or attributes and values.

  • Zero—return both attributes and values

  • Non-zero—return only attributes

res

(OUT) Returns a pointer to an array of result messages if the search succeeds or NULL if no results are returned.

Return Values

0x00

LDAP_SUCCESS

Non-zero

Failure. For a complete list, see LDAP Return Codes.

0x53

LDAP_ENCODING_ERROR

0X57

LDAP_FILTER_ERROR

Remarks

The ldap_search function is an older function which does not allow you to specify LDAP controls.

The LDAP_OPT_DEREF option in the LDAP session handle affects how aliases are handled during the search.

  • The LDAP_DEREF_FINDING value means aliases are dereferenced when locating the base object but not during the search.

  • The LDAP_DEREF_SEARCHING value means aliases are dereferenced during the search but not when locating the base object of the search.

Server timeouts and size limits for this function are set using the LDAP_OPT_TIMELIMIT and LDAP_OPT_SIZELIMIT options on the LDAP handle. This function has no client time or size limits.

See Also

ldap_search_ext, ldap_search_ext_s, ldap_search_st