]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/group.c
NVALUES: fix a couple of value_find_ex() calls
[openldap] / servers / slapd / back-bdb / group.c
1 /* group.c - bdb backend acl group routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 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
20 /* return 0 IFF op_dn is a value in member attribute
21  * of entry with gr_dn AND that entry has an objectClass
22  * value of groupOfNames
23  */
24 int
25 bdb_group(
26         Backend *be,
27         Connection *conn,
28         Operation *op,
29         Entry   *target,
30         struct berval   *gr_ndn,
31         struct berval   *op_ndn,
32         ObjectClass *group_oc,
33         AttributeDescription *group_at )
34 {
35         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
36         struct bdb_op_info *boi = NULL;
37         DB_TXN *txn = NULL;
38         Entry *e;
39         int     rc = 1;
40         Attribute *attr;
41
42         const char *group_oc_name = NULL;
43         const char *group_at_name = group_at->ad_cname.bv_val;
44
45         u_int32_t       locker = 0;
46         DB_LOCK         lock;
47         int             free_lock_id = 0;
48
49         if( group_oc->soc_names && group_oc->soc_names[0] ) {
50                 group_oc_name = group_oc->soc_names[0];
51         } else {
52                 group_oc_name = group_oc->soc_oid;
53         }
54
55 #ifdef NEW_LOGGING
56         LDAP_LOG( BACK_BDB, ENTRY, 
57                 "bdb_group: check (%s) member of (%s), oc %s\n",
58                 op_ndn->bv_val, gr_ndn->bv_val, group_oc_name );
59 #else
60         Debug( LDAP_DEBUG_ARGS,
61                 "=> bdb_group: group ndn: \"%s\"\n",
62                 gr_ndn->bv_val, 0, 0 ); 
63
64         Debug( LDAP_DEBUG_ARGS,
65                 "=> bdb_group: op ndn: \"%s\"\n",
66                 op_ndn->bv_val, 0, 0 ); 
67
68         Debug( LDAP_DEBUG_ARGS,
69                 "=> bdb_group: oc: \"%s\" at: \"%s\"\n", 
70                 group_oc_name, group_at_name, 0 ); 
71
72         Debug( LDAP_DEBUG_ARGS,
73                 "=> bdb_group: tr ndn: \"%s\"\n",
74                 target ? target->e_ndn : "", 0, 0 ); 
75 #endif
76
77         if( op ) boi = (struct bdb_op_info *) op->o_private;
78         if( boi != NULL && be == boi->boi_bdb ) {
79                 txn = boi->boi_txn;
80                 locker = boi->boi_locker;
81         }
82
83         if ( txn ) {
84                 locker = TXN_ID( txn );
85         } else if ( !locker ) {
86                 rc = LOCK_ID ( bdb->bi_dbenv, &locker );
87                 free_lock_id = 1;
88                 switch(rc) {
89                 case 0:
90                         break;
91                 default:
92                         return 1;
93                 }
94         }
95
96         if ( target != NULL && dn_match( &target->e_nname, gr_ndn )) {
97                 /* we already have a LOCKED copy of the entry */
98                 e = target;
99 #ifdef NEW_LOGGING
100                 LDAP_LOG( BACK_BDB, DETAIL1, 
101                         "bdb_group: target is group (%s)\n", gr_ndn->bv_val, 0, 0 );
102 #else
103                 Debug( LDAP_DEBUG_ARGS,
104                         "=> bdb_group: target is group: \"%s\"\n",
105                         gr_ndn->bv_val, 0, 0 );
106 #endif
107         } else {
108 dn2entry_retry:
109                 /* can we find group entry */
110                 rc = bdb_dn2entry_r( be, txn, gr_ndn, &e, NULL, 0, locker, &lock ); 
111                 if( rc ) {
112                         boi->boi_err = rc;
113                         if ( rc == DB_LOCK_DEADLOCK || rc == DB_LOCK_NOTGRANTED ) {
114                                 if ( txn ) {
115                                 /* must let owning txn abort, but our result
116                                  * is still inconclusive, so don't let it
117                                  * get cached.
118                                  */
119                                         op->o_do_not_cache = 1;
120                                         return( 1 );
121                                 }
122                                 ldap_pvt_thread_yield();
123                                 goto dn2entry_retry;
124                         }
125                         if ( free_lock_id ) {
126                                 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
127                         }
128                         return( 1 );
129                 }
130                 if (e == NULL) {
131 #ifdef NEW_LOGGING
132                         LDAP_LOG( BACK_BDB, DETAIL1, 
133                                 "bdb_group: cannot find group (%s)\n", gr_ndn->bv_val, 0, 0 );
134 #else
135                         Debug( LDAP_DEBUG_ACL,
136                                 "=> bdb_group: cannot find group: \"%s\"\n",
137                                         gr_ndn->bv_val, 0, 0 ); 
138 #endif
139                         if ( free_lock_id ) {
140                                 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
141                         }
142                         return( 1 );
143                 }
144 #ifdef NEW_LOGGING
145                 LDAP_LOG( BACK_BDB, DETAIL1, 
146                         "bdb_group: found group (%s)\n", gr_ndn->bv_val, 0, 0 );
147 #else
148                 Debug( LDAP_DEBUG_ACL,
149                         "=> bdb_group: found group: \"%s\"\n",
150                         gr_ndn->bv_val, 0, 0 ); 
151 #endif
152         }
153
154         /* find it's objectClass and member attribute values
155          * make sure this is a group entry
156          * finally test if we can find op_dn in the member attribute value list
157          */
158         rc = 1;
159
160 #ifdef BDB_ALIASES
161         if( is_entry_alias( e ) ) {
162 #ifdef NEW_LOGGING
163                 LDAP_LOG( BACK_BDB, INFO, 
164                         "bdb_group: group (%s) is an alias\n", gr_ndn->bv_val, 0, 0);
165 #else
166                 Debug( LDAP_DEBUG_ACL,
167                         "<= bdb_group: group is an alias\n", 0, 0, 0 );
168 #endif
169                 goto return_results;
170         }
171 #endif
172
173         if( is_entry_referral( e ) ) {
174 #ifdef NEW_LOGGING
175                 LDAP_LOG( BACK_BDB, INFO, 
176                         "bdb_group: group (%s) is a referral.\n", gr_ndn->bv_val, 0, 0 );
177 #else
178                 Debug( LDAP_DEBUG_ACL,
179                         "<= bdb_group: group is a referral\n", 0, 0, 0 );
180 #endif
181                 goto return_results;
182         }
183
184         if( !is_entry_objectclass( e, group_oc, 0 ) ) {
185 #ifdef NEW_LOGGING
186                 LDAP_LOG( BACK_BDB, ERR, 
187                         "bdb_group: failed to find %s in objectClass.\n", 
188                         group_oc_name, 0, 0 );
189 #else
190                 Debug( LDAP_DEBUG_ACL,
191                         "<= bdb_group: failed to find %s in objectClass\n", 
192                                 group_oc_name, 0, 0 ); 
193 #endif
194                 goto return_results;
195         }
196
197         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
198 #ifdef NEW_LOGGING
199                 LDAP_LOG( BACK_BDB, INFO, 
200                         "bdb_group: failed to find %s\n", group_at_name, 0, 0 );
201 #else
202                 Debug( LDAP_DEBUG_ACL,
203                         "<= bdb_group: failed to find %s\n",
204                         group_at_name, 0, 0 ); 
205 #endif
206                 goto return_results;
207         }
208
209 #ifdef NEW_LOGGING
210         LDAP_LOG( BACK_BDB, ENTRY, 
211                 "bdb_group: found objectClass %s and %s\n",
212                 group_oc_name, group_at_name, 0 );
213 #else
214         Debug( LDAP_DEBUG_ACL,
215                 "<= bdb_group: found objectClass %s and %s\n",
216                 group_oc_name, group_at_name, 0 ); 
217 #endif
218
219 #ifdef SLAP_NVALUES
220         if( value_find_ex( group_at, SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH
221                         | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
222                 attr->a_nvals ? attr->a_nvals : attr->a_vals,
223                 op_ndn ) != LDAP_SUCCESS )
224 #else
225         if( value_find_ex( group_at, 0, attr->a_vals, op_ndn ) != LDAP_SUCCESS )
226 #endif
227         {
228 #ifdef NEW_LOGGING
229                 LDAP_LOG( BACK_BDB, DETAIL1, 
230                         "bdb_group: \"%s\" not in \"%s\": %s\n",
231                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
232 #else
233                 Debug( LDAP_DEBUG_ACL,
234                         "<= bdb_group: \"%s\" not in \"%s\": %s\n", 
235                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
236 #endif
237                 goto return_results;
238         }
239
240 #ifdef NEW_LOGGING
241         LDAP_LOG( BACK_BDB, DETAIL1, "bdb_group: %s is in %s: %s\n",
242                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
243 #else
244         Debug( LDAP_DEBUG_ACL,
245                 "<= bdb_group: \"%s\" is in \"%s\": %s\n", 
246                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
247 #endif
248
249         rc = 0;
250
251 return_results:
252         if( target != e ) {
253                 /* free entry */
254                 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
255         }
256
257         if ( free_lock_id ) {
258                 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
259         }
260
261 #ifdef NEW_LOGGING
262         LDAP_LOG( BACK_BDB, ENTRY, "bdb_group: rc=%d\n", rc, 0, 0 );
263 #else
264         Debug( LDAP_DEBUG_TRACE, "bdb_group: rc=%d\n", rc, 0, 0 ); 
265 #endif
266
267         return(rc);
268 }
269