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.
22 #include <ac/socket.h>
33 char *dn = NULL, *ndn=NULL;
36 #ifdef SLAPD_SCHEMA_NOT_COMPAT
37 struct berval *nvalue;
38 AttributeAssertion ava;
43 int rc = LDAP_SUCCESS;
49 Debug( LDAP_DEBUG_TRACE, "do_compare\n", 0, 0, 0 );
52 * Parse the compare request. It looks like this:
54 * CompareRequest := [APPLICATION 14] SEQUENCE {
55 * entry DistinguishedName,
58 * value AttributeValue
63 if ( ber_scanf( op->o_ber, "{a" /*}*/, &dn ) == LBER_ERROR ) {
64 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
65 send_ldap_disconnect( conn, op,
66 LDAP_PROTOCOL_ERROR, "decoding error" );
67 return SLAPD_DISCONNECT;
70 if ( ber_scanf( op->o_ber, "{oo}", &desc, &value ) == LBER_ERROR ) {
71 Debug( LDAP_DEBUG_ANY, "do_compare: get ava failed\n", 0, 0, 0 );
72 send_ldap_disconnect( conn, op,
73 LDAP_PROTOCOL_ERROR, "decoding error" );
74 rc = SLAPD_DISCONNECT;
78 if ( ber_scanf( op->o_ber, /*{*/ "}" ) == LBER_ERROR ) {
79 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
80 send_ldap_disconnect( conn, op,
81 LDAP_PROTOCOL_ERROR, "decoding error" );
82 rc = SLAPD_DISCONNECT;
86 if( ( rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
87 Debug( LDAP_DEBUG_ANY, "do_compare: get_ctrls failed\n", 0, 0, 0 );
91 ndn = ch_strdup( dn );
93 if( dn_normalize( ndn ) == NULL ) {
94 Debug( LDAP_DEBUG_ANY, "do_compare: invalid dn (%s)\n", dn, 0, 0 );
95 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
96 "invalid DN", NULL, NULL );
100 #ifdef SLAPD_SCHEMA_NOT_COMPAT
102 rc = slap_bv2ad( &desc, &ava.aa_desc, &text );
103 if( rc != LDAP_SUCCESS ) {
104 send_ldap_result( conn, op, rc, NULL,
109 if( !ava.aa_desc->ad_type->sat_equality ) {
110 /* no equality matching rule */
111 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_MATCHING, NULL,
112 "no equality matching rule defined", NULL, NULL );
116 rc = value_normalize( ava.aa_desc, SLAP_MR_EQUALITY, &value, &nvalue, &text );
118 if( rc != LDAP_SUCCESS ) {
119 send_ldap_result( conn, op, rc, NULL,
124 ava.aa_value = nvalue;
126 Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
127 dn, ava.aa_desc->ad_cname, ava.aa_value->bv_val );
129 Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d CMP dn=\"%s\" attr=\"%s\"\n",
130 op->o_connid, op->o_opid, dn, ava.aa_desc->ad_cname, 0 );
133 ava.ava_type = desc.bv_val;
134 ava.ava_value = value;
135 attr_normalize( ava.ava_type );
136 value_normalize( ava.ava_value.bv_val, attr_syntax( ava.ava_type ) );
138 Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
139 dn, ava.ava_type, ava.ava_value.bv_val );
141 Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d CMP dn=\"%s\" attr=\"%s\"\n",
142 op->o_connid, op->o_opid, dn, ava.ava_type, 0 );
147 * We could be serving multiple database backends. Select the
148 * appropriate one, or send a referral to our "referral server"
149 * if we don't hold it.
151 if ( (be = select_backend( ndn )) == NULL ) {
152 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
153 NULL, NULL, default_referral, NULL );
158 /* make sure this backend recongizes critical controls */
159 rc = backend_check_controls( be, conn, op, &text ) ;
161 if( rc != LDAP_SUCCESS ) {
162 send_ldap_result( conn, op, rc,
163 NULL, text, NULL, NULL );
167 /* deref suffix alias if appropriate */
168 ndn = suffix_alias( be, ndn );
170 if ( be->be_compare ) {
171 (*be->be_compare)( be, conn, op, dn, ndn, &ava );
173 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
174 NULL, "operation not supported within namingContext", NULL, NULL );
181 free( value.bv_val );
182 #ifdef SLAPD_SCHEMA_NOT_COMPAT
183 if( ava.aa_desc != NULL ) {
184 ad_free( ava.aa_desc, 1 );