]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/group.c
Cancel exop updates
[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, NULL, gr_ndn, &e, NULL, 0, locker, &lock ); 
111                 if( rc ) {
112                         if ( rc == DB_LOCK_DEADLOCK || rc == DB_LOCK_NOTGRANTED )
113                                 goto dn2entry_retry;
114                         boi->boi_err = rc;
115                         if ( free_lock_id ) {
116                                 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
117                         }
118                         return( 1 );
119                 }
120                 if (e == NULL) {
121 #ifdef NEW_LOGGING
122                         LDAP_LOG( BACK_BDB, DETAIL1, 
123                                 "bdb_group: cannot find group (%s)\n", gr_ndn->bv_val, 0, 0 );
124 #else
125                         Debug( LDAP_DEBUG_ACL,
126                                 "=> bdb_group: cannot find group: \"%s\"\n",
127                                         gr_ndn->bv_val, 0, 0 ); 
128 #endif
129                         if ( free_lock_id ) {
130                                 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
131                         }
132                         return( 1 );
133                 }
134 #ifdef NEW_LOGGING
135                 LDAP_LOG( BACK_BDB, DETAIL1, 
136                         "bdb_group: found group (%s)\n", gr_ndn->bv_val, 0, 0 );
137 #else
138                 Debug( LDAP_DEBUG_ACL,
139                         "=> bdb_group: found group: \"%s\"\n",
140                         gr_ndn->bv_val, 0, 0 ); 
141 #endif
142         }
143
144         /* find it's objectClass and member attribute values
145          * make sure this is a group entry
146          * finally test if we can find op_dn in the member attribute value list
147          */
148         rc = 1;
149
150 #ifdef BDB_ALIASES
151         if( is_entry_alias( e ) ) {
152 #ifdef NEW_LOGGING
153                 LDAP_LOG( BACK_BDB, INFO, 
154                         "bdb_group: group (%s) is an alias\n", gr_ndn->bv_val, 0, 0);
155 #else
156                 Debug( LDAP_DEBUG_ACL,
157                         "<= bdb_group: group is an alias\n", 0, 0, 0 );
158 #endif
159                 goto return_results;
160         }
161 #endif
162
163         if( is_entry_referral( e ) ) {
164 #ifdef NEW_LOGGING
165                 LDAP_LOG( BACK_BDB, INFO, 
166                         "bdb_group: group (%s) is a referral.\n", gr_ndn->bv_val, 0, 0 );
167 #else
168                 Debug( LDAP_DEBUG_ACL,
169                         "<= bdb_group: group is a referral\n", 0, 0, 0 );
170 #endif
171                 goto return_results;
172         }
173
174         if( !is_entry_objectclass( e, group_oc, 0 ) ) {
175 #ifdef NEW_LOGGING
176                 LDAP_LOG( BACK_BDB, ERR, 
177                         "bdb_group: failed to find %s in objectClass.\n", 
178                         group_oc_name, 0, 0 );
179 #else
180                 Debug( LDAP_DEBUG_ACL,
181                         "<= bdb_group: failed to find %s in objectClass\n", 
182                                 group_oc_name, 0, 0 ); 
183 #endif
184                 goto return_results;
185         }
186
187         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
188 #ifdef NEW_LOGGING
189                 LDAP_LOG( BACK_BDB, INFO, 
190                         "bdb_group: failed to find %s\n", group_at_name, 0, 0 );
191 #else
192                 Debug( LDAP_DEBUG_ACL,
193                         "<= bdb_group: failed to find %s\n",
194                         group_at_name, 0, 0 ); 
195 #endif
196                 goto return_results;
197         }
198
199 #ifdef NEW_LOGGING
200         LDAP_LOG( BACK_BDB, ENTRY, 
201                 "bdb_group: found objectClass %s and %s\n",
202                 group_oc_name, group_at_name, 0 );
203 #else
204         Debug( LDAP_DEBUG_ACL,
205                 "<= bdb_group: found objectClass %s and %s\n",
206                 group_oc_name, group_at_name, 0 ); 
207 #endif
208
209         if( value_find_ex( group_at, SLAP_MR_VALUE_NORMALIZED_MATCH,
210                 attr->a_vals, op_ndn ) != LDAP_SUCCESS ) {
211 #ifdef NEW_LOGGING
212                 LDAP_LOG( BACK_BDB, DETAIL1, 
213                         "bdb_group: \"%s\" not in \"%s\": %s\n",
214                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
215 #else
216                 Debug( LDAP_DEBUG_ACL,
217                         "<= bdb_group: \"%s\" not in \"%s\": %s\n", 
218                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
219 #endif
220                 goto return_results;
221         }
222
223 #ifdef NEW_LOGGING
224         LDAP_LOG( BACK_BDB, DETAIL1, "bdb_group: %s is in %s: %s\n",
225                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
226 #else
227         Debug( LDAP_DEBUG_ACL,
228                 "<= bdb_group: \"%s\" is in \"%s\": %s\n", 
229                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
230 #endif
231
232         rc = 0;
233
234 return_results:
235         if( target != e ) {
236                 /* free entry */
237                 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
238         }
239
240         if ( free_lock_id ) {
241                 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
242         }
243
244 #ifdef NEW_LOGGING
245         LDAP_LOG( BACK_BDB, ENTRY, "bdb_group: rc=%d\n", rc, 0, 0 );
246 #else
247         Debug( LDAP_DEBUG_TRACE, "bdb_group: rc=%d\n", rc, 0, 0 ); 
248 #endif
249
250         return(rc);
251 }
252