1 /* attribute.c - ldbm backend acl attribute routine */
4 * Copyright 1998-2000 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;
42 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
43 "ldbm_back_attribute: gr dn: \"%s\"\n", entry_ndn ));
44 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
45 "ldbm_back_attribute: at: \"%s\"\n", entry_at_name));
46 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
47 "ldbm_back_attribute: tr dn: \"%s\"\n",
48 target ? target->e_ndn : "" ));
50 Debug( LDAP_DEBUG_ARGS,
51 "=> ldbm_back_attribute: gr dn: \"%s\"\n",
53 Debug( LDAP_DEBUG_ARGS,
54 "=> ldbm_back_attribute: at: \"%s\"\n",
55 entry_at_name, 0, 0 );
57 Debug( LDAP_DEBUG_ARGS,
58 "=> ldbm_back_attribute: tr dn: \"%s\"\n",
59 target ? target->e_ndn : "", 0, 0 );
62 if (target != NULL && strcmp(target->e_ndn, entry_ndn->bv_val) == 0) {
63 /* we already have a LOCKED copy of the entry */
66 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
67 "ldbm_back_attribute: target is LOCKED (%s)\n",
70 Debug( LDAP_DEBUG_ARGS,
71 "=> ldbm_back_attribute: target is entry: \"%s\"\n",
72 entry_ndn->bv_val, 0, 0 );
77 /* can we find entry with reader lock */
78 if ((e = dn2entry_r(be, entry_ndn, NULL )) == NULL) {
80 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
81 "ldbm_back_attribute: cannot find entry (%s)\n",
84 Debug( LDAP_DEBUG_ACL,
85 "=> ldbm_back_attribute: cannot find entry: \"%s\"\n",
89 return LDAP_NO_SUCH_OBJECT;
93 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
94 "ldbm_back_attribute: found entry (%s)\n",
97 Debug( LDAP_DEBUG_ACL,
98 "=> ldbm_back_attribute: found entry: \"%s\"\n",
99 entry_ndn->bv_val, 0, 0 );
104 /* find attribute values */
106 if( is_entry_alias( e ) ) {
108 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
109 "ldbm_back_attribute: entry (%s) is an alias\n", e->e_dn ));
111 Debug( LDAP_DEBUG_ACL,
112 "<= ldbm_back_attribute: entry is an alias\n", 0, 0, 0 );
115 rc = LDAP_ALIAS_PROBLEM;
119 if( is_entry_referral( e ) ) {
121 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
122 "ldbm_back_attribute: entry (%s) is a referral.\n", e->e_dn ));
124 Debug( LDAP_DEBUG_ACL,
125 "<= ldbm_back_attribute: entry is an referral\n", 0, 0, 0 );
132 if (conn != NULL && op != NULL
133 && access_allowed(be, conn, op, e, slap_schema.si_ad_entry,
134 NULL, ACL_READ) == 0)
136 rc = LDAP_INSUFFICIENT_ACCESS;
140 if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
142 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
143 "ldbm_back_attribute: failed to find %s.\n", entry_at_name ));
145 Debug( LDAP_DEBUG_ACL,
146 "<= ldbm_back_attribute: failed to find %s\n",
147 entry_at_name, 0, 0 );
150 rc = LDAP_NO_SUCH_ATTRIBUTE;
154 if (conn != NULL && op != NULL
155 && access_allowed(be, conn, op, e, entry_at, NULL, ACL_READ) == 0)
157 rc = LDAP_INSUFFICIENT_ACCESS;
161 for ( i = 0; attr->a_vals[i].bv_val != NULL; i++ ) {
165 v = (BVarray) ch_malloc( sizeof(struct berval) * (i+1) );
167 for ( iv=attr->a_vals, jv=v; iv->bv_val; iv++ ) {
170 && access_allowed(be, conn, op, e, entry_at,
177 if( jv->bv_val != NULL ) jv++;
183 rc = LDAP_INSUFFICIENT_ACCESS;
192 /* free entry and reader lock */
193 cache_return_entry_r( &li->li_cache, e );
197 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
198 "ldbm_back_attribute: rc=%d nvals=%d.\n",
201 Debug( LDAP_DEBUG_TRACE,
202 "ldbm_back_attribute: rc=%d nvals=%d\n",