Fix include paths to new location of libutil.
[bbaumbach/samba-autobuild/.git] / source4 / torture / libnet / libnet_BecomeDC.c
index f8699fe06abaccd4bfcef313e85443b7128322dc..2b1bff40ee64efedeb50882676f82a613f8ed8c4 100644 (file)
@@ -26,7 +26,7 @@
 #include "libnet/libnet.h"
 #include "lib/events/events.h"
 #include "dsdb/samdb/samdb.h"
-#include "lib/util/dlinklist.h"
+#include "../lib/util/dlinklist.h"
 #include "lib/ldb/include/ldb.h"
 #include "lib/ldb/include/ldb_errors.h"
 #include "librpc/ndr/libndr.h"
@@ -38,6 +38,7 @@
 #include "auth/auth.h"
 #include "param/param.h"
 #include "torture/util.h"
+#include "param/provision.h"
 
 struct test_become_dc_state {
        struct libnet_context *ctx;
@@ -66,59 +67,28 @@ static NTSTATUS test_become_dc_prepare_db(void *private_data,
 {
        struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
        struct provision_settings settings;
+       struct provision_result result;
        NTSTATUS status;
-       bool ok;
-       struct loadparm_context *lp_ctx = loadparm_init(s);
-       char *smbconf;
-
-       if (!lp_ctx) {
-               return NT_STATUS_NO_MEMORY;
-       }
 
-       settings.dns_name = p->dest_dsa->dns_name;
        settings.site_name = p->dest_dsa->site_name;
        settings.root_dn_str = p->forest->root_dn_str;
        settings.domain_dn_str = p->domain->dn_str;
        settings.config_dn_str = p->forest->config_dn_str;
        settings.schema_dn_str = p->forest->schema_dn_str;
+       settings.server_dn_str = torture_join_server_dn_str(s->tj);
+       settings.invocation_id = &p->dest_dsa->invocation_id;
        settings.netbios_name = p->dest_dsa->netbios_name;
+       settings.host_ip = NULL;
        settings.realm = torture_join_dom_dns_name(s->tj);
        settings.domain = torture_join_dom_netbios_name(s->tj);
-       settings.server_dn_str = torture_join_server_dn_str(s->tj);
+       settings.ntds_dn_str = p->dest_dsa->ntds_dn_str;
        settings.machine_password = cli_credentials_get_password(s->machine_account);
        settings.targetdir = s->targetdir;
 
-       status = provision_bare(s, s->lp_ctx, &settings);
-       
-       smbconf = talloc_asprintf(lp_ctx, "%s/%s", s->targetdir, "/etc/smb.conf");
-
-       ok = lp_load(lp_ctx, smbconf);
-       if (!ok) {
-               DEBUG(0,("Failed load freshly generated smb.conf '%s'\n", smbconf));
-               return NT_STATUS_INVALID_PARAMETER;
-       }
-
-       s->ldb = ldb_wrap_connect(s, lp_ctx, lp_sam_url(lp_ctx),
-                                 system_session(s, lp_ctx),
-                                 NULL, 0, NULL);
-       if (!s->ldb) {
-               DEBUG(0,("Failed to open '%s'\n", lp_sam_url(lp_ctx)));
-               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;
-       }
+       status = provision_bare(s, s->lp_ctx, &settings, &result);
        
-       s->lp_ctx = lp_ctx;
-
+       s->ldb = result.samdb;
+       s->lp_ctx = result.lp_ctx;
         return NT_STATUS_OK;
 
 
@@ -153,7 +123,6 @@ static NTSTATUS test_apply_schema(struct test_become_dc_state *s,
 {
        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;
@@ -182,7 +151,6 @@ static NTSTATUS test_apply_schema(struct test_become_dc_state *s,
        switch (c->ctr_level) {
        case 1:
                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;
@@ -194,7 +162,6 @@ static NTSTATUS test_apply_schema(struct test_become_dc_state *s,
                break;
        case 6:
                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: ! */
@@ -355,7 +322,7 @@ static NTSTATUS test_apply_schema(struct test_become_dc_state *s,
 
        sam_ldb_path = talloc_asprintf(s, "%s/%s", s->targetdir, "private/sam.ldb");
        DEBUG(0,("Reopen the SAM LDB with system credentials and a already stored schema: %s\n", sam_ldb_path));
-       s->ldb = ldb_wrap_connect(s, s->tctx->lp_ctx, sam_ldb_path,
+       s->ldb = ldb_wrap_connect(s, s->tctx->ev, s->tctx->lp_ctx, sam_ldb_path,
                                  system_session(s, s->tctx->lp_ctx),
                                  NULL, 0, NULL);
        if (!s->ldb) {
@@ -390,34 +357,41 @@ static NTSTATUS test_become_dc_schema_chunk(void *private_data,
        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 nc_object_count;
        uint32_t object_count;
        struct drsuapi_DsReplicaObjectListItemEx *first_object;
        struct drsuapi_DsReplicaObjectListItemEx *cur;
+       uint32_t nc_linked_attributes_count;
+       uint32_t linked_attributes_count;
 
        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;
+               nc_object_count                 = c->ctr1->extended_ret; /* maybe w2k send this unexpected? */
+               object_count                    = c->ctr1->object_count;
+               first_object                    = c->ctr1->first_object;
+               nc_linked_attributes_count      = 0;
+               linked_attributes_count         = 0;
                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;
+               nc_object_count                 = c->ctr6->nc_object_count;
+               object_count                    = c->ctr6->object_count;
+               first_object                    = c->ctr6->first_object;
+               nc_linked_attributes_count      = c->ctr6->nc_linked_attributes_count;
+               linked_attributes_count         = c->ctr6->linked_attributes_count;
                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));
+       if (nc_object_count) {
+               DEBUG(0,("Schema-DN[%s] objects[%u/%u] linked_values[%u/%u]\n",
+                       c->partition->nc.dn, object_count, nc_object_count,
+                       linked_attributes_count, nc_linked_attributes_count));
        } else {
-               DEBUG(0,("Schema-DN[%s] objects[%u]\n",
-               c->partition->nc.dn, object_count));
+               DEBUG(0,("Schema-DN[%s] objects[%u] linked_values[%u\n",
+               c->partition->nc.dn, object_count, linked_attributes_count));
        }
 
        if (!s->schema) {
@@ -449,7 +423,7 @@ static NTSTATUS test_become_dc_schema_chunk(void *private_data,
        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) {
+       if (!c->partition->more_data) {
                return test_apply_schema(s, c);
        }
 
@@ -462,9 +436,10 @@ static NTSTATUS test_become_dc_store_chunk(void *private_data,
        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 nc_object_count;
        uint32_t object_count;
        struct drsuapi_DsReplicaObjectListItemEx *first_object;
+       uint32_t nc_linked_attributes_count;
        uint32_t linked_attributes_count;
        struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
        const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
@@ -481,9 +456,10 @@ static NTSTATUS test_become_dc_store_chunk(void *private_data,
        switch (c->ctr_level) {
        case 1:
                mapping_ctr                     = &c->ctr1->mapping_ctr;
-               total_object_count              = c->ctr1->total_object_count;
+               nc_object_count                 = c->ctr1->extended_ret; /* maybe w2k send this unexpected? */
                object_count                    = c->ctr1->object_count;
                first_object                    = c->ctr1->first_object;
+               nc_linked_attributes_count      = 0;
                linked_attributes_count         = 0;
                linked_attributes               = NULL;
                s_dsa->highwatermark            = c->ctr1->new_highwatermark;
@@ -493,9 +469,10 @@ static NTSTATUS test_become_dc_store_chunk(void *private_data,
                break;
        case 6:
                mapping_ctr                     = &c->ctr6->mapping_ctr;
-               total_object_count              = c->ctr6->total_object_count;
+               nc_object_count                 = c->ctr6->nc_object_count;
                object_count                    = c->ctr6->object_count;
                first_object                    = c->ctr6->first_object;
+               nc_linked_attributes_count      = c->ctr6->nc_linked_attributes_count;
                linked_attributes_count         = c->ctr6->linked_attributes_count;
                linked_attributes               = c->ctr6->linked_attributes;
                s_dsa->highwatermark            = c->ctr6->new_highwatermark;
@@ -518,12 +495,13 @@ static NTSTATUS test_become_dc_store_chunk(void *private_data,
        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));
+       if (nc_object_count) {
+               DEBUG(0,("Partition[%s] objects[%u/%u] linked_values[%u/%u]\n",
+                       c->partition->nc.dn, object_count, nc_object_count,
+                       linked_attributes_count, nc_linked_attributes_count));
        } else {
-               DEBUG(0,("Partition[%s] objects[%u]\n",
-               c->partition->nc.dn, object_count));
+               DEBUG(0,("Partition[%s] objects[%u] linked_values[%u\n",
+               c->partition->nc.dn, object_count, linked_attributes_count));
        }
 
        status = dsdb_extended_replicated_objects_commit(s->ldb,
@@ -626,7 +604,7 @@ bool torture_net_become_dc(struct torture_context *torture)
        s->ctx = libnet_context_init(torture->ev, torture->lp_ctx);
        s->ctx->cred = cmdline_credentials;
 
-       s->ldb = ldb_init(s);
+       s->ldb = ldb_init(s, torture->ev);
 
        ZERO_STRUCT(b);
        b.in.domain_dns_name            = torture_join_dom_dns_name(s->tj);
@@ -687,7 +665,7 @@ bool torture_net_become_dc(struct torture_context *torture)
 
        sam_ldb_path = talloc_asprintf(s, "%s/%s", s->targetdir, "private/sam.ldb");
        DEBUG(0,("Reopen the SAM LDB with system credentials and all replicated data: %s\n", sam_ldb_path));
-       s->ldb = ldb_wrap_connect(s, s->lp_ctx, sam_ldb_path,
+       s->ldb = ldb_wrap_connect(s, s->tctx->ev, s->lp_ctx, sam_ldb_path,
                                  system_session(s, s->lp_ctx),
                                  NULL, 0, NULL);
        if (!s->ldb) {
@@ -724,7 +702,7 @@ cleanup:
        }
 
        /* Leave domain. */                          
-       torture_leave_domain(s->tj);
+       torture_leave_domain(torture, s->tj);
 
        talloc_free(s);
        return ret;