r20733: add a function to load the oid mappings from ldb_val's
[ira/wip.git] / source4 / torture / libnet / libnet_BecomeDC.c
index fa0cfe29bf257b69adc49ecd3d41beeaff1e2fa8..a23a2e4c3b819be4c6098056c70e2c68324a8a36 100644 (file)
 #include "libnet/libnet.h"
 #include "lib/events/events.h"
 #include "dsdb/samdb/samdb.h"
+#include "lib/util/dlinklist.h"
+#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
+#include "librpc/ndr/libndr.h"
+#include "librpc/gen_ndr/ndr_drsuapi.h"
+#include "librpc/gen_ndr/ndr_drsblobs.h"
+#include "librpc/gen_ndr/ndr_misc.h"
+#include "system/time.h"
+#include "auth/auth.h"
+#include "lib/db_wrap.h"
+#include "lib/appweb/ejs/ejs.h"
+#include "lib/appweb/ejs/ejsInternal.h"
+#include "scripting/ejs/smbcalls.h"
+
+static EjsId eid;
+static int ejs_error;
+
+static void test_ejs_exception(const char *reason)
+{
+       Ejs *ep = ejsPtr(eid);
+       ejsSetErrorMsg(eid, "%s", reason);
+       fprintf(stderr, "%s", ep->error);
+       ejs_error = 127;
+}
+
+static int test_run_ejs(char *script)
+{
+       EjsHandle handle = 0;
+       MprVar result;
+       char *emsg;
+       TALLOC_CTX *mem_ctx = talloc_new(NULL);
+       struct MprVar *return_var;
+
+       mprSetCtx(mem_ctx);
+
+       if (ejsOpen(NULL, NULL, NULL) != 0) {
+               d_printf("ejsOpen(): unable to initialise EJS subsystem\n");
+               ejs_error = 127;
+               goto failed;
+       }
+
+       smb_setup_ejs_functions(test_ejs_exception);
+
+       if ((eid = ejsOpenEngine(handle, 0)) == (EjsId)-1) {
+               d_printf("smbscript: ejsOpenEngine(): unable to initialise an EJS engine\n");
+               ejs_error = 127;
+               goto failed;
+       }
+
+       mprSetVar(ejsGetGlobalObject(eid), "ARGV", mprList("ARGV", NULL));
+
+       /* run the script */
+       if (ejsEvalScript(eid, script, &result, &emsg) == -1) {
+               d_printf("smbscript: ejsEvalScript(): %s\n", emsg);
+               if (ejs_error == 0) ejs_error = 127;
+               goto failed;
+       }
+
+       return_var = ejsGetReturnValue(eid);
+       ejs_error = mprVarToNumber(return_var);
+
+failed:
+       ejsClose();
+       talloc_free(mem_ctx);
+       return ejs_error;
+}
 
 #define TORTURE_NETBIOS_NAME "smbtorturedc"
