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 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "torture/torture.h"
23 #include "system/filesys.h"
24 #include "libcli/raw/libcliraw.h"
25 #include "libcli/libcli.h"
28 #define BASEDIR "\\testsearch"
31 callback function for single_search
33 static BOOL single_search_callback(void *private, union smb_search_data *file)
35 union smb_search_data *data = private;
43 do a single file (non-wildcard) search
45 NTSTATUS torture_single_search(struct smbcli_state *cli,
48 enum smb_search_level level,
50 union smb_search_data *data)
52 union smb_search_first io;
53 union smb_search_close c;
56 io.generic.level = level;
57 if (level == RAW_SEARCH_SEARCH ||
58 level == RAW_SEARCH_FFIRST ||
59 level == RAW_SEARCH_FUNIQUE) {
60 io.search_first.in.max_count = 1;
61 io.search_first.in.search_attrib = attrib;
62 io.search_first.in.pattern = pattern;
64 io.t2ffirst.in.search_attrib = attrib;
65 io.t2ffirst.in.max_count = 1;
66 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE;
67 io.t2ffirst.in.storage_type = 0;
68 io.t2ffirst.in.pattern = pattern;
71 status = smb_raw_search_first(cli->tree, mem_ctx,
72 &io, (void *)data, single_search_callback);
74 if (NT_STATUS_IS_OK(status) && level == RAW_SEARCH_FFIRST) {
75 c.fclose.level = RAW_FINDCLOSE_FCLOSE;
76 c.fclose.in.max_count = 1;
77 c.fclose.in.search_attrib = 0;
78 c.fclose.in.id = data->search.id;
79 status = smb_raw_search_close(cli->tree, &c);
88 enum smb_search_level level;
89 uint32_t capability_mask;
91 union smb_search_data data;
93 {"FFIRST", RAW_SEARCH_FFIRST, },
94 {"FUNIQUE", RAW_SEARCH_FUNIQUE, },
95 {"SEARCH", RAW_SEARCH_SEARCH, },
96 {"STANDARD", RAW_SEARCH_STANDARD, },
97 {"EA_SIZE", RAW_SEARCH_EA_SIZE, },
98 {"DIRECTORY_INFO", RAW_SEARCH_DIRECTORY_INFO, },
99 {"FULL_DIRECTORY_INFO", RAW_SEARCH_FULL_DIRECTORY_INFO, },
100 {"NAME_INFO", RAW_SEARCH_NAME_INFO, },
101 {"BOTH_DIRECTORY_INFO", RAW_SEARCH_BOTH_DIRECTORY_INFO, },
102 {"ID_FULL_DIRECTORY_INFO", RAW_SEARCH_ID_FULL_DIRECTORY_INFO, },
103 {"ID_BOTH_DIRECTORY_INFO", RAW_SEARCH_ID_BOTH_DIRECTORY_INFO, },
104 {"UNIX_INFO", RAW_SEARCH_UNIX_INFO, CAP_UNIX}
107 /* find a level in the table by name */
108 static union smb_search_data *find(const char *name)
111 for (i=0;i<ARRAY_SIZE(levels);i++) {
112 if (NT_STATUS_IS_OK(levels[i].status) &&
113 strcmp(levels[i].name, name) == 0) {
114 return &levels[i].data;
121 basic testing of all RAW_SEARCH_* calls using a single file
123 static BOOL test_one_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
127 const char *fname = "\\torture_search.txt";
128 const char *fname2 = "\\torture_search-NOTEXIST.txt";
131 union smb_fileinfo all_info, alt_info, name_info, internal_info;
132 union smb_search_data *s;
134 printf("Testing one file searches\n");
136 fnum = create_complex_file(cli, mem_ctx, fname);
138 printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
143 /* call all the levels */
144 for (i=0;i<ARRAY_SIZE(levels);i++) {
145 NTSTATUS expected_status;
146 uint32_t cap = cli->transport->negotiate.capabilities;
148 printf("testing %s\n", levels[i].name);
150 levels[i].status = torture_single_search(cli, mem_ctx, fname,
154 /* see if this server claims to support this level */
155 if ((cap & levels[i].capability_mask) != levels[i].capability_mask) {
156 printf("search level %s(%d) not supported by server\n",
157 levels[i].name, (int)levels[i].level);
161 if (!NT_STATUS_IS_OK(levels[i].status)) {
162 printf("search level %s(%d) failed - %s\n",
163 levels[i].name, (int)levels[i].level,
164 nt_errstr(levels[i].status));
169 status = torture_single_search(cli, mem_ctx, fname2,
173 expected_status = NT_STATUS_NO_SUCH_FILE;
174 if (levels[i].level == RAW_SEARCH_SEARCH ||
175 levels[i].level == RAW_SEARCH_FFIRST ||
176 levels[i].level == RAW_SEARCH_FUNIQUE) {
177 expected_status = STATUS_NO_MORE_FILES;
179 if (!NT_STATUS_EQUAL(status, expected_status)) {
180 printf("search level %s(%d) should fail with %s - %s\n",
181 levels[i].name, (int)levels[i].level,
182 nt_errstr(expected_status),
188 /* get the all_info file into to check against */
189 all_info.generic.level = RAW_FILEINFO_ALL_INFO;
190 all_info.generic.file.path = fname;
191 status = smb_raw_pathinfo(cli->tree, mem_ctx, &all_info);
192 if (!NT_STATUS_IS_OK(status)) {
193 printf("RAW_FILEINFO_ALL_INFO failed - %s\n", nt_errstr(status));
198 alt_info.generic.level = RAW_FILEINFO_ALT_NAME_INFO;
199 alt_info.generic.file.path = fname;
200 status = smb_raw_pathinfo(cli->tree, mem_ctx, &alt_info);
201 if (!NT_STATUS_IS_OK(status)) {
202 printf("RAW_FILEINFO_ALT_NAME_INFO failed - %s\n", nt_errstr(status));
207 internal_info.generic.level = RAW_FILEINFO_INTERNAL_INFORMATION;
208 internal_info.generic.file.path = fname;
209 status = smb_raw_pathinfo(cli->tree, mem_ctx, &internal_info);
210 if (!NT_STATUS_IS_OK(status)) {
211 printf("RAW_FILEINFO_INTERNAL_INFORMATION failed - %s\n", nt_errstr(status));
216 name_info.generic.level = RAW_FILEINFO_NAME_INFO;
217 name_info.generic.file.path = fname;
218 status = smb_raw_pathinfo(cli->tree, mem_ctx, &name_info);
219 if (!NT_STATUS_IS_OK(status)) {
220 printf("RAW_FILEINFO_NAME_INFO failed - %s\n", nt_errstr(status));
225 #define CHECK_VAL(name, sname1, field1, v, sname2, field2) do { \
228 if ((s->sname1.field1) != (v.sname2.out.field2)) { \
229 printf("(%s) %s/%s [0x%x] != %s/%s [0x%x]\n", \
231 #sname1, #field1, (int)s->sname1.field1, \
232 #sname2, #field2, (int)v.sname2.out.field2); \
237 #define CHECK_TIME(name, sname1, field1, v, sname2, field2) do { \
240 if (s->sname1.field1 != (~1 & nt_time_to_unix(v.sname2.out.field2))) { \
241 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
243 #sname1, #field1, timestring(mem_ctx, s->sname1.field1), \
244 #sname2, #field2, nt_time_string(mem_ctx, v.sname2.out.field2)); \
249 #define CHECK_NTTIME(name, sname1, field1, v, sname2, field2) do { \
252 if (s->sname1.field1 != v.sname2.out.field2) { \
253 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
255 #sname1, #field1, nt_time_string(mem_ctx, s->sname1.field1), \
256 #sname2, #field2, nt_time_string(mem_ctx, v.sname2.out.field2)); \
261 #define CHECK_STR(name, sname1, field1, v, sname2, field2) do { \
264 if (!s->sname1.field1 || strcmp(s->sname1.field1, v.sname2.out.field2.s)) { \
265 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
267 #sname1, #field1, s->sname1.field1, \
268 #sname2, #field2, v.sname2.out.field2.s); \
273 #define CHECK_WSTR(name, sname1, field1, v, sname2, field2, flags) do { \
276 if (!s->sname1.field1.s || \
277 strcmp(s->sname1.field1.s, v.sname2.out.field2.s) || \
278 wire_bad_flags(&s->sname1.field1, flags, cli)) { \
279 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
281 #sname1, #field1, s->sname1.field1.s, \
282 #sname2, #field2, v.sname2.out.field2.s); \
287 #define CHECK_NAME(name, sname1, field1, fname, flags) do { \
290 if (!s->sname1.field1.s || \
291 strcmp(s->sname1.field1.s, fname) || \
292 wire_bad_flags(&s->sname1.field1, flags, cli)) { \
293 printf("(%s) %s/%s [%s] != %s\n", \
295 #sname1, #field1, s->sname1.field1.s, \
301 #define CHECK_UNIX_NAME(name, sname1, field1, fname, flags) do { \
304 if (!s->sname1.field1 || \
305 strcmp(s->sname1.field1, fname)) { \
306 printf("(%s) %s/%s [%s] != %s\n", \
308 #sname1, #field1, s->sname1.field1, \
314 /* check that all the results are as expected */
315 CHECK_VAL("SEARCH", search, attrib, all_info, all_info, attrib&0xFFF);
316 CHECK_VAL("STANDARD", standard, attrib, all_info, all_info, attrib&0xFFF);
317 CHECK_VAL("EA_SIZE", ea_size, attrib, all_info, all_info, attrib&0xFFF);
318 CHECK_VAL("DIRECTORY_INFO", directory_info, attrib, all_info, all_info, attrib);
319 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, attrib, all_info, all_info, attrib);
320 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, attrib, all_info, all_info, attrib);
321 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, attrib, all_info, all_info, attrib);
322 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, attrib, all_info, all_info, attrib);
324 CHECK_TIME("SEARCH", search, write_time, all_info, all_info, write_time);
325 CHECK_TIME("STANDARD", standard, write_time, all_info, all_info, write_time);
326 CHECK_TIME("EA_SIZE", ea_size, write_time, all_info, all_info, write_time);
327 CHECK_TIME("STANDARD", standard, create_time, all_info, all_info, create_time);
328 CHECK_TIME("EA_SIZE", ea_size, create_time, all_info, all_info, create_time);
329 CHECK_TIME("STANDARD", standard, access_time, all_info, all_info, access_time);
330 CHECK_TIME("EA_SIZE", ea_size, access_time, all_info, all_info, access_time);
332 CHECK_NTTIME("DIRECTORY_INFO", directory_info, write_time, all_info, all_info, write_time);
333 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, write_time, all_info, all_info, write_time);
334 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, write_time, all_info, all_info, write_time);
335 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, write_time, all_info, all_info, write_time);
336 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, write_time, all_info, all_info, write_time);
338 CHECK_NTTIME("DIRECTORY_INFO", directory_info, create_time, all_info, all_info, create_time);
339 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, create_time, all_info, all_info, create_time);
340 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, create_time, all_info, all_info, create_time);
341 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, create_time, all_info, all_info, create_time);
342 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, create_time, all_info, all_info, create_time);
344 CHECK_NTTIME("DIRECTORY_INFO", directory_info, access_time, all_info, all_info, access_time);
345 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, access_time, all_info, all_info, access_time);
346 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, access_time, all_info, all_info, access_time);
347 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, access_time, all_info, all_info, access_time);
348 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, access_time, all_info, all_info, access_time);
350 CHECK_NTTIME("DIRECTORY_INFO", directory_info, change_time, all_info, all_info, change_time);
351 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, change_time, all_info, all_info, change_time);
352 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, change_time, all_info, all_info, change_time);
353 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, change_time, all_info, all_info, change_time);
354 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, change_time, all_info, all_info, change_time);
356 CHECK_VAL("SEARCH", search, size, all_info, all_info, size);
357 CHECK_VAL("STANDARD", standard, size, all_info, all_info, size);
358 CHECK_VAL("EA_SIZE", ea_size, size, all_info, all_info, size);
359 CHECK_VAL("DIRECTORY_INFO", directory_info, size, all_info, all_info, size);
360 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, size, all_info, all_info, size);
361 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, size, all_info, all_info, size);
362 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, size, all_info, all_info, size);
363 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, size, all_info, all_info, size);
364 CHECK_VAL("UNIX_INFO", unix_info, size, all_info, all_info, size);
366 CHECK_VAL("STANDARD", standard, alloc_size, all_info, all_info, alloc_size);
367 CHECK_VAL("EA_SIZE", ea_size, alloc_size, all_info, all_info, alloc_size);
368 CHECK_VAL("DIRECTORY_INFO", directory_info, alloc_size, all_info, all_info, alloc_size);
369 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, alloc_size, all_info, all_info, alloc_size);
370 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, alloc_size, all_info, all_info, alloc_size);
371 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, alloc_size, all_info, all_info, alloc_size);
372 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, alloc_size, all_info, all_info, alloc_size);
373 CHECK_VAL("UNIX_INFO", unix_info, alloc_size, all_info, all_info, alloc_size);
375 CHECK_VAL("EA_SIZE", ea_size, ea_size, all_info, all_info, ea_size);
376 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, ea_size, all_info, all_info, ea_size);
377 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, ea_size, all_info, all_info, ea_size);
378 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, ea_size, all_info, all_info, ea_size);
379 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, ea_size, all_info, all_info, ea_size);
381 CHECK_STR("SEARCH", search, name, alt_info, alt_name_info, fname);
382 CHECK_WSTR("BOTH_DIRECTORY_INFO", both_directory_info, short_name, alt_info, alt_name_info, fname, STR_UNICODE);
384 CHECK_NAME("STANDARD", standard, name, fname+1, 0);
385 CHECK_NAME("EA_SIZE", ea_size, name, fname+1, 0);
386 CHECK_NAME("DIRECTORY_INFO", directory_info, name, fname+1, STR_TERMINATE_ASCII);
387 CHECK_NAME("FULL_DIRECTORY_INFO", full_directory_info, name, fname+1, STR_TERMINATE_ASCII);
388 CHECK_NAME("NAME_INFO", name_info, name, fname+1, STR_TERMINATE_ASCII);
389 CHECK_NAME("BOTH_DIRECTORY_INFO", both_directory_info, name, fname+1, STR_TERMINATE_ASCII);
390 CHECK_NAME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, name, fname+1, STR_TERMINATE_ASCII);
391 CHECK_NAME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, name, fname+1, STR_TERMINATE_ASCII);
392 CHECK_UNIX_NAME("UNIX_INFO", unix_info, name, fname+1, STR_TERMINATE_ASCII);
394 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, file_id, internal_info, internal_information, file_id);
395 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, file_id, internal_info, internal_information, file_id);
398 smb_raw_exit(cli->session);
399 smbcli_unlink(cli->tree, fname);
405 struct multiple_result {
408 union smb_search_data *list;
412 callback function for multiple_search
414 static BOOL multiple_search_callback(void *private, union smb_search_data *file)
416 struct multiple_result *data = private;
420 data->list = talloc_realloc(data->mem_ctx,
422 union smb_search_data,
425 data->list[data->count-1] = *file;
430 enum continue_type {CONT_FLAGS, CONT_NAME, CONT_RESUME_KEY};
433 do a single file (non-wildcard) search
435 static NTSTATUS multiple_search(struct smbcli_state *cli,
438 enum smb_search_level level,
439 enum continue_type cont_type,
442 union smb_search_first io;
443 union smb_search_next io2;
445 const int per_search = 100;
446 struct multiple_result *result = data;
448 io.generic.level = level;
449 if (level == RAW_SEARCH_SEARCH) {
450 io.search_first.in.max_count = per_search;
451 io.search_first.in.search_attrib = 0;
452 io.search_first.in.pattern = pattern;
454 io.t2ffirst.in.search_attrib = 0;
455 io.t2ffirst.in.max_count = per_search;
456 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE_IF_END;
457 io.t2ffirst.in.storage_type = 0;
458 io.t2ffirst.in.pattern = pattern;
459 if (cont_type == CONT_RESUME_KEY) {
460 io.t2ffirst.in.flags |= FLAG_TRANS2_FIND_REQUIRE_RESUME |
461 FLAG_TRANS2_FIND_BACKUP_INTENT;
465 status = smb_raw_search_first(cli->tree, mem_ctx,
466 &io, data, multiple_search_callback);
469 while (NT_STATUS_IS_OK(status)) {
470 io2.generic.level = level;
471 if (level == RAW_SEARCH_SEARCH) {
472 io2.search_next.in.max_count = per_search;
473 io2.search_next.in.search_attrib = 0;
474 io2.search_next.in.id = result->list[result->count-1].search.id;
476 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
477 io2.t2fnext.in.max_count = per_search;
478 io2.t2fnext.in.resume_key = 0;
479 io2.t2fnext.in.flags = FLAG_TRANS2_FIND_CLOSE_IF_END;
480 io2.t2fnext.in.last_name = "";
482 case CONT_RESUME_KEY:
483 if (level == RAW_SEARCH_STANDARD) {
484 io2.t2fnext.in.resume_key =
485 result->list[result->count-1].standard.resume_key;
486 } else if (level == RAW_SEARCH_EA_SIZE) {
487 io2.t2fnext.in.resume_key =
488 result->list[result->count-1].ea_size.resume_key;
489 } else if (level == RAW_SEARCH_DIRECTORY_INFO) {
490 io2.t2fnext.in.resume_key =
491 result->list[result->count-1].directory_info.file_index;
493 io2.t2fnext.in.resume_key =
494 result->list[result->count-1].both_directory_info.file_index;
496 if (io2.t2fnext.in.resume_key == 0) {
497 printf("Server does not support resume by key\n");
498 return NT_STATUS_NOT_SUPPORTED;
500 io2.t2fnext.in.flags |= FLAG_TRANS2_FIND_REQUIRE_RESUME |
501 FLAG_TRANS2_FIND_BACKUP_INTENT;
504 if (level == RAW_SEARCH_STANDARD) {
505 io2.t2fnext.in.last_name =
506 result->list[result->count-1].standard.name.s;
507 } else if (level == RAW_SEARCH_EA_SIZE) {
508 io2.t2fnext.in.last_name =
509 result->list[result->count-1].ea_size.name.s;
510 } else if (level == RAW_SEARCH_DIRECTORY_INFO) {
511 io2.t2fnext.in.last_name =
512 result->list[result->count-1].directory_info.name.s;
514 io2.t2fnext.in.last_name =
515 result->list[result->count-1].both_directory_info.name.s;
519 io2.t2fnext.in.flags |= FLAG_TRANS2_FIND_CONTINUE;
524 status = smb_raw_search_next(cli->tree, mem_ctx,
525 &io2, data, multiple_search_callback);
526 if (!NT_STATUS_IS_OK(status)) {
529 if (level == RAW_SEARCH_SEARCH) {
530 if (io2.search_next.out.count == 0) {
533 } else if (io2.t2fnext.out.count == 0 ||
534 io2.t2fnext.out.end_of_search) {
542 #define CHECK_STATUS(status, correct) do { \
543 if (!NT_STATUS_EQUAL(status, correct)) { \
544 printf("(%s) Incorrect status %s - should be %s\n", \
545 __location__, nt_errstr(status), nt_errstr(correct)); \
550 #define CHECK_VALUE(v, correct) do { \
551 if ((v) != (correct)) { \
552 printf("(%s) Incorrect value %s=%ld - should be %ld\n", \
553 __location__, #v, (long)v, (long)correct); \
558 #define CHECK_STRING(v, correct) do { \
559 if (strcasecmp_m(v, correct) != 0) { \
560 printf("(%s) Incorrect value %s='%s' - should be '%s'\n", \
561 __location__, #v, v, correct); \
566 static int search_both_compare(union smb_search_data *d1, union smb_search_data *d2)
568 return strcmp_safe(d1->both_directory_info.name.s, d2->both_directory_info.name.s);
571 static int search_standard_compare(union smb_search_data *d1, union smb_search_data *d2)
573 return strcmp_safe(d1->standard.name.s, d2->standard.name.s);
576 static int search_ea_size_compare(union smb_search_data *d1, union smb_search_data *d2)
578 return strcmp_safe(d1->ea_size.name.s, d2->ea_size.name.s);
581 static int search_directory_info_compare(union smb_search_data *d1, union smb_search_data *d2)
583 return strcmp_safe(d1->directory_info.name.s, d2->directory_info.name.s);
586 static int search_old_compare(union smb_search_data *d1, union smb_search_data *d2)
588 return strcmp_safe(d1->search.name, d2->search.name);
593 basic testing of search calls using many files
595 static BOOL test_many_files(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
597 const int num_files = 700;
602 struct multiple_result result;
605 const char *cont_name;
606 enum smb_search_level level;
607 enum continue_type cont_type;
609 {"SEARCH", "ID", RAW_SEARCH_SEARCH, CONT_RESUME_KEY},
610 {"BOTH_DIRECTORY_INFO", "NAME", RAW_SEARCH_BOTH_DIRECTORY_INFO, CONT_NAME},
611 {"BOTH_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_BOTH_DIRECTORY_INFO, CONT_FLAGS},
612 {"BOTH_DIRECTORY_INFO", "KEY", RAW_SEARCH_BOTH_DIRECTORY_INFO, CONT_RESUME_KEY},
613 {"STANDARD", "FLAGS", RAW_SEARCH_STANDARD, CONT_FLAGS},
614 {"STANDARD", "KEY", RAW_SEARCH_STANDARD, CONT_RESUME_KEY},
615 {"STANDARD", "NAME", RAW_SEARCH_STANDARD, CONT_NAME},
616 {"EA_SIZE", "FLAGS", RAW_SEARCH_EA_SIZE, CONT_FLAGS},
617 {"EA_SIZE", "KEY", RAW_SEARCH_EA_SIZE, CONT_RESUME_KEY},
618 {"EA_SIZE", "NAME", RAW_SEARCH_EA_SIZE, CONT_NAME},
619 {"DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DIRECTORY_INFO, CONT_FLAGS},
620 {"DIRECTORY_INFO", "KEY", RAW_SEARCH_DIRECTORY_INFO, CONT_RESUME_KEY},
621 {"DIRECTORY_INFO", "NAME", RAW_SEARCH_DIRECTORY_INFO, CONT_NAME}
624 if (!torture_setup_dir(cli, BASEDIR)) {
628 printf("Creating %d files\n", num_files);
630 for (i=0;i<num_files;i++) {
631 fname = talloc_asprintf(cli, BASEDIR "\\t%03d-%d.txt", i, i);
632 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
634 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
639 smbcli_close(cli->tree, fnum);
643 for (t=0;t<ARRAY_SIZE(search_types);t++) {
645 result.mem_ctx = talloc_new(mem_ctx);
647 printf("Continue %s via %s\n", search_types[t].name, search_types[t].cont_name);
649 status = multiple_search(cli, mem_ctx, BASEDIR "\\*.*",
650 search_types[t].level,
651 search_types[t].cont_type,
654 if (!NT_STATUS_IS_OK(status)) {
655 printf("search failed - %s\n", nt_errstr(status));
659 CHECK_VALUE(result.count, num_files);
661 if (search_types[t].level == RAW_SEARCH_BOTH_DIRECTORY_INFO) {
662 qsort(result.list, result.count, sizeof(result.list[0]),
663 QSORT_CAST search_both_compare);
664 } else if (search_types[t].level == RAW_SEARCH_STANDARD) {
665 qsort(result.list, result.count, sizeof(result.list[0]),
666 QSORT_CAST search_standard_compare);
667 } else if (search_types[t].level == RAW_SEARCH_EA_SIZE) {
668 qsort(result.list, result.count, sizeof(result.list[0]),
669 QSORT_CAST search_ea_size_compare);
670 } else if (search_types[t].level == RAW_SEARCH_DIRECTORY_INFO) {
671 qsort(result.list, result.count, sizeof(result.list[0]),
672 QSORT_CAST search_directory_info_compare);
674 qsort(result.list, result.count, sizeof(result.list[0]),
675 QSORT_CAST search_old_compare);
678 for (i=0;i<result.count;i++) {
680 if (search_types[t].level == RAW_SEARCH_BOTH_DIRECTORY_INFO) {
681 s = result.list[i].both_directory_info.name.s;
682 } else if (search_types[t].level == RAW_SEARCH_STANDARD) {
683 s = result.list[i].standard.name.s;
684 } else if (search_types[t].level == RAW_SEARCH_EA_SIZE) {
685 s = result.list[i].ea_size.name.s;
686 } else if (search_types[t].level == RAW_SEARCH_DIRECTORY_INFO) {
687 s = result.list[i].directory_info.name.s;
689 s = result.list[i].search.name;
691 fname = talloc_asprintf(cli, "t%03d-%d.txt", i, i);
692 if (strcmp(fname, s)) {
693 printf("Incorrect name %s at entry %d\n", s, i);
699 talloc_free(result.mem_ctx);
703 smb_raw_exit(cli->session);
704 smbcli_deltree(cli->tree, BASEDIR);
710 check a individual file result
712 static BOOL check_result(struct multiple_result *result, const char *name, BOOL exist, uint32_t attrib)
715 for (i=0;i<result->count;i++) {
716 if (strcmp(name, result->list[i].both_directory_info.name.s) == 0) break;
718 if (i == result->count) {
720 printf("failed: '%s' should exist with attribute %s\n",
721 name, attrib_string(result->list, attrib));
728 printf("failed: '%s' should NOT exist (has attribute %s)\n",
729 name, attrib_string(result->list, result->list[i].both_directory_info.attrib));
733 if ((result->list[i].both_directory_info.attrib&0xFFF) != attrib) {
734 printf("failed: '%s' should have attribute 0x%x (has 0x%x)\n",
736 attrib, result->list[i].both_directory_info.attrib);
743 test what happens when the directory is modified during a search
745 static BOOL test_modify_search(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
747 const int num_files = 20;
752 struct multiple_result result;
753 union smb_search_first io;
754 union smb_search_next io2;
755 union smb_setfileinfo sfinfo;
757 if (!torture_setup_dir(cli, BASEDIR)) {
761 printf("Creating %d files\n", num_files);
763 for (i=num_files-1;i>=0;i--) {
764 fname = talloc_asprintf(cli, BASEDIR "\\t%03d-%d.txt", i, i);
765 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
767 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
772 smbcli_close(cli->tree, fnum);
775 printf("pulling the first file\n");
777 result.mem_ctx = talloc_new(mem_ctx);
779 io.generic.level = RAW_SEARCH_BOTH_DIRECTORY_INFO;
780 io.t2ffirst.in.search_attrib = 0;
781 io.t2ffirst.in.max_count = 0;
782 io.t2ffirst.in.flags = 0;
783 io.t2ffirst.in.storage_type = 0;
784 io.t2ffirst.in.pattern = BASEDIR "\\*.*";
786 status = smb_raw_search_first(cli->tree, mem_ctx,
787 &io, &result, multiple_search_callback);
788 CHECK_STATUS(status, NT_STATUS_OK);
789 CHECK_VALUE(result.count, 1);
791 printf("pulling the second file\n");
792 io2.generic.level = RAW_SEARCH_BOTH_DIRECTORY_INFO;
793 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
794 io2.t2fnext.in.max_count = 1;
795 io2.t2fnext.in.resume_key = 0;
796 io2.t2fnext.in.flags = 0;
797 io2.t2fnext.in.last_name = result.list[result.count-1].both_directory_info.name.s;
799 status = smb_raw_search_next(cli->tree, mem_ctx,
800 &io2, &result, multiple_search_callback);
801 CHECK_STATUS(status, NT_STATUS_OK);
802 CHECK_VALUE(result.count, 2);
806 printf("Changing attributes and deleting\n");
807 smbcli_open(cli->tree, BASEDIR "\\T003-03.txt.2", O_CREAT|O_RDWR, DENY_NONE);
808 smbcli_open(cli->tree, BASEDIR "\\T013-13.txt.2", O_CREAT|O_RDWR, DENY_NONE);
809 fnum = create_complex_file(cli, mem_ctx, BASEDIR "\\T013-13.txt.3");
810 smbcli_unlink(cli->tree, BASEDIR "\\T014-14.txt");
811 torture_set_file_attribute(cli->tree, BASEDIR "\\T015-15.txt", FILE_ATTRIBUTE_HIDDEN);
812 torture_set_file_attribute(cli->tree, BASEDIR "\\T016-16.txt", FILE_ATTRIBUTE_NORMAL);
813 torture_set_file_attribute(cli->tree, BASEDIR "\\T017-17.txt", FILE_ATTRIBUTE_SYSTEM);
814 torture_set_file_attribute(cli->tree, BASEDIR "\\T018-18.txt", 0);
815 sfinfo.generic.level = RAW_SFILEINFO_DISPOSITION_INFORMATION;
816 sfinfo.generic.file.fnum = fnum;
817 sfinfo.disposition_info.in.delete_on_close = 1;
818 status = smb_raw_setfileinfo(cli->tree, &sfinfo);
819 CHECK_STATUS(status, NT_STATUS_OK);
821 io2.generic.level = RAW_SEARCH_BOTH_DIRECTORY_INFO;
822 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
823 io2.t2fnext.in.max_count = num_files + 3;
824 io2.t2fnext.in.resume_key = 0;
825 io2.t2fnext.in.flags = 0;
826 io2.t2fnext.in.last_name = ".";
828 status = smb_raw_search_next(cli->tree, mem_ctx,
829 &io2, &result, multiple_search_callback);
830 CHECK_STATUS(status, NT_STATUS_OK);
831 CHECK_VALUE(result.count, 20);
833 ret &= check_result(&result, "t009-9.txt", True, FILE_ATTRIBUTE_ARCHIVE);
834 ret &= check_result(&result, "t014-14.txt", False, 0);
835 ret &= check_result(&result, "t015-15.txt", False, 0);
836 ret &= check_result(&result, "t016-16.txt", True, FILE_ATTRIBUTE_NORMAL);
837 ret &= check_result(&result, "t017-17.txt", False, 0);
838 ret &= check_result(&result, "t018-18.txt", True, FILE_ATTRIBUTE_ARCHIVE);
839 ret &= check_result(&result, "t019-19.txt", True, FILE_ATTRIBUTE_ARCHIVE);
840 ret &= check_result(&result, "T013-13.txt.2", True, FILE_ATTRIBUTE_ARCHIVE);
841 ret &= check_result(&result, "T003-3.txt.2", False, 0);
842 ret &= check_result(&result, "T013-13.txt.3", True, FILE_ATTRIBUTE_ARCHIVE);
845 for (i=0;i<result.count;i++) {
846 printf("%s %s (0x%x)\n",
847 result.list[i].both_directory_info.name.s,
848 attrib_string(mem_ctx, result.list[i].both_directory_info.attrib),
849 result.list[i].both_directory_info.attrib);
854 smb_raw_exit(cli->session);
855 smbcli_deltree(cli->tree, BASEDIR);
862 testing if directories always come back sorted
864 static BOOL test_sorted(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
866 const int num_files = 700;
871 struct multiple_result result;
873 if (!torture_setup_dir(cli, BASEDIR)) {
877 printf("Creating %d files\n", num_files);
879 for (i=0;i<num_files;i++) {
880 fname = talloc_asprintf(cli, BASEDIR "\\%s.txt", generate_random_str_list(mem_ctx, 10, "abcdefgh"));
881 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
883 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
888 smbcli_close(cli->tree, fnum);
893 result.mem_ctx = mem_ctx;
895 status = multiple_search(cli, mem_ctx, BASEDIR "\\*.*",
896 RAW_SEARCH_BOTH_DIRECTORY_INFO,
898 CHECK_STATUS(status, NT_STATUS_OK);
899 CHECK_VALUE(result.count, num_files);
901 for (i=0;i<num_files-1;i++) {
902 const char *name1, *name2;
903 name1 = result.list[i].both_directory_info.name.s;
904 name2 = result.list[i+1].both_directory_info.name.s;
905 if (strcasecmp_m(name1, name2) > 0) {
906 printf("non-alphabetical order at entry %d '%s' '%s'\n",
908 printf("Server does not produce sorted directory listings (not an error)\n");
913 talloc_free(result.list);
916 smb_raw_exit(cli->session);
917 smbcli_deltree(cli->tree, BASEDIR);
925 basic testing of many old style search calls using separate dirs
927 static BOOL test_many_dirs(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
929 const int num_dirs = 100;
934 union smb_search_data *file, *file2, *file3;
936 if (!torture_setup_dir(cli, BASEDIR)) {
940 printf("Creating %d dirs\n", num_dirs);
942 for (i=0;i<num_dirs;i++) {
943 dname = talloc_asprintf(cli, BASEDIR "\\d%d", i);
944 status = smbcli_mkdir(cli->tree, dname);
945 if (!NT_STATUS_IS_OK(status)) {
946 printf("(%s) Failed to create %s - %s\n",
947 __location__, dname, nt_errstr(status));
953 fname = talloc_asprintf(cli, BASEDIR "\\d%d\\f%d-%d.txt", i, i, n);
954 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
956 printf("(%s) Failed to create %s - %s\n",
957 __location__, fname, smbcli_errstr(cli->tree));
962 smbcli_close(cli->tree, fnum);
968 file = talloc_zero_array(mem_ctx, union smb_search_data, num_dirs);
969 file2 = talloc_zero_array(mem_ctx, union smb_search_data, num_dirs);
970 file3 = talloc_zero_array(mem_ctx, union smb_search_data, num_dirs);
972 printf("Search first on %d dirs\n", num_dirs);
974 for (i=0;i<num_dirs;i++) {
975 union smb_search_first io;
976 io.generic.level = RAW_SEARCH_SEARCH;
977 io.search_first.in.max_count = 1;
978 io.search_first.in.search_attrib = 0;
979 io.search_first.in.pattern = talloc_asprintf(mem_ctx, BASEDIR "\\d%d\\*.txt", i);
980 fname = talloc_asprintf(mem_ctx, "f%d-", i);
982 io.search_first.out.count = 0;
984 status = smb_raw_search_first(cli->tree, mem_ctx,
985 &io, (void *)&file[i], single_search_callback);
986 if (io.search_first.out.count != 1) {
987 printf("(%s) search first gave %d entries for dir %d - %s\n",
988 __location__, io.search_first.out.count, i, nt_errstr(status));
992 CHECK_STATUS(status, NT_STATUS_OK);
993 if (strncasecmp(file[i].search.name, fname, strlen(fname)) != 0) {
994 printf("(%s) incorrect name '%s' expected '%s'[12].txt\n",
995 __location__, file[i].search.name, fname);
1003 printf("Search next on %d dirs\n", num_dirs);
1005 for (i=0;i<num_dirs;i++) {
1006 union smb_search_next io2;
1008 io2.generic.level = RAW_SEARCH_SEARCH;
1009 io2.search_next.in.max_count = 1;
1010 io2.search_next.in.search_attrib = 0;
1011 io2.search_next.in.id = file[i].search.id;
1012 fname = talloc_asprintf(mem_ctx, "f%d-", i);
1014 io2.search_next.out.count = 0;
1016 status = smb_raw_search_next(cli->tree, mem_ctx,
1017 &io2, (void *)&file2[i], single_search_callback);
1018 if (io2.search_next.out.count != 1) {
1019 printf("(%s) search next gave %d entries for dir %d - %s\n",
1020 __location__, io2.search_next.out.count, i, nt_errstr(status));
1024 CHECK_STATUS(status, NT_STATUS_OK);
1025 if (strncasecmp(file2[i].search.name, fname, strlen(fname)) != 0) {
1026 printf("(%s) incorrect name '%s' expected '%s'[12].txt\n",
1027 __location__, file2[i].search.name, fname);
1036 printf("Search next (rewind) on %d dirs\n", num_dirs);
1038 for (i=0;i<num_dirs;i++) {
1039 union smb_search_next io2;
1041 io2.generic.level = RAW_SEARCH_SEARCH;
1042 io2.search_next.in.max_count = 1;
1043 io2.search_next.in.search_attrib = 0;
1044 io2.search_next.in.id = file[i].search.id;
1045 fname = talloc_asprintf(mem_ctx, "f%d-", i);
1046 io2.search_next.out.count = 0;
1048 status = smb_raw_search_next(cli->tree, mem_ctx,
1049 &io2, (void *)&file3[i], single_search_callback);
1050 if (io2.search_next.out.count != 1) {
1051 printf("(%s) search next gave %d entries for dir %d - %s\n",
1052 __location__, io2.search_next.out.count, i, nt_errstr(status));
1056 CHECK_STATUS(status, NT_STATUS_OK);
1058 if (strncasecmp(file3[i].search.name, file2[i].search.name, 3) != 0) {
1059 printf("(%s) incorrect name '%s' on rewind at dir %d\n",
1060 __location__, file2[i].search.name, i);
1065 if (strcmp(file3[i].search.name, file2[i].search.name) != 0) {
1066 printf("(%s) server did not rewind - got '%s' expected '%s'\n",
1067 __location__, file3[i].search.name, file2[i].search.name);
1077 smb_raw_exit(cli->session);
1078 smbcli_deltree(cli->tree, BASEDIR);
1085 testing of OS/2 style delete
1087 static BOOL test_os2_delete(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1089 const int num_files = 700;
1090 const int delete_count = 4;
1091 int total_deleted = 0;
1096 union smb_search_first io;
1097 union smb_search_next io2;
1098 struct multiple_result result;
1100 if (!torture_setup_dir(cli, BASEDIR)) {
1104 printf("Testing OS/2 style delete on %d files\n", num_files);
1106 for (i=0;i<num_files;i++) {
1107 fname = talloc_asprintf(cli, BASEDIR "\\file%u.txt", i);
1108 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1110 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
1115 smbcli_close(cli->tree, fnum);
1119 ZERO_STRUCT(result);
1120 result.mem_ctx = mem_ctx;
1122 io.t2ffirst.level = RAW_SEARCH_EA_SIZE;
1123 io.t2ffirst.in.search_attrib = 0;
1124 io.t2ffirst.in.max_count = 100;
1125 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1126 io.t2ffirst.in.storage_type = 0;
1127 io.t2ffirst.in.pattern = BASEDIR "\\*";
1129 status = smb_raw_search_first(cli->tree, mem_ctx,
1130 &io, &result, multiple_search_callback);
1131 CHECK_STATUS(status, NT_STATUS_OK);
1133 for (i=0;i<MIN(result.count, delete_count);i++) {
1134 fname = talloc_asprintf(cli, BASEDIR "\\%s", result.list[i].ea_size.name.s);
1135 status = smbcli_unlink(cli->tree, fname);
1136 CHECK_STATUS(status, NT_STATUS_OK);
1141 io2.t2fnext.level = RAW_SEARCH_EA_SIZE;
1142 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
1143 io2.t2fnext.in.max_count = 100;
1144 io2.t2fnext.in.resume_key = result.list[i-1].ea_size.resume_key;
1145 io2.t2fnext.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1146 io2.t2fnext.in.last_name = result.list[i-1].ea_size.name.s;
1149 ZERO_STRUCT(result);
1150 result.mem_ctx = mem_ctx;
1152 status = smb_raw_search_next(cli->tree, mem_ctx,
1153 &io2, &result, multiple_search_callback);
1154 if (!NT_STATUS_IS_OK(status)) {
1158 for (i=0;i<MIN(result.count, delete_count);i++) {
1159 fname = talloc_asprintf(cli, BASEDIR "\\%s", result.list[i].ea_size.name.s);
1160 status = smbcli_unlink(cli->tree, fname);
1161 CHECK_STATUS(status, NT_STATUS_OK);
1167 io2.t2fnext.in.resume_key = result.list[i-1].ea_size.resume_key;
1168 io2.t2fnext.in.last_name = result.list[i-1].ea_size.name.s;
1170 } while (NT_STATUS_IS_OK(status) && result.count != 0);
1172 CHECK_STATUS(status, NT_STATUS_OK);
1174 if (total_deleted != num_files) {
1175 printf("error: deleted %d - expected to delete %d\n",
1176 total_deleted, num_files);
1181 smb_raw_exit(cli->session);
1182 smbcli_deltree(cli->tree, BASEDIR);
1188 static int ealist_cmp(union smb_search_data *r1, union smb_search_data *r2)
1190 return strcmp(r1->ea_list.name.s, r2->ea_list.name.s);
1194 testing of the rather strange ea_list level
1196 static BOOL test_ea_list(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1201 union smb_search_first io;
1202 union smb_search_next nxt;
1203 struct multiple_result result;
1204 union smb_setfileinfo setfile;
1206 if (!torture_setup_dir(cli, BASEDIR)) {
1210 printf("Testing RAW_SEARCH_EA_LIST level\n");
1212 fnum = smbcli_open(cli->tree, BASEDIR "\\file1.txt", O_CREAT|O_RDWR, DENY_NONE);
1213 smbcli_close(cli->tree, fnum);
1215 fnum = smbcli_open(cli->tree, BASEDIR "\\file2.txt", O_CREAT|O_RDWR, DENY_NONE);
1216 smbcli_close(cli->tree, fnum);
1218 fnum = smbcli_open(cli->tree, BASEDIR "\\file3.txt", O_CREAT|O_RDWR, DENY_NONE);
1219 smbcli_close(cli->tree, fnum);
1221 setfile.generic.level = RAW_SFILEINFO_EA_SET;
1222 setfile.generic.file.path = BASEDIR "\\file2.txt";
1223 setfile.ea_set.in.num_eas = 2;
1224 setfile.ea_set.in.eas = talloc_array(mem_ctx, struct ea_struct, 2);
1225 setfile.ea_set.in.eas[0].flags = 0;
1226 setfile.ea_set.in.eas[0].name.s = "EA ONE";
1227 setfile.ea_set.in.eas[0].value = data_blob_string_const("VALUE 1");
1228 setfile.ea_set.in.eas[1].flags = 0;
1229 setfile.ea_set.in.eas[1].name.s = "SECOND EA";
1230 setfile.ea_set.in.eas[1].value = data_blob_string_const("Value Two");
1232 status = smb_raw_setpathinfo(cli->tree, &setfile);
1233 CHECK_STATUS(status, NT_STATUS_OK);
1235 setfile.generic.file.path = BASEDIR "\\file3.txt";
1236 status = smb_raw_setpathinfo(cli->tree, &setfile);
1237 CHECK_STATUS(status, NT_STATUS_OK);
1239 ZERO_STRUCT(result);
1240 result.mem_ctx = mem_ctx;
1242 io.t2ffirst.level = RAW_SEARCH_EA_LIST;
1243 io.t2ffirst.in.search_attrib = 0;
1244 io.t2ffirst.in.max_count = 2;
1245 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1246 io.t2ffirst.in.storage_type = 0;
1247 io.t2ffirst.in.pattern = BASEDIR "\\*";
1248 io.t2ffirst.in.num_names = 2;
1249 io.t2ffirst.in.ea_names = talloc_array(mem_ctx, struct ea_name, 2);
1250 io.t2ffirst.in.ea_names[0].name.s = "SECOND EA";
1251 io.t2ffirst.in.ea_names[1].name.s = "THIRD EA";
1253 status = smb_raw_search_first(cli->tree, mem_ctx,
1254 &io, &result, multiple_search_callback);
1255 CHECK_STATUS(status, NT_STATUS_OK);
1256 CHECK_VALUE(result.count, 2);
1258 nxt.t2fnext.level = RAW_SEARCH_EA_LIST;
1259 nxt.t2fnext.in.handle = io.t2ffirst.out.handle;
1260 nxt.t2fnext.in.max_count = 2;
1261 nxt.t2fnext.in.resume_key = result.list[1].ea_list.resume_key;
1262 nxt.t2fnext.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME | FLAG_TRANS2_FIND_CONTINUE;
1263 nxt.t2fnext.in.last_name = result.list[1].ea_list.name.s;
1264 nxt.t2fnext.in.num_names = 2;
1265 nxt.t2fnext.in.ea_names = talloc_array(mem_ctx, struct ea_name, 2);
1266 nxt.t2fnext.in.ea_names[0].name.s = "SECOND EA";
1267 nxt.t2fnext.in.ea_names[1].name.s = "THIRD EA";
1269 status = smb_raw_search_next(cli->tree, mem_ctx,
1270 &nxt, &result, multiple_search_callback);
1271 CHECK_STATUS(status, NT_STATUS_OK);
1273 /* we have to sort the result as different servers can return directories
1274 in different orders */
1275 qsort(result.list, result.count, sizeof(result.list[0]),
1276 (comparison_fn_t)ealist_cmp);
1278 CHECK_VALUE(result.count, 3);
1279 CHECK_VALUE(result.list[0].ea_list.eas.num_eas, 2);
1280 CHECK_STRING(result.list[0].ea_list.name.s, "file1.txt");
1281 CHECK_STRING(result.list[0].ea_list.eas.eas[0].name.s, "SECOND EA");
1282 CHECK_VALUE(result.list[0].ea_list.eas.eas[0].value.length, 0);
1283 CHECK_STRING(result.list[0].ea_list.eas.eas[1].name.s, "THIRD EA");
1284 CHECK_VALUE(result.list[0].ea_list.eas.eas[1].value.length, 0);
1286 CHECK_STRING(result.list[1].ea_list.name.s, "file2.txt");
1287 CHECK_STRING(result.list[1].ea_list.eas.eas[0].name.s, "SECOND EA");
1288 CHECK_VALUE(result.list[1].ea_list.eas.eas[0].value.length, 9);
1289 CHECK_STRING((const char *)result.list[1].ea_list.eas.eas[0].value.data, "Value Two");
1290 CHECK_STRING(result.list[1].ea_list.eas.eas[1].name.s, "THIRD EA");
1291 CHECK_VALUE(result.list[1].ea_list.eas.eas[1].value.length, 0);
1293 CHECK_STRING(result.list[2].ea_list.name.s, "file3.txt");
1294 CHECK_STRING(result.list[2].ea_list.eas.eas[0].name.s, "SECOND EA");
1295 CHECK_VALUE(result.list[2].ea_list.eas.eas[0].value.length, 9);
1296 CHECK_STRING((const char *)result.list[2].ea_list.eas.eas[0].value.data, "Value Two");
1297 CHECK_STRING(result.list[2].ea_list.eas.eas[1].name.s, "THIRD EA");
1298 CHECK_VALUE(result.list[2].ea_list.eas.eas[1].value.length, 0);
1301 smb_raw_exit(cli->session);
1302 smbcli_deltree(cli->tree, BASEDIR);
1310 basic testing of all RAW_SEARCH_* calls using a single file
1312 BOOL torture_raw_search(void)
1314 struct smbcli_state *cli;
1316 TALLOC_CTX *mem_ctx;
1318 if (!torture_open_connection(&cli)) {
1322 mem_ctx = talloc_init("torture_search");
1324 ret &= test_one_file(cli, mem_ctx);
1325 ret &= test_many_files(cli, mem_ctx);
1326 ret &= test_sorted(cli, mem_ctx);
1327 ret &= test_modify_search(cli, mem_ctx);
1328 ret &= test_many_dirs(cli, mem_ctx);
1329 ret &= test_os2_delete(cli, mem_ctx);
1330 ret &= test_ea_list(cli, mem_ctx);
1332 torture_close_connection(cli);
1333 talloc_free(mem_ctx);