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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "libcli/raw/libcliraw.h"
25 #include "libcli/smb2/smb2.h"
26 #include "libcli/smb2/smb2_calls.h"
27 #include "lib/cmdline/popt_common.h"
28 #include "lib/events/events.h"
31 #define FNAME "scan-getinfo.dat"
32 #define DNAME "scan-getinfo.dir"
36 scan for valid SMB2 getinfo levels
38 BOOL torture_smb2_getinfo_scan(void)
40 TALLOC_CTX *mem_ctx = talloc_new(NULL);
41 struct smb2_tree *tree;
43 struct smb2_getinfo io;
44 struct smb2_handle fhandle, dhandle;
47 if (!torture_smb2_connection(mem_ctx, &tree)) {
51 status = torture_setup_complex_file(tree, FNAME);
52 if (!NT_STATUS_IS_OK(status)) {
53 printf("Failed to setup complex file '%s'\n", FNAME);
56 torture_setup_complex_file(tree, FNAME ":2ndstream");
58 status = torture_setup_complex_dir(tree, DNAME);
59 if (!NT_STATUS_IS_OK(status)) {
60 printf("Failed to setup complex dir '%s'\n", DNAME);
63 torture_setup_complex_file(tree, DNAME ":2ndstream");
65 torture_smb2_testfile(tree, FNAME, &fhandle);
66 torture_smb2_testdir(tree, DNAME, &dhandle);
70 io.in.max_response_size = 0xFFFF;
73 for (i=0;i<0x100;i++) {
74 io.in.level = (i<<8) | c;
76 io.in.handle = fhandle;
77 status = smb2_getinfo(tree, mem_ctx, &io);
78 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS) &&
79 !NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) &&
80 !NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
81 printf("file level 0x%04x is %ld bytes - %s\n",
82 io.in.level, (long)io.out.blob.length, nt_errstr(status));
83 dump_data(1, io.out.blob.data, io.out.blob.length);
86 io.in.handle = dhandle;
87 status = smb2_getinfo(tree, mem_ctx, &io);
88 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS) &&
89 !NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) &&
90 !NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
91 printf("dir level 0x%04x is %ld bytes - %s\n",
92 io.in.level, (long)io.out.blob.length, nt_errstr(status));
93 dump_data(1, io.out.blob.data, io.out.blob.length);
104 scan for valid SMB2 setinfo levels
106 BOOL torture_smb2_setinfo_scan(void)
108 TALLOC_CTX *mem_ctx = talloc_new(NULL);
109 struct smb2_tree *tree;
111 struct smb2_setinfo io;
112 struct smb2_handle handle;
115 if (!torture_smb2_connection(mem_ctx, &tree)) {
119 status = torture_setup_complex_file(tree, FNAME);
120 if (!NT_STATUS_IS_OK(status)) {
121 printf("Failed to setup complex file '%s'\n", FNAME);
124 torture_setup_complex_file(tree, FNAME ":2ndstream");
126 torture_smb2_testfile(tree, FNAME, &handle);
129 io.in.blob = data_blob_talloc(mem_ctx, NULL, 1024);
132 for (i=0;i<0x100;i++) {
133 io.in.level = (i<<8) | c;
134 io.in.handle = handle;
135 status = smb2_setinfo(tree, &io);
136 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS) &&
137 !NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
138 printf("file level 0x%04x - %s\n",
139 io.in.level, nt_errstr(status));
144 talloc_free(mem_ctx);
151 scan for valid SMB2 scan levels
153 BOOL torture_smb2_find_scan(void)
155 TALLOC_CTX *mem_ctx = talloc_new(NULL);
156 struct smb2_tree *tree;
159 struct smb2_handle handle;
162 if (!torture_smb2_connection(mem_ctx, &tree)) {
166 status = smb2_util_roothandle(tree, &handle);
167 if (!NT_STATUS_IS_OK(status)) {
168 printf("Failed to open roothandle - %s\n", nt_errstr(status));
174 io.in.continue_flags = SMB2_CONTINUE_FLAG_RESTART;
175 io.in.max_response_size = 0x10000;
176 io.in.handle = handle;
178 for (i=1;i<0x100;i++) {
181 io.in.handle = handle;
182 status = smb2_find(tree, mem_ctx, &io);
183 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS) &&
184 !NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) &&
185 !NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
186 printf("find level 0x%04x is %ld bytes - %s\n",
187 io.in.level, (long)io.out.blob.length, nt_errstr(status));
188 dump_data(1, io.out.blob.data, io.out.blob.length);
192 talloc_free(mem_ctx);
198 scan for valid SMB2 opcodes
200 BOOL torture_smb2_scan(void)
202 TALLOC_CTX *mem_ctx = talloc_new(NULL);
203 struct smb2_tree *tree;
204 const char *host = lp_parm_string(-1, "torture", "host");
205 const char *share = lp_parm_string(-1, "torture", "share");
206 struct cli_credentials *credentials = cmdline_credentials;
209 struct smb2_request *req;
211 status = smb2_connect(mem_ctx, host, share, credentials, &tree,
212 event_context_find(mem_ctx));
213 if (!NT_STATUS_IS_OK(status)) {
214 printf("Connection failed - %s\n", nt_errstr(status));
218 tree->session->transport->options.timeout = 3;
220 for (opcode=0;opcode<1000;opcode++) {
221 req = smb2_request_init_tree(tree, opcode, 2, 0);
222 SSVAL(req->out.body, 0, 0);
223 smb2_transport_send(req);
224 if (!smb2_request_receive(req)) {
226 status = smb2_connect(mem_ctx, host, share, credentials, &tree,
227 event_context_find(mem_ctx));
228 if (!NT_STATUS_IS_OK(status)) {
229 printf("Connection failed - %s\n", nt_errstr(status));
232 tree->session->transport->options.timeout = 3;
234 status = smb2_request_destroy(req);
235 printf("active opcode %4d gave status %s\n", opcode, nt_errstr(status));
239 talloc_free(mem_ctx);