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 bdbinfo *li = (struct bdbinfo *) be->be_private;
33 struct bdb_op_info *boi = (struct bdb_op_info *) op->o_private;
39 const char *entry_at_name = entry_at->ad_cname.bv_val;
42 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
43 "bdb_attribute: gr dn: \"%s\"\n", entry_ndn->bv_val ));
44 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
45 "bdb_attribute: at: \"%s\"\n", entry_at_name));
46 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
47 "bdb_attribute: tr dn: \"%s\"\n",
48 target ? target->e_ndn : "" ));
50 Debug( LDAP_DEBUG_ARGS,
51 "=> bdb_attribute: gr dn: \"%s\"\n",
52 entry_ndn->bv_val, 0, 0 );
53 Debug( LDAP_DEBUG_ARGS,
54 "=> bdb_attribute: at: \"%s\"\n",
55 entry_at_name, 0, 0 );
57 Debug( LDAP_DEBUG_ARGS,
58 "=> bdb_attribute: tr dn: \"%s\"\n",
59 target ? target->e_ndn : "", 0, 0 );
62 if( boi != NULL && be == boi->boi_bdb ) {
66 if (target != NULL && dn_match(&target->e_nname, entry_ndn)) {
67 /* we already have a LOCKED copy of the entry */
70 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
71 "bdb_attribute: target is LOCKED (%s)\n",
74 Debug( LDAP_DEBUG_ARGS,
75 "=> bdb_attribute: target is entry: \"%s\"\n",
76 entry_ndn->bv_val, 0, 0 );
81 /* can we find entry */
82 rc = bdb_dn2entry( be, txn, entry_ndn, &e, NULL, 0 );
95 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
96 "bdb_attribute: cannot find entry (%s)\n",
99 Debug( LDAP_DEBUG_ACL,
100 "=> bdb_attribute: cannot find entry: \"%s\"\n",
101 entry_ndn->bv_val, 0, 0 );
103 return LDAP_NO_SUCH_OBJECT;
107 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
108 "bdb_attribute: found entry (%s)\n",
109 entry_ndn->bv_val ));
111 Debug( LDAP_DEBUG_ACL,
112 "=> bdb_attribute: found entry: \"%s\"\n",
113 entry_ndn->bv_val, 0, 0 );
117 /* find attribute values */
118 if( is_entry_alias( e ) ) {
120 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
121 "bdb_attribute: entry (%s) is an alias\n", e->e_dn ));
123 Debug( LDAP_DEBUG_ACL,
124 "<= bdb_attribute: entry is an alias\n", 0, 0, 0 );
126 rc = LDAP_ALIAS_PROBLEM;
130 if( is_entry_referral( e ) ) {
132 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
133 "bdb_attribute: entry (%s) is a referral.\n", e->e_dn ));
135 Debug( LDAP_DEBUG_ACL,
136 "<= bdb_attribute: entry is a referral\n", 0, 0, 0 );
142 if (conn != NULL && op != NULL
143 && access_allowed(be, conn, op, e, slap_schema.si_ad_entry,
144 NULL, ACL_READ) == 0)
146 rc = LDAP_INSUFFICIENT_ACCESS;
150 if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
152 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
153 "bdb_attribute: failed to find %s.\n", entry_at_name ));
155 Debug( LDAP_DEBUG_ACL,
156 "<= bdb_attribute: failed to find %s\n",
157 entry_at_name, 0, 0 );
159 rc = LDAP_NO_SUCH_ATTRIBUTE;
163 if (conn != NULL && op != NULL
164 && access_allowed(be, conn, op, e, entry_at, NULL, ACL_READ) == 0)
166 rc = LDAP_INSUFFICIENT_ACCESS;
170 for ( i = 0; attr->a_vals[i].bv_val != NULL; i++ ) {
174 v = (BerVarray) ch_malloc( sizeof(struct berval) * (i+1) );
176 for ( i=0, j=0; attr->a_vals[i].bv_val != NULL; i++ ) {
179 && access_allowed(be, conn, op, e, entry_at,
180 &attr->a_vals[i], ACL_READ) == 0)
184 ber_dupbv( &v[j], &attr->a_vals[i] );
186 if( v[j].bv_val != NULL ) j++;
192 rc = LDAP_INSUFFICIENT_ACCESS;
203 bdb_entry_return( be, e );
207 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
208 "bdb_attribute: rc=%d nvals=%d.\n",
211 Debug( LDAP_DEBUG_TRACE,
212 "bdb_attribute: rc=%d nvals=%d\n",