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.
16 #include <ac/socket.h>
17 #include <ac/string.h>
23 * ldap_compare_ext - perform an ldap extended compare operation. The dn
24 * of the entry to compare to and the attribute and value to compare (in
25 * attr and value) are supplied. The msgid of the response is returned.
28 * struct berval bvalue = { "secret", strlen("secret") };
29 * rc = ldap_compare( ld, "c=us@cn=bob",
30 * "userPassword", &bvalue,
31 * sctrl, cctrl, &msgid )
37 LDAP_CONST char *attr,
38 struct berval *bvalue,
45 /* The compare request looks like this:
46 * CompareRequest ::= SEQUENCE {
47 * entry DistinguishedName,
50 * value AttributeValue
53 * and must be wrapped in an LDAPMessage.
56 Debug( LDAP_DEBUG_TRACE, "ldap_compare\n", 0, 0, 0 );
58 /* create a message to send */
59 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
60 return( LDAP_NO_MEMORY );
63 if ( ber_printf( ber, "{it{s{sO}}", /* leave open '}' */
65 LDAP_REQ_COMPARE, dn, attr, &bvalue ) == -1 )
67 ld->ld_errno = LDAP_ENCODING_ERROR;
69 return( ld->ld_errno );
72 /* Put Server Controls */
73 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
78 if( ber_printf( ber, "}" ) == -1 ) {
79 ld->ld_errno = LDAP_ENCODING_ERROR;
81 return( ld->ld_errno );
85 if ( ld->ld_cache != NULL ) {
86 if ( ldap_check_cache( ld, LDAP_REQ_COMPARE, ber ) == 0 ) {
88 ld->ld_errno = LDAP_SUCCESS;
89 *msgidp = ld->ld_msgid;
90 return( ld->ld_errno );
92 ldap_add_request_to_cache( ld, LDAP_REQ_COMPARE, ber );
94 #endif /* LDAP_NOCACHE */
96 /* send the message */
97 *msgidp = ldap_send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber );
98 return ( *msgidp < 0 ? ld->ld_errno : LDAP_SUCCESS );
102 * ldap_compare_ext - perform an ldap extended compare operation. The dn
103 * of the entry to compare to and the attribute and value to compare (in
104 * attr and value) are supplied. The msgid of the response is returned.
107 * msgid = ldap_compare( ld, "c=us@cn=bob", "userPassword", "secret" )
113 LDAP_CONST char *attr,
114 LDAP_CONST char *value )
117 struct berval bvalue;
119 bvalue.bv_val = (char *) value;
120 bvalue.bv_len = (value == NULL) ? 0 : strlen( value );
122 return ldap_compare_ext( ld, dn, attr, &bvalue, NULL, NULL, &msgid ) == LDAP_SUCCESS
130 LDAP_CONST char *attr,
131 struct berval *bvalue,
133 LDAPControl **cctrl )
139 rc = ldap_compare_ext( ld, dn, attr, bvalue, sctrl, cctrl, &msgid );
141 if ( rc != LDAP_SUCCESS )
144 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
145 return( ld->ld_errno );
147 return( ldap_result2error( ld, res, 1 ) );
154 LDAP_CONST char *attr,
155 LDAP_CONST char *value )
157 struct berval bvalue;
159 bvalue.bv_val = (char *) value;
160 bvalue.bv_len = (value == NULL) ? 0 : strlen( value );
162 return ldap_compare_ext_s( ld, dn, attr, &bvalue, NULL, NULL );