]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/oc.c
update for new backend types
[openldap] / servers / slapd / oc.c
index 87f4728e0808969872c9fee42549dac15cfa81cc..a721a35d6f24be7afe38a54d2be743c22c46c11a 100644 (file)
@@ -385,6 +385,7 @@ oc_destroy( void )
                if (o->soc_sups) ldap_memfree(o->soc_sups);
                if (o->soc_required) ldap_memfree(o->soc_required);
                if (o->soc_allowed) ldap_memfree(o->soc_allowed);
+               if (o->soc_oidmacro) ldap_memfree(o->soc_oidmacro);
                ldap_objectclass_free((LDAPObjectClass *)o);
        }
        
@@ -396,6 +397,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,
@@ -411,19 +463,27 @@ oc_insert(
                oir->oir_name.bv_len = strlen( soc->soc_oid );
                oir->oir_oc = soc;
 
-               assert( oir->oir_name.bv_val );
-               assert( oir->oir_oc );
+               assert( oir->oir_name.bv_val != NULL );
+               assert( oir->oir_oc != NULL );
 
                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) ) {
@@ -434,15 +494,23 @@ oc_insert(
                        oir->oir_name.bv_len = strlen( *names );
                        oir->oir_oc = soc;
 
-                       assert( oir->oir_name.bv_val );
-                       assert( oir->oir_oc );
+                       assert( oir->oir_name.bv_val != NULL );
+                       assert( oir->oir_oc != NULL );
 
                        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 +521,6 @@ oc_insert(
        }
        LDAP_STAILQ_INSERT_TAIL( &oc_list, soc, soc_next );
 
-
        return 0;
 }
 
@@ -538,7 +605,7 @@ oc_unparse( BerVarray *res, ObjectClass *start, ObjectClass *end, int sys )
        ObjectClass *oc;
        int i, num;
        struct berval bv, *bva = NULL, idx;
-       char ibuf[32], *ptr;
+       char ibuf[32];
 
        if ( !start )
                start = LDAP_STAILQ_FIRST( &oc_list );