From: Andrew Bartlett Date: Mon, 16 Nov 2009 07:48:46 +0000 (+1100) Subject: s4:schema Add the GUID to each defaultObjectCategory when loading from LDIF X-Git-Tag: tdb-1.2.0~79 X-Git-Url: http://git.samba.org/samba.git/?p=bbaumbach%2Fsamba-autobuild%2F.git;a=commitdiff_plain;h=e9f4dbce64b29882ae2f2f51cda50805c4e27190 s4:schema Add the GUID to each defaultObjectCategory when loading from LDIF This makes these full extended DNs, so we set the right values into the database, even before we actually set the schema objects themselves. Andrew Bartlett --- diff --git a/source4/dsdb/schema/schema_set.c b/source4/dsdb/schema/schema_set.c index ab870741cfd..c321bc9ccad 100644 --- a/source4/dsdb/schema/schema_set.c +++ b/source4/dsdb/schema/schema_set.c @@ -25,6 +25,8 @@ #include "dsdb/samdb/samdb.h" #include "lib/ldb/include/ldb_module.h" #include "param/param.h" +#include "librpc/ndr/libndr.h" +#include "librpc/gen_ndr/ndr_misc.h" /* override the name to attribute handler function @@ -456,6 +458,47 @@ void dsdb_make_schema_global(struct ldb_context *ldb) dsdb_set_global_schema(ldb); } +/* When loading the schema from LDIF files, we don't get the extended DNs. + + We need to set these up, so that from the moment we start the provision, the defaultObjectCategory links are set up correctly. + */ +int dsdb_schema_fill_extended_dn(struct ldb_context *ldb, struct dsdb_schema *schema) +{ + struct dsdb_class *cur; + const struct dsdb_class *target_class; + for (cur = schema->classes; cur; cur = cur->next) { + enum ndr_err_code ndr_err; + const struct ldb_val *rdn; + struct ldb_val guid; + struct ldb_dn *dn = ldb_dn_new(NULL, ldb, cur->defaultObjectCategory); + if (!dn) { + return LDB_ERR_INVALID_DN_SYNTAX; + } + rdn = ldb_dn_get_component_val(dn, 0); + if (!rdn) { + talloc_free(dn); + return LDB_ERR_INVALID_DN_SYNTAX; + } + target_class = dsdb_class_by_cn_ldb_val(schema, rdn); + if (!target_class) { + talloc_free(dn); + return LDB_ERR_CONSTRAINT_VIOLATION; + } + + ndr_err = ndr_push_struct_blob(&guid, dn, NULL, &target_class->objectGUID, + (ndr_push_flags_fn_t)ndr_push_GUID); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + talloc_free(dn); + return LDB_ERR_OPERATIONS_ERROR; + } + ldb_dn_set_extended_component(dn, "GUID", &guid); + + cur->defaultObjectCategory = ldb_dn_get_extended_linearized(cur, dn, 1); + talloc_free(dn); + } + return LDB_SUCCESS; +} + /** * Add an element to the schema (attribute or class) from an LDB message */ @@ -580,6 +623,12 @@ WERROR dsdb_set_schema_from_ldif(struct ldb_context *ldb, const char *pf, const goto failed; } + ret = dsdb_schema_fill_extended_dn(ldb, schema); + if (ret != LDB_SUCCESS) { + status = WERR_FOOBAR; + goto failed; + } + goto done; nomem: