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 = (struct bdb_op_info *) op->o_private;
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( boi != NULL && be == boi->boi_bdb ) {
78 if (dn_match(&target->e_name, gr_ndn)) {
79 /* we already have a LOCKED copy of the entry */
82 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
83 "bdb_group: target is group (%s)\n", gr_ndn->bv_val ));
85 Debug( LDAP_DEBUG_ARGS,
86 "=> bdb_group: target is group: \"%s\"\n",
87 gr_ndn->bv_val, 0, 0 );
90 /* can we find group entry */
91 rc = bdb_dn2entry_r( be, NULL, gr_ndn, &e, NULL, 0 );
100 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
101 "bdb_group: cannot find group (%s)\n",
104 Debug( LDAP_DEBUG_ACL,
105 "=> bdb_group: cannot find group: \"%s\"\n",
106 gr_ndn->bv_val, 0, 0 );
111 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
112 "bdb_group: found group (%s)\n", gr_ndn->bv_val ));
114 Debug( LDAP_DEBUG_ACL,
115 "=> bdb_group: found group: \"%s\"\n",
116 gr_ndn->bv_val, 0, 0 );
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
126 if( is_entry_alias( e ) ) {
128 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
129 "bdb_group: group (%s) is an alias\n", gr_ndn->bv_val ));
131 Debug( LDAP_DEBUG_ACL,
132 "<= bdb_group: group is an alias\n", 0, 0, 0 );
137 if( is_entry_referral( e ) ) {
139 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
140 "bdb_group: group (%s) is a referral.\n", gr_ndn->bv_val ));
142 Debug( LDAP_DEBUG_ACL,
143 "<= bdb_group: group is a referral\n", 0, 0, 0 );
148 if( !is_entry_objectclass( e, group_oc, 0 ) ) {
150 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
151 "bdb_group: failed to find %s in objectClass.\n",
154 Debug( LDAP_DEBUG_ACL,
155 "<= bdb_group: failed to find %s in objectClass\n",
156 group_oc_name, 0, 0 );
161 if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
163 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
164 "bdb_group: failed to find %s\n", group_at_name ));
166 Debug( LDAP_DEBUG_ACL,
167 "<= bdb_group: failed to find %s\n",
168 group_at_name, 0, 0 );
174 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
175 "bdb_group: found objectClass %s and %s\n",
176 group_oc_name, group_at_name ));
178 Debug( LDAP_DEBUG_ACL,
179 "<= bdb_group: found objectClass %s and %s\n",
180 group_oc_name, group_at_name, 0 );
183 if( value_find( group_at, attr->a_vals, op_ndn ) != LDAP_SUCCESS ) {
185 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
186 "bdb_group: \"%s\" not in \"%s\": %s\n",
187 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ));
189 Debug( LDAP_DEBUG_ACL,
190 "<= bdb_group: \"%s\" not in \"%s\": %s\n",
191 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
197 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
198 "bdb_group: %s is in %s: %s\n",
199 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ));
201 Debug( LDAP_DEBUG_ACL,
202 "<= bdb_group: \"%s\" is in \"%s\": %s\n",
203 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
211 bdb_cache_return_entry_r( &bdb->bi_cache, e );
215 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
216 "bdb_group: rc=%d\n", rc ));
218 Debug( LDAP_DEBUG_TRACE, "bdb_group: rc=%d\n", rc, 0, 0 );