2 Unix SMB/CIFS implementation.
3 SMB torture tester - scanning functions
4 Copyright (C) Andrew Tridgell 2001
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/>.
21 #include "system/filesys.h"
22 #include "torture/proto.h"
28 #define DATA_SIZE 1024
29 #define PARAM_SIZE 1024
31 /****************************************************************************
32 look for a partial hit
33 ****************************************************************************/
34 static void trans2_check_hit(const char *format
, int op
, int level
, NTSTATUS status
)
36 if (NT_STATUS_V(status
) == NT_STATUS_V(NT_STATUS_INVALID_LEVEL
) ||
37 NT_STATUS_V(status
) == NT_STATUS_V(NT_STATUS_NOT_IMPLEMENTED
) ||
38 NT_STATUS_V(status
) == NT_STATUS_V(NT_STATUS_NOT_SUPPORTED
) ||
39 NT_STATUS_V(status
) == NT_STATUS_V(NT_STATUS_UNSUCCESSFUL
) ||
40 NT_STATUS_V(status
) == NT_STATUS_V(NT_STATUS_INVALID_INFO_CLASS
)) {
44 printf("possible %s hit op=%3d level=%5d status=%s\n",
45 format
, op
, level
, nt_errstr(status
));
49 /****************************************************************************
50 check for existance of a trans2 call
51 ****************************************************************************/
52 static NTSTATUS
try_trans2(struct cli_state
*cli
,
54 uint8_t *param
, uint8_t *data
,
55 uint32_t param_len
, uint32_t data_len
,
56 uint32_t *rparam_len
, uint32_t *rdata_len
)
59 uint8_t *rparam
=NULL
, *rdata
=NULL
;
62 SSVAL(setup
+0, 0, op
);
64 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
65 NULL
, -1, /* name, fid */
67 NULL
, 0, 0, /* setup */
69 data
, data_len
, cli
->max_xmit
,
70 NULL
, /* recv_flags2 */
71 NULL
, 0, NULL
, /* rsetup */
72 &rparam
, 0, rparam_len
,
73 &rdata
, 0, rdata_len
);
82 static NTSTATUS
try_trans2_len(struct cli_state
*cli
,
85 uint8_t *param
, uint8_t *data
,
86 uint32_t param_len
, uint32_t *data_len
,
87 uint32_t *rparam_len
, uint32_t *rdata_len
)
89 NTSTATUS ret
=NT_STATUS_OK
;
91 ret
= try_trans2(cli
, op
, param
, data
, param_len
,
92 DATA_SIZE
, rparam_len
, rdata_len
);
94 printf("op=%d level=%d ret=%s\n", op
, level
, nt_errstr(ret
));
96 if (!NT_STATUS_IS_OK(ret
)) return ret
;
99 while (*data_len
< DATA_SIZE
) {
100 ret
= try_trans2(cli
, op
, param
, data
, param_len
,
101 *data_len
, rparam_len
, rdata_len
);
102 if (NT_STATUS_IS_OK(ret
)) break;
105 if (NT_STATUS_IS_OK(ret
)) {
106 printf("found %s level=%d data_len=%d rparam_len=%d rdata_len=%d\n",
107 format
, level
, *data_len
, *rparam_len
, *rdata_len
);
109 trans2_check_hit(format
, op
, level
, ret
);
114 /****************************************************************************
115 check for existance of a trans2 call
116 ****************************************************************************/
117 static bool scan_trans2(struct cli_state
*cli
, int op
, int level
,
118 int fnum
, int dnum
, const char *fname
)
120 uint32_t data_len
= 0;
121 uint32_t param_len
= 0;
122 uint32_t rparam_len
, rdata_len
;
123 uint8_t param
[PARAM_SIZE
], data
[DATA_SIZE
];
126 memset(data
, 0, sizeof(data
));
129 /* try with a info level only */
131 SSVAL(param
, 0, level
);
132 status
= try_trans2_len(cli
, "void", op
, level
, param
, data
, param_len
, &data_len
,
133 &rparam_len
, &rdata_len
);
134 if (NT_STATUS_IS_OK(status
)) return True
;
136 /* try with a file descriptor */
138 SSVAL(param
, 0, fnum
);
139 SSVAL(param
, 2, level
);
141 status
= try_trans2_len(cli
, "fnum", op
, level
, param
, data
, param_len
, &data_len
,
142 &rparam_len
, &rdata_len
);
143 if (NT_STATUS_IS_OK(status
)) return True
;
146 /* try with a notify style */
148 SSVAL(param
, 0, dnum
);
149 SSVAL(param
, 2, dnum
);
150 SSVAL(param
, 4, level
);
151 status
= try_trans2_len(cli
, "notify", op
, level
, param
, data
, param_len
, &data_len
,
152 &rparam_len
, &rdata_len
);
153 if (NT_STATUS_IS_OK(status
)) return True
;
155 /* try with a file name */
157 SSVAL(param
, 0, level
);
160 param_len
+= clistr_push(cli
, ¶m
[6], fname
, -1, STR_TERMINATE
);
162 status
= try_trans2_len(cli
, "fname", op
, level
, param
, data
, param_len
, &data_len
,
163 &rparam_len
, &rdata_len
);
164 if (NT_STATUS_IS_OK(status
)) return True
;
166 /* try with a new file name */
168 SSVAL(param
, 0, level
);
171 param_len
+= clistr_push(cli
, ¶m
[6], "\\newfile.dat", -1, STR_TERMINATE
);
173 status
= try_trans2_len(cli
, "newfile", op
, level
, param
, data
, param_len
, &data_len
,
174 &rparam_len
, &rdata_len
);
175 cli_unlink(cli
, "\\newfile.dat", aSYSTEM
| aHIDDEN
);
176 cli_rmdir(cli
, "\\newfile.dat");
177 if (NT_STATUS_IS_OK(status
)) return True
;
180 cli_mkdir(cli
, "\\testdir");
182 SSVAL(param
, 0, level
);
183 param_len
+= clistr_push(cli
, ¶m
[2], "\\testdir", -1, STR_TERMINATE
);
185 status
= try_trans2_len(cli
, "dfs", op
, level
, param
, data
, param_len
, &data_len
,
186 &rparam_len
, &rdata_len
);
187 cli_rmdir(cli
, "\\testdir");
188 if (NT_STATUS_IS_OK(status
)) return True
;
194 bool torture_trans2_scan(int dummy
)
196 static struct cli_state
*cli
;
198 const char *fname
= "\\scanner.dat";
201 printf("starting trans2 scan test\n");
203 if (!torture_open_connection(&cli
, 0)) {
207 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
,
208 DENY_NONE
, &fnum
))) {
209 printf("open of %s failed\n", fname
);
212 if (!NT_STATUS_IS_OK(cli_open(cli
, "\\", O_RDONLY
, DENY_NONE
, &dnum
))) {
213 printf("open of \\ failed\n");
217 for (op
=OP_MIN
; op
<=OP_MAX
; op
++) {
218 printf("Scanning op=%d\n", op
);
219 for (level
= 0; level
<= 50; level
++) {
220 scan_trans2(cli
, op
, level
, fnum
, dnum
, fname
);
223 for (level
= 0x100; level
<= 0x130; level
++) {
224 scan_trans2(cli
, op
, level
, fnum
, dnum
, fname
);
227 for (level
= 1000; level
< 1050; level
++) {
228 scan_trans2(cli
, op
, level
, fnum
, dnum
, fname
);
232 torture_close_connection(cli
);
234 printf("trans2 scan finished\n");
241 /****************************************************************************
242 look for a partial hit
243 ****************************************************************************/
244 static void nttrans_check_hit(const char *format
, int op
, int level
, NTSTATUS status
)
246 if (NT_STATUS_V(status
) == NT_STATUS_V(NT_STATUS_INVALID_LEVEL
) ||
247 NT_STATUS_V(status
) == NT_STATUS_V(NT_STATUS_NOT_IMPLEMENTED
) ||
248 NT_STATUS_V(status
) == NT_STATUS_V(NT_STATUS_NOT_SUPPORTED
) ||
249 NT_STATUS_V(status
) == NT_STATUS_V(NT_STATUS_UNSUCCESSFUL
) ||
250 NT_STATUS_V(status
) == NT_STATUS_V(NT_STATUS_INVALID_INFO_CLASS
)) {
254 printf("possible %s hit op=%3d level=%5d status=%s\n",
255 format
, op
, level
, nt_errstr(status
));
259 /****************************************************************************
260 check for existance of a nttrans call
261 ****************************************************************************/
262 static NTSTATUS
try_nttrans(struct cli_state
*cli
,
264 uint8_t *param
, uint8_t *data
,
265 int32_t param_len
, uint32_t data_len
,
266 uint32_t *rparam_len
,
269 uint8_t *rparam
=NULL
, *rdata
=NULL
;
272 status
= cli_trans(talloc_tos(), cli
, SMBnttrans
,
273 NULL
, -1, /* name, fid */
275 NULL
, 0, 0, /* setup */
277 data
, data_len
, cli
->max_xmit
,
278 NULL
, /* recv_flags2 */
279 NULL
, 0, NULL
, /* rsetup */
280 &rparam
, 0, rparam_len
,
281 &rdata
, 0, rdata_len
);
289 static NTSTATUS
try_nttrans_len(struct cli_state
*cli
,
292 uint8_t *param
, uint8_t *data
,
293 int param_len
, uint32_t *data_len
,
294 uint32_t *rparam_len
, uint32_t *rdata_len
)
296 NTSTATUS ret
=NT_STATUS_OK
;
298 ret
= try_nttrans(cli
, op
, param
, data
, param_len
,
299 DATA_SIZE
, rparam_len
, rdata_len
);
301 printf("op=%d level=%d ret=%s\n", op
, level
, nt_errstr(ret
));
303 if (!NT_STATUS_IS_OK(ret
)) return ret
;
306 while (*data_len
< DATA_SIZE
) {
307 ret
= try_nttrans(cli
, op
, param
, data
, param_len
,
308 *data_len
, rparam_len
, rdata_len
);
309 if (NT_STATUS_IS_OK(ret
)) break;
312 if (NT_STATUS_IS_OK(ret
)) {
313 printf("found %s level=%d data_len=%d rparam_len=%d rdata_len=%d\n",
314 format
, level
, *data_len
, *rparam_len
, *rdata_len
);
316 nttrans_check_hit(format
, op
, level
, ret
);
321 /****************************************************************************
322 check for existance of a nttrans call
323 ****************************************************************************/
324 static bool scan_nttrans(struct cli_state
*cli
, int op
, int level
,
325 int fnum
, int dnum
, const char *fname
)
327 uint32_t data_len
= 0;
328 uint32_t param_len
= 0;
329 uint32_t rparam_len
, rdata_len
;
330 uint8_t param
[PARAM_SIZE
], data
[DATA_SIZE
];
333 memset(data
, 0, sizeof(data
));
336 /* try with a info level only */
338 SSVAL(param
, 0, level
);
339 status
= try_nttrans_len(cli
, "void", op
, level
, param
, data
, param_len
, &data_len
,
340 &rparam_len
, &rdata_len
);
341 if (NT_STATUS_IS_OK(status
)) return True
;
343 /* try with a file descriptor */
345 SSVAL(param
, 0, fnum
);
346 SSVAL(param
, 2, level
);
348 status
= try_nttrans_len(cli
, "fnum", op
, level
, param
, data
, param_len
, &data_len
,
349 &rparam_len
, &rdata_len
);
350 if (NT_STATUS_IS_OK(status
)) return True
;
353 /* try with a notify style */
355 SSVAL(param
, 0, dnum
);
356 SSVAL(param
, 2, dnum
);
357 SSVAL(param
, 4, level
);
358 status
= try_nttrans_len(cli
, "notify", op
, level
, param
, data
, param_len
, &data_len
,
359 &rparam_len
, &rdata_len
);
360 if (NT_STATUS_IS_OK(status
)) return True
;
362 /* try with a file name */
364 SSVAL(param
, 0, level
);
367 param_len
+= clistr_push(cli
, ¶m
[6], fname
, -1, STR_TERMINATE
);
369 status
= try_nttrans_len(cli
, "fname", op
, level
, param
, data
, param_len
, &data_len
,
370 &rparam_len
, &rdata_len
);
371 if (NT_STATUS_IS_OK(status
)) return True
;
373 /* try with a new file name */
375 SSVAL(param
, 0, level
);
378 param_len
+= clistr_push(cli
, ¶m
[6], "\\newfile.dat", -1, STR_TERMINATE
);
380 status
= try_nttrans_len(cli
, "newfile", op
, level
, param
, data
, param_len
, &data_len
,
381 &rparam_len
, &rdata_len
);
382 cli_unlink(cli
, "\\newfile.dat", aSYSTEM
| aHIDDEN
);
383 cli_rmdir(cli
, "\\newfile.dat");
384 if (NT_STATUS_IS_OK(status
)) return True
;
387 cli_mkdir(cli
, "\\testdir");
389 SSVAL(param
, 0, level
);
390 param_len
+= clistr_push(cli
, ¶m
[2], "\\testdir", -1, STR_TERMINATE
);
392 status
= try_nttrans_len(cli
, "dfs", op
, level
, param
, data
, param_len
, &data_len
,
393 &rparam_len
, &rdata_len
);
394 cli_rmdir(cli
, "\\testdir");
395 if (NT_STATUS_IS_OK(status
)) return True
;
401 bool torture_nttrans_scan(int dummy
)
403 static struct cli_state
*cli
;
405 const char *fname
= "\\scanner.dat";
408 printf("starting nttrans scan test\n");
410 if (!torture_open_connection(&cli
, 0)) {
414 cli_open(cli
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
,
416 cli_open(cli
, "\\", O_RDONLY
, DENY_NONE
, &dnum
);
418 for (op
=OP_MIN
; op
<=OP_MAX
; op
++) {
419 printf("Scanning op=%d\n", op
);
420 for (level
= 0; level
<= 50; level
++) {
421 scan_nttrans(cli
, op
, level
, fnum
, dnum
, fname
);
424 for (level
= 0x100; level
<= 0x130; level
++) {
425 scan_nttrans(cli
, op
, level
, fnum
, dnum
, fname
);
428 for (level
= 1000; level
< 1050; level
++) {
429 scan_nttrans(cli
, op
, level
, fnum
, dnum
, fname
);
433 torture_close_connection(cli
);
435 printf("nttrans scan finished\n");