2000-02-05 13:01:41 +08:00
|
|
|
/* oc.c - object class routines */
|
|
|
|
/* $OpenLDAP$ */
|
2003-11-27 09:17:14 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2008-01-08 08:19:56 +08:00
|
|
|
* Copyright 1998-2008 The OpenLDAP Foundation.
|
2003-11-27 09:17:14 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
2000-02-05 13:01:41 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
|
2000-05-29 00:36:34 +08:00
|
|
|
int is_object_subclass(
|
2002-02-10 07:55:37 +08:00
|
|
|
ObjectClass *sup,
|
|
|
|
ObjectClass *sub )
|
2000-05-29 00:36:34 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2000-06-20 00:12:57 +08:00
|
|
|
if( sub == NULL || sup == NULL ) return 0;
|
|
|
|
|
2004-04-29 04:10:21 +08:00
|
|
|
#if 0
|
2000-06-20 00:12:57 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "is_object_subclass(%s,%s) %d\n",
|
2002-02-10 07:55:37 +08:00
|
|
|
sup->soc_oid, sub->soc_oid, sup == sub );
|
2000-06-20 00:12:57 +08:00
|
|
|
#endif
|
|
|
|
|
2007-03-20 09:07:10 +08:00
|
|
|
if ( sup == sub ) {
|
2000-05-29 00:36:34 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-03-20 09:07:10 +08:00
|
|
|
if ( sub->soc_sups == NULL ) {
|
2000-05-29 00:36:34 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-20 09:07:10 +08:00
|
|
|
for ( i = 0; sub->soc_sups[i] != NULL; i++ ) {
|
|
|
|
if ( is_object_subclass( sup, sub->soc_sups[i] ) ) {
|
2000-05-29 00:36:34 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
int is_entry_objectclass(
|
|
|
|
Entry* e,
|
2002-01-19 10:58:00 +08:00
|
|
|
ObjectClass *oc,
|
2005-08-21 03:01:53 +08:00
|
|
|
unsigned flags )
|
2000-02-05 13:01:41 +08:00
|
|
|
{
|
2003-01-03 07:55:37 +08:00
|
|
|
/*
|
|
|
|
* set_flags should only be true if oc is one of operational
|
|
|
|
* object classes which we support objectClass flags for
|
|
|
|
* (e.g., referral, alias, ...). See <slap.h>.
|
|
|
|
*/
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
Attribute *attr;
|
2002-01-02 19:00:36 +08:00
|
|
|
struct berval *bv;
|
2003-01-03 07:55:37 +08:00
|
|
|
|
2005-08-21 03:01:53 +08:00
|
|
|
assert( !( e == NULL || oc == NULL ) );
|
|
|
|
assert( ( flags & SLAP_OCF_MASK ) != SLAP_OCF_MASK );
|
2000-05-19 10:44:47 +08:00
|
|
|
|
2007-03-20 09:07:10 +08:00
|
|
|
if ( e == NULL || oc == NULL ) {
|
2000-02-05 13:01:41 +08:00
|
|
|
return 0;
|
2000-05-19 10:44:47 +08:00
|
|
|
}
|
2000-02-05 13:01:41 +08:00
|
|
|
|
2007-03-20 09:07:10 +08:00
|
|
|
if ( flags == SLAP_OCF_SET_FLAGS && ( e->e_ocflags & SLAP_OC__END ) )
|
2005-08-21 03:01:53 +08:00
|
|
|
{
|
2003-01-03 07:55:37 +08:00
|
|
|
/* flags are set, use them */
|
2003-01-23 06:01:21 +08:00
|
|
|
return (e->e_ocflags & oc->soc_flags & SLAP_OC__MASK) != 0;
|
2002-01-19 10:58:00 +08:00
|
|
|
}
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
/*
|
|
|
|
* find objectClass attribute
|
|
|
|
*/
|
2005-08-21 03:01:53 +08:00
|
|
|
attr = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
|
2007-03-20 09:07:10 +08:00
|
|
|
if ( attr == NULL ) {
|
2000-02-05 13:01:41 +08:00
|
|
|
/* no objectClass attribute */
|
2000-05-19 10:44:47 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "is_entry_objectclass(\"%s\", \"%s\") "
|
|
|
|
"no objectClass attribute\n",
|
2000-06-07 22:07:50 +08:00
|
|
|
e->e_dn == NULL ? "" : e->e_dn,
|
|
|
|
oc->soc_oclass.oc_oid, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-20 09:07:10 +08:00
|
|
|
for ( bv = attr->a_vals; bv->bv_val; bv++ ) {
|
2002-01-02 19:00:36 +08:00
|
|
|
ObjectClass *objectClass = oc_bvfind( bv );
|
2000-05-22 06:46:51 +08:00
|
|
|
|
2005-08-21 03:01:53 +08:00
|
|
|
if ( objectClass == NULL ) {
|
|
|
|
/* FIXME: is this acceptable? */
|
|
|
|
continue;
|
2000-05-22 06:46:51 +08:00
|
|
|
}
|
2005-08-21 03:01:53 +08:00
|
|
|
|
|
|
|
if ( !( flags & SLAP_OCF_SET_FLAGS ) ) {
|
|
|
|
if ( objectClass == oc ) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ( flags & SLAP_OCF_CHECK_SUP )
|
|
|
|
&& is_object_subclass( oc, objectClass ) )
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2002-01-31 22:10:19 +08:00
|
|
|
}
|
2005-08-21 03:01:53 +08:00
|
|
|
|
|
|
|
e->e_ocflags |= objectClass->soc_flags;
|
2002-01-19 10:58:00 +08:00
|
|
|
}
|
2000-05-22 06:46:51 +08:00
|
|
|
|
2003-01-03 07:55:37 +08:00
|
|
|
/* mark flags as set */
|
|
|
|
e->e_ocflags |= SLAP_OC__END;
|
|
|
|
|
2005-08-21 03:01:53 +08:00
|
|
|
return ( e->e_ocflags & oc->soc_flags & SLAP_OC__MASK ) != 0;
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct oindexrec {
|
2003-03-17 02:10:16 +08:00
|
|
|
struct berval oir_name;
|
2000-02-05 13:01:41 +08:00
|
|
|
ObjectClass *oir_oc;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Avlnode *oc_index = NULL;
|
2005-01-23 04:18:38 +08:00
|
|
|
static Avlnode *oc_cache = NULL;
|
2007-03-20 09:07:10 +08:00
|
|
|
static LDAP_STAILQ_HEAD(OCList, ObjectClass) oc_list
|
2005-03-21 16:31:48 +08:00
|
|
|
= LDAP_STAILQ_HEAD_INITIALIZER(oc_list);
|
2006-11-18 06:52:20 +08:00
|
|
|
|
|
|
|
ObjectClass *oc_sys_tail;
|
2000-02-05 13:01:41 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
oc_index_cmp(
|
2002-12-15 06:25:52 +08:00
|
|
|
const void *v_oir1,
|
|
|
|
const void *v_oir2 )
|
2000-02-05 13:01:41 +08:00
|
|
|
{
|
2002-12-15 06:25:52 +08:00
|
|
|
const struct oindexrec *oir1 = v_oir1, *oir2 = v_oir2;
|
2001-12-28 19:45:25 +08:00
|
|
|
int i = oir1->oir_name.bv_len - oir2->oir_name.bv_len;
|
2004-04-29 04:10:21 +08:00
|
|
|
if (i) return i;
|
2001-12-28 19:45:25 +08:00
|
|
|
return strcasecmp( oir1->oir_name.bv_val, oir2->oir_name.bv_val );
|
2001-12-26 12:17:49 +08:00
|
|
|
}
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
static int
|
|
|
|
oc_index_name_cmp(
|
2002-12-15 06:25:52 +08:00
|
|
|
const void *v_name,
|
|
|
|
const void *v_oir )
|
2000-02-05 13:01:41 +08:00
|
|
|
{
|
2002-12-15 06:25:52 +08:00
|
|
|
const struct berval *name = v_name;
|
|
|
|
const struct oindexrec *oir = v_oir;
|
2001-12-28 19:45:25 +08:00
|
|
|
int i = name->bv_len - oir->oir_name.bv_len;
|
2004-04-29 04:10:21 +08:00
|
|
|
if (i) return i;
|
2001-12-28 19:45:25 +08:00
|
|
|
return strncasecmp( name->bv_val, oir->oir_name.bv_val, name->bv_len );
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjectClass *
|
|
|
|
oc_find( const char *ocname )
|
|
|
|
{
|
2001-12-28 19:45:25 +08:00
|
|
|
struct berval bv;
|
2000-05-28 01:05:28 +08:00
|
|
|
|
2001-12-28 19:45:25 +08:00
|
|
|
bv.bv_val = (char *)ocname;
|
|
|
|
bv.bv_len = strlen( ocname );
|
2000-05-28 01:05:28 +08:00
|
|
|
|
2001-12-28 19:45:25 +08:00
|
|
|
return( oc_bvfind( &bv ) );
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
|
|
|
|
2001-12-26 12:17:49 +08:00
|
|
|
ObjectClass *
|
|
|
|
oc_bvfind( struct berval *ocname )
|
|
|
|
{
|
|
|
|
struct oindexrec *oir;
|
|
|
|
|
2005-01-23 04:18:38 +08:00
|
|
|
if ( oc_cache ) {
|
|
|
|
oir = avl_find( oc_cache, ocname, oc_index_name_cmp );
|
|
|
|
if ( oir ) return oir->oir_oc;
|
|
|
|
}
|
2002-12-15 06:25:52 +08:00
|
|
|
oir = avl_find( oc_index, ocname, oc_index_name_cmp );
|
2001-12-26 12:17:49 +08:00
|
|
|
|
|
|
|
if ( oir != NULL ) {
|
2005-01-23 04:18:38 +08:00
|
|
|
if ( at_oc_cache ) {
|
|
|
|
avl_insert( &oc_cache, (caddr_t) oir,
|
|
|
|
oc_index_cmp, avl_dup_error );
|
|
|
|
}
|
2001-12-26 12:17:49 +08:00
|
|
|
return( oir->oir_oc );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
2007-03-20 09:07:10 +08:00
|
|
|
static LDAP_STAILQ_HEAD(OCUList, ObjectClass) oc_undef_list
|
2005-03-21 16:31:48 +08:00
|
|
|
= LDAP_STAILQ_HEAD_INITIALIZER(oc_undef_list);
|
2004-12-02 05:47:13 +08:00
|
|
|
|
|
|
|
ObjectClass *
|
|
|
|
oc_bvfind_undef( struct berval *ocname )
|
|
|
|
{
|
|
|
|
ObjectClass *oc = oc_bvfind( ocname );
|
|
|
|
|
|
|
|
if ( oc ) {
|
|
|
|
return oc;
|
|
|
|
}
|
|
|
|
|
2005-03-21 16:31:48 +08:00
|
|
|
LDAP_STAILQ_FOREACH( oc, &oc_undef_list, soc_next ) {
|
2004-12-02 05:47:13 +08:00
|
|
|
int d = oc->soc_cname.bv_len - ocname->bv_len;
|
|
|
|
|
|
|
|
if ( d ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcasecmp( oc->soc_cname.bv_val, ocname->bv_val ) == 0 ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( oc ) {
|
|
|
|
return oc;
|
|
|
|
}
|
|
|
|
|
|
|
|
oc = ch_malloc( sizeof( ObjectClass ) + ocname->bv_len + 1 );
|
|
|
|
memset( oc, 0, sizeof( ObjectClass ) );
|
|
|
|
|
|
|
|
oc->soc_cname.bv_len = ocname->bv_len;
|
|
|
|
oc->soc_cname.bv_val = (char *)&oc[ 1 ];
|
|
|
|
AC_MEMCPY( oc->soc_cname.bv_val, ocname->bv_val, ocname->bv_len );
|
|
|
|
|
2008-09-04 16:05:17 +08:00
|
|
|
/* canonical to upper case */
|
|
|
|
ldap_pvt_str2upper( oc->soc_cname.bv_val );
|
|
|
|
|
2005-03-21 16:31:48 +08:00
|
|
|
LDAP_STAILQ_NEXT( oc, soc_next ) = NULL;
|
2005-08-22 17:46:17 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &oc_undef_mutex );
|
2005-03-21 16:31:48 +08:00
|
|
|
LDAP_STAILQ_INSERT_HEAD( &oc_undef_list, oc, soc_next );
|
2005-08-22 17:46:17 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &oc_undef_mutex );
|
2004-12-02 05:47:13 +08:00
|
|
|
|
|
|
|
return oc;
|
|
|
|
}
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
static int
|
|
|
|
oc_create_required(
|
2005-09-09 04:46:48 +08:00
|
|
|
ObjectClass *soc,
|
|
|
|
char **attrs,
|
2002-05-30 13:23:37 +08:00
|
|
|
int *op,
|
2005-09-09 04:46:48 +08:00
|
|
|
const char **err )
|
2000-02-05 13:01:41 +08:00
|
|
|
{
|
|
|
|
char **attrs1;
|
|
|
|
AttributeType *sat;
|
|
|
|
AttributeType **satp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if ( attrs ) {
|
|
|
|
attrs1 = attrs;
|
|
|
|
while ( *attrs1 ) {
|
|
|
|
sat = at_find(*attrs1);
|
|
|
|
if ( !sat ) {
|
|
|
|
*err = *attrs1;
|
|
|
|
return SLAP_SCHERR_ATTR_NOT_FOUND;
|
|
|
|
}
|
2002-05-30 13:23:37 +08:00
|
|
|
|
|
|
|
if( is_at_operational( sat )) (*op)++;
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
if ( at_find_in_list(sat, soc->soc_required) < 0) {
|
|
|
|
if ( at_append_to_list(sat, &soc->soc_required) ) {
|
|
|
|
*err = *attrs1;
|
|
|
|
return SLAP_SCHERR_OUTOFMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
attrs1++;
|
|
|
|
}
|
|
|
|
/* Now delete duplicates from the allowed list */
|
|
|
|
for ( satp = soc->soc_required; *satp; satp++ ) {
|
2005-09-09 04:46:48 +08:00
|
|
|
i = at_find_in_list(*satp, soc->soc_allowed);
|
2000-02-05 13:01:41 +08:00
|
|
|
if ( i >= 0 ) {
|
|
|
|
at_delete_from_list(i, &soc->soc_allowed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
oc_create_allowed(
|
|
|
|
ObjectClass *soc,
|
|
|
|
char **attrs,
|
2002-05-30 13:23:37 +08:00
|
|
|
int *op,
|
2000-06-20 00:12:57 +08:00
|
|
|
const char **err )
|
2000-02-05 13:01:41 +08:00
|
|
|
{
|
|
|
|
char **attrs1;
|
|
|
|
AttributeType *sat;
|
|
|
|
|
|
|
|
if ( attrs ) {
|
|
|
|
attrs1 = attrs;
|
|
|
|
while ( *attrs1 ) {
|
|
|
|
sat = at_find(*attrs1);
|
|
|
|
if ( !sat ) {
|
|
|
|
*err = *attrs1;
|
|
|
|
return SLAP_SCHERR_ATTR_NOT_FOUND;
|
|
|
|
}
|
2002-05-30 13:23:37 +08:00
|
|
|
|
|
|
|
if( is_at_operational( sat )) (*op)++;
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
if ( at_find_in_list(sat, soc->soc_required) < 0 &&
|
|
|
|
at_find_in_list(sat, soc->soc_allowed) < 0 ) {
|
|
|
|
if ( at_append_to_list(sat, &soc->soc_allowed) ) {
|
|
|
|
*err = *attrs1;
|
|
|
|
return SLAP_SCHERR_OUTOFMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
attrs1++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
oc_add_sups(
|
2005-09-09 04:46:48 +08:00
|
|
|
ObjectClass *soc,
|
|
|
|
char **sups,
|
2002-05-30 13:23:37 +08:00
|
|
|
int *op,
|
2005-09-09 04:46:48 +08:00
|
|
|
const char **err )
|
2000-02-05 13:01:41 +08:00
|
|
|
{
|
|
|
|
int code;
|
|
|
|
ObjectClass *soc1;
|
|
|
|
int nsups;
|
2001-01-22 16:09:25 +08:00
|
|
|
char **sups1;
|
2000-02-05 13:01:41 +08:00
|
|
|
int add_sups = 0;
|
|
|
|
|
|
|
|
if ( sups ) {
|
|
|
|
if ( !soc->soc_sups ) {
|
|
|
|
/* We are at the first recursive level */
|
|
|
|
add_sups = 1;
|
2001-01-22 16:09:25 +08:00
|
|
|
nsups = 1;
|
2000-02-05 13:01:41 +08:00
|
|
|
sups1 = sups;
|
|
|
|
while ( *sups1 ) {
|
|
|
|
nsups++;
|
|
|
|
sups1++;
|
|
|
|
}
|
2000-03-10 03:15:48 +08:00
|
|
|
soc->soc_sups = (ObjectClass **)ch_calloc(nsups,
|
|
|
|
sizeof(ObjectClass *));
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
2001-01-22 16:09:25 +08:00
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
nsups = 0;
|
|
|
|
sups1 = sups;
|
|
|
|
while ( *sups1 ) {
|
|
|
|
soc1 = oc_find(*sups1);
|
|
|
|
if ( !soc1 ) {
|
|
|
|
*err = *sups1;
|
|
|
|
return SLAP_SCHERR_CLASS_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2001-01-22 16:09:25 +08:00
|
|
|
/* check object class usage
|
|
|
|
* abstract classes can only sup abstract classes
|
|
|
|
* structural classes can not sup auxiliary classes
|
|
|
|
* auxiliary classes can not sup structural classes
|
|
|
|
*/
|
|
|
|
if( soc->soc_kind != soc1->soc_kind
|
|
|
|
&& soc1->soc_kind != LDAP_SCHEMA_ABSTRACT )
|
|
|
|
{
|
|
|
|
*err = *sups1;
|
2002-10-10 03:24:02 +08:00
|
|
|
return SLAP_SCHERR_CLASS_BAD_SUP;
|
2001-01-22 16:09:25 +08:00
|
|
|
}
|
|
|
|
|
2002-10-10 10:07:24 +08:00
|
|
|
if( soc1->soc_obsolete && !soc->soc_obsolete ) {
|
|
|
|
*err = *sups1;
|
|
|
|
return SLAP_SCHERR_CLASS_BAD_SUP;
|
|
|
|
}
|
|
|
|
|
2002-05-30 13:23:37 +08:00
|
|
|
if( soc->soc_flags & SLAP_OC_OPERATIONAL ) (*op)++;
|
|
|
|
|
|
|
|
if ( add_sups ) {
|
2000-02-05 13:01:41 +08:00
|
|
|
soc->soc_sups[nsups] = soc1;
|
2002-05-30 13:23:37 +08:00
|
|
|
}
|
2000-02-05 13:01:41 +08:00
|
|
|
|
2002-05-30 13:23:37 +08:00
|
|
|
code = oc_add_sups( soc, soc1->soc_sup_oids, op, err );
|
2000-06-20 00:12:57 +08:00
|
|
|
if ( code ) return code;
|
|
|
|
|
2002-05-30 13:23:37 +08:00
|
|
|
code = oc_create_required( soc, soc1->soc_at_oids_must, op, err );
|
2000-06-20 00:12:57 +08:00
|
|
|
if ( code ) return code;
|
2000-02-05 13:01:41 +08:00
|
|
|
|
2002-05-30 13:23:37 +08:00
|
|
|
code = oc_create_allowed( soc, soc1->soc_at_oids_may, op, err );
|
2000-06-20 00:12:57 +08:00
|
|
|
if ( code ) return code;
|
2000-02-05 13:01:41 +08:00
|
|
|
|
|
|
|
nsups++;
|
|
|
|
sups1++;
|
|
|
|
}
|
|
|
|
}
|
2001-01-22 16:09:25 +08:00
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:06:04 +08:00
|
|
|
static void
|
|
|
|
oc_delete_names( ObjectClass *oc )
|
|
|
|
{
|
|
|
|
char **names = oc->soc_names;
|
|
|
|
|
|
|
|
while (*names) {
|
|
|
|
struct oindexrec tmpoir, *oir;
|
|
|
|
|
|
|
|
ber_str2bv( *names, 0, 0, &tmpoir.oir_name );
|
|
|
|
tmpoir.oir_oc = oc;
|
|
|
|
oir = (struct oindexrec *)avl_delete( &oc_index,
|
|
|
|
(caddr_t)&tmpoir, oc_index_cmp );
|
|
|
|
assert( oir != NULL );
|
|
|
|
ldap_memfree( oir );
|
|
|
|
names++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark the ObjectClass as deleted, remove from list, and remove all its
|
|
|
|
* names from the AVL tree. Leave the OID in the tree.
|
|
|
|
*/
|
2006-09-14 08:14:27 +08:00
|
|
|
void
|
2006-09-14 08:06:04 +08:00
|
|
|
oc_delete( ObjectClass *oc )
|
|
|
|
{
|
|
|
|
oc->soc_flags |= SLAP_OC_DELETED;
|
|
|
|
|
2007-03-20 09:07:10 +08:00
|
|
|
LDAP_STAILQ_REMOVE(&oc_list, oc, ObjectClass, soc_next);
|
2006-09-14 08:06:04 +08:00
|
|
|
|
|
|
|
oc_delete_names( oc );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
oc_clean( ObjectClass *o )
|
|
|
|
{
|
2007-02-07 22:54:57 +08:00
|
|
|
if (o->soc_sups) {
|
|
|
|
ldap_memfree(o->soc_sups);
|
|
|
|
o->soc_sups = NULL;
|
|
|
|
}
|
|
|
|
if (o->soc_required) {
|
|
|
|
ldap_memfree(o->soc_required);
|
|
|
|
o->soc_required = NULL;
|
|
|
|
}
|
|
|
|
if (o->soc_allowed) {
|
|
|
|
ldap_memfree(o->soc_allowed);
|
|
|
|
o->soc_allowed = NULL;
|
|
|
|
}
|
|
|
|
if (o->soc_oidmacro) {
|
|
|
|
ldap_memfree(o->soc_oidmacro);
|
|
|
|
o->soc_oidmacro = NULL;
|
|
|
|
}
|
2006-09-14 08:06:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
oc_destroy_one( void *v )
|
|
|
|
{
|
|
|
|
struct oindexrec *oir = v;
|
|
|
|
ObjectClass *o = oir->oir_oc;
|
|
|
|
|
|
|
|
oc_clean( o );
|
|
|
|
ldap_objectclass_free((LDAPObjectClass *)o);
|
|
|
|
ldap_memfree(oir);
|
|
|
|
}
|
|
|
|
|
2001-11-07 09:03:49 +08:00
|
|
|
void
|
|
|
|
oc_destroy( void )
|
|
|
|
{
|
2003-01-21 04:21:17 +08:00
|
|
|
ObjectClass *o;
|
2001-11-07 09:03:49 +08:00
|
|
|
|
2005-03-21 16:31:48 +08:00
|
|
|
while( !LDAP_STAILQ_EMPTY(&oc_list) ) {
|
|
|
|
o = LDAP_STAILQ_FIRST(&oc_list);
|
|
|
|
LDAP_STAILQ_REMOVE_HEAD(&oc_list, soc_next);
|
2003-01-21 04:21:17 +08:00
|
|
|
|
2006-09-14 08:06:04 +08:00
|
|
|
oc_delete_names( o );
|
2001-11-07 09:03:49 +08:00
|
|
|
}
|
2004-12-02 05:47:13 +08:00
|
|
|
|
2006-09-14 08:06:04 +08:00
|
|
|
avl_free( oc_index, oc_destroy_one );
|
|
|
|
|
2005-03-21 16:31:48 +08:00
|
|
|
while( !LDAP_STAILQ_EMPTY(&oc_undef_list) ) {
|
|
|
|
o = LDAP_STAILQ_FIRST(&oc_undef_list);
|
|
|
|
LDAP_STAILQ_REMOVE_HEAD(&oc_undef_list, soc_next);
|
2004-12-02 05:47:13 +08:00
|
|
|
|
|
|
|
ch_free( (ObjectClass *)o );
|
|
|
|
}
|
2001-11-07 09:03:49 +08:00
|
|
|
}
|
|
|
|
|
2006-09-14 08:06:04 +08:00
|
|
|
int
|
|
|
|
oc_start( ObjectClass **oc )
|
|
|
|
{
|
|
|
|
assert( oc != NULL );
|
|
|
|
|
|
|
|
*oc = LDAP_STAILQ_FIRST(&oc_list);
|
|
|
|
|
|
|
|
return (*oc != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
oc_next( ObjectClass **oc )
|
|
|
|
{
|
|
|
|
assert( oc != NULL );
|
|
|
|
|
2007-02-07 22:54:57 +08:00
|
|
|
#if 0 /* pedantic check: breaks when deleting an oc, don't use it. */
|
2006-09-14 08:06:04 +08:00
|
|
|
{
|
|
|
|
ObjectClass *tmp = NULL;
|
|
|
|
|
|
|
|
LDAP_STAILQ_FOREACH(tmp,&oc_list,soc_next) {
|
|
|
|
if ( tmp == *oc ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert( tmp != NULL );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-02-26 00:18:36 +08:00
|
|
|
if ( *oc == NULL ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:06:04 +08:00
|
|
|
*oc = LDAP_STAILQ_NEXT(*oc,soc_next);
|
|
|
|
|
|
|
|
return (*oc != NULL);
|
|
|
|
}
|
|
|
|
|
2005-04-10 23:40:15 +08:00
|
|
|
/*
|
|
|
|
* check whether the two ObjectClasses actually __are__ identical,
|
|
|
|
* or rather inconsistent
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
oc_check_dup(
|
|
|
|
ObjectClass *soc,
|
|
|
|
ObjectClass *new_soc )
|
|
|
|
{
|
|
|
|
if ( new_soc->soc_oid != NULL ) {
|
|
|
|
if ( soc->soc_oid == NULL ) {
|
|
|
|
return SLAP_SCHERR_CLASS_INCONSISTENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcmp( soc->soc_oid, new_soc->soc_oid ) != 0 ) {
|
|
|
|
return SLAP_SCHERR_CLASS_INCONSISTENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if ( soc->soc_oid != NULL ) {
|
|
|
|
return SLAP_SCHERR_CLASS_INCONSISTENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( new_soc->soc_names ) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if ( soc->soc_names == NULL ) {
|
|
|
|
return SLAP_SCHERR_CLASS_INCONSISTENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = 0; new_soc->soc_names[ i ]; i++ ) {
|
|
|
|
if ( soc->soc_names[ i ] == NULL ) {
|
|
|
|
return SLAP_SCHERR_CLASS_INCONSISTENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcasecmp( soc->soc_names[ i ],
|
|
|
|
new_soc->soc_names[ i ] ) != 0 )
|
|
|
|
{
|
|
|
|
return SLAP_SCHERR_CLASS_INCONSISTENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( soc->soc_names != NULL ) {
|
|
|
|
return SLAP_SCHERR_CLASS_INCONSISTENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SLAP_SCHERR_CLASS_DUP;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:06:04 +08:00
|
|
|
static struct oindexrec *oir_old;
|
|
|
|
|
|
|
|
static int
|
|
|
|
oc_dup_error( void *left, void *right )
|
|
|
|
{
|
|
|
|
oir_old = left;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
static int
|
|
|
|
oc_insert(
|
2006-09-14 08:06:04 +08:00
|
|
|
ObjectClass **roc,
|
|
|
|
ObjectClass *prev,
|
2004-04-29 04:10:21 +08:00
|
|
|
const char **err )
|
2000-02-05 13:01:41 +08:00
|
|
|
{
|
|
|
|
struct oindexrec *oir;
|
|
|
|
char **names;
|
2006-09-14 08:06:04 +08:00
|
|
|
ObjectClass *soc = *roc;
|
2000-02-05 13:01:41 +08:00
|
|
|
|
|
|
|
if ( soc->soc_oid ) {
|
|
|
|
oir = (struct oindexrec *)
|
|
|
|
ch_calloc( 1, sizeof(struct oindexrec) );
|
2006-09-14 08:06:04 +08:00
|
|
|
ber_str2bv( soc->soc_oid, 0, 0, &oir->oir_name );
|
2000-02-05 13:01:41 +08:00
|
|
|
oir->oir_oc = soc;
|
2006-09-14 08:06:04 +08:00
|
|
|
oir_old = NULL;
|
2000-05-28 01:05:28 +08:00
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
if ( avl_insert( &oc_index, (caddr_t) oir,
|
2006-09-14 08:06:04 +08:00
|
|
|
oc_index_cmp, oc_dup_error ) )
|
2000-05-28 01:05:28 +08:00
|
|
|
{
|
2005-04-10 23:40:15 +08:00
|
|
|
ObjectClass *old_soc;
|
|
|
|
int rc;
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
*err = soc->soc_oid;
|
2005-04-10 23:40:15 +08:00
|
|
|
|
2006-09-14 08:06:04 +08:00
|
|
|
assert( oir_old != NULL );
|
|
|
|
old_soc = oir_old->oir_oc;
|
|
|
|
|
|
|
|
/* replacing a deleted definition? */
|
|
|
|
if ( old_soc->soc_flags & SLAP_OC_DELETED ) {
|
|
|
|
ObjectClass tmp;
|
|
|
|
|
|
|
|
/* Keep old oid, free new oid;
|
|
|
|
* Keep new everything else, free old
|
|
|
|
*/
|
|
|
|
tmp = *old_soc;
|
|
|
|
*old_soc = *soc;
|
|
|
|
old_soc->soc_oid = tmp.soc_oid;
|
|
|
|
tmp.soc_oid = soc->soc_oid;
|
|
|
|
*soc = tmp;
|
|
|
|
|
|
|
|
oc_clean( soc );
|
|
|
|
oc_destroy_one( oir );
|
|
|
|
|
|
|
|
oir = oir_old;
|
|
|
|
soc = old_soc;
|
|
|
|
*roc = soc;
|
|
|
|
} else {
|
|
|
|
rc = oc_check_dup( old_soc, soc );
|
2005-04-10 23:40:15 +08:00
|
|
|
|
2006-09-14 08:06:04 +08:00
|
|
|
ldap_memfree( oir );
|
|
|
|
return rc;
|
|
|
|
}
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
2000-05-28 01:05:28 +08:00
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
/* FIX: temporal consistency check */
|
2005-04-10 23:40:15 +08:00
|
|
|
assert( oc_bvfind( &oir->oir_name ) != NULL );
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
2000-05-28 01:05:28 +08:00
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
if ( (names = soc->soc_names) ) {
|
|
|
|
while ( *names ) {
|
|
|
|
oir = (struct oindexrec *)
|
|
|
|
ch_calloc( 1, sizeof(struct oindexrec) );
|
2001-12-28 19:45:25 +08:00
|
|
|
oir->oir_name.bv_val = *names;
|
|
|
|
oir->oir_name.bv_len = strlen( *names );
|
2000-02-05 13:01:41 +08:00
|
|
|
oir->oir_oc = soc;
|
2000-05-28 01:05:28 +08:00
|
|
|
|
2005-07-18 14:22:33 +08:00
|
|
|
assert( oir->oir_name.bv_val != NULL );
|
|
|
|
assert( oir->oir_oc != NULL );
|
2000-05-28 01:05:28 +08:00
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
if ( avl_insert( &oc_index, (caddr_t) oir,
|
2004-04-29 04:10:21 +08:00
|
|
|
oc_index_cmp, avl_dup_error ) )
|
2000-05-28 01:05:28 +08:00
|
|
|
{
|
2005-04-10 23:40:15 +08:00
|
|
|
ObjectClass *old_soc;
|
|
|
|
int rc;
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
*err = *names;
|
2005-04-10 23:40:15 +08:00
|
|
|
|
|
|
|
old_soc = oc_bvfind( &oir->oir_name );
|
|
|
|
assert( old_soc != NULL );
|
|
|
|
rc = oc_check_dup( old_soc, soc );
|
|
|
|
|
|
|
|
ldap_memfree( oir );
|
2005-11-19 08:33:19 +08:00
|
|
|
|
|
|
|
while ( names > soc->soc_names ) {
|
|
|
|
struct oindexrec tmpoir;
|
|
|
|
|
|
|
|
names--;
|
|
|
|
ber_str2bv( *names, 0, 0, &tmpoir.oir_name );
|
|
|
|
tmpoir.oir_oc = soc;
|
|
|
|
oir = (struct oindexrec *)avl_delete( &oc_index,
|
|
|
|
(caddr_t)&tmpoir, oc_index_cmp );
|
|
|
|
assert( oir != NULL );
|
|
|
|
ldap_memfree( oir );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( soc->soc_oid ) {
|
|
|
|
struct oindexrec tmpoir;
|
|
|
|
|
|
|
|
ber_str2bv( soc->soc_oid, 0, 0, &tmpoir.oir_name );
|
|
|
|
tmpoir.oir_oc = soc;
|
|
|
|
oir = (struct oindexrec *)avl_delete( &oc_index,
|
|
|
|
(caddr_t)&tmpoir, oc_index_cmp );
|
|
|
|
assert( oir != NULL );
|
|
|
|
ldap_memfree( oir );
|
|
|
|
}
|
|
|
|
|
2005-04-10 23:40:15 +08:00
|
|
|
return rc;
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
2000-05-28 01:05:28 +08:00
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
/* FIX: temporal consistency check */
|
2001-12-28 19:45:25 +08:00
|
|
|
assert( oc_bvfind(&oir->oir_name) != NULL );
|
2000-05-28 01:05:28 +08:00
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
names++;
|
|
|
|
}
|
|
|
|
}
|
2006-11-18 04:11:11 +08:00
|
|
|
if ( soc->soc_flags & SLAP_OC_HARDCODE ) {
|
|
|
|
prev = oc_sys_tail;
|
|
|
|
oc_sys_tail = soc;
|
|
|
|
}
|
|
|
|
if ( prev ) {
|
|
|
|
LDAP_STAILQ_INSERT_AFTER( &oc_list, prev, soc, soc_next );
|
|
|
|
} else {
|
|
|
|
LDAP_STAILQ_INSERT_TAIL( &oc_list, soc, soc_next );
|
|
|
|
}
|
2005-03-21 16:31:48 +08:00
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
oc_add(
|
2000-07-23 01:30:44 +08:00
|
|
|
LDAPObjectClass *oc,
|
2002-05-30 13:23:37 +08:00
|
|
|
int user,
|
2005-03-21 16:31:48 +08:00
|
|
|
ObjectClass **rsoc,
|
2006-09-14 08:06:04 +08:00
|
|
|
ObjectClass *prev,
|
2004-04-29 04:10:21 +08:00
|
|
|
const char **err )
|
2000-02-05 13:01:41 +08:00
|
|
|
{
|
|
|
|
ObjectClass *soc;
|
|
|
|
int code;
|
2002-05-30 13:23:37 +08:00
|
|
|
int op = 0;
|
2005-04-10 00:13:04 +08:00
|
|
|
char *oidm = NULL;
|
2000-02-05 13:01:41 +08:00
|
|
|
|
2001-06-08 06:47:02 +08:00
|
|
|
if ( oc->oc_names != NULL ) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for( i=0; oc->oc_names[i]; i++ ) {
|
|
|
|
if( !slap_valid_descr( oc->oc_names[i] ) ) {
|
|
|
|
return SLAP_SCHERR_BAD_DESCR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-10 13:31:49 +08:00
|
|
|
if ( !OID_LEADCHAR( oc->oc_oid[0] )) {
|
|
|
|
/* Expand OID macros */
|
|
|
|
char *oid = oidm_find( oc->oc_oid );
|
|
|
|
if ( !oid ) {
|
|
|
|
*err = oc->oc_oid;
|
|
|
|
return SLAP_SCHERR_OIDM;
|
|
|
|
}
|
|
|
|
if ( oid != oc->oc_oid ) {
|
2005-04-10 00:13:04 +08:00
|
|
|
oidm = oc->oc_oid;
|
2002-01-10 13:31:49 +08:00
|
|
|
oc->oc_oid = oid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
soc = (ObjectClass *) ch_calloc( 1, sizeof(ObjectClass) );
|
2000-07-28 09:07:07 +08:00
|
|
|
AC_MEMCPY( &soc->soc_oclass, oc, sizeof(LDAPObjectClass) );
|
2000-06-20 00:12:57 +08:00
|
|
|
|
2005-04-10 00:13:04 +08:00
|
|
|
soc->soc_oidmacro = oidm;
|
2002-08-29 09:12:59 +08:00
|
|
|
if( oc->oc_names != NULL ) {
|
|
|
|
soc->soc_cname.bv_val = soc->soc_names[0];
|
|
|
|
} else {
|
|
|
|
soc->soc_cname.bv_val = soc->soc_oid;
|
|
|
|
}
|
|
|
|
soc->soc_cname.bv_len = strlen( soc->soc_cname.bv_val );
|
|
|
|
|
2000-06-20 00:12:57 +08:00
|
|
|
if( soc->soc_sup_oids == NULL &&
|
|
|
|
soc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
|
|
|
|
{
|
|
|
|
/* structural object classes implicitly inherit from 'top' */
|
|
|
|
static char *top_oids[] = { SLAPD_TOP_OID, NULL };
|
2002-05-30 13:23:37 +08:00
|
|
|
code = oc_add_sups( soc, top_oids, &op, err );
|
2000-06-20 00:12:57 +08:00
|
|
|
} else {
|
2002-05-30 13:23:37 +08:00
|
|
|
code = oc_add_sups( soc, soc->soc_sup_oids, &op, err );
|
2000-06-20 00:12:57 +08:00
|
|
|
}
|
2001-01-22 16:09:25 +08:00
|
|
|
|
2005-09-09 04:46:48 +08:00
|
|
|
if ( code != 0 ) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( user && op ) {
|
|
|
|
code = SLAP_SCHERR_CLASS_BAD_SUP;
|
|
|
|
goto done;
|
|
|
|
}
|
2000-06-20 00:12:57 +08:00
|
|
|
|
2002-05-30 13:23:37 +08:00
|
|
|
code = oc_create_required( soc, soc->soc_at_oids_must, &op, err );
|
2005-09-09 04:46:48 +08:00
|
|
|
if ( code != 0 ) {
|
|
|
|
goto done;
|
|
|
|
}
|
2000-06-20 00:12:57 +08:00
|
|
|
|
2002-05-30 13:23:37 +08:00
|
|
|
code = oc_create_allowed( soc, soc->soc_at_oids_may, &op, err );
|
2005-09-09 04:46:48 +08:00
|
|
|
if ( code != 0 ) {
|
|
|
|
goto done;
|
|
|
|
}
|
2000-06-20 00:12:57 +08:00
|
|
|
|
2005-09-09 04:46:48 +08:00
|
|
|
if ( user && op ) {
|
|
|
|
code = SLAP_SCHERR_CLASS_BAD_USAGE;
|
|
|
|
goto done;
|
|
|
|
}
|
2002-05-30 13:23:37 +08:00
|
|
|
|
2005-09-09 04:46:48 +08:00
|
|
|
if ( !user ) {
|
|
|
|
soc->soc_flags |= SLAP_OC_HARDCODE;
|
|
|
|
}
|
2005-03-21 16:31:48 +08:00
|
|
|
|
2006-09-14 08:06:04 +08:00
|
|
|
code = oc_insert(&soc,prev,err);
|
2005-09-09 04:46:48 +08:00
|
|
|
done:;
|
|
|
|
if ( code != 0 ) {
|
|
|
|
if ( soc->soc_sups ) {
|
|
|
|
ch_free( soc->soc_sups );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( soc->soc_required ) {
|
|
|
|
ch_free( soc->soc_required );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( soc->soc_allowed ) {
|
|
|
|
ch_free( soc->soc_allowed );
|
|
|
|
}
|
|
|
|
|
|
|
|
ch_free( soc );
|
|
|
|
|
|
|
|
} else if ( rsoc ) {
|
2005-03-21 16:31:48 +08:00
|
|
|
*rsoc = soc;
|
2005-09-09 04:46:48 +08:00
|
|
|
}
|
2000-02-05 13:01:41 +08:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2005-03-21 16:31:48 +08:00
|
|
|
void
|
|
|
|
oc_unparse( BerVarray *res, ObjectClass *start, ObjectClass *end, int sys )
|
|
|
|
{
|
|
|
|
ObjectClass *oc;
|
|
|
|
int i, num;
|
|
|
|
struct berval bv, *bva = NULL, idx;
|
2005-07-15 03:52:08 +08:00
|
|
|
char ibuf[32];
|
2005-03-21 16:31:48 +08:00
|
|
|
|
|
|
|
if ( !start )
|
|
|
|
start = LDAP_STAILQ_FIRST( &oc_list );
|
|
|
|
|
|
|
|
/* count the result size */
|
|
|
|
i = 0;
|
2005-03-21 18:23:01 +08:00
|
|
|
for ( oc=start; oc; oc=LDAP_STAILQ_NEXT(oc, soc_next)) {
|
2006-11-18 06:52:20 +08:00
|
|
|
if ( sys && !(oc->soc_flags & SLAP_OC_HARDCODE)) break;
|
2005-03-21 16:31:48 +08:00
|
|
|
i++;
|
2005-03-21 18:23:01 +08:00
|
|
|
if ( oc == end ) break;
|
2005-03-21 16:31:48 +08:00
|
|
|
}
|
|
|
|
if (!i) return;
|
|
|
|
|
|
|
|
num = i;
|
|
|
|
bva = ch_malloc( (num+1) * sizeof(struct berval) );
|
|
|
|
BER_BVZERO( bva );
|
|
|
|
idx.bv_val = ibuf;
|
|
|
|
if ( sys ) {
|
|
|
|
idx.bv_len = 0;
|
|
|
|
ibuf[0] = '\0';
|
|
|
|
}
|
|
|
|
i = 0;
|
2005-03-21 18:23:01 +08:00
|
|
|
for ( oc=start; oc; oc=LDAP_STAILQ_NEXT(oc, soc_next)) {
|
2005-04-10 00:13:04 +08:00
|
|
|
LDAPObjectClass loc, *locp;
|
2006-11-18 06:52:20 +08:00
|
|
|
if ( sys && !(oc->soc_flags & SLAP_OC_HARDCODE)) break;
|
2005-04-10 00:13:04 +08:00
|
|
|
if ( oc->soc_oidmacro ) {
|
|
|
|
loc = oc->soc_oclass;
|
|
|
|
loc.oc_oid = oc->soc_oidmacro;
|
|
|
|
locp = &loc;
|
|
|
|
} else {
|
|
|
|
locp = &oc->soc_oclass;
|
|
|
|
}
|
|
|
|
if ( ldap_objectclass2bv( locp, &bv ) == NULL ) {
|
2005-03-21 16:31:48 +08:00
|
|
|
ber_bvarray_free( bva );
|
|
|
|
}
|
|
|
|
if ( !sys ) {
|
2005-04-10 00:13:04 +08:00
|
|
|
idx.bv_len = sprintf(idx.bv_val, "{%d}", i);
|
2005-03-21 16:31:48 +08:00
|
|
|
}
|
|
|
|
bva[i].bv_len = idx.bv_len + bv.bv_len;
|
|
|
|
bva[i].bv_val = ch_malloc( bva[i].bv_len + 1 );
|
|
|
|
strcpy( bva[i].bv_val, ibuf );
|
|
|
|
strcpy( bva[i].bv_val + idx.bv_len, bv.bv_val );
|
|
|
|
i++;
|
|
|
|
bva[i].bv_val = NULL;
|
|
|
|
ldap_memfree( bv.bv_val );
|
2005-03-21 18:23:01 +08:00
|
|
|
if ( oc == end ) break;
|
2005-03-21 16:31:48 +08:00
|
|
|
}
|
|
|
|
*res = bva;
|
|
|
|
}
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
int
|
|
|
|
oc_schema_info( Entry *e )
|
|
|
|
{
|
2000-05-16 07:36:37 +08:00
|
|
|
AttributeDescription *ad_objectClasses = slap_schema.si_ad_objectClasses;
|
2003-02-28 15:06:06 +08:00
|
|
|
ObjectClass *oc;
|
|
|
|
struct berval val;
|
|
|
|
struct berval nval;
|
2000-02-05 13:01:41 +08:00
|
|
|
|
2005-03-21 16:31:48 +08:00
|
|
|
LDAP_STAILQ_FOREACH( oc, &oc_list, soc_next ) {
|
2002-10-09 15:11:50 +08:00
|
|
|
if( oc->soc_flags & SLAP_OC_HIDE ) continue;
|
|
|
|
|
2003-02-28 15:06:06 +08:00
|
|
|
if ( ldap_objectclass2bv( &oc->soc_oclass, &val ) == NULL ) {
|
2000-02-05 13:01:41 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2002-05-29 14:14:55 +08:00
|
|
|
|
2004-04-29 04:10:21 +08:00
|
|
|
nval = oc->soc_cname;
|
2003-02-28 15:06:06 +08:00
|
|
|
|
2004-04-28 13:12:53 +08:00
|
|
|
#if 0
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "Merging oc [%ld] %s (%s)\n",
|
|
|
|
(long) val.bv_len, val.bv_val, nval.bv_val );
|
|
|
|
#endif
|
|
|
|
|
2004-04-29 04:10:21 +08:00
|
|
|
if( attr_merge_one( e, ad_objectClasses, &val, &nval ) ) {
|
2002-11-02 02:59:52 +08:00
|
|
|
return -1;
|
2003-02-26 05:08:48 +08:00
|
|
|
}
|
2003-02-28 15:06:06 +08:00
|
|
|
ldap_memfree( val.bv_val );
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-09-13 20:48:45 +08:00
|
|
|
|
|
|
|
int
|
2008-04-07 04:04:10 +08:00
|
|
|
register_oc( const char *def, ObjectClass **soc, int dupok )
|
2006-09-13 20:48:45 +08:00
|
|
|
{
|
|
|
|
LDAPObjectClass *oc;
|
|
|
|
int code;
|
|
|
|
const char *err;
|
|
|
|
|
|
|
|
oc = ldap_str2objectclass( def, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
|
|
|
|
if ( !oc ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"register_oc: objectclass \"%s\": %s, %s\n",
|
|
|
|
def, ldap_scherr2str(code), err );
|
|
|
|
return code;
|
|
|
|
}
|
2006-09-14 08:06:04 +08:00
|
|
|
code = oc_add(oc,0,NULL,NULL,&err);
|
2006-09-13 20:48:45 +08:00
|
|
|
if ( code && ( code != SLAP_SCHERR_CLASS_DUP || !dupok )) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"register_oc: objectclass \"%s\": %s, %s\n",
|
|
|
|
def, scherr2str(code), err );
|
|
|
|
ldap_objectclass_free(oc);
|
|
|
|
return code;
|
|
|
|
}
|
2006-09-13 21:26:56 +08:00
|
|
|
if ( soc )
|
|
|
|
*soc = oc_find(oc->oc_names[0]);
|
2006-09-13 20:48:45 +08:00
|
|
|
if ( code ) {
|
|
|
|
ldap_objectclass_free(oc);
|
|
|
|
} else {
|
|
|
|
ldap_memfree(oc);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|