s4:torture/raw/session: make sure we got a reauth of the existing session
[obnox/samba/samba-obnox.git] / source4 / torture / raw / session.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for session setup operations
4    Copyright (C) Gregor Beck 2012
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "torture.h"
22 #include "smb_cli.h"
23 #include "torture/raw/proto.h"
24 #include "smb_composite/smb_composite.h"
25 #include "lib/cmdline/popt_common.h"
26 #include "param/param.h"
27 #include "torture/util.h"
28
29
30 static bool test_session_reauth(struct torture_context *tctx,
31                                 struct smbcli_state *cli)
32 {
33         NTSTATUS status;
34         struct smb_composite_sesssetup io;
35         int fnum, num;
36         const int dlen = 255;
37         char *data;
38         char fname[256];
39         char buf[dlen+1];
40         bool ok = true;
41         uint16_t vuid1 = cli->session->vuid;
42
43         data = generate_random_str(tctx, dlen);
44         torture_assert(tctx, (data != NULL), "memory allocation failed");
45         snprintf(fname, sizeof(fname), "raw_session_reconnect_%.8s.dat", data);
46
47         fnum = smbcli_nt_create_full(cli->tree, fname, 0,
48                                      SEC_RIGHTS_FILE_ALL,
49                                      FILE_ATTRIBUTE_NORMAL,
50                                      NTCREATEX_SHARE_ACCESS_NONE,
51                                      NTCREATEX_DISP_OPEN_IF,
52                                      NTCREATEX_OPTIONS_DELETE_ON_CLOSE,
53                                      0);
54         torture_assert_ntstatus_ok_goto(tctx, smbcli_nt_error(cli->tree), ok,
55                                         done, "create file");
56         torture_assert_goto(tctx, fnum > 0, ok, done, "create file");
57
58         num = smbcli_smbwrite(cli->tree, fnum, data, 0, dlen);
59         torture_assert_int_equal_goto(tctx, num, dlen, ok, done, "write file");
60
61         ZERO_STRUCT(io);
62         io.in.sesskey         = cli->transport->negotiate.sesskey;
63         io.in.capabilities    = cli->transport->negotiate.capabilities;
64         io.in.credentials     = cmdline_credentials;
65         io.in.workgroup       = lpcfg_workgroup(tctx->lp_ctx);
66         io.in.gensec_settings = lpcfg_gensec_settings(tctx, tctx->lp_ctx);
67         status = smb_composite_sesssetup(cli->session, &io);
68         torture_assert_ntstatus_ok_goto(tctx, status, ok, done, "setup2");
69         torture_assert_int_equal_goto(tctx, io.out.vuid, vuid1, ok, done, "setup2");
70
71         num = smbcli_read(cli->tree, fnum, &buf, 0, dlen);
72         torture_assert_int_equal_goto(tctx, num, dlen, ok, done, "read file");
73         torture_assert_str_equal_goto(tctx, buf, data, ok, done, "read file");
74
75 done:
76         talloc_free(data);
77
78         if (fnum > 0) {
79                 status = smbcli_close(cli->tree, fnum);
80                 torture_assert_ntstatus_ok(tctx, status, "close");
81         }
82         return ok;
83 }
84
85 struct torture_suite *torture_raw_session(TALLOC_CTX *mem_ctx)
86 {
87         struct torture_suite *suite = torture_suite_create(mem_ctx, "session");
88         suite->description = talloc_strdup(suite, "RAW-SESSION tests");
89
90         torture_suite_add_1smb_test(suite, "reauth", test_session_reauth);
91
92         return suite;
93 }