]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/group.c
More places where LOCK_ID() calls need to be checked.
[openldap] / servers / slapd / back-bdb / group.c
1 /* group.c - bdb backend acl group 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
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 {
36         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
37         struct bdb_op_info *boi = NULL;
38         DB_TXN *txn = NULL;
39         Entry *e;
40         int     rc = 1;
41         Attribute *attr;
42
43         AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
44         const char *group_oc_name = NULL;
45         const char *group_at_name = group_at->ad_cname.bv_val;
46
47         u_int32_t       locker;
48         DB_LOCK         lock;
49
50         if( group_oc->soc_names && group_oc->soc_names[0] ) {
51                 group_oc_name = group_oc->soc_names[0];
52         } else {
53                 group_oc_name = group_oc->soc_oid;
54         }
55
56 #ifdef NEW_LOGGING
57         LDAP_LOG( BACK_BDB, ENTRY, 
58                 "bdb_group: check (%s) member of (%s), oc %s\n",
59                 op_ndn->bv_val, gr_ndn->bv_val, group_oc_name );
60 #else
61         Debug( LDAP_DEBUG_ARGS,
62                 "=> bdb_group: gr dn: \"%s\"\n",
63                 gr_ndn->bv_val, 0, 0 ); 
64
65         Debug( LDAP_DEBUG_ARGS,
66                 "=> bdb_group: op dn: \"%s\"\n",
67                 op_ndn->bv_val, 0, 0 ); 
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 dn: \"%s\"\n",
74                 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         }
81
82         if ( txn ) {
83                 locker = TXN_ID( txn );
84         } else {
85                 /* XXYYZ: need to check return value */
86                 LOCK_ID ( bdb->bi_dbenv, &locker );
87         }
88
89         if (dn_match(&target->e_name, gr_ndn)) {
90                 /* we already have a LOCKED copy of the entry */
91                 e = target;
92 #ifdef NEW_LOGGING
93                 LDAP_LOG( BACK_BDB, DETAIL1, 
94                         "bdb_group: target is group (%s)\n", gr_ndn->bv_val, 0, 0 );
95 #else
96                 Debug( LDAP_DEBUG_ARGS,
97                         "=> bdb_group: target is group: \"%s\"\n",
98                         gr_ndn->bv_val, 0, 0 );
99 #endif
100         } else {
101 dn2entry_retry:
102                 /* can we find group entry */
103                 rc = bdb_dn2entry_r( be, NULL, gr_ndn, &e, NULL, 0, locker, &lock ); 
104                 if( rc ) {
105                         if ( rc == DB_LOCK_DEADLOCK || rc == DB_LOCK_NOTGRANTED )
106                                 goto dn2entry_retry;
107                         if( txn ) {
108                                 boi->boi_err = rc;
109                         }
110                         else {
111                                 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
112                         }
113                         return( 1 );
114                 }
115                 if (e == NULL) {
116 #ifdef NEW_LOGGING
117                         LDAP_LOG( BACK_BDB, DETAIL1, 
118                                 "bdb_group: cannot find group (%s)\n", gr_ndn->bv_val, 0, 0 );
119 #else
120                         Debug( LDAP_DEBUG_ACL,
121                                 "=> bdb_group: cannot find group: \"%s\"\n",
122                                         gr_ndn->bv_val, 0, 0 ); 
123 #endif
124                         if ( txn == NULL ) {
125                                 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
126                         }
127                         return( 1 );
128                 }
129 #ifdef NEW_LOGGING
130                 LDAP_LOG( BACK_BDB, DETAIL1, 
131                         "bdb_group: found group (%s)\n", gr_ndn->bv_val, 0, 0 );
132 #else
133                 Debug( LDAP_DEBUG_ACL,
134                         "=> bdb_group: found group: \"%s\"\n",
135                         gr_ndn->bv_val, 0, 0 ); 
136 #endif
137         }
138
139         /* find it's objectClass and member attribute values
140          * make sure this is a group entry
141          * finally test if we can find op_dn in the member attribute value list
142          */
143         rc = 1;
144
145 #ifdef BDB_ALIASES
146         if( is_entry_alias( e ) ) {
147 #ifdef NEW_LOGGING
148                 LDAP_LOG( BACK_BDB, INFO, 
149                         "bdb_group: group (%s) is an alias\n", gr_ndn->bv_val, 0, 0);
150 #else
151                 Debug( LDAP_DEBUG_ACL,
152                         "<= bdb_group: group is an alias\n", 0, 0, 0 );
153 #endif
154                 goto return_results;
155         }
156 #endif
157
158         if( is_entry_referral( e ) ) {
159 #ifdef NEW_LOGGING
160                 LDAP_LOG( BACK_BDB, INFO, 
161                         "bdb_group: group (%s) is a referral.\n", gr_ndn->bv_val, 0, 0 );
162 #else
163                 Debug( LDAP_DEBUG_ACL,
164                         "<= bdb_group: group is a referral\n", 0, 0, 0 );
165 #endif
166                 goto return_results;
167         }
168
169         if( !is_entry_objectclass( e, group_oc, 0 ) ) {
170 #ifdef NEW_LOGGING
171                 LDAP_LOG( BACK_BDB, ERR, 
172                         "bdb_group: failed to find %s in objectClass.\n", 
173                         group_oc_name, 0, 0 );
174 #else
175                 Debug( LDAP_DEBUG_ACL,
176                         "<= bdb_group: failed to find %s in objectClass\n", 
177                                 group_oc_name, 0, 0 ); 
178 #endif
179                 goto return_results;
180         }
181
182         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
183 #ifdef NEW_LOGGING
184                 LDAP_LOG( BACK_BDB, INFO, 
185                         "bdb_group: failed to find %s\n", group_at_name, 0, 0 );
186 #else
187                 Debug( LDAP_DEBUG_ACL,
188                         "<= bdb_group: failed to find %s\n",
189                         group_at_name, 0, 0 ); 
190 #endif
191                 goto return_results;
192         }
193
194 #ifdef NEW_LOGGING
195         LDAP_LOG( BACK_BDB, ENTRY, 
196                 "bdb_group: found objectClass %s and %s\n",
197                 group_oc_name, group_at_name, 0 );
198 #else
199         Debug( LDAP_DEBUG_ACL,
200                 "<= bdb_group: found objectClass %s and %s\n",
201                 group_oc_name, group_at_name, 0 ); 
202 #endif
203
204         if( value_find( group_at, attr->a_vals, op_ndn ) != LDAP_SUCCESS ) {
205 #ifdef NEW_LOGGING
206                 LDAP_LOG( BACK_BDB, DETAIL1, 
207                         "bdb_group: \"%s\" not in \"%s\": %s\n",
208                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
209 #else
210                 Debug( LDAP_DEBUG_ACL,
211                         "<= bdb_group: \"%s\" not in \"%s\": %s\n", 
212                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
213 #endif
214                 goto return_results;
215         }
216
217 #ifdef NEW_LOGGING
218         LDAP_LOG( BACK_BDB, DETAIL1, "bdb_group: %s is in %s: %s\n",
219                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
220 #else
221         Debug( LDAP_DEBUG_ACL,
222                 "<= bdb_group: \"%s\" is in \"%s\": %s\n", 
223                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
224 #endif
225
226         rc = 0;
227
228 return_results:
229         if( target != e ) {
230                 /* free entry */
231                 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
232         }
233
234         if ( txn == NULL ) {
235                 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
236         }
237
238 #ifdef NEW_LOGGING
239         LDAP_LOG( BACK_BDB, ENTRY, "bdb_group: rc=%d\n", rc, 0, 0 );
240 #else
241         Debug( LDAP_DEBUG_TRACE, "bdb_group: rc=%d\n", rc, 0, 0 ); 
242 #endif
243
244         return(rc);
245 }
246