1 /* group.c - bdb backend acl group routine */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
13 #include <ac/string.h>
17 #include "proto-bdb.h"
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
30 struct berval *gr_ndn,
31 struct berval *op_ndn,
32 ObjectClass *group_oc,
33 AttributeDescription *group_at
36 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
37 struct bdb_op_info *boi = NULL;
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;
50 if( group_oc->soc_names && group_oc->soc_names[0] ) {
51 group_oc_name = group_oc->soc_names[0];
53 group_oc_name = group_oc->soc_oid;
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 );
61 Debug( LDAP_DEBUG_ARGS,
62 "=> bdb_group: gr dn: \"%s\"\n",
63 gr_ndn->bv_val, 0, 0 );
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 );
72 Debug( LDAP_DEBUG_ARGS,
73 "=> bdb_group: tr dn: \"%s\"\n",
74 target->e_ndn, 0, 0 );
77 if( op ) boi = (struct bdb_op_info *) op->o_private;
78 if( boi != NULL && be == boi->boi_bdb ) {
83 locker = TXN_ID( txn );
85 LOCK_ID ( bdb->bi_dbenv, &locker );
87 if (dn_match(&target->e_name, gr_ndn)) {
88 /* we already have a LOCKED copy of the entry */
91 LDAP_LOG( BACK_BDB, DETAIL1,
92 "bdb_group: target is group (%s)\n", gr_ndn->bv_val, 0, 0 );
94 Debug( LDAP_DEBUG_ARGS,
95 "=> bdb_group: target is group: \"%s\"\n",
96 gr_ndn->bv_val, 0, 0 );
100 /* can we find group entry */
101 rc = bdb_dn2entry_r( be, NULL, gr_ndn, &e, NULL, 0, locker, &lock );
103 if ( rc == DB_LOCK_DEADLOCK || rc == DB_LOCK_NOTGRANTED )
109 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
115 LDAP_LOG( BACK_BDB, DETAIL1,
116 "bdb_group: cannot find group (%s)\n", gr_ndn->bv_val, 0, 0 );
118 Debug( LDAP_DEBUG_ACL,
119 "=> bdb_group: cannot find group: \"%s\"\n",
120 gr_ndn->bv_val, 0, 0 );
123 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
128 LDAP_LOG( BACK_BDB, DETAIL1,
129 "bdb_group: found group (%s)\n", gr_ndn->bv_val, 0, 0 );
131 Debug( LDAP_DEBUG_ACL,
132 "=> bdb_group: found group: \"%s\"\n",
133 gr_ndn->bv_val, 0, 0 );
137 /* find it's objectClass and member attribute values
138 * make sure this is a group entry
139 * finally test if we can find op_dn in the member attribute value list
144 if( is_entry_alias( e ) ) {
146 LDAP_LOG( BACK_BDB, INFO,
147 "bdb_group: group (%s) is an alias\n", gr_ndn->bv_val, 0, 0);
149 Debug( LDAP_DEBUG_ACL,
150 "<= bdb_group: group is an alias\n", 0, 0, 0 );
156 if( is_entry_referral( e ) ) {
158 LDAP_LOG( BACK_BDB, INFO,
159 "bdb_group: group (%s) is a referral.\n", gr_ndn->bv_val, 0, 0 );
161 Debug( LDAP_DEBUG_ACL,
162 "<= bdb_group: group is a referral\n", 0, 0, 0 );
167 if( !is_entry_objectclass( e, group_oc, 0 ) ) {
169 LDAP_LOG( BACK_BDB, ERR,
170 "bdb_group: failed to find %s in objectClass.\n",
171 group_oc_name, 0, 0 );
173 Debug( LDAP_DEBUG_ACL,
174 "<= bdb_group: failed to find %s in objectClass\n",
175 group_oc_name, 0, 0 );
180 if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
182 LDAP_LOG( BACK_BDB, INFO,
183 "bdb_group: failed to find %s\n", group_at_name, 0, 0 );
185 Debug( LDAP_DEBUG_ACL,
186 "<= bdb_group: failed to find %s\n",
187 group_at_name, 0, 0 );
193 LDAP_LOG( BACK_BDB, ENTRY,
194 "bdb_group: found objectClass %s and %s\n",
195 group_oc_name, group_at_name, 0 );
197 Debug( LDAP_DEBUG_ACL,
198 "<= bdb_group: found objectClass %s and %s\n",
199 group_oc_name, group_at_name, 0 );
202 if( value_find( group_at, attr->a_vals, op_ndn ) != LDAP_SUCCESS ) {
204 LDAP_LOG( BACK_BDB, DETAIL1,
205 "bdb_group: \"%s\" not in \"%s\": %s\n",
206 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
208 Debug( LDAP_DEBUG_ACL,
209 "<= bdb_group: \"%s\" not in \"%s\": %s\n",
210 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
216 LDAP_LOG( BACK_BDB, DETAIL1, "bdb_group: %s is in %s: %s\n",
217 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
219 Debug( LDAP_DEBUG_ACL,
220 "<= bdb_group: \"%s\" is in \"%s\": %s\n",
221 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
229 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
233 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
237 LDAP_LOG( BACK_BDB, ENTRY, "bdb_group: rc=%d\n", rc, 0, 0 );
239 Debug( LDAP_DEBUG_TRACE, "bdb_group: rc=%d\n", rc, 0, 0 );