3 * Copyright 1998-2003 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>
35 * ldap_compare_ext - perform an ldap extended compare operation. The dn
36 * of the entry to compare to and the attribute and value to compare (in
37 * attr and value) are supplied. The msgid of the response is returned.
40 * struct berval bvalue = { "secret", sizeof("secret")-1 };
41 * rc = ldap_compare( ld, "c=us@cn=bob",
42 * "userPassword", &bvalue,
43 * sctrl, cctrl, &msgid )
49 LDAP_CONST char *attr,
50 struct berval *bvalue,
60 LDAP_LOG ( OPERATION, ENTRY, "ldap_compare\n", 0, 0, 0 );
62 Debug( LDAP_DEBUG_TRACE, "ldap_compare\n", 0, 0, 0 );
66 assert( LDAP_VALID( ld ) );
68 assert( attr != NULL );
69 assert( msgidp != NULL );
71 /* check client controls */
72 rc = ldap_int_client_controls( ld, cctrls );
73 if( rc != LDAP_SUCCESS ) return rc;
75 /* create a message to send */
76 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
77 return( LDAP_NO_MEMORY );
80 LDAP_NEXT_MSGID(ld, id);
81 rc = ber_printf( ber, "{it{s{sON}N}", /* '}' */
83 LDAP_REQ_COMPARE, dn, attr, bvalue );
86 ld->ld_errno = LDAP_ENCODING_ERROR;
88 return( ld->ld_errno );
91 /* Put Server Controls */
92 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
97 if( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
98 ld->ld_errno = LDAP_ENCODING_ERROR;
100 return( ld->ld_errno );
104 /* send the message */
105 *msgidp = ldap_send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber, id );
106 return ( *msgidp < 0 ? ld->ld_errno : LDAP_SUCCESS );
110 * ldap_compare_ext - perform an ldap extended compare operation. The dn
111 * of the entry to compare to and the attribute and value to compare (in
112 * attr and value) are supplied. The msgid of the response is returned.
115 * msgid = ldap_compare( ld, "c=us@cn=bob", "userPassword", "secret" )
121 LDAP_CONST char *attr,
122 LDAP_CONST char *value )
125 struct berval bvalue;
127 assert( value != NULL );
129 bvalue.bv_val = (char *) value;
130 bvalue.bv_len = (value == NULL) ? 0 : strlen( value );
132 return ldap_compare_ext( ld, dn, attr, &bvalue, NULL, NULL, &msgid ) == LDAP_SUCCESS
140 LDAP_CONST char *attr,
141 struct berval *bvalue,
143 LDAPControl **cctrl )
149 rc = ldap_compare_ext( ld, dn, attr, bvalue, sctrl, cctrl, &msgid );
151 if ( rc != LDAP_SUCCESS )
154 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
155 return( ld->ld_errno );
157 return( ldap_result2error( ld, res, 1 ) );
164 LDAP_CONST char *attr,
165 LDAP_CONST char *value )
167 struct berval bvalue;
169 assert( value != NULL );
171 bvalue.bv_val = (char *) value;
172 bvalue.bv_len = (value == NULL) ? 0 : strlen( value );
174 return ldap_compare_ext_s( ld, dn, attr, &bvalue, NULL, NULL );