summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/dsdb/samdb/ldb_modules/schema_load.c26
-rw-r--r--source4/dsdb/schema/schema_init.c56
-rw-r--r--source4/torture/drs/drs_util.c46
3 files changed, 48 insertions, 80 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/schema_load.c b/source4/dsdb/samdb/ldb_modules/schema_load.c
index b7b5f6bae7..ec574b33e3 100644
--- a/source4/dsdb/samdb/ldb_modules/schema_load.c
+++ b/source4/dsdb/samdb/ldb_modules/schema_load.c
@@ -150,8 +150,7 @@ static int dsdb_schema_from_db(struct ldb_module *module, struct ldb_dn *schema_
char *error_string;
int ret;
struct ldb_result *schema_res;
- struct ldb_result *a_res;
- struct ldb_result *c_res;
+ struct ldb_result *res;
static const char *schema_attrs[] = {
"prefixMap",
"schemaInfo",
@@ -190,36 +189,21 @@ static int dsdb_schema_from_db(struct ldb_module *module, struct ldb_dn *schema_
/*
* load the attribute definitions
*/
- ret = dsdb_module_search(module, tmp_ctx, &a_res,
- schema_dn, LDB_SCOPE_ONELEVEL, NULL,
- DSDB_FLAG_NEXT_MODULE,
- NULL,
- "(objectClass=attributeSchema)");
- if (ret != LDB_SUCCESS) {
- ldb_asprintf_errstring(ldb,
- "dsdb_schema: failed to search attributeSchema objects: %s",
- ldb_errstring(ldb));
- goto failed;
- }
-
- /*
- * load the objectClass definitions
- */
- ret = dsdb_module_search(module, tmp_ctx, &c_res,
+ ret = dsdb_module_search(module, tmp_ctx, &res,
schema_dn, LDB_SCOPE_ONELEVEL, NULL,
DSDB_FLAG_NEXT_MODULE |
DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT,
NULL,
- "(objectClass=classSchema)");
+ "(|(objectClass=attributeSchema)(objectClass=classSchema))");
if (ret != LDB_SUCCESS) {
ldb_asprintf_errstring(ldb,
- "dsdb_schema: failed to search classSchema objects: %s",
+ "dsdb_schema: failed to search attributeSchema and classSchema objects: %s",
ldb_errstring(ldb));
goto failed;
}
ret = dsdb_schema_from_ldb_results(tmp_ctx, ldb,
- schema_res, a_res, c_res, schema, &error_string);
+ schema_res, res, schema, &error_string);
if (ret != LDB_SUCCESS) {
ldb_asprintf_errstring(ldb,
"dsdb_schema load failed: %s",
diff --git a/source4/dsdb/schema/schema_init.c b/source4/dsdb/schema/schema_init.c
index 70d177c799..0a9dedff8a 100644
--- a/source4/dsdb/schema/schema_init.c
+++ b/source4/dsdb/schema/schema_init.c
@@ -775,6 +775,33 @@ WERROR dsdb_class_from_ldb(struct dsdb_schema *schema,
#define dsdb_oom(error_string, mem_ctx) *error_string = talloc_asprintf(mem_ctx, "dsdb out of memory at %s:%d\n", __FILE__, __LINE__)
/*
+ Fill a DSDB schema from the ldb results provided. This is called
+ directly when a schema must be created with a pre-initialised prefixMap
+*/
+
+int dsdb_load_ldb_results_into_schema(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
+ struct dsdb_schema *schema,
+ struct ldb_result *attrs_class_res,
+ char **error_string)
+{
+ unsigned int i;
+
+ for (i=0; i < attrs_class_res->count; i++) {
+ WERROR status = dsdb_schema_set_el_from_ldb_msg(ldb, schema, attrs_class_res->msgs[i]);
+ if (!W_ERROR_IS_OK(status)) {
+ *error_string = talloc_asprintf(mem_ctx,
+ "dsdb_load_ldb_results_into_schema: failed to load attribute or class definition: %s:%s",
+ ldb_dn_get_linearized(attrs_class_res->msgs[i]->dn),
+ win_errstr(status));
+ DEBUG(0,(__location__ ": %s\n", *error_string));
+ return LDB_ERR_CONSTRAINT_VIOLATION;
+ }
+ }
+
+ return LDB_SUCCESS;
+}
+
+/*
Create a DSDB schema from the ldb results provided. This is called
directly when the schema is provisioned from an on-disk LDIF file, or
from dsdb_schema_from_schema_dn in schema_fsmo
@@ -782,16 +809,16 @@ WERROR dsdb_class_from_ldb(struct dsdb_schema *schema,
int dsdb_schema_from_ldb_results(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
struct ldb_result *schema_res,
- struct ldb_result *attrs_res, struct ldb_result *objectclass_res,
+ struct ldb_result *attrs_class_res,
struct dsdb_schema **schema_out,
char **error_string)
{
WERROR status;
- unsigned int i;
const struct ldb_val *prefix_val;
const struct ldb_val *info_val;
struct ldb_val info_val_default;
struct dsdb_schema *schema;
+ int ret;
schema = dsdb_new_schema(mem_ctx);
if (!schema) {
@@ -830,28 +857,9 @@ int dsdb_schema_from_ldb_results(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
return LDB_ERR_CONSTRAINT_VIOLATION;
}
- for (i=0; i < attrs_res->count; i++) {
- status = dsdb_attribute_from_ldb(ldb, schema, attrs_res->msgs[i]);
- if (!W_ERROR_IS_OK(status)) {
- *error_string = talloc_asprintf(mem_ctx,
- "schema_fsmo_init: failed to load attribute definition: %s:%s",
- ldb_dn_get_linearized(attrs_res->msgs[i]->dn),
- win_errstr(status));
- DEBUG(0,(__location__ ": %s\n", *error_string));
- return LDB_ERR_CONSTRAINT_VIOLATION;
- }
- }
-
- for (i=0; i < objectclass_res->count; i++) {
- status = dsdb_class_from_ldb(schema, objectclass_res->msgs[i]);
- if (!W_ERROR_IS_OK(status)) {
- *error_string = talloc_asprintf(mem_ctx,
- "schema_fsmo_init: failed to load class definition: %s:%s",
- ldb_dn_get_linearized(objectclass_res->msgs[i]->dn),
- win_errstr(status));
- DEBUG(0,(__location__ ": %s\n", *error_string));
- return LDB_ERR_CONSTRAINT_VIOLATION;
- }
+ ret = dsdb_load_ldb_results_into_schema(mem_ctx, ldb, schema, attrs_class_res, error_string);
+ if (ret != LDB_SUCCESS) {
+ return ret;
}
schema->fsmo.master_dn = ldb_msg_find_attr_as_dn(ldb, schema, schema_res->msgs[0], "fSMORoleOwner");
diff --git a/source4/torture/drs/drs_util.c b/source4/torture/drs/drs_util.c
index 8773745760..9a071505c7 100644
--- a/source4/torture/drs/drs_util.c
+++ b/source4/torture/drs/drs_util.c
@@ -112,11 +112,10 @@ bool drs_util_dsdb_schema_load_ldb(struct torture_context *tctx,
const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr,
bool reload_schema)
{
- int i, ret;
+ int ret;
WERROR werr;
- const char *err_msg;
- struct ldb_result *a_res;
- struct ldb_result *c_res;
+ char *err_msg;
+ struct ldb_result *res;
struct ldb_dn *schema_dn;
struct dsdb_schema *ldap_schema;
@@ -137,50 +136,27 @@ bool drs_util_dsdb_schema_load_ldb(struct torture_context *tctx,
"Failed to construct prefixMap from drsuapi data");
/*
- * load the attribute definitions
+ * load the attribute and objectClass definitions
*/
- ret = ldb_search(ldb, ldap_schema, &a_res,
+ ret = ldb_search(ldb, ldap_schema, &res,
schema_dn, LDB_SCOPE_ONELEVEL, NULL,
- "(objectClass=attributeSchema)");
+ "(|(objectClass=attributeSchema)(objectClass=classSchema))");
if (ret != LDB_SUCCESS) {
err_msg = talloc_asprintf(tctx,
- "failed to search attributeSchema objects: %s",
+ "failed to search attributeSchema or classSchema objects: %s",
ldb_errstring(ldb));
torture_fail(tctx, err_msg);
}
- /*
- * load the objectClass definitions
- */
- ret = ldb_search(ldb, ldap_schema, &c_res,
- schema_dn, LDB_SCOPE_ONELEVEL, NULL,
- "(objectClass=classSchema)");
+ ret = dsdb_load_ldb_results_into_schema(tctx, ldb, ldap_schema, res, &err_msg);
if (ret != LDB_SUCCESS) {
err_msg = talloc_asprintf(tctx,
- "failed to search classSchema objects: %s",
- ldb_errstring(ldb));
+ "dsdb_load_ldb_results_into_schema failed: %s",
+ err_msg);
torture_fail(tctx, err_msg);
}
- /* Build schema */
- for (i=0; i < a_res->count; i++) {
- werr = dsdb_attribute_from_ldb(ldb, ldap_schema, a_res->msgs[i]);
- torture_assert_werr_ok(tctx, werr,
- talloc_asprintf(tctx,
- "dsdb_attribute_from_ldb() failed for: %s",
- ldb_dn_get_linearized(a_res->msgs[i]->dn)));
- }
-
- for (i=0; i < c_res->count; i++) {
- werr = dsdb_class_from_ldb(ldap_schema, c_res->msgs[i]);
- torture_assert_werr_ok(tctx, werr,
- talloc_asprintf(tctx,
- "dsdb_class_from_ldb() failed for: %s",
- ldb_dn_get_linearized(c_res->msgs[i]->dn)));
- }
-
- talloc_free(a_res);
- talloc_free(c_res);
+ talloc_free(res);
ret = dsdb_set_schema(ldb, ldap_schema);
if (ret != LDB_SUCCESS) {