3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1990 Regents of the University of Michigan.
13 /* The compare request looks like this:
14 * CompareRequest ::= SEQUENCE {
15 * entry DistinguishedName,
18 * value AttributeValue
27 #include <ac/socket.h>
28 #include <ac/string.h>
34 * ldap_compare_ext - perform an ldap extended compare operation. The dn
35 * of the entry to compare to and the attribute and value to compare (in
36 * attr and value) are supplied. The msgid of the response is returned.
39 * struct berval bvalue = { "secret", sizeof("secret")-1 };
40 * rc = ldap_compare( ld, "c=us@cn=bob",
41 * "userPassword", &bvalue,
42 * sctrl, cctrl, &msgid )
48 LDAP_CONST char *attr,
49 struct berval *bvalue,
57 Debug( LDAP_DEBUG_TRACE, "ldap_compare\n", 0, 0, 0 );
60 assert( LDAP_VALID( ld ) );
62 assert( attr != NULL );
63 assert( msgidp != NULL );
65 /* check client controls */
66 rc = ldap_int_client_controls( ld, cctrls );
67 if( rc != LDAP_SUCCESS ) return rc;
69 /* create a message to send */
70 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
71 return( LDAP_NO_MEMORY );
74 if ( ber_printf( ber, "{it{s{sON}N}", /* '}' */
76 LDAP_REQ_COMPARE, dn, attr, bvalue ) == -1 )
78 ld->ld_errno = LDAP_ENCODING_ERROR;
80 return( ld->ld_errno );
83 /* Put Server Controls */
84 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
89 if( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
90 ld->ld_errno = LDAP_ENCODING_ERROR;
92 return( ld->ld_errno );
96 if ( ld->ld_cache != NULL ) {
97 if ( ldap_check_cache( ld, LDAP_REQ_COMPARE, ber ) == 0 ) {
99 ld->ld_errno = LDAP_SUCCESS;
100 *msgidp = ld->ld_msgid;
101 return( ld->ld_errno );
103 ldap_add_request_to_cache( ld, LDAP_REQ_COMPARE, ber );
105 #endif /* LDAP_NOCACHE */
107 /* send the message */
108 *msgidp = ldap_send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber );
109 return ( *msgidp < 0 ? ld->ld_errno : LDAP_SUCCESS );
113 * ldap_compare_ext - perform an ldap extended compare operation. The dn
114 * of the entry to compare to and the attribute and value to compare (in
115 * attr and value) are supplied. The msgid of the response is returned.
118 * msgid = ldap_compare( ld, "c=us@cn=bob", "userPassword", "secret" )
124 LDAP_CONST char *attr,
125 LDAP_CONST char *value )
128 struct berval bvalue;
130 bvalue.bv_val = (char *) value;
131 bvalue.bv_len = (value == NULL) ? 0 : strlen( value );
133 return ldap_compare_ext( ld, dn, attr, &bvalue, NULL, NULL, &msgid ) == LDAP_SUCCESS
141 LDAP_CONST char *attr,
142 struct berval *bvalue,
144 LDAPControl **cctrl )
150 rc = ldap_compare_ext( ld, dn, attr, bvalue, sctrl, cctrl, &msgid );
152 if ( rc != LDAP_SUCCESS )
155 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
156 return( ld->ld_errno );
158 return( ldap_result2error( ld, res, 1 ) );
165 LDAP_CONST char *attr,
166 LDAP_CONST char *value )
168 struct berval bvalue;
170 bvalue.bv_val = (char *) value;
171 bvalue.bv_len = (value == NULL) ? 0 : strlen( value );
173 return ldap_compare_ext_s( ld, dn, attr, &bvalue, NULL, NULL );