Remove more event_context_init() uses from function calls within deep down the code.
[bbaumbach/samba-autobuild/.git] / source4 / torture / rpc / samba3rpc.c
index 779a28e1263b7b85706927b14091c89ce5820e06..40a7c156f41deb715fb75d90a77e5be33d6840b6 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"
@@ -47,6 +48,7 @@
 #include "libcli/smb_composite/smb_composite.h"
 #include "libcli/auth/libcli_auth.h"
 #include "lib/crypto/crypto.h"
+#include "auth/ntlmssp/ntlmssp.h"
 #include "libcli/security/proto.h"
 #include "param/param.h"
 #include "lib/registry/registry.h"
@@ -87,7 +89,7 @@ bool torture_bind_authcontext(struct torture_context *torture)
                                        lp_smb_ports(torture->lp_ctx),
                                        "IPC$", NULL, cmdline_credentials,
                                        lp_resolve_context(torture->lp_ctx),
-                                       NULL, &options);
+                                       torture->ev, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
@@ -301,7 +303,7 @@ bool torture_bind_samba3(struct torture_context *torture)
                                        lp_smb_ports(torture->lp_ctx),
                                        "IPC$", NULL, cmdline_credentials,
                                        lp_resolve_context(torture->lp_ctx),
-                                       NULL, &options);
+                                       torture->ev, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
@@ -682,6 +684,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");
@@ -701,6 +704,22 @@ static bool join3(struct smbcli_state *cli,
                goto done;
        }
 
+       {
+               struct samr_QueryUserInfo q;
+
+               q.in.user_handle = wks_handle;
+               q.in.level = 21;
+
+               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 = q.out.info->info21.last_password_change;
+       }
+
        cli_credentials_set_domain(wks_creds, dom_name, CRED_SPECIFIED);
 
        if (use_level25) {
@@ -794,6 +813,39 @@ static bool join3(struct smbcli_state *cli,
                }
        }
 
+       {
+               struct samr_QueryUserInfo q;
+
+               q.in.user_handle = wks_handle;
+               q.in.level = 21;
+
+               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
+                           == q.out.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
+                           != q.out.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:
@@ -985,7 +1037,8 @@ static bool schan(struct smbcli_state *cli,
 
                generate_random_buffer(chal.data, chal.length);
                names_blob = NTLMv2_generate_names_blob(
-                       mem_ctx, cli_credentials_get_workstation(user_creds),
+                       mem_ctx, lp_iconv_convenience(lp_ctx), 
+                       cli_credentials_get_workstation(user_creds),
                        cli_credentials_get_domain(user_creds));
                status = cli_credentials_get_ntlm_response(
                        user_creds, mem_ctx, &flags, chal, names_blob,
@@ -1167,7 +1220,7 @@ bool torture_netlogon_samba3(struct torture_context *torture)
                                        lp_smb_ports(torture->lp_ctx),
                                        "IPC$", NULL, anon_creds, 
                                        lp_resolve_context(torture->lp_ctx),
-                                       NULL, &options);
+                                       torture->ev, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
@@ -1254,7 +1307,7 @@ static bool test_join3(struct torture_context *tctx,
                                        lp_smb_ports(tctx->lp_ctx),
                                        "IPC$", NULL, smb_creds, 
                                        lp_resolve_context(tctx->lp_ctx),
-                                       NULL, &options);
+                                       tctx->ev, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
@@ -1320,6 +1373,8 @@ bool torture_samba3_sessionkey(struct torture_context *torture)
                goto done;
        }
 
+       cli_credentials_set_workstation(anon_creds, wks_name, CRED_SPECIFIED);
+
        ret = true;
 
        if (!torture_setting_bool(torture, "samba3", false)) {
@@ -1627,7 +1682,7 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
                lp_smb_ports(torture->lp_ctx),
                "IPC$", NULL, cmdline_credentials, 
                lp_resolve_context(torture->lp_ctx),
-               NULL, &options);
+               torture->ev, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) smbcli_full_connection failed: %s\n",
                         __location__, nt_errstr(status));
@@ -1654,7 +1709,7 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture)
                lp_smb_ports(torture->lp_ctx),
                "IPC$", NULL, anon_creds, 
                lp_resolve_context(torture->lp_ctx),
-               NULL, &options);
+               torture->ev, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) anon smbcli_full_connection failed: %s\n",
                         __location__, nt_errstr(status));
@@ -2337,6 +2392,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;
@@ -2346,7 +2402,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;
        }
@@ -2354,7 +2410,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)
+       if (pull_ascii_talloc(mem_ctx, iconv_convenience
                              name, servername) < 0) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -2561,7 +2617,7 @@ bool torture_samba3_rpc_spoolss(struct torture_context *torture)
                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));
@@ -2747,7 +2803,7 @@ bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
                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));
@@ -3066,6 +3122,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)
 {
@@ -3083,7 +3140,7 @@ static NTSTATUS get_hklm_handle(TALLOC_CTX *mem_ctx,
 
        if (!(p = dcerpc_pipe_init(result,
                                   cli->transport->socket->event.ctx,
-                                  lp_iconv_convenience(global_loadparm)))) {
+                                  iconv_convenience))) {
                status = NT_STATUS_NO_MEMORY;
                goto fail;
        }
@@ -3128,6 +3185,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;
@@ -3142,7 +3200,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;
@@ -3199,7 +3257,8 @@ static NTSTATUS torture_samba3_deleteshare(struct torture_context *torture,
        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;
@@ -3226,6 +3285,7 @@ static NTSTATUS torture_samba3_deleteshare(struct torture_context *torture,
 }
 
 static NTSTATUS torture_samba3_setconfig(struct smbcli_state *cli,
+                                        struct loadparm_context *lp_ctx,
                                         const char *sharename,
                                         const char *parameter,
                                         const char *value)
@@ -3238,7 +3298,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;;
@@ -3263,7 +3323,8 @@ static NTSTATUS torture_samba3_setconfig(struct smbcli_state *cli,
                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;
        }
@@ -3298,14 +3359,14 @@ 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));