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 * Portions Copyright (C) The Internet Society (1997)
14 * ASN.1 fragments are from RFC 2251; see RFC for full legal notices.
17 /* The compare request looks like this:
18 * CompareRequest ::= SEQUENCE {
19 * entry DistinguishedName,
22 * value AttributeValue
31 #include <ac/socket.h>
32 #include <ac/string.h>
39 * ldap_compare_ext - perform an ldap extended compare operation. The dn
40 * of the entry to compare to and the attribute and value to compare (in
41 * attr and value) are supplied. The msgid of the response is returned.
44 * struct berval bvalue = { "secret", sizeof("secret")-1 };
45 * rc = ldap_compare( ld, "c=us@cn=bob",
46 * "userPassword", &bvalue,
47 * sctrl, cctrl, &msgid )
53 LDAP_CONST char *attr,
54 struct berval *bvalue,
64 LDAP_LOG ( OPERATION, ENTRY, "ldap_compare\n", 0, 0, 0 );
66 Debug( LDAP_DEBUG_TRACE, "ldap_compare\n", 0, 0, 0 );
70 assert( LDAP_VALID( ld ) );
72 assert( attr != NULL );
73 assert( msgidp != NULL );
75 /* check client controls */
76 rc = ldap_int_client_controls( ld, cctrls );
77 if( rc != LDAP_SUCCESS ) return rc;
79 /* create a message to send */
80 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
81 return( LDAP_NO_MEMORY );
84 LDAP_NEXT_MSGID(ld, id);
85 rc = ber_printf( ber, "{it{s{sON}N}", /* '}' */
87 LDAP_REQ_COMPARE, dn, attr, bvalue );
90 ld->ld_errno = LDAP_ENCODING_ERROR;
92 return( ld->ld_errno );
95 /* Put Server Controls */
96 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
101 if( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
102 ld->ld_errno = LDAP_ENCODING_ERROR;
104 return( ld->ld_errno );
108 /* send the message */
109 *msgidp = ldap_send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber, id );
110 return ( *msgidp < 0 ? ld->ld_errno : LDAP_SUCCESS );
114 * ldap_compare_ext - perform an ldap extended compare operation. The dn
115 * of the entry to compare to and the attribute and value to compare (in
116 * attr and value) are supplied. The msgid of the response is returned.
119 * msgid = ldap_compare( ld, "c=us@cn=bob", "userPassword", "secret" )
125 LDAP_CONST char *attr,
126 LDAP_CONST char *value )
129 struct berval bvalue;
131 assert( value != NULL );
133 bvalue.bv_val = (char *) value;
134 bvalue.bv_len = (value == NULL) ? 0 : strlen( value );
136 return ldap_compare_ext( ld, dn, attr, &bvalue, NULL, NULL, &msgid ) == LDAP_SUCCESS
144 LDAP_CONST char *attr,
145 struct berval *bvalue,
147 LDAPControl **cctrl )
153 rc = ldap_compare_ext( ld, dn, attr, bvalue, sctrl, cctrl, &msgid );
155 if ( rc != LDAP_SUCCESS )
158 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
159 return( ld->ld_errno );
161 return( ldap_result2error( ld, res, 1 ) );
168 LDAP_CONST char *attr,
169 LDAP_CONST char *value )
171 struct berval bvalue;
173 assert( value != NULL );
175 bvalue.bv_val = (char *) value;
176 bvalue.bv_len = (value == NULL) ? 0 : strlen( value );
178 return ldap_compare_ext_s( ld, dn, attr, &bvalue, NULL, NULL );