]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/attribute.c
Turn these functions on again. Need backend_attribute for SASLauthz stuff.
[openldap] / servers / slapd / back-bdb / attribute.c
1 /* attribute.c - bdb 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-bdb.h"
17 #include "proto-bdb.h"
18
19 /* return LDAP_SUCCESS IFF we can retrieve the attributes
20  * of entry with e_ndn
21  */
22 int
23 bdb_attribute(
24         Backend *be,
25         Connection *conn,
26         Operation *op,
27         Entry *target,
28         struct berval *entry_ndn,
29         AttributeDescription *entry_at,
30         BerVarray *vals )
31 {
32         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
33         struct bdb_op_info *boi = NULL;
34         DB_TXN *txn = NULL;
35         Entry *e;
36         int     i, j = 0, rc;
37         Attribute *attr;
38         BerVarray v;
39         const char *entry_at_name = entry_at->ad_cname.bv_val;
40         AccessControlState acl_state = ACL_STATE_INIT;
41
42 #ifdef NEW_LOGGING
43         LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
44                 "bdb_attribute: gr dn: \"%s\"\n", entry_ndn->bv_val ));
45         LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
46                 "bdb_attribute: at: \"%s\"\n", entry_at_name));
47         LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
48                 "bdb_attribute: tr dn: \"%s\"\n",
49                 target ? target->e_ndn : "" ));
50 #else
51         Debug( LDAP_DEBUG_ARGS,
52                 "=> bdb_attribute: gr dn: \"%s\"\n",
53                 entry_ndn->bv_val, 0, 0 ); 
54         Debug( LDAP_DEBUG_ARGS,
55                 "=> bdb_attribute: at: \"%s\"\n", 
56                 entry_at_name, 0, 0 ); 
57
58         Debug( LDAP_DEBUG_ARGS,
59                 "=> bdb_attribute: tr dn: \"%s\"\n",
60                 target ? target->e_ndn : "", 0, 0 ); 
61 #endif
62
63         if( op ) boi = (struct bdb_op_info *) op->o_private;
64         if( boi != NULL && be == boi->boi_bdb ) {
65                 txn = boi->boi_txn;
66         }
67
68         if (target != NULL && dn_match(&target->e_nname, entry_ndn)) {
69                 /* we already have a LOCKED copy of the entry */
70                 e = target;
71 #ifdef NEW_LOGGING
72                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
73                         "bdb_attribute: target is LOCKED (%s)\n",
74                         entry_ndn->bv_val ));
75 #else
76                 Debug( LDAP_DEBUG_ARGS,
77                         "=> bdb_attribute: target is entry: \"%s\"\n",
78                         entry_ndn->bv_val, 0, 0 );
79 #endif
80
81
82         } else {
83                 /* can we find entry */
84                 rc = bdb_dn2entry_r( be, NULL, entry_ndn, &e, NULL, 0 );
85                 switch( rc ) {
86                 case DB_NOTFOUND:
87                 case 0:
88                         break;
89                 default:
90                         if( txn != NULL ) {
91                                 boi->boi_err = rc;
92                         }
93                         return (rc != LDAP_BUSY) ? LDAP_OTHER : LDAP_BUSY;
94                 }
95                 if (e == NULL) {
96 #ifdef NEW_LOGGING
97                         LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
98                                 "bdb_attribute: cannot find entry (%s)\n",
99                                 entry_ndn->bv_val ));
100 #else
101                         Debug( LDAP_DEBUG_ACL,
102                                 "=> bdb_attribute: cannot find entry: \"%s\"\n",
103                                         entry_ndn->bv_val, 0, 0 ); 
104 #endif
105                         return LDAP_NO_SUCH_OBJECT; 
106                 }
107                 
108 #ifdef NEW_LOGGING
109                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
110                         "bdb_attribute: found entry (%s)\n",
111                         entry_ndn->bv_val ));
112 #else
113                 Debug( LDAP_DEBUG_ACL,
114                         "=> bdb_attribute: found entry: \"%s\"\n",
115                         entry_ndn->bv_val, 0, 0 ); 
116 #endif
117         }
118
119 #ifdef BDB_ALIASES
120         /* find attribute values */
121         if( is_entry_alias( e ) ) {
122 #ifdef NEW_LOGGING
123                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
124                         "bdb_attribute: entry (%s) is an alias\n", e->e_dn ));
125 #else
126                 Debug( LDAP_DEBUG_ACL,
127                         "<= bdb_attribute: entry is an alias\n", 0, 0, 0 );
128 #endif
129                 rc = LDAP_ALIAS_PROBLEM;
130                 goto return_results;
131         }
132 #endif
133
134         if( is_entry_referral( e ) ) {
135 #ifdef NEW_LOGGING
136                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
137                         "bdb_attribute: entry (%s) is a referral.\n", e->e_dn ));
138 #else
139                 Debug( LDAP_DEBUG_ACL,
140                         "<= bdb_attribute: entry is a referral\n", 0, 0, 0 );
141 #endif
142                 rc = LDAP_REFERRAL;
143                 goto return_results;
144         }
145
146         if (conn != NULL && op != NULL
147                 && access_allowed( be, conn, op, e, slap_schema.si_ad_entry,
148                         NULL, ACL_READ, &acl_state ) == 0 )
149         {
150                 rc = LDAP_INSUFFICIENT_ACCESS;
151                 goto return_results;
152         }
153
154         if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
155 #ifdef NEW_LOGGING
156                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
157                         "bdb_attribute: failed to find %s.\n", entry_at_name ));
158 #else
159                 Debug( LDAP_DEBUG_ACL,
160                         "<= bdb_attribute: failed to find %s\n",
161                         entry_at_name, 0, 0 ); 
162 #endif
163                 rc = LDAP_NO_SUCH_ATTRIBUTE;
164                 goto return_results;
165         }
166
167         if (conn != NULL && op != NULL
168                 && access_allowed( be, conn, op, e, entry_at, NULL, ACL_READ, 
169                            &acl_state ) == 0 )
170         {
171                 rc = LDAP_INSUFFICIENT_ACCESS;
172                 goto return_results;
173         }
174
175         for ( i = 0; attr->a_vals[i].bv_val != NULL; i++ ) {
176                 /* count them */
177         }
178
179         v = (BerVarray) ch_malloc( sizeof(struct berval) * (i+1) );
180
181         for ( i=0, j=0; attr->a_vals[i].bv_val != NULL; i++ ) {
182                 if( conn != NULL
183                         && op != NULL
184                         && access_allowed(be, conn, op, e, entry_at,
185                                 &attr->a_vals[i], ACL_READ, &acl_state ) == 0)
186                 {
187                         continue;
188                 }
189                 ber_dupbv( &v[j], &attr->a_vals[i] );
190
191                 if( v[j].bv_val != NULL ) j++;
192         }
193
194         if( j == 0 ) {
195                 ch_free( v );
196                 *vals = NULL;
197                 rc = LDAP_INSUFFICIENT_ACCESS;
198         } else {
199                 v[j].bv_val = NULL;
200                 v[j].bv_len = 0;
201                 *vals = v;
202                 rc = LDAP_SUCCESS;
203         }
204
205 return_results:
206         if( target != e ) {
207                 /* free entry */
208                 bdb_cache_return_entry_r(&bdb->bi_cache, e);
209         }
210
211 #ifdef NEW_LOGGING
212         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
213                 "bdb_attribute: rc=%d nvals=%d.\n",
214                 rc, j ));
215 #else
216         Debug( LDAP_DEBUG_TRACE,
217                 "bdb_attribute: rc=%d nvals=%d\n",
218                 rc, j, 0 ); 
219 #endif
220         return(rc);
221 }