1 /* attribute.c - bdb backend acl attribute routine */
4 * Copyright 1998-2002 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;
46 LDAP_LOG( BACK_BDB, ARGS,
47 "bdb_attribute: gr dn: \"%s\"\n", entry_ndn->bv_val, 0, 0 );
48 LDAP_LOG( BACK_BDB, ARGS,
49 "bdb_attribute: at: \"%s\"\n", entry_at_name, 0, 0);
50 LDAP_LOG( BACK_BDB, ARGS, "bdb_attribute: tr dn: \"%s\"\n",
51 target ? target->e_ndn : "", 0, 0 );
53 Debug( LDAP_DEBUG_ARGS,
54 "=> bdb_attribute: gr dn: \"%s\"\n",
55 entry_ndn->bv_val, 0, 0 );
56 Debug( LDAP_DEBUG_ARGS,
57 "=> bdb_attribute: at: \"%s\"\n",
58 entry_at_name, 0, 0 );
60 Debug( LDAP_DEBUG_ARGS,
61 "=> bdb_attribute: tr dn: \"%s\"\n",
62 target ? target->e_ndn : "", 0, 0 );
65 if( op ) boi = (struct bdb_op_info *) op->o_private;
66 if( boi != NULL && be == boi->boi_bdb ) {
71 locker = TXN_ID ( txn );
73 /* XXYYZ: need to check return value */
74 LOCK_ID ( bdb->bi_dbenv, &locker );
77 if (target != NULL && dn_match(&target->e_nname, entry_ndn)) {
78 /* we already have a LOCKED copy of the entry */
81 LDAP_LOG( BACK_BDB, DETAIL1,
82 "bdb_attribute: target is LOCKED (%s)\n", entry_ndn->bv_val, 0, 0 );
84 Debug( LDAP_DEBUG_ARGS,
85 "=> bdb_attribute: target is entry: \"%s\"\n",
86 entry_ndn->bv_val, 0, 0 );
92 /* can we find entry */
93 rc = bdb_dn2entry_r( be, NULL, entry_ndn, &e, NULL, 0, locker, &lock );
98 case DB_LOCK_DEADLOCK:
99 case DB_LOCK_NOTGRANTED:
106 LOCK_ID_FREE( bdb->bi_dbenv, locker );
108 return (rc != LDAP_BUSY) ? LDAP_OTHER : LDAP_BUSY;
112 LDAP_LOG( BACK_BDB, INFO,
113 "bdb_attribute: cannot find entry (%s)\n",
114 entry_ndn->bv_val, 0, 0 );
116 Debug( LDAP_DEBUG_ACL,
117 "=> bdb_attribute: cannot find entry: \"%s\"\n",
118 entry_ndn->bv_val, 0, 0 );
121 LOCK_ID_FREE( bdb->bi_dbenv, locker );
123 return LDAP_NO_SUCH_OBJECT;
127 LDAP_LOG( BACK_BDB, DETAIL1, "bdb_attribute: found entry (%s)\n",
128 entry_ndn->bv_val, 0, 0 );
130 Debug( LDAP_DEBUG_ACL,
131 "=> bdb_attribute: found entry: \"%s\"\n",
132 entry_ndn->bv_val, 0, 0 );
137 /* find attribute values */
138 if( is_entry_alias( e ) ) {
140 LDAP_LOG( BACK_BDB, INFO,
141 "bdb_attribute: entry (%s) is an alias\n", e->e_dn, 0, 0 );
143 Debug( LDAP_DEBUG_ACL,
144 "<= bdb_attribute: entry is an alias\n", 0, 0, 0 );
146 rc = LDAP_ALIAS_PROBLEM;
151 if( is_entry_referral( e ) ) {
153 LDAP_LOG( BACK_BDB, INFO,
154 "bdb_attribute: entry (%s) is a referral.\n", e->e_dn, 0, 0);
156 Debug( LDAP_DEBUG_ACL,
157 "<= bdb_attribute: entry is a referral\n", 0, 0, 0 );
163 if (conn != NULL && op != NULL
164 && access_allowed( be, conn, op, e, slap_schema.si_ad_entry,
165 NULL, ACL_READ, &acl_state ) == 0 )
167 rc = LDAP_INSUFFICIENT_ACCESS;
171 if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
173 LDAP_LOG( BACK_BDB, INFO,
174 "bdb_attribute: failed to find %s.\n", entry_at_name, 0, 0 );
176 Debug( LDAP_DEBUG_ACL,
177 "<= bdb_attribute: failed to find %s\n",
178 entry_at_name, 0, 0 );
180 rc = LDAP_NO_SUCH_ATTRIBUTE;
184 if (conn != NULL && op != NULL
185 && access_allowed( be, conn, op, e, entry_at, NULL, ACL_READ,
188 rc = LDAP_INSUFFICIENT_ACCESS;
192 for ( i = 0; attr->a_vals[i].bv_val != NULL; i++ ) {
196 v = (BerVarray) ch_malloc( sizeof(struct berval) * (i+1) );
198 for ( i=0, j=0; attr->a_vals[i].bv_val != NULL; i++ ) {
201 && access_allowed(be, conn, op, e, entry_at,
202 &attr->a_vals[i], ACL_READ, &acl_state ) == 0)
206 ber_dupbv( &v[j], &attr->a_vals[i] );
208 if( v[j].bv_val != NULL ) j++;
214 rc = LDAP_INSUFFICIENT_ACCESS;
225 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
229 LOCK_ID_FREE( bdb->bi_dbenv, locker );
233 LDAP_LOG( BACK_BDB, ENTRY, "bdb_attribute: rc=%d nvals=%d.\n", rc, j, 0 );
235 Debug( LDAP_DEBUG_TRACE,
236 "bdb_attribute: rc=%d nvals=%d\n",