]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/attribute.c
b15729333763065759240a4c71ddbf6b3cc09ff6
[openldap] / servers / slapd / back-ldbm / attribute.c
1 /* attribute.c - ldbm backend acl attribute routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/socket.h>
13 #include <ac/string.h>
14
15 #include "slap.h"
16 #include "back-ldbm.h"
17 #include "proto-back-ldbm.h"
18
19
20 /* return LDAP_SUCCESS IFF we can retrieve the attributes
21  * of entry with e_ndn
22  */
23 int
24 ldbm_back_attribute(
25         Backend *be,
26         Connection *conn,
27         Operation *op,
28         Entry   *target,
29         struct berval   *entry_ndn,
30         AttributeDescription *entry_at,
31         BerVarray *vals )
32 {
33         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
34         Entry        *e;
35         int          rc;
36         Attribute   *attr;
37         BerVarray v;
38         const char *entry_at_name = entry_at->ad_cname.bv_val;
39         struct berval *iv, *jv;
40         AccessControlState acl_state = ACL_STATE_INIT;
41
42 #ifdef NEW_LOGGING
43         LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
44                 "ldbm_back_attribute: gr dn: \"%s\"\n", entry_ndn->bv_val ));
45         LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
46                 "ldbm_back_attribute: at: \"%s\"\n", entry_at_name));
47         LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
48                 "ldbm_back_attribute: tr dn: \"%s\"\n",
49                 target ? target->e_ndn : "" ));
50 #else
51         Debug( LDAP_DEBUG_ARGS,
52                 "=> ldbm_back_attribute: gr dn: \"%s\"\n",
53                 entry_ndn->bv_val, 0, 0 ); 
54         Debug( LDAP_DEBUG_ARGS,
55                 "=> ldbm_back_attribute: at: \"%s\"\n", 
56                 entry_at_name, 0, 0 ); 
57
58         Debug( LDAP_DEBUG_ARGS,
59                 "=> ldbm_back_attribute: tr dn: \"%s\"\n",
60                 target ? target->e_ndn : "", 0, 0 ); 
61 #endif
62
63         if (target != NULL && dn_match( &target->e_nname, entry_ndn) ) {
64                 /* we already have a LOCKED copy of the entry */
65                 e = target;
66 #ifdef NEW_LOGGING
67                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
68                         "ldbm_back_attribute: target is LOCKED (%s)\n",
69                         entry_ndn->bv_val ));
70 #else
71                 Debug( LDAP_DEBUG_ARGS,
72                         "=> ldbm_back_attribute: target is entry: \"%s\"\n",
73                         entry_ndn->bv_val, 0, 0 );
74 #endif
75
76
77         } else {
78                 /* can we find entry with reader lock */
79                 if ((e = dn2entry_r(be, entry_ndn, NULL )) == NULL) {
80 #ifdef NEW_LOGGING
81                         LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
82                                 "ldbm_back_attribute: cannot find entry (%s)\n",
83                                 entry_ndn->bv_val ));
84 #else
85                         Debug( LDAP_DEBUG_ACL,
86                                 "=> ldbm_back_attribute: cannot find entry: \"%s\"\n",
87                                         entry_ndn->bv_val, 0, 0 ); 
88 #endif
89
90                         return LDAP_NO_SUCH_OBJECT; 
91                 }
92                 
93 #ifdef NEW_LOGGING
94                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
95                         "ldbm_back_attribute: found entry (%s)\n",
96                         entry_ndn->bv_val ));
97 #else
98                 Debug( LDAP_DEBUG_ACL,
99                         "=> ldbm_back_attribute: found entry: \"%s\"\n",
100                         entry_ndn->bv_val, 0, 0 ); 
101 #endif
102
103     }
104
105         /* find attribute values */
106
107         if( is_entry_alias( e ) ) {
108 #ifdef NEW_LOGGING
109                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
110                         "ldbm_back_attribute: entry (%s) is an alias\n", e->e_dn ));
111 #else
112                 Debug( LDAP_DEBUG_ACL,
113                         "<= ldbm_back_attribute: entry is an alias\n", 0, 0, 0 );
114 #endif
115
116                 rc = LDAP_ALIAS_PROBLEM;
117                 goto return_results;
118         }
119
120         if( is_entry_referral( e ) ) {
121 #ifdef NEW_LOGGING
122                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
123                         "ldbm_back_attribute: entry (%s) is a referral.\n", e->e_dn ));
124 #else
125                 Debug( LDAP_DEBUG_ACL,
126                         "<= ldbm_back_attribute: entry is an referral\n", 0, 0, 0 );
127 #endif
128
129                 rc = LDAP_REFERRAL;
130                 goto return_results;
131         }
132
133         if (conn != NULL && op != NULL
134                 && access_allowed( be, conn, op, e, slap_schema.si_ad_entry,
135                         NULL, ACL_READ, NULL ) == 0)
136         {
137                 rc = LDAP_INSUFFICIENT_ACCESS;
138                 goto return_results;
139         }
140
141         if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
142 #ifdef NEW_LOGGING
143                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
144                         "ldbm_back_attribute: failed to find %s.\n", entry_at_name ));
145 #else
146                 Debug( LDAP_DEBUG_ACL,
147                         "<= ldbm_back_attribute: failed to find %s\n",
148                         entry_at_name, 0, 0 ); 
149 #endif
150
151                 rc = LDAP_NO_SUCH_ATTRIBUTE;
152                 goto return_results;
153         }
154
155         if (conn != NULL && op != NULL
156                 && access_allowed( be, conn, op, e, entry_at, NULL,
157                         ACL_READ, &acl_state ) == 0)
158         {
159                 rc = LDAP_INSUFFICIENT_ACCESS;
160                 goto return_results;
161         }
162
163         for ( iv = attr->a_vals; iv->bv_val != NULL; iv++ ) {
164                 /* count them */
165         }
166
167         v = (BerVarray) ch_malloc( sizeof(struct berval) * ((iv - attr->a_vals)+1) );
168
169         for ( iv=attr->a_vals, jv=v; iv->bv_val; iv++ ) {
170                 if( conn != NULL
171                         && op != NULL
172                         && access_allowed( be, conn, op, e, entry_at,
173                                 iv, ACL_READ, &acl_state ) == 0)
174                 {
175                         continue;
176                 }
177                 ber_dupbv( jv, iv );
178
179                 if( jv->bv_val != NULL ) jv++;
180         }
181
182         if( jv == v ) {
183                 ch_free( v );
184                 *vals = NULL;
185                 rc = LDAP_INSUFFICIENT_ACCESS;
186         } else {
187                 jv->bv_val = NULL;
188                 *vals = v;
189                 rc = LDAP_SUCCESS;
190         }
191
192 return_results:
193         if( target != e ) {
194                 /* free entry and reader lock */
195                 cache_return_entry_r( &li->li_cache, e );                 
196         }
197
198 #ifdef NEW_LOGGING
199         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
200                    "ldbm_back_attribute: rc=%d nvals=%d.\n",
201                    rc, jv - v ));
202 #else
203         Debug( LDAP_DEBUG_TRACE,
204                 "ldbm_back_attribute: rc=%d nvals=%d\n",
205                 rc, jv - v, 0 ); 
206 #endif
207
208         return(rc);
209 }
210