summaryrefslogtreecommitdiff
path: root/source4/dsdb/schema/schema_set.c
diff options
context:
space:
mode:
authorMatthieu Patou <mat@matws.net>2013-01-26 23:42:10 -0800
committerAndrew Bartlett <abartlet@samba.org>2013-05-23 20:26:07 +1000
commitfe85bc1fb9ab2f891a9fd46bd8e00325622d39cf (patch)
treea0e2d5cebb75470477e36ff356a727519809b055 /source4/dsdb/schema/schema_set.c
parentc524be17815e92ce9fcdd0565e76b026e483cc9d (diff)
downloadsamba-fe85bc1fb9ab2f891a9fd46bd8e00325622d39cf.tar.gz
samba-fe85bc1fb9ab2f891a9fd46bd8e00325622d39cf.tar.bz2
samba-fe85bc1fb9ab2f891a9fd46bd8e00325622d39cf.zip
dsdb-schema: make deduplication of class and schema possible (bug #8680)
When a class or an attribute is replicated it might already exists in the existing schema, so while replicating the new version of this object we want to get rid of the old version of the object is the current validating schema so that we don't end up having duplicates. Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Matthieu Patou <mat@matws.net> Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/dsdb/schema/schema_set.c')
-rw-r--r--source4/dsdb/schema/schema_set.c46
1 files changed, 41 insertions, 5 deletions
diff --git a/source4/dsdb/schema/schema_set.c b/source4/dsdb/schema/schema_set.c
index 31862a43b7..73264f9545 100644
--- a/source4/dsdb/schema/schema_set.c
+++ b/source4/dsdb/schema/schema_set.c
@@ -329,6 +329,18 @@ int dsdb_setup_sorted_accessors(struct ldb_context *ldb,
unsigned int num_int_id;
int ret;
+ for (i=0; i < schema->classes_to_remove_size; i++) {
+ DLIST_REMOVE(schema->classes, schema->classes_to_remove[i]);
+ TALLOC_FREE(schema->classes_to_remove[i]);
+ }
+ for (i=0; i < schema->attributes_to_remove_size; i++) {
+ DLIST_REMOVE(schema->attributes, schema->attributes_to_remove[i]);
+ TALLOC_FREE(schema->attributes_to_remove[i]);
+ }
+
+ TALLOC_FREE(schema->attributes_to_remove);
+ TALLOC_FREE(schema->classes_to_remove);
+
/* free all caches */
dsdb_sorted_accessors_free(schema);
@@ -669,10 +681,26 @@ int dsdb_schema_fill_extended_dn(struct ldb_context *ldb, struct dsdb_schema *sc
}
/**
- * Add an element to the schema (attribute or class) from an LDB message
+ * @brief Add a new element to the schema and checks if it's a duplicate
+ *
+ * This function will add a new element to the schema and checks for existing
+ * duplicates.
+ *
+ * @param[in] ldb A pointer to an LDB context
+ *
+ * @param[in] schema A pointer to the dsdb_schema where the element
+ * will be added.
+ *
+ * @param[in] msg The ldb_message object representing the element
+ * to add.
+ *
+ * @param[in] checkdups A boolean to indicate if checks for duplicates
+ * should be done.
+ *
+ * @return A WERROR code
*/
-WERROR dsdb_schema_set_el_from_ldb_msg(struct ldb_context *ldb, struct dsdb_schema *schema,
- struct ldb_message *msg)
+WERROR dsdb_schema_set_el_from_ldb_msg_dups(struct ldb_context *ldb, struct dsdb_schema *schema,
+ struct ldb_message *msg, bool checkdups)
{
const char* tstring;
time_t ts;
@@ -686,15 +714,23 @@ WERROR dsdb_schema_set_el_from_ldb_msg(struct ldb_context *ldb, struct dsdb_sche
}
if (samdb_find_attribute(ldb, msg,
"objectclass", "attributeSchema") != NULL) {
- return dsdb_set_attribute_from_ldb(ldb, schema, msg);
+
+ return dsdb_set_attribute_from_ldb_dups(ldb, schema, msg, checkdups);
} else if (samdb_find_attribute(ldb, msg,
"objectclass", "classSchema") != NULL) {
- return dsdb_set_class_from_ldb(schema, msg);
+ return dsdb_set_class_from_ldb_dups(schema, msg, checkdups);
}
/* Don't fail on things not classes or attributes */
return WERR_OK;
}
+WERROR dsdb_schema_set_el_from_ldb_msg(struct ldb_context *ldb,
+ struct dsdb_schema *schema,
+ struct ldb_message *msg)
+{
+ return dsdb_schema_set_el_from_ldb_msg_dups(ldb, schema, msg, false);
+}
+
/**
* Rather than read a schema from the LDB itself, read it from an ldif
* file. This allows schema to be loaded and used while adding the