From 354693400513bb19ecc12641d18cb7242a91bb2c Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sun, 10 Apr 2005 15:40:15 +0000 Subject: [PATCH] same for objectClass; improve previous commit --- servers/slapd/at.c | 2 + servers/slapd/oc.c | 78 ++++++++++++++++++++++++++++++++++--- servers/slapd/schemaparse.c | 3 +- servers/slapd/slap.h | 1 + 4 files changed, 77 insertions(+), 7 deletions(-) diff --git a/servers/slapd/at.c b/servers/slapd/at.c index 75f2e11b83..784f3974ca 100644 --- a/servers/slapd/at.c +++ b/servers/slapd/at.c @@ -335,6 +335,7 @@ at_insert( *err = sat->sat_oid; old_sat = at_bvfind( &air->air_name ); + assert( old_sat != NULL ); rc = at_check_dup( old_sat, sat ); ldap_memfree( air ); @@ -362,6 +363,7 @@ at_insert( *err = *names; old_sat = at_bvfind( &air->air_name ); + assert( old_sat != NULL ); rc = at_check_dup( old_sat, sat ); ldap_memfree(air); diff --git a/servers/slapd/oc.c b/servers/slapd/oc.c index 87f4728e08..cd381f1bf3 100644 --- a/servers/slapd/oc.c +++ b/servers/slapd/oc.c @@ -396,6 +396,57 @@ oc_destroy( void ) } } +/* + * 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; +} + static int oc_insert( ObjectClass *soc, @@ -417,13 +468,21 @@ oc_insert( if ( avl_insert( &oc_index, (caddr_t) oir, oc_index_cmp, avl_dup_error ) ) { + ObjectClass *old_soc; + int rc; + *err = soc->soc_oid; - ldap_memfree(oir); - return SLAP_SCHERR_CLASS_DUP; + + old_soc = oc_bvfind( &oir->oir_name ); + assert( old_soc != NULL ); + rc = oc_check_dup( old_soc, soc ); + + ldap_memfree( oir ); + return rc; } /* FIX: temporal consistency check */ - assert( oc_bvfind(&oir->oir_name) != NULL ); + assert( oc_bvfind( &oir->oir_name ) != NULL ); } if ( (names = soc->soc_names) ) { @@ -440,9 +499,17 @@ oc_insert( if ( avl_insert( &oc_index, (caddr_t) oir, oc_index_cmp, avl_dup_error ) ) { + ObjectClass *old_soc; + int rc; + *err = *names; - ldap_memfree(oir); - return SLAP_SCHERR_CLASS_DUP; + + old_soc = oc_bvfind( &oir->oir_name ); + assert( old_soc != NULL ); + rc = oc_check_dup( old_soc, soc ); + + ldap_memfree( oir ); + return rc; } /* FIX: temporal consistency check */ @@ -453,7 +520,6 @@ oc_insert( } LDAP_STAILQ_INSERT_TAIL( &oc_list, soc, soc_next ); - return 0; } diff --git a/servers/slapd/schemaparse.c b/servers/slapd/schemaparse.c index b43874d059..d0b0d5b77a 100644 --- a/servers/slapd/schemaparse.c +++ b/servers/slapd/schemaparse.c @@ -37,13 +37,14 @@ static char *const err2text[] = { "user-defined ObjectClass includes operational attributes", "user-defined ObjectClass has inappropriate SUPerior", "Duplicate objectClass", + "Inconsistent duplicate objectClass", "AttributeType not found", "AttributeType inappropriate matching rule", "AttributeType inappropriate USAGE", "AttributeType inappropriate SUPerior", "AttributeType SYNTAX or SUPerior required", "Duplicate attributeType", - "Inconsistent attributeType", + "Inconsistent duplicate attributeType", "MatchingRule not found", "MatchingRule incomplete", "Duplicate matchingRule", diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 91f7c1a996..3ab274a426 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -285,6 +285,7 @@ enum { SLAP_SCHERR_CLASS_BAD_USAGE, SLAP_SCHERR_CLASS_BAD_SUP, SLAP_SCHERR_CLASS_DUP, + SLAP_SCHERR_CLASS_INCONSISTENT, SLAP_SCHERR_ATTR_NOT_FOUND, SLAP_SCHERR_ATTR_BAD_MR, SLAP_SCHERR_ATTR_BAD_USAGE, -- 2.39.5