s4-loadparm: 2nd half of lp_ to lpcfg_ conversion
[kamenim/samba.git] / source4 / torture / rpc / dssync.c
index 58ea07e36ba7f6f21b1bae140ad134e87486eceb..5e5929f7341891337ecb784fee35f4b15aa09ba1 100644 (file)
 #include "auth/gensec/gensec.h"
 #include "param/param.h"
 #include "dsdb/samdb/samdb.h"
-#include "lib/ldb_wrap.h"
-#include "torture/rpc/rpc.h"
+#include "torture/rpc/torture_rpc.h"
 #include "torture/drs/proto.h"
 #include "lib/tsocket/tsocket.h"
 #include "libcli/resolve/resolve.h"
 
 struct DsSyncBindInfo {
        struct dcerpc_pipe *drs_pipe;
+       struct dcerpc_binding_handle *drs_handle;
        struct drsuapi_DsBind req;
        struct GUID bind_guid;
        struct drsuapi_DsBindInfoCtr our_bind_info_ctr;
@@ -104,7 +104,7 @@ static struct DsSyncTest *test_create_context(struct torture_context *tctx)
        make_nbt_name_server(&name, ctx->drsuapi_binding->host);
 
        /* do an initial name resolution to find its IP */
-       status = resolve_name(lp_resolve_context(tctx->lp_ctx), &name, tctx,
+       status = resolve_name(lpcfg_resolve_context(tctx->lp_ctx), &name, tctx,
                              &ctx->dest_address, tctx->ev);
        if (!NT_STATUS_IS_OK(status)) {
                printf("Failed to resolve %s - %s\n",
@@ -164,7 +164,7 @@ static struct DsSyncTest *test_create_context(struct torture_context *tctx)
        our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
        our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7;
        our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT;
-       if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "xpress", false)) {
+       if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "xpress", false)) {
                our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS;
        }
        our_bind_info28->site_guid              = GUID_zero();
@@ -203,13 +203,11 @@ static bool _test_DsBind(struct torture_context *tctx,
                printf("Failed to connect to server as a BDC: %s\n", nt_errstr(status));
                return false;
        }
+       b->drs_handle = b->drs_pipe->binding_handle;
 
-       status = dcerpc_drsuapi_DsBind(b->drs_pipe, ctx, &b->req);
+       status = dcerpc_drsuapi_DsBind_r(b->drs_handle, ctx, &b->req);
        if (!NT_STATUS_IS_OK(status)) {
                const char *errstr = nt_errstr(status);
-               if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
-                       errstr = dcerpc_errstr(ctx, b->drs_pipe->last_fault_code);
-               }
                printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
                ret = false;
        } else if (!W_ERROR_IS_OK(b->req.out.result)) {
@@ -274,7 +272,7 @@ static bool test_LDAPBind(struct torture_context *tctx, struct DsSyncTest *ctx,
        ldb_set_modules_dir(ldb,
                            talloc_asprintf(ldb,
                                            "%s/ldb",
-                                           lp_modulesdir(tctx->lp_ctx)));
+                                           lpcfg_modulesdir(tctx->lp_ctx)));
 
        if (ldb_set_opaque(ldb, "credentials", credentials)) {
                talloc_free(ldb);
@@ -313,11 +311,11 @@ static bool test_GetInfo(struct torture_context *tctx, struct DsSyncTest *ctx)
 
        ret2 = tsocket_address_inet_from_strings(tctx, "ip",
                                                 ctx->dest_address,
-                                                lp_cldap_port(tctx->lp_ctx),
+                                                lpcfg_cldap_port(tctx->lp_ctx),
                                                 &dest_addr);
        if (ret2 != 0) {
                printf("failed to create tsocket_address for '%s' port %u - %s\n",
-                       ctx->drsuapi_binding->host, lp_cldap_port(tctx->lp_ctx),
+                       ctx->drsuapi_binding->host, lpcfg_cldap_port(tctx->lp_ctx),
                        strerror(errno));
                return false;
        }
@@ -339,17 +337,14 @@ static bool test_GetInfo(struct torture_context *tctx, struct DsSyncTest *ctx)
        r.in.req->req1.format_flags     = DRSUAPI_DS_NAME_FLAG_NO_FLAGS;
        r.in.req->req1.format_offered   = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
        r.in.req->req1.format_desired   = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
-       names[0].str = talloc_asprintf(ctx, "%s\\", lp_workgroup(tctx->lp_ctx));
+       names[0].str = talloc_asprintf(ctx, "%s\\", lpcfg_workgroup(tctx->lp_ctx));
 
        r.out.level_out                 = &level_out;
        r.out.ctr                       = &ctr;
 
-       status = dcerpc_drsuapi_DsCrackNames(ctx->admin.drsuapi.drs_pipe, ctx, &r);
+       status = dcerpc_drsuapi_DsCrackNames_r(ctx->admin.drsuapi.drs_handle, ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
                const char *errstr = nt_errstr(status);
-               if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
-                       errstr = dcerpc_errstr(ctx, ctx->admin.drsuapi.drs_pipe->last_fault_code);
-               }
                printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
                return false;
        } else if (!W_ERROR_IS_OK(r.out.result)) {
@@ -365,7 +360,7 @@ static bool test_GetInfo(struct torture_context *tctx, struct DsSyncTest *ctx)
        search.in.acct_control = -1;
        search.in.version               = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX;
        search.in.map_response = true;
-       status = cldap_netlogon(cldap, lp_iconv_convenience(tctx->lp_ctx), ctx, &search);
+       status = cldap_netlogon(cldap, ctx, &search);
        if (!NT_STATUS_IS_OK(status)) {
                const char *errstr = nt_errstr(status);
                ctx->site_name = talloc_asprintf(ctx, "%s", "Default-First-Site-Name");
@@ -406,12 +401,12 @@ static bool test_analyse_objects(struct torture_context *tctx,
        struct ldb_extended_dn_control *extended_dn_ctrl;
        const char *err_msg;
        
-       if (!dsdb_get_schema(ldb)) {
+       if (!dsdb_get_schema(ldb, NULL)) {
                struct dsdb_schema *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, lp_iconv_convenience(tctx->lp_ctx));
+               ldap_schema = dsdb_new_schema(ctx);
                if (!ldap_schema) {
                        return false;
                }
@@ -605,12 +600,12 @@ static bool test_analyse_objects(struct torture_context *tctx,
                talloc_free(search_req);
        }
 
-       if (!lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "print_pwd_blobs", false)) {
+       if (!lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "print_pwd_blobs", false)) {
                talloc_free(objs);
                return true;    
        }
 
-       save_values_dir = lp_parm_string(tctx->lp_ctx, NULL, "dssync", "save_pwd_blobs_dir");
+       save_values_dir = lpcfg_parm_string(tctx->lp_ctx, NULL, "dssync", "save_pwd_blobs_dir");
 
        for (cur = first_object; cur; cur = cur->next_object) {
                const char *dn;
@@ -731,8 +726,7 @@ static bool test_analyse_objects(struct torture_context *tctx,
                                if (pull_fn) {
                                        /* Can't use '_all' because of PIDL bugs with relative pointers */
                                        ndr_err = ndr_pull_struct_blob(&plain_data, ptr,
-                                                                      lp_iconv_convenience(tctx->lp_ctx), ptr,
-                                                                      pull_fn);
+                                                                      ptr, pull_fn);
                                        if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
                                                ndr_print_debug(print_fn, name, ptr);
                                        } else {
@@ -779,17 +773,17 @@ static bool test_FetchData(struct torture_context *tctx, struct DsSyncTest *ctx)
        ZERO_STRUCT(null_guid);
        ZERO_STRUCT(null_sid);
 
-       partition = lp_parm_string(tctx->lp_ctx, NULL, "dssync", "partition");
+       partition = lpcfg_parm_string(tctx->lp_ctx, NULL, "dssync", "partition");
        if (partition == NULL) {
                partition = ctx->domain_dn;
                printf("dssync:partition not specified, defaulting to %s.\n", ctx->domain_dn);
        }
 
-       highest_usn = lp_parm_int(tctx->lp_ctx, NULL, "dssync", "highest_usn", 0);
+       highest_usn = lpcfg_parm_int(tctx->lp_ctx, NULL, "dssync", "highest_usn", 0);
 
-       array[0].level = lp_parm_int(tctx->lp_ctx, NULL, "dssync", "get_nc_changes_level", array[0].level);
+       array[0].level = lpcfg_parm_int(tctx->lp_ctx, NULL, "dssync", "get_nc_changes_level", array[0].level);
 
-       if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "print_pwd_blobs", false)) {
+       if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "print_pwd_blobs", false)) {
                const struct samr_Password *nthash;
                nthash = cli_credentials_get_nt_hash(ctx->new_dc.credentials, ctx);
                if (nthash) {
@@ -804,7 +798,7 @@ static bool test_FetchData(struct torture_context *tctx, struct DsSyncTest *ctx)
        }
 
        for (i=0; i < ARRAY_SIZE(array); i++) {
-               printf("testing DsGetNCChanges level %d\n",
+               printf("Testing DsGetNCChanges level %d\n",
                        array[i].level);
 
                r.in.bind_handle        = &ctx->new_dc.drsuapi.bind_handle;
@@ -825,10 +819,10 @@ static bool test_FetchData(struct torture_context *tctx, struct DsSyncTest *ctx)
                        r.in.req->req5.highwatermark.highest_usn        = highest_usn;
                        r.in.req->req5.uptodateness_vector              = NULL;
                        r.in.req->req5.replica_flags                    = 0;
-                       if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "compression", false)) {
+                       if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "compression", false)) {
                                r.in.req->req5.replica_flags            |= DRSUAPI_DRS_USE_COMPRESSION;
                        }
-                       if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "neighbour_writeable", true)) {
+                       if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "neighbour_writeable", true)) {
                                r.in.req->req5.replica_flags            |= DRSUAPI_DRS_WRIT_REP;
                        }
                        r.in.req->req5.replica_flags                    |= DRSUAPI_DRS_INIT_SYNC
