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>
23 * ldap_compare - perform an ldap (and X.500) 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 * ldap_compare( ld, "c=us@cn=bob", "userPassword", "secret" )
31 ldap_compare( LDAP *ld, char *dn, char *attr, char *value )
35 /* The compare request looks like this:
36 * CompareRequest ::= SEQUENCE {
37 * entry DistinguishedName,
40 * value AttributeValue
43 * and must be wrapped in an LDAPMessage.
46 Debug( LDAP_DEBUG_TRACE, "ldap_compare\n", 0, 0, 0 );
48 /* create a message to send */
49 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
53 if ( ber_printf( ber, "{it{s{ss}}}", ++ld->ld_msgid, LDAP_REQ_COMPARE,
54 dn, attr, value ) == -1 ) {
55 ld->ld_errno = LDAP_ENCODING_ERROR;
61 if ( ld->ld_cache != NULL ) {
62 if ( ldap_check_cache( ld, LDAP_REQ_COMPARE, ber ) == 0 ) {
64 ld->ld_errno = LDAP_SUCCESS;
65 return( ld->ld_msgid );
67 ldap_add_request_to_cache( ld, LDAP_REQ_COMPARE, ber );
69 #endif /* LDAP_NOCACHE */
71 /* send the message */
72 return ( ldap_send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber ));
76 ldap_compare_s( LDAP *ld, char *dn, char *attr, char *value )
81 if ( (msgid = ldap_compare( ld, dn, attr, value )) == -1 )
82 return( ld->ld_errno );
84 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
85 return( ld->ld_errno );
87 return( ldap_result2error( ld, res, 1 ) );