Platform SDK: Active Directory, ADSI, and Directory Services |
The ldap_search_s function searches the LDAP directory and returns a requested set of attributes for each entry matched.
ULONG ldap_search_s( LDAP* ld, PCHAR base, ULONG scope, PCHAR filter, PCHAR attrs[], ULONG attrsonly, LDAPMessage** res );
If the function succeeds, the return value is LDAP_SUCCESS.
If the function fails it returns an error code, however ldap_search_s can fail and can still allocate pMsg. See the example below for handling this behavior. Also, see Return Values for more information.
The ldap_search_s function initiates a synchronous search operation. The scope of the search is determined by the value of the scope parameter, as shown in the following table.
Scope Constant | Meaning |
---|---|
LDAP_SCOPE_BASE | Search the base entry only. |
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. |
Three options in the Session Options also determine how the search is performed: LDAP_OPT_SIZELIMIT, LDAP_OPT_TIMELIMIT, and LDAP_OPT_DEREF.
Upon completion of the search operation, ldap_search_s returns to the caller. Use ldap_search if you prefer to have the operation carried out asynchronously.
Multithreading: Calls to ldap_search_s are thread-safe.
The following code example shows how to allocate pMsg in the event ldap_search_s fails.
dwErr = ldap_search_s (i_pldap, i_lpszBase, i_ulScope, i_lpszSearchFilter, lpszAttributes, 0, pMsg ); //ldap_search_s may return a failure and still allocate pMsg. delete [] lpszAttributes; If (LDAP_SUCCESS !=dwErr) { DebugOutLDAPError(i_pldap, dwErr, _T("ldap_search_s")); hr = HRESULT_FROM_WIN32(dwErr); } else //Skip to the end of else. { ldap_msgfree(pMsg); //Still in else, not freed in failure. } if (FAILED(HR)) { for (i = 0; i<i_ulAttrCount; i++) FreeAttrValList(o_ppValues[i]); } return hr; //Leak pMsg here. }
Windows NT/2000: Requires Windows NT 4.0 SP4 or later.
Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
Header: Declared in Winldap.h.
Library: Use Wldap32.lib.
Unicode: Declared as Unicode and ANSI prototypes.