]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/group.c
ITS#1711 txn was uninitialized
[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 = (struct bdb_op_info *) op->o_private;
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         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_r( be, NULL, 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 #ifdef BDB_ALIASES
127         if( is_entry_alias( e ) ) {
128 #ifdef NEW_LOGGING
129                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
130                         "bdb_group: group (%s) is an alias\n", gr_ndn->bv_val ));
131 #else
132                 Debug( LDAP_DEBUG_ACL,
133                         "<= bdb_group: group is an alias\n", 0, 0, 0 );
134 #endif
135                 goto return_results;
136         }
137 #endif
138
139         if( is_entry_referral( e ) ) {
140 #ifdef NEW_LOGGING
141                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
142                         "bdb_group: group (%s) is a referral.\n", gr_ndn->bv_val ));
143 #else
144                 Debug( LDAP_DEBUG_ACL,
145                         "<= bdb_group: group is a referral\n", 0, 0, 0 );
146 #endif
147                 goto return_results;
148         }
149
150         if( !is_entry_objectclass( e, group_oc, 0 ) ) {
151 #ifdef NEW_LOGGING
152                 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
153                         "bdb_group: failed to find %s in objectClass.\n",
154                         group_oc_name ));
155 #else
156                 Debug( LDAP_DEBUG_ACL,
157                         "<= bdb_group: failed to find %s in objectClass\n", 
158                                 group_oc_name, 0, 0 ); 
159 #endif
160                 goto return_results;
161         }
162
163         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
164 #ifdef NEW_LOGGING
165                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
166                         "bdb_group: failed to find %s\n", group_at_name ));
167 #else
168                 Debug( LDAP_DEBUG_ACL,
169                         "<= bdb_group: failed to find %s\n",
170                         group_at_name, 0, 0 ); 
171 #endif
172                 goto return_results;
173         }
174
175 #ifdef NEW_LOGGING
176         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
177                 "bdb_group: found objectClass %s and %s\n",
178                 group_oc_name, group_at_name ));
179 #else
180         Debug( LDAP_DEBUG_ACL,
181                 "<= bdb_group: found objectClass %s and %s\n",
182                 group_oc_name, group_at_name, 0 ); 
183 #endif
184
185         if( value_find( group_at, attr->a_vals, op_ndn ) != LDAP_SUCCESS ) {
186 #ifdef NEW_LOGGING
187                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
188                         "bdb_group: \"%s\" not in \"%s\": %s\n",
189                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name ));
190 #else
191                 Debug( LDAP_DEBUG_ACL,
192                         "<= bdb_group: \"%s\" not in \"%s\": %s\n", 
193                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
194 #endif
195                 goto return_results;
196         }
197
198 #ifdef NEW_LOGGING
199         LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
200                 "bdb_group: %s is in %s: %s\n",
201                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ));
202 #else
203         Debug( LDAP_DEBUG_ACL,
204                 "<= bdb_group: \"%s\" is in \"%s\": %s\n", 
205                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
206 #endif
207
208         rc = 0;
209
210 return_results:
211         if( target != e ) {
212                 /* free entry */
213                 bdb_cache_return_entry_r( &bdb->bi_cache, e );
214         }
215
216 #ifdef NEW_LOGGING
217         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
218                 "bdb_group: rc=%d\n", rc ));
219 #else
220         Debug( LDAP_DEBUG_TRACE, "bdb_group: rc=%d\n", rc, 0, 0 ); 
221 #endif
222
223         return(rc);
224 }
225