1 /* compare.c - ldbm backend compare routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2006 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
21 #include <ac/socket.h>
22 #include <ac/string.h>
25 #include "back-ldbm.h"
26 #include "proto-back-ldbm.h"
33 struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
37 int manageDSAit = get_manageDSAit( op );
39 rs->sr_matched = NULL;
42 /* grab giant lock for reading */
43 ldap_pvt_thread_rdwr_rlock(&li->li_giant_rwlock);
45 /* get entry with reader lock */
46 e = dn2entry_r( op->o_bd, &op->o_req_ndn, &matched );
48 if ( matched != NULL ) {
51 ber_str2bv_x( matched, 0, 1, &bv, op->o_tmpmemctx );
52 rs->sr_matched = bv.bv_val;
53 rs->sr_ref = is_entry_referral( matched )
54 ? get_entry_referrals( op, matched )
56 cache_return_entry_r( &li->li_cache, matched );
58 rs->sr_ref = referral_rewrite( default_referral,
59 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
62 ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
64 rs->sr_err = LDAP_REFERRAL;
68 if ( !manageDSAit && is_entry_referral( e ) ) {
71 /* entry is a referral, don't allow add */
72 rs->sr_ref = get_entry_referrals( op, e );
74 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
78 rs->sr_err = LDAP_REFERRAL;
79 ber_dupbv_x( &bv, &e->e_name, op->o_tmpmemctx );
80 rs->sr_matched = bv.bv_val;
85 if ( ! access_allowed( op, e,
86 op->oq_compare.rs_ava->aa_desc, &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL ) )
88 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
93 rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
95 for(a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
97 a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
99 rs->sr_err = LDAP_COMPARE_FALSE;
101 if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
102 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
103 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
104 a->a_nvals, &op->oq_compare.rs_ava->aa_value,
105 op->o_tmpmemctx ) == 0 )
107 rs->sr_err = LDAP_COMPARE_TRUE;
113 cache_return_entry_r( &li->li_cache, e );
114 ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
116 send_ldap_result( op, rs );
118 switch ( rs->sr_err ) {
119 case LDAP_COMPARE_FALSE:
120 case LDAP_COMPARE_TRUE:
121 rs->sr_err = LDAP_SUCCESS;
125 if ( rs->sr_ref != NULL ) {
126 ber_bvarray_free( rs->sr_ref );
130 if ( rs->sr_matched != NULL ) {
131 op->o_tmpfree( (char *)rs->sr_matched, op->o_tmpmemctx );
132 rs->sr_matched = NULL;