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 const char *group_oc_name = NULL;
44 const char *group_at_name = group_at->ad_cname.bv_val;
49 if( group_oc->soc_names && group_oc->soc_names[0] ) {
50 group_oc_name = group_oc->soc_names[0];
52 group_oc_name = group_oc->soc_oid;
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 );
60 Debug( LDAP_DEBUG_ARGS,
61 "=> bdb_group: gr dn: \"%s\"\n",
62 gr_ndn->bv_val, 0, 0 );
64 Debug( LDAP_DEBUG_ARGS,
65 "=> bdb_group: op dn: \"%s\"\n",
66 op_ndn->bv_val, 0, 0 );
67 Debug( LDAP_DEBUG_ARGS,
68 "=> bdb_group: oc: \"%s\" at: \"%s\"\n",
69 group_oc_name, group_at_name, 0 );
71 Debug( LDAP_DEBUG_ARGS,
72 "=> bdb_group: tr dn: \"%s\"\n",
73 target->e_ndn, 0, 0 );
76 if( op ) boi = (struct bdb_op_info *) op->o_private;
77 if( boi != NULL && be == boi->boi_bdb ) {
82 locker = TXN_ID( txn );
84 rc = LOCK_ID ( bdb->bi_dbenv, &locker );
93 if (dn_match(&target->e_name, gr_ndn)) {
94 /* we already have a LOCKED copy of the entry */
97 LDAP_LOG( BACK_BDB, DETAIL1,
98 "bdb_group: target is group (%s)\n", gr_ndn->bv_val, 0, 0 );
100 Debug( LDAP_DEBUG_ARGS,
101 "=> bdb_group: target is group: \"%s\"\n",
102 gr_ndn->bv_val, 0, 0 );
106 /* can we find group entry */
107 rc = bdb_dn2entry_r( be, NULL, gr_ndn, &e, NULL, 0, locker, &lock );
109 if ( rc == DB_LOCK_DEADLOCK || rc == DB_LOCK_NOTGRANTED )
115 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
121 LDAP_LOG( BACK_BDB, DETAIL1,
122 "bdb_group: cannot find group (%s)\n", gr_ndn->bv_val, 0, 0 );
124 Debug( LDAP_DEBUG_ACL,
125 "=> bdb_group: cannot find group: \"%s\"\n",
126 gr_ndn->bv_val, 0, 0 );
129 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
134 LDAP_LOG( BACK_BDB, DETAIL1,
135 "bdb_group: found group (%s)\n", gr_ndn->bv_val, 0, 0 );
137 Debug( LDAP_DEBUG_ACL,
138 "=> bdb_group: found group: \"%s\"\n",
139 gr_ndn->bv_val, 0, 0 );
143 /* find it's objectClass and member attribute values
144 * make sure this is a group entry
145 * finally test if we can find op_dn in the member attribute value list
150 if( is_entry_alias( e ) ) {
152 LDAP_LOG( BACK_BDB, INFO,
153 "bdb_group: group (%s) is an alias\n", gr_ndn->bv_val, 0, 0);
155 Debug( LDAP_DEBUG_ACL,
156 "<= bdb_group: group is an alias\n", 0, 0, 0 );
162 if( is_entry_referral( e ) ) {
164 LDAP_LOG( BACK_BDB, INFO,
165 "bdb_group: group (%s) is a referral.\n", gr_ndn->bv_val, 0, 0 );
167 Debug( LDAP_DEBUG_ACL,
168 "<= bdb_group: group is a referral\n", 0, 0, 0 );
173 if( !is_entry_objectclass( e, group_oc, 0 ) ) {
175 LDAP_LOG( BACK_BDB, ERR,
176 "bdb_group: failed to find %s in objectClass.\n",
177 group_oc_name, 0, 0 );
179 Debug( LDAP_DEBUG_ACL,
180 "<= bdb_group: failed to find %s in objectClass\n",
181 group_oc_name, 0, 0 );
186 if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
188 LDAP_LOG( BACK_BDB, INFO,
189 "bdb_group: failed to find %s\n", group_at_name, 0, 0 );
191 Debug( LDAP_DEBUG_ACL,
192 "<= bdb_group: failed to find %s\n",
193 group_at_name, 0, 0 );
199 LDAP_LOG( BACK_BDB, ENTRY,
200 "bdb_group: found objectClass %s and %s\n",
201 group_oc_name, group_at_name, 0 );
203 Debug( LDAP_DEBUG_ACL,
204 "<= bdb_group: found objectClass %s and %s\n",
205 group_oc_name, group_at_name, 0 );
208 if( value_find( group_at, attr->a_vals, op_ndn ) != LDAP_SUCCESS ) {
210 LDAP_LOG( BACK_BDB, DETAIL1,
211 "bdb_group: \"%s\" not in \"%s\": %s\n",
212 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
214 Debug( LDAP_DEBUG_ACL,
215 "<= bdb_group: \"%s\" not in \"%s\": %s\n",
216 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
222 LDAP_LOG( BACK_BDB, DETAIL1, "bdb_group: %s is in %s: %s\n",
223 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
225 Debug( LDAP_DEBUG_ACL,
226 "<= bdb_group: \"%s\" is in \"%s\": %s\n",
227 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
235 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
239 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
243 LDAP_LOG( BACK_BDB, ENTRY, "bdb_group: rc=%d\n", rc, 0, 0 );
245 Debug( LDAP_DEBUG_TRACE, "bdb_group: rc=%d\n", rc, 0, 0 );