2 * Copyright (c) 1990 Regents of the University of Michigan.
9 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
19 #if !defined( MACOS ) && !defined( DOS )
20 #include <sys/types.h>
21 #include <sys/socket.h>
29 * ldap_compare - perform an ldap (and X.500) compare operation. The dn
30 * of the entry to compare to and the attribute and value to compare (in
31 * attr and value) are supplied. The msgid of the response is returned.
34 * ldap_compare( ld, "c=us@cn=bob", "userPassword", "secret" )
37 ldap_compare( LDAP *ld, char *dn, char *attr, char *value )
41 /* The compare request looks like this:
42 * CompareRequest ::= SEQUENCE {
43 * entry DistinguishedName,
46 * value AttributeValue
49 * and must be wrapped in an LDAPMessage.
52 Debug( LDAP_DEBUG_TRACE, "ldap_compare\n", 0, 0, 0 );
54 /* create a message to send */
55 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
59 if ( ber_printf( ber, "{it{s{ss}}}", ++ld->ld_msgid, LDAP_REQ_COMPARE,
60 dn, attr, value ) == -1 ) {
61 ld->ld_errno = LDAP_ENCODING_ERROR;
67 if ( ld->ld_cache != NULL ) {
68 if ( ldap_check_cache( ld, LDAP_REQ_COMPARE, ber ) == 0 ) {
70 ld->ld_errno = LDAP_SUCCESS;
71 return( ld->ld_msgid );
73 ldap_add_request_to_cache( ld, LDAP_REQ_COMPARE, ber );
77 /* send the message */
78 return ( ldap_send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber ));
82 ldap_compare_s( LDAP *ld, char *dn, char *attr, char *value )
87 if ( (msgid = ldap_compare( ld, dn, attr, value )) == -1 )
88 return( ld->ld_errno );
90 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
91 return( ld->ld_errno );
93 return( ldap_result2error( ld, res, 1 ) );