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 bdbinfo *li = (struct bdbinfo *) be->be_private;
41 AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
42 const char *group_oc_name = NULL;
43 const char *group_at_name = group_at->ad_cname.bv_val;
45 if( group_oc->soc_names && group_oc->soc_names[0] ) {
46 group_oc_name = group_oc->soc_names[0];
48 group_oc_name = group_oc->soc_oid;
52 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
53 "bdb_group: check (%s) member of (%s), oc %s\n",
54 op_ndn->bv_val, gr_ndn->bv_val, group_oc_name ));
56 Debug( LDAP_DEBUG_ARGS,
57 "=> bdb_group: gr dn: \"%s\"\n",
58 gr_ndn->bv_val, 0, 0 );
60 Debug( LDAP_DEBUG_ARGS,
61 "=> bdb_group: op dn: \"%s\"\n",
62 op_ndn->bv_val, 0, 0 );
63 Debug( LDAP_DEBUG_ARGS,
64 "=> bdb_group: oc: \"%s\" at: \"%s\"\n",
65 group_oc_name, group_at_name, 0 );
67 Debug( LDAP_DEBUG_ARGS,
68 "=> bdb_group: tr dn: \"%s\"\n",
69 target->e_ndn, 0, 0 );
72 if (dn_match(&target->e_name, gr_ndn)) {
73 /* we already have a LOCKED copy of the entry */
76 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
77 "bdb_group: target is group (%s)\n", gr_ndn->bv_val ));
79 Debug( LDAP_DEBUG_ARGS,
80 "=> bdb_group: target is group: \"%s\"\n",
81 gr_ndn->bv_val, 0, 0 );
84 /* can we find group entry */
85 rc = bdb_dn2entry( be, NULL, gr_ndn, &e, NULL, 0 );
91 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
92 "bdb_group: cannot find group (%s)\n",
95 Debug( LDAP_DEBUG_ACL,
96 "=> bdb_group: cannot find group: \"%s\"\n",
97 gr_ndn->bv_val, 0, 0 );
102 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
103 "bdb_group: found group (%s)\n", gr_ndn->bv_val ));
105 Debug( LDAP_DEBUG_ACL,
106 "=> bdb_group: found group: \"%s\"\n",
107 gr_ndn->bv_val, 0, 0 );
111 /* find it's objectClass and member attribute values
112 * make sure this is a group entry
113 * finally test if we can find op_dn in the member attribute value list
117 if( is_entry_alias( e ) ) {
119 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
120 "bdb_group: group (%s) is an alias\n", gr_ndn->bv_val ));
122 Debug( LDAP_DEBUG_ACL,
123 "<= bdb_group: group is an alias\n", 0, 0, 0 );
128 if( is_entry_referral( e ) ) {
130 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
131 "bdb_group: group (%s) is a referral.\n", gr_ndn->bv_val ));
133 Debug( LDAP_DEBUG_ACL,
134 "<= bdb_group: group is a referral\n", 0, 0, 0 );
139 if( !is_entry_objectclass( e, group_oc ) ) {
141 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
142 "bdb_group: failed to find %s in objectClass.\n",
145 Debug( LDAP_DEBUG_ACL,
146 "<= bdb_group: failed to find %s in objectClass\n",
147 group_oc_name, 0, 0 );
152 if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
154 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
155 "bdb_group: failed to find %s\n", group_at_name ));
157 Debug( LDAP_DEBUG_ACL,
158 "<= bdb_group: failed to find %s\n",
159 group_at_name, 0, 0 );
165 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
166 "bdb_group: found objectClass %s and %s\n",
167 group_oc_name, group_at_name ));
169 Debug( LDAP_DEBUG_ACL,
170 "<= bdb_group: found objectClass %s and %s\n",
171 group_oc_name, group_at_name, 0 );
174 if( value_find( group_at, attr->a_vals, op_ndn ) != LDAP_SUCCESS ) {
176 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
177 "bdb_group: \"%s\" not in \"%s\": %s\n",
178 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ));
180 Debug( LDAP_DEBUG_ACL,
181 "<= bdb_group: \"%s\" not in \"%s\": %s\n",
182 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
188 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
189 "bdb_group: %s is 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\" is in \"%s\": %s\n",
194 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
202 bdb_entry_return( be, e );
206 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
207 "bdb_group: rc=%d\n", rc ));
209 Debug( LDAP_DEBUG_TRACE, "bdb_group: rc=%d\n", rc, 0, 0 );