s4:torture/smb2: remove unused var
[Samba.git] / source4 / torture / smb2 / session.c
blob814d01788047d02054d2060c1570dce7f0237263
1 /*
2 Unix SMB/CIFS implementation.
4 test suite for SMB2 session setups
6 Copyright (C) Michael Adam 2012
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
25 #include "torture/torture.h"
26 #include "torture/smb2/proto.h"
27 #include "../libcli/smb/smbXcli_base.h"
29 #define CHECK_VAL(v, correct) do { \
30 if ((v) != (correct)) { \
31 torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s got 0x%x - should be 0x%x\n", \
32 __location__, #v, (int)v, (int)correct); \
33 ret = false; \
34 }} while (0)
36 #define CHECK_STATUS(status, correct) do { \
37 if (!NT_STATUS_EQUAL(status, correct)) { \
38 torture_result(tctx, TORTURE_FAIL, __location__": Incorrect status %s - should be %s", \
39 nt_errstr(status), nt_errstr(correct)); \
40 ret = false; \
41 goto done; \
42 }} while (0)
44 #define CHECK_CREATED(__io, __created, __attribute) \
45 do { \
46 CHECK_VAL((__io)->out.create_action, NTCREATEX_ACTION_ ## __created); \
47 CHECK_VAL((__io)->out.alloc_size, 0); \
48 CHECK_VAL((__io)->out.size, 0); \
49 CHECK_VAL((__io)->out.file_attr, (__attribute)); \
50 CHECK_VAL((__io)->out.reserved2, 0); \
51 } while(0)
54 /**
55 * basic test for doing a session reconnect
57 bool test_session_reconnect(struct torture_context *tctx, struct smb2_tree *tree)
59 NTSTATUS status;
60 TALLOC_CTX *mem_ctx = talloc_new(tctx);
61 char fname[256];
62 struct smb2_handle _h1;
63 struct smb2_handle *h1 = NULL;
64 struct smb2_handle _h2;
65 struct smb2_handle *h2 = NULL;
66 struct smb2_create io1, io2;
67 uint64_t previous_session_id;
68 bool ret = true;
69 struct smb2_tree *tree2;
70 union smb_fileinfo qfinfo;
72 /* Add some random component to the file name. */
73 snprintf(fname, 256, "session_reconnect_%s.dat",
74 generate_random_str(tctx, 8));
76 smb2_util_unlink(tree, fname);
78 smb2_oplock_create_share(&io1, fname,
79 smb2_util_share_access(""),
80 smb2_util_oplock_level("b"));
82 status = smb2_create(tree, mem_ctx, &io1);
83 CHECK_STATUS(status, NT_STATUS_OK);
84 _h1 = io1.out.file.handle;
85 h1 = &_h1;
86 CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
87 CHECK_VAL(io1.out.oplock_level, smb2_util_oplock_level("b"));
89 /* disconnect, reconnect and then do durable reopen */
90 previous_session_id = smb2cli_session_current_id(tree->session->smbXcli);
92 if (!torture_smb2_connection_ext(tctx, previous_session_id, &tree2)) {
93 torture_warning(tctx, "session reconnect failed\n");
94 ret = false;
95 goto done;
98 smb2_oplock_create_share(&io2, fname,
99 smb2_util_share_access(""),
100 smb2_util_oplock_level("b"));
102 status = smb2_create(tree2, mem_ctx, &io2);
103 CHECK_STATUS(status, NT_STATUS_OK);
104 CHECK_CREATED(&io2, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
105 CHECK_VAL(io2.out.oplock_level, smb2_util_oplock_level("b"));
106 _h2 = io2.out.file.handle;
107 h2 = &_h2;
109 /* try to access the file via the old handle */
111 ZERO_STRUCT(qfinfo);
112 qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
113 qfinfo.generic.in.file.handle = _h1;
114 status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
115 CHECK_STATUS(status, NT_STATUS_USER_SESSION_DELETED);
117 done:
118 if (h2 != NULL) {
119 smb2_util_close(tree2, *h2);
122 smb2_util_unlink(tree2, fname);
124 talloc_free(tree);
125 talloc_free(tree2);
127 talloc_free(mem_ctx);
129 return ret;
132 struct torture_suite *torture_smb2_session_init(void)
134 struct torture_suite *suite =
135 torture_suite_create(talloc_autofree_context(), "session");
137 torture_suite_add_1smb2_test(suite, "reconnect", test_session_reconnect);
139 suite->description = talloc_strdup(suite, "SMB2-SESSION tests");
141 return suite;