summaryrefslogtreecommitdiff
path: root/source4/torture
diff options
context:
space:
mode:
authorKamen Mazdrashki <kamenim@samba.org>2010-08-07 12:52:07 +0300
committerKamen Mazdrashki <kamenim@samba.org>2010-08-11 00:18:14 +0300
commit06f59855a7b4fcc6f4957d9e1a8e29e387397b50 (patch)
tree80118284623a656c6b88510e888a9cd134752354 /source4/torture
parentc30f9bd7345cddd85502eb9d099279606959f447 (diff)
downloadsamba-06f59855a7b4fcc6f4957d9e1a8e29e387397b50.tar.gz
samba-06f59855a7b4fcc6f4957d9e1a8e29e387397b50.tar.bz2
samba-06f59855a7b4fcc6f4957d9e1a8e29e387397b50.zip
s4-test: Move dsdb_schema loading into public function
I will use this function for tests implementation later
Diffstat (limited to 'source4/torture')
-rw-r--r--source4/torture/drs/drs_util.c92
-rw-r--r--source4/torture/drs/rpc/dssync.c64
2 files changed, 96 insertions, 60 deletions
diff --git a/source4/torture/drs/drs_util.c b/source4/torture/drs/drs_util.c
index e917b71d9c..c0a6bf1ec1 100644
--- a/source4/torture/drs/drs_util.c
+++ b/source4/torture/drs/drs_util.c
@@ -21,6 +21,7 @@
#include "includes.h"
#include "torture/torture.h"
+#include "dsdb/samdb/samdb.h"
#include "torture/rpc/drsuapi.h"
#include "../lib/util/asn1.h"
@@ -166,3 +167,94 @@ const char * drs_util_DsAttributeId_to_string(enum drsuapi_DsAttributeId r)
}
return val;
}
+
+
+/**
+ * Loads dsdb_schema from ldb connection using remote prefixMap.
+ * Schema will be loaded only if:
+ * - ldb has no attached schema
+ * - reload_schema is true
+ *
+ * This function is to be used in tests that use GetNCChanges() function
+ */
+bool drs_util_dsdb_schema_load_ldb(struct torture_context *tctx,
+ struct ldb_context *ldb,
+ const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr,
+ bool reload_schema)
+{
+ int i, ret;
+ WERROR werr;
+ const char *err_msg;
+ struct ldb_result *a_res;
+ struct ldb_result *c_res;
+ struct ldb_dn *schema_dn;
+ struct dsdb_schema *ldap_schema;
+
+ ldap_schema = dsdb_get_schema(ldb, NULL);
+ if (ldap_schema && !reload_schema) {
+ return true;
+ }
+
+ schema_dn = ldb_get_schema_basedn(ldb);
+ torture_assert(tctx, schema_dn != NULL,
+ talloc_asprintf(tctx, "ldb_get_schema_basedn() failed: %s", ldb_errstring(ldb)));
+
+ ldap_schema = dsdb_new_schema(ldb);
+ torture_assert(tctx, ldap_schema != NULL, "dsdb_new_schema() failed!");
+
+ werr = dsdb_load_prefixmap_from_drsuapi(ldap_schema, mapping_ctr);
+
+ /*
+ * load the attribute definitions
+ */
+ ret = ldb_search(ldb, ldap_schema, &a_res,
+ schema_dn, LDB_SCOPE_ONELEVEL, NULL,
+ "(objectClass=attributeSchema)");
+ if (ret != LDB_SUCCESS) {
+ err_msg = talloc_asprintf(tctx,
+ "failed to search attributeSchema 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)");
+ if (ret != LDB_SUCCESS) {
+ err_msg = talloc_asprintf(tctx,
+ "failed to search classSchema objects: %s",
+ ldb_errstring(ldb));
+ 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);
+
+ ret = dsdb_set_schema(ldb, ldap_schema);
+ if (ret != LDB_SUCCESS) {
+ torture_fail(tctx,
+ talloc_asprintf(tctx, "dsdb_set_schema() failed: %s", ldb_strerror(ret)));
+ }
+
+ return true;
+}
diff --git a/source4/torture/drs/rpc/dssync.c b/source4/torture/drs/rpc/dssync.c
index 641a537298..5a7ceb8dc5 100644
--- a/source4/torture/drs/rpc/dssync.c
+++ b/source4/torture/drs/rpc/dssync.c
@@ -335,67 +335,11 @@ static bool test_analyse_objects(struct torture_context *tctx,
const char *err_msg;
struct dsdb_schema *ldap_schema;
+ /* load dsdb_schema using remote prefixMap */
+ torture_assert(tctx,
+ drs_util_dsdb_schema_load_ldb(tctx, ldb, mapping_ctr, false),
+ "drs_util_dsdb_schema_load_ldb() failed");
ldap_schema = dsdb_get_schema(ldb, NULL);
- if (!ldap_schema) {
- struct ldb_result *a_res;
- struct ldb_result *c_res;
- struct ldb_dn *schema_dn = ldb_get_schema_basedn(ldb);
- ldap_schema = dsdb_new_schema(ctx);
- if (!ldap_schema) {
- return false;
- }
- status = dsdb_load_prefixmap_from_drsuapi(ldap_schema, mapping_ctr);
-
- /*
- * load the attribute definitions
- */
- ret = ldb_search(ldb, ldap_schema, &a_res,
- schema_dn, LDB_SCOPE_ONELEVEL, NULL,
- "(objectClass=attributeSchema)");
- if (ret != LDB_SUCCESS) {
- err_msg = talloc_asprintf(tctx,
- "failed to search attributeSchema 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)");
- if (ret != LDB_SUCCESS) {
- err_msg = talloc_asprintf(tctx,
- "failed to search classSchema objects: %s",
- ldb_errstring(ldb));
- torture_fail(tctx, err_msg);
- }
-
- /* Build schema */
- for (i=0; i < a_res->count; i++) {
- status = dsdb_attribute_from_ldb(ldb, ldap_schema, a_res->msgs[i]);
- torture_assert_werr_ok(tctx, status,
- 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++) {
- status = dsdb_class_from_ldb(ldap_schema, c_res->msgs[i]);
- torture_assert_werr_ok(tctx, status,
- 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);
- ret = dsdb_set_schema(ldb, ldap_schema);
- if (ret != LDB_SUCCESS) {
- torture_fail(tctx,
- talloc_asprintf(tctx, "dsdb_set_schema() failed: %s", ldb_strerror(ret)));
- }
- }
status = dsdb_extended_replicated_objects_convert(ldb,
partition,