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 "libcli/raw/libcliraw.h"
25 #define BASEDIR "\\testsearch"
28 callback function for single_search
30 static BOOL single_search_callback(void *private, union smb_search_data *file)
32 union smb_search_data *data = private;
40 do a single file (non-wildcard) search
42 static NTSTATUS single_search(struct smbcli_state *cli,
45 enum smb_search_level level,
46 union smb_search_data *data)
48 union smb_search_first io;
49 union smb_search_close c;
52 io.generic.level = level;
53 if (level == RAW_SEARCH_SEARCH ||
54 level == RAW_SEARCH_FFIRST ||
55 level == RAW_SEARCH_FUNIQUE) {
56 io.search_first.in.max_count = 1;
57 io.search_first.in.search_attrib = 0;
58 io.search_first.in.pattern = pattern;
60 io.t2ffirst.in.search_attrib = 0;
61 io.t2ffirst.in.max_count = 1;
62 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE;
63 io.t2ffirst.in.storage_type = 0;
64 io.t2ffirst.in.pattern = pattern;
67 status = smb_raw_search_first(cli->tree, mem_ctx,
68 &io, (void *)data, single_search_callback);
70 if (NT_STATUS_IS_OK(status) && level == RAW_SEARCH_FFIRST) {
71 c.fclose.level = RAW_FINDCLOSE_FCLOSE;
72 c.fclose.in.max_count = 1;
73 c.fclose.in.search_attrib = 0;
74 c.fclose.in.id = data->search.id;
75 status = smb_raw_search_close(cli->tree, &c);
84 enum smb_search_level level;
85 uint32_t capability_mask;
87 union smb_search_data data;
89 {"FFIRST", RAW_SEARCH_FFIRST, },
90 {"FUNIQUE", RAW_SEARCH_FUNIQUE, },
91 {"SEARCH", RAW_SEARCH_SEARCH, },
92 {"STANDARD", RAW_SEARCH_STANDARD, },
93 {"EA_SIZE", RAW_SEARCH_EA_SIZE, },
94 {"DIRECTORY_INFO", RAW_SEARCH_DIRECTORY_INFO, },
95 {"FULL_DIRECTORY_INFO", RAW_SEARCH_FULL_DIRECTORY_INFO, },
96 {"NAME_INFO", RAW_SEARCH_NAME_INFO, },
97 {"BOTH_DIRECTORY_INFO", RAW_SEARCH_BOTH_DIRECTORY_INFO, },
98 {"ID_FULL_DIRECTORY_INFO", RAW_SEARCH_ID_FULL_DIRECTORY_INFO, },
99 {"ID_BOTH_DIRECTORY_INFO", RAW_SEARCH_ID_BOTH_DIRECTORY_INFO, },
100 {"UNIX_INFO", RAW_SEARCH_UNIX_INFO, CAP_UNIX}
103 /* find a level in the table by name */
104 static union smb_search_data *find(const char *name)
107 for (i=0;i<ARRAY_SIZE(levels);i++) {
108 if (NT_STATUS_IS_OK(levels[i].status) &&
109 strcmp(levels[i].name, name) == 0) {
110 return &levels[i].data;
117 basic testing of all RAW_SEARCH_* calls using a single file
119 static BOOL test_one_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
123 const char *fname = "\\torture_search.txt";
124 const char *fname2 = "\\torture_search-NOTEXIST.txt";
127 union smb_fileinfo all_info, alt_info, name_info, internal_info;
128 union smb_search_data *s;
130 printf("Testing one file searches\n");
132 fnum = create_complex_file(cli, mem_ctx, fname);
134 printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
139 /* call all the levels */
140 for (i=0;i<ARRAY_SIZE(levels);i++) {
141 NTSTATUS expected_status;
142 uint32_t cap = cli->transport->negotiate.capabilities;
144 printf("testing %s\n", levels[i].name);
146 levels[i].status = single_search(cli, mem_ctx, fname,
147 levels[i].level, &levels[i].data);
149 /* see if this server claims to support this level */
150 if ((cap & levels[i].capability_mask) != levels[i].capability_mask) {
151 printf("search level %s(%d) not supported by server\n",
152 levels[i].name, (int)levels[i].level);
156 if (!NT_STATUS_IS_OK(levels[i].status)) {
157 printf("search level %s(%d) failed - %s\n",
158 levels[i].name, (int)levels[i].level,
159 nt_errstr(levels[i].status));
164 status = single_search(cli, mem_ctx, fname2,
165 levels[i].level, &levels[i].data);
167 expected_status = NT_STATUS_NO_SUCH_FILE;
168 if (levels[i].level == RAW_SEARCH_SEARCH ||
169 levels[i].level == RAW_SEARCH_FFIRST ||
170 levels[i].level == RAW_SEARCH_FUNIQUE) {
171 expected_status = STATUS_NO_MORE_FILES;
173 if (!NT_STATUS_EQUAL(status, expected_status)) {
174 printf("search level %s(%d) should fail with %s - %s\n",
175 levels[i].name, (int)levels[i].level,
176 nt_errstr(expected_status),
182 /* get the all_info file into to check against */
183 all_info.generic.level = RAW_FILEINFO_ALL_INFO;
184 all_info.generic.in.fname = fname;
185 status = smb_raw_pathinfo(cli->tree, mem_ctx, &all_info);
186 if (!NT_STATUS_IS_OK(status)) {
187 printf("RAW_FILEINFO_ALL_INFO failed - %s\n", nt_errstr(status));
192 alt_info.generic.level = RAW_FILEINFO_ALT_NAME_INFO;
193 alt_info.generic.in.fname = fname;
194 status = smb_raw_pathinfo(cli->tree, mem_ctx, &alt_info);
195 if (!NT_STATUS_IS_OK(status)) {
196 printf("RAW_FILEINFO_ALT_NAME_INFO failed - %s\n", nt_errstr(status));
201 internal_info.generic.level = RAW_FILEINFO_INTERNAL_INFORMATION;
202 internal_info.generic.in.fname = fname;
203 status = smb_raw_pathinfo(cli->tree, mem_ctx, &internal_info);
204 if (!NT_STATUS_IS_OK(status)) {
205 printf("RAW_FILEINFO_INTERNAL_INFORMATION failed - %s\n", nt_errstr(status));
210 name_info.generic.level = RAW_FILEINFO_NAME_INFO;
211 name_info.generic.in.fname = fname;
212 status = smb_raw_pathinfo(cli->tree, mem_ctx, &name_info);
213 if (!NT_STATUS_IS_OK(status)) {
214 printf("RAW_FILEINFO_NAME_INFO failed - %s\n", nt_errstr(status));
219 #define CHECK_VAL(name, sname1, field1, v, sname2, field2) do { \
222 if ((s->sname1.field1) != (v.sname2.out.field2)) { \
223 printf("(%s) %s/%s [0x%x] != %s/%s [0x%x]\n", \
225 #sname1, #field1, (int)s->sname1.field1, \
226 #sname2, #field2, (int)v.sname2.out.field2); \
231 #define CHECK_TIME(name, sname1, field1, v, sname2, field2) do { \
234 if (s->sname1.field1 != (~1 & nt_time_to_unix(v.sname2.out.field2))) { \
235 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
237 #sname1, #field1, timestring(mem_ctx, s->sname1.field1), \
238 #sname2, #field2, nt_time_string(mem_ctx, v.sname2.out.field2)); \
243 #define CHECK_NTTIME(name, sname1, field1, v, sname2, field2) do { \
246 if (s->sname1.field1 != v.sname2.out.field2) { \
247 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
249 #sname1, #field1, nt_time_string(mem_ctx, s->sname1.field1), \
250 #sname2, #field2, nt_time_string(mem_ctx, v.sname2.out.field2)); \
255 #define CHECK_STR(name, sname1, field1, v, sname2, field2) do { \
258 if (!s->sname1.field1 || strcmp(s->sname1.field1, v.sname2.out.field2.s)) { \
259 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
261 #sname1, #field1, s->sname1.field1, \
262 #sname2, #field2, v.sname2.out.field2.s); \
267 #define CHECK_WSTR(name, sname1, field1, v, sname2, field2, flags) do { \
270 if (!s->sname1.field1.s || \
271 strcmp(s->sname1.field1.s, v.sname2.out.field2.s) || \
272 wire_bad_flags(&s->sname1.field1, flags, cli)) { \
273 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
275 #sname1, #field1, s->sname1.field1.s, \
276 #sname2, #field2, v.sname2.out.field2.s); \
281 #define CHECK_NAME(name, sname1, field1, fname, flags) do { \
284 if (!s->sname1.field1.s || \
285 strcmp(s->sname1.field1.s, fname) || \
286 wire_bad_flags(&s->sname1.field1, flags, cli)) { \
287 printf("(%s) %s/%s [%s] != %s\n", \
289 #sname1, #field1, s->sname1.field1.s, \
295 #define CHECK_UNIX_NAME(name, sname1, field1, fname, flags) do { \
298 if (!s->sname1.field1 || \
299 strcmp(s->sname1.field1, fname)) { \
300 printf("(%s) %s/%s [%s] != %s\n", \
302 #sname1, #field1, s->sname1.field1, \
308 /* check that all the results are as expected */
309 CHECK_VAL("SEARCH", search, attrib, all_info, all_info, attrib&0xFFF);
310 CHECK_VAL("STANDARD", standard, attrib, all_info, all_info, attrib&0xFFF);
311 CHECK_VAL("EA_SIZE", ea_size, attrib, all_info, all_info, attrib&0xFFF);
312 CHECK_VAL("DIRECTORY_INFO", directory_info, attrib, all_info, all_info, attrib);
313 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, attrib, all_info, all_info, attrib);
314 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, attrib, all_info, all_info, attrib);
315 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, attrib, all_info, all_info, attrib);
316 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, attrib, all_info, all_info, attrib);
318 CHECK_TIME("SEARCH", search, write_time, all_info, all_info, write_time);
319 CHECK_TIME("STANDARD", standard, write_time, all_info, all_info, write_time);
320 CHECK_TIME("EA_SIZE", ea_size, write_time, all_info, all_info, write_time);
321 CHECK_TIME("STANDARD", standard, create_time, all_info, all_info, create_time);
322 CHECK_TIME("EA_SIZE", ea_size, create_time, all_info, all_info, create_time);
323 CHECK_TIME("STANDARD", standard, access_time, all_info, all_info, access_time);
324 CHECK_TIME("EA_SIZE", ea_size, access_time, all_info, all_info, access_time);
326 CHECK_NTTIME("DIRECTORY_INFO", directory_info, write_time, all_info, all_info, write_time);
327 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, write_time, all_info, all_info, write_time);
328 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, write_time, all_info, all_info, write_time);
329 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, write_time, all_info, all_info, write_time);
330 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, write_time, all_info, all_info, write_time);
332 CHECK_NTTIME("DIRECTORY_INFO", directory_info, create_time, all_info, all_info, create_time);
333 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, create_time, all_info, all_info, create_time);
334 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, create_time, all_info, all_info, create_time);
335 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, create_time, all_info, all_info, create_time);
336 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, create_time, all_info, all_info, create_time);
338 CHECK_NTTIME("DIRECTORY_INFO", directory_info, access_time, all_info, all_info, access_time);
339 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, access_time, all_info, all_info, access_time);
340 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, access_time, all_info, all_info, access_time);
341 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, access_time, all_info, all_info, access_time);
342 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, access_time, all_info, all_info, access_time);
344 CHECK_NTTIME("DIRECTORY_INFO", directory_info, create_time, all_info, all_info, create_time);
345 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, create_time, all_info, all_info, create_time);
346 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, create_time, all_info, all_info, create_time);
347 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, create_time, all_info, all_info, create_time);
348 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, create_time, all_info, all_info, create_time);
350 CHECK_VAL("SEARCH", search, size, all_info, all_info, size);
351 CHECK_VAL("STANDARD", standard, size, all_info, all_info, size);
352 CHECK_VAL("EA_SIZE", ea_size, size, all_info, all_info, size);
353 CHECK_VAL("DIRECTORY_INFO", directory_info, size, all_info, all_info, size);
354 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, size, all_info, all_info, size);
355 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, size, all_info, all_info, size);
356 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, size, all_info, all_info, size);
357 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, size, all_info, all_info, size);
358 CHECK_VAL("UNIX_INFO", unix_info, size, all_info, all_info, size);
360 CHECK_VAL("STANDARD", standard, alloc_size, all_info, all_info, alloc_size);
361 CHECK_VAL("EA_SIZE", ea_size, alloc_size, all_info, all_info, alloc_size);
362 CHECK_VAL("DIRECTORY_INFO", directory_info, alloc_size, all_info, all_info, alloc_size);
363 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, alloc_size, all_info, all_info, alloc_size);
364 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, alloc_size, all_info, all_info, alloc_size);
365 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, alloc_size, all_info, all_info, alloc_size);
366 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, alloc_size, all_info, all_info, alloc_size);
367 CHECK_VAL("UNIX_INFO", unix_info, alloc_size, all_info, all_info, alloc_size);
369 CHECK_VAL("EA_SIZE", ea_size, ea_size, all_info, all_info, ea_size);
370 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, ea_size, all_info, all_info, ea_size);
371 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, ea_size, all_info, all_info, ea_size);
372 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, ea_size, all_info, all_info, ea_size);
373 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, ea_size, all_info, all_info, ea_size);
375 CHECK_STR("SEARCH", search, name, alt_info, alt_name_info, fname);
376 CHECK_WSTR("BOTH_DIRECTORY_INFO", both_directory_info, short_name, alt_info, alt_name_info, fname, STR_UNICODE);
378 CHECK_NAME("STANDARD", standard, name, fname+1, 0);
379 CHECK_NAME("EA_SIZE", ea_size, name, fname+1, 0);
380 CHECK_NAME("DIRECTORY_INFO", directory_info, name, fname+1, STR_TERMINATE_ASCII);
381 CHECK_NAME("FULL_DIRECTORY_INFO", full_directory_info, name, fname+1, STR_TERMINATE_ASCII);
382 CHECK_NAME("NAME_INFO", name_info, name, fname+1, STR_TERMINATE_ASCII);
383 CHECK_NAME("BOTH_DIRECTORY_INFO", both_directory_info, name, fname+1, STR_TERMINATE_ASCII);
384 CHECK_NAME("ID_FULL_DIRECTORY_INFO", id_full_directory_info, name, fname+1, STR_TERMINATE_ASCII);
385 CHECK_NAME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, name, fname+1, STR_TERMINATE_ASCII);
386 CHECK_UNIX_NAME("UNIX_INFO", unix_info, name, fname+1, STR_TERMINATE_ASCII);
388 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, file_id, internal_info, internal_information, file_id);
389 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, file_id, internal_info, internal_information, file_id);
392 smb_raw_exit(cli->session);
393 smbcli_unlink(cli->tree, fname);
399 struct multiple_result {
402 union smb_search_data *list;
406 callback function for multiple_search
408 static BOOL multiple_search_callback(void *private, union smb_search_data *file)
410 struct multiple_result *data = private;
414 data->list = talloc_realloc_p(data->mem_ctx,
416 union smb_search_data,
419 data->list[data->count-1] = *file;
424 enum continue_type {CONT_FLAGS, CONT_NAME, CONT_RESUME_KEY};
427 do a single file (non-wildcard) search
429 static NTSTATUS multiple_search(struct smbcli_state *cli,
432 enum smb_search_level level,
433 enum continue_type cont_type,
436 union smb_search_first io;
437 union smb_search_next io2;
439 const int per_search = 300;
440 struct multiple_result *result = data;
442 io.generic.level = level;
443 if (level == RAW_SEARCH_SEARCH) {
444 io.search_first.in.max_count = per_search;
445 io.search_first.in.search_attrib = 0;
446 io.search_first.in.pattern = pattern;
448 io.t2ffirst.in.search_attrib = 0;
449 io.t2ffirst.in.max_count = per_search;
450 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE_IF_END;
451 io.t2ffirst.in.storage_type = 0;
452 io.t2ffirst.in.pattern = pattern;
453 if (cont_type == CONT_RESUME_KEY) {
454 io.t2ffirst.in.flags |= FLAG_TRANS2_FIND_REQUIRE_RESUME |
455 FLAG_TRANS2_FIND_BACKUP_INTENT;
459 status = smb_raw_search_first(cli->tree, mem_ctx,
460 &io, data, multiple_search_callback);
463 while (NT_STATUS_IS_OK(status)) {
464 io2.generic.level = level;
465 if (level == RAW_SEARCH_SEARCH) {
466 io2.search_next.in.max_count = per_search;
467 io2.search_next.in.search_attrib = 0;
468 io2.search_next.in.id = result->list[result->count-1].search.id;
470 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
471 io2.t2fnext.in.max_count = per_search;
472 io2.t2fnext.in.resume_key = 0;
473 io2.t2fnext.in.flags = FLAG_TRANS2_FIND_CLOSE_IF_END;
474 io2.t2fnext.in.last_name = "";
476 case CONT_RESUME_KEY:
477 if (level == RAW_SEARCH_STANDARD) {
478 io2.t2fnext.in.resume_key =
479 result->list[result->count-1].standard.resume_key;
480 } else if (level == RAW_SEARCH_EA_SIZE) {
481 io2.t2fnext.in.resume_key =
482 result->list[result->count-1].ea_size.resume_key;
483 } else if (level == RAW_SEARCH_DIRECTORY_INFO) {
484 io2.t2fnext.in.resume_key =
485 result->list[result->count-1].directory_info.file_index;
487 io2.t2fnext.in.resume_key =
488 result->list[result->count-1].both_directory_info.file_index;
490 if (io2.t2fnext.in.resume_key == 0) {
491 printf("Server does not support resume by key\n");
492 return NT_STATUS_NOT_SUPPORTED;
494 io2.t2fnext.in.flags |= FLAG_TRANS2_FIND_REQUIRE_RESUME |
495 FLAG_TRANS2_FIND_BACKUP_INTENT;
498 if (level == RAW_SEARCH_STANDARD) {
499 io2.t2fnext.in.last_name =
500 result->list[result->count-1].standard.name.s;
501 } else if (level == RAW_SEARCH_EA_SIZE) {
502 io2.t2fnext.in.last_name =
503 result->list[result->count-1].ea_size.name.s;
504 } else if (level == RAW_SEARCH_DIRECTORY_INFO) {
505 io2.t2fnext.in.last_name =
506 result->list[result->count-1].directory_info.name.s;
508 io2.t2fnext.in.last_name =
509 result->list[result->count-1].both_directory_info.name.s;
513 io2.t2fnext.in.flags |= FLAG_TRANS2_FIND_CONTINUE;
518 status = smb_raw_search_next(cli->tree, mem_ctx,
519 &io2, data, multiple_search_callback);
520 if (!NT_STATUS_IS_OK(status)) {
523 if (level == RAW_SEARCH_SEARCH) {
524 if (io2.search_next.out.count == 0) {
527 } else if (io2.t2fnext.out.count == 0 ||
528 io2.t2fnext.out.end_of_search) {
536 #define CHECK_STATUS(status, correct) do { \
537 if (!NT_STATUS_EQUAL(status, correct)) { \
538 printf("(%s) Incorrect status %s - should be %s\n", \
539 __location__, nt_errstr(status), nt_errstr(correct)); \
544 #define CHECK_VALUE(v, correct) do { \
545 if ((v) != (correct)) { \
546 printf("(%s) Incorrect value %s=%d - should be %d\n", \
547 __location__, #v, v, correct); \
551 #define CHECK_STRING(v, correct) do { \
552 if (StrCaseCmp(v, correct) != 0) { \
553 printf("(%s) Incorrect value %s='%s' - should be '%s'\n", \
554 __location__, #v, v, correct); \
559 static int search_both_compare(union smb_search_data *d1, union smb_search_data *d2)
561 return strcmp_safe(d1->both_directory_info.name.s, d2->both_directory_info.name.s);
564 static int search_standard_compare(union smb_search_data *d1, union smb_search_data *d2)
566 return strcmp_safe(d1->standard.name.s, d2->standard.name.s);
569 static int search_ea_size_compare(union smb_search_data *d1, union smb_search_data *d2)
571 return strcmp_safe(d1->ea_size.name.s, d2->ea_size.name.s);
574 static int search_directory_info_compare(union smb_search_data *d1, union smb_search_data *d2)
576 return strcmp_safe(d1->directory_info.name.s, d2->directory_info.name.s);
579 static int search_old_compare(union smb_search_data *d1, union smb_search_data *d2)
581 return strcmp_safe(d1->search.name, d2->search.name);
586 basic testing of search calls using many files
588 static BOOL test_many_files(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
590 const int num_files = 700;
595 struct multiple_result result;
598 const char *cont_name;
599 enum smb_search_level level;
600 enum continue_type cont_type;
602 {"SEARCH", "ID", RAW_SEARCH_SEARCH, CONT_RESUME_KEY},
603 {"BOTH_DIRECTORY_INFO", "NAME", RAW_SEARCH_BOTH_DIRECTORY_INFO, CONT_NAME},
604 {"BOTH_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_BOTH_DIRECTORY_INFO, CONT_FLAGS},
605 {"BOTH_DIRECTORY_INFO", "KEY", RAW_SEARCH_BOTH_DIRECTORY_INFO, CONT_RESUME_KEY},
606 {"STANDARD", "FLAGS", RAW_SEARCH_STANDARD, CONT_FLAGS},
607 {"STANDARD", "KEY", RAW_SEARCH_STANDARD, CONT_RESUME_KEY},
608 {"STANDARD", "NAME", RAW_SEARCH_STANDARD, CONT_NAME},
609 {"EA_SIZE", "FLAGS", RAW_SEARCH_EA_SIZE, CONT_FLAGS},
610 {"EA_SIZE", "KEY", RAW_SEARCH_EA_SIZE, CONT_RESUME_KEY},
611 {"EA_SIZE", "NAME", RAW_SEARCH_EA_SIZE, CONT_NAME},
612 {"DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DIRECTORY_INFO, CONT_FLAGS},
613 {"DIRECTORY_INFO", "KEY", RAW_SEARCH_DIRECTORY_INFO, CONT_RESUME_KEY},
614 {"DIRECTORY_INFO", "NAME", RAW_SEARCH_DIRECTORY_INFO, CONT_NAME}
617 if (!torture_setup_dir(cli, BASEDIR)) {
621 printf("Creating %d files\n", num_files);
623 for (i=0;i<num_files;i++) {
624 asprintf(&fname, BASEDIR "\\t%03d-%d.txt", i, i);
625 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
627 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
632 smbcli_close(cli->tree, fnum);
636 for (t=0;t<ARRAY_SIZE(search_types);t++) {
638 result.mem_ctx = talloc_new(mem_ctx);
640 printf("Continue %s via %s\n", search_types[t].name, search_types[t].cont_name);
642 status = multiple_search(cli, mem_ctx, BASEDIR "\\*.*",
643 search_types[t].level,
644 search_types[t].cont_type,
647 if (!NT_STATUS_IS_OK(status)) {
648 printf("search failed - %s\n", nt_errstr(status));
652 CHECK_VALUE(result.count, num_files);
654 if (search_types[t].level == RAW_SEARCH_BOTH_DIRECTORY_INFO) {
655 qsort(result.list, result.count, sizeof(result.list[0]),
656 QSORT_CAST search_both_compare);
657 } else if (search_types[t].level == RAW_SEARCH_STANDARD) {
658 qsort(result.list, result.count, sizeof(result.list[0]),
659 QSORT_CAST search_standard_compare);
660 } else if (search_types[t].level == RAW_SEARCH_EA_SIZE) {
661 qsort(result.list, result.count, sizeof(result.list[0]),
662 QSORT_CAST search_ea_size_compare);
663 } else if (search_types[t].level == RAW_SEARCH_DIRECTORY_INFO) {
664 qsort(result.list, result.count, sizeof(result.list[0]),
665 QSORT_CAST search_directory_info_compare);
667 qsort(result.list, result.count, sizeof(result.list[0]),
668 QSORT_CAST search_old_compare);
671 for (i=0;i<result.count;i++) {
673 if (search_types[t].level == RAW_SEARCH_BOTH_DIRECTORY_INFO) {
674 s = result.list[i].both_directory_info.name.s;
675 } else if (search_types[t].level == RAW_SEARCH_STANDARD) {
676 s = result.list[i].standard.name.s;
677 } else if (search_types[t].level == RAW_SEARCH_EA_SIZE) {
678 s = result.list[i].ea_size.name.s;
679 } else if (search_types[t].level == RAW_SEARCH_DIRECTORY_INFO) {
680 s = result.list[i].directory_info.name.s;
682 s = result.list[i].search.name;
684 asprintf(&fname, "t%03d-%d.txt", i, i);
685 if (strcmp(fname, s)) {
686 printf("Incorrect name %s at entry %d\n", s, i);
692 talloc_free(result.mem_ctx);
696 smb_raw_exit(cli->session);
697 smbcli_deltree(cli->tree, BASEDIR);
703 check a individual file result
705 static BOOL check_result(struct multiple_result *result, const char *name, BOOL exist, uint32_t attrib)
708 for (i=0;i<result->count;i++) {
709 if (strcmp(name, result->list[i].both_directory_info.name.s) == 0) break;
711 if (i == result->count) {
713 printf("failed: '%s' should exist with attribute %s\n",
714 name, attrib_string(result->list, attrib));
721 printf("failed: '%s' should NOT exist (has attribute %s)\n",
722 name, attrib_string(result->list, result->list[i].both_directory_info.attrib));
726 if ((result->list[i].both_directory_info.attrib&0xFFF) != attrib) {
727 printf("failed: '%s' should have attribute 0x%x (has 0x%x)\n",
729 attrib, result->list[i].both_directory_info.attrib);
736 test what happens when the directory is modified during a search
738 static BOOL test_modify_search(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
740 const int num_files = 20;
745 struct multiple_result result;
746 union smb_search_first io;
747 union smb_search_next io2;
748 union smb_setfileinfo sfinfo;
750 if (!torture_setup_dir(cli, BASEDIR)) {
754 printf("Creating %d files\n", num_files);
756 for (i=num_files-1;i>=0;i--) {
757 asprintf(&fname, BASEDIR "\\t%03d-%d.txt", i, i);
758 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
760 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
765 smbcli_close(cli->tree, fnum);
768 printf("pulling the first file\n");
770 result.mem_ctx = talloc_new(mem_ctx);
772 io.generic.level = RAW_SEARCH_BOTH_DIRECTORY_INFO;
773 io.t2ffirst.in.search_attrib = 0;
774 io.t2ffirst.in.max_count = 0;
775 io.t2ffirst.in.flags = 0;
776 io.t2ffirst.in.storage_type = 0;
777 io.t2ffirst.in.pattern = BASEDIR "\\*.*";
779 status = smb_raw_search_first(cli->tree, mem_ctx,
780 &io, &result, multiple_search_callback);
781 CHECK_STATUS(status, NT_STATUS_OK);
782 CHECK_VALUE(result.count, 1);
784 printf("pulling the second file\n");
785 io2.generic.level = RAW_SEARCH_BOTH_DIRECTORY_INFO;
786 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
787 io2.t2fnext.in.max_count = 1;
788 io2.t2fnext.in.resume_key = 0;
789 io2.t2fnext.in.flags = 0;
790 if (result.count == 0) {
791 io2.t2fnext.in.last_name = "";
793 io2.t2fnext.in.last_name = result.list[result.count-1].both_directory_info.name.s;
796 status = smb_raw_search_next(cli->tree, mem_ctx,
797 &io2, &result, multiple_search_callback);
798 CHECK_STATUS(status, NT_STATUS_OK);
799 CHECK_VALUE(result.count, 2);
801 printf("Changing attributes and deleting\n");
802 smbcli_open(cli->tree, BASEDIR "\\T003-03.txt.2", O_CREAT|O_RDWR, DENY_NONE);
803 smbcli_open(cli->tree, BASEDIR "\\T013-13.txt.2", O_CREAT|O_RDWR, DENY_NONE);
804 fnum = create_complex_file(cli, mem_ctx, BASEDIR "\\T013-13.txt.3");
805 smbcli_unlink(cli->tree, BASEDIR "\\T014-14.txt");
806 torture_set_file_attribute(cli->tree, BASEDIR "\\T015-15.txt", FILE_ATTRIBUTE_HIDDEN);
807 torture_set_file_attribute(cli->tree, BASEDIR "\\T016-16.txt", FILE_ATTRIBUTE_NORMAL);
808 torture_set_file_attribute(cli->tree, BASEDIR "\\T017-17.txt", FILE_ATTRIBUTE_SYSTEM);
809 torture_set_file_attribute(cli->tree, BASEDIR "\\T018-18.txt", 0);
810 sfinfo.generic.level = RAW_SFILEINFO_DISPOSITION_INFORMATION;
811 sfinfo.generic.file.fnum = fnum;
812 sfinfo.disposition_info.in.delete_on_close = 1;
813 status = smb_raw_setfileinfo(cli->tree, &sfinfo);
814 CHECK_STATUS(status, NT_STATUS_OK);
816 io2.generic.level = RAW_SEARCH_BOTH_DIRECTORY_INFO;
817 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
818 io2.t2fnext.in.max_count = num_files - 1;
819 io2.t2fnext.in.resume_key = 0;
820 io2.t2fnext.in.flags = 0;
821 io2.t2fnext.in.last_name = result.list[result.count-2].both_directory_info.name.s;
823 status = smb_raw_search_next(cli->tree, mem_ctx,
824 &io2, &result, multiple_search_callback);
825 CHECK_STATUS(status, NT_STATUS_OK);
826 CHECK_VALUE(result.count, 21);
828 ret &= check_result(&result, "t009-9.txt", True, FILE_ATTRIBUTE_ARCHIVE);
829 ret &= check_result(&result, "t014-14.txt", False, 0);
830 ret &= check_result(&result, "t015-15.txt", False, 0);
831 ret &= check_result(&result, "t016-16.txt", True, FILE_ATTRIBUTE_NORMAL);
832 ret &= check_result(&result, "t017-17.txt", False, 0);
833 ret &= check_result(&result, "t018-18.txt", True, FILE_ATTRIBUTE_ARCHIVE);
834 ret &= check_result(&result, "t019-19.txt", True, FILE_ATTRIBUTE_ARCHIVE);
835 ret &= check_result(&result, "T013-13.txt.2", True, FILE_ATTRIBUTE_ARCHIVE);
836 ret &= check_result(&result, "T003-3.txt.2", False, 0);
837 ret &= check_result(&result, "T013-13.txt.3", True, FILE_ATTRIBUTE_ARCHIVE);
840 for (i=0;i<result.count;i++) {
841 printf("%s %s (0x%x)\n",
842 result.list[i].both_directory_info.name.s,
843 attrib_string(mem_ctx, result.list[i].both_directory_info.attrib),
844 result.list[i].both_directory_info.attrib);
849 smb_raw_exit(cli->session);
850 smbcli_deltree(cli->tree, BASEDIR);
857 testing if directories always come back sorted
859 static BOOL test_sorted(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
861 const int num_files = 700;
866 struct multiple_result result;
868 if (!torture_setup_dir(cli, BASEDIR)) {
872 printf("Creating %d files\n", num_files);
874 for (i=0;i<num_files;i++) {
875 asprintf(&fname, BASEDIR "\\%s.txt", generate_random_str_list(mem_ctx, 10, "abcdefgh"));
876 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
878 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
883 smbcli_close(cli->tree, fnum);
888 result.mem_ctx = mem_ctx;
890 status = multiple_search(cli, mem_ctx, BASEDIR "\\*.*",
891 RAW_SEARCH_BOTH_DIRECTORY_INFO,
893 CHECK_STATUS(status, NT_STATUS_OK);
894 CHECK_VALUE(result.count, num_files);
896 for (i=0;i<num_files-1;i++) {
897 const char *name1, *name2;
898 name1 = result.list[i].both_directory_info.name.s;
899 name2 = result.list[i+1].both_directory_info.name.s;
900 if (StrCaseCmp(name1, name2) > 0) {
901 printf("non-alphabetical order at entry %d '%s' '%s'\n",
903 printf("Server does not produce sorted directory listings (not an error)\n");
908 talloc_free(result.list);
911 smb_raw_exit(cli->session);
912 smbcli_deltree(cli->tree, BASEDIR);
920 basic testing of many old style search calls using separate dirs
922 static BOOL test_many_dirs(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
924 const int num_dirs = 300;
929 union smb_search_data *file, *file2, *file3;
931 if (!torture_setup_dir(cli, BASEDIR)) {
935 printf("Creating %d dirs\n", num_dirs);
937 for (i=0;i<num_dirs;i++) {
938 asprintf(&dname, BASEDIR "\\d%d", i);
939 status = smbcli_mkdir(cli->tree, dname);
940 if (!NT_STATUS_IS_OK(status)) {
941 printf("(%s) Failed to create %s - %s\n",
942 __location__, dname, nt_errstr(status));
948 asprintf(&fname, BASEDIR "\\d%d\\f%d-%d.txt", i, i, n);
949 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
951 printf("(%s) Failed to create %s - %s\n",
952 __location__, fname, smbcli_errstr(cli->tree));
960 smbcli_close(cli->tree, fnum);
963 file = talloc_zero_array(mem_ctx, union smb_search_data, num_dirs);
964 file2 = talloc_zero_array(mem_ctx, union smb_search_data, num_dirs);
965 file3 = talloc_zero_array(mem_ctx, union smb_search_data, num_dirs);
967 printf("Search first on %d dirs\n", num_dirs);
969 for (i=0;i<num_dirs;i++) {
970 union smb_search_first io;
971 io.generic.level = RAW_SEARCH_SEARCH;
972 io.search_first.in.max_count = 1;
973 io.search_first.in.search_attrib = 0;
974 io.search_first.in.pattern = talloc_asprintf(mem_ctx, BASEDIR "\\d%d\\*.txt", i);
975 fname = talloc_asprintf(mem_ctx, "f%d-", i);
977 io.search_first.out.count = 0;
979 status = smb_raw_search_first(cli->tree, mem_ctx,
980 &io, (void *)&file[i], single_search_callback);
981 if (io.search_first.out.count != 1) {
982 printf("(%s) search first gave %d entries for dir %d - %s\n",
983 __location__, io.search_first.out.count, i, nt_errstr(status));
987 CHECK_STATUS(status, NT_STATUS_OK);
988 if (strncasecmp(file[i].search.name, fname, strlen(fname)) != 0) {
989 printf("(%s) incorrect name '%s' expected '%s'[12].txt\n",
990 __location__, file[i].search.name, fname);
998 printf("Search next on %d dirs\n", num_dirs);
1000 for (i=0;i<num_dirs;i++) {
1001 union smb_search_next io2;
1003 io2.generic.level = RAW_SEARCH_SEARCH;
1004 io2.search_next.in.max_count = 1;
1005 io2.search_next.in.search_attrib = 0;
1006 io2.search_next.in.id = file[i].search.id;
1007 fname = talloc_asprintf(mem_ctx, "f%d-", i);
1009 io2.search_next.out.count = 0;
1011 status = smb_raw_search_next(cli->tree, mem_ctx,
1012 &io2, (void *)&file2[i], single_search_callback);
1013 if (io2.search_next.out.count != 1) {
1014 printf("(%s) search next gave %d entries for dir %d - %s\n",
1015 __location__, io2.search_next.out.count, i, nt_errstr(status));
1019 CHECK_STATUS(status, NT_STATUS_OK);
1020 if (strncasecmp(file2[i].search.name, fname, strlen(fname)) != 0) {
1021 printf("(%s) incorrect name '%s' expected '%s'[12].txt\n",
1022 __location__, file2[i].search.name, fname);
1031 printf("Search next (rewind) on %d dirs\n", num_dirs);
1033 for (i=0;i<num_dirs;i++) {
1034 union smb_search_next io2;
1036 io2.generic.level = RAW_SEARCH_SEARCH;
1037 io2.search_next.in.max_count = 1;
1038 io2.search_next.in.search_attrib = 0;
1039 io2.search_next.in.id = file[i].search.id;
1040 fname = talloc_asprintf(mem_ctx, "f%d-", i);
1041 io2.search_next.out.count = 0;
1043 status = smb_raw_search_next(cli->tree, mem_ctx,
1044 &io2, (void *)&file3[i], single_search_callback);
1045 if (io2.search_next.out.count != 1) {
1046 printf("(%s) search next gave %d entries for dir %d - %s\n",
1047 __location__, io2.search_next.out.count, i, nt_errstr(status));
1051 CHECK_STATUS(status, NT_STATUS_OK);
1053 if (strncasecmp(file3[i].search.name, file2[i].search.name, 3) != 0) {
1054 printf("(%s) incorrect name '%s' on rewind at dir %d\n",
1055 __location__, file2[i].search.name, i);
1060 if (strcmp(file3[i].search.name, file2[i].search.name) != 0) {
1061 printf("(%s) server did not rewind - got '%s' expected '%s'\n",
1062 __location__, file3[i].search.name, file2[i].search.name);
1072 smb_raw_exit(cli->session);
1073 smbcli_deltree(cli->tree, BASEDIR);
1080 testing of OS/2 style delete
1082 static BOOL test_os2_delete(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1084 const int num_files = 700;
1085 const int delete_count = 4;
1086 int total_deleted = 0;
1091 union smb_search_first io;
1092 union smb_search_next io2;
1093 struct multiple_result result;
1095 if (!torture_setup_dir(cli, BASEDIR)) {
1099 printf("Testing OS/2 style delete on %d files\n", num_files);
1101 for (i=0;i<num_files;i++) {
1102 asprintf(&fname, BASEDIR "\\file%u.txt", i);
1103 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1105 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
1110 smbcli_close(cli->tree, fnum);
1114 ZERO_STRUCT(result);
1115 result.mem_ctx = mem_ctx;
1117 io.t2ffirst.level = RAW_SEARCH_EA_SIZE;
1118 io.t2ffirst.in.search_attrib = 0;
1119 io.t2ffirst.in.max_count = 100;
1120 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1121 io.t2ffirst.in.storage_type = 0;
1122 io.t2ffirst.in.pattern = BASEDIR "\\*";
1124 status = smb_raw_search_first(cli->tree, mem_ctx,
1125 &io, &result, multiple_search_callback);
1126 CHECK_STATUS(status, NT_STATUS_OK);
1128 for (i=0;i<MIN(result.count, delete_count);i++) {
1129 asprintf(&fname, BASEDIR "\\%s", result.list[i].ea_size.name.s);
1130 status = smbcli_unlink(cli->tree, fname);
1131 CHECK_STATUS(status, NT_STATUS_OK);
1135 io2.t2fnext.level = RAW_SEARCH_EA_SIZE;
1136 io2.t2fnext.in.handle = io.t2ffirst.out.handle;
1137 io2.t2fnext.in.max_count = 100;
1138 io2.t2fnext.in.resume_key = result.list[i-1].ea_size.resume_key;
1139 io2.t2fnext.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1140 io2.t2fnext.in.last_name = result.list[i-1].ea_size.name.s;
1143 ZERO_STRUCT(result);
1144 result.mem_ctx = mem_ctx;
1146 status = smb_raw_search_next(cli->tree, mem_ctx,
1147 &io2, &result, multiple_search_callback);
1148 if (!NT_STATUS_IS_OK(status)) {
1152 for (i=0;i<MIN(result.count, delete_count);i++) {
1153 asprintf(&fname, BASEDIR "\\%s", result.list[i].ea_size.name.s);
1154 status = smbcli_unlink(cli->tree, fname);
1155 CHECK_STATUS(status, NT_STATUS_OK);
1160 io2.t2fnext.in.resume_key = result.list[i-1].ea_size.resume_key;
1161 io2.t2fnext.in.last_name = result.list[i-1].ea_size.name.s;
1163 } while (NT_STATUS_IS_OK(status) && result.count != 0);
1165 CHECK_STATUS(status, NT_STATUS_OK);
1167 if (total_deleted != num_files) {
1168 printf("error: deleted %d - expected to delete %d\n",
1169 total_deleted, num_files);
1174 smb_raw_exit(cli->session);
1175 smbcli_deltree(cli->tree, BASEDIR);
1182 testing of the rather strange ea_list level
1184 static BOOL test_ea_list(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1189 union smb_search_first io;
1190 union smb_search_next nxt;
1191 struct multiple_result result;
1192 union smb_setfileinfo setfile;
1194 if (!torture_setup_dir(cli, BASEDIR)) {
1198 printf("Testing RAW_SEARCH_EA_LIST level\n");
1200 fnum = smbcli_open(cli->tree, BASEDIR "\\file1.txt", O_CREAT|O_RDWR, DENY_NONE);
1201 smbcli_close(cli->tree, fnum);
1203 fnum = smbcli_open(cli->tree, BASEDIR "\\file2.txt", O_CREAT|O_RDWR, DENY_NONE);
1204 smbcli_close(cli->tree, fnum);
1206 fnum = smbcli_open(cli->tree, BASEDIR "\\file3.txt", O_CREAT|O_RDWR, DENY_NONE);
1207 smbcli_close(cli->tree, fnum);
1209 setfile.generic.level = RAW_SFILEINFO_EA_SET;
1210 setfile.generic.file.fname = BASEDIR "\\file2.txt";
1211 setfile.ea_set.in.num_eas = 2;
1212 setfile.ea_set.in.eas = talloc_array_p(mem_ctx, struct ea_struct, 2);
1213 setfile.ea_set.in.eas[0].flags = 0;
1214 setfile.ea_set.in.eas[0].name.s = "EA ONE";
1215 setfile.ea_set.in.eas[0].value = data_blob_string_const("VALUE 1");
1216 setfile.ea_set.in.eas[1].flags = 0;
1217 setfile.ea_set.in.eas[1].name.s = "SECOND EA";
1218 setfile.ea_set.in.eas[1].value = data_blob_string_const("Value Two");
1220 status = smb_raw_setpathinfo(cli->tree, &setfile);
1221 CHECK_STATUS(status, NT_STATUS_OK);
1223 setfile.generic.file.fname = BASEDIR "\\file3.txt";
1224 status = smb_raw_setpathinfo(cli->tree, &setfile);
1225 CHECK_STATUS(status, NT_STATUS_OK);
1227 ZERO_STRUCT(result);
1228 result.mem_ctx = mem_ctx;
1230 io.t2ffirst.level = RAW_SEARCH_EA_LIST;
1231 io.t2ffirst.in.search_attrib = 0;
1232 io.t2ffirst.in.max_count = 2;
1233 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
1234 io.t2ffirst.in.storage_type = 0;
1235 io.t2ffirst.in.pattern = BASEDIR "\\*";
1236 io.t2ffirst.in.num_names = 2;
1237 io.t2ffirst.in.ea_names = talloc_array_p(mem_ctx, struct ea_name, 2);
1238 io.t2ffirst.in.ea_names[0].name.s = "SECOND EA";
1239 io.t2ffirst.in.ea_names[1].name.s = "THIRD EA";
1241 status = smb_raw_search_first(cli->tree, mem_ctx,
1242 &io, &result, multiple_search_callback);
1243 CHECK_STATUS(status, NT_STATUS_OK);
1244 CHECK_VALUE(result.count, 2);
1246 nxt.t2fnext.level = RAW_SEARCH_EA_LIST;
1247 nxt.t2fnext.in.handle = io.t2ffirst.out.handle;
1248 nxt.t2fnext.in.max_count = 2;
1249 nxt.t2fnext.in.resume_key = result.list[1].ea_list.resume_key;
1250 nxt.t2fnext.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME | FLAG_TRANS2_FIND_CONTINUE;
1251 nxt.t2fnext.in.last_name = "file2.txt";
1252 nxt.t2fnext.in.num_names = 2;
1253 nxt.t2fnext.in.ea_names = talloc_array_p(mem_ctx, struct ea_name, 2);
1254 nxt.t2fnext.in.ea_names[0].name.s = "SECOND EA";
1255 nxt.t2fnext.in.ea_names[1].name.s = "THIRD EA";
1257 status = smb_raw_search_next(cli->tree, mem_ctx,
1258 &nxt, &result, multiple_search_callback);
1259 CHECK_STATUS(status, NT_STATUS_OK);
1262 CHECK_VALUE(result.count, 3);
1263 CHECK_VALUE(result.list[0].ea_list.eas.num_eas, 2);
1264 CHECK_STRING(result.list[0].ea_list.name.s, "file1.txt");
1265 CHECK_STRING(result.list[0].ea_list.eas.eas[0].name.s, "SECOND EA");
1266 CHECK_VALUE(result.list[0].ea_list.eas.eas[0].value.length, 0);
1267 CHECK_STRING(result.list[0].ea_list.eas.eas[1].name.s, "THIRD EA");
1268 CHECK_VALUE(result.list[0].ea_list.eas.eas[1].value.length, 0);
1270 CHECK_STRING(result.list[1].ea_list.name.s, "file2.txt");
1271 CHECK_STRING(result.list[1].ea_list.eas.eas[0].name.s, "SECOND EA");
1272 CHECK_VALUE(result.list[1].ea_list.eas.eas[0].value.length, 9);
1273 CHECK_STRING(result.list[1].ea_list.eas.eas[0].value.data, "Value Two");
1274 CHECK_STRING(result.list[1].ea_list.eas.eas[1].name.s, "THIRD EA");
1275 CHECK_VALUE(result.list[1].ea_list.eas.eas[1].value.length, 0);
1277 CHECK_STRING(result.list[2].ea_list.name.s, "file3.txt");
1278 CHECK_STRING(result.list[2].ea_list.eas.eas[0].name.s, "SECOND EA");
1279 CHECK_VALUE(result.list[2].ea_list.eas.eas[0].value.length, 9);
1280 CHECK_STRING(result.list[2].ea_list.eas.eas[0].value.data, "Value Two");
1281 CHECK_STRING(result.list[2].ea_list.eas.eas[1].name.s, "THIRD EA");
1282 CHECK_VALUE(result.list[2].ea_list.eas.eas[1].value.length, 0);
1285 smb_raw_exit(cli->session);
1286 smbcli_deltree(cli->tree, BASEDIR);
1294 basic testing of all RAW_SEARCH_* calls using a single file
1296 BOOL torture_raw_search(void)
1298 struct smbcli_state *cli;
1300 TALLOC_CTX *mem_ctx;
1302 if (!torture_open_connection(&cli)) {
1306 mem_ctx = talloc_init("torture_search");
1308 ret &= test_one_file(cli, mem_ctx);
1309 ret &= test_many_files(cli, mem_ctx);
1310 ret &= test_sorted(cli, mem_ctx);
1311 ret &= test_modify_search(cli, mem_ctx);
1312 ret &= test_many_dirs(cli, mem_ctx);
1313 ret &= test_os2_delete(cli, mem_ctx);
1314 ret &= test_ea_list(cli, mem_ctx);
1316 torture_close_connection(cli);
1317 talloc_destroy(mem_ctx);