2 * Copyright (c) 1990 Regents of the University of Michigan.
11 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
16 #include <ac/socket.h>
17 #include <ac/string.h>
24 * ldap_compare - perform an ldap (and X.500) compare operation. The dn
25 * of the entry to compare to and the attribute and value to compare (in
26 * attr and value) are supplied. The msgid of the response is returned.
29 * ldap_compare( ld, "c=us@cn=bob", "userPassword", "secret" )
32 ldap_compare( LDAP *ld, char *dn, char *attr, char *value )
36 /* The compare request looks like this:
37 * CompareRequest ::= SEQUENCE {
38 * entry DistinguishedName,
41 * value AttributeValue
44 * and must be wrapped in an LDAPMessage.
47 Debug( LDAP_DEBUG_TRACE, "ldap_compare\n", 0, 0, 0 );
49 /* create a message to send */
50 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
54 if ( ber_printf( ber, "{it{s{ss}}}", ++ld->ld_msgid, LDAP_REQ_COMPARE,
55 dn, attr, value ) == -1 ) {
56 ld->ld_errno = LDAP_ENCODING_ERROR;
62 if ( ld->ld_cache != NULL ) {
63 if ( ldap_check_cache( ld, LDAP_REQ_COMPARE, ber ) == 0 ) {
65 ld->ld_errno = LDAP_SUCCESS;
66 return( ld->ld_msgid );
68 ldap_add_request_to_cache( ld, LDAP_REQ_COMPARE, ber );
72 /* send the message */
73 return ( ldap_send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber ));
77 ldap_compare_s( LDAP *ld, char *dn, char *attr, char *value )
82 if ( (msgid = ldap_compare( ld, dn, attr, value )) == -1 )
83 return( ld->ld_errno );
85 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
86 return( ld->ld_errno );
88 return( ldap_result2error( ld, res, 1 ) );