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 const char *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) == 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",
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", entry_ndn ));
95 Debug( LDAP_DEBUG_ACL,
96 "=> ldbm_back_attribute: found entry: \"%s\"\n",
102 /* find attribute values */
104 if( is_entry_alias( e ) ) {
106 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
107 "ldbm_back_attribute: entry (%s) is an alias\n", e->e_dn ));
109 Debug( LDAP_DEBUG_ACL,
110 "<= ldbm_back_attribute: entry is an alias\n", 0, 0, 0 );
113 rc = LDAP_ALIAS_PROBLEM;
117 if( is_entry_referral( e ) ) {
119 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
120 "ldbm_back_attribute: entry (%s) is a referral.\n", e->e_dn ));
122 Debug( LDAP_DEBUG_ACL,
123 "<= ldbm_back_attribute: entry is an referral\n", 0, 0, 0 );
130 if (conn != NULL && op != NULL
131 && access_allowed(be, conn, op, e, slap_schema.si_ad_entry,
132 NULL, ACL_READ) == 0)
134 rc = LDAP_INSUFFICIENT_ACCESS;
138 if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
140 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
141 "ldbm_back_attribute: failed to find %s.\n", entry_at_name ));
143 Debug( LDAP_DEBUG_ACL,
144 "<= ldbm_back_attribute: failed to find %s\n",
145 entry_at_name, 0, 0 );
148 rc = LDAP_NO_SUCH_ATTRIBUTE;
152 if (conn != NULL && op != NULL
153 && access_allowed(be, conn, op, e, entry_at, NULL, ACL_READ) == 0)
155 rc = LDAP_INSUFFICIENT_ACCESS;
159 for ( i = 0; attr->a_vals[i] != NULL; i++ ) {
163 v = (struct berval **) ch_malloc( sizeof(struct berval *) * (i+1) );
165 for ( i=0, j=0; attr->a_vals[i] != NULL; i++ ) {
168 && access_allowed(be, conn, op, e, entry_at,
169 attr->a_vals[i], ACL_READ) == 0)
173 v[j] = ber_bvdup( attr->a_vals[i] );
175 if( v[j] != NULL ) j++;
181 rc = LDAP_INSUFFICIENT_ACCESS;
190 /* free entry and reader lock */
191 cache_return_entry_r( &li->li_cache, e );
195 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
196 "ldbm_back_attribute: rc=%d nvals=%d.\n",
199 Debug( LDAP_DEBUG_TRACE,
200 "ldbm_back_attribute: rc=%d nvals=%d\n",