s4: fix various warnings (not "const" related ones)
[sfrench/samba-autobuild/.git] / source4 / torture / rpc / samba3rpc.c
index 260c1cc1499bc6baeb74f19b8c940352e00e0d49..4a529d38f628f5ec7048e75d77665d5a7ae719ff 100644 (file)
@@ -49,7 +49,7 @@
 #include "libcli/auth/libcli_auth.h"
 #include "../lib/crypto/crypto.h"
 #include "auth/ntlmssp/ntlmssp.h"
-#include "libcli/security/proto.h"
+#include "libcli/security/security.h"
 #include "param/param.h"
 #include "lib/registry/registry.h"
 #include "libcli/resolve/resolve.h"
@@ -89,9 +89,13 @@ bool torture_bind_authcontext(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, cmdline_credentials,
+                                       "IPC$", NULL, 
+                                       lp_socket_options(torture->lp_ctx),
+                                       cmdline_credentials,
                                        lp_resolve_context(torture->lp_ctx),
-                                       torture->ev, &options, &session_options);
+                                       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));
@@ -159,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)) {
@@ -207,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;
 
@@ -231,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));
@@ -255,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)) {
@@ -305,9 +312,13 @@ bool torture_bind_samba3(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, cmdline_credentials,
+                                       "IPC$", NULL, 
+                                       lp_socket_options(torture->lp_ctx),
+                                       cmdline_credentials,
                                        lp_resolve_context(torture->lp_ctx),
-                                       torture->ev, &options, &session_options);
+                                       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));
@@ -344,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;
@@ -354,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;
@@ -380,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",
@@ -412,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)) {
@@ -419,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[dom_idx].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)) {
@@ -442,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);
@@ -466,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)) {
@@ -480,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);
@@ -498,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;
 
@@ -544,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;
 
 
@@ -559,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;
@@ -586,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)) {
@@ -593,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;
@@ -710,9 +732,11 @@ 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)) {
@@ -721,7 +745,7 @@ static bool join3(struct smbcli_state *cli,
                        goto done;
                }
 
-               last_password_change = q.out.info->info21.last_password_change;
+               last_password_change = info->info21.last_password_change;
        }
 
        cli_credentials_set_domain(wks_creds, dom_name, CRED_SPECIFIED);
@@ -743,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),
@@ -784,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)) {
@@ -819,9 +847,11 @@ 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)) {
@@ -832,7 +862,7 @@ static bool join3(struct smbcli_state *cli,
 
                if (use_level25) {
                        if (last_password_change
-                           == q.out.info->info21.last_password_change) {
+                           == info->info21.last_password_change) {
                                d_printf("(%s) last_password_change unchanged "
                                         "during join, level25 must change "
                                         "it\n", __location__);
@@ -841,7 +871,7 @@ static bool join3(struct smbcli_state *cli,
                }
                else {
                        if (last_password_change
-                           != q.out.info->info21.last_password_change) {
+                           != info->info21.last_password_change) {
                                d_printf("(%s) last_password_change changed "
                                         "during join, level24 doesn't "
                                         "change it\n", __location__);
@@ -874,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;
 
@@ -916,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)) {
@@ -928,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(
@@ -942,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)) {
@@ -951,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;
        }
@@ -1009,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
@@ -1024,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;
@@ -1041,7 +1077,7 @@ static bool schan(struct smbcli_state *cli,
 
                generate_random_buffer(chal.data, chal.length);
                names_blob = NTLMv2_generate_names_blob(
-                       mem_ctx, lp_iconv_convenience(lp_ctx), 
+                       mem_ctx, 
                        cli_credentials_get_workstation(user_creds),
                        cli_credentials_get_domain(user_creds));
                status = cli_credentials_get_ntlm_response(
@@ -1054,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);
@@ -1071,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);
@@ -1080,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)) {
@@ -1091,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);
@@ -1109,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)) {
@@ -1121,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;
@@ -1131,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));
@@ -1139,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)) {
@@ -1151,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");
                }
 
