Remove more uses of global_loadparm.
[jelmer/samba4-debian.git] / source / torture / rpc / samba3rpc.c
index 941c7b4f748febec55b46556a3d5eb409bde3ffb..1386f61c2b1adbfa658f317be48d6b076466776b 100644 (file)
 #include "libcli/security/proto.h"
 #include "param/param.h"
 #include "lib/registry/registry.h"
-
-static struct cli_credentials *create_anon_creds(TALLOC_CTX *mem_ctx)
-{
-       struct cli_credentials *result;
-
-       if (!(result = cli_credentials_init(mem_ctx))) {
-               return NULL;
-       }
-
-       cli_credentials_set_conf(result, global_loadparm);
-       cli_credentials_set_anonymous(result);
-
-       return result;
-}
+#include "libcli/resolve/resolve.h"
 
 /*
  * This tests a RPC call using an invalid vuid
@@ -84,6 +71,7 @@ bool torture_bind_authcontext(struct torture_context *torture)
        struct dcerpc_pipe *lsa_pipe;
        struct cli_credentials *anon_creds;
        struct smb_composite_sesssetup setup;
+       struct smbcli_options options;
 
        mem_ctx = talloc_init("torture_bind_authcontext");
 
@@ -92,17 +80,22 @@ bool torture_bind_authcontext(struct torture_context *torture)
                return false;
        }
 
+       lp_smbcli_options(torture->lp_ctx, &options);
+
        status = smbcli_full_connection(mem_ctx, &cli,
                                        torture_setting_string(torture, "host", NULL),
+                                       lp_smb_ports(torture->lp_ctx),
                                        "IPC$", NULL, cmdline_credentials,
-                                       NULL);
+                                       lp_resolve_context(torture->lp_ctx),
+                                       NULL, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
                goto done;
        }
 
-       lsa_pipe = dcerpc_pipe_init(mem_ctx, cli->transport->socket->event.ctx);
+       lsa_pipe = dcerpc_pipe_init(mem_ctx, cli->transport->socket->event.ctx,
+                                   lp_iconv_convenience(torture->lp_ctx));
        if (lsa_pipe == NULL) {
                d_printf("dcerpc_pipe_init failed\n");
                goto done;
@@ -153,7 +146,7 @@ bool torture_bind_authcontext(struct torture_context *torture)
                goto done;
        }
 
-       if (!(anon_creds = create_anon_creds(mem_ctx))) {
+       if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
                d_printf("create_anon_creds failed\n");
                goto done;
        }
@@ -199,6 +192,7 @@ bool torture_bind_authcontext(struct torture_context *torture)
 
 static bool bindtest(struct smbcli_state *cli,
                     struct cli_credentials *credentials,
+                    struct loadparm_context *lp_ctx,
                     uint8_t auth_type, uint8_t auth_level)
 {
        TALLOC_CTX *mem_ctx;
@@ -218,7 +212,8 @@ static bool bindtest(struct smbcli_state *cli,
        }
 
        lsa_pipe = dcerpc_pipe_init(mem_ctx,
-                                   cli->transport->socket->event.ctx);
+                                   cli->transport->socket->event.ctx,
+                                   lp_iconv_convenience(lp_ctx));
        if (lsa_pipe == NULL) {
                d_printf("dcerpc_pipe_init failed\n");
                goto done;
@@ -232,7 +227,7 @@ static bool bindtest(struct smbcli_state *cli,
        }
 
        status = dcerpc_bind_auth(lsa_pipe, &ndr_table_lsarpc,
-                                 credentials, auth_type, auth_level,
+                                 credentials, lp_ctx, auth_type, auth_level,
                                  NULL);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("dcerpc_bind_auth failed: %s\n", nt_errstr(status));
@@ -290,6 +285,7 @@ bool torture_bind_samba3(struct torture_context *torture)
        NTSTATUS status;
        bool ret = false;
        struct smbcli_state *cli;
+       struct smbcli_options options;
 
        mem_ctx = talloc_init("torture_bind_authcontext");
 
@@ -298,10 +294,14 @@ bool torture_bind_samba3(struct torture_context *torture)
                return false;
        }
 
+       lp_smbcli_options(torture->lp_ctx, &options);
+
        status = smbcli_full_connection(mem_ctx, &cli,
                                        torture_setting_string(torture, "host", NULL),
+                                       lp_smb_ports(torture->lp_ctx),
                                        "IPC$", NULL, cmdline_credentials,
-                                       NULL);
+                                       lp_resolve_context(torture->lp_ctx),
+                                       NULL, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
@@ -310,13 +310,13 @@ bool torture_bind_samba3(struct torture_context *torture)
 
        ret = true;
 
-       ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
+       ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_NTLMSSP,
                        DCERPC_AUTH_LEVEL_INTEGRITY);
-       ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
+       ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_NTLMSSP,
                        DCERPC_AUTH_LEVEL_PRIVACY);
-       ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
+       ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_SPNEGO,
                        DCERPC_AUTH_LEVEL_INTEGRITY);
-       ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
+       ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_SPNEGO,
                        DCERPC_AUTH_LEVEL_PRIVACY);
 
  done:
@@ -330,6 +330,7 @@ bool torture_bind_samba3(struct torture_context *torture)
 
 static NTSTATUS get_usr_handle(struct smbcli_state *cli,
                               TALLOC_CTX *mem_ctx,
+                              struct loadparm_context *lp_ctx,
                               struct cli_credentials *admin_creds,
                               uint8_t auth_type,
                               uint8_t auth_level,
@@ -356,7 +357,8 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
        uint32_t user_rid,access_granted;
 
        samr_pipe = dcerpc_pipe_init(mem_ctx,
-                                    cli->transport->socket->event.ctx);
+                                    cli->transport->socket->event.ctx,
+                                    lp_iconv_convenience(lp_ctx));
        if (samr_pipe == NULL) {
                d_printf("dcerpc_pipe_init failed\n");
                status = NT_STATUS_NO_MEMORY;
@@ -372,7 +374,7 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
 
        if (admin_creds != NULL) {
                status = dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
-                                         admin_creds, auth_type, auth_level,
+                                         admin_creds, lp_ctx, auth_type, auth_level,
                                          NULL);
                if (!NT_STATUS_IS_OK(status)) {
                        d_printf("dcerpc_bind_auth failed: %s\n",
@@ -504,6 +506,7 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
  */
 
 static bool create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
