Make the schema_inferiors generation code to compile
authorAndrew Bartlett <abartlet@samba.org>
Wed, 8 Apr 2009 13:18:49 +0000 (23:18 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 8 Apr 2009 13:18:49 +0000 (23:18 +1000)
Sadly it still segfaults at this stage

Andrew Bartlett

source4/dsdb/config.mk
source4/dsdb/schema/schema.h
source4/dsdb/schema/schema_inferiors.c
source4/dsdb/schema/schema_set.c

index 6db2890738a9f85d6e030dbb7b35255ef25a3cf6..8d1647953f8799141c1634a191ea9d9e8938335f 100644 (file)
@@ -38,7 +38,8 @@ SAMDB_SCHEMA_OBJ_FILES = $(addprefix $(dsdbsrcdir)/schema/, \
                schema_query.o \
                schema_syntax.o \
                schema_description.o \
-               schema_convert_to_ol.o)
+               schema_convert_to_ol.o \
+               schema_inferiors.o)
 
 $(eval $(call proto_header_template,$(dsdbsrcdir)/schema/proto.h,$(SAMDB_SCHEMA_OBJ_FILES:.o=.c)))
 # PUBLIC_HEADERS += dsdb/schema/schema.h
index 98ccf5ed9e1f1c38b0951cff2dd0bfebc85a369e..92cfe113d4c9585d7dda1b794c1e82d8706494dc 100644 (file)
@@ -132,6 +132,12 @@ struct dsdb_class {
        bool defaultHidingValue;
        bool isDefunct;
        bool systemOnly;
+
+       char **supclasses;
+       char **subclasses;
+       char **subclasses_direct;
+       char **posssuperiors;
+       char **possible_inferiors;
 };
 
 struct dsdb_schema_oid_prefix {
index d9afff24a314d282acc598cc9eba78eb3bc8e206..abd8f7e4b073ddcb4c6abd37debea5c3bb7de0ae 100644 (file)
 /*
   create the SUPCLASSES() list
  */
-static char **schema_supclasses(struct dsdb_schema *schema, 
-                               TALLOC_CTX *mem_ctx, const char *oc)
+static char * const *schema_supclasses(struct dsdb_schema *schema, 
+                                      TALLOC_CTX *mem_ctx, struct dsdb_class *schema_class)
 {
-       char **list;
-       const struct dsdb_class *class;
+       char * const *list;
+
+       if (schema_class->supclasses) {
+               return schema_class->supclasses;
+       }
 
        list = str_list_make(mem_ctx, NULL, NULL);
        if (list == NULL) {
@@ -47,28 +50,21 @@ static char **schema_supclasses(struct dsdb_schema *schema,
                return NULL;
        }
 
-       if (strcmp(oc, "top") == 0) {
+       /* Cope with 'top SUP top', ie top is subClassOf top */ 
+       if (strcmp(schema_class->lDAPDisplayName, schema_class->subClassOf) == 0) {
+               schema_class->supclasses = list;
                return list;
        }
 
-       class = dsdb_class_by_lDAPDisplayName(schema, oc);
-       if (class == NULL) {
-               DEBUG(0,(__location__ " objectClass '%s' does not exist\n", oc));
-               return NULL;
-       }
-       
-       if (class->supclasses) {
-               return class->supclasses;
-       }
-
-       if (class->subClassOf) {
+       if (schema_class->subClassOf) {
                char **list2;
-               list = str_list_add(list, class->subClassOf);
-               list2 = schema_supclasses(schema, mem_ctx, class->subClassOf);
+               list = str_list_add(list, schema_class->subClassOf);
+
+               list2 = schema_supclasses(schema, mem_ctx, dsdb_class_by_lDAPDisplayName(schema, schema_class->subClassOf));
                list = str_list_append(list, list2);
        }
 
-       class->supclasses = list;
+       schema_class->supclasses = list;
        
        return list;
 }
@@ -78,15 +74,14 @@ static char **schema_supclasses(struct dsdb_schema *schema,
   matches SUBCLASSES() python function
  */
 static char **schema_subclasses(struct dsdb_schema *schema, TALLOC_CTX *mem_ctx,
-                               const char **oclist)
+                               const char * const *oclist)
 {
-       const char *oc;
        char **list = str_list_make(mem_ctx, NULL, NULL);
        int i;
 
        for (i=0; oclist && oclist[i]; i++) {
-               struct dsdb_class *class = dsdb_class_by_lDAPDisplayName(schema, oclist[i]);
-               list = str_list_append(list, class->subclasses);
+               struct dsdb_class *schema_class = dsdb_class_by_lDAPDisplayName(schema, oclist[i]);
+               list = str_list_append(list, schema_class->subclasses);
        }
        return list;
 }
@@ -96,77 +91,87 @@ static char **schema_subclasses(struct dsdb_schema *schema, TALLOC_CTX *mem_ctx,
    equivalent of the POSSSUPERIORS() python function
  */
 static char **schema_posssuperiors(struct dsdb_schema *schema, TALLOC_CTX *mem_ctx,
-                                  const char **oclist)
+                                  struct dsdb_class *schema_class)
 {
-       const char *oc;
        char **list = str_list_make(mem_ctx, NULL, NULL);
-       int i;
 
-       for (i=0; oclist && oclist[i]; i++) {
-               struct dsdb_class *class = dsdb_class_by_lDAPDisplayName(schema, oclist[i]);
-               if (class->posssuperiors) {
-                       list = str_list_append(list, class->posssuperiors);
-               } else {
-                       char **list2 = str_list_make(mem_ctx, NULL, NULL);
-                       list2 = str_list_append(list2, class->systemPossSuperiors);
-                       list2 = str_list_append(list2, class->possSuperiors);
-                       list2 = str_list_append(list2, schema_supclasses(schema, list2, oclist[i]));
-                       list2 = str_list_append(list2, schema_subclasses(schema, list2, list2));
-                       class->posssuperiors = list2;
-                       list = str_list_append(list, list2);
-               }
+       if (schema_class->posssuperiors) {
+               return schema_class->posssuperiors;
+       } else {
+               char * const *list2 = str_list_make(mem_ctx, NULL, NULL);
+               list2 = str_list_append(list2, schema_class->systemPossSuperiors);
+               list2 = str_list_append(list2, schema_class->possSuperiors);
+               list2 = str_list_append(list2, schema_supclasses(schema, list2, schema_class));
+               list2 = str_list_append(list2, schema_subclasses(schema, list2, list2));
+
+               schema_class->posssuperiors = list2;
+               return schema_class->posssuperiors;
        }
 
        return list;
 }
 
-static char **schema_subclasses_recurse(struct dsdb_schema *schema, struct dsdb_class *class)
+static char **schema_subclasses_recurse(struct dsdb_schema *schema, struct dsdb_class *schema_class)
 {
-       char **list = str_list_copy(class, class->subclasses_direct);
+       char * const *list = str_list_copy(schema_class, schema_class->subclasses_direct);
        int i;
        for (i=0;list && list[i]; i++) {
-               struct dsdb_class *class2 = dsdb_class_by_lDAPDisplayName(schema, list[i]);
-               list = str_list_append(list, schema_subclasses_recurse(schema, class2));
+               struct dsdb_class *schema_class2 = dsdb_class_by_lDAPDisplayName(schema, list[i]);
+               if (schema_class != schema_class2) {
+                       list = str_list_append(list, schema_subclasses_recurse(schema, schema_class2));
+               }
        }
        return list;
 }
 
 static void schema_create_subclasses(struct dsdb_schema *schema)
 {
-       struct dsdb_class *class;
-
-       for (class=schema->classes; class; class=class->next) {
-               struct dsdb_class *class2 = dsdb_class_by_lDAPDisplayName(schema, class->subClassOf);
-               class->subclasses_direct = str_list_make(class, NULL, NULL);
-               if (class != class2) {
-                       if (class2->subclasses_direct == NULL) {
-                               class2->subclasses_direct = str_list_make(class2, NULL, NULL);
+       struct dsdb_class *schema_class;
+
+       for (schema_class=schema->classes; schema_class; schema_class=schema_class->next) {
+               struct dsdb_class *schema_class2 = dsdb_class_by_lDAPDisplayName(schema, schema_class->subClassOf);
+               schema_class->subclasses_direct = str_list_make(schema_class, NULL, NULL);
+               if (schema_class != schema_class2) {
+                       if (schema_class2->subclasses_direct == NULL) {
+                               schema_class2->subclasses_direct = str_list_make(schema_class2, NULL, NULL);
                        }
-                       class2->subclasses_direct = str_list_add(class2->subclasses_direct, 
-                                                                class->subClassOf);
+                       schema_class2->subclasses_direct = str_list_add(schema_class2->subclasses_direct, 
+                                                                       schema_class->subClassOf);
                }
        }
 
-       for (class=schema->classes; class; class=class->next) {
-               class->subclasses = schema_subclasses_recurse(schema, class);
+       for (schema_class=schema->classes; schema_class; schema_class=schema_class->next) {
+               schema_class->subclasses = schema_subclasses_recurse(schema, schema_class);
        }       
 }
 
-void schema_fill_possible_inferiors(struct dsdb_schema *schema, struct dsdb_class *class)
+static void schema_fill_possible_inferiors(struct dsdb_schema *schema, struct dsdb_class *schema_class)
 {
        struct dsdb_class *c2;
-       
+
+       for (c2=schema->classes; c2; c2=c2->next) {
+               char **superiors = schema_posssuperiors(schema, c2, c2);
+               if (c2->systemOnly == false 
+                   && c2->objectClassCategory != 2 
+                   && c2->objectClassCategory != 3
+                   && str_list_check(superiors, schema_class->lDAPDisplayName)) {
+                       if (c2->possible_inferiors == NULL) {
+                               c2->possible_inferiors = str_list_make(c2, NULL, NULL);
+                       }
+                       c2->possible_inferiors = str_list_add_unique(c2->possible_inferiors,
+                                                                    schema_class->lDAPDisplayName);
+               }
+               talloc_free(superiors);
+       }
 }
 
-def possible_inferiors_constructed(db, classinfo, c):
-    list = []
-    for oc in classinfo:
-        superiors = POSSSUPERIORS(classinfo, [oc])
-        if (is_in_list(superiors, c) and
-            classinfo[oc]["systemOnly"] == False and
-            classinfo[oc]["objectClassCategory"] != 2 and
-            classinfo[oc]["objectClassCategory"] != 3):
-            list.append(oc)
-    list = uniq_list(list)
-    list.sort()
-    return list
+void schema_fill_constructed(struct dsdb_schema *schema) 
+{
+       struct dsdb_class *schema_class;
+
+       schema_create_subclasses(schema);
+
+       for (schema_class=schema->classes; schema_class; schema_class=schema_class->next) {
+               schema_fill_possible_inferiors(schema, schema_class);
+       }
+}
index 725fe845ad12661946c82c7b4a65eabb6bfde2da..dcaeb4fc89b06b58e01843ff0c7992d81e816627 100644 (file)
@@ -309,6 +309,23 @@ failed:
        return LDB_ERR_OPERATIONS_ERROR;
 }
 
+int dsdb_setup_schema_inversion(struct ldb_context *ldb, struct dsdb_schema *schema)
+{
+       /* Walk the list of schema classes */
+
+       /*  For each subClassOf, add us to subclasses of the parent */
+
+       /* collect these subclasses into a recursive list of total subclasses, preserving order */
+
+       /* For each subclass under 'top', write the index from it's
+        * order as an integer in the dsdb_class (for sorting
+        * objectClass lists efficiently) */
+
+       /* Walk the list of scheam classes */
+       
+       /*  Create a 'total possible superiors' on each class */
+       return LDB_SUCCESS;
+}
 
 /**
  * Attach the schema to an opaque pointer on the ldb, so ldb modules
@@ -324,6 +341,8 @@ int dsdb_set_schema(struct ldb_context *ldb, struct dsdb_schema *schema)
                return ret;
        }
 
+       schema_fill_constructed(schema);
+
        ret = ldb_set_opaque(ldb, "dsdb_schema", schema);
        if (ret != LDB_SUCCESS) {
                return ret;