1 /* compare.c - ldbm backend compare routine */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
13 #include <ac/string.h>
16 #include "back-ldbm.h"
17 #include "proto-back-ldbm.h"
26 AttributeAssertion *ava
29 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
34 int manageDSAit = get_manageDSAit( op );
36 /* grab giant lock for reading */
37 ldap_pvt_thread_rdwr_rlock(&li->li_giant_rwlock);
39 /* get entry with reader lock */
40 if ( (e = dn2entry_r( be, ndn, &matched )) == NULL ) {
41 char *matched_dn = NULL;
42 BerVarray refs = NULL;
44 if ( matched != NULL ) {
45 matched_dn = ch_strdup( matched->e_dn );
46 refs = is_entry_referral( matched )
47 ? get_entry_referrals( be, conn, op, matched )
49 cache_return_entry_r( &li->li_cache, matched );
51 refs = referral_rewrite( default_referral,
52 NULL, dn, LDAP_SCOPE_DEFAULT );
55 ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
57 send_ldap_result( conn, op, LDAP_REFERRAL,
58 matched_dn, NULL, refs, NULL );
60 if ( refs ) ber_bvarray_free( refs );
66 if (!manageDSAit && is_entry_referral( e ) ) {
67 /* entry is a referral, don't allow add */
68 BerVarray refs = get_entry_referrals( be,
72 LDAP_LOG( BACK_LDBM, INFO,
73 "ldbm_back_compare: entry (%s) is a referral.\n", e->e_dn, 0, 0 );
75 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
80 send_ldap_result( conn, op, LDAP_REFERRAL,
81 e->e_dn, NULL, refs, NULL );
83 if (refs ) ber_bvarray_free( refs );
89 if ( ! access_allowed( be, conn, op, e,
90 ava->aa_desc, &ava->aa_value, ACL_COMPARE, NULL ) )
92 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
93 NULL, NULL, NULL, NULL );
98 rc = LDAP_NO_SUCH_ATTRIBUTE;
100 for(a = attrs_find( e->e_attrs, ava->aa_desc );
102 a = attrs_find( a->a_next, ava->aa_desc ))
104 rc = LDAP_COMPARE_FALSE;
106 if ( value_find( ava->aa_desc, a->a_vals, &ava->aa_value ) == 0 ) {
107 rc = LDAP_COMPARE_TRUE;
112 send_ldap_result( conn, op, rc,
113 NULL, NULL, NULL, NULL );
115 if( rc != LDAP_NO_SUCH_ATTRIBUTE ) {
121 cache_return_entry_r( &li->li_cache, e );
122 ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);