1 /* attribute.c - bdb backend acl attribute 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>
17 #include "proto-bdb.h"
19 /* return LDAP_SUCCESS IFF we can retrieve the attributes
28 struct berval *entry_ndn,
29 AttributeDescription *entry_at,
32 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
33 struct bdb_op_info *boi = NULL;
39 const char *entry_at_name = entry_at->ad_cname.bv_val;
40 AccessControlState acl_state = ACL_STATE_INIT;
47 LDAP_LOG( BACK_BDB, ARGS,
48 "bdb_attribute: gr ndn: \"%s\"\n", entry_ndn->bv_val, 0, 0 );
49 LDAP_LOG( BACK_BDB, ARGS,
50 "bdb_attribute: at: \"%s\"\n", entry_at_name, 0, 0);
51 LDAP_LOG( BACK_BDB, ARGS, "bdb_attribute: tr ndn: \"%s\"\n",
52 target ? target->e_ndn : "", 0, 0 );
54 Debug( LDAP_DEBUG_ARGS,
55 "=> bdb_attribute: gr ndn: \"%s\"\n",
56 entry_ndn->bv_val, 0, 0 );
57 Debug( LDAP_DEBUG_ARGS,
58 "=> bdb_attribute: at: \"%s\"\n",
59 entry_at_name, 0, 0 );
61 Debug( LDAP_DEBUG_ARGS,
62 "=> bdb_attribute: tr ndn: \"%s\"\n",
63 target ? target->e_ndn : "", 0, 0 );
66 if( op ) boi = (struct bdb_op_info *) op->o_private;
67 if( boi != NULL && be == boi->boi_bdb ) {
69 locker = boi->boi_locker;
73 locker = TXN_ID ( txn );
74 } else if ( !locker ) {
75 rc = LOCK_ID ( bdb->bi_dbenv, &locker );
85 if (target != NULL && dn_match(&target->e_nname, entry_ndn)) {
86 /* we already have a LOCKED copy of the entry */
89 LDAP_LOG( BACK_BDB, DETAIL1,
90 "bdb_attribute: target is LOCKED (%s)\n", entry_ndn->bv_val, 0, 0 );
92 Debug( LDAP_DEBUG_ARGS,
93 "=> bdb_attribute: target is entry: \"%s\"\n",
94 entry_ndn->bv_val, 0, 0 );
99 /* can we find entry */
100 rc = bdb_dn2entry_r( be, txn, entry_ndn, &e, NULL, 0, locker, &lock );
105 case DB_LOCK_DEADLOCK:
106 case DB_LOCK_NOTGRANTED:
107 /* the txn must abort and retry */
112 ldap_pvt_thread_yield();
116 if ( free_lock_id ) {
117 LOCK_ID_FREE( bdb->bi_dbenv, locker );
119 return (rc != LDAP_BUSY) ? LDAP_OTHER : LDAP_BUSY;
123 LDAP_LOG( BACK_BDB, INFO,
124 "bdb_attribute: cannot find entry (%s)\n",
125 entry_ndn->bv_val, 0, 0 );
127 Debug( LDAP_DEBUG_ACL,
128 "=> bdb_attribute: cannot find entry: \"%s\"\n",
129 entry_ndn->bv_val, 0, 0 );
131 if ( free_lock_id ) {
132 LOCK_ID_FREE( bdb->bi_dbenv, locker );
134 return LDAP_NO_SUCH_OBJECT;
138 LDAP_LOG( BACK_BDB, DETAIL1, "bdb_attribute: found entry (%s)\n",
139 entry_ndn->bv_val, 0, 0 );
141 Debug( LDAP_DEBUG_ACL,
142 "=> bdb_attribute: found entry: \"%s\"\n",
143 entry_ndn->bv_val, 0, 0 );
148 /* find attribute values */
149 if( is_entry_alias( e ) ) {
151 LDAP_LOG( BACK_BDB, INFO,
152 "bdb_attribute: entry (%s) is an alias\n", e->e_dn, 0, 0 );
154 Debug( LDAP_DEBUG_ACL,
155 "<= bdb_attribute: entry is an alias\n", 0, 0, 0 );
157 rc = LDAP_ALIAS_PROBLEM;
162 if( is_entry_referral( e ) ) {
164 LDAP_LOG( BACK_BDB, INFO,
165 "bdb_attribute: entry (%s) is a referral.\n", e->e_dn, 0, 0);
167 Debug( LDAP_DEBUG_ACL,
168 "<= bdb_attribute: entry is a referral\n", 0, 0, 0 );
174 if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
176 LDAP_LOG( BACK_BDB, INFO,
177 "bdb_attribute: failed to find %s.\n", entry_at_name, 0, 0 );
179 Debug( LDAP_DEBUG_ACL,
180 "<= bdb_attribute: failed to find %s\n",
181 entry_at_name, 0, 0 );
183 rc = LDAP_NO_SUCH_ATTRIBUTE;
187 if (conn != NULL && op != NULL
188 && access_allowed( be, conn, op, e, entry_at, NULL,
189 ACL_AUTH, &acl_state ) == 0 )
191 rc = LDAP_INSUFFICIENT_ACCESS;
195 for ( i = 0; attr->a_vals[i].bv_val != NULL; i++ ) {
199 v = (BerVarray) ch_malloc( sizeof(struct berval) * (i+1) );
201 for ( i=0, j=0; attr->a_vals[i].bv_val != NULL; i++ ) {
204 && access_allowed(be, conn, op, e, entry_at,
205 &attr->a_vals[i], ACL_AUTH, &acl_state ) == 0)
209 ber_dupbv( &v[j], &attr->a_vals[i] );
211 if( v[j].bv_val != NULL ) j++;
217 rc = LDAP_INSUFFICIENT_ACCESS;
228 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
231 if ( free_lock_id ) {
232 LOCK_ID_FREE( bdb->bi_dbenv, locker );
236 LDAP_LOG( BACK_BDB, ENTRY, "bdb_attribute: rc=%d nvals=%d.\n", rc, j, 0 );
238 Debug( LDAP_DEBUG_TRACE,
239 "bdb_attribute: rc=%d nvals=%d\n",