]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/oc.c
Install *.schema only
[openldap] / servers / slapd / oc.c
index 513ba903e374b8c8ef6f002354dad304cfb1def2..c2a5c510d55a5601fe51fd1326ee004b52fb3181 100644 (file)
 #include "slap.h"
 #include "ldap_pvt.h"
 
+int is_object_subclass(
+       ObjectClass *sub,
+       ObjectClass *sup )
+{
+       int i;
+
+       if( sup == sub ) {
+               return 1;
+       }
+
+       if( sup->soc_sups == NULL ) {
+               return 0;
+       }
+
+       for( i=0; sup->soc_sups[i] != NULL; i++ ) {
+               if( is_object_subclass( sup->soc_sups[i], sup ) ) {
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
 int is_entry_objectclass(
        Entry*  e,
-       const char*     oc)
+#ifdef SLAPD_SCHEMA_NOT_COMPAT
+       ObjectClass *oc
+#else
+       const char*     oc
+#endif
+)
 {
        Attribute *attr;
-       struct berval bv;
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
+       int i;
        AttributeDescription *objectClass = slap_schema.si_ad_objectClass;
+       assert(!( e == NULL || oc == NULL ));
 #else
+       struct berval bv;
        static const char *objectClass = "objectclass";
+       assert(!( e == NULL || oc == NULL || *oc == '\0' ));
 #endif
 
-       if( e == NULL || oc == NULL || *oc == '\0' )
+       if( e == NULL || oc == NULL
+#ifndef SLAPD_SCHEMA_NOT_COMPAT
+               || *oc == '\0'
+#endif
+       ) {
                return 0;
+       }
 
        /*
         * find objectClass attribute
@@ -38,22 +74,35 @@ int is_entry_objectclass(
 
        if( attr == NULL ) {
                /* no objectClass attribute */
+               Debug( LDAP_DEBUG_ANY, "is_entry_objectclass(\"%s\", \"%s\") "
+                       "no objectClass attribute\n",
+                       e->e_dn == NULL ? "" : e->e_dn, oc, 0 );
+
                return 0;
        }
 
+#ifdef SLAPD_SCHEMA_NOT_COMPAT
+       for( i=0; attr->a_vals[i]; i++ ) {
+               ObjectClass *objectClass = oc_find( attr->a_vals[i]->bv_val );
+
+               if( objectClass == oc ) {
+                       return 1;
+               }
+       }
+
+       return 0;
+
+#else
        bv.bv_val = (char *) oc;
        bv.bv_len = strlen( bv.bv_val );
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
-       /* not yet implemented */
-#else
        if( value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
                /* entry is not of this objectclass */
                return 0;
        }
-#endif
 
        return 1;
+#endif
 }
 
 
@@ -67,7 +116,7 @@ static char *oc_op_usermod_attrs[] = {
         * which slapd supports modification of.
         *
         * Currently none.
-        * Likely candidate, "aci"
+        * Likely candidate, "OpenLDAPaci"
         */
        NULL
 };
@@ -90,7 +139,6 @@ static char *oc_op_attrs[] = {
        "supportedControl",
        "supportedSASLMechanisms",
        "supportedLDAPversion",
-       "supportedACIMechanisms",
        "subschemaSubentry",            /* NO USER MOD */
        NULL
 
@@ -111,7 +159,6 @@ static char *oc_op_no_usermod_attrs[] = {
 
        NULL
 };
-#endif
 
 
 /*
@@ -163,6 +210,7 @@ oc_check_op_no_usermod_attr( const char *type )
        return at->sat_no_user_mod;
 #endif
 }
+#endif
 
 
 struct oindexrec {
@@ -179,6 +227,11 @@ oc_index_cmp(
     struct oindexrec   *oir2
 )
 {
+       assert( oir1->oir_name );
+       assert( oir1->oir_oc );
+       assert( oir2->oir_name );
+       assert( oir2->oir_oc );
+
        return (strcasecmp( oir1->oir_name, oir2->oir_name ));
 }
 
@@ -188,18 +241,27 @@ oc_index_name_cmp(
     struct oindexrec   *oir
 )
 {
+       assert( oir->oir_name );
+       assert( oir->oir_oc );
+
        return (strcasecmp( name, oir->oir_name ));
 }
 
 ObjectClass *
 oc_find( const char *ocname )
 {
-       struct oindexrec        *oir = NULL;
+       struct oindexrec        *oir;
+
+       oir = (struct oindexrec *) avl_find( oc_index, ocname,
+            (AVL_CMP) oc_index_name_cmp );
+
+       if ( oir != NULL ) {
+               assert( oir->oir_name );
+               assert( oir->oir_oc );
 
-       if ( (oir = (struct oindexrec *) avl_find( oc_index, ocname,
-            (AVL_CMP) oc_index_name_cmp )) != NULL ) {
                return( oir->oir_oc );
        }
+
        return( NULL );
 }
 
@@ -351,34 +413,51 @@ oc_insert(
                        ch_calloc( 1, sizeof(struct oindexrec) );
                oir->oir_name = soc->soc_oid;
                oir->oir_oc = soc;
+
+               assert( oir->oir_name );
+               assert( oir->oir_oc );
+
                if ( avl_insert( &oc_index, (caddr_t) oir,
                                 (AVL_CMP) oc_index_cmp,
-                                (AVL_DUP) avl_dup_error ) ) {
+                                (AVL_DUP) avl_dup_error ) )
+               {
                        *err = soc->soc_oid;
+                       ldap_memfree(oir->oir_name);
                        ldap_memfree(oir);
                        return SLAP_SCHERR_DUP_CLASS;
                }
+
                /* FIX: temporal consistency check */
-               oc_find(oir->oir_name);
+               assert( oc_find(oir->oir_name) != NULL );
        }
+
        if ( (names = soc->soc_names) ) {
                while ( *names ) {
                        oir = (struct oindexrec *)
                                ch_calloc( 1, sizeof(struct oindexrec) );
                        oir->oir_name = ch_strdup(*names);
                        oir->oir_oc = soc;
+
+                       assert( oir->oir_name );
+                       assert( oir->oir_oc );
+
                        if ( avl_insert( &oc_index, (caddr_t) oir,
                                         (AVL_CMP) oc_index_cmp,
-                                        (AVL_DUP) avl_dup_error ) ) {
+                                        (AVL_DUP) avl_dup_error ) )
+                       {
                                *err = *names;
+                               ldap_memfree(oir->oir_name);
                                ldap_memfree(oir);
                                return SLAP_SCHERR_DUP_CLASS;
                        }
+
                        /* FIX: temporal consistency check */
-                       oc_find(oir->oir_name);
+                       assert( oc_find(oir->oir_name) != NULL );
+
                        names++;
                }
        }
+
        return 0;
 }
 
@@ -455,8 +534,10 @@ oc_schema_info( Entry *e )
                        return -1;
                }
                val.bv_len = strlen( val.bv_val );
+#if 0
                Debug( LDAP_DEBUG_TRACE, "Merging oc [%ld] %s\n",
               (long) val.bv_len, val.bv_val, 0 );
+#endif
                attr_merge( e, ad_objectClasses, vals );
                ldap_memfree( val.bv_val );
        }