@@ -857,10 +851,10 @@ static bool test_FetchData(struct torture_context *tctx, struct DsSyncTest *ctx)
                        r.in.req->req8.highwatermark.highest_usn        = highest_usn;
                        r.in.req->req8.uptodateness_vector              = NULL;
                        r.in.req->req8.replica_flags                    = 0;
-                       if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "compression", false)) {
+                       if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "compression", false)) {
                                r.in.req->req8.replica_flags            |= DRSUAPI_DRS_USE_COMPRESSION;
                        }
-                       if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "neighbour_writeable", true)) {
+                       if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "neighbour_writeable", true)) {
                                r.in.req->req8.replica_flags            |= DRSUAPI_DRS_WRIT_REP;
                        }
                        r.in.req->req8.replica_flags                    |= DRSUAPI_DRS_INIT_SYNC
@@ -907,7 +901,7 @@ static bool test_FetchData(struct torture_context *tctx, struct DsSyncTest *ctx)
                                                r.in.req->req8.highwatermark.highest_usn);
                        }
 
-                       status = dcerpc_drsuapi_DsGetNCChanges(ctx->new_dc.drsuapi.drs_pipe, ctx, &r);
+                       status = dcerpc_drsuapi_DsGetNCChanges_r(ctx->new_dc.drsuapi.drs_handle, ctx, &r);
                        torture_drsuapi_assert_call(tctx, ctx->new_dc.drsuapi.drs_pipe, status,
                                                    &r, "dcerpc_drsuapi_DsGetNCChanges");
 
