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;
47 if( group_oc->soc_names && group_oc->soc_names[0] ) {
48 group_oc_name = group_oc->soc_names[0];
50 group_oc_name = group_oc->soc_oid;
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 ));
58 Debug( LDAP_DEBUG_ARGS,
59 "=> bdb_group: gr dn: \"%s\"\n",
60 gr_ndn->bv_val, 0, 0 );
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 );
69 Debug( LDAP_DEBUG_ARGS,
70 "=> bdb_group: tr dn: \"%s\"\n",
71 target->e_ndn, 0, 0 );
74 if( op ) boi = (struct bdb_op_info *) op->o_private;
75 if( boi != NULL && be == boi->boi_bdb ) {
79 if (dn_match(&target->e_name, gr_ndn)) {
80 /* we already have a LOCKED copy of the entry */
83 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
84 "bdb_group: target is group (%s)\n", gr_ndn->bv_val ));
86 Debug( LDAP_DEBUG_ARGS,
87 "=> bdb_group: target is group: \"%s\"\n",
88 gr_ndn->bv_val, 0, 0 );
91 /* can we find group entry */
92 rc = bdb_dn2entry_r( be, NULL, gr_ndn, &e, NULL, 0 );
101 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
102 "bdb_group: cannot find group (%s)\n",
105 Debug( LDAP_DEBUG_ACL,
106 "=> bdb_group: cannot find group: \"%s\"\n",
107 gr_ndn->bv_val, 0, 0 );
112 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
113 "bdb_group: found group (%s)\n", gr_ndn->bv_val ));
115 Debug( LDAP_DEBUG_ACL,
116 "=> bdb_group: found group: \"%s\"\n",
117 gr_ndn->bv_val, 0, 0 );
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
128 if( is_entry_alias( e ) ) {
130 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
131 "bdb_group: group (%s) is an alias\n", gr_ndn->bv_val ));
133 Debug( LDAP_DEBUG_ACL,
134 "<= bdb_group: group is an alias\n", 0, 0, 0 );
140 if( is_entry_referral( e ) ) {
142 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
143 "bdb_group: group (%s) is a referral.\n", gr_ndn->bv_val ));
145 Debug( LDAP_DEBUG_ACL,
146 "<= bdb_group: group is a referral\n", 0, 0, 0 );
151 if( !is_entry_objectclass( e, group_oc, 0 ) ) {
153 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
154 "bdb_group: failed to find %s in objectClass.\n",
157 Debug( LDAP_DEBUG_ACL,
158 "<= bdb_group: failed to find %s in objectClass\n",
159 group_oc_name, 0, 0 );
164 if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
166 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
167 "bdb_group: failed to find %s\n", group_at_name ));
169 Debug( LDAP_DEBUG_ACL,
170 "<= bdb_group: failed to find %s\n",
171 group_at_name, 0, 0 );
177 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
178 "bdb_group: found objectClass %s and %s\n",
179 group_oc_name, group_at_name ));
181 Debug( LDAP_DEBUG_ACL,
182 "<= bdb_group: found objectClass %s and %s\n",
183 group_oc_name, group_at_name, 0 );
186 if( value_find( group_at, attr->a_vals, op_ndn ) != LDAP_SUCCESS ) {
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 ));
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 );
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 ));
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 );
214 bdb_cache_return_entry_r( &bdb->bi_cache, e );
218 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
219 "bdb_group: rc=%d\n", rc ));
221 Debug( LDAP_DEBUG_TRACE, "bdb_group: rc=%d\n", rc, 0, 0 );