s4: fix various warnings (not "const" related ones)
[sfrench/samba-autobuild/.git] / source4 / torture / rpc / samba3rpc.c
index a63772e96410ac47b388a32e74ccbcf29a5dcf6d..4a529d38f628f5ec7048e75d77665d5a7ae719ff 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "includes.h"
 #include "libcli/raw/libcliraw.h"
+#include "libcli/raw/raw_proto.h"
 #include "libcli/rap/rap.h"
 #include "torture/torture.h"
 #include "torture/util.h"
 #include "libcli/composite/composite.h"
 #include "libcli/smb_composite/smb_composite.h"
 #include "libcli/auth/libcli_auth.h"
-#include "lib/crypto/crypto.h"
-#include "libcli/security/proto.h"
+#include "../lib/crypto/crypto.h"
+#include "auth/ntlmssp/ntlmssp.h"
+#include "libcli/security/security.h"
 #include "param/param.h"
 #include "lib/registry/registry.h"
+#include "libcli/resolve/resolve.h"
 
 /*
  * This tests a RPC call using an invalid vuid
@@ -70,6 +73,8 @@ 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;
+       struct smbcli_session_options session_options;
 
        mem_ctx = talloc_init("torture_bind_authcontext");
 
@@ -78,18 +83,27 @@ bool torture_bind_authcontext(struct torture_context *torture)
                return false;
        }
 
+       lp_smbcli_options(torture->lp_ctx, &options);
+       lp_smbcli_session_options(torture->lp_ctx, &session_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);
+                                       "IPC$", NULL, 
+                                       lp_socket_options(torture->lp_ctx),
+                                       cmdline_credentials,
+                                       lp_resolve_context(torture->lp_ctx),
+                                       torture->ev, &options, &session_options,
+                                       lp_iconv_convenience(torture->lp_ctx),
+                                       lp_gensec_settings(torture, torture->lp_ctx));
        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;
@@ -134,7 +148,7 @@ bool torture_bind_authcontext(struct torture_context *torture)
                goto done;
        }
 
-       session2 = smbcli_session_init(cli->transport, mem_ctx, false);
+       session2 = smbcli_session_init(cli->transport, mem_ctx, false, session_options);
        if (session2 == NULL) {
                d_printf("smbcli_session_init failed\n");
                goto done;
@@ -149,6 +163,7 @@ bool torture_bind_authcontext(struct torture_context *torture)
        setup.in.capabilities = cli->transport->negotiate.capabilities;
        setup.in.workgroup = "";
        setup.in.credentials = anon_creds;
+       setup.in.gensec_settings = lp_gensec_settings(torture, torture->lp_ctx);
 
        status = smb_composite_sesssetup(session2, &setup);
        if (!NT_STATUS_IS_OK(status)) {
@@ -197,6 +212,7 @@ static bool bindtest(struct smbcli_state *cli,
        struct lsa_ObjectAttribute objectattr;
        struct lsa_OpenPolicy2 openpolicy;
        struct lsa_QueryInfoPolicy query;
+       union lsa_PolicyInformation *info = NULL;
        struct policy_handle handle;
        struct lsa_Close close_handle;
 
@@ -206,7 +222,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;
@@ -220,7 +237,7 @@ static bool bindtest(struct smbcli_state *cli,
        }
 
        status = dcerpc_bind_auth(lsa_pipe, &ndr_table_lsarpc,
-                                 credentials, lp_ctx, auth_type, auth_level,
+                                 credentials, lp_gensec_settings(lp_ctx, lp_ctx), auth_type, auth_level,
                                  NULL);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("dcerpc_bind_auth failed: %s\n", nt_errstr(status));
@@ -244,6 +261,7 @@ static bool bindtest(struct smbcli_state *cli,
 
        query.in.handle = &handle;
        query.in.level = LSA_POLICY_INFO_DOMAIN;
+       query.out.info = &info;
 
        status = dcerpc_lsa_QueryInfoPolicy(lsa_pipe, mem_ctx, &query);
        if (!NT_STATUS_IS_OK(status)) {
@@ -278,6 +296,8 @@ bool torture_bind_samba3(struct torture_context *torture)
        NTSTATUS status;
        bool ret = false;
        struct smbcli_state *cli;
+       struct smbcli_options options;
+       struct smbcli_session_options session_options;
 
        mem_ctx = talloc_init("torture_bind_authcontext");
 
@@ -286,11 +306,19 @@ bool torture_bind_samba3(struct torture_context *torture)
                return false;
        }
 
+       lp_smbcli_options(torture->lp_ctx, &options);
+       lp_smbcli_session_options(torture->lp_ctx, &session_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);
+                                       "IPC$", NULL, 
+                                       lp_socket_options(torture->lp_ctx),
+                                       cmdline_credentials,
+                                       lp_resolve_context(torture->lp_ctx),
+                                       torture->ev, &options, &session_options,
+                                       lp_iconv_convenience(torture->lp_ctx),
+                                       lp_gensec_settings(torture, torture->lp_ctx));
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
@@ -327,7 +355,7 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
                               char **domain,
                               struct dcerpc_pipe **result_pipe,
                               struct policy_handle **result_handle,
-                              struct dom_sid **sid)
+                              struct dom_sid **sid_p)
 {
        struct dcerpc_pipe *samr_pipe;
        NTSTATUS status;
@@ -337,7 +365,10 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
        struct samr_Connect2 conn;
        struct samr_EnumDomains enumdom;
        uint32_t resume_handle = 0;
+       uint32_t num_entries = 0;
+       struct samr_SamArray *sam = NULL;
        struct samr_LookupDomain l;
+       struct dom_sid2 *sid = NULL;
        int dom_idx;
        struct lsa_String domain_name;
        struct lsa_String user_name;
@@ -346,7 +377,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;
@@ -362,7 +394,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, lp_ctx, auth_type, auth_level,
+                                         admin_creds, lp_gensec_settings(lp_ctx, lp_ctx), auth_type, auth_level,
                                          NULL);
                if (!NT_STATUS_IS_OK(status)) {
                        d_printf("dcerpc_bind_auth failed: %s\n",
@@ -394,6 +426,8 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
        enumdom.in.resume_handle = &resume_handle;
        enumdom.in.buf_size = (uint32_t)-1;
        enumdom.out.resume_handle = &resume_handle;
+       enumdom.out.num_entries = &num_entries;
+       enumdom.out.sam = &sam;
 
        status = dcerpc_samr_EnumDomains(samr_pipe, mem_ctx, &enumdom);
        if (!NT_STATUS_IS_OK(status)) {
@@ -401,20 +435,21 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
                goto fail;
        }
 
-       if (enumdom.out.num_entries != 2) {
+       if (*enumdom.out.num_entries != 2) {
                d_printf("samr_EnumDomains returned %d entries, expected 2\n",
-                        enumdom.out.num_entries);
+                        *enumdom.out.num_entries);
                status = NT_STATUS_UNSUCCESSFUL;
                goto fail;
        }
 
-       dom_idx = strequal(enumdom.out.sam->entries[0].name.string,
+       dom_idx = strequal(sam->entries[0].name.string,
                           "builtin") ? 1:0;
 
        l.in.connect_handle = &conn_handle;
-       domain_name.string = enumdom.out.sam->entries[0].name.string;
+       domain_name.string = sam->entries[dom_idx].name.string;
        *domain = talloc_strdup(mem_ctx, domain_name.string);
        l.in.domain_name = &domain_name;
+       l.out.sid = &sid;
 
        status = dcerpc_samr_LookupDomain(samr_pipe, mem_ctx, &l);
        if (!NT_STATUS_IS_OK(status)) {
@@ -424,7 +459,7 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
 
        o.in.connect_handle = &conn_handle;
        o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
-       o.in.sid = l.out.sid;
+       o.in.sid = *l.out.sid;
        o.out.domain_handle = &domain_handle;
 
        status = dcerpc_samr_OpenDomain(samr_pipe, mem_ctx, &o);
@@ -448,10 +483,13 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
        if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
                struct samr_LookupNames ln;
                struct samr_OpenUser ou;
+               struct samr_Ids rids, types;
 
                ln.in.domain_handle = &domain_handle;
                ln.in.num_names = 1;
                ln.in.names = &user_name;
+               ln.out.rids = &rids;
+               ln.out.types = &types;
 
                status = dcerpc_samr_LookupNames(samr_pipe, mem_ctx, &ln);
                if (!NT_STATUS_IS_OK(status)) {
@@ -462,7 +500,7 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
 
                ou.in.domain_handle = &domain_handle;
                ou.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
-               user_rid = ou.in.rid = ln.out.rids.ids[0];
+               user_rid = ou.in.rid = ln.out.rids->ids[0];
                ou.out.user_handle = user_handle;
 
                status = dcerpc_samr_OpenUser(samr_pipe, mem_ctx, &ou);
@@ -480,8 +518,8 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
 
        *result_pipe = samr_pipe;
        *result_handle = user_handle;
-       if (sid != NULL) {
-               *sid = dom_sid_add_rid(mem_ctx, l.out.sid, user_rid);
+       if (sid_p != NULL) {
+               *sid_p = dom_sid_add_rid(mem_ctx, *l.out.sid, user_rid);
        }
        return NT_STATUS_OK;
 
@@ -517,7 +555,7 @@ static bool create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
                                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;
        }
 
@@ -526,6 +564,7 @@ static bool create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
                struct samr_SetUserInfo sui;
                struct samr_QueryUserInfo qui;
                union samr_UserInfo u_info;
+               union samr_UserInfo *info;
                DATA_BLOB session_key;
 
 
@@ -541,8 +580,8 @@ static bool create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
                arcfour_crypt_blob(u_info.info23.password.data, 516,
                                   &session_key);
                u_info.info23.info.password_expired = 0;
-               u_info.info23.info.fields_present = SAMR_FIELD_PASSWORD | 
-                                                   SAMR_FIELD_PASSWORD2 |
+               u_info.info23.info.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
+                                                   SAMR_FIELD_LM_PASSWORD_PRESENT |
                                                    SAMR_FIELD_EXPIRED_FLAG;
                sui2.in.user_handle = wks_handle;
                sui2.in.info = &u_info;
@@ -568,6 +607,7 @@ static bool create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
 
                qui.in.user_handle = wks_handle;
                qui.in.level = 21;
+               qui.out.info = &info;
 
                status = dcerpc_samr_QueryUserInfo(samr_pipe, tmp_ctx, &qui);
                if (!NT_STATUS_IS_OK(status)) {
@@ -575,14 +615,14 @@ static bool create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
                        goto done;
                }
 
-               qui.out.info->info21.allow_password_change = 0;
-               qui.out.info->info21.force_password_change = 0;
-               qui.out.info->info21.account_name.string = NULL;
-               qui.out.info->info21.rid = 0;
-               qui.out.info->info21.acct_expiry = 0;
-               qui.out.info->info21.fields_present = 0x81827fa; /* copy usrmgr.exe */
+               info->info21.allow_password_change = 0;
+               info->info21.force_password_change = 0;
+               info->info21.account_name.string = NULL;
+               info->info21.rid = 0;
+               info->info21.acct_expiry = 0;
+               info->info21.fields_present = 0x81827fa; /* copy usrmgr.exe */
 
