1 /* group.c - ldbm backend acl group routine */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
13 #include <ac/string.h>
16 #include "back-ldbm.h"
17 #include "proto-back-ldbm.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 ldbminfo *li = (struct ldbminfo *) be->be_private;
41 const char *group_oc_name = NULL;
42 const char *group_at_name = group_at->ad_cname.bv_val;
44 if( group_oc->soc_names && group_oc->soc_names[0] ) {
45 group_oc_name = group_oc->soc_names[0];
47 group_oc_name = group_oc->soc_oid;
51 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
52 "ldbm_back_group: check (%s) member of (%s), oc %s\n",
53 op_ndn->bv_val, gr_ndn->bv_val, group_oc_name ));
55 Debug( LDAP_DEBUG_ARGS,
56 "=> ldbm_back_group: gr dn: \"%s\"\n",
57 gr_ndn->bv_val, 0, 0 );
59 Debug( LDAP_DEBUG_ARGS,
60 "=> ldbm_back_group: op dn: \"%s\"\n",
61 op_ndn->bv_val, 0, 0 );
62 Debug( LDAP_DEBUG_ARGS,
63 "=> ldbm_back_group: oc: \"%s\" at: \"%s\"\n",
64 group_oc_name, group_at_name, 0 );
66 Debug( LDAP_DEBUG_ARGS,
67 "=> ldbm_back_group: tr dn: \"%s\"\n",
68 target->e_ndn, 0, 0 );
71 if (strcmp(target->e_ndn, gr_ndn->bv_val) == 0) {
72 /* we already have a LOCKED copy of the entry */
75 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
76 "ldbm_back_group: target is group (%s)\n",
79 Debug( LDAP_DEBUG_ARGS,
80 "=> ldbm_back_group: target is group: \"%s\"\n",
81 gr_ndn->bv_val, 0, 0 );
86 /* can we find group entry with reader lock */
87 if ((e = dn2entry_r(be, gr_ndn->bv_val, NULL )) == NULL) {
89 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
90 "ldbm_back_group: cannot find group (%s)\n",
93 Debug( LDAP_DEBUG_ACL,
94 "=> ldbm_back_group: cannot find group: \"%s\"\n",
95 gr_ndn->bv_val, 0, 0 );
102 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
103 "ldbm_back_group: found group (%s)\n", gr_ndn->bv_val ));
105 Debug( LDAP_DEBUG_ACL,
106 "=> ldbm_back_group: found group: \"%s\"\n",
107 gr_ndn->bv_val, 0, 0 );
112 /* find it's objectClass and member attribute values
113 * make sure this is a group entry
114 * finally test if we can find op_dn in the member attribute value list *
120 if( is_entry_alias( e ) ) {
122 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
123 "ldbm_back_group: group (%s) is an alias\n",
126 Debug( LDAP_DEBUG_ACL,
127 "<= ldbm_back_group: group is an alias\n", 0, 0, 0 );
133 if( is_entry_referral( e ) ) {
135 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
136 "ldbm_back_group: group (%s) is a referral.\n",
139 Debug( LDAP_DEBUG_ACL,
140 "<= ldbm_back_group: group is an referral\n", 0, 0, 0 );
146 if( !is_entry_objectclass( e, group_oc ) ) {
148 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
149 "ldbm_back_group: failed to find %s in objectClass.\n",
152 Debug( LDAP_DEBUG_ACL,
153 "<= ldbm_back_group: failed to find %s in objectClass\n",
154 group_oc_name, 0, 0 );
160 if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
162 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
163 "ldbm_back_group: failed to find %s\n", group_at_name ));
165 Debug( LDAP_DEBUG_ACL,
166 "<= ldbm_back_group: failed to find %s\n",
167 group_at_name, 0, 0 );
174 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
175 "ldbm_back_group: found objectClass %s and %s\n",
176 group_oc_name, group_at_name ));
178 Debug( LDAP_DEBUG_ACL,
179 "<= ldbm_back_group: found objectClass %s and %s\n",
180 group_oc_name, group_at_name, 0 );
184 if( value_find( group_at, attr->a_vals, op_ndn ) != LDAP_SUCCESS ) {
186 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
187 "ldbm_back_group: \"%s\" not in \"%s\": %s\n",
188 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ));
190 Debug( LDAP_DEBUG_ACL,
191 "<= ldbm_back_group: \"%s\" not in \"%s\": %s\n",
192 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
200 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
201 "ldbm_back_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 "<= ldbm_back_group: \"%s\" is in \"%s\": %s\n",
206 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
214 /* free entry and reader lock */
215 cache_return_entry_r( &li->li_cache, e );
219 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
220 "ldbm_back_group: rc=%d\n", rc ));
222 Debug( LDAP_DEBUG_TRACE, "ldbm_back_group: rc=%d\n", rc, 0, 0 );