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;
43 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
44 "ldbm_back_attribute: gr dn: \"%s\"\n", entry_ndn->bv_val ));
45 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
46 "ldbm_back_attribute: at: \"%s\"\n", entry_at_name));
47 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
48 "ldbm_back_attribute: tr dn: \"%s\"\n",
49 target ? target->e_ndn : "" ));
51 Debug( LDAP_DEBUG_ARGS,
52 "=> ldbm_back_attribute: gr dn: \"%s\"\n",
53 entry_ndn->bv_val, 0, 0 );
54 Debug( LDAP_DEBUG_ARGS,
55 "=> ldbm_back_attribute: at: \"%s\"\n",
56 entry_at_name, 0, 0 );
58 Debug( LDAP_DEBUG_ARGS,
59 "=> ldbm_back_attribute: tr dn: \"%s\"\n",
60 target ? target->e_ndn : "", 0, 0 );
63 if (target != NULL && dn_match( &target->e_nname, entry_ndn) ) {
64 /* we already have a LOCKED copy of the entry */
67 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
68 "ldbm_back_attribute: target is LOCKED (%s)\n",
71 Debug( LDAP_DEBUG_ARGS,
72 "=> ldbm_back_attribute: target is entry: \"%s\"\n",
73 entry_ndn->bv_val, 0, 0 );
78 /* can we find entry with reader lock */
79 if ((e = dn2entry_r(be, entry_ndn, NULL )) == NULL) {
81 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
82 "ldbm_back_attribute: cannot find entry (%s)\n",
85 Debug( LDAP_DEBUG_ACL,
86 "=> ldbm_back_attribute: cannot find entry: \"%s\"\n",
87 entry_ndn->bv_val, 0, 0 );
90 return LDAP_NO_SUCH_OBJECT;
94 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
95 "ldbm_back_attribute: found entry (%s)\n",
98 Debug( LDAP_DEBUG_ACL,
99 "=> ldbm_back_attribute: found entry: \"%s\"\n",
100 entry_ndn->bv_val, 0, 0 );
105 /* find attribute values */
107 if( is_entry_alias( e ) ) {
109 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
110 "ldbm_back_attribute: entry (%s) is an alias\n", e->e_dn ));
112 Debug( LDAP_DEBUG_ACL,
113 "<= ldbm_back_attribute: entry is an alias\n", 0, 0, 0 );
116 rc = LDAP_ALIAS_PROBLEM;
120 if( is_entry_referral( e ) ) {
122 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
123 "ldbm_back_attribute: entry (%s) is a referral.\n", e->e_dn ));
125 Debug( LDAP_DEBUG_ACL,
126 "<= ldbm_back_attribute: entry is an referral\n", 0, 0, 0 );
133 if (conn != NULL && op != NULL
134 && access_allowed( be, conn, op, e, slap_schema.si_ad_entry,
135 NULL, ACL_READ, NULL ) == 0)
137 rc = LDAP_INSUFFICIENT_ACCESS;
141 if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
143 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
144 "ldbm_back_attribute: failed to find %s.\n", entry_at_name ));
146 Debug( LDAP_DEBUG_ACL,
147 "<= ldbm_back_attribute: failed to find %s\n",
148 entry_at_name, 0, 0 );
151 rc = LDAP_NO_SUCH_ATTRIBUTE;
155 if (conn != NULL && op != NULL
156 && access_allowed( be, conn, op, e, entry_at, NULL,
157 ACL_READ, &acl_state ) == 0)
159 rc = LDAP_INSUFFICIENT_ACCESS;
163 for ( iv = attr->a_vals; iv->bv_val != NULL; iv++ ) {
167 v = (BerVarray) ch_malloc( sizeof(struct berval) * ((iv - attr->a_vals)+1) );
169 for ( iv=attr->a_vals, jv=v; iv->bv_val; iv++ ) {
172 && access_allowed( be, conn, op, e, entry_at,
173 iv, ACL_READ, &acl_state ) == 0)
179 if( jv->bv_val != NULL ) jv++;
185 rc = LDAP_INSUFFICIENT_ACCESS;
194 /* free entry and reader lock */
195 cache_return_entry_r( &li->li_cache, e );
199 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
200 "ldbm_back_attribute: rc=%d nvals=%d.\n",
203 Debug( LDAP_DEBUG_TRACE,
204 "ldbm_back_attribute: rc=%d nvals=%d\n",