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,
31 struct berval ***vals )
33 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
38 const char *entry_at_name = entry_at->ad_cname.bv_val;
41 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
42 "ldbm_back_attribute: gr dn: \"%s\"\n", entry_ndn ));
43 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
44 "ldbm_back_attribute: at: \"%s\"\n", entry_at_name));
45 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
46 "ldbm_back_attribute: tr dn: \"%s\"\n",
47 target ? target->e_ndn : "" ));
49 Debug( LDAP_DEBUG_ARGS,
50 "=> ldbm_back_attribute: gr dn: \"%s\"\n",
52 Debug( LDAP_DEBUG_ARGS,
53 "=> ldbm_back_attribute: at: \"%s\"\n",
54 entry_at_name, 0, 0 );
56 Debug( LDAP_DEBUG_ARGS,
57 "=> ldbm_back_attribute: tr dn: \"%s\"\n",
58 target ? target->e_ndn : "", 0, 0 );
61 if (target != NULL && strcmp(target->e_ndn, entry_ndn->bv_val) == 0) {
62 /* we already have a LOCKED copy of the entry */
65 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
66 "ldbm_back_attribute: target is LOCKED (%s)\n",
69 Debug( LDAP_DEBUG_ARGS,
70 "=> ldbm_back_attribute: target is entry: \"%s\"\n",
71 entry_ndn->bv_val, 0, 0 );
76 /* can we find entry with reader lock */
77 if ((e = dn2entry_r(be, entry_ndn, NULL )) == NULL) {
79 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
80 "ldbm_back_attribute: cannot find entry (%s)\n",
83 Debug( LDAP_DEBUG_ACL,
84 "=> ldbm_back_attribute: cannot find entry: \"%s\"\n",
88 return LDAP_NO_SUCH_OBJECT;
92 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
93 "ldbm_back_attribute: found entry (%s)\n",
96 Debug( LDAP_DEBUG_ACL,
97 "=> ldbm_back_attribute: found entry: \"%s\"\n",
98 entry_ndn->bv_val, 0, 0 );
103 /* find attribute values */
105 if( is_entry_alias( e ) ) {
107 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
108 "ldbm_back_attribute: entry (%s) is an alias\n", e->e_dn ));
110 Debug( LDAP_DEBUG_ACL,
111 "<= ldbm_back_attribute: entry is an alias\n", 0, 0, 0 );
114 rc = LDAP_ALIAS_PROBLEM;
118 if( is_entry_referral( e ) ) {
120 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
121 "ldbm_back_attribute: entry (%s) is a referral.\n", e->e_dn ));
123 Debug( LDAP_DEBUG_ACL,
124 "<= ldbm_back_attribute: entry is an referral\n", 0, 0, 0 );
131 if (conn != NULL && op != NULL
132 && access_allowed(be, conn, op, e, slap_schema.si_ad_entry,
133 NULL, ACL_READ) == 0)
135 rc = LDAP_INSUFFICIENT_ACCESS;
139 if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
141 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
142 "ldbm_back_attribute: failed to find %s.\n", entry_at_name ));
144 Debug( LDAP_DEBUG_ACL,
145 "<= ldbm_back_attribute: failed to find %s\n",
146 entry_at_name, 0, 0 );
149 rc = LDAP_NO_SUCH_ATTRIBUTE;
153 if (conn != NULL && op != NULL
154 && access_allowed(be, conn, op, e, entry_at, NULL, ACL_READ) == 0)
156 rc = LDAP_INSUFFICIENT_ACCESS;
160 for ( i = 0; attr->a_vals[i] != NULL; i++ ) {
164 v = (struct berval **) ch_malloc( sizeof(struct berval *) * (i+1) );
166 for ( i=0, j=0; attr->a_vals[i] != NULL; i++ ) {
169 && access_allowed(be, conn, op, e, entry_at,
170 attr->a_vals[i], ACL_READ) == 0)
174 v[j] = ber_bvdup( attr->a_vals[i] );
176 if( v[j] != NULL ) j++;
182 rc = LDAP_INSUFFICIENT_ACCESS;
191 /* free entry and reader lock */
192 cache_return_entry_r( &li->li_cache, e );
196 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
197 "ldbm_back_attribute: rc=%d nvals=%d.\n",
200 Debug( LDAP_DEBUG_TRACE,
201 "ldbm_back_attribute: rc=%d nvals=%d\n",