+                       struct loadparm_context *lp_ctx,
                        struct cli_credentials *admin_creds,
                        const char *username, const char *password,
                        char **domain_name,
@@ -520,13 +523,13 @@ static bool create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
                return false;
        }
 
-       status = get_usr_handle(cli, tmp_ctx, admin_creds,
+       status = get_usr_handle(cli, tmp_ctx, lp_ctx, admin_creds,
                                DCERPC_AUTH_TYPE_NTLMSSP,
                                DCERPC_AUTH_LEVEL_INTEGRITY,
                                username, domain_name, &samr_pipe, &wks_handle,
                                user_sid);
        if (!NT_STATUS_IS_OK(status)) {
-               d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
+               d_printf("get_usr_handle failed: %s\n", nt_errstr(status));
                goto done;
        }
 
@@ -616,6 +619,7 @@ static bool create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
  */
 
 static bool delete_user(struct smbcli_state *cli,
+                       struct loadparm_context *lp_ctx,
                        struct cli_credentials *admin_creds,
                        const char *username)
 {
@@ -631,7 +635,7 @@ static bool delete_user(struct smbcli_state *cli,
                return false;
        }
 
-       status = get_usr_handle(cli, mem_ctx, admin_creds,
+       status = get_usr_handle(cli, mem_ctx, lp_ctx, admin_creds,
                                DCERPC_AUTH_TYPE_NTLMSSP,
                                DCERPC_AUTH_LEVEL_INTEGRITY,
                                username, &dom_name, &samr_pipe,
@@ -667,6 +671,7 @@ static bool delete_user(struct smbcli_state *cli,
  */
 
 static bool join3(struct smbcli_state *cli,
+                 struct loadparm_context *lp_ctx,
                  bool use_level25,
                  struct cli_credentials *admin_creds,
                  struct cli_credentials *wks_creds)
@@ -684,7 +689,7 @@ static bool join3(struct smbcli_state *cli,
        }
 
        status = get_usr_handle(
-               cli, mem_ctx, admin_creds,
+               cli, mem_ctx, lp_ctx, admin_creds,
                DCERPC_AUTH_TYPE_NTLMSSP,
                DCERPC_AUTH_LEVEL_PRIVACY,
                talloc_asprintf(mem_ctx, "%s$",
@@ -801,6 +806,7 @@ static bool join3(struct smbcli_state *cli,
  */
 
 static bool auth2(struct smbcli_state *cli,
+                 struct loadparm_context *lp_ctx,
                  struct cli_credentials *wks_cred)
 {
        TALLOC_CTX *mem_ctx;
@@ -823,7 +829,8 @@ static bool auth2(struct smbcli_state *cli,
        }
 
        net_pipe = dcerpc_pipe_init(mem_ctx,
-                                   cli->transport->socket->event.ctx);
+                                   cli->transport->socket->event.ctx,
+                                   lp_iconv_convenience(lp_ctx));
        if (net_pipe == NULL) {
                d_printf("dcerpc_pipe_init failed\n");
                goto done;
@@ -908,6 +915,7 @@ static bool auth2(struct smbcli_state *cli,
  */
 
 static bool schan(struct smbcli_state *cli,
+                 struct loadparm_context *lp_ctx,
                  struct cli_credentials *wks_creds,
                  struct cli_credentials *user_creds)
 {
@@ -924,7 +932,8 @@ static bool schan(struct smbcli_state *cli,
        }
 
        net_pipe = dcerpc_pipe_init(mem_ctx,
-                                   cli->transport->socket->event.ctx);
+                                   cli->transport->socket->event.ctx,
+                                   lp_iconv_convenience(lp_ctx));
        if (net_pipe == NULL) {
                d_printf("dcerpc_pipe_init failed\n");
                goto done;
@@ -944,7 +953,7 @@ static bool schan(struct smbcli_state *cli,
 #if 1
        net_pipe->conn->flags |= (DCERPC_SIGN | DCERPC_SEAL);
        status = dcerpc_bind_auth(net_pipe, &ndr_table_netlogon,
-                                 wks_creds, DCERPC_AUTH_TYPE_SCHANNEL,
+                                 wks_creds, lp_ctx, DCERPC_AUTH_TYPE_SCHANNEL,
                                  DCERPC_AUTH_LEVEL_PRIVACY,
                                  NULL);
 #else
@@ -976,7 +985,8 @@ static bool schan(struct smbcli_state *cli,
 
                generate_random_buffer(chal.data, chal.length);
                names_blob = NTLMv2_generate_names_blob(
-                       mem_ctx, cli_credentials_get_workstation(user_creds),
+                       mem_ctx, lp_iconv_convenience(lp_ctx), 
+                       cli_credentials_get_workstation(user_creds),
                        cli_credentials_get_domain(user_creds));
                status = cli_credentials_get_ntlm_response(
                        user_creds, mem_ctx, &flags, chal, names_blob,
@@ -1105,6 +1115,7 @@ static bool schan(struct smbcli_state *cli,
  */
 
 static bool leave(struct smbcli_state *cli,
+                 struct loadparm_context *lp_ctx,
                  struct cli_credentials *admin_creds,
                  struct cli_credentials *wks_creds)
 {
@@ -1112,7 +1123,7 @@ static bool leave(struct smbcli_state *cli,
                NULL, "%s$", cli_credentials_get_workstation(wks_creds));
        bool ret;
 
-       ret = delete_user(cli, admin_creds, wks_name);
+       ret = delete_user(cli, lp_ctx, admin_creds, wks_name);
        talloc_free(wks_name);
        return ret;
 }
@@ -1131,6 +1142,7 @@ bool torture_netlogon_samba3(struct torture_context *torture)
        struct cli_credentials *wks_creds;
        const char *wks_name;
        int i;
+       struct smbcli_options options;
 
        wks_name = torture_setting_string(torture, "wksname", NULL);
        if (wks_name == NULL) {
@@ -1144,14 +1156,19 @@ bool torture_netlogon_samba3(struct torture_context *torture)
                return false;
        }
 
-       if (!(anon_creds = create_anon_creds(mem_ctx))) {
+       if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
                d_printf("create_anon_creds failed\n");
                goto done;
        }
 
+       lp_smbcli_options(torture->lp_ctx, &options);
+
        status = smbcli_full_connection(mem_ctx, &cli,
                                        torture_setting_string(torture, "host", NULL),
-                                       "IPC$", NULL, anon_creds, NULL);
+                                       lp_smb_ports(torture->lp_ctx),
+                                       "IPC$", NULL, anon_creds, 
+                                       lp_resolve_context(torture->lp_ctx),
+                                       NULL, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
@@ -1172,7 +1189,7 @@ bool torture_netlogon_samba3(struct torture_context *torture)
                                     generate_random_str(wks_creds, 8),
                                     CRED_SPECIFIED);
 
-       if (!join3(cli, false, cmdline_credentials, wks_creds)) {
+       if (!join3(cli, torture->lp_ctx, false, cmdline_credentials, wks_creds)) {
                d_printf("join failed\n");
                goto done;
        }
@@ -1189,20 +1206,20 @@ bool torture_netlogon_samba3(struct torture_context *torture)
 
                int j;
 
-               if (!auth2(cli, wks_creds)) {
+               if (!auth2(cli, torture->lp_ctx, wks_creds)) {
                        d_printf("auth2 failed\n");
                        goto done;
                }
 
                for (j=0; j<2; j++) {
-                       if (!schan(cli, wks_creds, cmdline_credentials)) {
+                       if (!schan(cli, torture->lp_ctx, wks_creds, cmdline_credentials)) {
                                d_printf("schan failed\n");
                                goto done;
                        }
                }
        }
 
-       if (!leave(cli, cmdline_credentials, wks_creds)) {
+       if (!leave(cli, torture->lp_ctx, cmdline_credentials, wks_creds)) {
                d_printf("leave failed\n");
                goto done;
        }
@@ -1219,7 +1236,7 @@ bool torture_netlogon_samba3(struct torture_context *torture)
  * credentials
  */
 
-static bool test_join3(TALLOC_CTX *mem_ctx,
+static bool test_join3(struct torture_context *tctx,
                       bool use_level25,
                       struct cli_credentials *smb_creds,
                       struct cli_credentials *samr_creds,
@@ -1229,10 +1246,16 @@ static bool test_join3(TALLOC_CTX *mem_ctx,
        bool ret = false;
        struct smbcli_state *cli;
        struct cli_credentials *wks_creds;
+       struct smbcli_options options;
 
-       status = smbcli_full_connection(mem_ctx, &cli,
-                                       lp_parm_string(global_loadparm, NULL, "torture", "host"),
-                                       "IPC$", NULL, smb_creds, NULL);
+       lp_smbcli_options(tctx->lp_ctx, &options);
+
+       status = smbcli_full_connection(tctx, &cli,
+                                       torture_setting_string(tctx, "host", NULL),
+                                       lp_smb_ports(tctx->lp_ctx),
+                                       "IPC$", NULL, smb_creds, 
+                                       lp_resolve_context(tctx->lp_ctx),
+                                       NULL, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
@@ -1245,7 +1268,7 @@ static bool test_join3(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       cli_credentials_set_conf(wks_creds, global_loadparm);
+       cli_credentials_set_conf(wks_creds, tctx->lp_ctx);
        cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
        cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
        cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
@@ -1253,7 +1276,7 @@ static bool test_join3(TALLOC_CTX *mem_ctx,
                                     generate_random_str(wks_creds, 8),
                                     CRED_SPECIFIED);
 
-       if (!join3(cli, use_level25, samr_creds, wks_creds)) {
+       if (!join3(cli, tctx->lp_ctx, use_level25, samr_creds, wks_creds)) {
                d_printf("join failed\n");
                goto done;
        }
@@ -1262,12 +1285,12 @@ static bool test_join3(TALLOC_CTX *mem_ctx,
                cmdline_credentials, cli_credentials_get_domain(wks_creds),
                CRED_SPECIFIED);
 
-       if (!auth2(cli, wks_creds)) {
+       if (!auth2(cli, tctx->lp_ctx, wks_creds)) {
                d_printf("auth2 failed\n");
                goto done;
        }
 
-       if (!leave(cli, samr_creds, wks_creds)) {
+       if (!leave(cli, tctx->lp_ctx, samr_creds, wks_creds)) {
                d_printf("leave failed\n");
                goto done;
        }
@@ -1287,21 +1310,13 @@ static bool test_join3(TALLOC_CTX *mem_ctx,
 
 bool torture_samba3_sessionkey(struct torture_context *torture)
 {
-       TALLOC_CTX *mem_ctx;
        bool ret = false;
        struct cli_credentials *anon_creds;
        const char *wks_name;
 
        wks_name = torture_setting_string(torture, "wksname", get_myname());
 
-       mem_ctx = talloc_init("torture_samba3_sessionkey");
-
-       if (mem_ctx == NULL) {
-               d_printf("talloc_init failed\n");
-               return false;
-       }
-
-       if (!(anon_creds = create_anon_creds(mem_ctx))) {
+       if (!(anon_creds = cli_credentials_init_anon(torture))) {
                d_printf("create_anon_creds failed\n");
                goto done;
        }
@@ -1313,27 +1328,27 @@ bool torture_samba3_sessionkey(struct torture_context *torture)
                /* Samba3 in the build farm right now does this happily. Need
                 * to fix :-) */
 
-               if (test_join3(mem_ctx, false, anon_creds, NULL, wks_name)) {
+               if (test_join3(torture, false, anon_creds, NULL, wks_name)) {
                        d_printf("join using anonymous bind on an anonymous smb "
                                 "connection succeeded -- HUH??\n");
                        ret = false;
                }
        }
 
-       if (!test_join3(mem_ctx, false, anon_creds, cmdline_credentials,
+       if (!test_join3(torture, false, anon_creds, cmdline_credentials,
                        wks_name)) {
                d_printf("join using ntlmssp bind on an anonymous smb "
                         "connection failed\n");
                ret = false;
        }
 
-       if (!test_join3(mem_ctx, false, cmdline_credentials, NULL, wks_name)) {
+       if (!test_join3(torture, false, cmdline_credentials, NULL, wks_name)) {
                d_printf("join using anonymous bind on an authenticated smb "
                         "connection failed\n");
                ret = false;
        }
 
-       if (!test_join3(mem_ctx, false, cmdline_credentials,
+       if (!test_join3(torture, false, cmdline_credentials,
                        cmdline_credentials,
                        wks_name)) {
                d_printf("join using ntlmssp bind on an authenticated smb "
@@ -1345,14 +1360,14 @@ bool torture_samba3_sessionkey(struct torture_context *torture)
         * The following two are tests for setuserinfolevel 25
         */
 
-       if (!test_join3(mem_ctx, true, anon_creds, cmdline_credentials,
+       if (!test_join3(torture, true, anon_creds, cmdline_credentials,
                        wks_name)) {
                d_printf("join using ntlmssp bind on an anonymous smb "
                         "connection failed\n");
                ret = false;
        }
 
-       if (!test_join3(mem_ctx, true, cmdline_credentials, NULL, wks_name)) {
+       if (!test_join3(torture, true, cmdline_credentials, NULL, wks_name)) {
                d_printf("join using anonymous bind on an authenticated smb "
                         "connection failed\n");
                ret = false;
@@ -1368,6 +1383,7 @@ bool torture_samba3_sessionkey(struct torture_context *torture)
  */
 
 static NTSTATUS pipe_bind_smb(TALLOC_CTX *mem_ctx,
+                             struct loadparm_context *lp_ctx,
                              struct smbcli_tree *tree,
                              const char *pipe_name,
                              const struct ndr_interface_table *iface,
@@ -1377,7 +1393,8 @@ static NTSTATUS pipe_bind_smb(TALLOC_CTX *mem_ctx,
        NTSTATUS status;
 
        if (!(result = dcerpc_pipe_init(
-                     mem_ctx, tree->session->transport->socket->event.ctx))) {
+                     mem_ctx, tree->session->transport->socket->event.ctx, 
+                     lp_iconv_convenience(lp_ctx)))) {
                return NT_STATUS_NO_MEMORY;
        }
 
@@ -1493,7 +1510,9 @@ static struct dom_sid *name2sid(TALLOC_CTX *mem_ctx,
  * Find out the user SID on this connection
  */
 
-static struct dom_sid *whoami(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree)
+static struct dom_sid *whoami(TALLOC_CTX *mem_ctx, 
+                             struct loadparm_context *lp_ctx, 
+                             struct smbcli_tree *tree)
 {
        struct dcerpc_pipe *lsa;
        struct lsa_GetUserName r;
@@ -1501,7 +1520,7 @@ static struct dom_sid *whoami(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree)
        struct lsa_StringPointer authority_name_p;
        struct dom_sid *result;
 
-       status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\lsarpc",
+       status = pipe_bind_smb(mem_ctx, lp_ctx, tree, "\\pipe\\lsarpc",
                               &ndr_table_lsarpc, &lsa);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) Could not bind to LSA: %s\n",
@@ -1596,14 +1615,20 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
        struct cli_credentials *anon_creds;
        struct cli_credentials *user_creds;
        char *domain_name;
+       struct smbcli_options options;
 
        if (!(mem_ctx = talloc_new(torture))) {
                return false;
        }
 
+       lp_smbcli_options(torture->lp_ctx, &options);
+
        status = smbcli_full_connection(
                mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
-               "IPC$", NULL, cmdline_credentials, NULL);
+               lp_smb_ports(torture->lp_ctx),
+               "IPC$", NULL, cmdline_credentials, 
+               lp_resolve_context(torture->lp_ctx),
+               NULL, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) smbcli_full_connection failed: %s\n",
                         __location__, nt_errstr(status));
@@ -1611,7 +1636,7 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
                goto done;
        }
 
-       if (!(user_sid = whoami(mem_ctx, cli->tree))) {
+       if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
                d_printf("(%s) whoami on auth'ed connection failed\n",
                         __location__);
                ret = false;
@@ -1619,7 +1644,7 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
 
        talloc_free(cli);
 
-       if (!(anon_creds = create_anon_creds(mem_ctx))) {
+       if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
                d_printf("(%s) create_anon_creds failed\n", __location__);
                ret = false;
                goto done;
@@ -1627,7 +1652,10 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
 
        status = smbcli_full_connection(
                mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
-               "IPC$", NULL, anon_creds, NULL);
+               lp_smb_ports(torture->lp_ctx),
+               "IPC$", NULL, anon_creds, 
+               lp_resolve_context(torture->lp_ctx),
+               NULL, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) anon smbcli_full_connection failed: %s\n",
                         __location__, nt_errstr(status));
@@ -1635,7 +1663,7 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
                goto done;
        }
 
-       if (!(user_sid = whoami(mem_ctx, cli->tree))) {
+       if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
                d_printf("(%s) whoami on anon connection failed\n",
                         __location__);
                ret = false;
@@ -1663,7 +1691,7 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
                                     generate_random_str(user_creds, 8),
                                     CRED_SPECIFIED);
 
-       if (!create_user(mem_ctx, cli, cmdline_credentials,
+       if (!create_user(mem_ctx, cli, torture->lp_ctx, cmdline_credentials,
                         cli_credentials_get_username(user_creds),
                         cli_credentials_get_password(user_creds),
                         &domain_name, &created_sid)) {
@@ -1709,7 +1737,7 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
                        goto done;
                }
 
-               if (!(user_sid = whoami(mem_ctx, tree))) {
+               if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, tree))) {
                        d_printf("(%s) whoami on user connection failed\n",
                                 __location__);
                        ret = false;
@@ -1728,7 +1756,8 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
        }
 
  delete:
-       if (!delete_user(cli, cmdline_credentials,
+       if (!delete_user(cli, torture->lp_ctx, 
+                        cmdline_credentials,
                         cli_credentials_get_username(user_creds))) {
                d_printf("(%s) delete_user failed\n", __location__);
                ret = false;
@@ -1840,14 +1869,14 @@ bool torture_samba3_rpc_srvsvc(struct torture_context *torture)
        }
 
        if (!(torture_open_connection_share(
-                     mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
+                     mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
                      "IPC$", NULL))) {
                talloc_free(mem_ctx);
                return false;
        }
 
-       status = pipe_bind_smb(mem_ctx, cli->tree, "\\pipe\\srvsvc",
-                              &ndr_table_srvsvc, &p);
+       status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, 
+                              "\\pipe\\srvsvc", &ndr_table_srvsvc, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) could not bind to srvsvc pipe: %s\n",
                         __location__, nt_errstr(status));
@@ -1902,14 +1931,15 @@ bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
 
        if (!(torture_open_connection_share(
                      mem_ctx, &cli,
-                     torture_setting_string(torture, "host", NULL),
+                     torture, torture_setting_string(torture, "host", NULL),
                      "IPC$", NULL))) {
                d_printf("IPC$ connection failed\n");
                goto done;
        }
 
        if (!(net_pipe = dcerpc_pipe_init(
-                     mem_ctx, cli->transport->socket->event.ctx))) {
+                     mem_ctx, cli->transport->socket->event.ctx,
+                     lp_iconv_convenience(torture->lp_ctx)))) {
                d_printf("dcerpc_pipe_init failed\n");
                goto done;
        }
@@ -1982,6 +2012,7 @@ bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
 }
 
 static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
+                                               struct loadparm_context *lp_ctx,
                                                struct smbcli_session *sess,
                                                const char *sharename)
 {
@@ -2003,7 +2034,7 @@ static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
                return NULL;
        }
 
-       status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\srvsvc",
+       status = pipe_bind_smb(mem_ctx, lp_ctx, tree, "\\pipe\\srvsvc",
                               &ndr_table_srvsvc, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) could not bind to srvsvc pipe: %s\n",
@@ -2035,6 +2066,7 @@ static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
 }
 
 static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
+                            struct loadparm_context *lp_ctx,
                             struct smbcli_session *sess,
                             const char *sharename,
                             struct security_descriptor *sd)
@@ -2058,7 +2090,7 @@ static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
                return NT_STATUS_UNSUCCESSFUL;
        }
 
-       status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\srvsvc",
+       status = pipe_bind_smb(mem_ctx, lp_ctx, tree, "\\pipe\\srvsvc",
                               &ndr_table_srvsvc, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) could not bind to srvsvc pipe: %s\n",
@@ -2090,6 +2122,7 @@ static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
 }
 
 bool try_tcon(TALLOC_CTX *mem_ctx,
+             struct loadparm_context *lp_ctx,
              struct security_descriptor *orig_sd,
              struct smbcli_session *session,
              const char *sharename, const struct dom_sid *user_sid,
@@ -2137,7 +2170,7 @@ bool try_tcon(TALLOC_CTX *mem_ctx,
                 return false;
         }
 
-       status = set_sharesec(mem_ctx, session, sharename, sd);
+       status = set_sharesec(mem_ctx, lp_ctx, session, sharename, sd);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("custom set_sharesec failed: %s\n",
                         nt_errstr(status));
@@ -2168,7 +2201,7 @@ bool try_tcon(TALLOC_CTX *mem_ctx,
  done:
        smbcli_rmdir(rmdir_tree, "sharesec_testdir");
 
-       status = set_sharesec(mem_ctx, session, sharename, orig_sd);
+       status = set_sharesec(mem_ctx, lp_ctx, session, sharename, orig_sd);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("custom set_sharesec failed: %s\n",
                         nt_errstr(status));
@@ -2193,32 +2226,32 @@ bool torture_samba3_rpc_sharesec(struct torture_context *torture)
        }
 
        if (!(torture_open_connection_share(
-                     mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
+                     mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
                      "IPC$", NULL))) {
                d_printf("IPC$ connection failed\n");
                talloc_free(mem_ctx);
                return false;
        }
 
-       if (!(user_sid = whoami(mem_ctx, cli->tree))) {
+       if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
                d_printf("whoami failed\n");
                talloc_free(mem_ctx);
                return false;
        }
 
-       sd = get_sharesec(mem_ctx, cli->session, torture_setting_string(torture,
-                                                               "share", NULL));
+       sd = get_sharesec(mem_ctx, torture->lp_ctx, cli->session, 
+                         torture_setting_string(torture, "share", NULL));
 
-       ret &= try_tcon(mem_ctx, sd, cli->session,
+       ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
                        torture_setting_string(torture, "share", NULL),
                        user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK);
 
-       ret &= try_tcon(mem_ctx, sd, cli->session,
+       ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
                        torture_setting_string(torture, "share", NULL),
                        user_sid, SEC_FILE_READ_DATA, NT_STATUS_OK,
                        NT_STATUS_MEDIA_WRITE_PROTECTED);
 
-       ret &= try_tcon(mem_ctx, sd, cli->session,
+       ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
                        torture_setting_string(torture, "share", NULL),
                        user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK);
 
@@ -2241,14 +2274,14 @@ bool torture_samba3_rpc_lsa(struct torture_context *torture)
        }
 
        if (!(torture_open_connection_share(
-                     mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
+                     mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
                      "IPC$", NULL))) {
                d_printf("IPC$ connection failed\n");
                talloc_free(mem_ctx);
                return false;
        }
 
-       status = pipe_bind_smb(mem_ctx, cli->tree, "\\lsarpc",
+       status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\lsarpc",
                               &ndr_table_lsarpc, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
@@ -2305,6 +2338,7 @@ bool torture_samba3_rpc_lsa(struct torture_context *torture)
 }
 
 static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
+                              struct smb_iconv_convenience *iconv_convenience,
                               char **name)
 {
        struct rap_WserverGetInfo r;
@@ -2314,7 +2348,7 @@ static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
        r.in.level = 0;
        r.in.bufsize = 0xffff;
 
-       status = smbcli_rap_netservergetinfo(tree, mem_ctx, &r);
+       status = smbcli_rap_netservergetinfo(tree, iconv_convenience, mem_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -2322,7 +2356,8 @@ static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
        memcpy(servername, r.out.info.info0.name, 16);
        servername[16] = '\0';
 
-       if (pull_ascii_talloc(mem_ctx, name, servername) < 0) {
+       if (pull_ascii_talloc(mem_ctx, iconv_convenience, 
+                             name, servername) < 0) {
                return NT_STATUS_NO_MEMORY;
        }
 
@@ -2330,7 +2365,8 @@ static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
 }
 
 
-static NTSTATUS find_printers(TALLOC_CTX *ctx, struct smbcli_tree *tree,
+static NTSTATUS find_printers(TALLOC_CTX *ctx, struct loadparm_context *lp_ctx,
+                             struct smbcli_tree *tree,
                              const char ***printers, int *num_printers)
 {
        TALLOC_CTX *mem_ctx;
@@ -2346,7 +2382,8 @@ static NTSTATUS find_printers(TALLOC_CTX *ctx, struct smbcli_tree *tree,
                return NT_STATUS_NO_MEMORY;
        }
 
-       status = pipe_bind_smb(mem_ctx, tree, "\\srvsvc", &ndr_table_srvsvc,
+       status = pipe_bind_smb(mem_ctx, lp_ctx, 
+                              tree, "\\srvsvc", &ndr_table_srvsvc,
                               &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("could not bind to srvsvc pipe\n");
@@ -2519,14 +2556,14 @@ bool torture_samba3_rpc_spoolss(struct torture_context *torture)
        }
 
        if (!(torture_open_connection_share(
-                     mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
+                     mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
                      "IPC$", NULL))) {
                d_printf("IPC$ connection failed\n");
                talloc_free(mem_ctx);
                return false;
        }
 
-       status = get_servername(mem_ctx, cli->tree, &servername);
+       status = get_servername(mem_ctx, cli->tree, lp_iconv_convenience(torture->lp_ctx), &servername);
        if (!NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, "(%s) get_servername returned %s\n",
                          __location__, nt_errstr(status));
@@ -2534,7 +2571,7 @@ bool torture_samba3_rpc_spoolss(struct torture_context *torture)
                return false;
        }
 
-       if (!NT_STATUS_IS_OK(find_printers(mem_ctx, cli->tree,
+       if (!NT_STATUS_IS_OK(find_printers(mem_ctx, torture->lp_ctx, cli->tree,
                                           &printers, &num_printers))) {
                talloc_free(mem_ctx);
                return false;
@@ -2546,7 +2583,7 @@ bool torture_samba3_rpc_spoolss(struct torture_context *torture)
                return true;
        }
 
-       status = pipe_bind_smb(mem_ctx, cli->tree, "\\spoolss",
+       status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\spoolss",
                               &ndr_table_spoolss, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
@@ -2705,14 +2742,14 @@ bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
        }
 
        if (!(torture_open_connection_share(
-                     mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
+                     mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
                      "IPC$", NULL))) {
                d_printf("IPC$ connection failed\n");
                talloc_free(mem_ctx);
                return false;
        }
 
-       status = get_servername(mem_ctx, cli->tree, &servername);
+       status = get_servername(mem_ctx, cli->tree, lp_iconv_convenience(torture->lp_ctx), &servername);
        if (!NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, "(%s) get_servername returned %s\n",
                          __location__, nt_errstr(status));
@@ -2720,7 +2757,7 @@ bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
                return false;
        }
 
-       status = pipe_bind_smb(mem_ctx, cli->tree, "\\wkssvc",
+       status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\wkssvc",
                               &ndr_table_wkssvc, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
@@ -2969,6 +3006,7 @@ bool torture_samba3_rpc_winreg(struct torture_context *torture)
 }
 
 static NTSTATUS get_shareinfo(TALLOC_CTX *mem_ctx,
+                             struct loadparm_context *lp_ctx,
                              struct smbcli_state *cli,
                              const char *share,
                              struct srvsvc_NetShareInfo502 **info)
@@ -2979,7 +3017,8 @@ static NTSTATUS get_shareinfo(TALLOC_CTX *mem_ctx,
        NTSTATUS status;
 
        if (!(p = dcerpc_pipe_init(cli,
-                                  cli->transport->socket->event.ctx))) {
+                                  cli->transport->socket->event.ctx,
+                                  lp_iconv_convenience(lp_ctx)))) {
                status = NT_STATUS_NO_MEMORY;
                goto fail;
        }
@@ -3029,6 +3068,7 @@ static NTSTATUS get_shareinfo(TALLOC_CTX *mem_ctx,
 
 static NTSTATUS get_hklm_handle(TALLOC_CTX *mem_ctx,
                                struct smbcli_state *cli,
+                               struct smb_iconv_convenience *iconv_convenience,
                                struct dcerpc_pipe **pipe_p,
                                struct policy_handle **handle)
 {
@@ -3045,7 +3085,8 @@ static NTSTATUS get_hklm_handle(TALLOC_CTX *mem_ctx,
        }
 
        if (!(p = dcerpc_pipe_init(result,
-                                  cli->transport->socket->event.ctx))) {
+                                  cli->transport->socket->event.ctx,
+                                  iconv_convenience))) {
                status = NT_STATUS_NO_MEMORY;
                goto fail;
        }
@@ -3090,6 +3131,7 @@ static NTSTATUS get_hklm_handle(TALLOC_CTX *mem_ctx,
 }
 
 static NTSTATUS torture_samba3_createshare(struct smbcli_state *cli,
+                                          struct smb_iconv_convenience *iconv_convenience,
                                           const char *sharename)
 {
        struct dcerpc_pipe *p;
@@ -3104,7 +3146,7 @@ static NTSTATUS torture_samba3_createshare(struct smbcli_state *cli,
        mem_ctx = talloc_new(cli);
        NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
 
-       status = get_hklm_handle(mem_ctx, cli, &p, &hklm);
+       status = get_hklm_handle(mem_ctx, cli, iconv_convenience, &p, &hklm);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
                goto fail;
@@ -3148,7 +3190,8 @@ static NTSTATUS torture_samba3_createshare(struct smbcli_state *cli,
        return status;
 }
 
-static NTSTATUS torture_samba3_deleteshare(struct smbcli_state *cli,
+static NTSTATUS torture_samba3_deleteshare(struct torture_context *torture,
+                                          struct smbcli_state *cli,
                                           const char *sharename)
 {
        struct dcerpc_pipe *p;
@@ -3160,7 +3203,8 @@ static NTSTATUS torture_samba3_deleteshare(struct smbcli_state *cli,
        mem_ctx = talloc_new(cli);
        NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
 
-       status = get_hklm_handle(cli, cli, &p, &hklm);
+       status = get_hklm_handle(cli, cli, lp_iconv_convenience(torture->lp_ctx),
+                                &p, &hklm);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
                goto fail;
@@ -3187,6 +3231,7 @@ static NTSTATUS torture_samba3_deleteshare(struct smbcli_state *cli,
 }
 
 static NTSTATUS torture_samba3_setconfig(struct smbcli_state *cli,
+                                        struct loadparm_context *lp_ctx,
                                         const char *sharename,
                                         const char *parameter,
                                         const char *value)
@@ -3199,7 +3244,7 @@ static NTSTATUS torture_samba3_setconfig(struct smbcli_state *cli,
        DATA_BLOB val;
        NTSTATUS status;
 
-       status = get_hklm_handle(cli, cli, &p, &hklm);
+       status = get_hklm_handle(cli, cli, lp_iconv_convenience(lp_ctx), &p, &hklm);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
                return status;;
@@ -3255,25 +3300,25 @@ bool torture_samba3_regconfig(struct torture_context *torture)
        bool ret = false;
        const char *comment = "Dummer Kommentar";
 
-       if (!(torture_open_connection(&cli, 0))) {
+       if (!(torture_open_connection(&cli, torture, 0))) {
                return false;
        }
 
-       status = torture_samba3_createshare(cli, "blubber");
+       status = torture_samba3_createshare(cli, lp_iconv_convenience(torture->lp_ctx), "blubber");
        if (!NT_STATUS_IS_OK(status)) {
                torture_warning(torture, "torture_samba3_createshare failed: "
                                "%s\n", nt_errstr(status));
                goto done;
        }
 
-       status = torture_samba3_setconfig(cli, "blubber", "comment", comment);
+       status = torture_samba3_setconfig(cli, torture->lp_ctx, "blubber", "comment", comment);
        if (!NT_STATUS_IS_OK(status)) {
                torture_warning(torture, "torture_samba3_setconfig failed: "
                                "%s\n", nt_errstr(status));
                goto done;
        }
 
-       status = get_shareinfo(torture, cli, "blubber", &i);
+       status = get_shareinfo(torture, torture->lp_ctx, cli, "blubber", &i);
        if (!NT_STATUS_IS_OK(status)) {
                torture_warning(torture, "get_shareinfo failed: "
                                "%s\n", nt_errstr(status));
@@ -3286,7 +3331,7 @@ bool torture_samba3_regconfig(struct torture_context *torture)
                goto done;
        }
 
-       status = torture_samba3_deleteshare(cli, "blubber");
+       status = torture_samba3_deleteshare(torture, cli, "blubber");
        if (!NT_STATUS_IS_OK(status)) {
                torture_warning(torture, "torture_samba3_deleteshare failed: "
                                "%s\n", nt_errstr(status));