Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : RAW_SEARCH_* individual test suite
4 : Copyright (C) Andrew Tridgell 2003
5 :
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.
10 :
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.
15 :
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/>.
18 : */
19 :
20 : #include "includes.h"
21 : #include "system/filesys.h"
22 : #include "libcli/raw/libcliraw.h"
23 : #include "libcli/raw/raw_proto.h"
24 : #include "libcli/libcli.h"
25 : #include "torture/util.h"
26 : #include "lib/util/tsort.h"
27 : #include "torture/raw/proto.h"
28 :
29 : #undef strncasecmp
30 :
31 : #define BASEDIR "\\testsearch"
32 :
33 : #define CHECK_STATUS_LEVEL(__tctx, __status, __level, __supp) \
34 : do { \
35 : if (NT_STATUS_EQUAL(__status, \
36 : NT_STATUS_NOT_SUPPORTED) || \
37 : NT_STATUS_EQUAL(__status, \
38 : NT_STATUS_NOT_IMPLEMENTED)) { \
39 : __supp = false; \
40 : } else { \
41 : __supp = true; \
42 : } \
43 : if (__supp) { \
44 : torture_assert_ntstatus_ok_goto(__tctx, \
45 : __status, ret, done, #__level" failed"); \
46 : } else { \
47 : torture_warning(__tctx, "(%s) Info " \
48 : "level "#__level" is %s", \
49 : __location__, nt_errstr(__status)); \
50 : } \
51 : } while (0)
52 :
53 : /*
54 : callback function for single_search
55 : */
56 245 : static bool single_search_callback(void *private_data, const union smb_search_data *file)
57 : {
58 245 : union smb_search_data *data = (union smb_search_data *)private_data;
59 :
60 245 : *data = *file;
61 :
62 245 : return true;
63 : }
64 :
65 : /*
66 : do a single file (non-wildcard) search
67 : */
68 197 : NTSTATUS torture_single_search(struct smbcli_state *cli,
69 : TALLOC_CTX *tctx,
70 : const char *pattern,
71 : enum smb_search_level level,
72 : enum smb_search_data_level data_level,
73 : uint16_t attrib,
74 : union smb_search_data *data)
75 : {
76 : union smb_search_first io;
77 : union smb_search_close c;
78 : NTSTATUS status;
79 :
80 197 : switch (level) {
81 6 : case RAW_SEARCH_SEARCH:
82 : case RAW_SEARCH_FFIRST:
83 : case RAW_SEARCH_FUNIQUE:
84 6 : io.search_first.level = level;
85 6 : io.search_first.data_level = RAW_SEARCH_DATA_SEARCH;
86 6 : io.search_first.in.max_count = 1;
87 6 : io.search_first.in.search_attrib = attrib;
88 6 : io.search_first.in.pattern = pattern;
89 6 : break;
90 :
91 191 : case RAW_SEARCH_TRANS2:
92 191 : io.t2ffirst.level = RAW_SEARCH_TRANS2;
93 191 : io.t2ffirst.data_level = data_level;
94 191 : io.t2ffirst.in.search_attrib = attrib;
95 191 : io.t2ffirst.in.max_count = 1;
96 191 : io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE;
97 191 : io.t2ffirst.in.storage_type = 0;
98 191 : io.t2ffirst.in.pattern = pattern;
99 191 : break;
100 :
101 0 : case RAW_SEARCH_SMB2:
102 0 : return NT_STATUS_INVALID_LEVEL;
103 : }
104 :
105 197 : status = smb_raw_search_first(cli->tree, tctx,
106 : &io, (void *)data, single_search_callback);
107 :
108 197 : if (NT_STATUS_IS_OK(status) && level == RAW_SEARCH_FFIRST) {
109 1 : c.fclose.level = RAW_FINDCLOSE_FCLOSE;
110 1 : c.fclose.in.max_count = 1;
111 1 : c.fclose.in.search_attrib = 0;
112 1 : c.fclose.in.id = data->search.id;
113 1 : status = smb_raw_search_close(cli->tree, &c);
114 : }
115 :
116 197 : return status;
117 : }
118 :
119 :
120 : static struct {
121 : const char *name;
122 : enum smb_search_level level;
123 : enum smb_search_data_level data_level;
124 : int name_offset;
125 : int resume_key_offset;
126 : uint32_t capability_mask;
127 : NTSTATUS status;
128 : union smb_search_data data;
129 : } levels[] = {
130 : {
131 : .name = "FFIRST",
132 : .level = RAW_SEARCH_FFIRST,
133 : .data_level = RAW_SEARCH_DATA_SEARCH,
134 : .name_offset = offsetof(union smb_search_data,
135 : search.name),
136 : .resume_key_offset = -1,
137 : },
138 : {
139 : .name = "FUNIQUE",
140 : .level = RAW_SEARCH_FUNIQUE,
141 : .data_level = RAW_SEARCH_DATA_SEARCH,
142 : .name_offset = offsetof(union smb_search_data,
143 : search.name),
144 : .resume_key_offset = -1,
145 : },
146 : {
147 : .name = "SEARCH",
148 : .level = RAW_SEARCH_SEARCH,
149 : .data_level = RAW_SEARCH_DATA_SEARCH,
150 : .name_offset = offsetof(union smb_search_data,
151 : search.name),
152 : .resume_key_offset = -1,
153 : },
154 : {
155 : .name = "STANDARD",
156 : .level = RAW_SEARCH_TRANS2,
157 : .data_level = RAW_SEARCH_DATA_STANDARD,
158 : .name_offset = offsetof(union smb_search_data,
159 : standard.name.s),
160 : .resume_key_offset = offsetof(union smb_search_data,
161 : standard.resume_key),
162 : },
163 : {
164 : .name = "EA_SIZE",
165 : .level = RAW_SEARCH_TRANS2,
166 : .data_level = RAW_SEARCH_DATA_EA_SIZE,
167 : .name_offset = offsetof(union smb_search_data,
168 : ea_size.name.s),
169 : .resume_key_offset = offsetof(union smb_search_data,
170 : ea_size.resume_key),
171 : },
172 : {
173 : .name = "DIRECTORY_INFO",
174 : .level = RAW_SEARCH_TRANS2,
175 : .data_level = RAW_SEARCH_DATA_DIRECTORY_INFO,
176 : .name_offset = offsetof(union smb_search_data,
177 : directory_info.name.s),
178 : .resume_key_offset = offsetof(union smb_search_data,
179 : directory_info.file_index),
180 : },
181 : {
182 : .name = "FULL_DIRECTORY_INFO",
183 : .level = RAW_SEARCH_TRANS2,
184 : .data_level = RAW_SEARCH_DATA_FULL_DIRECTORY_INFO,
185 : .name_offset = offsetof(union smb_search_data,
186 : full_directory_info.name.s),
187 : .resume_key_offset = offsetof(union smb_search_data,
188 : full_directory_info.file_index),
189 : },
190 : {
191 : .name = "NAME_INFO",
192 : .level = RAW_SEARCH_TRANS2,
193 : .data_level = RAW_SEARCH_DATA_NAME_INFO,
194 : .name_offset = offsetof(union smb_search_data,
195 : name_info.name.s),
196 : .resume_key_offset = offsetof(union smb_search_data,
197 : name_info.file_index),
198 : },
199 : {
200 : .name = "BOTH_DIRECTORY_INFO",
201 : .level = RAW_SEARCH_TRANS2,
202 : .data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO,
203 : .name_offset = offsetof(union smb_search_data,
204 : both_directory_info.name.s),
205 : .resume_key_offset = offsetof(union smb_search_data,
206 : both_directory_info.file_index),
207 : },
208 : {
209 : .name = "ID_FULL_DIRECTORY_INFO",
210 : .level = RAW_SEARCH_TRANS2,
211 : .data_level = RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO,
212 : .name_offset = offsetof(union smb_search_data,
213 : id_full_directory_info.name.s),
214 : .resume_key_offset = offsetof(union smb_search_data,
215 : id_full_directory_info.file_index),
216 : },
217 : {
218 : .name = "ID_BOTH_DIRECTORY_INFO",
219 : .level = RAW_SEARCH_TRANS2,
220 : .data_level = RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO,
221 : .name_offset = offsetof(union smb_search_data,
222 : id_both_directory_info.name.s),
223 : .resume_key_offset = offsetof(union smb_search_data,
224 : id_both_directory_info.file_index),
225 : },
226 : {
227 : .name = "UNIX_INFO",
228 : .level = RAW_SEARCH_TRANS2,
229 : .data_level = RAW_SEARCH_DATA_UNIX_INFO,
230 : .name_offset = offsetof(union smb_search_data,
231 : unix_info.name),
232 : .resume_key_offset = offsetof(union smb_search_data,
233 : unix_info.file_index),
234 : .capability_mask = CAP_UNIX
235 : },
236 : };
237 :
238 :
239 : /*
240 : return level name
241 : */
242 0 : static const char *level_name(enum smb_search_level level,
243 : enum smb_search_data_level data_level)
244 : {
245 : int i;
246 0 : for (i=0;i<ARRAY_SIZE(levels);i++) {
247 0 : if (level == levels[i].level &&
248 0 : data_level == levels[i].data_level) {
249 0 : return levels[i].name;
250 : }
251 : }
252 0 : return NULL;
253 : }
254 :
255 : /*
256 : extract the name from a smb_data structure and level
257 : */
258 268500 : static const char *extract_name(void *data, enum smb_search_level level,
259 : enum smb_search_data_level data_level)
260 : {
261 : int i;
262 1940545 : for (i=0;i<ARRAY_SIZE(levels);i++) {
263 3087792 : if (level == levels[i].level &&
264 1147247 : data_level == levels[i].data_level) {
265 268500 : return *(const char **)(levels[i].name_offset + (char *)data);
266 : }
267 : }
268 0 : return NULL;
269 : }
270 :
271 : /*
272 : extract the name from a smb_data structure and level
273 : */
274 49 : static uint32_t extract_resume_key(void *data, enum smb_search_level level,
275 : enum smb_search_data_level data_level)
276 : {
277 : int i;
278 364 : for (i=0;i<ARRAY_SIZE(levels);i++) {
279 581 : if (level == levels[i].level &&
280 217 : data_level == levels[i].data_level) {
281 49 : return *(uint32_t *)(levels[i].resume_key_offset + (char *)data);
282 : }
283 : }
284 0 : return 0;
285 : }
286 :
287 : /* find a level in the table by name */
288 70 : static union smb_search_data *find(const char *name)
289 : {
290 : int i;
291 538 : for (i=0;i<ARRAY_SIZE(levels);i++) {
292 1067 : if (NT_STATUS_IS_OK(levels[i].status) &&
293 532 : strcmp(levels[i].name, name) == 0) {
294 67 : return &levels[i].data;
295 : }
296 : }
297 3 : return NULL;
298 : }
299 :
300 : /*
301 : * Negotiate SMB1+POSIX.
302 : */
303 :
304 1 : static NTSTATUS setup_smb1_posix(struct torture_context *tctx,
305 : struct smbcli_state *cli_unix)
306 : {
307 : struct smb_trans2 tp;
308 : uint16_t setup;
309 : uint8_t data[12];
310 : uint8_t params[4];
311 1 : uint32_t cap = cli_unix->transport->negotiate.capabilities;
312 :
313 1 : if ((cap & CAP_UNIX) == 0) {
314 : /*
315 : * Server doesn't support SMB1+POSIX.
316 : * The caller will skip the UNIX info
317 : * level anyway.
318 : */
319 1 : torture_comment(tctx,
320 : "Server doesn't support SMB1+POSIX\n");
321 1 : return NT_STATUS_OK;
322 : }
323 :
324 : /* Setup POSIX on this connection. */
325 0 : SSVAL(data, 0, CIFS_UNIX_MAJOR_VERSION);
326 0 : SSVAL(data, 2, CIFS_UNIX_MINOR_VERSION);
327 0 : SBVAL(data,4,((uint64_t)(
328 : CIFS_UNIX_POSIX_ACLS_CAP|
329 : CIFS_UNIX_POSIX_PATHNAMES_CAP|
330 : CIFS_UNIX_FCNTL_LOCKS_CAP|
331 : CIFS_UNIX_EXTATTR_CAP|
332 : CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP)));
333 0 : setup = TRANSACT2_SETFSINFO;
334 0 : tp.in.max_setup = 0;
335 0 : tp.in.flags = 0;
336 0 : tp.in.timeout = 0;
337 0 : tp.in.setup_count = 1;
338 0 : tp.in.max_param = 0;
339 0 : tp.in.max_data = 0;
340 0 : tp.in.setup = &setup;
341 0 : tp.in.trans_name = NULL;
342 0 : SSVAL(params, 0, 0);
343 0 : SSVAL(params, 2, SMB_SET_CIFS_UNIX_INFO);
344 0 : tp.in.params = data_blob_talloc(tctx, params, 4);
345 0 : tp.in.data = data_blob_talloc(tctx, data, 12);
346 0 : return smb_raw_trans2(cli_unix->tree, tctx, &tp);
347 : }
348 :
349 : /*
350 : basic testing of all RAW_SEARCH_* calls using a single file
351 : */
352 1 : static bool test_one_file(struct torture_context *tctx,
353 : struct smbcli_state *cli,
354 : struct smbcli_state *cli_unix)
355 : {
356 1 : bool ret = true;
357 : int fnum;
358 1 : const char *fname = "torture_search.txt";
359 1 : const char *fname2 = "torture_search-NOTEXIST.txt";
360 : NTSTATUS status;
361 : int i;
362 : union smb_fileinfo all_info, alt_info, name_info, internal_info;
363 : bool all_info_supported, alt_info_supported, name_info_supported,
364 : internal_info_supported;
365 : union smb_search_data *s;
366 :
367 1 : status = setup_smb1_posix(tctx, cli_unix);
368 1 : if (!NT_STATUS_IS_OK(status)) {
369 0 : torture_result(tctx,
370 : TORTURE_FAIL,
371 : __location__"setup_smb1_posix() failed (%s)\n",
372 : nt_errstr(status));
373 0 : ret = false;
374 0 : goto done;
375 : }
376 :
377 1 : fnum = create_complex_file(cli, tctx, fname);
378 1 : if (fnum == -1) {
379 0 : torture_result(tctx,
380 : TORTURE_FAIL,
381 : __location__"ERROR: open of %s failed (%s)\n",
382 : fname,
383 : smbcli_errstr(cli->tree));
384 0 : ret = false;
385 0 : goto done;
386 : }
387 :
388 : /* call all the levels */
389 13 : for (i=0;i<ARRAY_SIZE(levels);i++) {
390 : NTSTATUS expected_status;
391 12 : uint32_t cap = cli->transport->negotiate.capabilities;
392 12 : struct smbcli_state *cli_search = cli;
393 :
394 12 : torture_comment(tctx, "Testing %s\n", levels[i].name);
395 :
396 12 : if (levels[i].data_level == RAW_SEARCH_DATA_UNIX_INFO) {
397 : /*
398 : * For an SMB1+POSIX info level, use the cli_unix
399 : * connection.
400 : */
401 1 : cli_search = cli_unix;
402 : }
403 :
404 12 : levels[i].status = torture_single_search(cli_search, tctx, fname,
405 : levels[i].level,
406 : levels[i].data_level,
407 : 0,
408 : &levels[i].data);
409 :
410 : /* see if this server claims to support this level */
411 12 : if (((cap & levels[i].capability_mask) != levels[i].capability_mask)
412 11 : || NT_STATUS_EQUAL(levels[i].status, NT_STATUS_NOT_SUPPORTED)) {
413 1 : printf("search level %s(%d) not supported by server\n",
414 1 : levels[i].name, (int)levels[i].level);
415 2 : continue;
416 : }
417 :
418 11 : if (!NT_STATUS_IS_OK(levels[i].status)) {
419 0 : torture_result(tctx,
420 : TORTURE_FAIL,
421 : __location__"search level %s(%d) failed - %s\n",
422 0 : levels[i].name, (int)levels[i].level,
423 : nt_errstr(levels[i].status));
424 0 : ret = false;
425 0 : continue;
426 : }
427 :
428 11 : status = torture_single_search(cli_search, tctx, fname2,
429 : levels[i].level,
430 : levels[i].data_level,
431 : 0,
432 : &levels[i].data);
433 :
434 11 : expected_status = NT_STATUS_NO_SUCH_FILE;
435 21 : if (levels[i].level == RAW_SEARCH_SEARCH ||
436 19 : levels[i].level == RAW_SEARCH_FFIRST ||
437 9 : levels[i].level == RAW_SEARCH_FUNIQUE) {
438 3 : expected_status = STATUS_NO_MORE_FILES;
439 : }
440 11 : if (!NT_STATUS_EQUAL(status, expected_status)) {
441 0 : torture_result(tctx,
442 : TORTURE_FAIL,
443 : __location__"search level %s(%d) should fail with %s - %s\n",
444 0 : levels[i].name, (int)levels[i].level,
445 : nt_errstr(expected_status),
446 : nt_errstr(status));
447 0 : ret = false;
448 : }
449 : }
450 :
451 : /* get the all_info file into to check against */
452 1 : all_info.generic.level = RAW_FILEINFO_ALL_INFO;
453 1 : all_info.generic.in.file.path = fname;
454 1 : status = smb_raw_pathinfo(cli->tree, tctx, &all_info);
455 1 : CHECK_STATUS_LEVEL(tctx, status, "RAW_FILEINFO_ALL_INFO",
456 : all_info_supported);
457 :
458 1 : alt_info.generic.level = RAW_FILEINFO_ALT_NAME_INFO;
459 1 : alt_info.generic.in.file.path = fname;
460 1 : status = smb_raw_pathinfo(cli->tree, tctx, &alt_info);
461 1 : CHECK_STATUS_LEVEL(tctx, status, "RAW_FILEINFO_ALT_NAME_INFO",
462 : alt_info_supported);
463 :
464 1 : internal_info.generic.level = RAW_FILEINFO_INTERNAL_INFORMATION;
465 1 : internal_info.generic.in.file.path = fname;
466 1 : status = smb_raw_pathinfo(cli->tree, tctx, &internal_info);
467 1 : CHECK_STATUS_LEVEL(tctx, status, "RAW_FILEINFO_INTERNAL_INFORMATION",
468 : internal_info_supported);
469 :
470 1 : name_info.generic.level = RAW_FILEINFO_NAME_INFO;
471 1 : name_info.generic.in.file.path = fname;
472 1 : status = smb_raw_pathinfo(cli->tree, tctx, &name_info);
473 1 : CHECK_STATUS_LEVEL(tctx, status, "RAW_FILEINFO_NAME_INFO",
474 : name_info_supported);
475 :
476 : #define CHECK_VAL(name, sname1, field1, v, sname2, field2) do { \
477 : s = find(name); \
478 : if (s) { \
479 : if ((s->sname1.field1) != (v.sname2.out.field2)) { \
480 : torture_result(tctx,\
481 : TORTURE_FAIL,\
482 : "(%s) %s/%s [0x%x] != %s/%s [0x%x]\n", \
483 : __location__, \
484 : #sname1, #field1, (int)s->sname1.field1, \
485 : #sname2, #field2, (int)v.sname2.out.field2); \
486 : ret = false; \
487 : } \
488 : }} while (0)
489 :
490 : #define CHECK_TIME(name, sname1, field1, v, sname2, field2) do { \
491 : s = find(name); \
492 : if (s) { \
493 : if (s->sname1.field1 != (~1 & nt_time_to_unix(v.sname2.out.field2))) { \
494 : torture_result(tctx,\
495 : TORTURE_FAIL,\
496 : "(%s) %s/%s [%s] != %s/%s [%s]\n", \
497 : __location__, \
498 : #sname1, #field1, timestring(tctx, s->sname1.field1), \
499 : #sname2, #field2, nt_time_string(tctx, v.sname2.out.field2)); \
500 : ret = false; \
501 : } \
502 : }} while (0)
503 :
504 : #define CHECK_NTTIME(name, sname1, field1, v, sname2, field2) do { \
505 : s = find(name); \
506 : if (s) { \
507 : if (s->sname1.field1 != v.sname2.out.field2) { \
508 : torture_result(tctx,\
509 : TORTURE_FAIL,\
510 : "(%s) %s/%s [%s] != %s/%s [%s]\n", \
511 : __location__, \
512 : #sname1, #field1, nt_time_string(tctx, s->sname1.field1), \
513 : #sname2, #field2, nt_time_string(tctx, v.sname2.out.field2)); \
514 : ret = false; \
515 : } \
516 : }} while (0)
517 :
518 : #define CHECK_STR(name, sname1, field1, v, sname2, field2) do { \
519 : s = find(name); \
520 : if (s) { \
521 : if (!s->sname1.field1 || strcmp(s->sname1.field1, v.sname2.out.field2.s)) { \
522 : torture_result(tctx,\
523 : TORTURE_FAIL,\
524 : "(%s) %s/%s [%s] != %s/%s [%s]\n", \
525 : __location__, \
526 : #sname1, #field1, s->sname1.field1, \
527 : #sname2, #field2, v.sname2.out.field2.s); \
528 : ret = false; \
529 : } \
530 : }} while (0)
531 :
532 : #define CHECK_WSTR(name, sname1, field1, v, sname2, field2, flags) do { \
533 : s = find(name); \
534 : if (s) { \
535 : if (!s->sname1.field1.s || \
536 : strcmp(s->sname1.field1.s, v.sname2.out.field2.s) || \
537 : wire_bad_flags(&s->sname1.field1, flags, cli->transport)) { \
538 : torture_result(tctx,\
539 : TORTURE_FAIL,\
540 : "(%s) %s/%s [%s] != %s/%s [%s]\n", \
541 : __location__, \
542 : #sname1, #field1, s->sname1.field1.s, \
543 : #sname2, #field2, v.sname2.out.field2.s); \
544 : ret = false; \
545 : } \
546 : }} while (0)
547 :
548 : #define CHECK_NAME(name, sname1, field1, fname, flags) do { \
549 : s = find(name); \
550 : if (s) { \
551 : if (!s->sname1.field1.s || \
552 : strcmp(s->sname1.field1.s, fname) || \
553 : wire_bad_flags(&s->sname1.field1, flags, cli->transport)) { \
554 : torture_result(tctx,\
555 : TORTURE_FAIL,\
556 : "(%s) %s/%s [%s] != %s\n", \
557 : __location__, \
558 : #sname1, #field1, s->sname1.field1.s, \
559 : fname); \
560 : ret = false; \
561 : } \
562 : }} while (0)
563 :
564 : #define CHECK_UNIX_NAME(name, sname1, field1, fname, flags) do { \
565 : s = find(name); \
566 : if (s) { \
567 : if (!s->sname1.field1 || \
568 : strcmp(s->sname1.field1, fname)) { \
569 : torture_result(tctx,\
570 : TORTURE_FAIL,\
571 : "(%s) %s/%s [%s] != %s\n", \
572 : __location__, \
573 : #sname1, #field1, s->sname1.field1, \
574 : fname); \
575 : ret = false; \
576 : } \
577 : }} while (0)
578 :
579 : /* check that all the results are as expected */
580 1 : CHECK_VAL("SEARCH", search, attrib, all_info, all_info, attrib&0xFFF);
581 1 : CHECK_VAL("STANDARD", standard, attrib, all_info, all_info, attrib&0xFFF);
582 1 : CHECK_VAL("EA_SIZE", ea_size, attrib, all_info, all_info, attrib&0xFFF);
583 1 : CHECK_VAL("DIRECTORY_INFO", directory_info, attrib, all_info, all_info, attrib);
584 1 : CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, attrib, all_info, all_info, attrib);
585 1 : CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, attrib, all_info, all_info, attrib);
586 1 : CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, attrib, all_info, all_info, attrib);
587 1 : CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, attrib, all_info, all_info, attrib);
588 :
589 1 : CHECK_TIME("SEARCH", search, write_time, all_info, all_info, write_time);
590 1 : CHECK_TIME("STANDARD", standard, write_time, all_info, all_info, write_time);
591 1 : CHECK_TIME("EA_SIZE", ea_size, write_time, all_info, all_info, write_time);
592 1 : CHECK_TIME("STANDARD", standard, create_time, all_info, all_info, create_time);
593 1 : CHECK_TIME("EA_SIZE", ea_size, create_time, all_info, all_info, create_time);
594 1 : CHECK_TIME("STANDARD", standard, access_time, all_info, all_info, access_time);
595 1 : CHECK_TIME("EA_SIZE", ea_size, access_time, all_info, all_info, access_time);
596 :
597 1 : CHECK_NTTIME("DIRECTORY_INFO", directory_info, write_time, all_info, all_info, write_time);
598 1 : CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, write_time, all_info, all_info, write_time);
599 1 : CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, write_time, all_info, all_info, write_time);
600 1 : CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, write_time, all_info, all_info, write_time);
601 1 : CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, write_time, all_info, all_info, write_time);
602 :
603 1 : CHECK_NTTIME("DIRECTORY_INFO", directory_info, create_time, all_info, all_info, create_time);
604 1 : CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, create_time, all_info, all_info, create_time);
605 1 : CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, create_time, all_info, all_info, create_time);
606 1 : CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, create_time, all_info, all_info, create_time);
607 1 : CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, create_time, all_info, all_info, create_time);
608 :
609 1 : CHECK_NTTIME("DIRECTORY_INFO", directory_info, access_time, all_info, all_info, access_time);
610 1 : CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, access_time, all_info, all_info, access_time);
611 1 : CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, access_time, all_info, all_info, access_time);
612 1 : CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, access_time, all_info, all_info, access_time);
613 1 : CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, access_time, all_info, all_info, access_time);
614 :
615 1 : CHECK_NTTIME("DIRECTORY_INFO", directory_info, change_time, all_info, all_info, change_time);
616 1 : CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, change_time, all_info, all_info, change_time);
617 1 : CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, change_time, all_info, all_info, change_time);
618 1 : CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, change_time, all_info, all_info, change_time);
619 1 : CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, change_time, all_info, all_info, change_time);
620 :
621 1 : CHECK_VAL("SEARCH", search, size, all_info, all_info, size);
622 1 : CHECK_VAL("STANDARD", standard, size, all_info, all_info, size);
623 1 : CHECK_VAL("EA_SIZE", ea_size, size, all_info, all_info, size);
624 1 : CHECK_VAL("DIRECTORY_INFO", directory_info, size, all_info, all_info, size);
625 1 : CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, size, all_info, all_info, size);
626 1 : CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, size, all_info, all_info, size);
627 1 : CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, size, all_info, all_info, size);
628 1 : CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, size, all_info, all_info, size);
629 1 : CHECK_VAL("UNIX_INFO", unix_info, size, all_info, all_info, size);
630 :
631 1 : CHECK_VAL("STANDARD", standard, alloc_size, all_info, all_info, alloc_size);
632 1 : CHECK_VAL("EA_SIZE", ea_size, alloc_size, all_info, all_info, alloc_size);
633 1 : CHECK_VAL("DIRECTORY_INFO", directory_info, alloc_size, all_info, all_info, alloc_size);
634 1 : CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, alloc_size, all_info, all_info, alloc_size);
635 1 : CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, alloc_size, all_info, all_info, alloc_size);
636 1 : CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, alloc_size, all_info, all_info, alloc_size);
637 1 : CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, alloc_size, all_info, all_info, alloc_size);
638 1 : CHECK_VAL("UNIX_INFO", unix_info, alloc_size, all_info, all_info, alloc_size);
639 :
640 1 : CHECK_VAL("EA_SIZE", ea_size, ea_size, all_info, all_info, ea_size);
641 1 : CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, ea_size, all_info, all_info, ea_size);
642 1 : CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, ea_size, all_info, all_info, ea_size);
643 1 : CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, ea_size, all_info, all_info, ea_size);
644 1 : CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, ea_size, all_info, all_info, ea_size);
645 :
646 1 : if (alt_info_supported) {
647 1 : CHECK_STR("SEARCH", search, name, alt_info, alt_name_info,
648 : fname);
649 1 : CHECK_WSTR("BOTH_DIRECTORY_INFO", both_directory_info,
650 : short_name, alt_info, alt_name_info, fname, STR_UNICODE);
651 : }
652 :
653 1 : CHECK_NAME("STANDARD", standard, name, fname, 0);
654 1 : CHECK_NAME("EA_SIZE", ea_size, name, fname, 0);
655 1 : CHECK_NAME("DIRECTORY_INFO", directory_info, name, fname, STR_TERMINATE_ASCII);
656 1 : CHECK_NAME("FULL_DIRECTORY_INFO", full_directory_info, name, fname, STR_TERMINATE_ASCII);
657 :
658 1 : if (name_info_supported) {
659 1 : CHECK_NAME("NAME_INFO", name_info, name, fname,
660 : STR_TERMINATE_ASCII);
661 : }
662 :
663 1 : CHECK_NAME("BOTH_DIRECTORY_INFO", both_directory_info, name, fname, STR_TERMINATE_ASCII);
664 1 : CHECK_NAME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, name, fname, STR_TERMINATE_ASCII);
665 1 : CHECK_NAME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, name, fname, STR_TERMINATE_ASCII);
666 1 : CHECK_UNIX_NAME("UNIX_INFO", unix_info, name, fname, STR_TERMINATE_ASCII);
667 :
668 1 : if (internal_info_supported) {
669 1 : CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info,
670 : file_id, internal_info, internal_information, file_id);
671 2 : CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info,
672 : file_id, internal_info, internal_information, file_id);
673 : }
674 :
675 2 : done:
676 1 : smb_raw_exit(cli->session);
677 1 : smbcli_unlink(cli->tree, fname);
678 :
679 1 : return ret;
680 : }
681 :
682 :
683 : struct multiple_result {
684 : TALLOC_CTX *tctx;
685 : int count;
686 : union smb_search_data *list;
687 : };
688 :
689 : /*
690 : callback function for multiple_search
691 : */
692 32427 : static bool multiple_search_callback(void *private_data, const union smb_search_data *file)
693 : {
694 32427 : struct multiple_result *data = (struct multiple_result *)private_data;
695 :
696 :
697 32427 : data->count++;
698 32427 : data->list = talloc_realloc(data->tctx,
699 : data->list,
700 : union smb_search_data,
701 : data->count);
702 :
703 32427 : data->list[data->count-1] = *file;
704 :
705 32427 : return true;
706 : }
707 :
708 : enum continue_type {CONT_FLAGS, CONT_NAME, CONT_RESUME_KEY};
709 :
710 : /*
711 : do a single file (non-wildcard) search
712 : */
713 23 : static NTSTATUS multiple_search(struct smbcli_state *cli,
714 : TALLOC_CTX *tctx,
715 : const char *pattern,
716 : enum smb_search_data_level data_level,
717 : enum continue_type cont_type,
718 : void *data)
719 : {
720 : union smb_search_first io;
721 : union smb_search_next io2;
722 : NTSTATUS status;
723 23 : const int per_search = 100;
724 23 : struct multiple_result *result = (struct multiple_result *)data;
725 :
726 23 : if (data_level == RAW_SEARCH_DATA_SEARCH) {
727 1 : io.search_first.level = RAW_SEARCH_SEARCH;
728 1 : io.search_first.data_level = RAW_SEARCH_DATA_SEARCH;
729 1 : io.search_first.in.max_count = per_search;
730 1 : io.search_first.in.search_attrib = 0;
731 1 : io.search_first.in.pattern = pattern;
732 : } else {
733 22 : io.t2ffirst.level = RAW_SEARCH_TRANS2;
734 22 : io.t2ffirst.data_level = data_level;
735 22 : io.t2ffirst.in.search_attrib = 0;
736 22 : io.t2ffirst.in.max_count = per_search;
737 22 : io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE_IF_END;
738 22 : io.t2ffirst.in.storage_type = 0;
739 22 : io.t2ffirst.in.pattern = pattern;
740 22 : if (cont_type == CONT_RESUME_KEY) {
741 7 : io.t2ffirst.in.flags |= FLAG_TRANS2_FIND_REQUIRE_RESUME |
742 : FLAG_TRANS2_FIND_BACKUP_INTENT;
743 : }
744 : }
745 :
746 23 : status = smb_raw_search_first(cli->tree, tctx,
747 : &io, data, multiple_search_callback);
748 :
749 :
750 184 : while (NT_STATUS_IS_OK(status)) {
751 161 : if (data_level == RAW_SEARCH_DATA_SEARCH) {
752 7 : io2.search_next.level = RAW_SEARCH_SEARCH;
753 7 : io2.search_next.data_level = RAW_SEARCH_DATA_SEARCH;
754 7 : io2.search_next.in.max_count = per_search;
755 7 : io2.search_next.in.search_attrib = 0;
756 7 : io2.search_next.in.id = result->list[result->count-1].search.id;
757 : } else {
758 154 : io2.t2fnext.level = RAW_SEARCH_TRANS2;
759 154 : io2.t2fnext.data_level = data_level;
760 154 : io2.t2fnext.in.handle = io.t2ffirst.out.handle;
761 154 : io2.t2fnext.in.max_count = per_search;
762 154 : io2.t2fnext.in.resume_key = 0;
763 154 : io2.t2fnext.in.flags = FLAG_TRANS2_FIND_CLOSE_IF_END;
764 154 : io2.t2fnext.in.last_name = "";
765 154 : switch (cont_type) {
766 49 : case CONT_RESUME_KEY:
767 49 : io2.t2fnext.in.resume_key = extract_resume_key(&result->list[result->count-1],
768 : io2.t2fnext.level, io2.t2fnext.data_level);
769 49 : if (io2.t2fnext.in.resume_key == 0) {
770 0 : printf("Server does not support resume by key for level %s\n",
771 : level_name(io2.t2fnext.level, io2.t2fnext.data_level));
772 0 : return NT_STATUS_NOT_SUPPORTED;
773 : }
774 49 : io2.t2fnext.in.flags |= FLAG_TRANS2_FIND_REQUIRE_RESUME |
775 : FLAG_TRANS2_FIND_BACKUP_INTENT;
776 49 : break;
777 56 : case CONT_NAME:
778 56 : io2.t2fnext.in.last_name = extract_name(&result->list[result->count-1],
779 : io2.t2fnext.level, io2.t2fnext.data_level);
780 56 : break;
781 49 : case CONT_FLAGS:
782 49 : io2.t2fnext.in.flags |= FLAG_TRANS2_FIND_CONTINUE;
783 49 : break;
784 : }
785 : }
786 :
787 161 : status = smb_raw_search_next(cli->tree, tctx,
788 : &io2, data, multiple_search_callback);
789 161 : if (!NT_STATUS_IS_OK(status)) {
790 0 : break;
791 : }
792 161 : if (data_level == RAW_SEARCH_DATA_SEARCH) {
793 7 : if (io2.search_next.out.count == 0) {
794 1 : break;
795 : }
796 286 : } else if (io2.t2fnext.out.count == 0 ||
797 132 : io2.t2fnext.out.end_of_search) {
798 : break;
799 : }
800 : }
801 :
802 23 : return status;
803 : }
804 :
805 : #define CHECK_STATUS(status, correct) torture_assert_ntstatus_equal(tctx, status, correct, "incorrect status")
806 :
807 : #define CHECK_VALUE(v, correct) torture_assert_int_equal(tctx, (v), (correct), "incorrect value");
808 :
809 : #define CHECK_STRING(v, correct) torture_assert_casestr_equal(tctx, v, correct, "incorrect value");
810 :
811 :
812 : static enum smb_search_data_level compare_data_level;
813 :
814 126522 : static int search_compare(union smb_search_data *d1, union smb_search_data *d2)
815 : {
816 : const char *s1, *s2;
817 : enum smb_search_level level;
818 :
819 126522 : if (compare_data_level == RAW_SEARCH_DATA_SEARCH) {
820 5751 : level = RAW_SEARCH_SEARCH;
821 : } else {
822 120771 : level = RAW_SEARCH_TRANS2;
823 : }
824 :
825 126522 : s1 = extract_name(d1, level, compare_data_level);
826 126522 : s2 = extract_name(d2, level, compare_data_level);
827 126522 : return strcmp_safe(s1, s2);
828 : }
829 :
830 :
831 :
832 : /*
833 : basic testing of search calls using many files
834 : */
835 1 : static bool test_many_files(struct torture_context *tctx,
836 : struct smbcli_state *cli)
837 : {
838 1 : const int num_files = 700;
839 : int i, fnum, t;
840 : char *fname;
841 1 : bool ret = true;
842 : NTSTATUS status;
843 : struct multiple_result result;
844 : struct {
845 : const char *name;
846 : const char *cont_name;
847 : enum smb_search_data_level data_level;
848 : enum continue_type cont_type;
849 1 : } search_types[] = {
850 : {"SEARCH", "ID", RAW_SEARCH_DATA_SEARCH, CONT_RESUME_KEY},
851 : {"BOTH_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO, CONT_NAME},
852 : {"BOTH_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO, CONT_FLAGS},
853 : {"BOTH_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO, CONT_RESUME_KEY},
854 : {"STANDARD", "FLAGS", RAW_SEARCH_DATA_STANDARD, CONT_FLAGS},
855 : {"STANDARD", "KEY", RAW_SEARCH_DATA_STANDARD, CONT_RESUME_KEY},
856 : {"STANDARD", "NAME", RAW_SEARCH_DATA_STANDARD, CONT_NAME},
857 : {"EA_SIZE", "FLAGS", RAW_SEARCH_DATA_EA_SIZE, CONT_FLAGS},
858 : {"EA_SIZE", "KEY", RAW_SEARCH_DATA_EA_SIZE, CONT_RESUME_KEY},
859 : {"EA_SIZE", "NAME", RAW_SEARCH_DATA_EA_SIZE, CONT_NAME},
860 : {"DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_DIRECTORY_INFO, CONT_FLAGS},
861 : {"DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_DIRECTORY_INFO, CONT_RESUME_KEY},
862 : {"DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_DIRECTORY_INFO, CONT_NAME},
863 : {"FULL_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_FULL_DIRECTORY_INFO, CONT_FLAGS},
864 : {"FULL_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_FULL_DIRECTORY_INFO, CONT_RESUME_KEY},
865 : {"FULL_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_FULL_DIRECTORY_INFO, CONT_NAME},
866 : {"ID_FULL_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO, CONT_FLAGS},
867 : {"ID_FULL_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO, CONT_RESUME_KEY},
868 : {"ID_FULL_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO, CONT_NAME},
869 : {"ID_BOTH_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO, CONT_NAME},
870 : {"ID_BOTH_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO, CONT_FLAGS},
871 : {"ID_BOTH_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO, CONT_RESUME_KEY}
872 : };
873 :
874 1 : torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
875 :
876 1 : torture_comment(tctx, "Testing with %d files\n", num_files);
877 :
878 701 : for (i=0;i<num_files;i++) {
879 700 : fname = talloc_asprintf(cli, BASEDIR "\\t%03d-%d.txt", i, i);
880 700 : fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
881 700 : torture_assert(tctx, fnum != -1, "Failed to create");
882 700 : talloc_free(fname);
883 700 : smbcli_close(cli->tree, fnum);
884 : }
885 :
886 :
887 23 : for (t=0;t<ARRAY_SIZE(search_types);t++) {
888 22 : ZERO_STRUCT(result);
889 :
890 30 : if ((search_types[t].cont_type == CONT_RESUME_KEY) &&
891 15 : (search_types[t].data_level != RAW_SEARCH_DATA_SEARCH) &&
892 7 : !torture_setting_bool(tctx, "resume_key_support", true)) {
893 0 : torture_comment(tctx,
894 : "SKIP: Continue %s via %s\n",
895 : search_types[t].name, search_types[t].cont_name);
896 0 : continue;
897 : }
898 :
899 22 : result.tctx = talloc_new(tctx);
900 :
901 22 : torture_comment(tctx,
902 : "Continue %s via %s\n", search_types[t].name, search_types[t].cont_name);
903 :
904 22 : status = multiple_search(cli, tctx, BASEDIR "\\*.*",
905 : search_types[t].data_level,
906 : search_types[t].cont_type,
907 : &result);
908 22 : if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
909 0 : torture_warning(tctx, "search level %s not supported "
910 : "by server",
911 : search_types[t].name);
912 0 : continue;
913 : }
914 22 : torture_assert_ntstatus_ok(tctx, status, "search failed");
915 22 : CHECK_VALUE(result.count, num_files);
916 :
917 22 : compare_data_level = search_types[t].data_level;
918 :
919 22 : TYPESAFE_QSORT(result.list, result.count, search_compare);
920 :
921 15422 : for (i=0;i<result.count;i++) {
922 : const char *s;
923 : enum smb_search_level level;
924 15400 : if (compare_data_level == RAW_SEARCH_DATA_SEARCH) {
925 700 : level = RAW_SEARCH_SEARCH;
926 : } else {
927 14700 : level = RAW_SEARCH_TRANS2;
928 : }
929 15400 : s = extract_name(&result.list[i], level, compare_data_level);
930 15400 : fname = talloc_asprintf(cli, "t%03d-%d.txt", i, i);
931 15400 : torture_assert_str_equal(tctx, fname, s, "Incorrect name");
932 15400 : talloc_free(fname);
933 : }
934 22 : talloc_free(result.tctx);
935 : }
936 :
937 1 : smb_raw_exit(cli->session);
938 1 : smbcli_deltree(cli->tree, BASEDIR);
939 :
940 1 : return ret;
941 : }
942 :
943 : /*
944 : check a individual file result
945 : */
946 10 : static bool check_result(struct multiple_result *result, const char *name, bool exist, uint32_t attrib)
947 : {
948 : int i;
949 141 : for (i=0;i<result->count;i++) {
950 137 : if (strcmp(name, result->list[i].both_directory_info.name.s) == 0) break;
951 : }
952 10 : if (i == result->count) {
953 4 : if (exist) {
954 0 : printf("failed: '%s' should exist with attribute %s\n",
955 0 : name, attrib_string(result->list, attrib));
956 0 : return false;
957 : }
958 4 : return true;
959 : }
960 :
961 6 : if (!exist) {
962 0 : printf("failed: '%s' should NOT exist (has attribute %s)\n",
963 0 : name, attrib_string(result->list, result->list[i].both_directory_info.attrib));
964 0 : return false;
965 : }
966 :
967 6 : if ((result->list[i].both_directory_info.attrib&0xFFF) != attrib) {
968 0 : printf("failed: '%s' should have attribute 0x%x (has 0x%x)\n",
969 : name,
970 0 : attrib, result->list[i].both_directory_info.attrib);
971 0 : return false;
972 : }
973 6 : return true;
974 : }
975 :
976 : /*
977 : test what happens when the directory is modified during a search
978 : */
979 1 : static bool test_modify_search(struct torture_context *tctx,
980 : struct smbcli_state *cli)
981 : {
982 1 : const int num_files = 20;
983 : int i, fnum;
984 : char *fname;
985 1 : bool ret = true;
986 : NTSTATUS status;
987 : struct multiple_result result;
988 : union smb_search_first io;
989 : union smb_search_next io2;
990 : union smb_setfileinfo sfinfo;
991 :
992 1 : torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
993 :
994 1 : printf("Creating %d files\n", num_files);
995 :
996 21 : for (i=num_files-1;i>=0;i--) {
997 20 : fname = talloc_asprintf(cli, BASEDIR "\\t%03d-%d.txt", i, i);
998 20 : fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
999 20 : if (fnum == -1) {
1000 0 : printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
1001 0 : ret = false;
1002 0 : goto done;
1003 : }
1004 20 : talloc_free(fname);
1005 20 : smbcli_close(cli->tree, fnum);
1006 : }
1007 :
1008 1 : printf("pulling the first file\n");
1009 1 : ZERO_STRUCT(result);
1010 1 : result.tctx = talloc_new(tctx);
1011 :
1012 1 : io.t2ffirst.level = RAW_SEARCH_TRANS2;
1013 1 : io.t2ffirst.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
1014 1 : io.t2ffirst.in.search_attrib = 0;
1015 1 : io.t2ffirst.in.max_count = 0;
1016 1 : io.t2ffirst.in.flags = 0;
1017 1 : io.t2ffirst.in.storage_type = 0;
1018 1 : io.t2ffirst.in.pattern = BASEDIR "\\*.*";
1019 :
1020 1 : status = smb_raw_search_first(cli->tree, tctx,
1021 : &io, &result, multiple_search_callback);
1022 1 : CHECK_STATUS(status, NT_STATUS_OK);
1023 1 : CHECK_VALUE(result.count, 1);
1024 :
1025 1 : printf("pulling the second file\n");
1026 1 : io2.t2fnext.level = RAW_SEARCH_TRANS2;
1027 1 : io2.t2fnext.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
1028 1 : io2.t2fnext.in.handle = io.t2ffirst.out.handle;
1029 1 : io2.t2fnext.in.max_count = 1;
1030 1 : io2.t2fnext.in.resume_key = 0;
1031 1 : io2.t2fnext.in.flags = 0;
1032 1 : io2.t2fnext.in.last_name = result.list[result.count-1].both_directory_info.name.s;
1033 :
1034 1 : status = smb_raw_search_next(cli->tree, tctx,
1035 : &io2, &result, multiple_search_callback);
1036 1 : CHECK_STATUS(status, NT_STATUS_OK);
1037 1 : CHECK_VALUE(result.count, 2);
1038 :
1039 1 : result.count = 0;
1040 :
1041 1 : printf("Changing attributes and deleting\n");
1042 1 : smbcli_open(cli->tree, BASEDIR "\\T003-03.txt.2", O_CREAT|O_RDWR, DENY_NONE);
1043 1 : smbcli_open(cli->tree, BASEDIR "\\T013-13.txt.2", O_CREAT|O_RDWR, DENY_NONE);
1044 1 : fnum = create_complex_file(cli, tctx, BASEDIR "\\T013-13.txt.3");
1045 1 : smbcli_unlink(cli->tree, BASEDIR "\\T014-14.txt");
1046 1 : torture_set_file_attribute(cli->tree, BASEDIR "\\T015-15.txt", FILE_ATTRIBUTE_HIDDEN);
1047 1 : torture_set_file_attribute(cli->tree, BASEDIR "\\T016-16.txt", FILE_ATTRIBUTE_NORMAL);
1048 1 : torture_set_file_attribute(cli->tree, BASEDIR "\\T017-17.txt", FILE_ATTRIBUTE_SYSTEM);
1049 1 : torture_set_file_attribute(cli->tree, BASEDIR "\\T018-18.txt", 0);
1050 1 : sfinfo.generic.level = RAW_SFILEINFO_DISPOSITION_INFORMATION;
1051 1 : sfinfo.generic.in.file.fnum = fnum;
1052 1 : sfinfo.disposition_info.in.delete_on_close = 1;
1053 1 : status = smb_raw_setfileinfo(cli->tree, &sfinfo);
1054 1 : CHECK_STATUS(status, NT_STATUS_OK);
1055 :
1056 1 : io2.t2fnext.level = RAW_SEARCH_TRANS2;
1057 1 : io2.t2fnext.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
1058 1 : io2.t2fnext.in.handle = io.t2ffirst.out.handle;
1059 1 : io2.t2fnext.in.max_count = num_files + 3;
1060 1 : io2.t2fnext.in.resume_key = 0;
1061 1 : io2.t2fnext.in.flags = 0;
1062 1 : io2.t2fnext.in.last_name = ".";
1063 :
1064 1 : status = smb_raw_search_next(cli->tree, tctx,
1065 : &io2, &result, multiple_search_callback);
1066 1 : CHECK_STATUS(status, NT_STATUS_OK);
1067 1 : CHECK_VALUE(result.count, 20);
1068 :
1069 1 : ret &= check_result(&result, "t009-9.txt", true, FILE_ATTRIBUTE_ARCHIVE);
1070 1 : ret &= check_result(&result, "t014-14.txt", false, 0);
1071 1 : ret &= check_result(&result, "t015-15.txt", false, 0);
1072 1 : ret &= check_result(&result, "t016-16.txt", true, FILE_ATTRIBUTE_NORMAL);
1073 1 : ret &= check_result(&result, "t017-17.txt", false, 0);
1074 1 : ret &= check_result(&result, "t018-18.txt", true, FILE_ATTRIBUTE_ARCHIVE);
1075 1 : ret &= check_result(&result, "t019-19.txt", true, FILE_ATTRIBUTE_ARCHIVE);
1076 1 : ret &= check_result(&result, "T013-13.txt.2", true, FILE_ATTRIBUTE_ARCHIVE);
1077 1 : ret &= check_result(&result, "T003-3.txt.2", false, 0);
1078 1 : ret &= check_result(&result, "T013-13.txt.3", true, FILE_ATTRIBUTE_ARCHIVE);
1079 :
1080 1 : if (!ret) {
1081 0 : for (i=0;i<result.count;i++) {
1082 0 : printf("%s %s (0x%x)\n",
1083 0 : result.list[i].both_directory_info.name.s,
1084 0 : attrib_string(tctx, result.list[i].both_directory_info.attrib),
1085 0 : result.list[i].both_directory_info.attrib);
1086 : }
1087 : }
1088 :
1089 1 : done:
1090 1 : smb_raw_exit(cli->session);
1091 1 : smbcli_deltree(cli->tree, BASEDIR);
1092 :
1093 1 : return ret;
1094 : }
1095 :
1096 :
1097 : /*
1098 : testing if directories always come back sorted
1099 : */
1100 1 : static bool test_sorted(struct torture_context *tctx, struct smbcli_state *cli)
1101 : {
1102 1 : const int num_files = 700;
1103 : int i, fnum;
1104 : char *fname;
1105 1 : bool ret = true;
1106 : NTSTATUS status;
1107 : struct multiple_result result;
1108 :
1109 1 : torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1110 :
1111 1 : printf("Creating %d files\n", num_files);
1112 :
1113 701 : for (i=0;i<num_files;i++) {
1114 700 : fname = talloc_asprintf(cli, BASEDIR "\\%s.txt", generate_random_str_list(tctx, 10, "abcdefgh"));
1115 700 : fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1116 700 : if (fnum == -1) {
1117 0 : printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
1118 0 : ret = false;
1119 0 : goto done;
1120 : }
1121 700 : talloc_free(fname);
1122 700 : smbcli_close(cli->tree, fnum);
1123 : }
1124 :
1125 :
1126 1 : ZERO_STRUCT(result);
1127 1 : result.tctx = tctx;
1128 :
1129 1 : status = multiple_search(cli, tctx, BASEDIR "\\*.*",
1130 : RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO,
1131 : CONT_NAME, &result);
1132 1 : CHECK_STATUS(status, NT_STATUS_OK);
1133 1 : CHECK_VALUE(result.count, num_files);
1134 :
1135 1 : for (i=0;i<num_files-1;i++) {
1136 : const char *name1, *name2;
1137 1 : name1 = result.list[i].both_directory_info.name.s;
1138 1 : name2 = result.list[i+1].both_directory_info.name.s;
1139 1 : if (strcasecmp_m(name1, name2) > 0) {
1140 1 : printf("non-alphabetical order at entry %d '%s' '%s'\n",
1141 : i, name1, name2);
1142 1 : printf("Server does not produce sorted directory listings (not an error)\n");
1143 1 : goto done;
1144 : }
1145 : }
1146 :
1147 0 : talloc_free(result.list);
1148 :
1149 1 : done:
1150 1 : smb_raw_exit(cli->session);
1151 1 : smbcli_deltree(cli->tree, BASEDIR);
1152 :
1153 1 : return ret;
1154 : }
1155 :
1156 :
1157 :
1158 : /*
1159 : basic testing of many old style search calls using separate dirs
1160 : */
1161 1 : static bool test_many_dirs(struct torture_context *tctx,
1162 : struct smbcli_state *cli)
1163 : {
1164 1 : const int num_dirs = 20;
1165 : int i, fnum, n;
1166 : char *fname, *dname;
1167 1 : bool ret = true;
1168 : NTSTATUS status;
1169 : union smb_search_data *file, *file2, *file3;
1170 :
1171 1 : if (!torture_setting_bool(tctx, "raw_search_search", true)) {
1172 0 : torture_comment(tctx, "Skipping these tests as the server "
1173 : "doesn't support old style search calls\n");
1174 0 : return true;
1175 : }
1176 1 : torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1177 :
1178 1 : printf("Creating %d dirs\n", num_dirs);
1179 :
1180 21 : for (i=0;i<num_dirs;i++) {
1181 20 : dname = talloc_asprintf(cli, BASEDIR "\\d%d", i);
1182 20 : status = smbcli_mkdir(cli->tree, dname);
1183 20 : if (!NT_STATUS_IS_OK(status)) {
1184 0 : printf("(%s) Failed to create %s - %s\n",
1185 : __location__, dname, nt_errstr(status));
1186 0 : ret = false;
1187 0 : goto done;
1188 : }
1189 :
1190 80 : for (n=0;n<3;n++) {
1191 60 : fname = talloc_asprintf(cli, BASEDIR "\\d%d\\f%d-%d.txt", i, i, n);
1192 60 : fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1193 60 : if (fnum == -1) {
1194 0 : printf("(%s) Failed to create %s - %s\n",
1195 : __location__, fname, smbcli_errstr(cli->tree));
1196 0 : ret = false;
1197 0 : goto done;
1198 : }
1199 60 : talloc_free(fname);
1200 60 : smbcli_close(cli->tree, fnum);
1201 : }
1202 :
1203 20 : talloc_free(dname);
1204 : }
1205 :
1206 1 : file = talloc_zero_array(tctx, union smb_search_data, num_dirs);
1207 1 : file2 = talloc_zero_array(tctx, union smb_search_data, num_dirs);
1208 1 : file3 = talloc_zero_array(tctx, union smb_search_data, num_dirs);
1209 :
1210 1 : printf("Search first on %d dirs\n", num_dirs);
1211 :
1212 42 : for (i=0;i<num_dirs;i++) {
1213 : union smb_search_first io;
1214 20 : io.search_first.level = RAW_SEARCH_SEARCH;
1215 20 : io.search_first.data_level = RAW_SEARCH_DATA_SEARCH;
1216 20 : io.search_first.in.max_count = 1;
1217 20 : io.search_first.in.search_attrib = 0;
1218 20 : io.search_first.in.pattern = talloc_asprintf(tctx, BASEDIR "\\d%d\\*.txt", i);
1219 20 : fname = talloc_asprintf(tctx, "f%d-", i);
1220 :
1221 20 : io.search_first.out.count = 0;
1222 :
1223 20 : status = smb_raw_search_first(cli->tree, tctx,
1224 20 : &io, (void *)&file[i], single_search_callback);
1225 20 : if (io.search_first.out.count != 1) {
1226 0 : printf("(%s) search first gave %d entries for dir %d - %s\n",
1227 0 : __location__, io.search_first.out.count, i, nt_errstr(status));
1228 0 : ret = false;
1229 0 : goto done;
1230 : }
1231 20 : CHECK_STATUS(status, NT_STATUS_OK);
1232 20 : if (strncasecmp(file[i].search.name, fname, strlen(fname)) != 0) {
1233 0 : printf("(%s) incorrect name '%s' expected '%s'[12].txt\n",
1234 0 : __location__, file[i].search.name, fname);
1235 0 : ret = false;
1236 0 : goto done;
1237 : }
1238 :
1239 20 : talloc_free(fname);
1240 : }
1241 :
1242 1 : printf("Search next on %d dirs\n", num_dirs);
1243 :
1244 42 : for (i=0;i<num_dirs;i++) {
1245 : union smb_search_next io2;
1246 :
1247 20 : io2.search_next.level = RAW_SEARCH_SEARCH;
1248 20 : io2.search_next.data_level = RAW_SEARCH_DATA_SEARCH;
1249 20 : io2.search_next.in.max_count = 1;
1250 20 : io2.search_next.in.search_attrib = 0;
1251 20 : io2.search_next.in.id = file[i].search.id;
1252 20 : fname = talloc_asprintf(tctx, "f%d-", i);
1253 :
1254 20 : io2.search_next.out.count = 0;
1255 :
1256 20 : status = smb_raw_search_next(cli->tree, tctx,
1257 20 : &io2, (void *)&file2[i], single_search_callback);
1258 20 : if (io2.search_next.out.count != 1) {
1259 0 : printf("(%s) search next gave %d entries for dir %d - %s\n",
1260 0 : __location__, io2.search_next.out.count, i, nt_errstr(status));
1261 0 : ret = false;
1262 0 : goto done;
1263 : }
1264 20 : CHECK_STATUS(status, NT_STATUS_OK);
1265 20 : if (strncasecmp(file2[i].search.name, fname, strlen(fname)) != 0) {
1266 0 : printf("(%s) incorrect name '%s' expected '%s'[12].txt\n",
1267 0 : __location__, file2[i].search.name, fname);
1268 0 : ret = false;
1269 0 : goto done;
1270 : }
1271 :
1272 20 : talloc_free(fname);
1273 : }
1274 :
1275 :
1276 1 : printf("Search next (rewind) on %d dirs\n", num_dirs);
1277 :
1278 42 : for (i=0;i<num_dirs;i++) {
1279 : union smb_search_next io2;
1280 :
1281 20 : io2.search_next.level = RAW_SEARCH_SEARCH;
1282 20 : io2.search_next.data_level = RAW_SEARCH_DATA_SEARCH;
1283 20 : io2.search_next.in.max_count = 1;
1284 20 : io2.search_next.in.search_attrib = 0;
1285 20 : io2.search_next.in.id = file[i].search.id;
1286 20 : fname = talloc_asprintf(tctx, "f%d-", i);
1287 20 : io2.search_next.out.count = 0;
1288 :
1289 20 : status = smb_raw_search_next(cli->tree, tctx,
1290 20 : &io2, (void *)&file3[i], single_search_callback);
1291 20 : if (io2.search_next.out.count != 1) {
1292 0 : printf("(%s) search next gave %d entries for dir %d - %s\n",
1293 0 : __location__, io2.search_next.out.count, i, nt_errstr(status));
1294 0 : ret = false;
1295 0 : goto done;
1296 : }
1297 20 : CHECK_STATUS(status, NT_STATUS_OK);
1298 :
1299 20 : if (strncasecmp(file3[i].search.name, file2[i].search.name, 3) != 0) {
1300 0 : printf("(%s) incorrect name '%s' on rewind at dir %d\n",
1301 0 : __location__, file2[i].search.name, i);
1302 0 : ret = false;
1303 0 : goto done;
1304 : }
1305 :
1306 40 : if (torture_setting_bool(tctx, "rewind_support", true) &&
1307 20 : strcmp(file3[i].search.name, file2[i].search.name) != 0) {
1308 0 : printf("(%s) server did not rewind - got '%s' expected '%s'\n",
1309 0 : __location__, file3[i].search.name, file2[i].search.name);
1310 0 : ret = false;
1311 0 : goto done;
1312 : }
1313 :
1314 20 : talloc_free(fname);
1315 : }
1316 :
1317 :
1318 1 : done:
1319 1 : smb_raw_exit(cli->session);
1320 1 : smbcli_deltree(cli->tree, BASEDIR);
1321 :
1322 1 : return ret;
1323 : }
1324 :
1325 :
1326 : /*
1327 : testing of OS/2 style delete
1328 : */
1329 1 : static bool test_os2_delete(struct torture_context *tctx,
1330 : struct smbcli_state *cli)
1331 : {
1332 1 : const int num_files = 700;
1333 1 : const int delete_count = 4;
1334 1 : int total_deleted = 0;
1335 : int i, fnum;
1336 : char *fname;
1337 1 : bool ret = true;
1338 : NTSTATUS status;
1339 : union smb_search_first io;
1340 : union smb_search_next io2;
1341 : struct multiple_result result;
1342 :
1343 1 : if (!torture_setting_bool(tctx, "search_ea_size", true)){
1344 0 : torture_comment(tctx,
1345 : "Server does not support RAW_SEARCH_EA_SIZE "
1346 : "level. Skipping this test\n");
1347 0 : return true;
1348 : }
1349 :
1350 1 : torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1351 :
1352 1 : printf("Testing OS/2 style delete on %d files\n", num_files);
1353 :
1354 701 : for (i=0;i<num_files;i++) {
1355 700 : fname = talloc_asprintf(cli, BASEDIR "\\file%u.txt", i);
1356 700 : fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1357 700 : if (fnum == -1) {
1358 0 : printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
1359 0 : ret = false;
1360 0 : goto done;
1361 : }
1362 700 : talloc_free(fname);
1363 700 : smbcli_close(cli->tree, fnum);
1364 : }
1365 :
1366 :
1367 1 : ZERO_STRUCT(result);
1368 1 : result.tctx = tctx;
1369 :
1370 1 : io.t2ffirst.level = RAW_SEARCH_TRANS2;
1371 1 : io.t2ffirst.data_level = RAW_SEARCH_DATA_EA_SIZE;
1372 1 : io.t2ffirst.in.search_attrib = 0;
1373 1 : io.t2ffirst.in.max_count = 100;
1374 1 : io.t2ffirst.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1375 1 : io.t2ffirst.in.storage_type = 0;
1376 1 : io.t2ffirst.in.pattern = BASEDIR "\\*";
1377 :
1378 1 : status = smb_raw_search_first(cli->tree, tctx,
1379 : &io, &result, multiple_search_callback);
1380 1 : CHECK_STATUS(status, NT_STATUS_OK);
1381 :
1382 5 : for (i=0;i<MIN(result.count, delete_count);i++) {
1383 4 : fname = talloc_asprintf(cli, BASEDIR "\\%s", result.list[i].ea_size.name.s);
1384 4 : status = smbcli_unlink(cli->tree, fname);
1385 4 : CHECK_STATUS(status, NT_STATUS_OK);
1386 4 : total_deleted++;
1387 4 : talloc_free(fname);
1388 : }
1389 :
1390 1 : io2.t2fnext.level = RAW_SEARCH_TRANS2;
1391 1 : io2.t2fnext.data_level = RAW_SEARCH_DATA_EA_SIZE;
1392 1 : io2.t2fnext.in.handle = io.t2ffirst.out.handle;
1393 1 : io2.t2fnext.in.max_count = 100;
1394 1 : io2.t2fnext.in.resume_key = result.list[i-1].ea_size.resume_key;
1395 1 : io2.t2fnext.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1396 1 : io2.t2fnext.in.last_name = result.list[i-1].ea_size.name.s;
1397 :
1398 : do {
1399 175 : ZERO_STRUCT(result);
1400 175 : result.tctx = tctx;
1401 :
1402 175 : status = smb_raw_search_next(cli->tree, tctx,
1403 : &io2, &result, multiple_search_callback);
1404 175 : if (!NT_STATUS_IS_OK(status)) {
1405 0 : break;
1406 : }
1407 :
1408 871 : for (i=0;i<MIN(result.count, delete_count);i++) {
1409 696 : fname = talloc_asprintf(cli, BASEDIR "\\%s", result.list[i].ea_size.name.s);
1410 696 : status = smbcli_unlink(cli->tree, fname);
1411 696 : CHECK_STATUS(status, NT_STATUS_OK);
1412 696 : total_deleted++;
1413 696 : talloc_free(fname);
1414 : }
1415 :
1416 175 : if (i>0) {
1417 174 : io2.t2fnext.in.resume_key = result.list[i-1].ea_size.resume_key;
1418 174 : io2.t2fnext.in.last_name = result.list[i-1].ea_size.name.s;
1419 : }
1420 175 : } while (NT_STATUS_IS_OK(status) && result.count != 0);
1421 :
1422 1 : CHECK_STATUS(status, NT_STATUS_OK);
1423 :
1424 1 : if (total_deleted != num_files) {
1425 0 : printf("error: deleted %d - expected to delete %d\n",
1426 : total_deleted, num_files);
1427 0 : ret = false;
1428 : }
1429 :
1430 2 : done:
1431 1 : smb_raw_exit(cli->session);
1432 1 : smbcli_deltree(cli->tree, BASEDIR);
1433 :
1434 1 : return ret;
1435 : }
1436 :
1437 :
1438 3 : static int ealist_cmp(union smb_search_data *r1, union smb_search_data *r2)
1439 : {
1440 3 : return strcmp(r1->ea_list.name.s, r2->ea_list.name.s);
1441 : }
1442 :
1443 : /*
1444 : testing of the rather strange ea_list level
1445 : */
1446 1 : static bool test_ea_list(struct torture_context *tctx,
1447 : struct smbcli_state *cli)
1448 : {
1449 : int fnum;
1450 1 : bool ret = true;
1451 : NTSTATUS status;
1452 : union smb_search_first io;
1453 : union smb_search_next nxt;
1454 : struct multiple_result result;
1455 : union smb_setfileinfo setfile;
1456 :
1457 1 : torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1458 :
1459 1 : printf("Testing RAW_SEARCH_EA_LIST level\n");
1460 :
1461 2 : if (!torture_setting_bool(tctx, "search_ea_support", true) ||
1462 1 : !torture_setting_bool(tctx, "ea_support", true)) {
1463 0 : printf("..skipped per target configuration.\n");
1464 0 : return true;
1465 : }
1466 :
1467 1 : fnum = smbcli_open(cli->tree, BASEDIR "\\file1.txt", O_CREAT|O_RDWR, DENY_NONE);
1468 1 : smbcli_close(cli->tree, fnum);
1469 :
1470 1 : fnum = smbcli_open(cli->tree, BASEDIR "\\file2.txt", O_CREAT|O_RDWR, DENY_NONE);
1471 1 : smbcli_close(cli->tree, fnum);
1472 :
1473 1 : fnum = smbcli_open(cli->tree, BASEDIR "\\file3.txt", O_CREAT|O_RDWR, DENY_NONE);
1474 1 : smbcli_close(cli->tree, fnum);
1475 :
1476 1 : setfile.generic.level = RAW_SFILEINFO_EA_SET;
1477 1 : setfile.generic.in.file.path = BASEDIR "\\file2.txt";
1478 1 : setfile.ea_set.in.num_eas = 2;
1479 1 : setfile.ea_set.in.eas = talloc_array(tctx, struct ea_struct, 2);
1480 1 : setfile.ea_set.in.eas[0].flags = 0;
1481 1 : setfile.ea_set.in.eas[0].name.s = "EA ONE";
1482 1 : setfile.ea_set.in.eas[0].value = data_blob_string_const("VALUE 1");
1483 1 : setfile.ea_set.in.eas[1].flags = 0;
1484 1 : setfile.ea_set.in.eas[1].name.s = "SECOND EA";
1485 1 : setfile.ea_set.in.eas[1].value = data_blob_string_const("Value Two");
1486 :
1487 1 : status = smb_raw_setpathinfo(cli->tree, &setfile);
1488 1 : CHECK_STATUS(status, NT_STATUS_OK);
1489 :
1490 1 : setfile.generic.in.file.path = BASEDIR "\\file3.txt";
1491 1 : status = smb_raw_setpathinfo(cli->tree, &setfile);
1492 1 : CHECK_STATUS(status, NT_STATUS_OK);
1493 :
1494 1 : ZERO_STRUCT(result);
1495 1 : result.tctx = tctx;
1496 :
1497 1 : io.t2ffirst.level = RAW_SEARCH_TRANS2;
1498 1 : io.t2ffirst.data_level = RAW_SEARCH_DATA_EA_LIST;
1499 1 : io.t2ffirst.in.search_attrib = 0;
1500 1 : io.t2ffirst.in.max_count = 2;
1501 1 : io.t2ffirst.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1502 1 : io.t2ffirst.in.storage_type = 0;
1503 1 : io.t2ffirst.in.pattern = BASEDIR "\\*";
1504 1 : io.t2ffirst.in.num_names = 2;
1505 1 : io.t2ffirst.in.ea_names = talloc_array(tctx, struct ea_name, 2);
1506 1 : io.t2ffirst.in.ea_names[0].name.s = "SECOND EA";
1507 1 : io.t2ffirst.in.ea_names[1].name.s = "THIRD EA";
1508 :
1509 1 : status = smb_raw_search_first(cli->tree, tctx,
1510 : &io, &result, multiple_search_callback);
1511 1 : CHECK_STATUS(status, NT_STATUS_OK);
1512 1 : CHECK_VALUE(result.count, 2);
1513 :
1514 1 : nxt.t2fnext.level = RAW_SEARCH_TRANS2;
1515 1 : nxt.t2fnext.data_level = RAW_SEARCH_DATA_EA_LIST;
1516 1 : nxt.t2fnext.in.handle = io.t2ffirst.out.handle;
1517 1 : nxt.t2fnext.in.max_count = 2;
1518 1 : nxt.t2fnext.in.resume_key = result.list[1].ea_list.resume_key;
1519 1 : nxt.t2fnext.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME | FLAG_TRANS2_FIND_CONTINUE;
1520 1 : nxt.t2fnext.in.last_name = result.list[1].ea_list.name.s;
1521 1 : nxt.t2fnext.in.num_names = 2;
1522 1 : nxt.t2fnext.in.ea_names = talloc_array(tctx, struct ea_name, 2);
1523 1 : nxt.t2fnext.in.ea_names[0].name.s = "SECOND EA";
1524 1 : nxt.t2fnext.in.ea_names[1].name.s = "THIRD EA";
1525 :
1526 1 : status = smb_raw_search_next(cli->tree, tctx,
1527 : &nxt, &result, multiple_search_callback);
1528 1 : CHECK_STATUS(status, NT_STATUS_OK);
1529 :
1530 : /* we have to sort the result as different servers can return directories
1531 : in different orders */
1532 1 : TYPESAFE_QSORT(result.list, result.count, ealist_cmp);
1533 :
1534 1 : CHECK_VALUE(result.count, 3);
1535 1 : CHECK_VALUE(result.list[0].ea_list.eas.num_eas, 2);
1536 1 : CHECK_STRING(result.list[0].ea_list.name.s, "file1.txt");
1537 1 : CHECK_STRING(result.list[0].ea_list.eas.eas[0].name.s, "SECOND EA");
1538 1 : CHECK_VALUE(result.list[0].ea_list.eas.eas[0].value.length, 0);
1539 1 : CHECK_STRING(result.list[0].ea_list.eas.eas[1].name.s, "THIRD EA");
1540 1 : CHECK_VALUE(result.list[0].ea_list.eas.eas[1].value.length, 0);
1541 :
1542 1 : CHECK_STRING(result.list[1].ea_list.name.s, "file2.txt");
1543 1 : CHECK_STRING(result.list[1].ea_list.eas.eas[0].name.s, "SECOND EA");
1544 1 : CHECK_VALUE(result.list[1].ea_list.eas.eas[0].value.length, 9);
1545 1 : CHECK_STRING((const char *)result.list[1].ea_list.eas.eas[0].value.data, "Value Two");
1546 1 : CHECK_STRING(result.list[1].ea_list.eas.eas[1].name.s, "THIRD EA");
1547 1 : CHECK_VALUE(result.list[1].ea_list.eas.eas[1].value.length, 0);
1548 :
1549 1 : CHECK_STRING(result.list[2].ea_list.name.s, "file3.txt");
1550 1 : CHECK_STRING(result.list[2].ea_list.eas.eas[0].name.s, "SECOND EA");
1551 1 : CHECK_VALUE(result.list[2].ea_list.eas.eas[0].value.length, 9);
1552 1 : CHECK_STRING((const char *)result.list[2].ea_list.eas.eas[0].value.data, "Value Two");
1553 1 : CHECK_STRING(result.list[2].ea_list.eas.eas[1].name.s, "THIRD EA");
1554 1 : CHECK_VALUE(result.list[2].ea_list.eas.eas[1].value.length, 0);
1555 :
1556 1 : smb_raw_exit(cli->session);
1557 1 : smbcli_deltree(cli->tree, BASEDIR);
1558 :
1559 1 : return ret;
1560 : }
1561 :
1562 : /*
1563 : Test the behavior of max count parameter in TRANS2_FIND_FIRST2 and
1564 : TRANS2_FIND_NEXT2 queries
1565 : */
1566 1 : static bool test_max_count(struct torture_context *tctx,
1567 : struct smbcli_state *cli)
1568 : {
1569 1 : const int num_files = 2;
1570 : int i, fnum;
1571 : char *fname;
1572 1 : bool ret = true;
1573 : NTSTATUS status;
1574 : struct multiple_result result;
1575 : union smb_search_first io;
1576 : union smb_search_next io2;
1577 :
1578 1 : torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1579 :
1580 1 : torture_comment(tctx, "Creating %d files\n", num_files);
1581 :
1582 3 : for (i=num_files-1;i>=0;i--) {
1583 2 : fname = talloc_asprintf(cli, BASEDIR "\\t%03d-%d.txt", i, i);
1584 2 : fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1585 2 : if (fnum == -1) {
1586 0 : torture_comment(tctx,
1587 : "Failed to create %s - %s\n",
1588 : fname, smbcli_errstr(cli->tree));
1589 0 : ret = false;
1590 0 : goto done;
1591 : }
1592 2 : talloc_free(fname);
1593 2 : smbcli_close(cli->tree, fnum);
1594 : }
1595 :
1596 1 : torture_comment(tctx, "Set max_count parameter to 0. "
1597 : "This should return 1 entry\n");
1598 1 : ZERO_STRUCT(result);
1599 1 : result.tctx = talloc_new(tctx);
1600 :
1601 1 : io.t2ffirst.level = RAW_SEARCH_TRANS2;
1602 1 : io.t2ffirst.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
1603 1 : io.t2ffirst.in.search_attrib = 0;
1604 1 : io.t2ffirst.in.max_count = 0;
1605 1 : io.t2ffirst.in.flags = 0;
1606 1 : io.t2ffirst.in.storage_type = 0;
1607 1 : io.t2ffirst.in.pattern = BASEDIR "\\*.*";
1608 :
1609 1 : status = smb_raw_search_first(cli->tree, tctx,
1610 : &io, &result, multiple_search_callback);
1611 1 : CHECK_STATUS(status, NT_STATUS_OK);
1612 1 : CHECK_VALUE(result.count, 1);
1613 :
1614 1 : torture_comment(tctx, "Set max_count to 1. This should also "
1615 : "return 1 entry\n");
1616 1 : io2.t2fnext.level = RAW_SEARCH_TRANS2;
1617 1 : io2.t2fnext.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
1618 1 : io2.t2fnext.in.handle = io.t2ffirst.out.handle;
1619 1 : io2.t2fnext.in.max_count = 1;
1620 1 : io2.t2fnext.in.resume_key = 0;
1621 1 : io2.t2fnext.in.flags = 0;
1622 1 : io2.t2fnext.in.last_name =
1623 1 : result.list[result.count-1].both_directory_info.name.s;
1624 :
1625 1 : status = smb_raw_search_next(cli->tree, tctx,
1626 : &io2, &result, multiple_search_callback);
1627 1 : CHECK_STATUS(status, NT_STATUS_OK);
1628 1 : CHECK_VALUE(result.count, 2);
1629 1 : done:
1630 1 : smb_raw_exit(cli->session);
1631 1 : smbcli_deltree(cli->tree, BASEDIR);
1632 :
1633 1 : return ret;
1634 : }
1635 :
1636 : /*
1637 : basic testing of all RAW_SEARCH_* calls using a single file
1638 : */
1639 964 : struct torture_suite *torture_raw_search(TALLOC_CTX *mem_ctx)
1640 : {
1641 964 : struct torture_suite *suite = torture_suite_create(mem_ctx, "search");
1642 :
1643 964 : torture_suite_add_2smb_test(suite, "one file search", test_one_file);
1644 964 : torture_suite_add_1smb_test(suite, "many files", test_many_files);
1645 964 : torture_suite_add_1smb_test(suite, "sorted", test_sorted);
1646 964 : torture_suite_add_1smb_test(suite, "modify search", test_modify_search);
1647 964 : torture_suite_add_1smb_test(suite, "many dirs", test_many_dirs);
1648 964 : torture_suite_add_1smb_test(suite, "os2 delete", test_os2_delete);
1649 964 : torture_suite_add_1smb_test(suite, "ea list", test_ea_list);
1650 964 : torture_suite_add_1smb_test(suite, "max count", test_max_count);
1651 :
1652 964 : return suite;
1653 : }
|