1 /* attribute.c - ldbm 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>
16 #include "back-ldbm.h"
17 #include "proto-back-ldbm.h"
20 /* return LDAP_SUCCESS IFF we can retrieve the attributes
29 struct berval *entry_ndn,
30 AttributeDescription *entry_at,
33 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
38 const char *entry_at_name = entry_at->ad_cname.bv_val;
39 struct berval *iv, *jv;
40 AccessControlState acl_state = ACL_STATE_INIT;
44 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
45 "ldbm_back_attribute: gr dn: \"%s\"\n", entry_ndn->bv_val ));
46 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
47 "ldbm_back_attribute: at: \"%s\"\n", entry_at_name));
48 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
49 "ldbm_back_attribute: tr dn: \"%s\"\n",
50 target ? target->e_ndn : "" ));
52 Debug( LDAP_DEBUG_ARGS,
53 "=> ldbm_back_attribute: gr dn: \"%s\"\n",
54 entry_ndn->bv_val, 0, 0 );
55 Debug( LDAP_DEBUG_ARGS,
56 "=> ldbm_back_attribute: at: \"%s\"\n",
57 entry_at_name, 0, 0 );
59 Debug( LDAP_DEBUG_ARGS,
60 "=> ldbm_back_attribute: tr dn: \"%s\"\n",
61 target ? target->e_ndn : "", 0, 0 );
64 if (target != NULL && dn_match( &target->e_nname, entry_ndn) ) {
65 /* we already have a LOCKED copy of the entry */
68 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
69 "ldbm_back_attribute: target is LOCKED (%s)\n",
72 Debug( LDAP_DEBUG_ARGS,
73 "=> ldbm_back_attribute: target is entry: \"%s\"\n",
74 entry_ndn->bv_val, 0, 0 );
79 /* can we find entry with reader lock */
80 if ((e = dn2entry_r(be, entry_ndn, NULL )) == NULL) {
82 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
83 "ldbm_back_attribute: cannot find entry (%s)\n",
86 Debug( LDAP_DEBUG_ACL,
87 "=> ldbm_back_attribute: cannot find entry: \"%s\"\n",
88 entry_ndn->bv_val, 0, 0 );
91 return LDAP_NO_SUCH_OBJECT;
95 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
96 "ldbm_back_attribute: found entry (%s)\n",
99 Debug( LDAP_DEBUG_ACL,
100 "=> ldbm_back_attribute: found entry: \"%s\"\n",
101 entry_ndn->bv_val, 0, 0 );
106 /* find attribute values */
108 if( is_entry_alias( e ) ) {
110 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
111 "ldbm_back_attribute: entry (%s) is an alias\n", e->e_dn ));
113 Debug( LDAP_DEBUG_ACL,
114 "<= ldbm_back_attribute: entry is an alias\n", 0, 0, 0 );
117 rc = LDAP_ALIAS_PROBLEM;
121 if( is_entry_referral( e ) ) {
123 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
124 "ldbm_back_attribute: entry (%s) is a referral.\n", e->e_dn ));
126 Debug( LDAP_DEBUG_ACL,
127 "<= ldbm_back_attribute: entry is an referral\n", 0, 0, 0 );
134 if (conn != NULL && op != NULL
135 && access_allowed( be, conn, op, e, slap_schema.si_ad_entry,
136 NULL, ACL_READ, NULL ) == 0)
138 rc = LDAP_INSUFFICIENT_ACCESS;
142 if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
144 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
145 "ldbm_back_attribute: failed to find %s.\n", entry_at_name ));
147 Debug( LDAP_DEBUG_ACL,
148 "<= ldbm_back_attribute: failed to find %s\n",
149 entry_at_name, 0, 0 );
152 rc = LDAP_NO_SUCH_ATTRIBUTE;
156 if (conn != NULL && op != NULL
157 && access_allowed( be, conn, op, e, entry_at, NULL,
158 ACL_READ, &acl_state ) == 0)
160 rc = LDAP_INSUFFICIENT_ACCESS;
164 for ( iv = attr->a_vals; iv->bv_val != NULL; iv++ ) {
168 v = (BerVarray) ch_malloc( sizeof(struct berval) * ((iv - attr->a_vals)+1) );
170 for ( iv=attr->a_vals, jv=v; iv->bv_val; iv++ ) {
173 && access_allowed( be, conn, op, e, entry_at,
174 iv, ACL_READ, &acl_state ) == 0)
180 if( jv->bv_val != NULL ) jv++;
188 rc = LDAP_INSUFFICIENT_ACCESS;
197 /* free entry and reader lock */
198 cache_return_entry_r( &li->li_cache, e );
202 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
203 "ldbm_back_attribute: rc=%d nvals=%d.\n",
206 Debug( LDAP_DEBUG_TRACE,
207 "ldbm_back_attribute: rc=%d nvals=%d\n",