1 /* attribute.c - bdb 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>
17 #include "proto-bdb.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 bdbinfo *li = (struct bdbinfo *) be->be_private;
38 const char *entry_at_name = entry_at->ad_cname.bv_val;
41 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
42 "bdb_attribute: gr dn: \"%s\"\n", entry_ndn ));
43 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
44 "bdb_attribute: at: \"%s\"\n", entry_at_name));
45 LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
46 "bdb_attribute: tr dn: \"%s\"\n",
47 target ? target->e_ndn : "" ));
49 Debug( LDAP_DEBUG_ARGS,
50 "=> bdb_attribute: gr dn: \"%s\"\n",
52 Debug( LDAP_DEBUG_ARGS,
53 "=> bdb_attribute: at: \"%s\"\n",
54 entry_at_name, 0, 0 );
56 Debug( LDAP_DEBUG_ARGS,
57 "=> bdb_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 "bdb_attribute: target is LOCKED (%s)\n",
69 Debug( LDAP_DEBUG_ARGS,
70 "=> bdb_attribute: target is entry: \"%s\"\n",
76 /* can we find entry */
77 rc = bdb_dn2entry( be, NULL, entry_ndn, &e, NULL, 0 );
87 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
88 "bdb_attribute: cannot find entry (%s)\n",
91 Debug( LDAP_DEBUG_ACL,
92 "=> bdb_attribute: cannot find entry: \"%s\"\n",
95 return LDAP_NO_SUCH_OBJECT;
99 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
100 "bdb_attribute: found entry (%s)\n", e_ndn ));
102 Debug( LDAP_DEBUG_ACL,
103 "=> bdb_attribute: found entry: \"%s\"\n",
108 /* find attribute values */
109 if( is_entry_alias( e ) ) {
111 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
112 "bdb_attribute: entry (%s) is an alias\n", e->e_dn ));
114 Debug( LDAP_DEBUG_ACL,
115 "<= bdb_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 "bdb_attribute: entry (%s) is a referral.\n", e->e_dn ));
126 Debug( LDAP_DEBUG_ACL,
127 "<= bdb_attribute: entry is a 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) == 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 "bdb_attribute: failed to find %s.\n", entry_at_name ));
146 Debug( LDAP_DEBUG_ACL,
147 "<= bdb_attribute: failed to find %s\n",
148 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] != NULL; i++ ) {
165 v = (struct berval **) ch_malloc( sizeof(struct berval *) * (i+1) );
167 for ( i=0, j=0; attr->a_vals[i] != NULL; i++ ) {
170 && access_allowed(be, conn, op, e, entry_at,
171 attr->a_vals[i], ACL_READ) == 0)
175 v[j] = ber_bvdup( attr->a_vals[i] );
177 if( v[j] != NULL ) j++;
183 rc = LDAP_INSUFFICIENT_ACCESS;
193 bdb_entry_return( be, e );
197 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
198 "bdb_attribute: rc=%d nvals=%d.\n",
201 Debug( LDAP_DEBUG_TRACE,
202 "bdb_attribute: rc=%d nvals=%d\n",