1 /* compare.c - bdb backend compare routine */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
17 bdb_compare( Operation *op, SlapReply *rs )
19 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
23 int manageDSAit = get_manageDSAit( op );
28 rs->sr_err = LOCK_ID(bdb->bi_dbenv, &locker);
33 send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
39 rs->sr_err = bdb_dn2entry( op->o_bd, NULL, &op->o_req_ndn, &ei, 1, locker, &lock, op->o_tmpmemctx );
41 switch( rs->sr_err ) {
46 rs->sr_text = "ldap server busy";
48 case DB_LOCK_DEADLOCK:
49 case DB_LOCK_NOTGRANTED:
52 rs->sr_err = LDAP_OTHER;
53 rs->sr_text = "internal error";
58 if ( rs->sr_err == DB_NOTFOUND ) {
60 rs->sr_matched = ch_strdup( e->e_dn );
61 rs->sr_ref = is_entry_referral( e )
62 ? get_entry_referrals( op, e )
64 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
68 rs->sr_ref = referral_rewrite( default_referral,
69 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
72 rs->sr_err = LDAP_REFERRAL;
73 send_ldap_result( op, rs );
75 ber_bvarray_free( rs->sr_ref );
76 free( (char *)rs->sr_matched );
78 rs->sr_matched = NULL;
83 if (!manageDSAit && is_entry_referral( e ) ) {
84 /* entry is a referral, don't allow add */
85 rs->sr_ref = get_entry_referrals( op, e );
88 LDAP_LOG ( OPERATION, DETAIL1,
89 "bdb_compare: entry is referral\n", 0, 0, 0 );
91 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
95 rs->sr_err = LDAP_REFERRAL;
96 rs->sr_matched = e->e_name.bv_val;
97 send_ldap_result( op, rs );
99 ber_bvarray_free( rs->sr_ref );
101 rs->sr_matched = NULL;
105 rs->sr_err = access_allowed( op, e,
106 op->oq_compare.rs_ava->aa_desc, &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL );
107 if ( ! rs->sr_err ) {
108 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
112 rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
114 for(a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
116 a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
118 rs->sr_err = LDAP_COMPARE_FALSE;
120 if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
121 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
122 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
123 a->a_nvals, &op->oq_compare.rs_ava->aa_value, op->o_tmpmemctx ) == 0 )
125 rs->sr_err = LDAP_COMPARE_TRUE;
131 send_ldap_result( op, rs );
133 if( rs->sr_err == LDAP_COMPARE_FALSE || rs->sr_err == LDAP_COMPARE_TRUE ) {
134 rs->sr_err = LDAP_SUCCESS;
140 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
143 LOCK_ID_FREE ( bdb->bi_dbenv, locker );