2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Copyright (c) 1990 Regents of the University of Michigan.
12 /* The compare request looks like this:
13 * CompareRequest ::= SEQUENCE {
14 * entry DistinguishedName,
17 * value AttributeValue
26 #include <ac/socket.h>
27 #include <ac/string.h>
33 * ldap_compare_ext - perform an ldap extended compare operation. The dn
34 * of the entry to compare to and the attribute and value to compare (in
35 * attr and value) are supplied. The msgid of the response is returned.
38 * struct berval bvalue = { "secret", strlen("secret") };
39 * rc = ldap_compare( ld, "c=us@cn=bob",
40 * "userPassword", &bvalue,
41 * sctrl, cctrl, &msgid )
47 LDAP_CONST char *attr,
48 struct berval *bvalue,
55 Debug( LDAP_DEBUG_TRACE, "ldap_compare\n", 0, 0, 0 );
58 assert( LDAP_VALID( ld ) );
60 assert( attr != NULL );
61 assert( msgidp != NULL );
63 /* create a message to send */
64 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
65 return( LDAP_NO_MEMORY );
68 if ( ber_printf( ber, "{it{s{sO}}", /* '}' */
70 LDAP_REQ_COMPARE, dn, attr, &bvalue ) == -1 )
72 ld->ld_errno = LDAP_ENCODING_ERROR;
74 return( ld->ld_errno );
77 /* Put Server Controls */
78 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
83 if( ber_printf( ber, /*{*/ "}" ) == -1 ) {
84 ld->ld_errno = LDAP_ENCODING_ERROR;
86 return( ld->ld_errno );
90 if ( ld->ld_cache != NULL ) {
91 if ( ldap_check_cache( ld, LDAP_REQ_COMPARE, ber ) == 0 ) {
93 ld->ld_errno = LDAP_SUCCESS;
94 *msgidp = ld->ld_msgid;
95 return( ld->ld_errno );
97 ldap_add_request_to_cache( ld, LDAP_REQ_COMPARE, ber );
99 #endif /* LDAP_NOCACHE */
101 /* send the message */
102 *msgidp = ldap_send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber );
103 return ( *msgidp < 0 ? ld->ld_errno : LDAP_SUCCESS );
107 * ldap_compare_ext - perform an ldap extended compare operation. The dn
108 * of the entry to compare to and the attribute and value to compare (in
109 * attr and value) are supplied. The msgid of the response is returned.
112 * msgid = ldap_compare( ld, "c=us@cn=bob", "userPassword", "secret" )
118 LDAP_CONST char *attr,
119 LDAP_CONST char *value )
122 struct berval bvalue;
124 bvalue.bv_val = (char *) value;
125 bvalue.bv_len = (value == NULL) ? 0 : strlen( value );
127 return ldap_compare_ext( ld, dn, attr, &bvalue, NULL, NULL, &msgid ) == LDAP_SUCCESS
135 LDAP_CONST char *attr,
136 struct berval *bvalue,
138 LDAPControl **cctrl )
144 rc = ldap_compare_ext( ld, dn, attr, bvalue, sctrl, cctrl, &msgid );
146 if ( rc != LDAP_SUCCESS )
149 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
150 return( ld->ld_errno );
152 return( ldap_result2error( ld, res, 1 ) );
159 LDAP_CONST char *attr,
160 LDAP_CONST char *value )
162 struct berval bvalue;
164 bvalue.bv_val = (char *) value;
165 bvalue.bv_len = (value == NULL) ? 0 : strlen( value );
167 return ldap_compare_ext_s( ld, dn, attr, &bvalue, NULL, NULL );