2 Unix SMB/CIFS implementation.
3 RAW_SEARCH_* individual test suite
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "system/filesys.h"
22 #include "libcli/raw/libcliraw.h"
23 #include "libcli/raw/raw_proto.h"
24 #include "libcli/libcli.h"
25 #include "torture/util.h"
26 #include "lib/util/tsort.h"
27 #include "torture/raw/proto.h"
30 #define BASEDIR "\\testsearch"
32 #define CHECK_STATUS_LEVEL(__tctx, __status, __level, __supp) \
34 if (NT_STATUS_EQUAL(__status, \
35 NT_STATUS_NOT_SUPPORTED) || \
36 NT_STATUS_EQUAL(__status, \
37 NT_STATUS_NOT_IMPLEMENTED)) { \
38 torture_warning(__tctx, "(%s) Info " \
39 "level "#__level" is %s", \
40 __location__, nt_errstr(__status)); \
43 torture_assert_ntstatus_ok_goto(__tctx, \
44 __status, ret, done, #__level" failed"); \
50 callback function for single_search
52 static bool single_search_callback(void *private_data
, const union smb_search_data
*file
)
54 union smb_search_data
*data
= (union smb_search_data
*)private_data
;
62 do a single file (non-wildcard) search
64 NTSTATUS
torture_single_search(struct smbcli_state
*cli
,
67 enum smb_search_level level
,
68 enum smb_search_data_level data_level
,
70 union smb_search_data
*data
)
72 union smb_search_first io
;
73 union smb_search_close c
;
77 case RAW_SEARCH_SEARCH
:
78 case RAW_SEARCH_FFIRST
:
79 case RAW_SEARCH_FUNIQUE
:
80 io
.search_first
.level
= level
;
81 io
.search_first
.data_level
= RAW_SEARCH_DATA_SEARCH
;
82 io
.search_first
.in
.max_count
= 1;
83 io
.search_first
.in
.search_attrib
= attrib
;
84 io
.search_first
.in
.pattern
= pattern
;
87 case RAW_SEARCH_TRANS2
:
88 io
.t2ffirst
.level
= RAW_SEARCH_TRANS2
;
89 io
.t2ffirst
.data_level
= data_level
;
90 io
.t2ffirst
.in
.search_attrib
= attrib
;
91 io
.t2ffirst
.in
.max_count
= 1;
92 io
.t2ffirst
.in
.flags
= FLAG_TRANS2_FIND_CLOSE
;
93 io
.t2ffirst
.in
.storage_type
= 0;
94 io
.t2ffirst
.in
.pattern
= pattern
;
98 return NT_STATUS_INVALID_LEVEL
;
101 status
= smb_raw_search_first(cli
->tree
, tctx
,
102 &io
, (void *)data
, single_search_callback
);
104 if (NT_STATUS_IS_OK(status
) && level
== RAW_SEARCH_FFIRST
) {
105 c
.fclose
.level
= RAW_FINDCLOSE_FCLOSE
;
106 c
.fclose
.in
.max_count
= 1;
107 c
.fclose
.in
.search_attrib
= 0;
108 c
.fclose
.in
.id
= data
->search
.id
;
109 status
= smb_raw_search_close(cli
->tree
, &c
);
118 enum smb_search_level level
;
119 enum smb_search_data_level data_level
;
121 int resume_key_offset
;
122 uint32_t capability_mask
;
124 union smb_search_data data
;
127 RAW_SEARCH_FFIRST
, RAW_SEARCH_DATA_SEARCH
,
128 offsetof(union smb_search_data
, search
.name
),
132 RAW_SEARCH_FUNIQUE
, RAW_SEARCH_DATA_SEARCH
,
133 offsetof(union smb_search_data
, search
.name
),
137 RAW_SEARCH_SEARCH
, RAW_SEARCH_DATA_SEARCH
,
138 offsetof(union smb_search_data
, search
.name
),
142 RAW_SEARCH_TRANS2
, RAW_SEARCH_DATA_STANDARD
,
143 offsetof(union smb_search_data
, standard
.name
.s
),
144 offsetof(union smb_search_data
, standard
.resume_key
),
147 RAW_SEARCH_TRANS2
, RAW_SEARCH_DATA_EA_SIZE
,
148 offsetof(union smb_search_data
, ea_size
.name
.s
),
149 offsetof(union smb_search_data
, ea_size
.resume_key
),
152 RAW_SEARCH_TRANS2
, RAW_SEARCH_DATA_DIRECTORY_INFO
,
153 offsetof(union smb_search_data
, directory_info
.name
.s
),
154 offsetof(union smb_search_data
, directory_info
.file_index
),
156 {"FULL_DIRECTORY_INFO",
157 RAW_SEARCH_TRANS2
, RAW_SEARCH_DATA_FULL_DIRECTORY_INFO
,
158 offsetof(union smb_search_data
, full_directory_info
.name
.s
),
159 offsetof(union smb_search_data
, full_directory_info
.file_index
),
162 RAW_SEARCH_TRANS2
, RAW_SEARCH_DATA_NAME_INFO
,
163 offsetof(union smb_search_data
, name_info
.name
.s
),
164 offsetof(union smb_search_data
, name_info
.file_index
),
166 {"BOTH_DIRECTORY_INFO",
167 RAW_SEARCH_TRANS2
, RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
,
168 offsetof(union smb_search_data
, both_directory_info
.name
.s
),
169 offsetof(union smb_search_data
, both_directory_info
.file_index
),
171 {"ID_FULL_DIRECTORY_INFO",
172 RAW_SEARCH_TRANS2
, RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO
,
173 offsetof(union smb_search_data
, id_full_directory_info
.name
.s
),
174 offsetof(union smb_search_data
, id_full_directory_info
.file_index
),
176 {"ID_BOTH_DIRECTORY_INFO",
177 RAW_SEARCH_TRANS2
, RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO
,
178 offsetof(union smb_search_data
, id_both_directory_info
.name
.s
),
179 offsetof(union smb_search_data
, id_both_directory_info
.file_index
),
182 RAW_SEARCH_TRANS2
, RAW_SEARCH_DATA_UNIX_INFO
,
183 offsetof(union smb_search_data
, unix_info
.name
),
184 offsetof(union smb_search_data
, unix_info
.file_index
),
192 static const char *level_name(enum smb_search_level level
,
193 enum smb_search_data_level data_level
)
196 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
197 if (level
== levels
[i
].level
&&
198 data_level
== levels
[i
].data_level
) {
199 return levels
[i
].name
;
206 extract the name from a smb_data structure and level
208 static const char *extract_name(void *data
, enum smb_search_level level
,
209 enum smb_search_data_level data_level
)
212 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
213 if (level
== levels
[i
].level
&&
214 data_level
== levels
[i
].data_level
) {
215 return *(const char **)(levels
[i
].name_offset
+ (char *)data
);
222 extract the name from a smb_data structure and level
224 static uint32_t extract_resume_key(void *data
, enum smb_search_level level
,
225 enum smb_search_data_level data_level
)
228 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
229 if (level
== levels
[i
].level
&&
230 data_level
== levels
[i
].data_level
) {
231 return *(uint32_t *)(levels
[i
].resume_key_offset
+ (char *)data
);
237 /* find a level in the table by name */
238 static union smb_search_data
*find(const char *name
)
241 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
242 if (NT_STATUS_IS_OK(levels
[i
].status
) &&
243 strcmp(levels
[i
].name
, name
) == 0) {
244 return &levels
[i
].data
;
251 basic testing of all RAW_SEARCH_* calls using a single file
253 static bool test_one_file(struct torture_context
*tctx
,
254 struct smbcli_state
*cli
)
258 const char *fname
= "\\torture_search.txt";
259 const char *fname2
= "\\torture_search-NOTEXIST.txt";
262 union smb_fileinfo all_info
, alt_info
, name_info
, internal_info
;
263 bool all_info_supported
, alt_info_supported
, name_info_supported
,
264 internal_info_supported
;
265 union smb_search_data
*s
;
267 fnum
= create_complex_file(cli
, tctx
, fname
);
269 printf("ERROR: open of %s failed (%s)\n", fname
, smbcli_errstr(cli
->tree
));
274 /* call all the levels */
275 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
276 NTSTATUS expected_status
;
277 uint32_t cap
= cli
->transport
->negotiate
.capabilities
;
279 torture_comment(tctx
, "Testing %s\n", levels
[i
].name
);
281 levels
[i
].status
= torture_single_search(cli
, tctx
, fname
,
283 levels
[i
].data_level
,
287 /* see if this server claims to support this level */
288 if (((cap
& levels
[i
].capability_mask
) != levels
[i
].capability_mask
)
289 || NT_STATUS_EQUAL(levels
[i
].status
, NT_STATUS_NOT_SUPPORTED
)) {
290 printf("search level %s(%d) not supported by server\n",
291 levels
[i
].name
, (int)levels
[i
].level
);
295 if (!NT_STATUS_IS_OK(levels
[i
].status
)) {
296 printf("search level %s(%d) failed - %s\n",
297 levels
[i
].name
, (int)levels
[i
].level
,
298 nt_errstr(levels
[i
].status
));
303 status
= torture_single_search(cli
, tctx
, fname2
,
305 levels
[i
].data_level
,
309 expected_status
= NT_STATUS_NO_SUCH_FILE
;
310 if (levels
[i
].level
== RAW_SEARCH_SEARCH
||
311 levels
[i
].level
== RAW_SEARCH_FFIRST
||
312 levels
[i
].level
== RAW_SEARCH_FUNIQUE
) {
313 expected_status
= STATUS_NO_MORE_FILES
;
315 if (!NT_STATUS_EQUAL(status
, expected_status
)) {
316 printf("search level %s(%d) should fail with %s - %s\n",
317 levels
[i
].name
, (int)levels
[i
].level
,
318 nt_errstr(expected_status
),
324 /* get the all_info file into to check against */
325 all_info
.generic
.level
= RAW_FILEINFO_ALL_INFO
;
326 all_info
.generic
.in
.file
.path
= fname
;
327 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &all_info
);
328 CHECK_STATUS_LEVEL(tctx
, status
, "RAW_FILEINFO_ALL_INFO",
331 alt_info
.generic
.level
= RAW_FILEINFO_ALT_NAME_INFO
;
332 alt_info
.generic
.in
.file
.path
= fname
;
333 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &alt_info
);
334 CHECK_STATUS_LEVEL(tctx
, status
, "RAW_FILEINFO_ALT_NAME_INFO",
337 internal_info
.generic
.level
= RAW_FILEINFO_INTERNAL_INFORMATION
;
338 internal_info
.generic
.in
.file
.path
= fname
;
339 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &internal_info
);
340 CHECK_STATUS_LEVEL(tctx
, status
, "RAW_FILEINFO_INTERNAL_INFORMATION",
341 internal_info_supported
);
343 name_info
.generic
.level
= RAW_FILEINFO_NAME_INFO
;
344 name_info
.generic
.in
.file
.path
= fname
;
345 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &name_info
);
346 CHECK_STATUS_LEVEL(tctx
, status
, "RAW_FILEINFO_NAME_INFO",
347 name_info_supported
);
349 #define CHECK_VAL(name, sname1, field1, v, sname2, field2) do { \
352 if ((s->sname1.field1) != (v.sname2.out.field2)) { \
353 printf("(%s) %s/%s [0x%x] != %s/%s [0x%x]\n", \
355 #sname1, #field1, (int)s->sname1.field1, \
356 #sname2, #field2, (int)v.sname2.out.field2); \
361 #define CHECK_TIME(name, sname1, field1, v, sname2, field2) do { \
364 if (s->sname1.field1 != (~1 & nt_time_to_unix(v.sname2.out.field2))) { \
365 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
367 #sname1, #field1, timestring(tctx, s->sname1.field1), \
368 #sname2, #field2, nt_time_string(tctx, v.sname2.out.field2)); \
373 #define CHECK_NTTIME(name, sname1, field1, v, sname2, field2) do { \
376 if (s->sname1.field1 != v.sname2.out.field2) { \
377 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
379 #sname1, #field1, nt_time_string(tctx, s->sname1.field1), \
380 #sname2, #field2, nt_time_string(tctx, v.sname2.out.field2)); \
385 #define CHECK_STR(name, sname1, field1, v, sname2, field2) do { \
388 if (!s->sname1.field1 || strcmp(s->sname1.field1, v.sname2.out.field2.s)) { \
389 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
391 #sname1, #field1, s->sname1.field1, \
392 #sname2, #field2, v.sname2.out.field2.s); \
397 #define CHECK_WSTR(name, sname1, field1, v, sname2, field2, flags) do { \
400 if (!s->sname1.field1.s || \
401 strcmp(s->sname1.field1.s, v.sname2.out.field2.s) || \
402 wire_bad_flags(&s->sname1.field1, flags, cli->transport)) { \
403 printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
405 #sname1, #field1, s->sname1.field1.s, \
406 #sname2, #field2, v.sname2.out.field2.s); \
411 #define CHECK_NAME(name, sname1, field1, fname, flags) do { \
414 if (!s->sname1.field1.s || \
415 strcmp(s->sname1.field1.s, fname) || \
416 wire_bad_flags(&s->sname1.field1, flags, cli->transport)) { \
417 printf("(%s) %s/%s [%s] != %s\n", \
419 #sname1, #field1, s->sname1.field1.s, \
425 #define CHECK_UNIX_NAME(name, sname1, field1, fname, flags) do { \
428 if (!s->sname1.field1 || \
429 strcmp(s->sname1.field1, fname)) { \
430 printf("(%s) %s/%s [%s] != %s\n", \
432 #sname1, #field1, s->sname1.field1, \
438 /* check that all the results are as expected */
439 CHECK_VAL("SEARCH", search
, attrib
, all_info
, all_info
, attrib
&0xFFF);
440 CHECK_VAL("STANDARD", standard
, attrib
, all_info
, all_info
, attrib
&0xFFF);
441 CHECK_VAL("EA_SIZE", ea_size
, attrib
, all_info
, all_info
, attrib
&0xFFF);
442 CHECK_VAL("DIRECTORY_INFO", directory_info
, attrib
, all_info
, all_info
, attrib
);
443 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info
, attrib
, all_info
, all_info
, attrib
);
444 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info
, attrib
, all_info
, all_info
, attrib
);
445 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, attrib
, all_info
, all_info
, attrib
);
446 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, attrib
, all_info
, all_info
, attrib
);
448 CHECK_TIME("SEARCH", search
, write_time
, all_info
, all_info
, write_time
);
449 CHECK_TIME("STANDARD", standard
, write_time
, all_info
, all_info
, write_time
);
450 CHECK_TIME("EA_SIZE", ea_size
, write_time
, all_info
, all_info
, write_time
);
451 CHECK_TIME("STANDARD", standard
, create_time
, all_info
, all_info
, create_time
);
452 CHECK_TIME("EA_SIZE", ea_size
, create_time
, all_info
, all_info
, create_time
);
453 CHECK_TIME("STANDARD", standard
, access_time
, all_info
, all_info
, access_time
);
454 CHECK_TIME("EA_SIZE", ea_size
, access_time
, all_info
, all_info
, access_time
);
456 CHECK_NTTIME("DIRECTORY_INFO", directory_info
, write_time
, all_info
, all_info
, write_time
);
457 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info
, write_time
, all_info
, all_info
, write_time
);
458 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info
, write_time
, all_info
, all_info
, write_time
);
459 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, write_time
, all_info
, all_info
, write_time
);
460 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, write_time
, all_info
, all_info
, write_time
);
462 CHECK_NTTIME("DIRECTORY_INFO", directory_info
, create_time
, all_info
, all_info
, create_time
);
463 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info
, create_time
, all_info
, all_info
, create_time
);
464 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info
, create_time
, all_info
, all_info
, create_time
);
465 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, create_time
, all_info
, all_info
, create_time
);
466 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, create_time
, all_info
, all_info
, create_time
);
468 CHECK_NTTIME("DIRECTORY_INFO", directory_info
, access_time
, all_info
, all_info
, access_time
);
469 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info
, access_time
, all_info
, all_info
, access_time
);
470 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info
, access_time
, all_info
, all_info
, access_time
);
471 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, access_time
, all_info
, all_info
, access_time
);
472 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, access_time
, all_info
, all_info
, access_time
);
474 CHECK_NTTIME("DIRECTORY_INFO", directory_info
, change_time
, all_info
, all_info
, change_time
);
475 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info
, change_time
, all_info
, all_info
, change_time
);
476 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info
, change_time
, all_info
, all_info
, change_time
);
477 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, change_time
, all_info
, all_info
, change_time
);
478 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, change_time
, all_info
, all_info
, change_time
);
480 CHECK_VAL("SEARCH", search
, size
, all_info
, all_info
, size
);
481 CHECK_VAL("STANDARD", standard
, size
, all_info
, all_info
, size
);
482 CHECK_VAL("EA_SIZE", ea_size
, size
, all_info
, all_info
, size
);
483 CHECK_VAL("DIRECTORY_INFO", directory_info
, size
, all_info
, all_info
, size
);
484 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info
, size
, all_info
, all_info
, size
);
485 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info
, size
, all_info
, all_info
, size
);
486 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, size
, all_info
, all_info
, size
);
487 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, size
, all_info
, all_info
, size
);
488 CHECK_VAL("UNIX_INFO", unix_info
, size
, all_info
, all_info
, size
);
490 CHECK_VAL("STANDARD", standard
, alloc_size
, all_info
, all_info
, alloc_size
);
491 CHECK_VAL("EA_SIZE", ea_size
, alloc_size
, all_info
, all_info
, alloc_size
);
492 CHECK_VAL("DIRECTORY_INFO", directory_info
, alloc_size
, all_info
, all_info
, alloc_size
);
493 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info
, alloc_size
, all_info
, all_info
, alloc_size
);
494 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info
, alloc_size
, all_info
, all_info
, alloc_size
);
495 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, alloc_size
, all_info
, all_info
, alloc_size
);
496 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, alloc_size
, all_info
, all_info
, alloc_size
);
497 CHECK_VAL("UNIX_INFO", unix_info
, alloc_size
, all_info
, all_info
, alloc_size
);
499 CHECK_VAL("EA_SIZE", ea_size
, ea_size
, all_info
, all_info
, ea_size
);
500 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info
, ea_size
, all_info
, all_info
, ea_size
);
501 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info
, ea_size
, all_info
, all_info
, ea_size
);
502 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, ea_size
, all_info
, all_info
, ea_size
);
503 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, ea_size
, all_info
, all_info
, ea_size
);
505 if (alt_info_supported
) {
506 CHECK_STR("SEARCH", search
, name
, alt_info
, alt_name_info
,
508 CHECK_WSTR("BOTH_DIRECTORY_INFO", both_directory_info
,
509 short_name
, alt_info
, alt_name_info
, fname
, STR_UNICODE
);
512 CHECK_NAME("STANDARD", standard
, name
, fname
+1, 0);
513 CHECK_NAME("EA_SIZE", ea_size
, name
, fname
+1, 0);
514 CHECK_NAME("DIRECTORY_INFO", directory_info
, name
, fname
+1, STR_TERMINATE_ASCII
);
515 CHECK_NAME("FULL_DIRECTORY_INFO", full_directory_info
, name
, fname
+1, STR_TERMINATE_ASCII
);
517 if (name_info_supported
) {
518 CHECK_NAME("NAME_INFO", name_info
, name
, fname
+1,
519 STR_TERMINATE_ASCII
);
522 CHECK_NAME("BOTH_DIRECTORY_INFO", both_directory_info
, name
, fname
+1, STR_TERMINATE_ASCII
);
523 CHECK_NAME("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, name
, fname
+1, STR_TERMINATE_ASCII
);
524 CHECK_NAME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, name
, fname
+1, STR_TERMINATE_ASCII
);
525 CHECK_UNIX_NAME("UNIX_INFO", unix_info
, name
, fname
+1, STR_TERMINATE_ASCII
);
527 if (internal_info_supported
) {
528 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info
,
529 file_id
, internal_info
, internal_information
, file_id
);
530 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
,
531 file_id
, internal_info
, internal_information
, file_id
);
535 smb_raw_exit(cli
->session
);
536 smbcli_unlink(cli
->tree
, fname
);
542 struct multiple_result
{
545 union smb_search_data
*list
;
549 callback function for multiple_search
551 static bool multiple_search_callback(void *private_data
, const union smb_search_data
*file
)
553 struct multiple_result
*data
= (struct multiple_result
*)private_data
;
557 data
->list
= talloc_realloc(data
->tctx
,
559 union smb_search_data
,
562 data
->list
[data
->count
-1] = *file
;
567 enum continue_type
{CONT_FLAGS
, CONT_NAME
, CONT_RESUME_KEY
};
570 do a single file (non-wildcard) search
572 static NTSTATUS
multiple_search(struct smbcli_state
*cli
,
575 enum smb_search_data_level data_level
,
576 enum continue_type cont_type
,
579 union smb_search_first io
;
580 union smb_search_next io2
;
582 const int per_search
= 100;
583 struct multiple_result
*result
= (struct multiple_result
*)data
;
585 if (data_level
== RAW_SEARCH_DATA_SEARCH
) {
586 io
.search_first
.level
= RAW_SEARCH_SEARCH
;
587 io
.search_first
.data_level
= RAW_SEARCH_DATA_SEARCH
;
588 io
.search_first
.in
.max_count
= per_search
;
589 io
.search_first
.in
.search_attrib
= 0;
590 io
.search_first
.in
.pattern
= pattern
;
592 io
.t2ffirst
.level
= RAW_SEARCH_TRANS2
;
593 io
.t2ffirst
.data_level
= data_level
;
594 io
.t2ffirst
.in
.search_attrib
= 0;
595 io
.t2ffirst
.in
.max_count
= per_search
;
596 io
.t2ffirst
.in
.flags
= FLAG_TRANS2_FIND_CLOSE_IF_END
;
597 io
.t2ffirst
.in
.storage_type
= 0;
598 io
.t2ffirst
.in
.pattern
= pattern
;
599 if (cont_type
== CONT_RESUME_KEY
) {
600 io
.t2ffirst
.in
.flags
|= FLAG_TRANS2_FIND_REQUIRE_RESUME
|
601 FLAG_TRANS2_FIND_BACKUP_INTENT
;
605 status
= smb_raw_search_first(cli
->tree
, tctx
,
606 &io
, data
, multiple_search_callback
);
609 while (NT_STATUS_IS_OK(status
)) {
610 if (data_level
== RAW_SEARCH_DATA_SEARCH
) {
611 io2
.search_next
.level
= RAW_SEARCH_SEARCH
;
612 io2
.search_next
.data_level
= RAW_SEARCH_DATA_SEARCH
;
613 io2
.search_next
.in
.max_count
= per_search
;
614 io2
.search_next
.in
.search_attrib
= 0;
615 io2
.search_next
.in
.id
= result
->list
[result
->count
-1].search
.id
;
617 io2
.t2fnext
.level
= RAW_SEARCH_TRANS2
;
618 io2
.t2fnext
.data_level
= data_level
;
619 io2
.t2fnext
.in
.handle
= io
.t2ffirst
.out
.handle
;
620 io2
.t2fnext
.in
.max_count
= per_search
;
621 io2
.t2fnext
.in
.resume_key
= 0;
622 io2
.t2fnext
.in
.flags
= FLAG_TRANS2_FIND_CLOSE_IF_END
;
623 io2
.t2fnext
.in
.last_name
= "";
625 case CONT_RESUME_KEY
:
626 io2
.t2fnext
.in
.resume_key
= extract_resume_key(&result
->list
[result
->count
-1],
627 io2
.t2fnext
.level
, io2
.t2fnext
.data_level
);
628 if (io2
.t2fnext
.in
.resume_key
== 0) {
629 printf("Server does not support resume by key for level %s\n",
630 level_name(io2
.t2fnext
.level
, io2
.t2fnext
.data_level
));
631 return NT_STATUS_NOT_SUPPORTED
;
633 io2
.t2fnext
.in
.flags
|= FLAG_TRANS2_FIND_REQUIRE_RESUME
|
634 FLAG_TRANS2_FIND_BACKUP_INTENT
;
637 io2
.t2fnext
.in
.last_name
= extract_name(&result
->list
[result
->count
-1],
638 io2
.t2fnext
.level
, io2
.t2fnext
.data_level
);
641 io2
.t2fnext
.in
.flags
|= FLAG_TRANS2_FIND_CONTINUE
;
646 status
= smb_raw_search_next(cli
->tree
, tctx
,
647 &io2
, data
, multiple_search_callback
);
648 if (!NT_STATUS_IS_OK(status
)) {
651 if (data_level
== RAW_SEARCH_DATA_SEARCH
) {
652 if (io2
.search_next
.out
.count
== 0) {
655 } else if (io2
.t2fnext
.out
.count
== 0 ||
656 io2
.t2fnext
.out
.end_of_search
) {
664 #define CHECK_STATUS(status, correct) torture_assert_ntstatus_equal(tctx, status, correct, "incorrect status")
666 #define CHECK_VALUE(v, correct) torture_assert_int_equal(tctx, (v), (correct), "incorrect value");
668 #define CHECK_STRING(v, correct) torture_assert_casestr_equal(tctx, v, correct, "incorrect value");
671 static enum smb_search_data_level compare_data_level
;
673 static int search_compare(union smb_search_data
*d1
, union smb_search_data
*d2
)
676 enum smb_search_level level
;
678 if (compare_data_level
== RAW_SEARCH_DATA_SEARCH
) {
679 level
= RAW_SEARCH_SEARCH
;
681 level
= RAW_SEARCH_TRANS2
;
684 s1
= extract_name(d1
, level
, compare_data_level
);
685 s2
= extract_name(d2
, level
, compare_data_level
);
686 return strcmp_safe(s1
, s2
);
692 basic testing of search calls using many files
694 static bool test_many_files(struct torture_context
*tctx
,
695 struct smbcli_state
*cli
)
697 const int num_files
= 700;
702 struct multiple_result result
;
705 const char *cont_name
;
706 enum smb_search_data_level data_level
;
707 enum continue_type cont_type
;
709 {"SEARCH", "ID", RAW_SEARCH_DATA_SEARCH
, CONT_RESUME_KEY
},
710 {"BOTH_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
, CONT_NAME
},
711 {"BOTH_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
, CONT_FLAGS
},
712 {"BOTH_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
, CONT_RESUME_KEY
},
713 {"STANDARD", "FLAGS", RAW_SEARCH_DATA_STANDARD
, CONT_FLAGS
},
714 {"STANDARD", "KEY", RAW_SEARCH_DATA_STANDARD
, CONT_RESUME_KEY
},
715 {"STANDARD", "NAME", RAW_SEARCH_DATA_STANDARD
, CONT_NAME
},
716 {"EA_SIZE", "FLAGS", RAW_SEARCH_DATA_EA_SIZE
, CONT_FLAGS
},
717 {"EA_SIZE", "KEY", RAW_SEARCH_DATA_EA_SIZE
, CONT_RESUME_KEY
},
718 {"EA_SIZE", "NAME", RAW_SEARCH_DATA_EA_SIZE
, CONT_NAME
},
719 {"DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_DIRECTORY_INFO
, CONT_FLAGS
},
720 {"DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_DIRECTORY_INFO
, CONT_RESUME_KEY
},
721 {"DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_DIRECTORY_INFO
, CONT_NAME
},
722 {"FULL_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_FULL_DIRECTORY_INFO
, CONT_FLAGS
},
723 {"FULL_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_FULL_DIRECTORY_INFO
, CONT_RESUME_KEY
},
724 {"FULL_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_FULL_DIRECTORY_INFO
, CONT_NAME
},
725 {"ID_FULL_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO
, CONT_FLAGS
},
726 {"ID_FULL_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO
, CONT_RESUME_KEY
},
727 {"ID_FULL_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO
, CONT_NAME
},
728 {"ID_BOTH_DIRECTORY_INFO", "NAME", RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO
, CONT_NAME
},
729 {"ID_BOTH_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO
, CONT_FLAGS
},
730 {"ID_BOTH_DIRECTORY_INFO", "KEY", RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO
, CONT_RESUME_KEY
}
733 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
735 torture_comment(tctx
, "Testing with %d files\n", num_files
);
737 for (i
=0;i
<num_files
;i
++) {
738 fname
= talloc_asprintf(cli
, BASEDIR
"\\t%03d-%d.txt", i
, i
);
739 fnum
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
, DENY_NONE
);
740 torture_assert(tctx
, fnum
!= -1, "Failed to create");
742 smbcli_close(cli
->tree
, fnum
);
746 for (t
=0;t
<ARRAY_SIZE(search_types
);t
++) {
749 if ((search_types
[t
].cont_type
== CONT_RESUME_KEY
) &&
750 (search_types
[t
].data_level
!= RAW_SEARCH_DATA_SEARCH
) &&
751 !torture_setting_bool(tctx
, "resume_key_support", true)) {
752 torture_comment(tctx
,
753 "SKIP: Continue %s via %s\n",
754 search_types
[t
].name
, search_types
[t
].cont_name
);
758 result
.tctx
= talloc_new(tctx
);
760 torture_comment(tctx
,
761 "Continue %s via %s\n", search_types
[t
].name
, search_types
[t
].cont_name
);
763 status
= multiple_search(cli
, tctx
, BASEDIR
"\\*.*",
764 search_types
[t
].data_level
,
765 search_types
[t
].cont_type
,
767 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_SUPPORTED
)) {
768 torture_warning(tctx
, "search level %s not supported "
770 search_types
[t
].name
);
773 torture_assert_ntstatus_ok(tctx
, status
, "search failed");
774 CHECK_VALUE(result
.count
, num_files
);
776 compare_data_level
= search_types
[t
].data_level
;
778 TYPESAFE_QSORT(result
.list
, result
.count
, search_compare
);
780 for (i
=0;i
<result
.count
;i
++) {
782 enum smb_search_level level
;
783 if (compare_data_level
== RAW_SEARCH_DATA_SEARCH
) {
784 level
= RAW_SEARCH_SEARCH
;
786 level
= RAW_SEARCH_TRANS2
;
788 s
= extract_name(&result
.list
[i
], level
, compare_data_level
);
789 fname
= talloc_asprintf(cli
, "t%03d-%d.txt", i
, i
);
790 torture_assert_str_equal(tctx
, fname
, s
, "Incorrect name");
793 talloc_free(result
.tctx
);
796 smb_raw_exit(cli
->session
);
797 smbcli_deltree(cli
->tree
, BASEDIR
);
803 check a individual file result
805 static bool check_result(struct multiple_result
*result
, const char *name
, bool exist
, uint32_t attrib
)
808 for (i
=0;i
<result
->count
;i
++) {
809 if (strcmp(name
, result
->list
[i
].both_directory_info
.name
.s
) == 0) break;
811 if (i
== result
->count
) {
813 printf("failed: '%s' should exist with attribute %s\n",
814 name
, attrib_string(result
->list
, attrib
));
821 printf("failed: '%s' should NOT exist (has attribute %s)\n",
822 name
, attrib_string(result
->list
, result
->list
[i
].both_directory_info
.attrib
));
826 if ((result
->list
[i
].both_directory_info
.attrib
&0xFFF) != attrib
) {
827 printf("failed: '%s' should have attribute 0x%x (has 0x%x)\n",
829 attrib
, result
->list
[i
].both_directory_info
.attrib
);
836 test what happens when the directory is modified during a search
838 static bool test_modify_search(struct torture_context
*tctx
,
839 struct smbcli_state
*cli
)
841 const int num_files
= 20;
846 struct multiple_result result
;
847 union smb_search_first io
;
848 union smb_search_next io2
;
849 union smb_setfileinfo sfinfo
;
851 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
853 printf("Creating %d files\n", num_files
);
855 for (i
=num_files
-1;i
>=0;i
--) {
856 fname
= talloc_asprintf(cli
, BASEDIR
"\\t%03d-%d.txt", i
, i
);
857 fnum
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
, DENY_NONE
);
859 printf("Failed to create %s - %s\n", fname
, smbcli_errstr(cli
->tree
));
864 smbcli_close(cli
->tree
, fnum
);
867 printf("pulling the first file\n");
869 result
.tctx
= talloc_new(tctx
);
871 io
.t2ffirst
.level
= RAW_SEARCH_TRANS2
;
872 io
.t2ffirst
.data_level
= RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
;
873 io
.t2ffirst
.in
.search_attrib
= 0;
874 io
.t2ffirst
.in
.max_count
= 0;
875 io
.t2ffirst
.in
.flags
= 0;
876 io
.t2ffirst
.in
.storage_type
= 0;
877 io
.t2ffirst
.in
.pattern
= BASEDIR
"\\*.*";
879 status
= smb_raw_search_first(cli
->tree
, tctx
,
880 &io
, &result
, multiple_search_callback
);
881 CHECK_STATUS(status
, NT_STATUS_OK
);
882 CHECK_VALUE(result
.count
, 1);
884 printf("pulling the second file\n");
885 io2
.t2fnext
.level
= RAW_SEARCH_TRANS2
;
886 io2
.t2fnext
.data_level
= RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
;
887 io2
.t2fnext
.in
.handle
= io
.t2ffirst
.out
.handle
;
888 io2
.t2fnext
.in
.max_count
= 1;
889 io2
.t2fnext
.in
.resume_key
= 0;
890 io2
.t2fnext
.in
.flags
= 0;
891 io2
.t2fnext
.in
.last_name
= result
.list
[result
.count
-1].both_directory_info
.name
.s
;
893 status
= smb_raw_search_next(cli
->tree
, tctx
,
894 &io2
, &result
, multiple_search_callback
);
895 CHECK_STATUS(status
, NT_STATUS_OK
);
896 CHECK_VALUE(result
.count
, 2);
900 printf("Changing attributes and deleting\n");
901 smbcli_open(cli
->tree
, BASEDIR
"\\T003-03.txt.2", O_CREAT
|O_RDWR
, DENY_NONE
);
902 smbcli_open(cli
->tree
, BASEDIR
"\\T013-13.txt.2", O_CREAT
|O_RDWR
, DENY_NONE
);
903 fnum
= create_complex_file(cli
, tctx
, BASEDIR
"\\T013-13.txt.3");
904 smbcli_unlink(cli
->tree
, BASEDIR
"\\T014-14.txt");
905 torture_set_file_attribute(cli
->tree
, BASEDIR
"\\T015-15.txt", FILE_ATTRIBUTE_HIDDEN
);
906 torture_set_file_attribute(cli
->tree
, BASEDIR
"\\T016-16.txt", FILE_ATTRIBUTE_NORMAL
);
907 torture_set_file_attribute(cli
->tree
, BASEDIR
"\\T017-17.txt", FILE_ATTRIBUTE_SYSTEM
);
908 torture_set_file_attribute(cli
->tree
, BASEDIR
"\\T018-18.txt", 0);
909 sfinfo
.generic
.level
= RAW_SFILEINFO_DISPOSITION_INFORMATION
;
910 sfinfo
.generic
.in
.file
.fnum
= fnum
;
911 sfinfo
.disposition_info
.in
.delete_on_close
= 1;
912 status
= smb_raw_setfileinfo(cli
->tree
, &sfinfo
);
913 CHECK_STATUS(status
, NT_STATUS_OK
);
915 io2
.t2fnext
.level
= RAW_SEARCH_TRANS2
;
916 io2
.t2fnext
.data_level
= RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
;
917 io2
.t2fnext
.in
.handle
= io
.t2ffirst
.out
.handle
;
918 io2
.t2fnext
.in
.max_count
= num_files
+ 3;
919 io2
.t2fnext
.in
.resume_key
= 0;
920 io2
.t2fnext
.in
.flags
= 0;
921 io2
.t2fnext
.in
.last_name
= ".";
923 status
= smb_raw_search_next(cli
->tree
, tctx
,
924 &io2
, &result
, multiple_search_callback
);
925 CHECK_STATUS(status
, NT_STATUS_OK
);
926 CHECK_VALUE(result
.count
, 20);
928 ret
&= check_result(&result
, "t009-9.txt", true, FILE_ATTRIBUTE_ARCHIVE
);
929 ret
&= check_result(&result
, "t014-14.txt", false, 0);
930 ret
&= check_result(&result
, "t015-15.txt", false, 0);
931 ret
&= check_result(&result
, "t016-16.txt", true, FILE_ATTRIBUTE_NORMAL
);
932 ret
&= check_result(&result
, "t017-17.txt", false, 0);
933 ret
&= check_result(&result
, "t018-18.txt", true, FILE_ATTRIBUTE_ARCHIVE
);
934 ret
&= check_result(&result
, "t019-19.txt", true, FILE_ATTRIBUTE_ARCHIVE
);
935 ret
&= check_result(&result
, "T013-13.txt.2", true, FILE_ATTRIBUTE_ARCHIVE
);
936 ret
&= check_result(&result
, "T003-3.txt.2", false, 0);
937 ret
&= check_result(&result
, "T013-13.txt.3", true, FILE_ATTRIBUTE_ARCHIVE
);
940 for (i
=0;i
<result
.count
;i
++) {
941 printf("%s %s (0x%x)\n",
942 result
.list
[i
].both_directory_info
.name
.s
,
943 attrib_string(tctx
, result
.list
[i
].both_directory_info
.attrib
),
944 result
.list
[i
].both_directory_info
.attrib
);
949 smb_raw_exit(cli
->session
);
950 smbcli_deltree(cli
->tree
, BASEDIR
);
957 testing if directories always come back sorted
959 static bool test_sorted(struct torture_context
*tctx
, struct smbcli_state
*cli
)
961 const int num_files
= 700;
966 struct multiple_result result
;
968 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
970 printf("Creating %d files\n", num_files
);
972 for (i
=0;i
<num_files
;i
++) {
973 fname
= talloc_asprintf(cli
, BASEDIR
"\\%s.txt", generate_random_str_list(tctx
, 10, "abcdefgh"));
974 fnum
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
, DENY_NONE
);
976 printf("Failed to create %s - %s\n", fname
, smbcli_errstr(cli
->tree
));
981 smbcli_close(cli
->tree
, fnum
);
988 status
= multiple_search(cli
, tctx
, BASEDIR
"\\*.*",
989 RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
,
991 CHECK_STATUS(status
, NT_STATUS_OK
);
992 CHECK_VALUE(result
.count
, num_files
);
994 for (i
=0;i
<num_files
-1;i
++) {
995 const char *name1
, *name2
;
996 name1
= result
.list
[i
].both_directory_info
.name
.s
;
997 name2
= result
.list
[i
+1].both_directory_info
.name
.s
;
998 if (strcasecmp_m(name1
, name2
) > 0) {
999 printf("non-alphabetical order at entry %d '%s' '%s'\n",
1001 printf("Server does not produce sorted directory listings (not an error)\n");
1006 talloc_free(result
.list
);
1009 smb_raw_exit(cli
->session
);
1010 smbcli_deltree(cli
->tree
, BASEDIR
);
1018 basic testing of many old style search calls using separate dirs
1020 static bool test_many_dirs(struct torture_context
*tctx
,
1021 struct smbcli_state
*cli
)
1023 const int num_dirs
= 20;
1025 char *fname
, *dname
;
1028 union smb_search_data
*file
, *file2
, *file3
;
1030 if (!torture_setting_bool(tctx
, "raw_search_search", true)) {
1031 torture_comment(tctx
, "Skipping these tests as the server "
1032 "doesn't support old style search calls\n");
1035 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1037 printf("Creating %d dirs\n", num_dirs
);
1039 for (i
=0;i
<num_dirs
;i
++) {
1040 dname
= talloc_asprintf(cli
, BASEDIR
"\\d%d", i
);
1041 status
= smbcli_mkdir(cli
->tree
, dname
);
1042 if (!NT_STATUS_IS_OK(status
)) {
1043 printf("(%s) Failed to create %s - %s\n",
1044 __location__
, dname
, nt_errstr(status
));
1050 fname
= talloc_asprintf(cli
, BASEDIR
"\\d%d\\f%d-%d.txt", i
, i
, n
);
1051 fnum
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
, DENY_NONE
);
1053 printf("(%s) Failed to create %s - %s\n",
1054 __location__
, fname
, smbcli_errstr(cli
->tree
));
1059 smbcli_close(cli
->tree
, fnum
);
1065 file
= talloc_zero_array(tctx
, union smb_search_data
, num_dirs
);
1066 file2
= talloc_zero_array(tctx
, union smb_search_data
, num_dirs
);
1067 file3
= talloc_zero_array(tctx
, union smb_search_data
, num_dirs
);
1069 printf("Search first on %d dirs\n", num_dirs
);
1071 for (i
=0;i
<num_dirs
;i
++) {
1072 union smb_search_first io
;
1073 io
.search_first
.level
= RAW_SEARCH_SEARCH
;
1074 io
.search_first
.data_level
= RAW_SEARCH_DATA_SEARCH
;
1075 io
.search_first
.in
.max_count
= 1;
1076 io
.search_first
.in
.search_attrib
= 0;
1077 io
.search_first
.in
.pattern
= talloc_asprintf(tctx
, BASEDIR
"\\d%d\\*.txt", i
);
1078 fname
= talloc_asprintf(tctx
, "f%d-", i
);
1080 io
.search_first
.out
.count
= 0;
1082 status
= smb_raw_search_first(cli
->tree
, tctx
,
1083 &io
, (void *)&file
[i
], single_search_callback
);
1084 if (io
.search_first
.out
.count
!= 1) {
1085 printf("(%s) search first gave %d entries for dir %d - %s\n",
1086 __location__
, io
.search_first
.out
.count
, i
, nt_errstr(status
));
1090 CHECK_STATUS(status
, NT_STATUS_OK
);
1091 if (strncasecmp(file
[i
].search
.name
, fname
, strlen(fname
)) != 0) {
1092 printf("(%s) incorrect name '%s' expected '%s'[12].txt\n",
1093 __location__
, file
[i
].search
.name
, fname
);
1101 printf("Search next on %d dirs\n", num_dirs
);
1103 for (i
=0;i
<num_dirs
;i
++) {
1104 union smb_search_next io2
;
1106 io2
.search_next
.level
= RAW_SEARCH_SEARCH
;
1107 io2
.search_next
.data_level
= RAW_SEARCH_DATA_SEARCH
;
1108 io2
.search_next
.in
.max_count
= 1;
1109 io2
.search_next
.in
.search_attrib
= 0;
1110 io2
.search_next
.in
.id
= file
[i
].search
.id
;
1111 fname
= talloc_asprintf(tctx
, "f%d-", i
);
1113 io2
.search_next
.out
.count
= 0;
1115 status
= smb_raw_search_next(cli
->tree
, tctx
,
1116 &io2
, (void *)&file2
[i
], single_search_callback
);
1117 if (io2
.search_next
.out
.count
!= 1) {
1118 printf("(%s) search next gave %d entries for dir %d - %s\n",
1119 __location__
, io2
.search_next
.out
.count
, i
, nt_errstr(status
));
1123 CHECK_STATUS(status
, NT_STATUS_OK
);
1124 if (strncasecmp(file2
[i
].search
.name
, fname
, strlen(fname
)) != 0) {
1125 printf("(%s) incorrect name '%s' expected '%s'[12].txt\n",
1126 __location__
, file2
[i
].search
.name
, fname
);
1135 printf("Search next (rewind) on %d dirs\n", num_dirs
);
1137 for (i
=0;i
<num_dirs
;i
++) {
1138 union smb_search_next io2
;
1140 io2
.search_next
.level
= RAW_SEARCH_SEARCH
;
1141 io2
.search_next
.data_level
= RAW_SEARCH_DATA_SEARCH
;
1142 io2
.search_next
.in
.max_count
= 1;
1143 io2
.search_next
.in
.search_attrib
= 0;
1144 io2
.search_next
.in
.id
= file
[i
].search
.id
;
1145 fname
= talloc_asprintf(tctx
, "f%d-", i
);
1146 io2
.search_next
.out
.count
= 0;
1148 status
= smb_raw_search_next(cli
->tree
, tctx
,
1149 &io2
, (void *)&file3
[i
], single_search_callback
);
1150 if (io2
.search_next
.out
.count
!= 1) {
1151 printf("(%s) search next gave %d entries for dir %d - %s\n",
1152 __location__
, io2
.search_next
.out
.count
, i
, nt_errstr(status
));
1156 CHECK_STATUS(status
, NT_STATUS_OK
);
1158 if (strncasecmp(file3
[i
].search
.name
, file2
[i
].search
.name
, 3) != 0) {
1159 printf("(%s) incorrect name '%s' on rewind at dir %d\n",
1160 __location__
, file2
[i
].search
.name
, i
);
1165 if (torture_setting_bool(tctx
, "rewind_support", true) &&
1166 strcmp(file3
[i
].search
.name
, file2
[i
].search
.name
) != 0) {
1167 printf("(%s) server did not rewind - got '%s' expected '%s'\n",
1168 __location__
, file3
[i
].search
.name
, file2
[i
].search
.name
);
1178 smb_raw_exit(cli
->session
);
1179 smbcli_deltree(cli
->tree
, BASEDIR
);
1186 testing of OS/2 style delete
1188 static bool test_os2_delete(struct torture_context
*tctx
,
1189 struct smbcli_state
*cli
)
1191 const int num_files
= 700;
1192 const int delete_count
= 4;
1193 int total_deleted
= 0;
1198 union smb_search_first io
;
1199 union smb_search_next io2
;
1200 struct multiple_result result
;
1202 if (!torture_setting_bool(tctx
, "search_ea_size", true)){
1203 torture_comment(tctx
,
1204 "Server does not support RAW_SEARCH_EA_SIZE "
1205 "level. Skipping this test\n");
1209 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1211 printf("Testing OS/2 style delete on %d files\n", num_files
);
1213 for (i
=0;i
<num_files
;i
++) {
1214 fname
= talloc_asprintf(cli
, BASEDIR
"\\file%u.txt", i
);
1215 fnum
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
, DENY_NONE
);
1217 printf("Failed to create %s - %s\n", fname
, smbcli_errstr(cli
->tree
));
1222 smbcli_close(cli
->tree
, fnum
);
1226 ZERO_STRUCT(result
);
1229 io
.t2ffirst
.level
= RAW_SEARCH_TRANS2
;
1230 io
.t2ffirst
.data_level
= RAW_SEARCH_DATA_EA_SIZE
;
1231 io
.t2ffirst
.in
.search_attrib
= 0;
1232 io
.t2ffirst
.in
.max_count
= 100;
1233 io
.t2ffirst
.in
.flags
= FLAG_TRANS2_FIND_REQUIRE_RESUME
;
1234 io
.t2ffirst
.in
.storage_type
= 0;
1235 io
.t2ffirst
.in
.pattern
= BASEDIR
"\\*";
1237 status
= smb_raw_search_first(cli
->tree
, tctx
,
1238 &io
, &result
, multiple_search_callback
);
1239 CHECK_STATUS(status
, NT_STATUS_OK
);
1241 for (i
=0;i
<MIN(result
.count
, delete_count
);i
++) {
1242 fname
= talloc_asprintf(cli
, BASEDIR
"\\%s", result
.list
[i
].ea_size
.name
.s
);
1243 status
= smbcli_unlink(cli
->tree
, fname
);
1244 CHECK_STATUS(status
, NT_STATUS_OK
);
1249 io2
.t2fnext
.level
= RAW_SEARCH_TRANS2
;
1250 io2
.t2fnext
.data_level
= RAW_SEARCH_DATA_EA_SIZE
;
1251 io2
.t2fnext
.in
.handle
= io
.t2ffirst
.out
.handle
;
1252 io2
.t2fnext
.in
.max_count
= 100;
1253 io2
.t2fnext
.in
.resume_key
= result
.list
[i
-1].ea_size
.resume_key
;
1254 io2
.t2fnext
.in
.flags
= FLAG_TRANS2_FIND_REQUIRE_RESUME
;
1255 io2
.t2fnext
.in
.last_name
= result
.list
[i
-1].ea_size
.name
.s
;
1258 ZERO_STRUCT(result
);
1261 status
= smb_raw_search_next(cli
->tree
, tctx
,
1262 &io2
, &result
, multiple_search_callback
);
1263 if (!NT_STATUS_IS_OK(status
)) {
1267 for (i
=0;i
<MIN(result
.count
, delete_count
);i
++) {
1268 fname
= talloc_asprintf(cli
, BASEDIR
"\\%s", result
.list
[i
].ea_size
.name
.s
);
1269 status
= smbcli_unlink(cli
->tree
, fname
);
1270 CHECK_STATUS(status
, NT_STATUS_OK
);
1276 io2
.t2fnext
.in
.resume_key
= result
.list
[i
-1].ea_size
.resume_key
;
1277 io2
.t2fnext
.in
.last_name
= result
.list
[i
-1].ea_size
.name
.s
;
1279 } while (NT_STATUS_IS_OK(status
) && result
.count
!= 0);
1281 CHECK_STATUS(status
, NT_STATUS_OK
);
1283 if (total_deleted
!= num_files
) {
1284 printf("error: deleted %d - expected to delete %d\n",
1285 total_deleted
, num_files
);
1290 smb_raw_exit(cli
->session
);
1291 smbcli_deltree(cli
->tree
, BASEDIR
);
1297 static int ealist_cmp(union smb_search_data
*r1
, union smb_search_data
*r2
)
1299 return strcmp(r1
->ea_list
.name
.s
, r2
->ea_list
.name
.s
);
1303 testing of the rather strange ea_list level
1305 static bool test_ea_list(struct torture_context
*tctx
,
1306 struct smbcli_state
*cli
)
1311 union smb_search_first io
;
1312 union smb_search_next nxt
;
1313 struct multiple_result result
;
1314 union smb_setfileinfo setfile
;
1316 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1318 printf("Testing RAW_SEARCH_EA_LIST level\n");
1320 if (!torture_setting_bool(tctx
, "search_ea_support", true) ||
1321 !torture_setting_bool(tctx
, "ea_support", true)) {
1322 printf("..skipped per target configuration.\n");
1326 fnum
= smbcli_open(cli
->tree
, BASEDIR
"\\file1.txt", O_CREAT
|O_RDWR
, DENY_NONE
);
1327 smbcli_close(cli
->tree
, fnum
);
1329 fnum
= smbcli_open(cli
->tree
, BASEDIR
"\\file2.txt", O_CREAT
|O_RDWR
, DENY_NONE
);
1330 smbcli_close(cli
->tree
, fnum
);
1332 fnum
= smbcli_open(cli
->tree
, BASEDIR
"\\file3.txt", O_CREAT
|O_RDWR
, DENY_NONE
);
1333 smbcli_close(cli
->tree
, fnum
);
1335 setfile
.generic
.level
= RAW_SFILEINFO_EA_SET
;
1336 setfile
.generic
.in
.file
.path
= BASEDIR
"\\file2.txt";
1337 setfile
.ea_set
.in
.num_eas
= 2;
1338 setfile
.ea_set
.in
.eas
= talloc_array(tctx
, struct ea_struct
, 2);
1339 setfile
.ea_set
.in
.eas
[0].flags
= 0;
1340 setfile
.ea_set
.in
.eas
[0].name
.s
= "EA ONE";
1341 setfile
.ea_set
.in
.eas
[0].value
= data_blob_string_const("VALUE 1");
1342 setfile
.ea_set
.in
.eas
[1].flags
= 0;
1343 setfile
.ea_set
.in
.eas
[1].name
.s
= "SECOND EA";
1344 setfile
.ea_set
.in
.eas
[1].value
= data_blob_string_const("Value Two");
1346 status
= smb_raw_setpathinfo(cli
->tree
, &setfile
);
1347 CHECK_STATUS(status
, NT_STATUS_OK
);
1349 setfile
.generic
.in
.file
.path
= BASEDIR
"\\file3.txt";
1350 status
= smb_raw_setpathinfo(cli
->tree
, &setfile
);
1351 CHECK_STATUS(status
, NT_STATUS_OK
);
1353 ZERO_STRUCT(result
);
1356 io
.t2ffirst
.level
= RAW_SEARCH_TRANS2
;
1357 io
.t2ffirst
.data_level
= RAW_SEARCH_DATA_EA_LIST
;
1358 io
.t2ffirst
.in
.search_attrib
= 0;
1359 io
.t2ffirst
.in
.max_count
= 2;
1360 io
.t2ffirst
.in
.flags
= FLAG_TRANS2_FIND_REQUIRE_RESUME
;
1361 io
.t2ffirst
.in
.storage_type
= 0;
1362 io
.t2ffirst
.in
.pattern
= BASEDIR
"\\*";
1363 io
.t2ffirst
.in
.num_names
= 2;
1364 io
.t2ffirst
.in
.ea_names
= talloc_array(tctx
, struct ea_name
, 2);
1365 io
.t2ffirst
.in
.ea_names
[0].name
.s
= "SECOND EA";
1366 io
.t2ffirst
.in
.ea_names
[1].name
.s
= "THIRD EA";
1368 status
= smb_raw_search_first(cli
->tree
, tctx
,
1369 &io
, &result
, multiple_search_callback
);
1370 CHECK_STATUS(status
, NT_STATUS_OK
);
1371 CHECK_VALUE(result
.count
, 2);
1373 nxt
.t2fnext
.level
= RAW_SEARCH_TRANS2
;
1374 nxt
.t2fnext
.data_level
= RAW_SEARCH_DATA_EA_LIST
;
1375 nxt
.t2fnext
.in
.handle
= io
.t2ffirst
.out
.handle
;
1376 nxt
.t2fnext
.in
.max_count
= 2;
1377 nxt
.t2fnext
.in
.resume_key
= result
.list
[1].ea_list
.resume_key
;
1378 nxt
.t2fnext
.in
.flags
= FLAG_TRANS2_FIND_REQUIRE_RESUME
| FLAG_TRANS2_FIND_CONTINUE
;
1379 nxt
.t2fnext
.in
.last_name
= result
.list
[1].ea_list
.name
.s
;
1380 nxt
.t2fnext
.in
.num_names
= 2;
1381 nxt
.t2fnext
.in
.ea_names
= talloc_array(tctx
, struct ea_name
, 2);
1382 nxt
.t2fnext
.in
.ea_names
[0].name
.s
= "SECOND EA";
1383 nxt
.t2fnext
.in
.ea_names
[1].name
.s
= "THIRD EA";
1385 status
= smb_raw_search_next(cli
->tree
, tctx
,
1386 &nxt
, &result
, multiple_search_callback
);
1387 CHECK_STATUS(status
, NT_STATUS_OK
);
1389 /* we have to sort the result as different servers can return directories
1390 in different orders */
1391 TYPESAFE_QSORT(result
.list
, result
.count
, ealist_cmp
);
1393 CHECK_VALUE(result
.count
, 3);
1394 CHECK_VALUE(result
.list
[0].ea_list
.eas
.num_eas
, 2);
1395 CHECK_STRING(result
.list
[0].ea_list
.name
.s
, "file1.txt");
1396 CHECK_STRING(result
.list
[0].ea_list
.eas
.eas
[0].name
.s
, "SECOND EA");
1397 CHECK_VALUE(result
.list
[0].ea_list
.eas
.eas
[0].value
.length
, 0);
1398 CHECK_STRING(result
.list
[0].ea_list
.eas
.eas
[1].name
.s
, "THIRD EA");
1399 CHECK_VALUE(result
.list
[0].ea_list
.eas
.eas
[1].value
.length
, 0);
1401 CHECK_STRING(result
.list
[1].ea_list
.name
.s
, "file2.txt");
1402 CHECK_STRING(result
.list
[1].ea_list
.eas
.eas
[0].name
.s
, "SECOND EA");
1403 CHECK_VALUE(result
.list
[1].ea_list
.eas
.eas
[0].value
.length
, 9);
1404 CHECK_STRING((const char *)result
.list
[1].ea_list
.eas
.eas
[0].value
.data
, "Value Two");
1405 CHECK_STRING(result
.list
[1].ea_list
.eas
.eas
[1].name
.s
, "THIRD EA");
1406 CHECK_VALUE(result
.list
[1].ea_list
.eas
.eas
[1].value
.length
, 0);
1408 CHECK_STRING(result
.list
[2].ea_list
.name
.s
, "file3.txt");
1409 CHECK_STRING(result
.list
[2].ea_list
.eas
.eas
[0].name
.s
, "SECOND EA");
1410 CHECK_VALUE(result
.list
[2].ea_list
.eas
.eas
[0].value
.length
, 9);
1411 CHECK_STRING((const char *)result
.list
[2].ea_list
.eas
.eas
[0].value
.data
, "Value Two");
1412 CHECK_STRING(result
.list
[2].ea_list
.eas
.eas
[1].name
.s
, "THIRD EA");
1413 CHECK_VALUE(result
.list
[2].ea_list
.eas
.eas
[1].value
.length
, 0);
1415 smb_raw_exit(cli
->session
);
1416 smbcli_deltree(cli
->tree
, BASEDIR
);
1422 Test the behavior of max count parameter in TRANS2_FIND_FIRST2 and
1423 TRANS2_FIND_NEXT2 queries
1425 static bool test_max_count(struct torture_context
*tctx
,
1426 struct smbcli_state
*cli
)
1428 const int num_files
= 2;
1433 struct multiple_result result
;
1434 union smb_search_first io
;
1435 union smb_search_next io2
;
1437 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1439 torture_comment(tctx
, "Creating %d files\n", num_files
);
1441 for (i
=num_files
-1;i
>=0;i
--) {
1442 fname
= talloc_asprintf(cli
, BASEDIR
"\\t%03d-%d.txt", i
, i
);
1443 fnum
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
, DENY_NONE
);
1445 torture_comment(tctx
,
1446 "Failed to create %s - %s\n",
1447 fname
, smbcli_errstr(cli
->tree
));
1452 smbcli_close(cli
->tree
, fnum
);
1455 torture_comment(tctx
, "Set max_count parameter to 0. "
1456 "This should return 1 entry\n");
1457 ZERO_STRUCT(result
);
1458 result
.tctx
= talloc_new(tctx
);
1460 io
.t2ffirst
.level
= RAW_SEARCH_TRANS2
;
1461 io
.t2ffirst
.data_level
= RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
;
1462 io
.t2ffirst
.in
.search_attrib
= 0;
1463 io
.t2ffirst
.in
.max_count
= 0;
1464 io
.t2ffirst
.in
.flags
= 0;
1465 io
.t2ffirst
.in
.storage_type
= 0;
1466 io
.t2ffirst
.in
.pattern
= BASEDIR
"\\*.*";
1468 status
= smb_raw_search_first(cli
->tree
, tctx
,
1469 &io
, &result
, multiple_search_callback
);
1470 CHECK_STATUS(status
, NT_STATUS_OK
);
1471 CHECK_VALUE(result
.count
, 1);
1473 torture_comment(tctx
, "Set max_count to 1. This should also "
1474 "return 1 entry\n");
1475 io2
.t2fnext
.level
= RAW_SEARCH_TRANS2
;
1476 io2
.t2fnext
.data_level
= RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
;
1477 io2
.t2fnext
.in
.handle
= io
.t2ffirst
.out
.handle
;
1478 io2
.t2fnext
.in
.max_count
= 1;
1479 io2
.t2fnext
.in
.resume_key
= 0;
1480 io2
.t2fnext
.in
.flags
= 0;
1481 io2
.t2fnext
.in
.last_name
=
1482 result
.list
[result
.count
-1].both_directory_info
.name
.s
;
1484 status
= smb_raw_search_next(cli
->tree
, tctx
,
1485 &io2
, &result
, multiple_search_callback
);
1486 CHECK_STATUS(status
, NT_STATUS_OK
);
1487 CHECK_VALUE(result
.count
, 2);
1489 smb_raw_exit(cli
->session
);
1490 smbcli_deltree(cli
->tree
, BASEDIR
);
1496 basic testing of all RAW_SEARCH_* calls using a single file
1498 struct torture_suite
*torture_raw_search(TALLOC_CTX
*mem_ctx
)
1500 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "search");
1502 torture_suite_add_1smb_test(suite
, "one file search", test_one_file
);
1503 torture_suite_add_1smb_test(suite
, "many files", test_many_files
);
1504 torture_suite_add_1smb_test(suite
, "sorted", test_sorted
);
1505 torture_suite_add_1smb_test(suite
, "modify search", test_modify_search
);
1506 torture_suite_add_1smb_test(suite
, "many dirs", test_many_dirs
);
1507 torture_suite_add_1smb_test(suite
, "os2 delete", test_os2_delete
);
1508 torture_suite_add_1smb_test(suite
, "ea list", test_ea_list
);
1509 torture_suite_add_1smb_test(suite
, "max count", test_max_count
);