]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/group.c
Set lock detector to DEFAULT, not NORUN.
[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 bdbinfo *li = (struct bdbinfo *) be->be_private;
37         struct bdb_op_info *boi = (struct bdb_op_info *) op->o_private;
38         DB_TXN *txn;
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         if( group_oc->soc_names && group_oc->soc_names[0] ) {
48                 group_oc_name = group_oc->soc_names[0];
49         } else {
50                 group_oc_name = group_oc->soc_oid;
51         }
52
53 #ifdef NEW_LOGGING
54         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
55                 "bdb_group: check (%s) member of (%s), oc %s\n",
56                 op_ndn->bv_val, gr_ndn->bv_val, group_oc_name ));
57 #else
58         Debug( LDAP_DEBUG_ARGS,
59                 "=> bdb_group: gr dn: \"%s\"\n",
60                 gr_ndn->bv_val, 0, 0 ); 
61
62         Debug( LDAP_DEBUG_ARGS,
63                 "=> bdb_group: op dn: \"%s\"\n",
64                 op_ndn->bv_val, 0, 0 ); 
65         Debug( LDAP_DEBUG_ARGS,
66                 "=> bdb_group: oc: \"%s\" at: \"%s\"\n", 
67                 group_oc_name, group_at_name, 0 ); 
68
69         Debug( LDAP_DEBUG_ARGS,
70                 "=> bdb_group: tr dn: \"%s\"\n",
71                 target->e_ndn, 0, 0 ); 
72 #endif
73
74         if( boi != NULL && be == boi->boi_bdb ) {
75                 txn = boi->boi_txn;
76         }
77
78         if (dn_match(&target->e_name, gr_ndn)) {
79                 /* we already have a LOCKED copy of the entry */
80                 e = target;
81 #ifdef NEW_LOGGING
82                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
83                         "bdb_group: target is group (%s)\n", gr_ndn->bv_val ));
84 #else
85                 Debug( LDAP_DEBUG_ARGS,
86                         "=> bdb_group: target is group: \"%s\"\n",
87                         gr_ndn->bv_val, 0, 0 );
88 #endif
89         } else {
90                 /* can we find group entry */
91                 rc = bdb_dn2entry( be, txn, gr_ndn, &e, NULL, 0 );
92                 if( rc ) {
93                         if( txn ) {
94                                 boi->boi_err = rc;
95                         }
96                         return( 1 );
97                 }
98                 if (e == NULL) {
99 #ifdef NEW_LOGGING
100                         LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
101                                 "bdb_group: cannot find group (%s)\n",
102                                 gr_ndn->bv_val ));
103 #else
104                         Debug( LDAP_DEBUG_ACL,
105                                 "=> bdb_group: cannot find group: \"%s\"\n",
106                                         gr_ndn->bv_val, 0, 0 ); 
107 #endif
108                         return( 1 );
109                 }
110 #ifdef NEW_LOGGING
111                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
112                         "bdb_group: found group (%s)\n", gr_ndn->bv_val ));
113 #else
114                 Debug( LDAP_DEBUG_ACL,
115                         "=> bdb_group: found group: \"%s\"\n",
116                         gr_ndn->bv_val, 0, 0 ); 
117 #endif
118         }
119
120         /* find it's objectClass and member attribute values
121          * make sure this is a group entry
122          * finally test if we can find op_dn in the member attribute value list
123          */
124         rc = 1;
125
126         if( is_entry_alias( e ) ) {
127 #ifdef NEW_LOGGING
128                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
129                         "bdb_group: group (%s) is an alias\n", gr_ndn->bv_val ));
130 #else
131                 Debug( LDAP_DEBUG_ACL,
132                         "<= bdb_group: group is an alias\n", 0, 0, 0 );
133 #endif
134                 goto return_results;
135         }
136
137         if( is_entry_referral( e ) ) {
138 #ifdef NEW_LOGGING
139                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
140                         "bdb_group: group (%s) is a referral.\n", gr_ndn->bv_val ));
141 #else
142                 Debug( LDAP_DEBUG_ACL,
143                         "<= bdb_group: group is a referral\n", 0, 0, 0 );
144 #endif
145                 goto return_results;
146         }
147
148         if( !is_entry_objectclass( e, group_oc, 0 ) ) {
149 #ifdef NEW_LOGGING
150                 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
151                         "bdb_group: failed to find %s in objectClass.\n",
152                         group_oc_name ));
153 #else
154                 Debug( LDAP_DEBUG_ACL,
155                         "<= bdb_group: failed to find %s in objectClass\n", 
156                                 group_oc_name, 0, 0 ); 
157 #endif
158                 goto return_results;
159         }
160
161         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
162 #ifdef NEW_LOGGING
163                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
164                         "bdb_group: failed to find %s\n", group_at_name ));
165 #else
166                 Debug( LDAP_DEBUG_ACL,
167                         "<= bdb_group: failed to find %s\n",
168                         group_at_name, 0, 0 ); 
169 #endif
170                 goto return_results;
171         }
172
173 #ifdef NEW_LOGGING
174         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
175                 "bdb_group: found objectClass %s and %s\n",
176                 group_oc_name, group_at_name ));
177 #else
178         Debug( LDAP_DEBUG_ACL,
179                 "<= bdb_group: found objectClass %s and %s\n",
180                 group_oc_name, group_at_name, 0 ); 
181 #endif
182
183         if( value_find( group_at, attr->a_vals, op_ndn ) != LDAP_SUCCESS ) {
184 #ifdef NEW_LOGGING
185                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
186                         "bdb_group: \"%s\" not in \"%s\": %s\n",
187                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name ));
188 #else
189                 Debug( LDAP_DEBUG_ACL,
190                         "<= bdb_group: \"%s\" not in \"%s\": %s\n", 
191                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
192 #endif
193                 goto return_results;
194         }
195
196 #ifdef NEW_LOGGING
197         LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
198                 "bdb_group: %s is in %s: %s\n",
199                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ));
200 #else
201         Debug( LDAP_DEBUG_ACL,
202                 "<= bdb_group: \"%s\" is in \"%s\": %s\n", 
203                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
204 #endif
205
206         rc = 0;
207
208 return_results:
209         if( target != e ) {
210                 /* free entry */
211                 bdb_entry_return( be, e );
212         }
213
214 #ifdef NEW_LOGGING
215         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
216                 "bdb_group: rc=%d\n", rc ));
217 #else
218         Debug( LDAP_DEBUG_TRACE, "bdb_group: rc=%d\n", rc, 0, 0 ); 
219 #endif
220
221         return(rc);
222 }
223