s4:torture: add a raw.session suite with a raw.session.reauth test
[Samba/gebeck_regimport.git] / source4 / torture / raw / session.c
blob5c454c6e9eb0ddd8a848ada93fdf48a14b19a497
1 /*
2 Unix SMB/CIFS implementation.
3 test suite for session setup operations
4 Copyright (C) Gregor Beck 2012
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.
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.
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/>.
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"
30 static bool test_session_reauth(struct torture_context *tctx,
31 struct smbcli_state *cli)
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;
42 data = generate_random_str(tctx, dlen);
43 snprintf(fname, sizeof(fname), "raw_session_reconnect_%.8s.dat", data);
45 fnum = smbcli_nt_create_full(cli->tree, fname, 0,
46 SEC_RIGHTS_FILE_ALL,
47 FILE_ATTRIBUTE_NORMAL,
48 NTCREATEX_SHARE_ACCESS_NONE,
49 NTCREATEX_DISP_OPEN_IF,
50 NTCREATEX_OPTIONS_DELETE_ON_CLOSE,
51 0);
52 torture_assert_ntstatus_ok_goto(tctx, smbcli_nt_error(cli->tree), ok,
53 done, "create file");
54 torture_assert_goto(tctx, fnum > 0, ok, done, "create file");
56 num = smbcli_smbwrite(cli->tree, fnum, data, 0, dlen);
57 torture_assert_int_equal_goto(tctx, num, dlen, ok, done, "write file");
59 ZERO_STRUCT(io);
60 io.in.sesskey = cli->transport->negotiate.sesskey;
61 io.in.capabilities = cli->transport->negotiate.capabilities;
62 io.in.credentials = cmdline_credentials;
63 io.in.workgroup = lpcfg_workgroup(tctx->lp_ctx);
64 io.in.gensec_settings = lpcfg_gensec_settings(tctx, tctx->lp_ctx);
65 status = smb_composite_sesssetup(cli->session, &io);
66 torture_assert_ntstatus_ok_goto(tctx, status, ok, done, "setup2");
68 num = smbcli_read(cli->tree, fnum, &buf, 0, dlen);
69 torture_assert_int_equal_goto(tctx, num, dlen, ok, done, "read file");
70 torture_assert_str_equal_goto(tctx, buf, data, ok, done, "read file");
72 done:
73 talloc_free(data);
75 if (fnum > 0) {
76 status = smbcli_close(cli->tree, fnum);
77 torture_assert_ntstatus_ok(tctx, status, "close");
79 return ok;
82 struct torture_suite *torture_raw_session(TALLOC_CTX *mem_ctx)
84 struct torture_suite *suite = torture_suite_create(mem_ctx, "session");
85 suite->description = talloc_strdup(suite, "RAW-SESSION tests");
87 torture_suite_add_1smb_test(suite, "reauth", test_session_reauth);
89 return suite;