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 "torture/torture.h"
22 #include "system/filesys.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "libcli/libcli.h"
25 #include "torture/util.h"
28 #define BASEDIR "\\testsearch"
31 callback function for single_search
33 static BOOL single_search_callback(void *private, const union smb_search_data *file)
35 union smb_search_data *data = private;
43 do a single file (non-wildcard) search
45 _PUBLIC_ NTSTATUS torture_single_search(struct smbcli_state *cli,
48 enum smb_search_level level,
49 enum smb_search_data_level data_level,
51 union smb_search_data *data)
53 union smb_search_first io;
54 union smb_search_close c;
58 case RAW_SEARCH_SEARCH:
59 case RAW_SEARCH_FFIRST:
60 case RAW_SEARCH_FUNIQUE:
61 io.search_first.level = level;
62 io.search_first.data_level = RAW_SEARCH_DATA_SEARCH;
63 io.search_first.in.max_count = 1;
64 io.search_first.in.search_attrib = attrib;
65 io.search_first.in.pattern = pattern;
68 case RAW_SEARCH_TRANS2:
69 io.t2ffirst.level = RAW_SEARCH_TRANS2;
70 io.t2ffirst.data_level = data_level;
71 io.t2ffirst.in.search_attrib = attrib;
72 io.t2ffirst.in.max_count = 1;
73 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE;
74 io.t2ffirst.in.storage_type = 0;
75 io.t2ffirst.in.pattern = pattern;
79 return NT_STATUS_INVALID_LEVEL;
82 status = smb_raw_search_first(cli->tree, mem_ctx,
83 &io, (void *)data, single_search_callback);
85 if (NT_STATUS_IS_OK(status) && level == RAW_SEARCH_FFIRST) {
86 c.fclose.level = RAW_FINDCLOSE_FCLOSE;
87 c.fclose.in.max_count = 1;
88 c.fclose.in.search_attrib = 0;
89 c.fclose.in.id = data->search.id;
90 status = smb_raw_search_close(cli->tree, &c);
99 enum smb_search_level level;
100 enum smb_search_data_level data_level;
102 int resume_key_offset;
103 uint32_t capability_mask;
105 union smb_search_data data;
108 RAW_SEARCH_FFIRST, RAW_SEARCH_DATA_SEARCH,
109 offsetof(union smb_search_data, search.name),
113 RAW_SEARCH_FUNIQUE, RAW_SEARCH_DATA_SEARCH,
114 offsetof(union smb_search_data, search.name),
118 RAW_SEARCH_SEARCH, RAW_SEARCH_DATA_SEARCH,
119 offsetof(union smb_search_data, search.name),
123 RAW_SEARCH_TRANS2, RAW_SEARCH_DATA_STANDARD,
124 offsetof(union smb_search_data, standard.name.s),
125 offsetof(union smb_search_data, standard.resume_key),
128 RAW_SEARCH_TRANS2, RAW_SEARCH_DATA_EA_SIZE,
129 offsetof(union smb_search_data, ea_size.name.s),
130 offsetof(union smb_search_data, ea_size.resume_key),
133 RAW_SEARCH_TRANS2, RAW_SEARCH_DATA_DIRECTORY_INFO,
134 offsetof(union smb_search_data, directory_info.name.s),
135 offsetof(union smb_search_data, directory_info.file_index),
137 {"FULL_DIRECTORY_INFO",
138 RAW_SEARCH_TRANS2, RAW_SEARCH_DATA_FULL_DIRECTORY_INFO,
139 offsetof(union smb_search_data, full_directory_info.name.s),
140 offsetof(union smb_search_data, full_directory_info.file_index),
143 RAW_SEARCH_TRANS2, RAW_SEARCH_DATA_NAME_INFO,
144 offsetof(union smb_search_data, name_info.name.s),
145 offsetof(union smb_search_data, name_info.file_index),
147 {"BOTH_DIRECTORY_INFO",
148 RAW_SEARCH_TRANS2, RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO,
149 offsetof(union smb_search_data, both_directory_info.name.s),
150 offsetof(union smb_search_data, both_directory_info.file_index),
152 {"ID_FULL_DIRECTORY_INFO",
153 RAW_SEARCH_TRANS2, RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO,
154 offsetof(union smb_search_data, id_full_directory_info.name.s),
155 offsetof(union smb_search_data, id_full_directory_info.file_index),
157 {"ID_BOTH_DIRECTORY_INFO",
158 RAW_SEARCH_TRANS2, RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO,
159 offsetof(union smb_search_data, id_both_directory_info.name.s),
160 offsetof(union smb_search_data, id_both_directory_info.file_index),
163 RAW_SEARCH_TRANS2, RAW_SEARCH_DATA_UNIX_INFO,
164 offsetof(union smb_search_data, unix_info.name),
165 offsetof(union smb_search_data, unix_info.file_index),
173 static const char *level_name(enum smb_search_level level,
174 enum smb_search_data_level data_level)
177 for (i=0;i<ARRAY_SIZE(levels);i++) {
178 if (level == levels[i].level &&
179 data_level == levels[i].data_level) {
180 return levels[i].name;
187 extract the name from a smb_data structure and level
189 static const char *extract_name(void *data, enum smb_search_level level,
190 enum smb_search_data_level data_level)
193 for (i=0;i<ARRAY_SIZE(levels);i++) {
194 if (level == levels[i].level &&
195 data_level == levels[i].data_level) {
196 return *(const char **)(levels[i].name_offset + (char *)data);
203 extract the name from a smb_data structure and level
205 static uint32_t extract_resume_key(void *data, enum smb_search_level level,
206 enum smb_search_data_level data_level)
209 for (i=0;i<ARRAY_SIZE(levels);i++) {
210 if (level == levels[i].level &&
211 data_level == levels[i].data_level) {
212 return *(uint32_t *)(levels[i].resume_key_offset + (char *)data);
218 /* find a level in the table by name */
219 static union smb_search_data *find(const char *name)
222 for (i=0;i<ARRAY_SIZE(levels);i++) {
223 if (NT_STATUS_IS_OK(levels[i].status) &&
224 strcmp(levels[i].name, name) == 0) {
225 return &levels[i].data;
232 basic testing of all RAW_SEARCH_* calls using a single file
234 static BOOL test_one_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
238 const char *fname = "\\torture_search.txt";
239 const char *fname2 = "\\torture_search-NOTEXIST.txt";
242 union smb_fileinfo all_info, alt_info, name_info, internal_info;
243 union smb_search_data *s;
245 printf("Testing one file searches\n");
247 fnum = create_complex_file(cli, mem_ctx, fname);
249 printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
254 /* call all the levels */
255 for (i=0;i<ARRAY_SIZE(levels);i++) {
256 NTSTATUS expected_status;
257 uint32_t cap = cli->transport->negotiate.capabilities;
259 printf("testing %s\n", levels[i].name);
261 levels[i].status = torture_single_search(cli, mem_ctx, fname,
263 levels[i].data_level,
267 /* see if this server claims to support this level */
268 if ((cap & levels[i].capability_mask) != levels[i].capability_mask) {
269 printf("search level %s(%d) not supported by server\n",
270 levels[i].name, (int)levels[i].level);
274 if (!NT_STATUS_IS_OK(levels[i].status)) {
275 printf("search level %s(%d) failed - %s\n",
276 levels[i].name, (int)levels[i].level,
277 nt_errstr(levels[i].status));
282 status = torture_single_search(cli, mem_ctx, fname2,
284 levels[i].data_level,
288 expected_status = NT_STATUS_NO_SUCH_FILE;
289 if (levels[i].level == RAW_SEARCH_SEARCH ||
290 levels[i].level == RAW_SEARCH_FFIRST ||
291 levels[i].level == RAW_SEARCH_FUNIQUE) {
292 expected_status = STATUS_NO_MORE_FILES;
294 if (!NT_STATUS_EQUAL(status, expected_status)) {
295 printf("search level %s(%d) should fail with %s - %s\n",
296 levels[i].name, (int)levels[i].level,
297 nt_errstr(expected_status),
303 /* get the all_info file into to check against */
304 all_info.generic.level = RAW_FILEINFO_ALL_INFO;
305 all_info.generic.in.file.path = fname;
306 status = smb_raw_pathinfo(cli->tree, mem_ctx, &all_info);
307 if (!NT_STATUS_IS_OK(status)) {
308 printf("RAW_FILEINFO_ALL_INFO failed - %s\n", nt_errstr(status));
313 alt_info.generic.level = RAW_FILEINFO_ALT_NAME_INFO;
314 alt_info.generic.in.file.path = fname;
315 status = smb_raw_pathinfo(cli->tree, mem_ctx, &alt_info);
316 if (!NT_STATUS_IS_OK(status)) {
317 printf("RAW_FILEINFO_ALT_NAME_INFO failed - %s\n", nt_errstr(status));
322 internal_info.generic.level = RAW_FILEINFO_INTERNAL_INFORMATION;
323 internal_info.generic.in.file.path = fname;
324 status = smb_raw_pathinfo(cli->tree, mem_ctx, &internal_info);
325 if (!NT_STATUS_IS_OK(status)) {
326 printf("RAW_FILEINFO_INTERNAL_INFORMATION failed - %s\n", nt_errstr(status));
331 name_info.generic.level = RAW_FILEINFO_NAME_INFO;
332 name_info.generic.in.file.path = fname;
333 status = smb_raw_pathinfo(cli->tree, mem_ctx, &name_info);
334 if (!NT_STATUS_IS_OK(status)) {
335 printf("RAW_FILEINFO_NAME_INFO failed - %s\n", nt_errstr(status));
340 #define CHECK_VAL(name, sname1, field1, v, sname2, field2) do { \
343 if ((s->sname1.field1) != (v.sname2.out.field2)) { \
344 printf("(%s) %s/%s [0x%x] != %s/%s [0x%x]\n", \
346 #sname1, #field1, (int)s->sname1.field1, \
347 #sname2, #field2, (int)v.sname2.out.field2); \
352 #define CHECK_TIME(name, sname1, field1, v, sname2, field2) do { \
355 if (s->sname1.field1 != (~1 & nt_time_to_unix(v.sname2.out.field2))) { \
356 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
358 #sname1, #field1, timestring(mem_ctx, s->sname1.field1), \
359 #sname2, #field2, nt_time_string(mem_ctx, v.sname2.out.field2)); \
364 #define CHECK_NTTIME(name, sname1, field1, v, sname2, field2) do { \
367 if (s->sname1.field1 != v.sname2.out.field2) { \
368 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
370 #sname1, #field1, nt_time_string(mem_ctx, s->sname1.field1), \
371 #sname2, #field2, nt_time_string(mem_ctx, v.sname2.out.field2)); \
376 #define CHECK_STR(name, sname1, field1, v, sname2, field2) do { \
379 if (!s->sname1.field1 || strcmp(s->sname1.field1, v.sname2.out.field2.s)) { \
380 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
382 #sname1, #field1, s->sname1.field1, \
383 #sname2, #field2, v.sname2.out.field2.s); \
388 #define CHECK_WSTR(name, sname1, field1, v, sname2, field2, flags) do { \
391 if (!s->sname1.field1.s || \
392 strcmp(s->sname1.field1.s, v.sname2.out.field2.s) || \
393 wire_bad_flags(&s->sname1.field1, flags, cli->transport)) { \
394 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
396 #sname1, #field1, s->sname1.field1.s, \
397 #sname2, #field2, v.sname2.out.field2.s); \
402 #define CHECK_NAME(name, sname1, field1, fname, flags) do { \
405 if (!s->sname1.field1.s || \
406 strcmp(s->sname1.field1.s, fname) || \
407 wire_bad_flags(&s->sname1.field1, flags, cli->transport)) { \
408 printf("(%s) %s/%s [%s] != %s\n", \
410 #sname1, #field1, s->sname1.field1.s, \
416 #define CHECK_UNIX_NAME(name, sname1, field1, fname, flags) do { \
419 if (!s->sname1.field1 || \
420 strcmp(s->sname1.field1, fname)) { \
421 printf("(%s) %s/%s [%s] != %s\n", \
423 #sname1, #field1, s->sname1.field1, \
429 /* check that all the results are as expected */
430 CHECK_VAL("SEARCH", search, attrib, all_info, all_info, attrib&0xFFF);
431 CHECK_VAL("STANDARD", standard, attrib, all_info, all_info, attrib&0xFFF);
432 CHECK_VAL("EA_SIZE", ea_size, attrib, all_info, all_info, attrib&0xFFF);
433 CHECK_VAL("DIRECTORY_INFO", directory_info, attrib, all_info, all_info, attrib);
434 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, attrib, all_info, all_info, attrib);
435 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, attrib, all_info, all_info, attrib);
436 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, attrib, all_info, all_info, attrib);
437 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, attrib, all_info, all_info, attrib);
439 CHECK_TIME("SEARCH", search, write_time, all_info, all_info, write_time);
440 CHECK_TIME("STANDARD", standard, write_time, all_info, all_info, write_time);
441 CHECK_TIME("EA_SIZE", ea_size, write_time, all_info, all_info, write_time);
442 CHECK_TIME("STANDARD", standard, create_time, all_info, all_info, create_time);
443 CHECK_TIME("EA_SIZE", ea_size, create_time, all_info, all_info, create_time);
444 CHECK_TIME("STANDARD", standard, access_time, all_info, all_info, access_time);
445 CHECK_TIME("EA_SIZE", ea_size, access_time, all_info, all_info, access_time);
447 CHECK_NTTIME("DIRECTORY_INFO", directory_info, write_time, all_info, all_info, write_time);
448 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, write_time, all_info, all_info, write_time);
449 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, write_time, all_info, all_info, write_time);
450 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, write_time, all_info, all_info, write_time);
451 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, write_time, all_info, all_info, write_time);
453 CHECK_NTTIME("DIRECTORY_INFO", directory_info, create_time, all_info, all_info, create_time);
454 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, create_time, all_info, all_info, create_time);
455 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, create_time, all_info, all_info, create_time);
456 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, create_time, all_info, all_info, create_time);
457 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, create_time, all_info, all_info, create_time);
459 CHECK_NTTIME("DIRECTORY_INFO", directory_info, access_time, all_info, all_info, access_time);
460 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, access_time, all_info, all_info, access_time);
461 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, access_time, all_info, all_info, access_time);
462 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, access_time, all_info, all_info, access_time);
463 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, access_time, all_info, all_info, access_time);
465 CHECK_NTTIME("DIRECTORY_INFO", directory_info, change_time, all_info, all_info, change_time);
466 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, change_time, all_info, all_info, change_time);
467 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, change_time, all_info, all_info, change_time);
468 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, change_time, all_info, all_info, change_time);
469 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, change_time, all_info, all_info, change_time);
471 CHECK_VAL("SEARCH", search, size, all_info, all_info, size);
472 CHECK_VAL("STANDARD", standard, size, all_info, all_info, size);
473 CHECK_VAL("EA_SIZE", ea_size, size, all_info, all_info, size);
474 CHECK_VAL("DIRECTORY_INFO", directory_info, size, all_info, all_info, size);
475 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, size, all_info, all_info, size);
476 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, size, all_info, all_info, size);
477 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, size, all_info, all_info, size);
478 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, size, all_info, all_info, size);
479 CHECK_VAL("UNIX_INFO", unix_info, size, all_info, all_info, size);
481 CHECK_VAL("STANDARD", standard, alloc_size, all_info, all_info, alloc_size);
482 CHECK_VAL("EA_SIZE", ea_size, alloc_size, all_info, all_info, alloc_size);
483 CHECK_VAL("DIRECTORY_INFO", directory_info, alloc_size, all_info, all_info, alloc_size);
484 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, alloc_size, all_info, all_info, alloc_size);
485 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, alloc_size, all_info, all_info, alloc_size);
486 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, alloc_size, all_info, all_info, alloc_size);
487 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, alloc_size, all_info, all_info, alloc_size);
488 CHECK_VAL("UNIX_INFO", unix_info, alloc_size, all_info, all_info, alloc_size);
490 CHECK_VAL("EA_SIZE", ea_size, ea_size, all_info, all_info, ea_size);
491 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, ea_size, all_info, all_info, ea_size);
492 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, ea_size, all_info, all_info, ea_size);
493 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, ea_size, all_info, all_info, ea_size);
494 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, ea_size, all_info, all_info, ea_size);
496 CHECK_STR("SEARCH", search, name, alt_info, alt_name_info, fname);
497 CHECK_WSTR("BOTH_DIRECTORY_INFO", both_directory_info, short_name, alt_info, alt_name_info, fname, STR_UNICODE);
499 CHECK_NAME("STANDARD", standard, name, fname+1, 0);
500 CHECK_NAME("EA_SIZE", ea_size, name, fname+1, 0);
501 CHECK_NAME("DIRECTORY_INFO", directory_info, name, fname+1, STR_TERMINATE_ASCII);
502 CHECK_NAME("FULL_DIRECTORY_INFO", full_directory_info, name, fname+1, STR_TERMINATE_ASCII);
503 CHECK_NAME("NAME_INFO", name_info, name, fname+1, STR_TERMINATE_ASCII);
504 CHECK_NAME("BOTH_DIRECTORY_INFO", both_directory_info, name, fname+1, STR_TERMINATE_ASCII);
505 CHECK_NAME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, name, fname+1, STR_TERMINATE_ASCII);
506 CHECK_NAME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, name, fname+1, STR_TERMINATE_ASCII);
507 CHECK_UNIX_NAME("UNIX_INFO", unix_info, name, fname+1, STR_TERMINATE_ASCII);
509 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, file_id, internal_info, internal_information, file_id);
510 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, file_id, internal_info, internal_information, file_id);
513 smb_raw_exit(cli->session);
514 smbcli_unlink(cli->tree, fname);
520 struct multiple_result {
523 union smb_search_data *list;
527 callback function for multiple_search
529 static BOOL multiple_search_callback(void *private, const union smb_search_data *file)
531 struct multiple_result *data = private;
535 data->list = talloc_realloc(data->mem_ctx,
537 union smb_search_data,
540 data->list[data->count-1] = *file;
545 enum continue_type {CONT_FLAGS, CONT_NAME, CONT_RESUME_KEY};
548 do a single file (non-wildcard) search
550 static NTSTATUS multiple_search(struct smbcli_state *cli,
553 enum smb_search_data_level data_level,
554 enum continue_type cont_type,
557 union smb_search_first io;
558 union smb_search_next io2;
560 const int per_search = 100;
561 struct multiple_result *result = data;
563 if (data_level == RAW_SEARCH_DATA_SEARCH) {
564 io.search_first.level = RAW_SEARCH_SEARCH;
565 io.search_first.data_level = RAW_SEARCH_DATA_SEARCH;
566 io.search_first.in.max_count = per_search;
567 io.search_first.in.search_attrib = 0;
568 io.search_first.in.pattern = pattern;
570 io.t2ffirst.level = RAW_SEARCH_TRANS2;
571 io.t2ffirst.data_level = data_level;
572 io.t2ffirst.in.search_attrib = 0;
573 io.t2ffirst.in.max_count = per_search;
574 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE_IF_END;
575 io.t2ffirst.in.storage_type = 0;
576 io.t2ffirst.in.pattern = pattern;
577 if (cont_type == CONT_RESUME_KEY) {
578 io.t2ffirst.in.flags |= FLAG_TRANS2_FIND_REQUIRE_RESUME |
579 FLAG_TRANS2_FIND_BACKUP_INTENT;
583 status = smb_raw_search_first(cli->tree, mem_ctx,
584 &io, data, multiple_search_callback);
587 while (NT_STATUS_IS_OK(status)) {
588 if (data_level == RAW_SEARCH_DATA_SEARCH) {
589 io2.search_next.level = RAW_SEARCH_SEARCH;
590 io2.search_next.data_level = RAW_SEARCH_DATA_SEARCH;
591 io2.search_next.in.max_count = per_search;
592 io2.search_next.in.search_attrib = 0;
593 io2.search_next.in.id = result->list[result->count-1].search.id;
595 io2.t2fnext.level = RAW_SEARCH_TRANS2;
596 io2.t2fnext.data_level = data_level;
597 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
598 io2.t2fnext.in.max_count = per_search;
599 io2.t2fnext.in.resume_key = 0;
600 io2.t2fnext.in.flags = FLAG_TRANS2_FIND_CLOSE_IF_END;
601 io2.t2fnext.in.last_name = "";
603 case CONT_RESUME_KEY:
604 io2.t2fnext.in.resume_key = extract_resume_key(&result->list[result->count-1],
605 io2.t2fnext.level, io2.t2fnext.data_level);
606 if (io2.t2fnext.in.resume_key == 0) {
607 printf("Server does not support resume by key for level %s\n",
608 level_name(io2.t2fnext.level, io2.t2fnext.data_level));
609 return NT_STATUS_NOT_SUPPORTED;
611 io2.t2fnext.in.flags |= FLAG_TRANS2_FIND_REQUIRE_RESUME |
612 FLAG_TRANS2_FIND_BACKUP_INTENT;
615 io2.t2fnext.in.last_name = extract_name(&result->list[result->count-1],
616 io2.t2fnext.level, io2.t2fnext.data_level);
619 io2.t2fnext.in.flags |= FLAG_TRANS2_FIND_CONTINUE;
624 status = smb_raw_search_next(cli->tree, mem_ctx,
625 &io2, data, multiple_search_callback);
626 if (!NT_STATUS_IS_OK(status)) {
629 if (data_level == RAW_SEARCH_DATA_SEARCH) {
630 if (io2.search_next.out.count == 0) {
633 } else if (io2.t2fnext.out.count == 0 ||
634 io2.t2fnext.out.end_of_search) {
642 #define CHECK_STATUS(status, correct) do { \
643 if (!NT_STATUS_EQUAL(status, correct)) { \
644 printf("(%s) Incorrect status %s - should be %s\n", \
645 __location__, nt_errstr(status), nt_errstr(correct)); \
650 #define CHECK_VALUE(v, correct) do { \
651 if ((v) != (correct)) { \
652 printf("(%s) Incorrect value %s=%ld - should be %ld\n", \
653 __location__, #v, (long)v, (long)correct); \
658 #define CHECK_STRING(v, correct) do { \
659 if (strcasecmp_m(v, correct) != 0) { \
660 printf("(%s) Incorrect value %s='%s' - should be '%s'\n", \
661 __location__, #v, v, correct); \
666 static enum smb_search_data_level compare_data_level;
668 static int search_compare(union smb_search_data *d1, union smb_search_data *d2)
671 enum smb_search_level level;
673 if (compare_data_level == RAW_SEARCH_DATA_SEARCH) {
674 level = RAW_SEARCH_SEARCH;
676 level = RAW_SEARCH_TRANS2;
679 s1 = extract_name(d1, level, compare_data_level);
680 s2 = extract_name(d2, level, compare_data_level);
681 return strcmp_safe(s1, s2);
687 basic testing of search calls using many files
689 static BOOL test_many_files(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
691 const int num_files = 700;
696 struct multiple_result result;
699 const char *cont_name;
700 enum smb_search_data_level data_level;
701 enum continue_type cont_type;
703 {"SEARCH", "ID", RAW_SEARCH_DATA_SEARCH, CONT_RESUME_KEY},
704 {"BOTH_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO, CONT_NAME},
705 {"BOTH_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO, CONT_FLAGS},
706 {"BOTH_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO, CONT_RESUME_KEY},
707 {"STANDARD", "FLAGS", RAW_SEARCH_DATA_STANDARD, CONT_FLAGS},
708 {"STANDARD", "KEY", RAW_SEARCH_DATA_STANDARD, CONT_RESUME_KEY},
709 {"STANDARD", "NAME", RAW_SEARCH_DATA_STANDARD, CONT_NAME},
710 {"EA_SIZE", "FLAGS", RAW_SEARCH_DATA_EA_SIZE, CONT_FLAGS},
711 {"EA_SIZE", "KEY", RAW_SEARCH_DATA_EA_SIZE, CONT_RESUME_KEY},
712 {"EA_SIZE", "NAME", RAW_SEARCH_DATA_EA_SIZE, CONT_NAME},
713 {"DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_DIRECTORY_INFO, CONT_FLAGS},
714 {"DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_DIRECTORY_INFO, CONT_RESUME_KEY},
715 {"DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_DIRECTORY_INFO, CONT_NAME},
716 {"FULL_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_FULL_DIRECTORY_INFO, CONT_FLAGS},
717 {"FULL_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_FULL_DIRECTORY_INFO, CONT_RESUME_KEY},
718 {"FULL_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_FULL_DIRECTORY_INFO, CONT_NAME},
719 {"ID_FULL_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO, CONT_FLAGS},
720 {"ID_FULL_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO, CONT_RESUME_KEY},
721 {"ID_FULL_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO, CONT_NAME},
722 {"ID_BOTH_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO, CONT_NAME},
723 {"ID_BOTH_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO, CONT_FLAGS},
724 {"ID_BOTH_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO, CONT_RESUME_KEY}
727 if (!torture_setup_dir(cli, BASEDIR)) {
731 printf("Testing with %d files\n", num_files);
733 for (i=0;i<num_files;i++) {
734 fname = talloc_asprintf(cli, BASEDIR "\\t%03d-%d.txt", i, i);
735 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
737 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
742 smbcli_close(cli->tree, fnum);
746 for (t=0;t<ARRAY_SIZE(search_types);t++) {
748 result.mem_ctx = talloc_new(mem_ctx);
750 printf("Continue %s via %s\n", search_types[t].name, search_types[t].cont_name);
752 status = multiple_search(cli, mem_ctx, BASEDIR "\\*.*",
753 search_types[t].data_level,
754 search_types[t].cont_type,
757 if (!NT_STATUS_IS_OK(status)) {
758 printf("search type %s failed - %s\n",
759 search_types[t].name,
764 CHECK_VALUE(result.count, num_files);
766 compare_data_level = search_types[t].data_level;
768 qsort(result.list, result.count, sizeof(result.list[0]),
769 QSORT_CAST search_compare);
771 for (i=0;i<result.count;i++) {
773 enum smb_search_level level;
774 if (compare_data_level == RAW_SEARCH_DATA_SEARCH) {
775 level = RAW_SEARCH_SEARCH;
777 level = RAW_SEARCH_TRANS2;
779 s = extract_name(&result.list[i], level, compare_data_level);
780 fname = talloc_asprintf(cli, "t%03d-%d.txt", i, i);
781 if (strcmp(fname, s)) {
782 printf("Incorrect name %s at entry %d\n", s, i);
788 talloc_free(result.mem_ctx);
792 smb_raw_exit(cli->session);
793 smbcli_deltree(cli->tree, BASEDIR);
799 check a individual file result
801 static BOOL check_result(struct multiple_result *result, const char *name, BOOL exist, uint32_t attrib)
804 for (i=0;i<result->count;i++) {
805 if (strcmp(name, result->list[i].both_directory_info.name.s) == 0) break;
807 if (i == result->count) {
809 printf("failed: '%s' should exist with attribute %s\n",
810 name, attrib_string(result->list, attrib));
817 printf("failed: '%s' should NOT exist (has attribute %s)\n",
818 name, attrib_string(result->list, result->list[i].both_directory_info.attrib));
822 if ((result->list[i].both_directory_info.attrib&0xFFF) != attrib) {
823 printf("failed: '%s' should have attribute 0x%x (has 0x%x)\n",
825 attrib, result->list[i].both_directory_info.attrib);
832 test what happens when the directory is modified during a search
834 static BOOL test_modify_search(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
836 const int num_files = 20;
841 struct multiple_result result;
842 union smb_search_first io;
843 union smb_search_next io2;
844 union smb_setfileinfo sfinfo;
846 if (!torture_setup_dir(cli, BASEDIR)) {
850 printf("Creating %d files\n", num_files);
852 for (i=num_files-1;i>=0;i--) {
853 fname = talloc_asprintf(cli, BASEDIR "\\t%03d-%d.txt", i, i);
854 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
856 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
861 smbcli_close(cli->tree, fnum);
864 printf("pulling the first file\n");
866 result.mem_ctx = talloc_new(mem_ctx);
868 io.t2ffirst.level = RAW_SEARCH_TRANS2;
869 io.t2ffirst.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
870 io.t2ffirst.in.search_attrib = 0;
871 io.t2ffirst.in.max_count = 0;
872 io.t2ffirst.in.flags = 0;
873 io.t2ffirst.in.storage_type = 0;
874 io.t2ffirst.in.pattern = BASEDIR "\\*.*";
876 status = smb_raw_search_first(cli->tree, mem_ctx,
877 &io, &result, multiple_search_callback);
878 CHECK_STATUS(status, NT_STATUS_OK);
879 CHECK_VALUE(result.count, 1);
881 printf("pulling the second file\n");
882 io2.t2fnext.level = RAW_SEARCH_TRANS2;
883 io2.t2fnext.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
884 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
885 io2.t2fnext.in.max_count = 1;
886 io2.t2fnext.in.resume_key = 0;
887 io2.t2fnext.in.flags = 0;
888 io2.t2fnext.in.last_name = result.list[result.count-1].both_directory_info.name.s;
890 status = smb_raw_search_next(cli->tree, mem_ctx,
891 &io2, &result, multiple_search_callback);
892 CHECK_STATUS(status, NT_STATUS_OK);
893 CHECK_VALUE(result.count, 2);
897 printf("Changing attributes and deleting\n");
898 smbcli_open(cli->tree, BASEDIR "\\T003-03.txt.2", O_CREAT|O_RDWR, DENY_NONE);
899 smbcli_open(cli->tree, BASEDIR "\\T013-13.txt.2", O_CREAT|O_RDWR, DENY_NONE);
900 fnum = create_complex_file(cli, mem_ctx, BASEDIR "\\T013-13.txt.3");
901 smbcli_unlink(cli->tree, BASEDIR "\\T014-14.txt");
902 torture_set_file_attribute(cli->tree, BASEDIR "\\T015-15.txt", FILE_ATTRIBUTE_HIDDEN);
903 torture_set_file_attribute(cli->tree, BASEDIR "\\T016-16.txt", FILE_ATTRIBUTE_NORMAL);
904 torture_set_file_attribute(cli->tree, BASEDIR "\\T017-17.txt", FILE_ATTRIBUTE_SYSTEM);
905 torture_set_file_attribute(cli->tree, BASEDIR "\\T018-18.txt", 0);
906 sfinfo.generic.level = RAW_SFILEINFO_DISPOSITION_INFORMATION;
907 sfinfo.generic.in.file.fnum = fnum;
908 sfinfo.disposition_info.in.delete_on_close = 1;
909 status = smb_raw_setfileinfo(cli->tree, &sfinfo);
910 CHECK_STATUS(status, NT_STATUS_OK);
912 io2.t2fnext.level = RAW_SEARCH_TRANS2;
913 io2.t2fnext.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
914 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
915 io2.t2fnext.in.max_count = num_files + 3;
916 io2.t2fnext.in.resume_key = 0;
917 io2.t2fnext.in.flags = 0;
918 io2.t2fnext.in.last_name = ".";
920 status = smb_raw_search_next(cli->tree, mem_ctx,
921 &io2, &result, multiple_search_callback);
922 CHECK_STATUS(status, NT_STATUS_OK);
923 CHECK_VALUE(result.count, 20);
925 ret &= check_result(&result, "t009-9.txt", True, FILE_ATTRIBUTE_ARCHIVE);
926 ret &= check_result(&result, "t014-14.txt", False, 0);
927 ret &= check_result(&result, "t015-15.txt", False, 0);
928 ret &= check_result(&result, "t016-16.txt", True, FILE_ATTRIBUTE_NORMAL);
929 ret &= check_result(&result, "t017-17.txt", False, 0);
930 ret &= check_result(&result, "t018-18.txt", True, FILE_ATTRIBUTE_ARCHIVE);
931 ret &= check_result(&result, "t019-19.txt", True, FILE_ATTRIBUTE_ARCHIVE);
932 ret &= check_result(&result, "T013-13.txt.2", True, FILE_ATTRIBUTE_ARCHIVE);
933 ret &= check_result(&result, "T003-3.txt.2", False, 0);
934 ret &= check_result(&result, "T013-13.txt.3", True, FILE_ATTRIBUTE_ARCHIVE);
937 for (i=0;i<result.count;i++) {
938 printf("%s %s (0x%x)\n",
939 result.list[i].both_directory_info.name.s,
940 attrib_string(mem_ctx, result.list[i].both_directory_info.attrib),
941 result.list[i].both_directory_info.attrib);
946 smb_raw_exit(cli->session);
947 smbcli_deltree(cli->tree, BASEDIR);
954 testing if directories always come back sorted
956 static BOOL test_sorted(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
958 const int num_files = 700;
963 struct multiple_result result;
965 if (!torture_setup_dir(cli, BASEDIR)) {
969 printf("Creating %d files\n", num_files);
971 for (i=0;i<num_files;i++) {
972 fname = talloc_asprintf(cli, BASEDIR "\\%s.txt", generate_random_str_list(mem_ctx, 10, "abcdefgh"));
973 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
975 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
980 smbcli_close(cli->tree, fnum);
985 result.mem_ctx = mem_ctx;
987 status = multiple_search(cli, mem_ctx, BASEDIR "\\*.*",
988 RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO,
990 CHECK_STATUS(status, NT_STATUS_OK);
991 CHECK_VALUE(result.count, num_files);
993 for (i=0;i<num_files-1;i++) {
994 const char *name1, *name2;
995 name1 = result.list[i].both_directory_info.name.s;
996 name2 = result.list[i+1].both_directory_info.name.s;
997 if (strcasecmp_m(name1, name2) > 0) {
998 printf("non-alphabetical order at entry %d '%s' '%s'\n",
1000 printf("Server does not produce sorted directory listings (not an error)\n");
1005 talloc_free(result.list);
1008 smb_raw_exit(cli->session);
1009 smbcli_deltree(cli->tree, BASEDIR);
1017 basic testing of many old style search calls using separate dirs
1019 static BOOL test_many_dirs(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1021 const int num_dirs = 20;
1023 char *fname, *dname;
1026 union smb_search_data *file, *file2, *file3;
1028 if (!torture_setup_dir(cli, BASEDIR)) {
1032 printf("Creating %d dirs\n", num_dirs);
1034 for (i=0;i<num_dirs;i++) {
1035 dname = talloc_asprintf(cli, BASEDIR "\\d%d", i);
1036 status = smbcli_mkdir(cli->tree, dname);
1037 if (!NT_STATUS_IS_OK(status)) {
1038 printf("(%s) Failed to create %s - %s\n",
1039 __location__, dname, nt_errstr(status));
1045 fname = talloc_asprintf(cli, BASEDIR "\\d%d\\f%d-%d.txt", i, i, n);
1046 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1048 printf("(%s) Failed to create %s - %s\n",
1049 __location__, fname, smbcli_errstr(cli->tree));
1054 smbcli_close(cli->tree, fnum);
1060 file = talloc_zero_array(mem_ctx, union smb_search_data, num_dirs);
1061 file2 = talloc_zero_array(mem_ctx, union smb_search_data, num_dirs);
1062 file3 = talloc_zero_array(mem_ctx, union smb_search_data, num_dirs);
1064 printf("Search first on %d dirs\n", num_dirs);
1066 for (i=0;i<num_dirs;i++) {
1067 union smb_search_first io;
1068 io.search_first.level = RAW_SEARCH_SEARCH;
1069 io.search_first.data_level = RAW_SEARCH_DATA_SEARCH;
1070 io.search_first.in.max_count = 1;
1071 io.search_first.in.search_attrib = 0;
1072 io.search_first.in.pattern = talloc_asprintf(mem_ctx, BASEDIR "\\d%d\\*.txt", i);
1073 fname = talloc_asprintf(mem_ctx, "f%d-", i);
1075 io.search_first.out.count = 0;
1077 status = smb_raw_search_first(cli->tree, mem_ctx,
1078 &io, (void *)&file[i], single_search_callback);
1079 if (io.search_first.out.count != 1) {
1080 printf("(%s) search first gave %d entries for dir %d - %s\n",
1081 __location__, io.search_first.out.count, i, nt_errstr(status));
1085 CHECK_STATUS(status, NT_STATUS_OK);
1086 if (strncasecmp(file[i].search.name, fname, strlen(fname)) != 0) {
1087 printf("(%s) incorrect name '%s' expected '%s'[12].txt\n",
1088 __location__, file[i].search.name, fname);
1096 printf("Search next on %d dirs\n", num_dirs);
1098 for (i=0;i<num_dirs;i++) {
1099 union smb_search_next io2;
1101 io2.search_next.level = RAW_SEARCH_SEARCH;
1102 io2.search_next.data_level = RAW_SEARCH_DATA_SEARCH;
1103 io2.search_next.in.max_count = 1;
1104 io2.search_next.in.search_attrib = 0;
1105 io2.search_next.in.id = file[i].search.id;
1106 fname = talloc_asprintf(mem_ctx, "f%d-", i);
1108 io2.search_next.out.count = 0;
1110 status = smb_raw_search_next(cli->tree, mem_ctx,
1111 &io2, (void *)&file2[i], single_search_callback);
1112 if (io2.search_next.out.count != 1) {
1113 printf("(%s) search next gave %d entries for dir %d - %s\n",
1114 __location__, io2.search_next.out.count, i, nt_errstr(status));
1118 CHECK_STATUS(status, NT_STATUS_OK);
1119 if (strncasecmp(file2[i].search.name, fname, strlen(fname)) != 0) {
1120 printf("(%s) incorrect name '%s' expected '%s'[12].txt\n",
1121 __location__, file2[i].search.name, fname);
1130 printf("Search next (rewind) on %d dirs\n", num_dirs);
1132 for (i=0;i<num_dirs;i++) {
1133 union smb_search_next io2;
1135 io2.search_next.level = RAW_SEARCH_SEARCH;
1136 io2.search_next.data_level = RAW_SEARCH_DATA_SEARCH;
1137 io2.search_next.in.max_count = 1;
1138 io2.search_next.in.search_attrib = 0;
1139 io2.search_next.in.id = file[i].search.id;
1140 fname = talloc_asprintf(mem_ctx, "f%d-", i);
1141 io2.search_next.out.count = 0;
1143 status = smb_raw_search_next(cli->tree, mem_ctx,
1144 &io2, (void *)&file3[i], single_search_callback);
1145 if (io2.search_next.out.count != 1) {
1146 printf("(%s) search next gave %d entries for dir %d - %s\n",
1147 __location__, io2.search_next.out.count, i, nt_errstr(status));
1151 CHECK_STATUS(status, NT_STATUS_OK);
1153 if (strncasecmp(file3[i].search.name, file2[i].search.name, 3) != 0) {
1154 printf("(%s) incorrect name '%s' on rewind at dir %d\n",
1155 __location__, file2[i].search.name, i);
1160 if (strcmp(file3[i].search.name, file2[i].search.name) != 0) {
1161 printf("(%s) server did not rewind - got '%s' expected '%s'\n",
1162 __location__, file3[i].search.name, file2[i].search.name);
1172 smb_raw_exit(cli->session);
1173 smbcli_deltree(cli->tree, BASEDIR);
1180 testing of OS/2 style delete
1182 static BOOL test_os2_delete(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1184 const int num_files = 700;
1185 const int delete_count = 4;
1186 int total_deleted = 0;
1191 union smb_search_first io;
1192 union smb_search_next io2;
1193 struct multiple_result result;
1195 if (!torture_setup_dir(cli, BASEDIR)) {
1199 printf("Testing OS/2 style delete on %d files\n", num_files);
1201 for (i=0;i<num_files;i++) {
1202 fname = talloc_asprintf(cli, BASEDIR "\\file%u.txt", i);
1203 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1205 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
1210 smbcli_close(cli->tree, fnum);
1214 ZERO_STRUCT(result);
1215 result.mem_ctx = mem_ctx;
1217 io.t2ffirst.level = RAW_SEARCH_TRANS2;
1218 io.t2ffirst.data_level = RAW_SEARCH_DATA_EA_SIZE;
1219 io.t2ffirst.in.search_attrib = 0;
1220 io.t2ffirst.in.max_count = 100;
1221 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1222 io.t2ffirst.in.storage_type = 0;
1223 io.t2ffirst.in.pattern = BASEDIR "\\*";
1225 status = smb_raw_search_first(cli->tree, mem_ctx,
1226 &io, &result, multiple_search_callback);
1227 CHECK_STATUS(status, NT_STATUS_OK);
1229 for (i=0;i<MIN(result.count, delete_count);i++) {
1230 fname = talloc_asprintf(cli, BASEDIR "\\%s", result.list[i].ea_size.name.s);
1231 status = smbcli_unlink(cli->tree, fname);
1232 CHECK_STATUS(status, NT_STATUS_OK);
1237 io2.t2fnext.level = RAW_SEARCH_TRANS2;
1238 io2.t2fnext.data_level = RAW_SEARCH_DATA_EA_SIZE;
1239 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
1240 io2.t2fnext.in.max_count = 100;
1241 io2.t2fnext.in.resume_key = result.list[i-1].ea_size.resume_key;
1242 io2.t2fnext.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1243 io2.t2fnext.in.last_name = result.list[i-1].ea_size.name.s;
1246 ZERO_STRUCT(result);
1247 result.mem_ctx = mem_ctx;
1249 status = smb_raw_search_next(cli->tree, mem_ctx,
1250 &io2, &result, multiple_search_callback);
1251 if (!NT_STATUS_IS_OK(status)) {
1255 for (i=0;i<MIN(result.count, delete_count);i++) {
1256 fname = talloc_asprintf(cli, BASEDIR "\\%s", result.list[i].ea_size.name.s);
1257 status = smbcli_unlink(cli->tree, fname);
1258 CHECK_STATUS(status, NT_STATUS_OK);
1264 io2.t2fnext.in.resume_key = result.list[i-1].ea_size.resume_key;
1265 io2.t2fnext.in.last_name = result.list[i-1].ea_size.name.s;
1267 } while (NT_STATUS_IS_OK(status) && result.count != 0);
1269 CHECK_STATUS(status, NT_STATUS_OK);
1271 if (total_deleted != num_files) {
1272 printf("error: deleted %d - expected to delete %d\n",
1273 total_deleted, num_files);
1278 smb_raw_exit(cli->session);
1279 smbcli_deltree(cli->tree, BASEDIR);
1285 static int ealist_cmp(union smb_search_data *r1, union smb_search_data *r2)
1287 return strcmp(r1->ea_list.name.s, r2->ea_list.name.s);
1291 testing of the rather strange ea_list level
1293 static BOOL test_ea_list(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1298 union smb_search_first io;
1299 union smb_search_next nxt;
1300 struct multiple_result result;
1301 union smb_setfileinfo setfile;
1303 if (!torture_setup_dir(cli, BASEDIR)) {
1307 printf("Testing RAW_SEARCH_EA_LIST level\n");
1309 fnum = smbcli_open(cli->tree, BASEDIR "\\file1.txt", O_CREAT|O_RDWR, DENY_NONE);
1310 smbcli_close(cli->tree, fnum);
1312 fnum = smbcli_open(cli->tree, BASEDIR "\\file2.txt", O_CREAT|O_RDWR, DENY_NONE);
1313 smbcli_close(cli->tree, fnum);
1315 fnum = smbcli_open(cli->tree, BASEDIR "\\file3.txt", O_CREAT|O_RDWR, DENY_NONE);
1316 smbcli_close(cli->tree, fnum);
1318 setfile.generic.level = RAW_SFILEINFO_EA_SET;
1319 setfile.generic.in.file.path = BASEDIR "\\file2.txt";
1320 setfile.ea_set.in.num_eas = 2;
1321 setfile.ea_set.in.eas = talloc_array(mem_ctx, struct ea_struct, 2);
1322 setfile.ea_set.in.eas[0].flags = 0;
1323 setfile.ea_set.in.eas[0].name.s = "EA ONE";
1324 setfile.ea_set.in.eas[0].value = data_blob_string_const("VALUE 1");
1325 setfile.ea_set.in.eas[1].flags = 0;
1326 setfile.ea_set.in.eas[1].name.s = "SECOND EA";
1327 setfile.ea_set.in.eas[1].value = data_blob_string_const("Value Two");
1329 status = smb_raw_setpathinfo(cli->tree, &setfile);
1330 CHECK_STATUS(status, NT_STATUS_OK);
1332 setfile.generic.in.file.path = BASEDIR "\\file3.txt";
1333 status = smb_raw_setpathinfo(cli->tree, &setfile);
1334 CHECK_STATUS(status, NT_STATUS_OK);
1336 ZERO_STRUCT(result);
1337 result.mem_ctx = mem_ctx;
1339 io.t2ffirst.level = RAW_SEARCH_TRANS2;
1340 io.t2ffirst.data_level = RAW_SEARCH_DATA_EA_LIST;
1341 io.t2ffirst.in.search_attrib = 0;
1342 io.t2ffirst.in.max_count = 2;
1343 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1344 io.t2ffirst.in.storage_type = 0;
1345 io.t2ffirst.in.pattern = BASEDIR "\\*";
1346 io.t2ffirst.in.num_names = 2;
1347 io.t2ffirst.in.ea_names = talloc_array(mem_ctx, struct ea_name, 2);
1348 io.t2ffirst.in.ea_names[0].name.s = "SECOND EA";
1349 io.t2ffirst.in.ea_names[1].name.s = "THIRD EA";
1351 status = smb_raw_search_first(cli->tree, mem_ctx,
1352 &io, &result, multiple_search_callback);
1353 CHECK_STATUS(status, NT_STATUS_OK);
1354 CHECK_VALUE(result.count, 2);
1356 nxt.t2fnext.level = RAW_SEARCH_TRANS2;
1357 nxt.t2fnext.data_level = RAW_SEARCH_DATA_EA_LIST;
1358 nxt.t2fnext.in.handle = io.t2ffirst.out.handle;
1359 nxt.t2fnext.in.max_count = 2;
1360 nxt.t2fnext.in.resume_key = result.list[1].ea_list.resume_key;
1361 nxt.t2fnext.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME | FLAG_TRANS2_FIND_CONTINUE;
1362 nxt.t2fnext.in.last_name = result.list[1].ea_list.name.s;
1363 nxt.t2fnext.in.num_names = 2;
1364 nxt.t2fnext.in.ea_names = talloc_array(mem_ctx, struct ea_name, 2);
1365 nxt.t2fnext.in.ea_names[0].name.s = "SECOND EA";
1366 nxt.t2fnext.in.ea_names[1].name.s = "THIRD EA";
1368 status = smb_raw_search_next(cli->tree, mem_ctx,
1369 &nxt, &result, multiple_search_callback);
1370 CHECK_STATUS(status, NT_STATUS_OK);
1372 /* we have to sort the result as different servers can return directories
1373 in different orders */
1374 qsort(result.list, result.count, sizeof(result.list[0]),
1375 (comparison_fn_t)ealist_cmp);
1377 CHECK_VALUE(result.count, 3);
1378 CHECK_VALUE(result.list[0].ea_list.eas.num_eas, 2);
1379 CHECK_STRING(result.list[0].ea_list.name.s, "file1.txt");
1380 CHECK_STRING(result.list[0].ea_list.eas.eas[0].name.s, "SECOND EA");
1381 CHECK_VALUE(result.list[0].ea_list.eas.eas[0].value.length, 0);
1382 CHECK_STRING(result.list[0].ea_list.eas.eas[1].name.s, "THIRD EA");
1383 CHECK_VALUE(result.list[0].ea_list.eas.eas[1].value.length, 0);
1385 CHECK_STRING(result.list[1].ea_list.name.s, "file2.txt");
1386 CHECK_STRING(result.list[1].ea_list.eas.eas[0].name.s, "SECOND EA");
1387 CHECK_VALUE(result.list[1].ea_list.eas.eas[0].value.length, 9);
1388 CHECK_STRING((const char *)result.list[1].ea_list.eas.eas[0].value.data, "Value Two");
1389 CHECK_STRING(result.list[1].ea_list.eas.eas[1].name.s, "THIRD EA");
1390 CHECK_VALUE(result.list[1].ea_list.eas.eas[1].value.length, 0);
1392 CHECK_STRING(result.list[2].ea_list.name.s, "file3.txt");
1393 CHECK_STRING(result.list[2].ea_list.eas.eas[0].name.s, "SECOND EA");
1394 CHECK_VALUE(result.list[2].ea_list.eas.eas[0].value.length, 9);
1395 CHECK_STRING((const char *)result.list[2].ea_list.eas.eas[0].value.data, "Value Two");
1396 CHECK_STRING(result.list[2].ea_list.eas.eas[1].name.s, "THIRD EA");
1397 CHECK_VALUE(result.list[2].ea_list.eas.eas[1].value.length, 0);
1400 smb_raw_exit(cli->session);
1401 smbcli_deltree(cli->tree, BASEDIR);
1409 basic testing of all RAW_SEARCH_* calls using a single file
1411 BOOL torture_raw_search(struct torture_context *torture)
1413 struct smbcli_state *cli;
1415 TALLOC_CTX *mem_ctx;
1417 if (!torture_open_connection(&cli, 0)) {
1421 mem_ctx = talloc_init("torture_search");
1423 ret &= test_one_file(cli, mem_ctx);
1424 ret &= test_many_files(cli, mem_ctx);
1425 ret &= test_sorted(cli, mem_ctx);
1426 ret &= test_modify_search(cli, mem_ctx);
1427 ret &= test_many_dirs(cli, mem_ctx);
1428 ret &= test_os2_delete(cli, mem_ctx);
1429 ret &= test_ea_list(cli, mem_ctx);
1431 torture_close_connection(cli);
1432 talloc_free(mem_ctx);