+#define TORTURE_SAMDB_LDB "test_samdb.ldb"
 
 struct test_become_dc_state {
        struct libnet_context *ctx;
        struct test_join *tj;
        struct cli_credentials *machine_account;
        struct dsdb_schema *schema;
+
+       struct ldb_context *ldb;
+
+       struct {
+               uint32_t object_count;
+               struct drsuapi_DsReplicaObjectListItemEx *first_object;
+               struct drsuapi_DsReplicaObjectListItemEx *last_object;
+       } schema_part;
 };
 
 static NTSTATUS test_become_dc_check_options(void *private_data,
@@ -62,6 +137,9 @@ static NTSTATUS test_become_dc_prepare_db(void *private_data,
                                          const struct libnet_BecomeDC_PrepareDB *p)
 {
        struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
+       char *ejs;
+       int ret;
+       bool ok;
 
        DEBUG(0,("New Server[%s] in Site[%s]\n",
                p->dest_dsa->dns_name, p->dest_dsa->site_name));
@@ -82,63 +160,158 @@ static NTSTATUS test_become_dc_prepare_db(void *private_data,
        DEBUG(0,("Domain Partition[%s]\n",
                p->domain->dn_str));
 
+       ejs = talloc_asprintf(s,
+               "libinclude(\"base.js\");\n"
+               "libinclude(\"provision.js\");\n"
+               "\n"
+               "function message() { print(vsprintf(arguments)); }\n"
+               "\n"
+               "var subobj = provision_guess();\n"
+               "subobj.ROOTDN       = \"%s\";\n"
+               "subobj.DOMAINDN     = \"%s\";\n"
+               "subobj.DOMAINDN_LDB = \"test_domain.ldb\";\n"
+               "subobj.CONFIGDN     = \"%s\";\n"
+               "subobj.CONFIGDN_LDB = \"test_config.ldb\";\n"
+               "subobj.SCHEMADN     = \"%s\";\n"
+               "subobj.SCHEMADN_LDB = \"test_schema.ldb\";\n"
+               "subobj.HOSTNAME     = \"%s\";\n"
+               "subobj.DNSNAME      = \"%s\";\n"
+               "subobj.DEFAULTSITE  = \"%s\";\n"
+               "\n"
+               "modules_list        = new Array(\"rootdse\",\n"
+               "                                \"kludge_acl\",\n"
+               "                                \"paged_results\",\n"
+               "                                \"server_sort\",\n"
+               "                                \"extended_dn\",\n"
+               "                                \"asq\",\n"
+               "                                \"samldb\",\n"
+               "                                \"password_hash\",\n"
+               "                                \"operational\",\n"
+               "                                \"objectclass\",\n"
+               "                                \"rdn_name\",\n"
+               "                                \"partition\");\n"
+               "subobj.MODULES_LIST = join(\",\", modules_list);\n"
+               "subobj.DOMAINDN_MOD = \"repl_meta_data\";\n"
+               "subobj.CONFIGDN_MOD = \"repl_meta_data\";\n"
+               "subobj.SCHEMADN_MOD = \"repl_meta_data\";\n"
+               "\n"
+               "var paths = provision_default_paths(subobj);\n"
+               "paths.samdb = \"%s\";\n"
+               "\n"
+               "var system_session = system_session();\n"
+               "\n"
+               "var ok = provision_become_dc(subobj, message, paths, system_session);\n"
+               "assert(ok);\n"
+               "\n"
+               "return 0;\n",
+               p->forest->root_dn_str,
+               p->domain->dn_str,
+               p->forest->config_dn_str,
+               p->forest->schema_dn_str,
+               p->dest_dsa->netbios_name,
+               p->dest_dsa->dns_name,
+               p->dest_dsa->site_name,
+               TORTURE_SAMDB_LDB);
+       NT_STATUS_HAVE_NO_MEMORY(ejs);
+
+       ret = test_run_ejs(ejs);
+       if (ret != 0) {
+               DEBUG(0,("Failed to run ejs script: %d:\n%s",
+                       ret, ejs));
+               talloc_free(ejs);
+               return NT_STATUS_FOOBAR;
+       }
+       talloc_free(ejs);
+
+       talloc_free(s->ldb);
+
+       s->ldb = ldb_wrap_connect(s, TORTURE_SAMDB_LDB,
+                                 system_session(s),
+                                 NULL, 0, NULL);
+       if (!s->ldb) {
+               DEBUG(0,("Failed to open '%s'\n",
+                       TORTURE_SAMDB_LDB));
+               return NT_STATUS_INTERNAL_DB_ERROR;
+       }
+
+       ok = samdb_set_ntds_invocation_id(s->ldb, &p->dest_dsa->invocation_id);
+       if (!ok) {
+               DEBUG(0,("Failed to set cached ntds invocationId\n"));
+               return NT_STATUS_FOOBAR;
+       }
+       ok = samdb_set_ntds_objectGUID(s->ldb, &p->dest_dsa->ntds_guid);
+       if (!ok) {
+               DEBUG(0,("Failed to set cached ntds objectGUID\n"));
+               return NT_STATUS_FOOBAR;
+       }
+
        return NT_STATUS_OK;
 }
 
-static NTSTATUS test_become_dc_schema_chunk(void *private_data,
-                                           const struct libnet_BecomeDC_StoreChunk *c)
+static NTSTATUS test_apply_schema(struct test_become_dc_state *s,
+                                 const struct libnet_BecomeDC_StoreChunk *c)
 {
-       struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
        WERROR status;
        const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
        uint32_t total_object_count;
        uint32_t object_count;
        struct drsuapi_DsReplicaObjectListItemEx *first_object;
        struct drsuapi_DsReplicaObjectListItemEx *cur;
+       uint32_t linked_attributes_count;
+       struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
+       const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
+       struct dsdb_extended_replicated_objects *objs;
+       struct repsFromTo1 *s_dsa;
+       char *tmp_dns_name;
+       uint32_t i;
+       int ret;
+
+       s_dsa                   = talloc_zero(s, struct repsFromTo1);
+       NT_STATUS_HAVE_NO_MEMORY(s_dsa);
+       s_dsa->other_info       = talloc(s_dsa, struct repsFromTo1OtherInfo);
+       NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
 
        switch (c->ctr_level) {
        case 1:
-               mapping_ctr             = &c->ctr1->mapping_ctr;
-               total_object_count      = c->ctr1->total_object_count;
-               object_count            = c->ctr1->object_count;
-               first_object            = c->ctr1->first_object;
+               mapping_ctr                     = &c->ctr1->mapping_ctr;
+               total_object_count              = c->ctr1->total_object_count;
+               object_count                    = s->schema_part.object_count;
+               first_object                    = s->schema_part.first_object;
+               linked_attributes_count         = 0;
+               linked_attributes               = NULL;
+               s_dsa->highwatermark            = c->ctr1->new_highwatermark;
+               s_dsa->source_dsa_obj_guid      = c->ctr1->source_dsa_guid;
+               s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
+               uptodateness_vector             = NULL; /* TODO: map it */
                break;
        case 6:
-               mapping_ctr             = &c->ctr6->mapping_ctr;
-               total_object_count      = c->ctr6->total_object_count;
-               object_count            = c->ctr6->object_count;
-               first_object            = c->ctr6->first_object;
+               mapping_ctr                     = &c->ctr6->mapping_ctr;
+               total_object_count              = c->ctr6->total_object_count;
+               object_count                    = s->schema_part.object_count;
+               first_object                    = s->schema_part.first_object;
+               linked_attributes_count         = 0; /* TODO: ! */
+               linked_attributes               = NULL; /* TODO: ! */;
+               s_dsa->highwatermark            = c->ctr6->new_highwatermark;
+               s_dsa->source_dsa_obj_guid      = c->ctr6->source_dsa_guid;
+               s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
+               uptodateness_vector             = c->ctr6->uptodateness_vector;
                break;
        default:
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       if (total_object_count) {
-               DEBUG(0,("Schema-DN[%s] objects[%u/%u]\n",
-                       c->partition->nc.dn, object_count, total_object_count));
-       } else {
-               DEBUG(0,("Schema-DN[%s] objects[%u]\n",
-               c->partition->nc.dn, object_count));
-       }
+       s_dsa->replica_flags            = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
+                                       | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
+                                       | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
+       memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
 
-       if (!s->schema) {
-               s->schema = talloc_zero(s, struct dsdb_schema);
-               NT_STATUS_HAVE_NO_MEMORY(s->schema);
-
-               status = dsdb_load_oid_mappings(s->schema, mapping_ctr);
-               if (!W_ERROR_IS_OK(status)) {
-                       return werror_to_ntstatus(status);
-               }
-       } else {
-               status = dsdb_verify_oid_mappings(s->schema, mapping_ctr);
-               if (!W_ERROR_IS_OK(status)) {
-                       return werror_to_ntstatus(status);
-               }
-       }
+       tmp_dns_name    = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
+       NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
+       tmp_dns_name    = talloc_asprintf_append(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
+       NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
+       s_dsa->other_info->dns_name = tmp_dns_name;
 
        for (cur = first_object; cur; cur = cur->next_object) {
-               uint32_t i;
-               bool dn_printed = false;
                bool is_attr = false;
                bool is_class = false;
 
@@ -150,19 +323,18 @@ static NTSTATUS test_become_dc_schema_chunk(void *private_data,
                        a = &cur->object.attribute_ctr.attributes[i];
                        status = dsdb_map_int2oid(s->schema, a->attid, s, &oid);
                        if (!W_ERROR_IS_OK(status)) {
-                               if (!dn_printed) {
-                                       DEBUG(0,("%s:\n", cur->object.identifier->dn));
-                                       dn_printed = true;
-                               }
-                               DEBUG(0,("\tattr 0x%08X => %s\n", a->attid, win_errstr(status)));
+                               return werror_to_ntstatus(status);
                        }
 
                        switch (a->attid) {
                        case DRSUAPI_ATTRIBUTE_objectClass:
-                       case DRSUAPI_ATTRIBUTE_attributeID:
-                       case DRSUAPI_ATTRIBUTE_attributeSyntax:
-                               for (j=0; j < a->value_ctr.uint32.num_values; j++) {
-                                       uint32_t val = *a->value_ctr.uint32.values[j].value;
+                               for (j=0; j < a->value_ctr.num_values; j++) {
+                                       uint32_t val = 0xFFFFFFFF;
+
+                                       if (a->value_ctr.values[i].blob
+                                           && a->value_ctr.values[i].blob->length == 4) {
+                                               val = IVAL(a->value_ctr.values[i].blob->data,0);
+                                       }
 
                                        if (val == DRSUAPI_OBJECTCLASS_attributeSchema) {
                                                is_attr = true;
@@ -170,17 +342,8 @@ static NTSTATUS test_become_dc_schema_chunk(void *private_data,
                                        if (val == DRSUAPI_OBJECTCLASS_classSchema) {
                                                is_class = true;
                                        }
-
-                                       status = dsdb_map_int2oid(s->schema, val, s, &oid);
-                                       if (!W_ERROR_IS_OK(status)) {
-                                               if (!dn_printed) {
-                                                       DEBUG(0,("%s:\n", cur->object.identifier->dn));
-                                                       dn_printed = true;
-                                               }
-                                               DEBUG(0,("\tattr 0x%08X => %s value[%u] 0x%08X => %s\n",
-                                                        a->attid, oid, j, val, win_errstr(status)));
-                                       }
                                }
+
                                break;
                        default:
                                break;
@@ -188,44 +351,202 @@ static NTSTATUS test_become_dc_schema_chunk(void *private_data,
                }
 
                if (is_attr) {
-                       struct dsdb_attribute sa;
-                       status = dsdb_attribute_from_drsuapi(s->schema, &cur->object, s, &sa);
+                       struct dsdb_attribute *sa;
+
+                       sa = talloc_zero(s->schema, struct dsdb_attribute);
+                       NT_STATUS_HAVE_NO_MEMORY(sa);
+
+                       status = dsdb_attribute_from_drsuapi(s->schema, &cur->object, s, sa);
                        if (!W_ERROR_IS_OK(status)) {
                                return werror_to_ntstatus(status);
                        }
+
+                       DLIST_ADD_END(s->schema->attributes, sa, struct dsdb_attribute *);
                }
 
                if (is_class) {
-                       struct dsdb_class sc;
-                       status = dsdb_class_from_drsuapi(s->schema, &cur->object, s, &sc);
+                       struct dsdb_class *sc;
+
+                       sc = talloc_zero(s->schema, struct dsdb_class);
+                       NT_STATUS_HAVE_NO_MEMORY(sc);
+
+                       status = dsdb_class_from_drsuapi(s->schema, &cur->object, s, sc);
                        if (!W_ERROR_IS_OK(status)) {
                                return werror_to_ntstatus(status);
                        }
+
+                       DLIST_ADD_END(s->schema->classes, sc, struct dsdb_class *);
                }
        }
 
+       ret = dsdb_set_schema(s->ldb, s->schema);
+       if (ret != LDB_SUCCESS) {
+               return NT_STATUS_FOOBAR;
+       }
+
+       status = dsdb_extended_replicated_objects_commit(s->ldb,
+                                                        c->partition->nc.dn,
+                                                        s->schema,
+                                                        mapping_ctr,
+                                                        object_count,
+                                                        first_object,
+                                                        linked_attributes_count,
+                                                        linked_attributes,
+                                                        s_dsa,
+                                                        uptodateness_vector,
+                                                        s, &objs);
+       if (!W_ERROR_IS_OK(status)) {
+               DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
+               return werror_to_ntstatus(status);
+       }
+
+       if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
+               for (i=0; i < objs->num_objects; i++) {
+                       struct ldb_ldif ldif;
+                       fprintf(stdout, "#\n");
+                       ldif.changetype = LDB_CHANGETYPE_NONE;
+                       ldif.msg = objs->objects[i].msg;
+                       ldb_ldif_write_file(s->ldb, stdout, &ldif);
+                       NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
+               }
+       }
+
+       talloc_free(s_dsa);
+       talloc_free(objs);
        return NT_STATUS_OK;
 }
 
-static NTSTATUS test_become_dc_store_chunk(void *private_data,
-                                          const struct libnet_BecomeDC_StoreChunk *c)
+static NTSTATUS test_become_dc_schema_chunk(void *private_data,
+                                           const struct libnet_BecomeDC_StoreChunk *c)
 {
+       struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
+       WERROR status;
+       const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
        uint32_t total_object_count;
        uint32_t object_count;
+       struct drsuapi_DsReplicaObjectListItemEx *first_object;
+       struct drsuapi_DsReplicaObjectListItemEx *cur;
 
        switch (c->ctr_level) {
        case 1:
+               mapping_ctr             = &c->ctr1->mapping_ctr;
                total_object_count      = c->ctr1->total_object_count;
                object_count            = c->ctr1->object_count;
+               first_object            = c->ctr1->first_object;
                break;
        case 6:
+               mapping_ctr             = &c->ctr6->mapping_ctr;
                total_object_count      = c->ctr6->total_object_count;
                object_count            = c->ctr6->object_count;
+               first_object            = c->ctr6->first_object;
+               break;
+       default:
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       if (total_object_count) {
+               DEBUG(0,("Schema-DN[%s] objects[%u/%u]\n",
+                       c->partition->nc.dn, object_count, total_object_count));
+       } else {
+               DEBUG(0,("Schema-DN[%s] objects[%u]\n",
+               c->partition->nc.dn, object_count));
+       }
+
+       if (!s->schema) {
+               s->schema = talloc_zero(s, struct dsdb_schema);
+               NT_STATUS_HAVE_NO_MEMORY(s->schema);
+
+               status = dsdb_load_oid_mappings_drsuapi(s->schema, mapping_ctr);
+               if (!W_ERROR_IS_OK(status)) {
+                       return werror_to_ntstatus(status);
+               }
+       } else {
+               status = dsdb_verify_oid_mappings_drsuapi(s->schema, mapping_ctr);
+               if (!W_ERROR_IS_OK(status)) {
+                       return werror_to_ntstatus(status);
+               }
+       }
+
+       if (!s->schema_part.first_object) {
+               s->schema_part.object_count = object_count;
+               s->schema_part.first_object = talloc_steal(s, first_object);
+       } else {
+               s->schema_part.object_count             += object_count;
+               s->schema_part.last_object->next_object = talloc_steal(s->schema_part.last_object,
+                                                                      first_object);
+       }
+       for (cur = first_object; cur->next_object; cur = cur->next_object) {}
+       s->schema_part.last_object = cur;
+
+       if (c->partition->highwatermark.tmp_highest_usn == c->partition->highwatermark.highest_usn) {
+               return test_apply_schema(s, c);
+       }
+
+       return NT_STATUS_OK;
+}
+
+static NTSTATUS test_become_dc_store_chunk(void *private_data,
+                                          const struct libnet_BecomeDC_StoreChunk *c)
+{
+       struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
+       WERROR status;
+       const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
+       uint32_t total_object_count;
+       uint32_t object_count;
+       struct drsuapi_DsReplicaObjectListItemEx *first_object;
+       uint32_t linked_attributes_count;
+       struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
+       const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
+       struct dsdb_extended_replicated_objects *objs;
+       struct repsFromTo1 *s_dsa;
+       char *tmp_dns_name;
+       uint32_t i;
+
+       s_dsa                   = talloc_zero(s, struct repsFromTo1);
+       NT_STATUS_HAVE_NO_MEMORY(s_dsa);
+       s_dsa->other_info       = talloc(s_dsa, struct repsFromTo1OtherInfo);
+       NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
+
+       switch (c->ctr_level) {
+       case 1:
+               mapping_ctr                     = &c->ctr1->mapping_ctr;
+               total_object_count              = c->ctr1->total_object_count;
+               object_count                    = c->ctr1->object_count;
+               first_object                    = c->ctr1->first_object;
+               linked_attributes_count         = 0;
+               linked_attributes               = NULL;
+               s_dsa->highwatermark            = c->ctr1->new_highwatermark;
+               s_dsa->source_dsa_obj_guid      = c->ctr1->source_dsa_guid;
+               s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
+               uptodateness_vector             = NULL; /* TODO: map it */
+               break;
+       case 6:
+               mapping_ctr                     = &c->ctr6->mapping_ctr;
+               total_object_count              = c->ctr6->total_object_count;
+               object_count                    = c->ctr6->object_count;
+               first_object                    = c->ctr6->first_object;
+               linked_attributes_count         = c->ctr6->linked_attributes_count;
+               linked_attributes               = c->ctr6->linked_attributes;
+               s_dsa->highwatermark            = c->ctr6->new_highwatermark;
+               s_dsa->source_dsa_obj_guid      = c->ctr6->source_dsa_guid;
+               s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
+               uptodateness_vector             = c->ctr6->uptodateness_vector;
                break;
        default:
                return NT_STATUS_INVALID_PARAMETER;
        }
 
+       s_dsa->replica_flags            = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
+                                       | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
+                                       | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
+       memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
+
+       tmp_dns_name    = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
+       NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
+       tmp_dns_name    = talloc_asprintf_append(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
+       NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
+       s_dsa->other_info->dns_name = tmp_dns_name;
+
        if (total_object_count) {
                DEBUG(0,("Partition[%s] objects[%u/%u]\n",
                        c->partition->nc.dn, object_count, total_object_count));
@@ -234,6 +555,61 @@ static NTSTATUS test_become_dc_store_chunk(void *private_data,
                c->partition->nc.dn, object_count));
        }
 
+       status = dsdb_extended_replicated_objects_commit(s->ldb,
+                                                        c->partition->nc.dn,
+                                                        s->schema,
+                                                        mapping_ctr,
+                                                        object_count,
+                                                        first_object,
+                                                        linked_attributes_count,
+                                                        linked_attributes,
+                                                        s_dsa,
+                                                        uptodateness_vector,
+                                                        s, &objs);
+       if (!W_ERROR_IS_OK(status)) {
+               DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
+               return werror_to_ntstatus(status);
+       }
+
+       if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
+               for (i=0; i < objs->num_objects; i++) {
+                       struct ldb_ldif ldif;
+                       fprintf(stdout, "#\n");
+                       ldif.changetype = LDB_CHANGETYPE_NONE;
+                       ldif.msg = objs->objects[i].msg;
+                       ldb_ldif_write_file(s->ldb, stdout, &ldif);
+                       NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
+               }
+       }
+       talloc_free(s_dsa);
+       talloc_free(objs);
+
+       for (i=0; i < linked_attributes_count; i++) {
+               const struct dsdb_attribute *sa;
+
+               if (!linked_attributes[i].identifier) {
+                       return NT_STATUS_FOOBAR;                
+               }
+
+               if (!linked_attributes[i].value.blob) {
+                       return NT_STATUS_FOOBAR;                
+               }
+
+               sa = dsdb_attribute_by_attributeID_id(s->schema,
+                                                     linked_attributes[i].attid);
+               if (!sa) {
+                       return NT_STATUS_FOOBAR;
+               }
+
+               if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
+                       DEBUG(0,("# %s\n", sa->lDAPDisplayName));
+                       NDR_PRINT_DEBUG(drsuapi_DsReplicaLinkedAttribute, &linked_attributes[i]);
+                       dump_data(0,
+                               linked_attributes[i].value.blob->data,
+                               linked_attributes[i].value.blob->length);
+               }
+       }
+
        return NT_STATUS_OK;
 }
 
@@ -261,6 +637,8 @@ BOOL torture_net_become_dc(struct torture_context *torture)
        s->ctx = libnet_context_init(event_context_init(s));
        s->ctx->cred = cmdline_credentials;
 
+       s->ldb = ldb_init(s);
+
        ZERO_STRUCT(b);
        b.in.domain_dns_name            = torture_join_dom_dns_name(s->tj);
        b.in.domain_netbios_name        = torture_join_dom_netbios_name(s->tj);