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"
19 /* return LDAP_SUCCESS IFF we can retrieve the attributes
28 struct berval *entry_ndn,
29 AttributeDescription *entry_at,
32 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
37 const char *entry_at_name = entry_at->ad_cname.bv_val;
38 struct berval *iv, *jv;
39 AccessControlState acl_state = ACL_STATE_INIT;
43 LDAP_LOG( BACK_LDBM, ARGS,
44 "ldbm_back_attribute: gr dn: \"%s\"\n", entry_ndn->bv_val, 0, 0 );
45 LDAP_LOG( BACK_LDBM, ARGS,
46 "ldbm_back_attribute: at: \"%s\"\n", entry_at_name, 0, 0);
47 LDAP_LOG( BACK_LDBM, ARGS, "ldbm_back_attribute: tr dn: \"%s\"\n",
48 target ? target->e_ndn : "", 0, 0 );
50 Debug( LDAP_DEBUG_ARGS,
51 "=> ldbm_back_attribute: gr dn: \"%s\"\n",
52 entry_ndn->bv_val, 0, 0 );
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 && dn_match( &target->e_nname, entry_ndn) ) {
63 /* we already have a LOCKED copy of the entry */
66 LDAP_LOG( BACK_LDBM, DETAIL1,
67 "ldbm_back_attribute: target is LOCKED (%s)\n",
68 entry_ndn->bv_val, 0, 0);
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( BACK_LDBM, INFO,
81 "ldbm_back_attribute: cannot find entry (%s)\n",
82 entry_ndn->bv_val, 0, 0 );
84 Debug( LDAP_DEBUG_ACL,
85 "=> ldbm_back_attribute: cannot find entry: \"%s\"\n",
86 entry_ndn->bv_val, 0, 0 );
89 return LDAP_NO_SUCH_OBJECT;
93 LDAP_LOG( BACK_LDBM, DETAIL1,
94 "ldbm_back_attribute: found entry (%s)\n", entry_ndn->bv_val, 0, 0);
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( BACK_LDBM, INFO,
108 "ldbm_back_attribute: entry (%s) is an alias\n", e->e_dn, 0, 0 );
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( BACK_LDBM, INFO,
121 "ldbm_back_attribute: entry (%s) is a referral.\n", e->e_dn, 0, 0 );
123 Debug( LDAP_DEBUG_ACL,
124 "<= ldbm_back_attribute: entry is an referral\n", 0, 0, 0 );
131 if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
133 LDAP_LOG( BACK_LDBM, INFO,
134 "ldbm_back_attribute: failed to find %s.\n", entry_at_name, 0, 0 );
136 Debug( LDAP_DEBUG_ACL,
137 "<= ldbm_back_attribute: failed to find %s\n",
138 entry_at_name, 0, 0 );
141 rc = LDAP_NO_SUCH_ATTRIBUTE;
145 if (conn != NULL && op != NULL
146 && access_allowed( be, conn, op, e, entry_at, NULL,
147 ACL_AUTH, &acl_state ) == 0)
149 rc = LDAP_INSUFFICIENT_ACCESS;
153 for ( iv = attr->a_vals; iv->bv_val != NULL; iv++ ) {
157 v = (BerVarray) ch_malloc( sizeof(struct berval) * ((iv - attr->a_vals)+1) );
159 for ( iv=attr->a_vals, jv=v; iv->bv_val; iv++ ) {
162 && access_allowed( be, conn, op, e, entry_at,
163 iv, ACL_AUTH, &acl_state ) == 0)
169 if( jv->bv_val != NULL ) jv++;
177 rc = LDAP_INSUFFICIENT_ACCESS;
186 /* free entry and reader lock */
187 cache_return_entry_r( &li->li_cache, e );
191 LDAP_LOG( BACK_LDBM, ENTRY,
192 "ldbm_back_attribute: rc=%d nvals=%d.\n", rc, nvals, 0 );
194 Debug( LDAP_DEBUG_TRACE,
195 "ldbm_back_attribute: rc=%d nvals=%d\n",