@@ -1203,7 +1251,7 @@ bool torture_netlogon_samba3(struct torture_context *torture)
 
        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");
@@ -1224,9 +1272,13 @@ bool torture_netlogon_samba3(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, 
+                                       "IPC$", NULL, 
+                                       lp_socket_options(torture->lp_ctx),
+                                       anon_creds, 
                                        lp_resolve_context(torture->lp_ctx),
-                                       torture->ev, &options, &session_options);
+                                       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));
@@ -1313,9 +1365,11 @@ static bool test_join3(struct torture_context *tctx,
        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),
-                                       tctx->ev, &options, &session_options);
+                                       "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));
@@ -1374,7 +1428,7 @@ 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");
@@ -1496,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;
@@ -1542,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)) {
@@ -1551,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;
@@ -1579,7 +1635,8 @@ static struct dom_sid *whoami(TALLOC_CTX *mem_ctx,
        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, lp_ctx, tree, "\\pipe\\lsarpc",
@@ -1591,12 +1648,14 @@ static struct dom_sid *whoami(TALLOC_CTX *mem_ctx,
        }
 
        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));
@@ -1604,8 +1663,8 @@ static struct dom_sid *whoami(TALLOC_CTX *mem_ctx,
                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;
@@ -1690,9 +1749,11 @@ 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, cmdline_credentials, 
+               "IPC$", NULL, lp_socket_options(torture->lp_ctx), cmdline_credentials, 
                lp_resolve_context(torture->lp_ctx),
-               torture->ev, &options, &session_options);
+               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));
@@ -1716,10 +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, 
+               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);
+               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));
@@ -1783,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)) {
@@ -1805,7 +1869,7 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
                        d_printf("(%s) whoami on user connection failed\n",
                                 __location__);
                        ret = false;
-                       goto delete;
+                       goto del;
                }
 
                talloc_free(tree);
@@ -1819,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))) {
@@ -1837,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;
@@ -1844,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);
 
@@ -1878,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;
                        }
@@ -1977,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;
@@ -2032,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)) {
@@ -2044,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(
@@ -2058,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);
 
@@ -2085,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))) {
@@ -2115,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)) {
@@ -2124,7 +2242,7 @@ 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;
 }
@@ -2141,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))) {
@@ -2172,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));
        }
 
@@ -2382,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 "
@@ -2393,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;
                        }
                }
        }
@@ -2420,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, iconv_convenience, 
-                             name, servername) < 0) {
+       if (!pull_ascii_talloc(mem_ctx, name, servername, NULL)) {
                return NT_STATUS_NO_MEMORY;
        }
 
@@ -2437,8 +2558,10 @@ static NTSTATUS find_printers(TALLOC_CTX *ctx, struct loadparm_context *lp_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);
@@ -2455,25 +2578,29 @@ static NTSTATUS find_printers(TALLOC_CTX *ctx, struct loadparm_context *lp_ctx,
                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;
@@ -2489,20 +2616,26 @@ static NTSTATUS find_printers(TALLOC_CTX *ctx, struct loadparm_context *lp_ctx,
        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));
@@ -2516,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),
@@ -2533,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)
 {
@@ -2546,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) {
@@ -2556,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));
@@ -2575,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),
@@ -2898,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;
@@ -2928,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;
 
@@ -2936,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;
 
@@ -3073,11 +3208,12 @@ 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,
@@ -3110,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;
 }
@@ -3182,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;
        }
 
@@ -3236,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;
        }
 
@@ -3245,11 +3385,12 @@ 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;
 }
@@ -3286,10 +3427,11 @@ static NTSTATUS torture_samba3_deleteshare(struct torture_context *torture,
        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;
 }
@@ -3330,6 +3472,7 @@ 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;
        }
 
@@ -3349,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;
 }