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>
25 * ldap_compare - perform an ldap (and X.500) compare operation. The dn
26 * of the entry to compare to and the attribute and value to compare (in
27 * attr and value) are supplied. The msgid of the response is returned.
30 * ldap_compare( ld, "c=us@cn=bob", "userPassword", "secret" )
33 ldap_compare( LDAP *ld, char *dn, char *attr, char *value )
37 /* The compare request looks like this:
38 * CompareRequest ::= SEQUENCE {
39 * entry DistinguishedName,
42 * value AttributeValue
45 * and must be wrapped in an LDAPMessage.
48 Debug( LDAP_DEBUG_TRACE, "ldap_compare\n", 0, 0, 0 );
50 /* create a message to send */
51 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
55 if ( ber_printf( ber, "{it{s{ss}}}", ++ld->ld_msgid, LDAP_REQ_COMPARE,
56 dn, attr, value ) == -1 ) {
57 ld->ld_errno = LDAP_ENCODING_ERROR;
63 if ( ld->ld_cache != NULL ) {
64 if ( ldap_check_cache( ld, LDAP_REQ_COMPARE, ber ) == 0 ) {
66 ld->ld_errno = LDAP_SUCCESS;
67 return( ld->ld_msgid );
69 ldap_add_request_to_cache( ld, LDAP_REQ_COMPARE, ber );
71 #endif /* LDAP_NOCACHE */
73 /* send the message */
74 return ( ldap_send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber ));
78 ldap_compare_s( LDAP *ld, char *dn, char *attr, char *value )
83 if ( (msgid = ldap_compare( ld, dn, attr, value )) == -1 )
84 return( ld->ld_errno );
86 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
87 return( ld->ld_errno );
89 return( ldap_result2error( ld, res, 1 ) );