2 Unix SMB/CIFS implementation.
3 RAW_SEARCH_* individual test suite
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 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 "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"
31 #define BASEDIR "\\testsearch"
33 #define CHECK_STATUS_LEVEL(__tctx, __status, __level, __supp) \
35 if (NT_STATUS_EQUAL(__status, \
36 NT_STATUS_NOT_SUPPORTED) || \
37 NT_STATUS_EQUAL(__status, \
38 NT_STATUS_NOT_IMPLEMENTED)) { \
44 torture_assert_ntstatus_ok_goto(__tctx, \
45 __status, ret, done, #__level" failed"); \
47 torture_warning(__tctx, "(%s) Info " \
48 "level "#__level" is %s", \
49 __location__, nt_errstr(__status)); \
54 callback function for single_search
56 static bool single_search_callback(void *private_data, const union smb_search_data *file)
58 union smb_search_data *data = (union smb_search_data *)private_data;
66 do a single file (non-wildcard) search
68 NTSTATUS torture_single_search(struct smbcli_state *cli,
71 enum smb_search_level level,
72 enum smb_search_data_level data_level,
74 union smb_search_data *data)
76 union smb_search_first io;
77 union smb_search_close c;
81 case RAW_SEARCH_SEARCH:
82 case RAW_SEARCH_FFIRST:
83 case RAW_SEARCH_FUNIQUE:
84 io.search_first.level = level;
85 io.search_first.data_level = RAW_SEARCH_DATA_SEARCH;
86 io.search_first.in.max_count = 1;
87 io.search_first.in.search_attrib = attrib;
88 io.search_first.in.pattern = pattern;
91 case RAW_SEARCH_TRANS2:
92 io.t2ffirst.level = RAW_SEARCH_TRANS2;
93 io.t2ffirst.data_level = data_level;
94 io.t2ffirst.in.search_attrib = attrib;
95 io.t2ffirst.in.max_count = 1;
96 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE;
97 io.t2ffirst.in.storage_type = 0;
98 io.t2ffirst.in.pattern = pattern;
101 case RAW_SEARCH_SMB2:
102 return NT_STATUS_INVALID_LEVEL;
105 status = smb_raw_search_first(cli->tree, tctx,
106 &io, (void *)data, single_search_callback);
108 if (NT_STATUS_IS_OK(status) && level == RAW_SEARCH_FFIRST) {
109 c.fclose.level = RAW_FINDCLOSE_FCLOSE;
110 c.fclose.in.max_count = 1;
111 c.fclose.in.search_attrib = 0;
112 c.fclose.in.id = data->search.id;
113 status = smb_raw_search_close(cli->tree, &c);
122 enum smb_search_level level;
123 enum smb_search_data_level data_level;
125 int resume_key_offset;
126 uint32_t capability_mask;
128 union smb_search_data data;
132 .level = RAW_SEARCH_FFIRST,
133 .data_level = RAW_SEARCH_DATA_SEARCH,
134 .name_offset = offsetof(union smb_search_data,
136 .resume_key_offset = -1,
140 .level = RAW_SEARCH_FUNIQUE,
141 .data_level = RAW_SEARCH_DATA_SEARCH,
142 .name_offset = offsetof(union smb_search_data,
144 .resume_key_offset = -1,
148 .level = RAW_SEARCH_SEARCH,
149 .data_level = RAW_SEARCH_DATA_SEARCH,
150 .name_offset = offsetof(union smb_search_data,
152 .resume_key_offset = -1,
156 .level = RAW_SEARCH_TRANS2,
157 .data_level = RAW_SEARCH_DATA_STANDARD,
158 .name_offset = offsetof(union smb_search_data,
160 .resume_key_offset = offsetof(union smb_search_data,
161 standard.resume_key),
165 .level = RAW_SEARCH_TRANS2,
166 .data_level = RAW_SEARCH_DATA_EA_SIZE,
167 .name_offset = offsetof(union smb_search_data,
169 .resume_key_offset = offsetof(union smb_search_data,
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),
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),
192 .level = RAW_SEARCH_TRANS2,
193 .data_level = RAW_SEARCH_DATA_NAME_INFO,
194 .name_offset = offsetof(union smb_search_data,
196 .resume_key_offset = offsetof(union smb_search_data,
197 name_info.file_index),
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),
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),
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),
228 .level = RAW_SEARCH_TRANS2,
229 .data_level = RAW_SEARCH_DATA_UNIX_INFO,
230 .name_offset = offsetof(union smb_search_data,
232 .resume_key_offset = offsetof(union smb_search_data,
233 unix_info.file_index),
234 .capability_mask = CAP_UNIX
242 static const char *level_name(enum smb_search_level level,
243 enum smb_search_data_level data_level)
246 for (i=0;i<ARRAY_SIZE(levels);i++) {
247 if (level == levels[i].level &&
248 data_level == levels[i].data_level) {
249 return levels[i].name;
256 extract the name from a smb_data structure and level
258 static const char *extract_name(void *data, enum smb_search_level level,
259 enum smb_search_data_level data_level)
262 for (i=0;i<ARRAY_SIZE(levels);i++) {
263 if (level == levels[i].level &&
264 data_level == levels[i].data_level) {
265 return *(const char **)(levels[i].name_offset + (char *)data);
272 extract the name from a smb_data structure and level
274 static uint32_t extract_resume_key(void *data, enum smb_search_level level,
275 enum smb_search_data_level data_level)
278 for (i=0;i<ARRAY_SIZE(levels);i++) {
279 if (level == levels[i].level &&
280 data_level == levels[i].data_level) {
281 return *(uint32_t *)(levels[i].resume_key_offset + (char *)data);
287 /* find a level in the table by name */
288 static union smb_search_data *find(const char *name)
291 for (i=0;i<ARRAY_SIZE(levels);i++) {
292 if (NT_STATUS_IS_OK(levels[i].status) &&
293 strcmp(levels[i].name, name) == 0) {
294 return &levels[i].data;
301 basic testing of all RAW_SEARCH_* calls using a single file
303 static bool test_one_file(struct torture_context *tctx,
304 struct smbcli_state *cli)
308 const char *fname = "\\torture_search.txt";
309 const char *fname2 = "\\torture_search-NOTEXIST.txt";
312 union smb_fileinfo all_info, alt_info, name_info, internal_info;
313 bool all_info_supported, alt_info_supported, name_info_supported,
314 internal_info_supported;
315 union smb_search_data *s;
317 fnum = create_complex_file(cli, tctx, fname);
319 printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
324 /* call all the levels */
325 for (i=0;i<ARRAY_SIZE(levels);i++) {
326 NTSTATUS expected_status;
327 uint32_t cap = cli->transport->negotiate.capabilities;
329 torture_comment(tctx, "Testing %s\n", levels[i].name);
331 levels[i].status = torture_single_search(cli, tctx, fname,
333 levels[i].data_level,
337 /* see if this server claims to support this level */
338 if (((cap & levels[i].capability_mask) != levels[i].capability_mask)
339 || NT_STATUS_EQUAL(levels[i].status, NT_STATUS_NOT_SUPPORTED)) {
340 printf("search level %s(%d) not supported by server\n",
341 levels[i].name, (int)levels[i].level);
345 if (!NT_STATUS_IS_OK(levels[i].status)) {
346 printf("search level %s(%d) failed - %s\n",
347 levels[i].name, (int)levels[i].level,
348 nt_errstr(levels[i].status));
353 status = torture_single_search(cli, tctx, fname2,
355 levels[i].data_level,
359 expected_status = NT_STATUS_NO_SUCH_FILE;
360 if (levels[i].level == RAW_SEARCH_SEARCH ||
361 levels[i].level == RAW_SEARCH_FFIRST ||
362 levels[i].level == RAW_SEARCH_FUNIQUE) {
363 expected_status = STATUS_NO_MORE_FILES;
365 if (!NT_STATUS_EQUAL(status, expected_status)) {
366 printf("search level %s(%d) should fail with %s - %s\n",
367 levels[i].name, (int)levels[i].level,
368 nt_errstr(expected_status),
374 /* get the all_info file into to check against */
375 all_info.generic.level = RAW_FILEINFO_ALL_INFO;
376 all_info.generic.in.file.path = fname;
377 status = smb_raw_pathinfo(cli->tree, tctx, &all_info);
378 CHECK_STATUS_LEVEL(tctx, status, "RAW_FILEINFO_ALL_INFO",
381 alt_info.generic.level = RAW_FILEINFO_ALT_NAME_INFO;
382 alt_info.generic.in.file.path = fname;
383 status = smb_raw_pathinfo(cli->tree, tctx, &alt_info);
384 CHECK_STATUS_LEVEL(tctx, status, "RAW_FILEINFO_ALT_NAME_INFO",
387 internal_info.generic.level = RAW_FILEINFO_INTERNAL_INFORMATION;
388 internal_info.generic.in.file.path = fname;
389 status = smb_raw_pathinfo(cli->tree, tctx, &internal_info);
390 CHECK_STATUS_LEVEL(tctx, status, "RAW_FILEINFO_INTERNAL_INFORMATION",
391 internal_info_supported);
393 name_info.generic.level = RAW_FILEINFO_NAME_INFO;
394 name_info.generic.in.file.path = fname;
395 status = smb_raw_pathinfo(cli->tree, tctx, &name_info);
396 CHECK_STATUS_LEVEL(tctx, status, "RAW_FILEINFO_NAME_INFO",
397 name_info_supported);
399 #define CHECK_VAL(name, sname1, field1, v, sname2, field2) do { \
402 if ((s->sname1.field1) != (v.sname2.out.field2)) { \
403 printf("(%s) %s/%s [0x%x] != %s/%s [0x%x]\n", \
405 #sname1, #field1, (int)s->sname1.field1, \
406 #sname2, #field2, (int)v.sname2.out.field2); \
411 #define CHECK_TIME(name, sname1, field1, v, sname2, field2) do { \
414 if (s->sname1.field1 != (~1 & nt_time_to_unix(v.sname2.out.field2))) { \
415 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
417 #sname1, #field1, timestring(tctx, s->sname1.field1), \
418 #sname2, #field2, nt_time_string(tctx, v.sname2.out.field2)); \
423 #define CHECK_NTTIME(name, sname1, field1, v, sname2, field2) do { \
426 if (s->sname1.field1 != v.sname2.out.field2) { \
427 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
429 #sname1, #field1, nt_time_string(tctx, s->sname1.field1), \
430 #sname2, #field2, nt_time_string(tctx, v.sname2.out.field2)); \
435 #define CHECK_STR(name, sname1, field1, v, sname2, field2) do { \
438 if (!s->sname1.field1 || strcmp(s->sname1.field1, v.sname2.out.field2.s)) { \
439 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
441 #sname1, #field1, s->sname1.field1, \
442 #sname2, #field2, v.sname2.out.field2.s); \
447 #define CHECK_WSTR(name, sname1, field1, v, sname2, field2, flags) do { \
450 if (!s->sname1.field1.s || \
451 strcmp(s->sname1.field1.s, v.sname2.out.field2.s) || \
452 wire_bad_flags(&s->sname1.field1, flags, cli->transport)) { \
453 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
455 #sname1, #field1, s->sname1.field1.s, \
456 #sname2, #field2, v.sname2.out.field2.s); \
461 #define CHECK_NAME(name, sname1, field1, fname, flags) do { \
464 if (!s->sname1.field1.s || \
465 strcmp(s->sname1.field1.s, fname) || \
466 wire_bad_flags(&s->sname1.field1, flags, cli->transport)) { \
467 printf("(%s) %s/%s [%s] != %s\n", \
469 #sname1, #field1, s->sname1.field1.s, \
475 #define CHECK_UNIX_NAME(name, sname1, field1, fname, flags) do { \
478 if (!s->sname1.field1 || \
479 strcmp(s->sname1.field1, fname)) { \
480 printf("(%s) %s/%s [%s] != %s\n", \
482 #sname1, #field1, s->sname1.field1, \
488 /* check that all the results are as expected */
489 CHECK_VAL("SEARCH", search, attrib, all_info, all_info, attrib&0xFFF);
490 CHECK_VAL("STANDARD", standard, attrib, all_info, all_info, attrib&0xFFF);
491 CHECK_VAL("EA_SIZE", ea_size, attrib, all_info, all_info, attrib&0xFFF);
492 CHECK_VAL("DIRECTORY_INFO", directory_info, attrib, all_info, all_info, attrib);
493 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, attrib, all_info, all_info, attrib);
494 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, attrib, all_info, all_info, attrib);
495 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, attrib, all_info, all_info, attrib);
496 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, attrib, all_info, all_info, attrib);
498 CHECK_TIME("SEARCH", search, write_time, all_info, all_info, write_time);
499 CHECK_TIME("STANDARD", standard, write_time, all_info, all_info, write_time);
500 CHECK_TIME("EA_SIZE", ea_size, write_time, all_info, all_info, write_time);
501 CHECK_TIME("STANDARD", standard, create_time, all_info, all_info, create_time);
502 CHECK_TIME("EA_SIZE", ea_size, create_time, all_info, all_info, create_time);
503 CHECK_TIME("STANDARD", standard, access_time, all_info, all_info, access_time);
504 CHECK_TIME("EA_SIZE", ea_size, access_time, all_info, all_info, access_time);
506 CHECK_NTTIME("DIRECTORY_INFO", directory_info, write_time, all_info, all_info, write_time);
507 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, write_time, all_info, all_info, write_time);
508 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, write_time, all_info, all_info, write_time);
509 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, write_time, all_info, all_info, write_time);
510 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, write_time, all_info, all_info, write_time);
512 CHECK_NTTIME("DIRECTORY_INFO", directory_info, create_time, all_info, all_info, create_time);
513 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, create_time, all_info, all_info, create_time);
514 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, create_time, all_info, all_info, create_time);
515 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, create_time, all_info, all_info, create_time);
516 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, create_time, all_info, all_info, create_time);
518 CHECK_NTTIME("DIRECTORY_INFO", directory_info, access_time, all_info, all_info, access_time);
519 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, access_time, all_info, all_info, access_time);
520 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, access_time, all_info, all_info, access_time);
521 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, access_time, all_info, all_info, access_time);
522 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, access_time, all_info, all_info, access_time);
524 CHECK_NTTIME("DIRECTORY_INFO", directory_info, change_time, all_info, all_info, change_time);
525 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, change_time, all_info, all_info, change_time);
526 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, change_time, all_info, all_info, change_time);
527 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, change_time, all_info, all_info, change_time);
528 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, change_time, all_info, all_info, change_time);
530 CHECK_VAL("SEARCH", search, size, all_info, all_info, size);
531 CHECK_VAL("STANDARD", standard, size, all_info, all_info, size);
532 CHECK_VAL("EA_SIZE", ea_size, size, all_info, all_info, size);
533 CHECK_VAL("DIRECTORY_INFO", directory_info, size, all_info, all_info, size);
534 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, size, all_info, all_info, size);
535 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, size, all_info, all_info, size);
536 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, size, all_info, all_info, size);
537 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, size, all_info, all_info, size);
538 CHECK_VAL("UNIX_INFO", unix_info, size, all_info, all_info, size);
540 CHECK_VAL("STANDARD", standard, alloc_size, all_info, all_info, alloc_size);
541 CHECK_VAL("EA_SIZE", ea_size, alloc_size, all_info, all_info, alloc_size);
542 CHECK_VAL("DIRECTORY_INFO", directory_info, alloc_size, all_info, all_info, alloc_size);
543 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, alloc_size, all_info, all_info, alloc_size);
544 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, alloc_size, all_info, all_info, alloc_size);
545 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, alloc_size, all_info, all_info, alloc_size);
546 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, alloc_size, all_info, all_info, alloc_size);
547 CHECK_VAL("UNIX_INFO", unix_info, alloc_size, all_info, all_info, alloc_size);
549 CHECK_VAL("EA_SIZE", ea_size, ea_size, all_info, all_info, ea_size);
550 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, ea_size, all_info, all_info, ea_size);
551 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, ea_size, all_info, all_info, ea_size);
552 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, ea_size, all_info, all_info, ea_size);
553 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, ea_size, all_info, all_info, ea_size);
555 if (alt_info_supported) {
556 CHECK_STR("SEARCH", search, name, alt_info, alt_name_info,
558 CHECK_WSTR("BOTH_DIRECTORY_INFO", both_directory_info,
559 short_name, alt_info, alt_name_info, fname, STR_UNICODE);
562 CHECK_NAME("STANDARD", standard, name, fname+1, 0);
563 CHECK_NAME("EA_SIZE", ea_size, name, fname+1, 0);
564 CHECK_NAME("DIRECTORY_INFO", directory_info, name, fname+1, STR_TERMINATE_ASCII);
565 CHECK_NAME("FULL_DIRECTORY_INFO", full_directory_info, name, fname+1, STR_TERMINATE_ASCII);
567 if (name_info_supported) {
568 CHECK_NAME("NAME_INFO", name_info, name, fname+1,
569 STR_TERMINATE_ASCII);
572 CHECK_NAME("BOTH_DIRECTORY_INFO", both_directory_info, name, fname+1, STR_TERMINATE_ASCII);
573 CHECK_NAME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, name, fname+1, STR_TERMINATE_ASCII);
574 CHECK_NAME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, name, fname+1, STR_TERMINATE_ASCII);
575 CHECK_UNIX_NAME("UNIX_INFO", unix_info, name, fname+1, STR_TERMINATE_ASCII);
577 if (internal_info_supported) {
578 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info,
579 file_id, internal_info, internal_information, file_id);
580 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info,
581 file_id, internal_info, internal_information, file_id);
585 smb_raw_exit(cli->session);
586 smbcli_unlink(cli->tree, fname);
592 struct multiple_result {
595 union smb_search_data *list;
599 callback function for multiple_search
601 static bool multiple_search_callback(void *private_data, const union smb_search_data *file)
603 struct multiple_result *data = (struct multiple_result *)private_data;
607 data->list = talloc_realloc(data->tctx,
609 union smb_search_data,
612 data->list[data->count-1] = *file;
617 enum continue_type {CONT_FLAGS, CONT_NAME, CONT_RESUME_KEY};
620 do a single file (non-wildcard) search
622 static NTSTATUS multiple_search(struct smbcli_state *cli,
625 enum smb_search_data_level data_level,
626 enum continue_type cont_type,
629 union smb_search_first io;
630 union smb_search_next io2;
632 const int per_search = 100;
633 struct multiple_result *result = (struct multiple_result *)data;
635 if (data_level == RAW_SEARCH_DATA_SEARCH) {
636 io.search_first.level = RAW_SEARCH_SEARCH;
637 io.search_first.data_level = RAW_SEARCH_DATA_SEARCH;
638 io.search_first.in.max_count = per_search;
639 io.search_first.in.search_attrib = 0;
640 io.search_first.in.pattern = pattern;
642 io.t2ffirst.level = RAW_SEARCH_TRANS2;
643 io.t2ffirst.data_level = data_level;
644 io.t2ffirst.in.search_attrib = 0;
645 io.t2ffirst.in.max_count = per_search;
646 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE_IF_END;
647 io.t2ffirst.in.storage_type = 0;
648 io.t2ffirst.in.pattern = pattern;
649 if (cont_type == CONT_RESUME_KEY) {
650 io.t2ffirst.in.flags |= FLAG_TRANS2_FIND_REQUIRE_RESUME |
651 FLAG_TRANS2_FIND_BACKUP_INTENT;
655 status = smb_raw_search_first(cli->tree, tctx,
656 &io, data, multiple_search_callback);
659 while (NT_STATUS_IS_OK(status)) {
660 if (data_level == RAW_SEARCH_DATA_SEARCH) {
661 io2.search_next.level = RAW_SEARCH_SEARCH;
662 io2.search_next.data_level = RAW_SEARCH_DATA_SEARCH;
663 io2.search_next.in.max_count = per_search;
664 io2.search_next.in.search_attrib = 0;
665 io2.search_next.in.id = result->list[result->count-1].search.id;
667 io2.t2fnext.level = RAW_SEARCH_TRANS2;
668 io2.t2fnext.data_level = data_level;
669 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
670 io2.t2fnext.in.max_count = per_search;
671 io2.t2fnext.in.resume_key = 0;
672 io2.t2fnext.in.flags = FLAG_TRANS2_FIND_CLOSE_IF_END;
673 io2.t2fnext.in.last_name = "";
675 case CONT_RESUME_KEY:
676 io2.t2fnext.in.resume_key = extract_resume_key(&result->list[result->count-1],
677 io2.t2fnext.level, io2.t2fnext.data_level);
678 if (io2.t2fnext.in.resume_key == 0) {
679 printf("Server does not support resume by key for level %s\n",
680 level_name(io2.t2fnext.level, io2.t2fnext.data_level));
681 return NT_STATUS_NOT_SUPPORTED;
683 io2.t2fnext.in.flags |= FLAG_TRANS2_FIND_REQUIRE_RESUME |
684 FLAG_TRANS2_FIND_BACKUP_INTENT;
687 io2.t2fnext.in.last_name = extract_name(&result->list[result->count-1],
688 io2.t2fnext.level, io2.t2fnext.data_level);
691 io2.t2fnext.in.flags |= FLAG_TRANS2_FIND_CONTINUE;
696 status = smb_raw_search_next(cli->tree, tctx,
697 &io2, data, multiple_search_callback);
698 if (!NT_STATUS_IS_OK(status)) {
701 if (data_level == RAW_SEARCH_DATA_SEARCH) {
702 if (io2.search_next.out.count == 0) {
705 } else if (io2.t2fnext.out.count == 0 ||
706 io2.t2fnext.out.end_of_search) {
714 #define CHECK_STATUS(status, correct) torture_assert_ntstatus_equal(tctx, status, correct, "incorrect status")
716 #define CHECK_VALUE(v, correct) torture_assert_int_equal(tctx, (v), (correct), "incorrect value");
718 #define CHECK_STRING(v, correct) torture_assert_casestr_equal(tctx, v, correct, "incorrect value");
721 static enum smb_search_data_level compare_data_level;
723 static int search_compare(union smb_search_data *d1, union smb_search_data *d2)
726 enum smb_search_level level;
728 if (compare_data_level == RAW_SEARCH_DATA_SEARCH) {
729 level = RAW_SEARCH_SEARCH;
731 level = RAW_SEARCH_TRANS2;
734 s1 = extract_name(d1, level, compare_data_level);
735 s2 = extract_name(d2, level, compare_data_level);
736 return strcmp_safe(s1, s2);
742 basic testing of search calls using many files
744 static bool test_many_files(struct torture_context *tctx,
745 struct smbcli_state *cli)
747 const int num_files = 700;
752 struct multiple_result result;
755 const char *cont_name;
756 enum smb_search_data_level data_level;
757 enum continue_type cont_type;
759 {"SEARCH", "ID", RAW_SEARCH_DATA_SEARCH, CONT_RESUME_KEY},
760 {"BOTH_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO, CONT_NAME},
761 {"BOTH_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO, CONT_FLAGS},
762 {"BOTH_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO, CONT_RESUME_KEY},
763 {"STANDARD", "FLAGS", RAW_SEARCH_DATA_STANDARD, CONT_FLAGS},
764 {"STANDARD", "KEY", RAW_SEARCH_DATA_STANDARD, CONT_RESUME_KEY},
765 {"STANDARD", "NAME", RAW_SEARCH_DATA_STANDARD, CONT_NAME},
766 {"EA_SIZE", "FLAGS", RAW_SEARCH_DATA_EA_SIZE, CONT_FLAGS},
767 {"EA_SIZE", "KEY", RAW_SEARCH_DATA_EA_SIZE, CONT_RESUME_KEY},
768 {"EA_SIZE", "NAME", RAW_SEARCH_DATA_EA_SIZE, CONT_NAME},
769 {"DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_DIRECTORY_INFO, CONT_FLAGS},
770 {"DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_DIRECTORY_INFO, CONT_RESUME_KEY},
771 {"DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_DIRECTORY_INFO, CONT_NAME},
772 {"FULL_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_FULL_DIRECTORY_INFO, CONT_FLAGS},
773 {"FULL_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_FULL_DIRECTORY_INFO, CONT_RESUME_KEY},
774 {"FULL_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_FULL_DIRECTORY_INFO, CONT_NAME},
775 {"ID_FULL_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO, CONT_FLAGS},
776 {"ID_FULL_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO, CONT_RESUME_KEY},
777 {"ID_FULL_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO, CONT_NAME},
778 {"ID_BOTH_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO, CONT_NAME},
779 {"ID_BOTH_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO, CONT_FLAGS},
780 {"ID_BOTH_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO, CONT_RESUME_KEY}
783 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
785 torture_comment(tctx, "Testing with %d files\n", num_files);
787 for (i=0;i<num_files;i++) {
788 fname = talloc_asprintf(cli, BASEDIR "\\t%03d-%d.txt", i, i);
789 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
790 torture_assert(tctx, fnum != -1, "Failed to create");
792 smbcli_close(cli->tree, fnum);
796 for (t=0;t<ARRAY_SIZE(search_types);t++) {
799 if ((search_types[t].cont_type == CONT_RESUME_KEY) &&
800 (search_types[t].data_level != RAW_SEARCH_DATA_SEARCH) &&
801 !torture_setting_bool(tctx, "resume_key_support", true)) {
802 torture_comment(tctx,
803 "SKIP: Continue %s via %s\n",
804 search_types[t].name, search_types[t].cont_name);
808 result.tctx = talloc_new(tctx);
810 torture_comment(tctx,
811 "Continue %s via %s\n", search_types[t].name, search_types[t].cont_name);
813 status = multiple_search(cli, tctx, BASEDIR "\\*.*",
814 search_types[t].data_level,
815 search_types[t].cont_type,
817 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
818 torture_warning(tctx, "search level %s not supported "
820 search_types[t].name);
823 torture_assert_ntstatus_ok(tctx, status, "search failed");
824 CHECK_VALUE(result.count, num_files);
826 compare_data_level = search_types[t].data_level;
828 TYPESAFE_QSORT(result.list, result.count, search_compare);
830 for (i=0;i<result.count;i++) {
832 enum smb_search_level level;
833 if (compare_data_level == RAW_SEARCH_DATA_SEARCH) {
834 level = RAW_SEARCH_SEARCH;
836 level = RAW_SEARCH_TRANS2;
838 s = extract_name(&result.list[i], level, compare_data_level);
839 fname = talloc_asprintf(cli, "t%03d-%d.txt", i, i);
840 torture_assert_str_equal(tctx, fname, s, "Incorrect name");
843 talloc_free(result.tctx);
846 smb_raw_exit(cli->session);
847 smbcli_deltree(cli->tree, BASEDIR);
853 check a individual file result
855 static bool check_result(struct multiple_result *result, const char *name, bool exist, uint32_t attrib)
858 for (i=0;i<result->count;i++) {
859 if (strcmp(name, result->list[i].both_directory_info.name.s) == 0) break;
861 if (i == result->count) {
863 printf("failed: '%s' should exist with attribute %s\n",
864 name, attrib_string(result->list, attrib));
871 printf("failed: '%s' should NOT exist (has attribute %s)\n",
872 name, attrib_string(result->list, result->list[i].both_directory_info.attrib));
876 if ((result->list[i].both_directory_info.attrib&0xFFF) != attrib) {
877 printf("failed: '%s' should have attribute 0x%x (has 0x%x)\n",
879 attrib, result->list[i].both_directory_info.attrib);
886 test what happens when the directory is modified during a search
888 static bool test_modify_search(struct torture_context *tctx,
889 struct smbcli_state *cli)
891 const int num_files = 20;
896 struct multiple_result result;
897 union smb_search_first io;
898 union smb_search_next io2;
899 union smb_setfileinfo sfinfo;
901 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
903 printf("Creating %d files\n", num_files);
905 for (i=num_files-1;i>=0;i--) {
906 fname = talloc_asprintf(cli, BASEDIR "\\t%03d-%d.txt", i, i);
907 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
909 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
914 smbcli_close(cli->tree, fnum);
917 printf("pulling the first file\n");
919 result.tctx = talloc_new(tctx);
921 io.t2ffirst.level = RAW_SEARCH_TRANS2;
922 io.t2ffirst.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
923 io.t2ffirst.in.search_attrib = 0;
924 io.t2ffirst.in.max_count = 0;
925 io.t2ffirst.in.flags = 0;
926 io.t2ffirst.in.storage_type = 0;
927 io.t2ffirst.in.pattern = BASEDIR "\\*.*";
929 status = smb_raw_search_first(cli->tree, tctx,
930 &io, &result, multiple_search_callback);
931 CHECK_STATUS(status, NT_STATUS_OK);
932 CHECK_VALUE(result.count, 1);
934 printf("pulling the second file\n");
935 io2.t2fnext.level = RAW_SEARCH_TRANS2;
936 io2.t2fnext.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
937 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
938 io2.t2fnext.in.max_count = 1;
939 io2.t2fnext.in.resume_key = 0;
940 io2.t2fnext.in.flags = 0;
941 io2.t2fnext.in.last_name = result.list[result.count-1].both_directory_info.name.s;
943 status = smb_raw_search_next(cli->tree, tctx,
944 &io2, &result, multiple_search_callback);
945 CHECK_STATUS(status, NT_STATUS_OK);
946 CHECK_VALUE(result.count, 2);
950 printf("Changing attributes and deleting\n");
951 smbcli_open(cli->tree, BASEDIR "\\T003-03.txt.2", O_CREAT|O_RDWR, DENY_NONE);
952 smbcli_open(cli->tree, BASEDIR "\\T013-13.txt.2", O_CREAT|O_RDWR, DENY_NONE);
953 fnum = create_complex_file(cli, tctx, BASEDIR "\\T013-13.txt.3");
954 smbcli_unlink(cli->tree, BASEDIR "\\T014-14.txt");
955 torture_set_file_attribute(cli->tree, BASEDIR "\\T015-15.txt", FILE_ATTRIBUTE_HIDDEN);
956 torture_set_file_attribute(cli->tree, BASEDIR "\\T016-16.txt", FILE_ATTRIBUTE_NORMAL);
957 torture_set_file_attribute(cli->tree, BASEDIR "\\T017-17.txt", FILE_ATTRIBUTE_SYSTEM);
958 torture_set_file_attribute(cli->tree, BASEDIR "\\T018-18.txt", 0);
959 sfinfo.generic.level = RAW_SFILEINFO_DISPOSITION_INFORMATION;
960 sfinfo.generic.in.file.fnum = fnum;
961 sfinfo.disposition_info.in.delete_on_close = 1;
962 status = smb_raw_setfileinfo(cli->tree, &sfinfo);
963 CHECK_STATUS(status, NT_STATUS_OK);
965 io2.t2fnext.level = RAW_SEARCH_TRANS2;
966 io2.t2fnext.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
967 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
968 io2.t2fnext.in.max_count = num_files + 3;
969 io2.t2fnext.in.resume_key = 0;
970 io2.t2fnext.in.flags = 0;
971 io2.t2fnext.in.last_name = ".";
973 status = smb_raw_search_next(cli->tree, tctx,
974 &io2, &result, multiple_search_callback);
975 CHECK_STATUS(status, NT_STATUS_OK);
976 CHECK_VALUE(result.count, 20);
978 ret &= check_result(&result, "t009-9.txt", true, FILE_ATTRIBUTE_ARCHIVE);
979 ret &= check_result(&result, "t014-14.txt", false, 0);
980 ret &= check_result(&result, "t015-15.txt", false, 0);
981 ret &= check_result(&result, "t016-16.txt", true, FILE_ATTRIBUTE_NORMAL);
982 ret &= check_result(&result, "t017-17.txt", false, 0);
983 ret &= check_result(&result, "t018-18.txt", true, FILE_ATTRIBUTE_ARCHIVE);
984 ret &= check_result(&result, "t019-19.txt", true, FILE_ATTRIBUTE_ARCHIVE);
985 ret &= check_result(&result, "T013-13.txt.2", true, FILE_ATTRIBUTE_ARCHIVE);
986 ret &= check_result(&result, "T003-3.txt.2", false, 0);
987 ret &= check_result(&result, "T013-13.txt.3", true, FILE_ATTRIBUTE_ARCHIVE);
990 for (i=0;i<result.count;i++) {
991 printf("%s %s (0x%x)\n",
992 result.list[i].both_directory_info.name.s,
993 attrib_string(tctx, result.list[i].both_directory_info.attrib),
994 result.list[i].both_directory_info.attrib);
999 smb_raw_exit(cli->session);
1000 smbcli_deltree(cli->tree, BASEDIR);
1007 testing if directories always come back sorted
1009 static bool test_sorted(struct torture_context *tctx, struct smbcli_state *cli)
1011 const int num_files = 700;
1016 struct multiple_result result;
1018 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1020 printf("Creating %d files\n", num_files);
1022 for (i=0;i<num_files;i++) {
1023 fname = talloc_asprintf(cli, BASEDIR "\\%s.txt", generate_random_str_list(tctx, 10, "abcdefgh"));
1024 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1026 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
1031 smbcli_close(cli->tree, fnum);
1035 ZERO_STRUCT(result);
1038 status = multiple_search(cli, tctx, BASEDIR "\\*.*",
1039 RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO,
1040 CONT_NAME, &result);
1041 CHECK_STATUS(status, NT_STATUS_OK);
1042 CHECK_VALUE(result.count, num_files);
1044 for (i=0;i<num_files-1;i++) {
1045 const char *name1, *name2;
1046 name1 = result.list[i].both_directory_info.name.s;
1047 name2 = result.list[i+1].both_directory_info.name.s;
1048 if (strcasecmp_m(name1, name2) > 0) {
1049 printf("non-alphabetical order at entry %d '%s' '%s'\n",
1051 printf("Server does not produce sorted directory listings (not an error)\n");
1056 talloc_free(result.list);
1059 smb_raw_exit(cli->session);
1060 smbcli_deltree(cli->tree, BASEDIR);
1068 basic testing of many old style search calls using separate dirs
1070 static bool test_many_dirs(struct torture_context *tctx,
1071 struct smbcli_state *cli)
1073 const int num_dirs = 20;
1075 char *fname, *dname;
1078 union smb_search_data *file, *file2, *file3;
1080 if (!torture_setting_bool(tctx, "raw_search_search", true)) {
1081 torture_comment(tctx, "Skipping these tests as the server "
1082 "doesn't support old style search calls\n");
1085 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1087 printf("Creating %d dirs\n", num_dirs);
1089 for (i=0;i<num_dirs;i++) {
1090 dname = talloc_asprintf(cli, BASEDIR "\\d%d", i);
1091 status = smbcli_mkdir(cli->tree, dname);
1092 if (!NT_STATUS_IS_OK(status)) {
1093 printf("(%s) Failed to create %s - %s\n",
1094 __location__, dname, nt_errstr(status));
1100 fname = talloc_asprintf(cli, BASEDIR "\\d%d\\f%d-%d.txt", i, i, n);
1101 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1103 printf("(%s) Failed to create %s - %s\n",
1104 __location__, fname, smbcli_errstr(cli->tree));
1109 smbcli_close(cli->tree, fnum);
1115 file = talloc_zero_array(tctx, union smb_search_data, num_dirs);
1116 file2 = talloc_zero_array(tctx, union smb_search_data, num_dirs);
1117 file3 = talloc_zero_array(tctx, union smb_search_data, num_dirs);
1119 printf("Search first on %d dirs\n", num_dirs);
1121 for (i=0;i<num_dirs;i++) {
1122 union smb_search_first io;
1123 io.search_first.level = RAW_SEARCH_SEARCH;
1124 io.search_first.data_level = RAW_SEARCH_DATA_SEARCH;
1125 io.search_first.in.max_count = 1;
1126 io.search_first.in.search_attrib = 0;
1127 io.search_first.in.pattern = talloc_asprintf(tctx, BASEDIR "\\d%d\\*.txt", i);
1128 fname = talloc_asprintf(tctx, "f%d-", i);
1130 io.search_first.out.count = 0;
1132 status = smb_raw_search_first(cli->tree, tctx,
1133 &io, (void *)&file[i], single_search_callback);
1134 if (io.search_first.out.count != 1) {
1135 printf("(%s) search first gave %d entries for dir %d - %s\n",
1136 __location__, io.search_first.out.count, i, nt_errstr(status));
1140 CHECK_STATUS(status, NT_STATUS_OK);
1141 if (strncasecmp(file[i].search.name, fname, strlen(fname)) != 0) {
1142 printf("(%s) incorrect name '%s' expected '%s'[12].txt\n",
1143 __location__, file[i].search.name, fname);
1151 printf("Search next on %d dirs\n", num_dirs);
1153 for (i=0;i<num_dirs;i++) {
1154 union smb_search_next io2;
1156 io2.search_next.level = RAW_SEARCH_SEARCH;
1157 io2.search_next.data_level = RAW_SEARCH_DATA_SEARCH;
1158 io2.search_next.in.max_count = 1;
1159 io2.search_next.in.search_attrib = 0;
1160 io2.search_next.in.id = file[i].search.id;
1161 fname = talloc_asprintf(tctx, "f%d-", i);
1163 io2.search_next.out.count = 0;
1165 status = smb_raw_search_next(cli->tree, tctx,
1166 &io2, (void *)&file2[i], single_search_callback);
1167 if (io2.search_next.out.count != 1) {
1168 printf("(%s) search next gave %d entries for dir %d - %s\n",
1169 __location__, io2.search_next.out.count, i, nt_errstr(status));
1173 CHECK_STATUS(status, NT_STATUS_OK);
1174 if (strncasecmp(file2[i].search.name, fname, strlen(fname)) != 0) {
1175 printf("(%s) incorrect name '%s' expected '%s'[12].txt\n",
1176 __location__, file2[i].search.name, fname);
1185 printf("Search next (rewind) on %d dirs\n", num_dirs);
1187 for (i=0;i<num_dirs;i++) {
1188 union smb_search_next io2;
1190 io2.search_next.level = RAW_SEARCH_SEARCH;
1191 io2.search_next.data_level = RAW_SEARCH_DATA_SEARCH;
1192 io2.search_next.in.max_count = 1;
1193 io2.search_next.in.search_attrib = 0;
1194 io2.search_next.in.id = file[i].search.id;
1195 fname = talloc_asprintf(tctx, "f%d-", i);
1196 io2.search_next.out.count = 0;
1198 status = smb_raw_search_next(cli->tree, tctx,
1199 &io2, (void *)&file3[i], single_search_callback);
1200 if (io2.search_next.out.count != 1) {
1201 printf("(%s) search next gave %d entries for dir %d - %s\n",
1202 __location__, io2.search_next.out.count, i, nt_errstr(status));
1206 CHECK_STATUS(status, NT_STATUS_OK);
1208 if (strncasecmp(file3[i].search.name, file2[i].search.name, 3) != 0) {
1209 printf("(%s) incorrect name '%s' on rewind at dir %d\n",
1210 __location__, file2[i].search.name, i);
1215 if (torture_setting_bool(tctx, "rewind_support", true) &&
1216 strcmp(file3[i].search.name, file2[i].search.name) != 0) {
1217 printf("(%s) server did not rewind - got '%s' expected '%s'\n",
1218 __location__, file3[i].search.name, file2[i].search.name);
1228 smb_raw_exit(cli->session);
1229 smbcli_deltree(cli->tree, BASEDIR);
1236 testing of OS/2 style delete
1238 static bool test_os2_delete(struct torture_context *tctx,
1239 struct smbcli_state *cli)
1241 const int num_files = 700;
1242 const int delete_count = 4;
1243 int total_deleted = 0;
1248 union smb_search_first io;
1249 union smb_search_next io2;
1250 struct multiple_result result;
1252 if (!torture_setting_bool(tctx, "search_ea_size", true)){
1253 torture_comment(tctx,
1254 "Server does not support RAW_SEARCH_EA_SIZE "
1255 "level. Skipping this test\n");
1259 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1261 printf("Testing OS/2 style delete on %d files\n", num_files);
1263 for (i=0;i<num_files;i++) {
1264 fname = talloc_asprintf(cli, BASEDIR "\\file%u.txt", i);
1265 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1267 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
1272 smbcli_close(cli->tree, fnum);
1276 ZERO_STRUCT(result);
1279 io.t2ffirst.level = RAW_SEARCH_TRANS2;
1280 io.t2ffirst.data_level = RAW_SEARCH_DATA_EA_SIZE;
1281 io.t2ffirst.in.search_attrib = 0;
1282 io.t2ffirst.in.max_count = 100;
1283 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1284 io.t2ffirst.in.storage_type = 0;
1285 io.t2ffirst.in.pattern = BASEDIR "\\*";
1287 status = smb_raw_search_first(cli->tree, tctx,
1288 &io, &result, multiple_search_callback);
1289 CHECK_STATUS(status, NT_STATUS_OK);
1291 for (i=0;i<MIN(result.count, delete_count);i++) {
1292 fname = talloc_asprintf(cli, BASEDIR "\\%s", result.list[i].ea_size.name.s);
1293 status = smbcli_unlink(cli->tree, fname);
1294 CHECK_STATUS(status, NT_STATUS_OK);
1299 io2.t2fnext.level = RAW_SEARCH_TRANS2;
1300 io2.t2fnext.data_level = RAW_SEARCH_DATA_EA_SIZE;
1301 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
1302 io2.t2fnext.in.max_count = 100;
1303 io2.t2fnext.in.resume_key = result.list[i-1].ea_size.resume_key;
1304 io2.t2fnext.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1305 io2.t2fnext.in.last_name = result.list[i-1].ea_size.name.s;
1308 ZERO_STRUCT(result);
1311 status = smb_raw_search_next(cli->tree, tctx,
1312 &io2, &result, multiple_search_callback);
1313 if (!NT_STATUS_IS_OK(status)) {
1317 for (i=0;i<MIN(result.count, delete_count);i++) {
1318 fname = talloc_asprintf(cli, BASEDIR "\\%s", result.list[i].ea_size.name.s);
1319 status = smbcli_unlink(cli->tree, fname);
1320 CHECK_STATUS(status, NT_STATUS_OK);
1326 io2.t2fnext.in.resume_key = result.list[i-1].ea_size.resume_key;
1327 io2.t2fnext.in.last_name = result.list[i-1].ea_size.name.s;
1329 } while (NT_STATUS_IS_OK(status) && result.count != 0);
1331 CHECK_STATUS(status, NT_STATUS_OK);
1333 if (total_deleted != num_files) {
1334 printf("error: deleted %d - expected to delete %d\n",
1335 total_deleted, num_files);
1340 smb_raw_exit(cli->session);
1341 smbcli_deltree(cli->tree, BASEDIR);
1347 static int ealist_cmp(union smb_search_data *r1, union smb_search_data *r2)
1349 return strcmp(r1->ea_list.name.s, r2->ea_list.name.s);
1353 testing of the rather strange ea_list level
1355 static bool test_ea_list(struct torture_context *tctx,
1356 struct smbcli_state *cli)
1361 union smb_search_first io;
1362 union smb_search_next nxt;
1363 struct multiple_result result;
1364 union smb_setfileinfo setfile;
1366 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1368 printf("Testing RAW_SEARCH_EA_LIST level\n");
1370 if (!torture_setting_bool(tctx, "search_ea_support", true) ||
1371 !torture_setting_bool(tctx, "ea_support", true)) {
1372 printf("..skipped per target configuration.\n");
1376 fnum = smbcli_open(cli->tree, BASEDIR "\\file1.txt", O_CREAT|O_RDWR, DENY_NONE);
1377 smbcli_close(cli->tree, fnum);
1379 fnum = smbcli_open(cli->tree, BASEDIR "\\file2.txt", O_CREAT|O_RDWR, DENY_NONE);
1380 smbcli_close(cli->tree, fnum);
1382 fnum = smbcli_open(cli->tree, BASEDIR "\\file3.txt", O_CREAT|O_RDWR, DENY_NONE);
1383 smbcli_close(cli->tree, fnum);
1385 setfile.generic.level = RAW_SFILEINFO_EA_SET;
1386 setfile.generic.in.file.path = BASEDIR "\\file2.txt";
1387 setfile.ea_set.in.num_eas = 2;
1388 setfile.ea_set.in.eas = talloc_array(tctx, struct ea_struct, 2);
1389 setfile.ea_set.in.eas[0].flags = 0;
1390 setfile.ea_set.in.eas[0].name.s = "EA ONE";
1391 setfile.ea_set.in.eas[0].value = data_blob_string_const("VALUE 1");
1392 setfile.ea_set.in.eas[1].flags = 0;
1393 setfile.ea_set.in.eas[1].name.s = "SECOND EA";
1394 setfile.ea_set.in.eas[1].value = data_blob_string_const("Value Two");
1396 status = smb_raw_setpathinfo(cli->tree, &setfile);
1397 CHECK_STATUS(status, NT_STATUS_OK);
1399 setfile.generic.in.file.path = BASEDIR "\\file3.txt";
1400 status = smb_raw_setpathinfo(cli->tree, &setfile);
1401 CHECK_STATUS(status, NT_STATUS_OK);
1403 ZERO_STRUCT(result);
1406 io.t2ffirst.level = RAW_SEARCH_TRANS2;
1407 io.t2ffirst.data_level = RAW_SEARCH_DATA_EA_LIST;
1408 io.t2ffirst.in.search_attrib = 0;
1409 io.t2ffirst.in.max_count = 2;
1410 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1411 io.t2ffirst.in.storage_type = 0;
1412 io.t2ffirst.in.pattern = BASEDIR "\\*";
1413 io.t2ffirst.in.num_names = 2;
1414 io.t2ffirst.in.ea_names = talloc_array(tctx, struct ea_name, 2);
1415 io.t2ffirst.in.ea_names[0].name.s = "SECOND EA";
1416 io.t2ffirst.in.ea_names[1].name.s = "THIRD EA";
1418 status = smb_raw_search_first(cli->tree, tctx,
1419 &io, &result, multiple_search_callback);
1420 CHECK_STATUS(status, NT_STATUS_OK);
1421 CHECK_VALUE(result.count, 2);
1423 nxt.t2fnext.level = RAW_SEARCH_TRANS2;
1424 nxt.t2fnext.data_level = RAW_SEARCH_DATA_EA_LIST;
1425 nxt.t2fnext.in.handle = io.t2ffirst.out.handle;
1426 nxt.t2fnext.in.max_count = 2;
1427 nxt.t2fnext.in.resume_key = result.list[1].ea_list.resume_key;
1428 nxt.t2fnext.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME | FLAG_TRANS2_FIND_CONTINUE;
1429 nxt.t2fnext.in.last_name = result.list[1].ea_list.name.s;
1430 nxt.t2fnext.in.num_names = 2;
1431 nxt.t2fnext.in.ea_names = talloc_array(tctx, struct ea_name, 2);
1432 nxt.t2fnext.in.ea_names[0].name.s = "SECOND EA";
1433 nxt.t2fnext.in.ea_names[1].name.s = "THIRD EA";
1435 status = smb_raw_search_next(cli->tree, tctx,
1436 &nxt, &result, multiple_search_callback);
1437 CHECK_STATUS(status, NT_STATUS_OK);
1439 /* we have to sort the result as different servers can return directories
1440 in different orders */
1441 TYPESAFE_QSORT(result.list, result.count, ealist_cmp);
1443 CHECK_VALUE(result.count, 3);
1444 CHECK_VALUE(result.list[0].ea_list.eas.num_eas, 2);
1445 CHECK_STRING(result.list[0].ea_list.name.s, "file1.txt");
1446 CHECK_STRING(result.list[0].ea_list.eas.eas[0].name.s, "SECOND EA");
1447 CHECK_VALUE(result.list[0].ea_list.eas.eas[0].value.length, 0);
1448 CHECK_STRING(result.list[0].ea_list.eas.eas[1].name.s, "THIRD EA");
1449 CHECK_VALUE(result.list[0].ea_list.eas.eas[1].value.length, 0);
1451 CHECK_STRING(result.list[1].ea_list.name.s, "file2.txt");
1452 CHECK_STRING(result.list[1].ea_list.eas.eas[0].name.s, "SECOND EA");
1453 CHECK_VALUE(result.list[1].ea_list.eas.eas[0].value.length, 9);
1454 CHECK_STRING((const char *)result.list[1].ea_list.eas.eas[0].value.data, "Value Two");
1455 CHECK_STRING(result.list[1].ea_list.eas.eas[1].name.s, "THIRD EA");
1456 CHECK_VALUE(result.list[1].ea_list.eas.eas[1].value.length, 0);
1458 CHECK_STRING(result.list[2].ea_list.name.s, "file3.txt");
1459 CHECK_STRING(result.list[2].ea_list.eas.eas[0].name.s, "SECOND EA");
1460 CHECK_VALUE(result.list[2].ea_list.eas.eas[0].value.length, 9);
1461 CHECK_STRING((const char *)result.list[2].ea_list.eas.eas[0].value.data, "Value Two");
1462 CHECK_STRING(result.list[2].ea_list.eas.eas[1].name.s, "THIRD EA");
1463 CHECK_VALUE(result.list[2].ea_list.eas.eas[1].value.length, 0);
1465 smb_raw_exit(cli->session);
1466 smbcli_deltree(cli->tree, BASEDIR);
1472 Test the behavior of max count parameter in TRANS2_FIND_FIRST2 and
1473 TRANS2_FIND_NEXT2 queries
1475 static bool test_max_count(struct torture_context *tctx,
1476 struct smbcli_state *cli)
1478 const int num_files = 2;
1483 struct multiple_result result;
1484 union smb_search_first io;
1485 union smb_search_next io2;
1487 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1489 torture_comment(tctx, "Creating %d files\n", num_files);
1491 for (i=num_files-1;i>=0;i--) {
1492 fname = talloc_asprintf(cli, BASEDIR "\\t%03d-%d.txt", i, i);
1493 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1495 torture_comment(tctx,
1496 "Failed to create %s - %s\n",
1497 fname, smbcli_errstr(cli->tree));
1502 smbcli_close(cli->tree, fnum);
1505 torture_comment(tctx, "Set max_count parameter to 0. "
1506 "This should return 1 entry\n");
1507 ZERO_STRUCT(result);
1508 result.tctx = talloc_new(tctx);
1510 io.t2ffirst.level = RAW_SEARCH_TRANS2;
1511 io.t2ffirst.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
1512 io.t2ffirst.in.search_attrib = 0;
1513 io.t2ffirst.in.max_count = 0;
1514 io.t2ffirst.in.flags = 0;
1515 io.t2ffirst.in.storage_type = 0;
1516 io.t2ffirst.in.pattern = BASEDIR "\\*.*";
1518 status = smb_raw_search_first(cli->tree, tctx,
1519 &io, &result, multiple_search_callback);
1520 CHECK_STATUS(status, NT_STATUS_OK);
1521 CHECK_VALUE(result.count, 1);
1523 torture_comment(tctx, "Set max_count to 1. This should also "
1524 "return 1 entry\n");
1525 io2.t2fnext.level = RAW_SEARCH_TRANS2;
1526 io2.t2fnext.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
1527 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
1528 io2.t2fnext.in.max_count = 1;
1529 io2.t2fnext.in.resume_key = 0;
1530 io2.t2fnext.in.flags = 0;
1531 io2.t2fnext.in.last_name =
1532 result.list[result.count-1].both_directory_info.name.s;
1534 status = smb_raw_search_next(cli->tree, tctx,
1535 &io2, &result, multiple_search_callback);
1536 CHECK_STATUS(status, NT_STATUS_OK);
1537 CHECK_VALUE(result.count, 2);
1539 smb_raw_exit(cli->session);
1540 smbcli_deltree(cli->tree, BASEDIR);
1546 basic testing of all RAW_SEARCH_* calls using a single file
1548 struct torture_suite *torture_raw_search(TALLOC_CTX *mem_ctx)
1550 struct torture_suite *suite = torture_suite_create(mem_ctx, "search");
1552 torture_suite_add_1smb_test(suite, "one file search", test_one_file);
1553 torture_suite_add_1smb_test(suite, "many files", test_many_files);
1554 torture_suite_add_1smb_test(suite, "sorted", test_sorted);
1555 torture_suite_add_1smb_test(suite, "modify search", test_modify_search);
1556 torture_suite_add_1smb_test(suite, "many dirs", test_many_dirs);
1557 torture_suite_add_1smb_test(suite, "os2 delete", test_os2_delete);
1558 torture_suite_add_1smb_test(suite, "ea list", test_ea_list);
1559 torture_suite_add_1smb_test(suite, "max count", test_max_count);