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