3 * Copyright 1998-1999 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", strlen("secret") };
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,
56 Debug( LDAP_DEBUG_TRACE, "ldap_compare\n", 0, 0, 0 );
59 assert( LDAP_VALID( ld ) );
61 assert( attr != NULL );
62 assert( msgidp != NULL );
64 /* create a message to send */
65 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
66 return( LDAP_NO_MEMORY );
69 if ( ber_printf( ber, "{it{s{sO}}", /* '}' */
71 LDAP_REQ_COMPARE, dn, attr, bvalue ) == -1 )
73 ld->ld_errno = LDAP_ENCODING_ERROR;
75 return( ld->ld_errno );
78 /* Put Server Controls */
79 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
84 if( ber_printf( ber, /*{*/ "}" ) == -1 ) {
85 ld->ld_errno = LDAP_ENCODING_ERROR;
87 return( ld->ld_errno );
91 if ( ld->ld_cache != NULL ) {
92 if ( ldap_check_cache( ld, LDAP_REQ_COMPARE, ber ) == 0 ) {
94 ld->ld_errno = LDAP_SUCCESS;
95 *msgidp = ld->ld_msgid;
96 return( ld->ld_errno );
98 ldap_add_request_to_cache( ld, LDAP_REQ_COMPARE, ber );
100 #endif /* LDAP_NOCACHE */
102 /* send the message */
103 *msgidp = ldap_send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber );
104 return ( *msgidp < 0 ? ld->ld_errno : LDAP_SUCCESS );
108 * ldap_compare_ext - perform an ldap extended compare operation. The dn
109 * of the entry to compare to and the attribute and value to compare (in
110 * attr and value) are supplied. The msgid of the response is returned.
113 * msgid = ldap_compare( ld, "c=us@cn=bob", "userPassword", "secret" )
119 LDAP_CONST char *attr,
120 LDAP_CONST char *value )
123 struct berval bvalue;
125 bvalue.bv_val = (char *) value;
126 bvalue.bv_len = (value == NULL) ? 0 : strlen( value );
128 return ldap_compare_ext( ld, dn, attr, &bvalue, NULL, NULL, &msgid ) == LDAP_SUCCESS
136 LDAP_CONST char *attr,
137 struct berval *bvalue,
139 LDAPControl **cctrl )
145 rc = ldap_compare_ext( ld, dn, attr, bvalue, sctrl, cctrl, &msgid );
147 if ( rc != LDAP_SUCCESS )
150 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
151 return( ld->ld_errno );
153 return( ldap_result2error( ld, res, 1 ) );
160 LDAP_CONST char *attr,
161 LDAP_CONST char *value )
163 struct berval bvalue;
165 bvalue.bv_val = (char *) value;
166 bvalue.bv_len = (value == NULL) ? 0 : strlen( value );
168 return ldap_compare_ext_s( ld, dn, attr, &bvalue, NULL, NULL );