-               u_info.info21 = qui.out.info->info21;
+               u_info.info21 = info->info21;
                sui.in.user_handle = wks_handle;
                sui.in.info = &u_info;
                sui.in.level = 21;
@@ -670,6 +710,7 @@ static bool join3(struct smbcli_state *cli,
        struct dcerpc_pipe *samr_pipe;
        struct policy_handle *wks_handle;
        bool ret = false;
+       NTTIME last_password_change;
 
        if ((mem_ctx = talloc_init("join3")) == NULL) {
                d_printf("talloc_init failed\n");
@@ -689,6 +730,24 @@ static bool join3(struct smbcli_state *cli,
                goto done;
        }
 
+       {
+               struct samr_QueryUserInfo q;
+               union samr_UserInfo *info;
+
+               q.in.user_handle = wks_handle;
+               q.in.level = 21;
+               q.out.info = &info;
+
+               status = dcerpc_samr_QueryUserInfo(samr_pipe, mem_ctx, &q);
+               if (!NT_STATUS_IS_OK(status)) {
+                       d_printf("(%s) QueryUserInfo failed: %s\n",
+                                 __location__, nt_errstr(status));
+                       goto done;
+               }
+
+               last_password_change = info->info21.last_password_change;
+       }
+
        cli_credentials_set_domain(wks_creds, dom_name, CRED_SPECIFIED);
 
        if (use_level25) {
@@ -708,7 +767,11 @@ static bool join3(struct smbcli_state *cli,
                        cli_credentials_get_workstation(wks_creds));
                i21->acct_flags = ACB_WSTRUST;
                i21->fields_present = SAMR_FIELD_FULL_NAME |
-                       SAMR_FIELD_ACCT_FLAGS | SAMR_FIELD_PASSWORD;
+                       SAMR_FIELD_ACCT_FLAGS | SAMR_FIELD_NT_PASSWORD_PRESENT;
+               /* this would break the test result expectations
+               i21->fields_present |= SAMR_FIELD_EXPIRED_FLAG;
+               i21->password_expired = 1;
+               */
 
                encode_pw_buffer(u_info.info25.password.data,
                                 cli_credentials_get_password(wks_creds),
@@ -749,8 +812,8 @@ static bool join3(struct smbcli_state *cli,
                encode_pw_buffer(u_info.info24.password.data,
                                 cli_credentials_get_password(wks_creds),
                                 STR_UNICODE);
-               u_info.info24.pw_len =
-                       strlen_m(cli_credentials_get_password(wks_creds))*2;
+               /* just to make this test pass */
+               u_info.info24.password_expired = 1;
 
                status = dcerpc_fetch_session_key(samr_pipe, &session_key);
                if (!NT_STATUS_IS_OK(status)) {
@@ -782,6 +845,41 @@ static bool join3(struct smbcli_state *cli,
                }
        }
 
+       {
+               struct samr_QueryUserInfo q;
+               union samr_UserInfo *info;
+
+               q.in.user_handle = wks_handle;
+               q.in.level = 21;
+               q.out.info = &info;
+
+               status = dcerpc_samr_QueryUserInfo(samr_pipe, mem_ctx, &q);
+               if (!NT_STATUS_IS_OK(status)) {
+                       d_printf("(%s) QueryUserInfo failed: %s\n",
+                                 __location__, nt_errstr(status));
+                       goto done;
+               }
+
+               if (use_level25) {
+                       if (last_password_change
+                           == info->info21.last_password_change) {
+                               d_printf("(%s) last_password_change unchanged "
+                                        "during join, level25 must change "
+                                        "it\n", __location__);
+                               goto done;
+                       }
+               }
+               else {
+                       if (last_password_change
+                           != info->info21.last_password_change) {
+                               d_printf("(%s) last_password_change changed "
+                                        "during join, level24 doesn't "
+                                        "change it\n", __location__);
+                               goto done;
+                       }
+               }
+       }
+
        ret = true;
 
  done:
@@ -794,6 +892,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;
@@ -805,7 +904,7 @@ static bool auth2(struct smbcli_state *cli,
        struct netr_Credential netr_srv_creds;
        uint32_t negotiate_flags;
        struct netr_ServerAuthenticate2 a;
-       struct creds_CredentialState *creds_state;
+       struct netlogon_creds_CredentialState *creds_state;
        struct netr_Credential netr_cred;
        struct samr_Password mach_pw;
 
@@ -816,7 +915,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;
@@ -846,7 +946,7 @@ static bool auth2(struct smbcli_state *cli,
        generate_random_buffer(netr_cli_creds.data,
                               sizeof(netr_cli_creds.data));
        r.in.credentials = &netr_cli_creds;
-       r.out.credentials = &netr_srv_creds;
+       r.out.return_credentials = &netr_srv_creds;
 
        status = dcerpc_netr_ServerReqChallenge(net_pipe, mem_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
@@ -858,11 +958,6 @@ static bool auth2(struct smbcli_state *cli,
        negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
        E_md4hash(cli_credentials_get_password(wks_cred), mach_pw.hash);
 
-       creds_state = talloc(mem_ctx, struct creds_CredentialState);
-       creds_client_init(creds_state, r.in.credentials,
-                         r.out.credentials, &mach_pw,
-                         &netr_cred, negotiate_flags);
-
        a.in.server_name = talloc_asprintf(
                mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
        a.in.account_name = talloc_asprintf(
@@ -872,7 +967,14 @@ static bool auth2(struct smbcli_state *cli,
        a.in.negotiate_flags = &negotiate_flags;
        a.out.negotiate_flags = &negotiate_flags;
        a.in.credentials = &netr_cred;
-       a.out.credentials = &netr_cred;
+       a.out.return_credentials = &netr_cred;
+
+       creds_state = netlogon_creds_client_init(mem_ctx, 
+                                                a.in.account_name, 
+                                                a.in.computer_name,
+                                                r.in.credentials,
+                                                r.out.return_credentials, &mach_pw,
+                                                &netr_cred, negotiate_flags);
 
        status = dcerpc_netr_ServerAuthenticate2(net_pipe, mem_ctx, &a);
        if (!NT_STATUS_IS_OK(status)) {
@@ -881,7 +983,7 @@ static bool auth2(struct smbcli_state *cli,
                goto done;
        }
 
-       if (!creds_client_check(creds_state, a.out.credentials)) {
+       if (!netlogon_creds_client_check(creds_state, a.out.return_credentials)) {
                d_printf("creds_client_check failed\n");
                goto done;
        }
@@ -918,7 +1020,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;
@@ -938,7 +1041,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, lp_ctx, DCERPC_AUTH_TYPE_SCHANNEL,
+                                 wks_creds, lp_gensec_settings(lp_ctx, lp_ctx), DCERPC_AUTH_TYPE_SCHANNEL,
                                  DCERPC_AUTH_LEVEL_PRIVACY,
                                  NULL);
 #else
@@ -953,11 +1056,15 @@ static bool schan(struct smbcli_state *cli,
        for (i=2; i<4; i++) {
                int flags;
                DATA_BLOB chal, nt_resp, lm_resp, names_blob, session_key;
-               struct creds_CredentialState *creds_state;
+               struct netlogon_creds_CredentialState *creds_state;
                struct netr_Authenticator netr_auth, netr_auth2;
                struct netr_NetworkInfo ninfo;
                struct netr_PasswordInfo pinfo;
                struct netr_LogonSamLogon r;
+               union netr_LogonLevel logon;
+               union netr_Validation validation;
+               uint8_t authoritative;
+               struct netr_Authenticator return_authenticator;
 
                flags = CLI_CRED_LANMAN_AUTH | CLI_CRED_NTLM_AUTH |
                        CLI_CRED_NTLMv2_AUTH;
@@ -970,7 +1077,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, 
+                       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,
@@ -982,7 +1090,7 @@ static bool schan(struct smbcli_state *cli,
                }
 
                creds_state = cli_credentials_get_netlogon_creds(wks_creds);
-               creds_client_authenticator(creds_state, &netr_auth);
+               netlogon_creds_client_authenticator(creds_state, &netr_auth);
 
                ninfo.identity_info.account_name.string =
                        cli_credentials_get_username(user_creds);
@@ -999,6 +1107,8 @@ static bool schan(struct smbcli_state *cli,
                ninfo.lm.length = lm_resp.length;
                ninfo.lm.data = lm_resp.data;
 
+               logon.network = &ninfo;
+
                r.in.server_name = talloc_asprintf(
                        mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
                ZERO_STRUCT(netr_auth2);
@@ -1008,8 +1118,10 @@ static bool schan(struct smbcli_state *cli,
                r.in.return_authenticator = &netr_auth2;
                r.in.logon_level = 2;
                r.in.validation_level = i;
-               r.in.logon.network = &ninfo;
-               r.out.return_authenticator = NULL;
+               r.in.logon = &logon;
+               r.out.validation = &validation;
+               r.out.authoritative = &authoritative;
+               r.out.return_authenticator = &return_authenticator;
 
                status = dcerpc_netr_LogonSamLogon(net_pipe, mem_ctx, &r);
                if (!NT_STATUS_IS_OK(status)) {
@@ -1019,13 +1131,13 @@ static bool schan(struct smbcli_state *cli,
                }
 
                if ((r.out.return_authenticator == NULL) ||
-                   (!creds_client_check(creds_state,
+                   (!netlogon_creds_client_check(creds_state,
                                         &r.out.return_authenticator->cred))) {
                        d_printf("Credentials check failed!\n");
                        goto done;
                }
 
-               creds_client_authenticator(creds_state, &netr_auth);
+               netlogon_creds_client_authenticator(creds_state, &netr_auth);
 
                pinfo.identity_info = ninfo.identity_info;
                ZERO_STRUCT(pinfo.lmpassword.hash);
@@ -1037,9 +1149,11 @@ static bool schan(struct smbcli_state *cli,
                                   sizeof(pinfo.ntpassword.hash),
                                   &session_key);
 
+               logon.password = &pinfo;
+
                r.in.logon_level = 1;
-               r.in.logon.password = &pinfo;
-               r.out.return_authenticator = NULL;
+               r.in.logon = &logon;
+               r.out.return_authenticator = &return_authenticator;
 
                status = dcerpc_netr_LogonSamLogon(net_pipe, mem_ctx, &r);
                if (!NT_STATUS_IS_OK(status)) {
@@ -1049,7 +1163,7 @@ static bool schan(struct smbcli_state *cli,
                }
 
                if ((r.out.return_authenticator == NULL) ||
-                   (!creds_client_check(creds_state,
+                   (!netlogon_creds_client_check(creds_state,
                                         &r.out.return_authenticator->cred))) {
                        d_printf("Credentials check failed!\n");
                        goto done;
@@ -1059,7 +1173,9 @@ static bool schan(struct smbcli_state *cli,
        {
                struct netr_ServerPasswordSet s;
                char *password = generate_random_str(wks_creds, 8);
-               struct creds_CredentialState *creds_state;
+               struct netlogon_creds_CredentialState *creds_state;
+               struct netr_Authenticator credential, return_authenticator;
+               struct samr_Password new_password;
 
                s.in.server_name = talloc_asprintf(
                        mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
@@ -1067,11 +1183,15 @@ static bool schan(struct smbcli_state *cli,
                s.in.account_name = talloc_asprintf(
                        mem_ctx, "%s$", s.in.computer_name);
                s.in.secure_channel_type = SEC_CHAN_WKSTA;
-               E_md4hash(password, s.in.new_password.hash);
+               s.in.credential = &credential;
+               s.in.new_password = &new_password;
+               s.out.return_authenticator = &return_authenticator;
+
+               E_md4hash(password, new_password.hash);
 
                creds_state = cli_credentials_get_netlogon_creds(wks_creds);
-               creds_des_encrypt(creds_state, &s.in.new_password);
-               creds_client_authenticator(creds_state, &s.in.credential);
+               netlogon_creds_des_encrypt(creds_state, &new_password);
+               netlogon_creds_client_authenticator(creds_state, &credential);
 
                status = dcerpc_netr_ServerPasswordSet(net_pipe, mem_ctx, &s);
                if (!NT_STATUS_IS_OK(status)) {
@@ -1079,8 +1199,8 @@ static bool schan(struct smbcli_state *cli,
                        goto done;
                }
 
-               if (!creds_client_check(creds_state,
-                                       &s.out.return_authenticator.cred)) {
+               if (!netlogon_creds_client_check(creds_state,
+                                                &s.out.return_authenticator->cred)) {
                        printf("Credential chaining failed\n");
                }
 
@@ -1126,10 +1246,12 @@ bool torture_netlogon_samba3(struct torture_context *torture)
        struct cli_credentials *wks_creds;
        const char *wks_name;
        int i;
+       struct smbcli_options options;
+       struct smbcli_session_options session_options;
 
        wks_name = torture_setting_string(torture, "wksname", NULL);
        if (wks_name == NULL) {
-               wks_name = get_myname();
+               wks_name = get_myname(torture);
        }
 
        mem_ctx = talloc_init("torture_netlogon_samba3");
@@ -1144,10 +1266,19 @@ bool torture_netlogon_samba3(struct torture_context *torture)
                goto done;
        }
 
+       lp_smbcli_options(torture->lp_ctx, &options);
+       lp_smbcli_session_options(torture->lp_ctx, &session_options);
+
        status = smbcli_full_connection(mem_ctx, &cli,
                                        torture_setting_string(torture, "host", NULL),
                                        lp_smb_ports(torture->lp_ctx),
-                                       "IPC$", NULL, anon_creds, NULL);
+                                       "IPC$", NULL, 
+                                       lp_socket_options(torture->lp_ctx),
+                                       anon_creds, 
+                                       lp_resolve_context(torture->lp_ctx),
+                                       torture->ev, &options, &session_options,
+                                       lp_iconv_convenience(torture->lp_ctx),
+                                       lp_gensec_settings(torture, torture->lp_ctx));
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
@@ -1185,7 +1316,7 @@ 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;
                }
@@ -1225,11 +1356,20 @@ static bool test_join3(struct torture_context *tctx,
        bool ret = false;
        struct smbcli_state *cli;
        struct cli_credentials *wks_creds;
+       struct smbcli_options options;
+       struct smbcli_session_options session_options;
+
+       lp_smbcli_options(tctx->lp_ctx, &options);
+       lp_smbcli_session_options(tctx->lp_ctx, &session_options);
 
        status = smbcli_full_connection(tctx, &cli,
                                        torture_setting_string(tctx, "host", NULL),
                                        lp_smb_ports(tctx->lp_ctx),
-                                       "IPC$", NULL, smb_creds, NULL);
+                                       "IPC$", NULL, lp_socket_options(tctx->lp_ctx),
+                                       smb_creds, lp_resolve_context(tctx->lp_ctx),
+                                       tctx->ev, &options, &session_options,
+                                       lp_iconv_convenience(tctx->lp_ctx),
+                                       lp_gensec_settings(tctx, tctx->lp_ctx));
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
@@ -1259,7 +1399,7 @@ static bool test_join3(struct torture_context *tctx,
                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;
        }
@@ -1288,13 +1428,15 @@ bool torture_samba3_sessionkey(struct torture_context *torture)
        struct cli_credentials *anon_creds;
        const char *wks_name;
 
-       wks_name = torture_setting_string(torture, "wksname", get_myname());
+       wks_name = torture_setting_string(torture, "wksname", get_myname(torture));
 
        if (!(anon_creds = cli_credentials_init_anon(torture))) {
                d_printf("create_anon_creds failed\n");
                goto done;
        }
 
+       cli_credentials_set_workstation(anon_creds, wks_name, CRED_SPECIFIED);
+
        ret = true;
 
        if (!torture_setting_bool(torture, "samba3", false)) {
@@ -1357,6 +1499,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,
@@ -1366,7 +1509,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;
        }
 
@@ -1406,6 +1550,7 @@ static struct dom_sid *name2sid(TALLOC_CTX *mem_ctx,
        struct policy_handle handle;
        struct lsa_LookupNames l;
        struct lsa_TransSidArray sids;
+       struct lsa_RefDomainList *domains = NULL;
        struct lsa_String lsa_name;
        uint32_t count = 0;
        struct dom_sid *result;
@@ -1452,6 +1597,7 @@ static struct dom_sid *name2sid(TALLOC_CTX *mem_ctx,
        l.in.count = &count;
        l.out.count = &count;
        l.out.sids = &sids;
+       l.out.domains = &domains;
 
        status = dcerpc_lsa_LookupNames(p, tmp_ctx, &l);
        if (!NT_STATUS_IS_OK(status)) {
@@ -1461,7 +1607,7 @@ static struct dom_sid *name2sid(TALLOC_CTX *mem_ctx,
                return NULL;
        }
 
-       result = dom_sid_add_rid(mem_ctx, l.out.domains->domains[0].sid,
+       result = dom_sid_add_rid(mem_ctx, domains->domains[0].sid,
                                 l.out.sids->sids[0].rid);
 
        c.in.handle = &handle;
@@ -1482,15 +1628,18 @@ 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;
        NTSTATUS status;
-       struct lsa_StringPointer authority_name_p;
+       struct lsa_String *authority_name_p = NULL;
+       struct lsa_String *account_name_p = NULL;
        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",
@@ -1499,12 +1648,14 @@ static struct dom_sid *whoami(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree)
        }
 
        r.in.system_name = "\\";
-       r.in.account_name = NULL;
-       authority_name_p.string = NULL;
+       r.in.account_name = &account_name_p;
        r.in.authority_name = &authority_name_p;
+       r.out.account_name = &account_name_p;
 
        status = dcerpc_lsa_GetUserName(lsa, mem_ctx, &r);
 
+       authority_name_p = *r.out.authority_name;
+
        if (!NT_STATUS_IS_OK(status)) {
                printf("(%s) GetUserName failed - %s\n",
                       __location__, nt_errstr(status));
@@ -1512,8 +1663,8 @@ static struct dom_sid *whoami(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree)
                return NULL;
        }
 
-       result = name2sid(mem_ctx, lsa, r.out.account_name->string,
-                         r.out.authority_name->string->string);
+       result = name2sid(mem_ctx, lsa, account_name_p->string,
+                         authority_name_p->string);
 
        talloc_free(lsa);
        return result;
@@ -1585,15 +1736,24 @@ 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;
+       struct smbcli_session_options session_options;
 
        if (!(mem_ctx = talloc_new(torture))) {
                return false;
        }
 
+       lp_smbcli_options(torture->lp_ctx, &options);
+       lp_smbcli_session_options(torture->lp_ctx, &session_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);
+               "IPC$", NULL, lp_socket_options(torture->lp_ctx), cmdline_credentials, 
+               lp_resolve_context(torture->lp_ctx),
+               torture->ev, &options, &session_options,
+               lp_iconv_convenience(torture->lp_ctx),
+               lp_gensec_settings(torture, torture->lp_ctx));
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) smbcli_full_connection failed: %s\n",
                         __location__, nt_errstr(status));
@@ -1601,7 +1761,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;
@@ -1617,8 +1777,12 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
 
        status = smbcli_full_connection(
                mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
-               lp_smb_ports(torture->lp_ctx),
-               "IPC$", NULL, anon_creds, NULL);
+               lp_smb_ports(torture->lp_ctx), "IPC$", NULL, 
+               lp_socket_options(torture->lp_ctx), anon_creds, 
+               lp_resolve_context(torture->lp_ctx),
+               torture->ev, &options, &session_options,
+               lp_iconv_convenience(torture->lp_ctx),
+               lp_gensec_settings(torture, torture->lp_ctx));
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) anon smbcli_full_connection failed: %s\n",
                         __location__, nt_errstr(status));
@@ -1626,7 +1790,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;
@@ -1671,7 +1835,7 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
                struct smb_composite_sesssetup setup;
                struct smbcli_tree *tree;
 
-               session2 = smbcli_session_init(cli->transport, mem_ctx, false);
+               session2 = smbcli_session_init(cli->transport, mem_ctx, false, session_options);
                if (session2 == NULL) {
                        d_printf("(%s) smbcli_session_init failed\n",
                                 __location__);
@@ -1682,6 +1846,7 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
                setup.in.capabilities = cli->transport->negotiate.capabilities;
                setup.in.workgroup = "";
                setup.in.credentials = user_creds;
+               setup.in.gensec_settings = lp_gensec_settings(torture, torture->lp_ctx);
 
                status = smb_composite_sesssetup(session2, &setup);
                if (!NT_STATUS_IS_OK(status)) {
@@ -1700,11 +1865,11 @@ 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;
-                       goto delete;
+                       goto del;
                }
 
                talloc_free(tree);
@@ -1718,7 +1883,7 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
                ret = false;
        }
 
- delete:
+ del:
        if (!delete_user(cli, torture->lp_ctx, 
                         cmdline_credentials,
                         cli_credentials_get_username(user_creds))) {
@@ -1736,6 +1901,7 @@ static bool test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
 {
        NTSTATUS status;
        struct srvsvc_NetShareGetInfo r;
+       union srvsvc_NetShareInfo info;
        uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 };
        int i;
        bool ret = true;
@@ -1743,12 +1909,11 @@ static bool test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s",
                                          dcerpc_server_name(p));
        r.in.share_name = sharename;
+       r.out.info = &info;
 
        for (i=0;i<ARRAY_SIZE(levels);i++) {
                r.in.level = levels[i];
 
-               ZERO_STRUCT(r.out);
-
                printf("testing NetShareGetInfo level %u on share '%s'\n", 
                       r.in.level, r.in.share_name);
 
@@ -1777,38 +1942,87 @@ static bool test_NetShareEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
 {
        NTSTATUS status;
        struct srvsvc_NetShareEnum r;
+       struct srvsvc_NetShareInfoCtr info_ctr;
        struct srvsvc_NetShareCtr0 c0;
+       struct srvsvc_NetShareCtr1 c1;
+       struct srvsvc_NetShareCtr2 c2;
+       struct srvsvc_NetShareCtr501 c501;
+       struct srvsvc_NetShareCtr502 c502;
+       struct srvsvc_NetShareCtr1004 c1004;
+       struct srvsvc_NetShareCtr1005 c1005;
+       struct srvsvc_NetShareCtr1006 c1006;
+       struct srvsvc_NetShareCtr1007 c1007;
+       uint32_t totalentries = 0;
        uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 };
        int i;
        bool ret = true;
 
+       ZERO_STRUCT(info_ctr);
+
        r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
-       r.in.ctr.ctr0 = &c0;
-       r.in.ctr.ctr0->count = 0;
-       r.in.ctr.ctr0->array = NULL;
+       r.in.info_ctr = &info_ctr;
        r.in.max_buffer = (uint32_t)-1;
        r.in.resume_handle = NULL;
+       r.out.totalentries = &totalentries;
+       r.out.info_ctr = &info_ctr;
 
        for (i=0;i<ARRAY_SIZE(levels);i++) {
-               r.in.level = levels[i];
-
-               ZERO_STRUCT(r.out);
+               info_ctr.level = levels[i];
+
+               switch (info_ctr.level) {
+               case 0:
+                       ZERO_STRUCT(c0);
+                       info_ctr.ctr.ctr0 = &c0;
+                       break;
+               case 1:
+                       ZERO_STRUCT(c1);
+                       info_ctr.ctr.ctr1 = &c1;
+                       break;
+               case 2:
+                       ZERO_STRUCT(c2);
+                       info_ctr.ctr.ctr2 = &c2;
+                       break;
+               case 501:
+                       ZERO_STRUCT(c501);
+                       info_ctr.ctr.ctr501 = &c501;
+                       break;
+               case 502:
+                       ZERO_STRUCT(c502);
+                       info_ctr.ctr.ctr502 = &c502;
+                       break;
+               case 1004:
+                       ZERO_STRUCT(c1004);
+                       info_ctr.ctr.ctr1004 = &c1004;
+                       break;
+               case 1005:
+                       ZERO_STRUCT(c1005);
+                       info_ctr.ctr.ctr1005 = &c1005;
+                       break;
+               case 1006:
+                       ZERO_STRUCT(c1006);
+                       info_ctr.ctr.ctr1006 = &c1006;
+                       break;
+               case 1007:
+                       ZERO_STRUCT(c1007);
+                       info_ctr.ctr.ctr1007 = &c1007;
+                       break;
+               }
 
-               printf("testing NetShareEnum level %u\n", r.in.level);
+               printf("testing NetShareEnum level %u\n", info_ctr.level);
                status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
                if (!NT_STATUS_IS_OK(status)) {
                        printf("NetShareEnum level %u failed - %s\n",
-                              r.in.level, nt_errstr(status));
+                              info_ctr.level, nt_errstr(status));
                        ret = false;
                        continue;
                }
                if (!W_ERROR_IS_OK(r.out.result)) {
                        printf("NetShareEnum level %u failed - %s\n",
-                              r.in.level, win_errstr(r.out.result));
+                              info_ctr.level, win_errstr(r.out.result));
                        continue;
                }
-               if (r.in.level == 0) {
-                       struct srvsvc_NetShareCtr0 *ctr = r.out.ctr.ctr0;
+               if (info_ctr.level == 0) {
+                       struct srvsvc_NetShareCtr0 *ctr = r.out.info_ctr->ctr.ctr0;
                        if (ctr->count > 0) {
                                *one_sharename = ctr->array[0].name;
                        }
@@ -1833,13 +2047,13 @@ bool torture_samba3_rpc_srvsvc(struct torture_context *torture)
 
        if (!(torture_open_connection_share(
                      mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
-                     "IPC$", NULL))) {
+                     "IPC$", torture->ev))) {
                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));
@@ -1876,7 +2090,7 @@ bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
        struct netr_Credential netr_srv_creds;
        uint32_t negotiate_flags;
        struct netr_ServerAuthenticate2 a;
-       struct creds_CredentialState *creds_state;
+       struct netlogon_creds_CredentialState *creds_state;
        struct netr_Credential netr_cred;
        struct samr_Password mach_pw;
        struct smbcli_state *cli;
@@ -1895,13 +2109,14 @@ bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
        if (!(torture_open_connection_share(
                      mem_ctx, &cli,
                      torture, torture_setting_string(torture, "host", NULL),
-                     "IPC$", NULL))) {
+                     "IPC$", torture->ev))) {
                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;
        }
@@ -1930,7 +2145,7 @@ bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
        generate_random_buffer(netr_cli_creds.data,
                               sizeof(netr_cli_creds.data));
        r.in.credentials = &netr_cli_creds;
-       r.out.credentials = &netr_srv_creds;
+       r.out.return_credentials = &netr_srv_creds;
 
        status = dcerpc_netr_ServerReqChallenge(net_pipe, mem_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
@@ -1942,11 +2157,6 @@ bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
        negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
        E_md4hash("foobar", mach_pw.hash);
 
-       creds_state = talloc(mem_ctx, struct creds_CredentialState);
-       creds_client_init(creds_state, r.in.credentials,
-                         r.out.credentials, &mach_pw,
-                         &netr_cred, negotiate_flags);
-
        a.in.server_name = talloc_asprintf(
                mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
        a.in.account_name = talloc_asprintf(
@@ -1956,7 +2166,15 @@ bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
        a.in.negotiate_flags = &negotiate_flags;
        a.out.negotiate_flags = &negotiate_flags;
        a.in.credentials = &netr_cred;
-       a.out.credentials = &netr_cred;
+       a.out.return_credentials = &netr_cred;
+
+       creds_state = netlogon_creds_client_init(mem_ctx, 
+                                                a.in.account_name,
+                                                a.in.computer_name,
+                                                r.in.credentials,
+                                                r.out.return_credentials, &mach_pw,
+                                                &netr_cred, negotiate_flags);
+       
 
        status = dcerpc_netr_ServerAuthenticate2(net_pipe, mem_ctx, &a);
 
@@ -1974,6 +2192,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)
 {
@@ -1982,6 +2201,7 @@ static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
        struct dcerpc_pipe *p;
        NTSTATUS status;
        struct srvsvc_NetShareGetInfo r;
+       union srvsvc_NetShareInfo info;
        struct security_descriptor *result;
 
        if (!(tmp_ctx = talloc_new(mem_ctx))) {
@@ -1995,7 +2215,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",
@@ -2012,6 +2232,7 @@ static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
                                          dcerpc_server_name(p));
        r.in.share_name = sharename;
        r.in.level = 502;
+       r.out.info = &info;
 
        status = dcerpc_srvsvc_NetShareGetInfo(p, tmp_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
@@ -2021,12 +2242,13 @@ static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
                return NULL;
        }
 
-       result = talloc_steal(mem_ctx, r.out.info.info502->sd);
+       result = talloc_steal(mem_ctx, info.info502->sd_buf.sd);
        talloc_free(tmp_ctx);
        return result;
 }
 
 static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
+                            struct loadparm_context *lp_ctx,
                             struct smbcli_session *sess,
                             const char *sharename,
                             struct security_descriptor *sd)
@@ -2037,6 +2259,7 @@ static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
        NTSTATUS status;
        struct sec_desc_buf i;
        struct srvsvc_NetShareSetInfo r;
+       union srvsvc_NetShareInfo info;
        uint32_t error = 0;
 
        if (!(tmp_ctx = talloc_new(mem_ctx))) {
@@ -2050,7 +2273,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",
@@ -2068,12 +2291,13 @@ static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
        r.in.share_name = sharename;
        r.in.level = 1501;
        i.sd = sd;
-       r.in.info.info1501 = &i;
+       info.info1501 = &i;
+       r.in.info = &info;
        r.in.parm_error = &error;
 
        status = dcerpc_srvsvc_NetShareSetInfo(p, tmp_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
-               d_printf("srvsvc_NetShareGetInfo failed: %s\n",
+               d_printf("srvsvc_NetShareSetInfo failed: %s\n",
                         nt_errstr(status));
        }
 
@@ -2082,6 +2306,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,
@@ -2129,7 +2354,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));
@@ -2160,7 +2385,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));
@@ -2186,31 +2411,31 @@ bool torture_samba3_rpc_sharesec(struct torture_context *torture)
 
        if (!(torture_open_connection_share(
                      mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
-                     "IPC$", NULL))) {
+                     "IPC$", torture->ev))) {
                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);
 
@@ -2234,13 +2459,13 @@ bool torture_samba3_rpc_lsa(struct torture_context *torture)
 
        if (!(torture_open_connection_share(
                      mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
-                     "IPC$", NULL))) {
+                     "IPC$", torture->ev))) {
                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__,
@@ -2277,8 +2502,10 @@ bool torture_samba3_rpc_lsa(struct torture_context *torture)
 
                for (i=0; i<ARRAY_SIZE(levels); i++) {
                        struct lsa_QueryInfoPolicy r;
+                       union lsa_PolicyInformation *info = NULL;
                        r.in.handle = &lsa_handle;
                        r.in.level = levels[i];
+                       r.out.info = &info;
                        status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
                        if (!NT_STATUS_IS_OK(status)) {
                                d_printf("(%s) dcerpc_lsa_QueryInfoPolicy %d "
@@ -2288,7 +2515,7 @@ bool torture_samba3_rpc_lsa(struct torture_context *torture)
                                return false;
                        }
                        if (levels[i] == 5) {
-                               domain_sid = r.out.info->account_domain.sid;
+                               domain_sid = info->account_domain.sid;
                        }
                }
        }
@@ -2297,6 +2524,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;
@@ -2306,7 +2534,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;
        }
@@ -2314,8 +2542,7 @@ 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, lp_iconv_convenience(global_loadparm), 
-                             name, servername) < 0) {
+       if (!pull_ascii_talloc(mem_ctx, name, servername, NULL)) {
                return NT_STATUS_NO_MEMORY;
        }
 
@@ -2323,15 +2550,18 @@ 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;
        NTSTATUS status;
        struct dcerpc_pipe *p;
        struct srvsvc_NetShareEnum r;
+       struct srvsvc_NetShareInfoCtr info_ctr;
        struct srvsvc_NetShareCtr1 c1_in;
        struct srvsvc_NetShareCtr1 *c1;
+       uint32_t totalentries = 0;
        int i;
 
        mem_ctx = talloc_new(ctx);
@@ -2339,7 +2569,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");
@@ -2347,25 +2578,29 @@ static NTSTATUS find_printers(TALLOC_CTX *ctx, struct smbcli_tree *tree,
                return status;
        }
 
+       ZERO_STRUCT(c1_in);
+       info_ctr.level = 1;
+       info_ctr.ctr.ctr1 = &c1_in;
+
        r.in.server_unc = talloc_asprintf(
                mem_ctx, "\\\\%s", dcerpc_server_name(p));
-       r.in.level = 1;
-       ZERO_STRUCT(c1_in);
-       r.in.ctr.ctr1 = &c1_in;
+       r.in.info_ctr = &info_ctr;
        r.in.max_buffer = (uint32_t)-1;
        r.in.resume_handle = NULL;
+       r.out.totalentries = &totalentries;
+       r.out.info_ctr = &info_ctr;
 
        status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("NetShareEnum level %u failed - %s\n",
-                        r.in.level, nt_errstr(status));
+                        info_ctr.level, nt_errstr(status));
                talloc_free(mem_ctx);
                return status;
        }
 
        *printers = NULL;
        *num_printers = 0;
-       c1 = r.out.ctr.ctr1;
+       c1 = r.out.info_ctr->ctr.ctr1;
        for (i=0; i<c1->count; i++) {
                if (c1->array[i].type != STYPE_PRINTQ) {
                        continue;
@@ -2381,20 +2616,26 @@ static NTSTATUS find_printers(TALLOC_CTX *ctx, struct smbcli_tree *tree,
        return NT_STATUS_OK;
 }
 
-static bool enumprinters(TALLOC_CTX *mem_ctx, struct dcerpc_pipe *pipe,
+static bool enumprinters(TALLOC_CTX *mem_ctx, struct dcerpc_pipe *p,
                         const char *servername, int level, int *num_printers)
 {
        struct spoolss_EnumPrinters r;
        NTSTATUS status;
        DATA_BLOB blob;
+       uint32_t needed;
+       uint32_t count;
+       union spoolss_PrinterInfo *info;
 
        r.in.flags = PRINTER_ENUM_LOCAL;
        r.in.server = talloc_asprintf(mem_ctx, "\\\\%s", servername);
        r.in.level = level;
        r.in.buffer = NULL;
        r.in.offered = 0;
+       r.out.needed = &needed;
+       r.out.count = &count;
+       r.out.info = &info;
 
-       status = dcerpc_spoolss_EnumPrinters(pipe, mem_ctx, &r);
+       status = dcerpc_spoolss_EnumPrinters(p, mem_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) dcerpc_spoolss_EnumPrinters failed: %s\n",
                         __location__, nt_errstr(status));
@@ -2408,16 +2649,16 @@ static bool enumprinters(TALLOC_CTX *mem_ctx, struct dcerpc_pipe *pipe,
                return false;
        }
 
-       blob = data_blob_talloc_zero(mem_ctx, r.out.needed);
+       blob = data_blob_talloc_zero(mem_ctx, needed);
        if (blob.data == NULL) {
                d_printf("(%s) data_blob_talloc failed\n", __location__);
                return false;
        }
 
        r.in.buffer = &blob;
-       r.in.offered = r.out.needed;
+       r.in.offered = needed;
 
-       status = dcerpc_spoolss_EnumPrinters(pipe, mem_ctx, &r);
+       status = dcerpc_spoolss_EnumPrinters(p, mem_ctx, &r);
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
                d_printf("(%s) dcerpc_spoolss_EnumPrinters failed: %s, "
                         "%s\n", __location__, nt_errstr(status),
@@ -2425,12 +2666,12 @@ static bool enumprinters(TALLOC_CTX *mem_ctx, struct dcerpc_pipe *pipe,
                return false;
        }
 
-       *num_printers = r.out.count;
+       *num_printers = count;
 
        return true;
 }
 
-static NTSTATUS getprinterinfo(TALLOC_CTX *ctx, struct dcerpc_pipe *pipe,
+static NTSTATUS getprinterinfo(TALLOC_CTX *ctx, struct dcerpc_pipe *p,
                               struct policy_handle *handle, int level,
                               union spoolss_PrinterInfo **res)
 {
@@ -2438,6 +2679,7 @@ static NTSTATUS getprinterinfo(TALLOC_CTX *ctx, struct dcerpc_pipe *pipe,
        struct spoolss_GetPrinter r;
        DATA_BLOB blob;
        NTSTATUS status;
+       uint32_t needed;
 
        mem_ctx = talloc_new(ctx);
        if (mem_ctx == NULL) {
@@ -2448,8 +2690,9 @@ static NTSTATUS getprinterinfo(TALLOC_CTX *ctx, struct dcerpc_pipe *pipe,
        r.in.level = level;
        r.in.buffer = NULL;
        r.in.offered = 0;
+       r.out.needed = &needed;
 
-       status = dcerpc_spoolss_GetPrinter(pipe, mem_ctx, &r);
+       status = dcerpc_spoolss_GetPrinter(p, mem_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) dcerpc_spoolss_GetPrinter failed: %s\n",
                         __location__, nt_errstr(status));
@@ -2467,16 +2710,16 @@ static NTSTATUS getprinterinfo(TALLOC_CTX *ctx, struct dcerpc_pipe *pipe,
 
        r.in.handle = handle;
        r.in.level = level;
-       blob = data_blob_talloc(mem_ctx, NULL, r.out.needed);
+       blob = data_blob_talloc(mem_ctx, NULL, needed);
        if (blob.data == NULL) {
                talloc_free(mem_ctx);
                return NT_STATUS_NO_MEMORY;
        }
        memset(blob.data, 0, blob.length);
        r.in.buffer = &blob;
-       r.in.offered = r.out.needed;
+       r.in.offered = needed;
 
-       status = dcerpc_spoolss_GetPrinter(pipe, mem_ctx, &r);
+       status = dcerpc_spoolss_GetPrinter(p, mem_ctx, &r);
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
                d_printf("(%s) dcerpc_spoolss_GetPrinter failed: %s, "
                         "%s\n", __location__, nt_errstr(status),
@@ -2513,13 +2756,13 @@ bool torture_samba3_rpc_spoolss(struct torture_context *torture)
 
        if (!(torture_open_connection_share(
                      mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
-                     "IPC$", NULL))) {
+                     "IPC$", torture->ev))) {
                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));
@@ -2527,7 +2770,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;
@@ -2539,7 +2782,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__,
@@ -2699,13 +2942,13 @@ bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
 
        if (!(torture_open_connection_share(
                      mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
-                     "IPC$", NULL))) {
+                     "IPC$", torture->ev))) {
                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));
@@ -2713,7 +2956,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__,
@@ -2790,7 +3033,7 @@ static NTSTATUS enumvalues(struct dcerpc_pipe *p, struct policy_handle *handle,
 
        while (1) {
                struct winreg_EnumValue r;
-               struct winreg_StringBuf name;
+               struct winreg_ValNameBuf name;
                enum winreg_Type type = 0;
                uint8_t buf8[1024];
                NTSTATUS status;
@@ -2820,7 +3063,7 @@ static NTSTATUS enumkeys(struct dcerpc_pipe *p, struct policy_handle *handle,
                         TALLOC_CTX *mem_ctx, int depth)
 {
        struct winreg_EnumKey r;
-       struct winreg_StringBuf class, name;
+       struct winreg_StringBuf kclass, name;
        NTSTATUS status;
        NTTIME t = 0;
 
@@ -2828,13 +3071,13 @@ static NTSTATUS enumkeys(struct dcerpc_pipe *p, struct policy_handle *handle,
                return NT_STATUS_OK;
        }
 
-       class.name   = "";
-       class.size   = 1024;
+       kclass.name   = "";
+       kclass.size   = 1024;
 
        r.in.handle = handle;
        r.in.enum_index = 0;
        r.in.name = &name;
-       r.in.keyclass = &class;
+       r.in.keyclass = &kclass;
        r.out.name = &name;
        r.in.last_changed_time = &t;
 
@@ -2962,17 +3205,20 @@ 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)
+                             struct srvsvc_NetShareInfo502 **info502)
 {
        struct smbcli_tree *ipc;
        struct dcerpc_pipe *p;
        struct srvsvc_NetShareGetInfo r;
+       union srvsvc_NetShareInfo info;
        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;
        }
@@ -3000,18 +3246,20 @@ static NTSTATUS get_shareinfo(TALLOC_CTX *mem_ctx,
                                          dcerpc_server_name(p));
        r.in.share_name = share;
        r.in.level = 502;
+       r.out.info = &info;
 
        status = dcerpc_srvsvc_NetShareGetInfo(p, p, &r);
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
-               d_printf("(%s) OpenHKLM failed: %s, %s\n", __location__,
+               d_printf("(%s) srvsvc_NetShareGetInfo failed: %s, %s\n", __location__,
                         nt_errstr(status), win_errstr(r.out.result));
+               status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(r.out.result) : status;
                goto fail;
        }
 
-       *info = talloc_move(mem_ctx, &r.out.info.info502);
+       *info502 = talloc_move(mem_ctx, &info.info502);
        return NT_STATUS_OK;
 
- fail:
+fail:
        talloc_free(p);
        return status;
 }
@@ -3022,6 +3270,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)
 {
@@ -3038,7 +3287,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;
        }
@@ -3070,6 +3320,7 @@ static NTSTATUS get_hklm_handle(TALLOC_CTX *mem_ctx,
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
                d_printf("(%s) OpenHKLM failed: %s, %s\n", __location__,
                         nt_errstr(status), win_errstr(r.out.result));
+               status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(r.out.result) : status;
                goto fail;
        }
 
@@ -3083,6 +3334,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;
@@ -3097,7 +3349,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;
@@ -3123,6 +3375,7 @@ static NTSTATUS torture_samba3_createshare(struct smbcli_state *cli,
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(c.out.result)) {
                d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
                         nt_errstr(status), win_errstr(c.out.result));
+               status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(c.out.result) : status;
                goto fail;
        }
 
@@ -3132,16 +3385,18 @@ static NTSTATUS torture_samba3_createshare(struct smbcli_state *cli,
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(cl.out.result)) {
                d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
                         nt_errstr(status), win_errstr(cl.out.result));
+               status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(cl.out.result) : status;
                goto fail;
        }
 
 
- fail:
+fail:
        talloc_free(mem_ctx);
        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;
@@ -3153,7 +3408,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;
@@ -3171,15 +3427,17 @@ static NTSTATUS torture_samba3_deleteshare(struct smbcli_state *cli,
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(d.out.result)) {
                d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
                         nt_errstr(status), win_errstr(d.out.result));
+               status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(d.out.result) : status;
                goto fail;
        }
 
- fail:
+fail:
        talloc_free(mem_ctx);
        return status;
 }
 
 static NTSTATUS torture_samba3_setconfig(struct smbcli_state *cli,
+                                        struct loadparm_context *lp_ctx,
                                         const char *sharename,
                                         const char *parameter,
                                         const char *value)
@@ -3192,7 +3450,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;;
@@ -3214,10 +3472,12 @@ static NTSTATUS torture_samba3_setconfig(struct smbcli_state *cli,
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(o.out.result)) {
                d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
                         nt_errstr(status), win_errstr(o.out.result));
+               status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(o.out.result) : status;
                goto done;
        }
 
-       if (!reg_string_to_val(hklm, "REG_SZ", value, &type, &val)) {
+       if (!reg_string_to_val(hklm, lp_iconv_convenience(lp_ctx), "REG_SZ", 
+                              value, &type, &val)) {
                d_printf("(%s) reg_string_to_val failed\n", __location__);
                goto done;
        }
@@ -3232,10 +3492,11 @@ static NTSTATUS torture_samba3_setconfig(struct smbcli_state *cli,
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(s.out.result)) {
                d_printf("(%s) SetValue failed: %s, %s\n", __location__,
                         nt_errstr(status), win_errstr(s.out.result));
+               status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(s.out.result) : status;
                goto done;
        }
 
- done:
+done:
        talloc_free(hklm);
        return status;
 }
@@ -3252,21 +3513,21 @@ bool torture_samba3_regconfig(struct torture_context *torture)
                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));
@@ -3279,7 +3540,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));