1999-02-02 01:37:43 +08:00
|
|
|
/* group.c - ldbm backend acl group routine */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-07 07:07:46 +08:00
|
|
|
/*
|
2000-05-13 10:47:56 +08:00
|
|
|
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
|
1999-08-07 07:07:46 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1998-08-21 14:33:42 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-21 14:33:42 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
1998-08-21 14:33:42 +08:00
|
|
|
#include "slap.h"
|
|
|
|
#include "back-ldbm.h"
|
1998-09-21 04:22:46 +08:00
|
|
|
#include "proto-back-ldbm.h"
|
1998-08-21 14:33:42 +08:00
|
|
|
|
|
|
|
|
1999-01-19 13:10:50 +08:00
|
|
|
/* return 0 IFF op_dn is a value in member attribute
|
|
|
|
* of entry with gr_dn AND that entry has an objectClass
|
1998-10-24 10:33:17 +08:00
|
|
|
* value of groupOfNames
|
1998-08-21 14:33:42 +08:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
ldbm_back_group(
|
1999-01-19 13:10:50 +08:00
|
|
|
Backend *be,
|
1998-12-30 11:35:23 +08:00
|
|
|
Entry *target,
|
1999-08-21 03:00:44 +08:00
|
|
|
const char *gr_ndn,
|
|
|
|
const char *op_ndn,
|
2000-05-29 00:36:34 +08:00
|
|
|
ObjectClass *group_oc,
|
2000-02-15 04:57:34 +08:00
|
|
|
AttributeDescription *group_at
|
1998-08-21 14:33:42 +08:00
|
|
|
)
|
|
|
|
{
|
1999-07-16 10:45:46 +08:00
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
|
|
|
Entry *e;
|
|
|
|
int rc = 1;
|
|
|
|
Attribute *attr;
|
2000-06-06 10:11:27 +08:00
|
|
|
struct berval bv;
|
1999-07-16 10:45:46 +08:00
|
|
|
|
2000-05-29 00:36:34 +08:00
|
|
|
AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
|
|
|
|
const char *group_oc_name = NULL;
|
|
|
|
const char *group_at_name = group_at->ad_cname->bv_val;
|
|
|
|
|
|
|
|
if( group_oc->soc_names && group_oc->soc_names[0] ) {
|
|
|
|
group_oc_name = group_oc->soc_names[0];
|
|
|
|
} else {
|
|
|
|
group_oc_name = group_oc->soc_oid;
|
|
|
|
}
|
2000-01-29 04:01:00 +08:00
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS,
|
1999-01-19 13:10:50 +08:00
|
|
|
"=> ldbm_back_group: gr dn: \"%s\"\n",
|
|
|
|
gr_ndn, 0, 0 );
|
1999-07-16 10:45:46 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS,
|
1999-01-19 13:10:50 +08:00
|
|
|
"=> ldbm_back_group: op dn: \"%s\"\n",
|
|
|
|
op_ndn, 0, 0 );
|
1999-07-16 10:45:46 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS,
|
2000-05-29 00:36:34 +08:00
|
|
|
"=> ldbm_back_group: oc: \"%s\" at: \"%s\"\n",
|
|
|
|
group_oc_name, group_at_name, 0 );
|
1999-01-19 13:10:50 +08:00
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS,
|
1999-01-19 13:10:50 +08:00
|
|
|
"=> ldbm_back_group: tr dn: \"%s\"\n",
|
|
|
|
target->e_ndn, 0, 0 );
|
|
|
|
|
|
|
|
if (strcmp(target->e_ndn, gr_ndn) == 0) {
|
1998-12-30 11:35:23 +08:00
|
|
|
/* we already have a LOCKED copy of the entry */
|
|
|
|
e = target;
|
|
|
|
Debug( LDAP_DEBUG_ARGS,
|
1999-01-19 13:10:50 +08:00
|
|
|
"=> ldbm_back_group: target is group: \"%s\"\n",
|
1999-07-16 10:45:46 +08:00
|
|
|
gr_ndn, 0, 0 );
|
|
|
|
|
1998-12-30 11:35:23 +08:00
|
|
|
} else {
|
1999-01-19 13:10:50 +08:00
|
|
|
/* can we find group entry with reader lock */
|
1999-07-16 10:45:46 +08:00
|
|
|
if ((e = dn2entry_r(be, gr_ndn, NULL )) == NULL) {
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"=> ldbm_back_group: cannot find group: \"%s\"\n",
|
|
|
|
gr_ndn, 0, 0 );
|
1998-12-30 11:35:23 +08:00
|
|
|
return( 1 );
|
|
|
|
}
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
1999-01-19 13:10:50 +08:00
|
|
|
"=> ldbm_back_group: found group: \"%s\"\n",
|
|
|
|
gr_ndn, 0, 0 );
|
1999-07-16 10:45:46 +08:00
|
|
|
}
|
1998-11-24 04:08:25 +08:00
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
/* find it's objectClass and member attribute values
|
|
|
|
* make sure this is a group entry
|
|
|
|
* finally test if we can find op_dn in the member attribute value list *
|
|
|
|
*/
|
|
|
|
|
|
|
|
rc = 1;
|
|
|
|
|
2000-06-06 10:11:27 +08:00
|
|
|
|
|
|
|
if( is_entry_alias( e ) ) {
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"<= ldbm_back_group: group is an alias\n", 0, 0, 0 );
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( is_entry_referral( e ) ) {
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"<= ldbm_back_group: group is an referral\n", 0, 0, 0 );
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2000-06-15 06:21:53 +08:00
|
|
|
if( !is_entry_objectclass( e, group_oc ) ) {
|
2000-06-06 10:11:27 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"<= ldbm_back_group: failed to find %s in objectClass\n",
|
|
|
|
group_oc_name, 0, 0 );
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"<= ldbm_back_group: failed to find %s\n",
|
|
|
|
group_at_name, 0, 0 );
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"<= ldbm_back_group: found objectClass %s and %s\n",
|
|
|
|
group_oc_name, group_at_name, 0 );
|
|
|
|
|
|
|
|
bv.bv_val = (char *) op_ndn;
|
|
|
|
bv.bv_len = strlen( op_ndn );
|
|
|
|
|
2000-06-15 07:28:28 +08:00
|
|
|
if( value_find( group_at, attr->a_vals, &bv ) != LDAP_SUCCESS ) {
|
2000-06-06 10:11:27 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"<= ldbm_back_group: \"%s\" not in \"%s\": %s\n",
|
|
|
|
op_ndn, gr_ndn, group_at_name );
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
|
2000-06-06 10:11:27 +08:00
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"<= ldbm_back_group: \"%s\" is in \"%s\": %s\n",
|
2000-05-29 00:36:34 +08:00
|
|
|
op_ndn, gr_ndn, group_at_name );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
rc = 0;
|
1998-08-21 14:33:42 +08:00
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
return_results:
|
1998-12-30 11:35:23 +08:00
|
|
|
if( target != e ) {
|
|
|
|
/* free entry and reader lock */
|
|
|
|
cache_return_entry_r( &li->li_cache, e );
|
|
|
|
}
|
1999-01-19 13:10:50 +08:00
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldbm_back_group: rc=%d\n", rc, 0, 0 );
|
1999-01-19 13:10:50 +08:00
|
|
|
return(rc);
|
1998-08-21 14:33:42 +08:00
|
|
|
}
|
|
|
|
|