]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/attribute.c
Remove abandon cruft
[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         struct berval   *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->bv_val) == 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->bv_val ));
68 #else
69                 Debug( LDAP_DEBUG_ARGS,
70                         "=> ldbm_back_attribute: target is entry: \"%s\"\n",
71                         entry_ndn->bv_val, 0, 0 );
72 #endif
73
74
75         } else {
76                 /* can we find entry with reader lock */
77                 if ((e = dn2entry_r(be, entry_ndn->bv_val, 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",
94                         entry_ndn->bv_val ));
95 #else
96                 Debug( LDAP_DEBUG_ACL,
97                         "=> ldbm_back_attribute: found entry: \"%s\"\n",
98                         entry_ndn->bv_val, 0, 0 ); 
99 #endif
100
101     }
102
103         /* find attribute values */
104         
105         if( is_entry_alias( e ) ) {
106 #ifdef NEW_LOGGING
107                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
108                         "ldbm_back_attribute: entry (%s) is an alias\n", e->e_dn ));
109 #else
110                 Debug( LDAP_DEBUG_ACL,
111                         "<= ldbm_back_attribute: entry is an alias\n", 0, 0, 0 );
112 #endif
113
114                 rc = LDAP_ALIAS_PROBLEM;
115                 goto return_results;
116         }
117
118         if( is_entry_referral( e ) ) {
119 #ifdef NEW_LOGGING
120                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
121                         "ldbm_back_attribute: entry (%s) is a referral.\n", e->e_dn ));
122 #else
123                 Debug( LDAP_DEBUG_ACL,
124                         "<= ldbm_back_attribute: entry is an referral\n", 0, 0, 0 );
125 #endif
126
127                 rc = LDAP_REFERRAL;
128                 goto return_results;
129         }
130
131         if (conn != NULL && op != NULL
132                 && access_allowed(be, conn, op, e, slap_schema.si_ad_entry,
133                         NULL, ACL_READ) == 0)
134         {
135                 rc = LDAP_INSUFFICIENT_ACCESS;
136                 goto return_results;
137         }
138
139         if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
140 #ifdef NEW_LOGGING
141                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
142                         "ldbm_back_attribute: failed to find %s.\n", entry_at_name ));
143 #else
144                 Debug( LDAP_DEBUG_ACL,
145                         "<= ldbm_back_attribute: failed to find %s\n",
146                         entry_at_name, 0, 0 ); 
147 #endif
148
149                 rc = LDAP_NO_SUCH_ATTRIBUTE;
150                 goto return_results;
151         }
152
153         if (conn != NULL && op != NULL
154                 && access_allowed(be, conn, op, e, entry_at, NULL, ACL_READ) == 0)
155         {
156                 rc = LDAP_INSUFFICIENT_ACCESS;
157                 goto return_results;
158         }
159
160         for ( i = 0; attr->a_vals[i] != NULL; i++ ) {
161                 /* count them */
162         }
163
164         v = (struct berval **) ch_malloc( sizeof(struct berval *) * (i+1) );
165
166         for ( i=0, j=0; attr->a_vals[i] != NULL; i++ ) {
167                 if( conn != NULL
168                         && op != NULL
169                         && access_allowed(be, conn, op, e, entry_at,
170                                 attr->a_vals[i], ACL_READ) == 0)
171                 {
172                         continue;
173                 }
174                 v[j] = ber_bvdup( attr->a_vals[i] );
175
176                 if( v[j] != NULL ) j++;
177         }
178
179         if( j == 0 ) {
180                 ch_free( v );
181                 *vals = NULL;
182                 rc = LDAP_INSUFFICIENT_ACCESS;
183         } else {
184                 v[j] = NULL;
185                 *vals = v;
186                 rc = LDAP_SUCCESS;
187         }
188
189 return_results:
190         if( target != e ) {
191                 /* free entry and reader lock */
192                 cache_return_entry_r( &li->li_cache, e );                 
193         }
194
195 #ifdef NEW_LOGGING
196         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
197                    "ldbm_back_attribute: rc=%d nvals=%d.\n",
198                    rc, j ));
199 #else
200         Debug( LDAP_DEBUG_TRACE,
201                 "ldbm_back_attribute: rc=%d nvals=%d\n",
202                 rc, j, 0 ); 
203 #endif
204
205         return(rc);
206 }
207