3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1995 Regents of the University of Michigan.
10 * Redistribution and use in source and binary forms are permitted
11 * provided that this notice is preserved and that due credit is given
12 * to the University of Michigan at Ann Arbor. The name of the University
13 * may not be used to endorse or promote products derived from this
14 * software without specific prior written permission. This software
15 * is provided ``as is'' without express or implied warranty.
21 #include <ac/socket.h>
32 char *dn = NULL, *ndn=NULL;
35 struct berval *nvalue;
36 AttributeAssertion ava;
38 int rc = LDAP_SUCCESS;
39 const char *text = NULL;
45 Debug( LDAP_DEBUG_TRACE, "do_compare\n", 0, 0, 0 );
48 * Parse the compare request. It looks like this:
50 * CompareRequest := [APPLICATION 14] SEQUENCE {
51 * entry DistinguishedName,
54 * value AttributeValue
59 if ( ber_scanf( op->o_ber, "{a" /*}*/, &dn ) == LBER_ERROR ) {
60 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
61 send_ldap_disconnect( conn, op,
62 LDAP_PROTOCOL_ERROR, "decoding error" );
63 return SLAPD_DISCONNECT;
66 if ( ber_scanf( op->o_ber, "{oo}", &desc, &value ) == LBER_ERROR ) {
67 Debug( LDAP_DEBUG_ANY, "do_compare: get ava failed\n", 0, 0, 0 );
68 send_ldap_disconnect( conn, op,
69 LDAP_PROTOCOL_ERROR, "decoding error" );
70 rc = SLAPD_DISCONNECT;
74 if ( ber_scanf( op->o_ber, /*{*/ "}" ) == LBER_ERROR ) {
75 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
76 send_ldap_disconnect( conn, op,
77 LDAP_PROTOCOL_ERROR, "decoding error" );
78 rc = SLAPD_DISCONNECT;
82 if( ( rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
83 Debug( LDAP_DEBUG_ANY, "do_compare: get_ctrls failed\n", 0, 0, 0 );
87 ndn = ch_strdup( dn );
89 if( dn_normalize( ndn ) == NULL ) {
90 Debug( LDAP_DEBUG_ANY, "do_compare: invalid dn (%s)\n", dn, 0, 0 );
91 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
92 "invalid DN", NULL, NULL );
97 * We could be serving multiple database backends. Select the
98 * appropriate one, or send a referral to our "referral server"
99 * if we don't hold it.
101 if ( (be = select_backend( ndn )) == NULL ) {
102 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
103 NULL, NULL, default_referral, NULL );
108 /* make sure this backend recongizes critical controls */
109 rc = backend_check_controls( be, conn, op, &text ) ;
111 if( rc != LDAP_SUCCESS ) {
112 send_ldap_result( conn, op, rc,
113 NULL, text, NULL, NULL );
117 /* check for referrals */
118 rc = backend_check_referrals( be, conn, op,
121 if ( rc != LDAP_SUCCESS ) {
125 rc = slap_bv2ad( &desc, &ava.aa_desc, &text );
126 if( rc != LDAP_SUCCESS ) {
127 send_ldap_result( conn, op, rc, NULL,
132 if( !ava.aa_desc->ad_type->sat_equality ) {
133 /* no equality matching rule */
134 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_MATCHING, NULL,
135 "no equality matching rule defined", NULL, NULL );
139 rc = value_normalize( ava.aa_desc, SLAP_MR_EQUALITY, &value, &nvalue, &text );
141 if( rc != LDAP_SUCCESS ) {
142 send_ldap_result( conn, op, rc, NULL,
147 ava.aa_value = nvalue;
149 Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
150 dn, ava.aa_desc->ad_cname->bv_val, ava.aa_value->bv_val );
152 Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d CMP dn=\"%s\" attr=\"%s\"\n",
153 op->o_connid, op->o_opid, dn, ava.aa_desc->ad_cname->bv_val, 0 );
156 /* deref suffix alias if appropriate */
157 ndn = suffix_alias( be, ndn );
159 if ( be->be_compare ) {
160 (*be->be_compare)( be, conn, op, dn, ndn, &ava );
162 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
163 NULL, "operation not supported within namingContext", NULL, NULL );
170 free( value.bv_val );
171 if( ava.aa_desc != NULL ) {
172 ad_free( ava.aa_desc, 1 );