Up to Contents

Back to Searching

Comparing a Value Against an Entry

The following routines are used to compare a given attribute value assertion against an LDAP entry. There are four variations:

           int ldap_compare_ext(
                   LDAP            *ld,
                   char            *dn,
                   char            *attr,
                   struct berval   *bvalue
                   LDAPControl     **serverctrls,
                   LDAPControl     **clientctrls,
                   int             *msgidp
           );

           int ldap_compare_ext_s(
                   LDAP            *ld,
                   char            *dn,
                   char            *attr,
                   struct berval   *bvalue,
                   LDAPControl     **serverctrls,
                   LDAPControl     **clientctrls
           );

           int ldap_compare(
                   LDAP            *ld,
                   char            *dn,
                   char            *attr,
                   char            *value
           );

           int ldap_compare_s(
                   LDAP            *ld,
                   char            *dn,
                   char            *attr,
                   char            *value
           );

Parameters are:

ld
The session handle.
dn
The name of the entry to compare against.
attr
The attribute to compare against.
bvalue
The attribute value to compare against those found in the given entry. This parameter is used in the extended routines and is a pointer to a struct berval so it is possible to compare binary values.
value
A string attribute value to compare against, used by the ldap_compare() and ldap_compare_s() functions. Use ldap_compare_ext() or ldap_compare_ext_s() if you need to compare binary values.
serverctrls
List of LDAP server controls.
clientctrls
List of client controls.
msgidp
This result parameter will be set to the message id of the request if the ldap_compare_ext() call succeeds.

The ldap_compare_ext() function initiates an asynchronous compare operation and returns the constant LDAP_SUCCESS if the request was successfully sent, or another LDAP error code if not. See the section below on error handling for more information about possible errors and how to interpret them. If successful, ldap_compare_ext() places the message id of the request in *msgidp. A subsequent call to ldap_result(), described below, can be used to obtain the result of the compare.

Similar to ldap_compare_ext(), the ldap_compare() function initiates an asynchronous compare operation and returns the message id of the operation initiated. As for ldap_compare_ext(), a subsequent call to ldap_result(), described below, can be used to obtain the result of the bind. In case of error, ldap_compare() will return -1, setting the session error parameters in the LDAP structure appropriately.

The synchronous ldap_compare_ext_s() and ldap_compare_s() functions both return the result of the operation, either the constants LDAP_COMPARE_TRUE or LDAP_COMPARE_FALSE if the operation was successful, or another LDAP error code if it was not. See the section below on error handling for more information about possible errors and how to interpret them.

The ldap_compare_ext() and ldap_compare_ext_s() functions support LDAPv3 server controls and client controls.

Up to Contents

Forward to Modifying an Entry