2 Unix SMB/CIFS implementation.
3 SMB trans2 alias scanner
4 Copyright (C) Andrew Tridgell 2003
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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "dlinklist.h"
23 #include "libcli/raw/libcliraw.h"
25 int create_complex_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, const char *fname);
28 struct trans2_blobs *next, *prev;
30 DATA_BLOB params, data;
33 /* look for aliases for a query */
34 static void gen_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int level_offset)
38 struct trans2_blobs *alias_blobs = NULL;
39 struct trans2_blobs *t2b, *t2b2;
40 int count=0, alias_count=0;
42 mem_ctx = talloc_init("aliases");
44 for (level=0;level<2000;level++) {
47 SSVAL(t2->in.params.data, level_offset, level);
49 status = smb_raw_trans2(cli->tree, mem_ctx, t2);
50 if (!NT_STATUS_IS_OK(status)) continue;
52 t2b = talloc(mem_ctx, struct trans2_blobs);
54 t2b->params = t2->out.params;
55 t2b->data = t2->out.data;
56 DLIST_ADD(alias_blobs, t2b);
57 d_printf("\tFound level %4u (0x%03x) of size %3d (0x%02x)\n",
59 (int)t2b->data.length, (int)t2b->data.length);
63 d_printf("Found %d levels with success status\n", count);
65 for (t2b=alias_blobs; t2b; t2b=t2b->next) {
66 for (t2b2=alias_blobs; t2b2; t2b2=t2b2->next) {
67 if (t2b->level >= t2b2->level) continue;
68 if (data_blob_equal(&t2b->params, &t2b2->params) &&
69 data_blob_equal(&t2b->data, &t2b2->data)) {
70 printf("\tLevel %u (0x%x) and level %u (0x%x) are possible aliases\n",
71 t2b->level, t2b->level, t2b2->level, t2b2->level);
77 d_printf("Found %d aliased levels\n", alias_count);
82 /* look for qfsinfo aliases */
83 static void qfsinfo_aliases(struct smbcli_state *cli)
86 uint16_t setup = TRANSACT2_QFSINFO;
88 d_printf("\nChecking for QFSINFO aliases\n");
91 t2.in.max_data = smb_raw_max_trans_data(cli->tree, 0);
95 t2.in.setup_count = 1;
97 t2.in.params = data_blob(NULL, 2);
98 t2.in.data = data_blob(NULL, 0);
100 gen_aliases(cli, &t2, 0);
103 /* look for qfileinfo aliases */
104 static void qfileinfo_aliases(struct smbcli_state *cli)
106 struct smb_trans2 t2;
107 uint16_t setup = TRANSACT2_QFILEINFO;
108 const char *fname = "\\qfileinfo_aliases.txt";
111 d_printf("\nChecking for QFILEINFO aliases\n");
114 t2.in.max_data = smb_raw_max_trans_data(cli->tree, 2);
118 t2.in.setup_count = 1;
119 t2.in.setup = &setup;
120 t2.in.params = data_blob(NULL, 4);
121 t2.in.data = data_blob(NULL, 0);
123 smbcli_unlink(cli->tree, fname);
124 fnum = create_complex_file(cli, cli, fname);
126 printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
129 smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2));
131 SSVAL(t2.in.params.data, 0, fnum);
133 gen_aliases(cli, &t2, 2);
135 smbcli_close(cli->tree, fnum);
136 smbcli_unlink(cli->tree, fname);
140 /* look for qpathinfo aliases */
141 static void qpathinfo_aliases(struct smbcli_state *cli)
143 struct smb_trans2 t2;
144 uint16_t setup = TRANSACT2_QPATHINFO;
145 const char *fname = "\\qpathinfo_aliases.txt";
149 mem_ctx = talloc_init("qpathinfo");
151 d_printf("\nChecking for QPATHINFO aliases\n");
154 t2.in.max_data = smb_raw_max_trans_data(cli->tree, 2);
158 t2.in.setup_count = 1;
159 t2.in.setup = &setup;
160 t2.in.params = data_blob_talloc(mem_ctx, NULL, 6);
161 t2.in.data = data_blob(NULL, 0);
163 smbcli_unlink(cli->tree, fname);
164 fnum = create_complex_file(cli, cli, fname);
166 printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
169 smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2));
170 smbcli_close(cli->tree, fnum);
172 SIVAL(t2.in.params.data, 2, 0);
174 smbcli_blob_append_string(cli->session, mem_ctx, &t2.in.params,
175 fname, STR_TERMINATE);
177 gen_aliases(cli, &t2, 0);
179 smbcli_unlink(cli->tree, fname);
180 talloc_free(mem_ctx);
184 /* look for trans2 findfirst aliases */
185 static void findfirst_aliases(struct smbcli_state *cli)
187 struct smb_trans2 t2;
188 uint16_t setup = TRANSACT2_FINDFIRST;
189 const char *fname = "\\findfirst_aliases.txt";
193 mem_ctx = talloc_init("findfirst");
195 d_printf("\nChecking for FINDFIRST aliases\n");
197 t2.in.max_param = 16;
198 t2.in.max_data = smb_raw_max_trans_data(cli->tree, 16);
202 t2.in.setup_count = 1;
203 t2.in.setup = &setup;
204 t2.in.params = data_blob_talloc(mem_ctx, NULL, 12);
205 t2.in.data = data_blob(NULL, 0);
207 smbcli_unlink(cli->tree, fname);
208 fnum = create_complex_file(cli, cli, fname);
210 printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
213 smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2));
214 smbcli_close(cli->tree, fnum);
216 SSVAL(t2.in.params.data, 0, 0);
217 SSVAL(t2.in.params.data, 2, 1);
218 SSVAL(t2.in.params.data, 4, FLAG_TRANS2_FIND_CLOSE);
219 SSVAL(t2.in.params.data, 6, 0);
220 SIVAL(t2.in.params.data, 8, 0);
222 smbcli_blob_append_string(cli->session, mem_ctx, &t2.in.params,
223 fname, STR_TERMINATE);
225 gen_aliases(cli, &t2, 6);
227 smbcli_unlink(cli->tree, fname);
228 talloc_free(mem_ctx);
233 /* look for aliases for a set function */
234 static void gen_set_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int level_offset)
238 struct trans2_blobs *alias_blobs = NULL;
239 struct trans2_blobs *t2b;
242 mem_ctx = talloc_init("aliases");
244 for (level=1;level<1100;level++) {
245 NTSTATUS status, status1;
246 SSVAL(t2->in.params.data, level_offset, level);
248 status1 = NT_STATUS_OK;
250 for (dsize=2; dsize<1024; dsize += 2) {
251 data_blob_free(&t2->in.data);
252 t2->in.data = data_blob(NULL, dsize);
253 data_blob_clear(&t2->in.data);
254 status = smb_raw_trans2(cli->tree, mem_ctx, t2);
255 /* some error codes mean that this whole level doesn't exist */
256 if (NT_STATUS_EQUAL(NT_STATUS_INVALID_LEVEL, status) ||
257 NT_STATUS_EQUAL(NT_STATUS_INVALID_INFO_CLASS, status) ||
258 NT_STATUS_EQUAL(NT_STATUS_NOT_SUPPORTED, status)) {
261 if (NT_STATUS_IS_OK(status)) break;
263 /* invalid parameter means that the level exists at this
264 size, but the contents are wrong (not surprising with
266 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) break;
268 /* this is the usual code for 'wrong size' */
269 if (NT_STATUS_EQUAL(status, NT_STATUS_INFO_LENGTH_MISMATCH)) {
273 if (!NT_STATUS_EQUAL(status, status1)) {
274 printf("level=%d size=%d %s\n", level, dsize, nt_errstr(status));
279 if (!NT_STATUS_IS_OK(status) &&
280 !NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) continue;
282 t2b = talloc(mem_ctx, struct trans2_blobs);
284 t2b->params = t2->out.params;
285 t2b->data = t2->out.data;
286 DLIST_ADD(alias_blobs, t2b);
287 d_printf("\tFound level %4u (0x%03x) of size %3d (0x%02x)\n",
289 (int)t2->in.data.length, (int)t2->in.data.length);
293 d_printf("Found %d valid levels\n", count);
294 talloc_free(mem_ctx);
299 /* look for setfileinfo aliases */
300 static void setfileinfo_aliases(struct smbcli_state *cli)
302 struct smb_trans2 t2;
303 uint16_t setup = TRANSACT2_SETFILEINFO;
304 const char *fname = "\\setfileinfo_aliases.txt";
307 d_printf("\nChecking for SETFILEINFO aliases\n");
314 t2.in.setup_count = 1;
315 t2.in.setup = &setup;
316 t2.in.params = data_blob(NULL, 6);
317 t2.in.data = data_blob(NULL, 0);
319 smbcli_unlink(cli->tree, fname);
320 fnum = create_complex_file(cli, cli, fname);
322 printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
325 smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2));
327 SSVAL(t2.in.params.data, 0, fnum);
328 SSVAL(t2.in.params.data, 4, 0);
330 gen_set_aliases(cli, &t2, 2);
332 smbcli_close(cli->tree, fnum);
333 smbcli_unlink(cli->tree, fname);
336 /* look for setpathinfo aliases */
337 static void setpathinfo_aliases(struct smbcli_state *cli)
339 struct smb_trans2 t2;
340 uint16_t setup = TRANSACT2_SETPATHINFO;
341 const char *fname = "\\setpathinfo_aliases.txt";
345 mem_ctx = talloc_init("findfirst");
347 d_printf("\nChecking for SETPATHINFO aliases\n");
349 t2.in.max_param = 32;
350 t2.in.max_data = smb_raw_max_trans_data(cli->tree, 32);
354 t2.in.setup_count = 1;
355 t2.in.setup = &setup;
356 t2.in.params = data_blob_talloc(mem_ctx, NULL, 4);
357 t2.in.data = data_blob(NULL, 0);
359 smbcli_unlink(cli->tree, fname);
361 fnum = create_complex_file(cli, cli, fname);
363 printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
366 smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2));
367 smbcli_close(cli->tree, fnum);
369 SSVAL(t2.in.params.data, 2, 0);
371 smbcli_blob_append_string(cli->session, mem_ctx, &t2.in.params,
372 fname, STR_TERMINATE);
374 gen_set_aliases(cli, &t2, 0);
376 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
377 printf("unlink: %s\n", smbcli_errstr(cli->tree));
379 talloc_free(mem_ctx);
383 /* look for aliased info levels in trans2 calls */
384 BOOL torture_trans2_aliases(void)
386 struct smbcli_state *cli;
388 if (!torture_open_connection(&cli)) {
393 qfsinfo_aliases(cli);
394 qfileinfo_aliases(cli);
395 qpathinfo_aliases(cli);
396 findfirst_aliases(cli);
397 setfileinfo_aliases(cli);
398 setpathinfo_aliases(cli);
400 if (!torture_close_connection(cli)) {