ldap_search function (winldap.h)

The ldap_search function searches the LDAP directory and returns a requested set of attributes for each matched entry.

Syntax

WINLDAPAPI ULONG LDAPAPI ldap_search(
  [in] LDAP   *ld,
  [in] PSTR   base,
  [in] ULONG  scope,
  [in] PSTR   filter,
  [in] PZPSTR attrs,
  [in] ULONG  attrsonly
);

Parameters

[in] ld

A session handle.

[in] base

A pointer to a null-terminated string that contains the distinguished name of the entry at which to start the search.

[in] scope

A data type that specifies one of the following values to indicate the search scope.

LDAP_SCOPE_BASE

Search only the base entry.

LDAP_SCOPE_ONELEVEL

Search all entries in the first level below the base entry, excluding the base entry.

LDAP_SCOPE_SUBTREE

Search the base entry and all entries in the tree below the base.

[in] filter

A pointer to a null-terminated string that specifies the search filter. For more information, see Search Filter Syntax.

[in] attrs

A null-terminated array of null-terminated strings that indicate which attributes to return for each matching entry. Pass NULL to retrieve available attributes.

[in] attrsonly

Boolean value that should be zero if both attribute types and values are to be returned, nonzero if only types are required.

Return value

If the function succeeds, it returns the message ID of the search operation.

If the function fails, it returns –1 and sets the session error parameters in the LDAP data structure.

Remarks

The ldap_search function initiates an asynchronous search operation.

Use the ldap_set_option function with the ld session handle to set the LDAP_OPT_SIZELIMIT, LDAP_OPT_TIMELIMIT, and LDAP_OPT_DEREF options that determine how the search is performed. For more information, see Session Options.

As an asynchronous function, ldap_search returns a message ID for the operation. Call ldap_result with the message ID to get the result of the operation. To cancel an asynchronous search operation before it has completed, call ldap_abandon.

To have the function return the results directly, use the synchronous routine ldap_search_s. Use ldap_search_ext or ldap_search_ext_s to implement support for LDAP 3 server and client controls.

Multithreading: Calls to ldap_search are thread-safe, provided that LdapGetLastError is used to retrieve the actual session error code when the function call returns the -1 failure code.

Note  When connecting to an LDAP 2 server, the application must perform a bind operation, by calling one of the ldap_bind or ldap_simple_bind routines, before attempting other operations.
 

Requirements

Requirement Value
Minimum supported client Windows Vista
Minimum supported server Windows Server 2008
Target Platform Windows
Header winldap.h
Library Wldap32.lib
DLL Wldap32.dll

See also

Functions

LDAP

ldap_abandon

ldap_bind

ldap_result

ldap_search_ext

ldap_search_ext_s

ldap_search_s

ldap_simple_bind