Platform SDK: Active Directory, ADSI, and Directory Services

ldap_compare

Use the ldap_compare function to determine whether an attribute for a given entry holds a known value.

ULONG ldap_compare(
  LDAP* ld,
  PCHAR dn,
  PCHAR attr,
  PCHAR value
);

Parameters

ld
[in] The session handle.
dn
[in] The distinguished name of the entry.
attr
[in] The attribute to compare.
value
[in] The string attribute value to compare to the attribute value.

Return Values

If the function succeeds, the return value is the message ID of the compare operation.

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

Remarks

The ldap_compare function initiates an asynchronous compare operation, comparing the value of an attribute to a known string value. Use ldap_compare_ext or ldap_compare_ext_s if you need to compare binary values. Use ldap_compare_s or ldap_compare_ext_s to carry out a synchronous compare operation.

As an asynchronous function, ldap_compare 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 operation before it has been completed, call ldap_abandon.

If you prefer to have the function return the results directly, use the synchronous routine ldap_compare_s. Use ldap_compare_ext or ldap_compare_ext_s if you need support for LDAP 3 server and client controls.

Multithreading: Calls to ldap_compare are not thread-safe because the function returns a message ID rather than the return code. In order to determine whether the call returned an error value, you have to retrieve the return code from the connection block. It's possible for another thread to overwrite the return code before you retrieve it. Use ldap_compare_ext, ldap_compare_s, or ldap_compare_ext_s, all of which are thread-safe.

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

  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.

See Also

Functions, ldap_abandon, ldap_bind, ldap_compare_ext, ldap_compare_ext_s, ldap_compare_s, ldap_result, ldap_simple_bind