s4:dsdb - introduce a only constant-time "get_last_structural_class()" call
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Wed, 4 Apr 2012 16:55:40 +0000 (18:55 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 11 Apr 2012 02:50:16 +0000 (12:50 +1000)
With the redesign of the previous patches this has become possible.

source4/dsdb/samdb/ldb_modules/descriptor.c
source4/dsdb/samdb/ldb_modules/objectclass.c
source4/dsdb/samdb/ldb_modules/schema.c

index f2afe742af03c7e33baeec6ae5d36b954a77d91b..0a4b1da39f9626498c9df14a67ada2f9e6fd2db6 100644 (file)
@@ -542,8 +542,7 @@ static int descriptor_add(struct ldb_module *module, struct ldb_request *req)
                return ldb_operr(ldb);
        }
 
-       objectclass = get_last_structural_class(schema, objectclass_element,
-                                               true);
+       objectclass = get_last_structural_class(schema, objectclass_element);
        if (objectclass == NULL) {
                return ldb_operr(ldb);
        }
@@ -661,8 +660,7 @@ static int descriptor_modify(struct ldb_module *module, struct ldb_request *req)
                return ldb_operr(ldb);
        }
 
-       objectclass = get_last_structural_class(schema, objectclass_element,
-                                               true);
+       objectclass = get_last_structural_class(schema, objectclass_element);
        if (objectclass == NULL) {
                return ldb_operr(ldb);
        }
index b8422ee86ec8f235b4d10130bcc1f09c562e6c33..033330c86c2859ff78789c2d6640ddd64b57a72c 100644 (file)
@@ -470,8 +470,7 @@ static int objectclass_do_add(struct oc_context *ac)
                 * unrelated structural classes
                 */
                objectclass = get_last_structural_class(ac->schema,
-                                                       objectclass_element,
-                                                       true);
+                                                       objectclass_element);
                if (objectclass == NULL) {
                        ldb_asprintf_errstring(ldb,
                                               "Failed to find a structural class for %s",
@@ -955,8 +954,7 @@ static int objectclass_do_mod(struct oc_context *ac)
                 * Get the new top-most structural object class and check for
                 * unrelated structural classes
                 */
-               objectclass = get_last_structural_class(ac->schema, oc_el_entry,
-                                                       true);
+               objectclass = get_last_structural_class(ac->schema, oc_el_entry);
                if (objectclass == NULL) {
                        ldb_set_errstring(ldb,
                                          "objectclass: cannot delete all structural objectclasses!");
@@ -1132,8 +1130,7 @@ static int objectclass_do_rename2(struct oc_context *ac)
                        /* existing entry without a valid object class? */
                        return ldb_operr(ldb);
                }
-               objectclass = get_last_structural_class(ac->schema, oc_el_entry,
-                                                       false);
+               objectclass = get_last_structural_class(ac->schema, oc_el_entry);
                if (objectclass == NULL) {
                        /* existing entry without a valid object class? */
                        return ldb_operr(ldb);
index d24d388d25b5d51d578ddc0c9207a6531c50d2fe..333fb1b0a68bbe2731a07d8f2ba398599ae3fe09 100644 (file)
 
 /*
  * This function determines the (last) structural or 88 object class of a passed
- * "objectClass" attribute.
- * Without schema this does not work and hence NULL is returned. If the
- * "objectClass" attribute has already been sorted then only a check on the
- * last value is necessary (MS-ADTS 3.1.1.1.4)
+ * "objectClass" attribute - per MS-ADTS 3.1.1.1.4 this is the last value.
+ * Without schema this does not work and hence NULL is returned.
  */
 const struct dsdb_class *get_last_structural_class(const struct dsdb_schema *schema,
-                                                  const struct ldb_message_element *element,
-                                                  bool sorted)
+                                                  const struct ldb_message_element *element)
 {
-       const struct dsdb_class *last_class = NULL;
-       unsigned int i = 0;
+       const struct dsdb_class *last_class;
 
        if (schema == NULL) {
                return NULL;
        }
 
-       if (sorted && (element->num_values > 1)) {
-               i = element->num_values - 1;
+       if (element->num_values == 0) {
+               return NULL;
        }
 
-       for (; i < element->num_values; i++){
-               const struct dsdb_class *tmp_class = dsdb_class_by_lDAPDisplayName_ldb_val(schema, &element->values[i]);
-
-               if(tmp_class == NULL) {
-                       continue;
-               }
-
-               if(tmp_class->objectClassCategory > 1) {
-                       continue;
-               }
-
-               if (!last_class) {
-                       last_class = tmp_class;
-               } else {
-                       if (tmp_class->subClass_order > last_class->subClass_order)
-                               last_class = tmp_class;
-               }
+       last_class = dsdb_class_by_lDAPDisplayName_ldb_val(schema,
+                                                          &element->values[element->num_values-1]);
+       if (last_class == NULL) {
+               return NULL;
+       }
+       if (last_class->objectClassCategory > 1) {
+               return NULL;
        }
 
        return last_class;