@@ -1002,22 +996,27 @@ static bool test_FetchNT4Data(struct torture_context *tctx,
        r.out.info              = &info;
        r.out.level_out         = &level_out;
 
-       req.req1.unknown1       = lp_parm_int(tctx->lp_ctx, NULL, "dssync", "nt4-1", 3);
-       req.req1.unknown2       = lp_parm_int(tctx->lp_ctx, NULL, "dssync", "nt4-2", 0x00004000);
+       req.req1.flags = lpcfg_parm_int(tctx->lp_ctx, NULL,
+                                    "dssync", "nt4changelog_flags",
+                                    DRSUAPI_NT4_CHANGELOG_GET_CHANGELOG |
+                                    DRSUAPI_NT4_CHANGELOG_GET_SERIAL_NUMBERS);
+       req.req1.preferred_maximum_length = lpcfg_parm_int(tctx->lp_ctx, NULL,
+                                       "dssync", "nt4changelog_preferred_len",
+                                       0x00004000);
 
        while (1) {
-               req.req1.length = cookie.length;
-               req.req1.data   = cookie.data;
+               req.req1.restart_length = cookie.length;
+               req.req1.restart_data = cookie.data;
 
                r.in.req = &req;
 
-               status = dcerpc_drsuapi_DsGetNT4ChangeLog(ctx->new_dc.drsuapi.drs_pipe, ctx, &r);
+               status = dcerpc_drsuapi_DsGetNT4ChangeLog_r(ctx->new_dc.drsuapi.drs_handle, ctx, &r);
                if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
                        torture_skip(tctx, "DsGetNT4ChangeLog not supported by target server");
                } else if (!NT_STATUS_IS_OK(status)) {
                        const char *errstr = nt_errstr(status);
-                       if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
-                               errstr = dcerpc_errstr(ctx, ctx->new_dc.drsuapi.drs_pipe->last_fault_code);
+                       if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE)) {
+                               torture_skip(tctx, "DsGetNT4ChangeLog not supported by target server");
                        }
                        torture_fail(tctx,
                                     talloc_asprintf(tctx, "dcerpc_drsuapi_DsGetNT4ChangeLog failed - %s\n",
@@ -1034,8 +1033,8 @@ static bool test_FetchNT4Data(struct torture_context *tctx,
                                                     *r.out.level_out));
                } else if (NT_STATUS_IS_OK(r.out.info->info1.status)) {
                } else if (NT_STATUS_EQUAL(r.out.info->info1.status, STATUS_MORE_ENTRIES)) {
-                       cookie.length   = r.out.info->info1.length1;
-                       cookie.data     = r.out.info->info1.data1;
+                       cookie.length   = r.out.info->info1.restart_length;
+                       cookie.data     = r.out.info->info1.restart_data;
                        continue;
                } else {
                        torture_fail(tctx,
@@ -1091,11 +1090,11 @@ static bool torture_dssync_tcase_teardown(struct torture_context *tctx, void *da
 
        /* Unbing admin handle */
        r.in.bind_handle = &ctx->admin.drsuapi.bind_handle;
-       dcerpc_drsuapi_DsUnbind(ctx->admin.drsuapi.drs_pipe, ctx, &r);
+       dcerpc_drsuapi_DsUnbind_r(ctx->admin.drsuapi.drs_handle, ctx, &r);
 
        /* Unbing new_dc handle */
        r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
-       dcerpc_drsuapi_DsUnbind(ctx->new_dc.drsuapi.drs_pipe, ctx, &r);
+       dcerpc_drsuapi_DsUnbind_r(ctx->new_dc.drsuapi.drs_handle, ctx, &r);
 
        talloc_free(ctx);