2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2005
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/>.
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
25 #include "lib/cmdline/cmdline.h"
26 #include "torture/torture.h"
27 #include "param/param.h"
28 #include "libcli/resolve/resolve.h"
30 #include "torture/smb2/proto.h"
33 scan for valid SMB2 getinfo levels
35 static bool torture_smb2_getinfo_scan(struct torture_context
*tctx
)
37 struct smb2_tree
*tree
;
39 struct smb2_getinfo io
;
40 struct smb2_handle fhandle
, dhandle
;
43 static const char *FNAME
= "scan-getinfo.dat";
44 static const char *FNAME2
= "scan-getinfo.dat:2ndstream";
45 static const char *DNAME
= "scan-getinfo.dir";
46 static const char *DNAME2
= "scan-getinfo.dir:2ndstream";
48 if (!torture_smb2_connection(tctx
, &tree
)) {
52 status
= torture_setup_complex_file(tctx
, tree
, FNAME
);
53 if (!NT_STATUS_IS_OK(status
)) {
54 torture_comment(tctx
, "Failed to setup complex file '%s': %s\n",
55 FNAME
, nt_errstr(status
));
58 torture_setup_complex_file(tctx
, tree
, FNAME2
);
60 status
= torture_setup_complex_dir(tctx
, tree
, DNAME
);
61 if (!NT_STATUS_IS_OK(status
)) {
62 torture_comment(tctx
, "Failed to setup complex dir '%s': %s\n",
63 DNAME
, nt_errstr(status
));
64 smb2_util_unlink(tree
, FNAME
);
67 torture_setup_complex_file(tctx
, tree
, DNAME2
);
69 torture_smb2_testfile(tree
, FNAME
, &fhandle
);
70 torture_smb2_testdir(tree
, DNAME
, &dhandle
);
74 io
.in
.output_buffer_length
= 0xFFFF;
77 for (i
=0;i
<0x100;i
++) {
81 io
.in
.file
.handle
= fhandle
;
82 status
= smb2_getinfo(tree
, tctx
, &io
);
83 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_INFO_CLASS
)) {
84 torture_comment(tctx
, "file level 0x%02x:%02x %u is %ld bytes - %s\n",
85 io
.in
.info_type
, io
.in
.info_class
,
86 (unsigned)io
.in
.info_class
,
87 (long)io
.out
.blob
.length
, nt_errstr(status
));
88 dump_data(1, io
.out
.blob
.data
, io
.out
.blob
.length
);
91 io
.in
.file
.handle
= dhandle
;
92 status
= smb2_getinfo(tree
, tctx
, &io
);
93 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_INFO_CLASS
)) {
94 torture_comment(tctx
, "dir level 0x%02x:%02x %u is %ld bytes - %s\n",
95 io
.in
.info_type
, io
.in
.info_class
,
96 (unsigned)io
.in
.info_class
,
97 (long)io
.out
.blob
.length
, nt_errstr(status
));
98 dump_data(1, io
.out
.blob
.data
, io
.out
.blob
.length
);
103 smb2_util_unlink(tree
, FNAME
);
104 smb2_util_rmdir(tree
, DNAME
);
109 scan for valid SMB2 setinfo levels
111 static bool torture_smb2_setinfo_scan(struct torture_context
*tctx
)
113 static const char *FNAME
= "scan-setinfo.dat";
114 static const char *FNAME2
= "scan-setinfo.dat:2ndstream";
116 struct smb2_tree
*tree
;
118 struct smb2_setinfo io
;
119 struct smb2_handle handle
;
122 if (!torture_smb2_connection(tctx
, &tree
)) {
126 status
= torture_setup_complex_file(tctx
, tree
, FNAME
);
127 if (!NT_STATUS_IS_OK(status
)) {
128 torture_comment(tctx
, "Failed to setup complex file '%s': %s\n",
129 FNAME
, nt_errstr(status
));
132 torture_setup_complex_file(tctx
, tree
, FNAME2
);
134 torture_smb2_testfile(tree
, FNAME
, &handle
);
137 io
.in
.blob
= data_blob_talloc_zero(tctx
, 1024);
140 for (i
=0;i
<0x100;i
++) {
141 io
.in
.level
= (i
<<8) | c
;
142 io
.in
.file
.handle
= handle
;
143 status
= smb2_setinfo(tree
, &io
);
144 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_INFO_CLASS
)) {
145 torture_comment(tctx
, "file level 0x%04x - %s\n",
146 io
.in
.level
, nt_errstr(status
));
151 smb2_util_unlink(tree
, FNAME
);
157 scan for valid SMB2 scan levels
159 static bool torture_smb2_find_scan(struct torture_context
*tctx
)
161 struct smb2_tree
*tree
;
164 struct smb2_handle handle
;
167 if (!torture_smb2_connection(tctx
, &tree
)) {
171 torture_assert_ntstatus_ok(tctx
,
172 smb2_util_roothandle(tree
, &handle
),
173 "Failed to open roothandle");
176 io
.in
.file
.handle
= handle
;
178 io
.in
.continue_flags
= SMB2_CONTINUE_FLAG_RESTART
;
179 io
.in
.max_response_size
= 0x10000;
181 for (i
=1;i
<0x100;i
++) {
184 io
.in
.file
.handle
= handle
;
185 status
= smb2_find(tree
, tctx
, &io
);
186 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_INFO_CLASS
) &&
187 !NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
) &&
188 !NT_STATUS_EQUAL(status
, NT_STATUS_NOT_SUPPORTED
)) {
189 torture_comment(tctx
, "find level 0x%04x is %ld bytes - %s\n",
190 io
.in
.level
, (long)io
.out
.blob
.length
, nt_errstr(status
));
191 dump_data(1, io
.out
.blob
.data
, io
.out
.blob
.length
);
199 scan for valid SMB2 opcodes
201 static bool torture_smb2_scan(struct torture_context
*tctx
)
203 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
204 struct smb2_tree
*tree
;
205 const char *host
= torture_setting_string(tctx
, "host", NULL
);
206 const char *share
= torture_setting_string(tctx
, "share", NULL
);
209 struct smb2_request
*req
;
210 struct smbcli_options options
;
212 lpcfg_smbcli_options(tctx
->lp_ctx
, &options
);
214 status
= smb2_connect(mem_ctx
, host
,
215 lpcfg_smb_ports(tctx
->lp_ctx
),
217 lpcfg_resolve_context(tctx
->lp_ctx
),
218 samba_cmdline_get_creds(),
219 &tree
, tctx
->ev
, &options
,
220 lpcfg_socket_options(tctx
->lp_ctx
),
221 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
222 torture_assert_ntstatus_ok(tctx
, status
, "Connection failed");
224 tree
->session
->transport
->options
.request_timeout
= 3;
226 for (opcode
=0;opcode
<1000;opcode
++) {
227 req
= smb2_request_init_tree(tree
, opcode
, 2, false, 0);
228 SSVAL(req
->out
.body
, 0, 0);
229 smb2_transport_send(req
);
230 if (!smb2_request_receive(req
)) {
232 status
= smb2_connect(mem_ctx
, host
,
233 lpcfg_smb_ports(tctx
->lp_ctx
),
235 lpcfg_resolve_context(tctx
->lp_ctx
),
236 samba_cmdline_get_creds(),
237 &tree
, tctx
->ev
, &options
,
238 lpcfg_socket_options(tctx
->lp_ctx
),
239 lpcfg_gensec_settings(mem_ctx
, tctx
->lp_ctx
));
240 torture_assert_ntstatus_ok(tctx
, status
, "Connection failed");
241 tree
->session
->transport
->options
.request_timeout
= 3;
243 status
= smb2_request_destroy(req
);
244 torture_comment(tctx
, "active opcode %4d gave status %s\n", opcode
, nt_errstr(status
));
248 talloc_free(mem_ctx
);
253 struct torture_suite
*torture_smb2_scan_init(TALLOC_CTX
*ctx
)
255 struct torture_suite
*suite
= torture_suite_create(ctx
, "scan");
257 torture_suite_add_simple_test(suite
, "scan", torture_smb2_scan
);
258 torture_suite_add_simple_test(suite
, "getinfo", torture_smb2_getinfo_scan
);
259 torture_suite_add_simple_test(suite
, "setinfo", torture_smb2_setinfo_scan
);
260 torture_suite_add_simple_test(suite
, "find", torture_smb2_find_scan
);
262 suite
->description
= talloc_strdup(suite
, "scan target (not a test)");