]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/attribute.c
Every quick mod to use a struct berval for e_dn/e_ndn. No bv_len yet.
[openldap] / servers / slapd / back-ldbm / attribute.c
1 /* attribute.c - ldbm backend acl attribute routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 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         const char      *entry_ndn,
30         AttributeDescription *entry_at,
31         struct berval ***vals )
32 {
33         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
34         Entry        *e;
35         int          i, j, rc;
36         Attribute   *attr;
37         struct berval **v;
38         const char *entry_at_name = entry_at->ad_cname.bv_val;
39
40 #ifdef NEW_LOGGING
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 : "" ));
48 #else
49         Debug( LDAP_DEBUG_ARGS,
50                 "=> ldbm_back_attribute: gr dn: \"%s\"\n",
51                 entry_ndn, 0, 0 ); 
52         Debug( LDAP_DEBUG_ARGS,
53                 "=> ldbm_back_attribute: at: \"%s\"\n", 
54                 entry_at_name, 0, 0 ); 
55
56         Debug( LDAP_DEBUG_ARGS,
57                 "=> ldbm_back_attribute: tr dn: \"%s\"\n",
58                 target ? target->e_ndn : "", 0, 0 ); 
59 #endif
60
61         if (target != NULL && strcmp(target->e_ndn, entry_ndn) == 0) {
62                 /* we already have a LOCKED copy of the entry */
63                 e = target;
64 #ifdef NEW_LOGGING
65                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
66                         "ldbm_back_attribute: target is LOCKED (%s)\n",
67                         entry_ndn ));
68 #else
69                 Debug( LDAP_DEBUG_ARGS,
70                         "=> ldbm_back_attribute: target is entry: \"%s\"\n",
71                         entry_ndn, 0, 0 );
72 #endif
73
74
75         } else {
76                 /* can we find entry with reader lock */
77                 if ((e = dn2entry_r(be, entry_ndn, NULL )) == NULL) {
78 #ifdef NEW_LOGGING
79                         LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
80                                 "ldbm_back_attribute: cannot find entry (%s)\n",
81                                 entry_ndn ));
82 #else
83                         Debug( LDAP_DEBUG_ACL,
84                                 "=> ldbm_back_attribute: cannot find entry: \"%s\"\n",
85                                         entry_ndn, 0, 0 ); 
86 #endif
87
88                         return LDAP_NO_SUCH_OBJECT; 
89                 }
90                 
91 #ifdef NEW_LOGGING
92                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
93                         "ldbm_back_attribute: found entry (%s)\n", entry_ndn ));
94 #else
95                 Debug( LDAP_DEBUG_ACL,
96                         "=> ldbm_back_attribute: found entry: \"%s\"\n",
97                         entry_ndn, 0, 0 ); 
98 #endif
99
100     }
101
102         /* find attribute values */
103         
104         if( is_entry_alias( e ) ) {
105 #ifdef NEW_LOGGING
106                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
107                            "ldbm_back_attribute: entry (%s) is an alias\n", e->e_dn ));
108 #else
109                 Debug( LDAP_DEBUG_ACL,
110                         "<= ldbm_back_attribute: entry is an alias\n", 0, 0, 0 );
111 #endif
112
113                 rc = LDAP_ALIAS_PROBLEM;
114                 goto return_results;
115         }
116
117         if( is_entry_referral( e ) ) {
118 #ifdef NEW_LOGGING
119                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
120                            "ldbm_back_attribute: entry (%s) is a referral.\n", e->e_dn ));
121 #else
122                 Debug( LDAP_DEBUG_ACL,
123                         "<= ldbm_back_attribute: entry is an referral\n", 0, 0, 0 );
124 #endif
125
126                 rc = LDAP_REFERRAL;
127                 goto return_results;
128         }
129
130         if (conn != NULL && op != NULL
131                 && access_allowed(be, conn, op, e, slap_schema.si_ad_entry,
132                         NULL, ACL_READ) == 0)
133         {
134                 rc = LDAP_INSUFFICIENT_ACCESS;
135                 goto return_results;
136         }
137
138         if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
139 #ifdef NEW_LOGGING
140                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
141                            "ldbm_back_attribute: failed to find %s.\n", entry_at_name ));
142 #else
143                 Debug( LDAP_DEBUG_ACL,
144                         "<= ldbm_back_attribute: failed to find %s\n",
145                         entry_at_name, 0, 0 ); 
146 #endif
147
148                 rc = LDAP_NO_SUCH_ATTRIBUTE;
149                 goto return_results;
150         }
151
152         if (conn != NULL && op != NULL
153                 && access_allowed(be, conn, op, e, entry_at, NULL, ACL_READ) == 0)
154         {
155                 rc = LDAP_INSUFFICIENT_ACCESS;
156                 goto return_results;
157         }
158
159         for ( i = 0; attr->a_vals[i] != NULL; i++ ) {
160                 /* count them */
161         }
162
163         v = (struct berval **) ch_malloc( sizeof(struct berval *) * (i+1) );
164
165         for ( i=0, j=0; attr->a_vals[i] != NULL; i++ ) {
166                 if( conn != NULL
167                         && op != NULL
168                         && access_allowed(be, conn, op, e, entry_at,
169                                 attr->a_vals[i], ACL_READ) == 0)
170                 {
171                         continue;
172                 }
173                 v[j] = ber_bvdup( attr->a_vals[i] );
174
175                 if( v[j] != NULL ) j++;
176         }
177
178         if( j == 0 ) {
179                 ch_free( v );
180                 *vals = NULL;
181                 rc = LDAP_INSUFFICIENT_ACCESS;
182         } else {
183                 v[j] = NULL;
184                 *vals = v;
185                 rc = LDAP_SUCCESS;
186         }
187
188 return_results:
189         if( target != e ) {
190                 /* free entry and reader lock */
191                 cache_return_entry_r( &li->li_cache, e );                 
192         }
193
194 #ifdef NEW_LOGGING
195         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
196                    "ldbm_back_attribute: rc=%d nvals=%d.\n",
197                    rc, j ));
198 #else
199         Debug( LDAP_DEBUG_TRACE,
200                 "ldbm_back_attribute: rc=%d nvals=%d\n",
201                 rc, j, 0 ); 
202 #endif
203
204         return(rc);
205 }
206