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/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
26 #include "lib/cmdline/popt_common.h"
27 #include "lib/events/events.h"
30 #define FNAME "scan-getinfo.dat"
31 #define DNAME "scan-getinfo.dir"
35 scan for valid SMB2 getinfo levels
37 BOOL torture_smb2_getinfo_scan(void)
39 TALLOC_CTX *mem_ctx = talloc_new(NULL);
40 struct smb2_tree *tree;
42 struct smb2_getinfo io;
43 struct smb2_handle fhandle, dhandle;
46 if (!torture_smb2_connection(mem_ctx, &tree)) {
50 status = torture_setup_complex_file(tree, FNAME);
51 if (!NT_STATUS_IS_OK(status)) {
52 printf("Failed to setup complex file '%s'\n", FNAME);
55 torture_setup_complex_file(tree, FNAME ":2ndstream");
57 status = torture_setup_complex_dir(tree, DNAME);
58 if (!NT_STATUS_IS_OK(status)) {
59 printf("Failed to setup complex dir '%s'\n", DNAME);
62 torture_setup_complex_file(tree, DNAME ":2ndstream");
64 torture_smb2_testfile(tree, FNAME, &fhandle);
65 torture_smb2_testdir(tree, DNAME, &dhandle);
69 io.in.max_response_size = 0xFFFF;
72 for (i=0;i<0x100;i++) {
73 io.in.level = (i<<8) | c;
75 io.in.handle = fhandle;
76 status = smb2_getinfo(tree, mem_ctx, &io);
77 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS) &&
78 !NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) &&
79 !NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
80 printf("file level 0x%04x is %ld bytes - %s\n",
81 io.in.level, (long)io.out.blob.length, nt_errstr(status));
82 dump_data(1, io.out.blob.data, io.out.blob.length);
85 io.in.handle = dhandle;
86 status = smb2_getinfo(tree, mem_ctx, &io);
87 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS) &&
88 !NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) &&
89 !NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
90 printf("dir level 0x%04x is %ld bytes - %s\n",
91 io.in.level, (long)io.out.blob.length, nt_errstr(status));
92 dump_data(1, io.out.blob.data, io.out.blob.length);
103 scan for valid SMB2 setinfo levels
105 BOOL torture_smb2_setinfo_scan(void)
107 TALLOC_CTX *mem_ctx = talloc_new(NULL);
108 struct smb2_tree *tree;
110 struct smb2_setinfo io;
111 struct smb2_handle handle;
114 if (!torture_smb2_connection(mem_ctx, &tree)) {
118 status = torture_setup_complex_file(tree, FNAME);
119 if (!NT_STATUS_IS_OK(status)) {
120 printf("Failed to setup complex file '%s'\n", FNAME);
123 torture_setup_complex_file(tree, FNAME ":2ndstream");
125 torture_smb2_testfile(tree, FNAME, &handle);
128 io.in.blob = data_blob_talloc(mem_ctx, NULL, 1024);
131 for (i=0;i<0x100;i++) {
132 io.in.level = (i<<8) | c;
133 io.in.handle = handle;
134 status = smb2_setinfo(tree, &io);
135 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS) &&
136 !NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
137 printf("file level 0x%04x - %s\n",
138 io.in.level, nt_errstr(status));
143 talloc_free(mem_ctx);
150 scan for valid SMB2 scan levels
152 BOOL torture_smb2_find_scan(void)
154 TALLOC_CTX *mem_ctx = talloc_new(NULL);
155 struct smb2_tree *tree;
158 struct smb2_handle handle;
161 if (!torture_smb2_connection(mem_ctx, &tree)) {
165 status = smb2_util_roothandle(tree, &handle);
166 if (!NT_STATUS_IS_OK(status)) {
167 printf("Failed to open roothandle - %s\n", nt_errstr(status));
173 io.in.continue_flags = SMB2_CONTINUE_FLAG_RESTART;
174 io.in.max_response_size = 0x10000;
175 io.in.handle = handle;
177 for (i=1;i<0x100;i++) {
180 io.in.handle = handle;
181 status = smb2_find(tree, mem_ctx, &io);
182 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS) &&
183 !NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) &&
184 !NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
185 printf("find level 0x%04x is %ld bytes - %s\n",
186 io.in.level, (long)io.out.blob.length, nt_errstr(status));
187 dump_data(1, io.out.blob.data, io.out.blob.length);
191 talloc_free(mem_ctx);
197 scan for valid SMB2 opcodes
199 BOOL torture_smb2_scan(void)
201 TALLOC_CTX *mem_ctx = talloc_new(NULL);
202 struct smb2_tree *tree;
203 const char *host = lp_parm_string(-1, "torture", "host");
204 const char *share = lp_parm_string(-1, "torture", "share");
205 struct cli_credentials *credentials = cmdline_credentials;
208 struct smb2_request *req;
210 status = smb2_connect(mem_ctx, host, share, credentials, &tree,
211 event_context_find(mem_ctx));
212 if (!NT_STATUS_IS_OK(status)) {
213 printf("Connection failed - %s\n", nt_errstr(status));
217 tree->session->transport->options.timeout = 3;
219 for (opcode=0;opcode<1000;opcode++) {
220 req = smb2_request_init_tree(tree, opcode, 2, 0);
221 SSVAL(req->out.body, 0, 0);
222 smb2_transport_send(req);
223 if (!smb2_request_receive(req)) {
225 status = smb2_connect(mem_ctx, host, share, credentials, &tree,
226 event_context_find(mem_ctx));
227 if (!NT_STATUS_IS_OK(status)) {
228 printf("Connection failed - %s\n", nt_errstr(status));
231 tree->session->transport->options.timeout = 3;
233 status = smb2_request_destroy(req);
234 printf("active opcode %4d gave status %s\n", opcode, nt_errstr(status));
238 talloc_free(mem_ctx);