3 * Copyright 1998-1999 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;
37 int rc = LDAP_SUCCESS;
38 #ifdef SLAPD_SCHEMA_NOT_COMPAT
40 AttributeAssertion ava;
51 Debug( LDAP_DEBUG_TRACE, "do_compare\n", 0, 0, 0 );
54 * Parse the compare request. It looks like this:
56 * CompareRequest := [APPLICATION 14] SEQUENCE {
57 * entry DistinguishedName,
60 * value AttributeValue
65 if ( ber_scanf( op->o_ber, "{a" /*}*/, &dn ) == LBER_ERROR ) {
66 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
67 send_ldap_disconnect( conn, op,
68 LDAP_PROTOCOL_ERROR, "decoding error" );
69 return SLAPD_DISCONNECT;
72 if ( ber_scanf( op->o_ber, "{oo}", &desc, &value ) == LBER_ERROR ) {
73 Debug( LDAP_DEBUG_ANY, "do_compare: get ava failed\n", 0, 0, 0 );
74 send_ldap_disconnect( conn, op,
75 LDAP_PROTOCOL_ERROR, "decoding error" );
76 rc = SLAPD_DISCONNECT;
80 if ( ber_scanf( op->o_ber, /*{*/ "}" ) == LBER_ERROR ) {
81 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
82 send_ldap_disconnect( conn, op,
83 LDAP_PROTOCOL_ERROR, "decoding error" );
84 rc = SLAPD_DISCONNECT;
88 if( ( rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
89 Debug( LDAP_DEBUG_ANY, "do_compare: get_ctrls failed\n", 0, 0, 0 );
93 ndn = ch_strdup( dn );
95 if( dn_normalize( ndn ) == NULL ) {
96 Debug( LDAP_DEBUG_ANY, "do_compare: invalid dn (%s)\n", dn, 0, 0 );
97 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
98 "invalid DN", NULL, NULL );
102 #ifdef SLAPD_SCHEMA_NOT_COMPAT
103 rc = slap_bv2ad( &desc, &ava.aa_desc, &text );
104 if( rc != LDAP_SUCCESS ) {
105 send_ldap_result( conn, op, rc, NULL,
109 ava.aa_value = &value;
111 Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
112 dn, ava.aa_desc->ad_cname, ava.aa_value->bv_val );
114 Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d CMP dn=\"%s\" attr=\"%s\"\n",
115 op->o_connid, op->o_opid, dn, ava.aa_desc->ad_cname, 0 );
118 ava.ava_type = desc.bv_val;
119 ava.ava_value = value;
120 attr_normalize( ava.ava_type );
121 value_normalize( ava.ava_value.bv_val, attr_syntax( ava.ava_type ) );
123 Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
124 dn, ava.ava_type, ava.ava_value.bv_val );
126 Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d CMP dn=\"%s\" attr=\"%s\"\n",
127 op->o_connid, op->o_opid, dn, ava.ava_type, 0 );
132 * We could be serving multiple database backends. Select the
133 * appropriate one, or send a referral to our "referral server"
134 * if we don't hold it.
136 if ( (be = select_backend( ndn )) == NULL ) {
137 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
138 NULL, NULL, default_referral, NULL );
143 /* make sure this backend recongizes critical controls */
144 rc = backend_check_controls( be, conn, op, &text ) ;
146 if( rc != LDAP_SUCCESS ) {
147 send_ldap_result( conn, op, rc,
148 NULL, text, NULL, NULL );
152 /* deref suffix alias if appropriate */
153 ndn = suffix_alias( be, ndn );
155 if ( be->be_compare ) {
156 (*be->be_compare)( be, conn, op, dn, ndn, &ava );
158 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
159 NULL, "Function not implemented", NULL, NULL );
166 free( value.bv_val );
167 #ifdef SLAPD_SCHEMA_NOT_COMPAT
168 if( ava.aa_desc != NULL ) {
169 ad_free( ava.aa_desc, 1 );