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_r( op->o_bd, NULL, &op->o_req_ndn, &e, &matched, 0, locker, &lock );
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 ( matched != NULL ) {
59 rs->sr_matched = ch_strdup( matched->e_dn );
60 rs->sr_ref = is_entry_referral( matched )
61 ? get_entry_referrals( op, matched )
63 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, matched, &lock );
67 rs->sr_ref = referral_rewrite( default_referral,
68 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
71 rs->sr_err = LDAP_REFERRAL;
72 send_ldap_result( op, rs );
74 ber_bvarray_free( rs->sr_ref );
75 free( (char *)rs->sr_matched );
77 rs->sr_matched = NULL;
82 if (!manageDSAit && is_entry_referral( e ) ) {
83 /* entry is a referral, don't allow add */
84 rs->sr_ref = get_entry_referrals( op, e );
87 LDAP_LOG ( OPERATION, DETAIL1,
88 "bdb_compare: entry is referral\n", 0, 0, 0 );
90 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
94 rs->sr_err = LDAP_REFERRAL;
95 rs->sr_matched = e->e_name.bv_val;
96 send_ldap_result( op, rs );
98 ber_bvarray_free( rs->sr_ref );
100 rs->sr_matched = NULL;
104 rs->sr_err = access_allowed( op, e,
105 op->oq_compare.rs_ava->aa_desc, &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL );
106 if ( ! rs->sr_err ) {
107 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
111 rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
113 for(a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
115 a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
117 rs->sr_err = LDAP_COMPARE_FALSE;
119 if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
120 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
121 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
122 a->a_nvals, &op->oq_compare.rs_ava->aa_value ) == 0 )
124 rs->sr_err = LDAP_COMPARE_TRUE;
130 send_ldap_result( op, rs );
132 if( rs->sr_err == LDAP_COMPARE_FALSE || rs->sr_err == LDAP_COMPARE_TRUE ) {
133 rs->sr_err = LDAP_SUCCESS;
139 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
142 LOCK_ID_FREE ( bdb->bi_dbenv, locker );