Debian Codegraph @

source4/torture/raw/search.c

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