2 Unix SMB/CIFS implementation.
3 RAW_SEARCH_* individual test suite
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define BASEDIR "\\testsearch"
27 callback function for single_search
29 static BOOL
single_search_callback(void *private, union smb_search_data
*file
)
31 union smb_search_data
*data
= private;
39 do a single file (non-wildcard) search
41 static NTSTATUS
single_search(struct cli_state
*cli
,
44 enum search_level level
,
45 union smb_search_data
*data
)
47 union smb_search_first io
;
50 io
.generic
.level
= level
;
51 if (level
== RAW_SEARCH_SEARCH
) {
52 io
.search_first
.in
.max_count
= 1;
53 io
.search_first
.in
.search_attrib
= 0;
54 io
.search_first
.in
.pattern
= pattern
;
56 io
.t2ffirst
.in
.search_attrib
= 0;
57 io
.t2ffirst
.in
.max_count
= 1;
58 io
.t2ffirst
.in
.flags
= FLAG_TRANS2_FIND_CLOSE
;
59 io
.t2ffirst
.in
.storage_type
= 0;
60 io
.t2ffirst
.in
.pattern
= pattern
;
63 status
= smb_raw_search_first(cli
->tree
, mem_ctx
,
64 &io
, (void *)data
, single_search_callback
);
72 enum search_level level
;
73 uint32 capability_mask
;
75 union smb_search_data data
;
77 {"SEARCH", RAW_SEARCH_SEARCH
, },
78 {"STANDARD", RAW_SEARCH_STANDARD
, },
79 {"EA_SIZE", RAW_SEARCH_EA_SIZE
, },
80 {"DIRECTORY_INFO", RAW_SEARCH_DIRECTORY_INFO
, },
81 {"FULL_DIRECTORY_INFO", RAW_SEARCH_FULL_DIRECTORY_INFO
, },
82 {"NAME_INFO", RAW_SEARCH_NAME_INFO
, },
83 {"BOTH_DIRECTORY_INFO", RAW_SEARCH_BOTH_DIRECTORY_INFO
, },
84 {"ID_FULL_DIRECTORY_INFO", RAW_SEARCH_ID_FULL_DIRECTORY_INFO
, },
85 {"ID_BOTH_DIRECTORY_INFO", RAW_SEARCH_ID_BOTH_DIRECTORY_INFO
, },
86 {"UNIX_INFO", RAW_SEARCH_UNIX_INFO
, CAP_UNIX
}
89 /* find a level in the table by name */
90 static union smb_search_data
*find(const char *name
)
93 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
94 if (NT_STATUS_IS_OK(levels
[i
].status
) &&
95 strcmp(levels
[i
].name
, name
) == 0) {
96 return &levels
[i
].data
;
103 basic testing of all RAW_SEARCH_* calls using a single file
105 static BOOL
test_one_file(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
)
109 const char *fname
= "\\torture_search.txt";
112 union smb_fileinfo all_info
, alt_info
, name_info
, internal_info
;
113 union smb_search_data
*s
;
115 printf("Testing one file searches\n");
117 fnum
= create_complex_file(cli
, mem_ctx
, fname
);
119 printf("ERROR: open of %s failed (%s)\n", fname
, cli_errstr(cli
->tree
));
124 /* call all the levels */
125 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
126 uint32 cap
= cli
->transport
->negotiate
.capabilities
;
128 printf("testing %s\n", levels
[i
].name
);
130 levels
[i
].status
= single_search(cli
, mem_ctx
, fname
,
131 levels
[i
].level
, &levels
[i
].data
);
133 /* see if this server claims to support this level */
134 if ((cap
& levels
[i
].capability_mask
) != levels
[i
].capability_mask
) {
135 printf("search level %s(%d) not supported by server\n",
136 levels
[i
].name
, (int)levels
[i
].level
);
140 if (!NT_STATUS_IS_OK(levels
[i
].status
)) {
141 printf("search level %s(%d) failed - %s\n",
142 levels
[i
].name
, (int)levels
[i
].level
,
143 nt_errstr(levels
[i
].status
));
148 /* get the all_info file into to check against */
149 all_info
.generic
.level
= RAW_FILEINFO_ALL_INFO
;
150 all_info
.generic
.in
.fname
= fname
;
151 status
= smb_raw_pathinfo(cli
->tree
, mem_ctx
, &all_info
);
152 if (!NT_STATUS_IS_OK(status
)) {
153 printf("RAW_FILEINFO_ALL_INFO failed - %s\n", nt_errstr(status
));
158 alt_info
.generic
.level
= RAW_FILEINFO_ALT_NAME_INFO
;
159 alt_info
.generic
.in
.fname
= fname
;
160 status
= smb_raw_pathinfo(cli
->tree
, mem_ctx
, &alt_info
);
161 if (!NT_STATUS_IS_OK(status
)) {
162 printf("RAW_FILEINFO_ALT_NAME_INFO failed - %s\n", nt_errstr(status
));
167 internal_info
.generic
.level
= RAW_FILEINFO_INTERNAL_INFORMATION
;
168 internal_info
.generic
.in
.fname
= fname
;
169 status
= smb_raw_pathinfo(cli
->tree
, mem_ctx
, &internal_info
);
170 if (!NT_STATUS_IS_OK(status
)) {
171 printf("RAW_FILEINFO_INTERNAL_INFORMATION failed - %s\n", nt_errstr(status
));
176 name_info
.generic
.level
= RAW_FILEINFO_NAME_INFO
;
177 name_info
.generic
.in
.fname
= fname
;
178 status
= smb_raw_pathinfo(cli
->tree
, mem_ctx
, &name_info
);
179 if (!NT_STATUS_IS_OK(status
)) {
180 printf("RAW_FILEINFO_NAME_INFO failed - %s\n", nt_errstr(status
));
185 #define CHECK_VAL(name, sname1, field1, v, sname2, field2) do { \
188 if (s->sname1.field1 != v.sname2.out.field2) { \
189 printf("(%d) %s/%s [%d] != %s/%s [%d]\n", \
191 #sname1, #field1, (int)s->sname1.field1, \
192 #sname2, #field2, (int)v.sname2.out.field2); \
197 #define CHECK_TIME(name, sname1, field1, v, sname2, field2) do { \
200 if (s->sname1.field1 != (~1 & nt_time_to_unix(&v.sname2.out.field2))) { \
201 printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \
203 #sname1, #field1, timestring(mem_ctx, s->sname1.field1), \
204 #sname2, #field2, nt_time_string(mem_ctx, &v.sname2.out.field2)); \
209 #define CHECK_NTTIME(name, sname1, field1, v, sname2, field2) do { \
212 if (memcmp(&s->sname1.field1, &v.sname2.out.field2, sizeof(NTTIME))) { \
213 printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \
215 #sname1, #field1, nt_time_string(mem_ctx, &s->sname1.field1), \
216 #sname2, #field2, nt_time_string(mem_ctx, &v.sname2.out.field2)); \
221 #define CHECK_STR(name, sname1, field1, v, sname2, field2) do { \
224 if (!s->sname1.field1 || strcmp(s->sname1.field1, v.sname2.out.field2.s)) { \
225 printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \
227 #sname1, #field1, s->sname1.field1, \
228 #sname2, #field2, v.sname2.out.field2.s); \
233 #define CHECK_WSTR(name, sname1, field1, v, sname2, field2, flags) do { \
236 if (!s->sname1.field1.s || \
237 strcmp(s->sname1.field1.s, v.sname2.out.field2.s) || \
238 wire_bad_flags(&s->sname1.field1, flags)) { \
239 printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \
241 #sname1, #field1, s->sname1.field1.s, \
242 #sname2, #field2, v.sname2.out.field2.s); \
247 #define CHECK_NAME(name, sname1, field1, fname, flags) do { \
250 if (!s->sname1.field1.s || \
251 strcmp(s->sname1.field1.s, fname) || \
252 wire_bad_flags(&s->sname1.field1, flags)) { \
253 printf("(%d) %s/%s [%s] != %s\n", \
255 #sname1, #field1, s->sname1.field1.s, \
261 /* check that all the results are as expected */
262 CHECK_VAL("SEARCH", search
, attrib
, all_info
, all_info
, attrib
);
263 CHECK_VAL("STANDARD", standard
, attrib
, all_info
, all_info
, attrib
);
264 CHECK_VAL("EA_SIZE", ea_size
, attrib
, all_info
, all_info
, attrib
);
265 CHECK_VAL("DIRECTORY_INFO", directory_info
, attrib
, all_info
, all_info
, attrib
);
266 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info
, attrib
, all_info
, all_info
, attrib
);
267 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info
, attrib
, all_info
, all_info
, attrib
);
268 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, attrib
, all_info
, all_info
, attrib
);
269 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, attrib
, all_info
, all_info
, attrib
);
271 CHECK_TIME("SEARCH", search
, write_time
, all_info
, all_info
, write_time
);
272 CHECK_TIME("STANDARD", standard
, write_time
, all_info
, all_info
, write_time
);
273 CHECK_TIME("EA_SIZE", ea_size
, write_time
, all_info
, all_info
, write_time
);
274 CHECK_TIME("STANDARD", standard
, create_time
, all_info
, all_info
, create_time
);
275 CHECK_TIME("EA_SIZE", ea_size
, create_time
, all_info
, all_info
, create_time
);
276 CHECK_TIME("STANDARD", standard
, access_time
, all_info
, all_info
, access_time
);
277 CHECK_TIME("EA_SIZE", ea_size
, access_time
, all_info
, all_info
, access_time
);
279 CHECK_NTTIME("DIRECTORY_INFO", directory_info
, write_time
, all_info
, all_info
, write_time
);
280 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info
, write_time
, all_info
, all_info
, write_time
);
281 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info
, write_time
, all_info
, all_info
, write_time
);
282 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, write_time
, all_info
, all_info
, write_time
);
283 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, write_time
, all_info
, all_info
, write_time
);
285 CHECK_NTTIME("DIRECTORY_INFO", directory_info
, create_time
, all_info
, all_info
, create_time
);
286 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info
, create_time
, all_info
, all_info
, create_time
);
287 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info
, create_time
, all_info
, all_info
, create_time
);
288 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, create_time
, all_info
, all_info
, create_time
);
289 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, create_time
, all_info
, all_info
, create_time
);
291 CHECK_NTTIME("DIRECTORY_INFO", directory_info
, access_time
, all_info
, all_info
, access_time
);
292 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info
, access_time
, all_info
, all_info
, access_time
);
293 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info
, access_time
, all_info
, all_info
, access_time
);
294 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, access_time
, all_info
, all_info
, access_time
);
295 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, access_time
, all_info
, all_info
, access_time
);
297 CHECK_NTTIME("DIRECTORY_INFO", directory_info
, create_time
, all_info
, all_info
, create_time
);
298 CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info
, create_time
, all_info
, all_info
, create_time
);
299 CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info
, create_time
, all_info
, all_info
, create_time
);
300 CHECK_NTTIME("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, create_time
, all_info
, all_info
, create_time
);
301 CHECK_NTTIME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, create_time
, all_info
, all_info
, create_time
);
303 CHECK_VAL("SEARCH", search
, size
, all_info
, all_info
, size
);
304 CHECK_VAL("STANDARD", standard
, size
, all_info
, all_info
, size
);
305 CHECK_VAL("EA_SIZE", ea_size
, size
, all_info
, all_info
, size
);
306 CHECK_VAL("DIRECTORY_INFO", directory_info
, size
, all_info
, all_info
, size
);
307 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info
, size
, all_info
, all_info
, size
);
308 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info
, size
, all_info
, all_info
, size
);
309 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, size
, all_info
, all_info
, size
);
310 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, size
, all_info
, all_info
, size
);
311 CHECK_VAL("UNIX_INFO", unix_info
, size
, all_info
, all_info
, size
);
313 CHECK_VAL("STANDARD", standard
, alloc_size
, all_info
, all_info
, alloc_size
);
314 CHECK_VAL("EA_SIZE", ea_size
, alloc_size
, all_info
, all_info
, alloc_size
);
315 CHECK_VAL("DIRECTORY_INFO", directory_info
, alloc_size
, all_info
, all_info
, alloc_size
);
316 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info
, alloc_size
, all_info
, all_info
, alloc_size
);
317 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info
, alloc_size
, all_info
, all_info
, alloc_size
);
318 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, alloc_size
, all_info
, all_info
, alloc_size
);
319 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, alloc_size
, all_info
, all_info
, alloc_size
);
320 CHECK_VAL("UNIX_INFO", unix_info
, alloc_size
, all_info
, all_info
, alloc_size
);
322 CHECK_VAL("EA_SIZE", ea_size
, ea_size
, all_info
, all_info
, ea_size
);
323 CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info
, ea_size
, all_info
, all_info
, ea_size
);
324 CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info
, ea_size
, all_info
, all_info
, ea_size
);
325 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, ea_size
, all_info
, all_info
, ea_size
);
326 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, ea_size
, all_info
, all_info
, ea_size
);
328 CHECK_STR("SEARCH", search
, name
, alt_info
, alt_name_info
, fname
);
329 CHECK_WSTR("BOTH_DIRECTORY_INFO", both_directory_info
, short_name
, alt_info
, alt_name_info
, fname
, STR_UNICODE
);
331 CHECK_NAME("STANDARD", standard
, name
, fname
+1, 0);
332 CHECK_NAME("EA_SIZE", ea_size
, name
, fname
+1, 0);
333 CHECK_NAME("DIRECTORY_INFO", directory_info
, name
, fname
+1, STR_TERMINATE_ASCII
);
334 CHECK_NAME("FULL_DIRECTORY_INFO", full_directory_info
, name
, fname
+1, STR_TERMINATE_ASCII
);
335 CHECK_NAME("NAME_INFO", name_info
, name
, fname
+1, STR_TERMINATE_ASCII
);
336 CHECK_NAME("BOTH_DIRECTORY_INFO", both_directory_info
, name
, fname
+1, STR_TERMINATE_ASCII
);
337 CHECK_NAME("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, name
, fname
+1, STR_TERMINATE_ASCII
);
338 CHECK_NAME("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, name
, fname
+1, STR_TERMINATE_ASCII
);
340 CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info
, file_id
, internal_info
, internal_information
, file_id
);
341 CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, file_id
, internal_info
, internal_information
, file_id
);
344 smb_raw_exit(cli
->session
);
345 cli_unlink(cli
->tree
, fname
);
351 struct multiple_result
{
354 union smb_search_data
*list
;
358 callback function for multiple_search
360 static BOOL
multiple_search_callback(void *private, union smb_search_data
*file
)
362 struct multiple_result
*data
= private;
366 data
->list
= talloc_realloc(data
->mem_ctx
,
368 data
->count
* (sizeof(data
->list
[0])));
370 data
->list
[data
->count
-1] = *file
;
375 enum continue_type
{CONT_FLAGS
, CONT_NAME
, CONT_RESUME_KEY
};
378 do a single file (non-wildcard) search
380 static NTSTATUS
multiple_search(struct cli_state
*cli
,
383 enum search_level level
,
384 enum continue_type cont_type
,
387 union smb_search_first io
;
388 union smb_search_next io2
;
390 const int per_search
= 300;
391 struct multiple_result
*result
= data
;
393 io
.generic
.level
= level
;
394 if (level
== RAW_SEARCH_SEARCH
) {
395 io
.search_first
.in
.max_count
= per_search
;
396 io
.search_first
.in
.search_attrib
= 0;
397 io
.search_first
.in
.pattern
= pattern
;
399 io
.t2ffirst
.in
.search_attrib
= 0;
400 io
.t2ffirst
.in
.max_count
= per_search
;
401 io
.t2ffirst
.in
.flags
= 0;
402 io
.t2ffirst
.in
.storage_type
= 0;
403 io
.t2ffirst
.in
.pattern
= pattern
;
404 if (cont_type
== CONT_RESUME_KEY
) {
405 io
.t2ffirst
.in
.flags
= FLAG_TRANS2_FIND_REQUIRE_RESUME
|
406 FLAG_TRANS2_FIND_BACKUP_INTENT
;
410 status
= smb_raw_search_first(cli
->tree
, mem_ctx
,
411 &io
, data
, multiple_search_callback
);
414 while (NT_STATUS_IS_OK(status
)) {
415 io2
.generic
.level
= level
;
416 if (level
== RAW_SEARCH_SEARCH
) {
417 io2
.search_next
.in
.max_count
= per_search
;
418 io2
.search_next
.in
.search_attrib
= 0;
419 io2
.search_next
.in
.search_id
= result
->list
[result
->count
-1].search
.search_id
;
421 io2
.t2fnext
.in
.handle
= io
.t2ffirst
.out
.handle
;
422 io2
.t2fnext
.in
.max_count
= per_search
;
423 io2
.t2fnext
.in
.resume_key
= 0;
424 io2
.t2fnext
.in
.flags
= 0;
425 io2
.t2fnext
.in
.last_name
= "";
427 case CONT_RESUME_KEY
:
428 if (level
== RAW_SEARCH_STANDARD
) {
429 io2
.t2fnext
.in
.resume_key
=
430 result
->list
[result
->count
-1].standard
.resume_key
;
431 } else if (level
== RAW_SEARCH_EA_SIZE
) {
432 io2
.t2fnext
.in
.resume_key
=
433 result
->list
[result
->count
-1].ea_size
.resume_key
;
434 } else if (level
== RAW_SEARCH_DIRECTORY_INFO
) {
435 io2
.t2fnext
.in
.resume_key
=
436 result
->list
[result
->count
-1].directory_info
.file_index
;
438 io2
.t2fnext
.in
.resume_key
=
439 result
->list
[result
->count
-1].both_directory_info
.file_index
;
441 io2
.t2fnext
.in
.flags
= FLAG_TRANS2_FIND_REQUIRE_RESUME
|
442 FLAG_TRANS2_FIND_BACKUP_INTENT
;
445 if (level
== RAW_SEARCH_STANDARD
) {
446 io2
.t2fnext
.in
.last_name
=
447 result
->list
[result
->count
-1].standard
.name
.s
;
448 } else if (level
== RAW_SEARCH_EA_SIZE
) {
449 io2
.t2fnext
.in
.last_name
=
450 result
->list
[result
->count
-1].ea_size
.name
.s
;
451 } else if (level
== RAW_SEARCH_DIRECTORY_INFO
) {
452 io2
.t2fnext
.in
.last_name
=
453 result
->list
[result
->count
-1].directory_info
.name
.s
;
455 io2
.t2fnext
.in
.last_name
=
456 result
->list
[result
->count
-1].both_directory_info
.name
.s
;
460 io2
.t2fnext
.in
.flags
= FLAG_TRANS2_FIND_CONTINUE
;
465 status
= smb_raw_search_next(cli
->tree
, mem_ctx
,
466 &io2
, data
, multiple_search_callback
);
467 if (!NT_STATUS_IS_OK(status
)) {
470 if (level
== RAW_SEARCH_SEARCH
) {
471 if (io2
.search_next
.out
.count
== 0) {
474 } else if (io2
.t2fnext
.out
.count
== 0 ||
475 io2
.t2fnext
.out
.end_of_search
) {
483 #define CHECK_STATUS(status, correct) do { \
484 if (!NT_STATUS_EQUAL(status, correct)) { \
485 printf("(%d) Incorrect status %s - should be %s\n", \
486 __LINE__, nt_errstr(status), nt_errstr(correct)); \
491 #define CHECK_VALUE(v, correct) do { \
492 if ((v) != (correct)) { \
493 printf("(%d) Incorrect value %s=%d - should be %d\n", \
494 __LINE__, #v, v, correct); \
499 static int search_both_compare(union smb_search_data
*d1
, union smb_search_data
*d2
)
501 return strcmp(d1
->both_directory_info
.name
.s
, d2
->both_directory_info
.name
.s
);
504 static int search_standard_compare(union smb_search_data
*d1
, union smb_search_data
*d2
)
506 return strcmp(d1
->standard
.name
.s
, d2
->standard
.name
.s
);
509 static int search_ea_size_compare(union smb_search_data
*d1
, union smb_search_data
*d2
)
511 return strcmp(d1
->ea_size
.name
.s
, d2
->ea_size
.name
.s
);
514 static int search_directory_info_compare(union smb_search_data
*d1
, union smb_search_data
*d2
)
516 return strcmp(d1
->directory_info
.name
.s
, d2
->directory_info
.name
.s
);
519 static int search_old_compare(union smb_search_data
*d1
, union smb_search_data
*d2
)
521 return strcmp(d1
->search
.name
, d2
->search
.name
);
526 basic testing of search calls using many files
528 static BOOL
test_many_files(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
)
530 const int num_files
= 700;
535 struct multiple_result result
;
538 const char *cont_name
;
539 enum search_level level
;
540 enum continue_type cont_type
;
542 {"BOTH_DIRECTORY_INFO", "NAME", RAW_SEARCH_BOTH_DIRECTORY_INFO
, CONT_NAME
},
543 {"BOTH_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_BOTH_DIRECTORY_INFO
, CONT_FLAGS
},
544 {"BOTH_DIRECTORY_INFO", "KEY", RAW_SEARCH_BOTH_DIRECTORY_INFO
, CONT_RESUME_KEY
},
545 {"STANDARD", "FLAGS", RAW_SEARCH_STANDARD
, CONT_FLAGS
},
546 {"STANDARD", "KEY", RAW_SEARCH_STANDARD
, CONT_RESUME_KEY
},
547 {"STANDARD", "NAME", RAW_SEARCH_STANDARD
, CONT_NAME
},
548 {"EA_SIZE", "FLAGS", RAW_SEARCH_EA_SIZE
, CONT_FLAGS
},
549 {"EA_SIZE", "KEY", RAW_SEARCH_EA_SIZE
, CONT_RESUME_KEY
},
550 {"EA_SIZE", "NAME", RAW_SEARCH_EA_SIZE
, CONT_NAME
},
551 {"DIRECTORY_INFO", "FLAGS", RAW_SEARCH_DIRECTORY_INFO
, CONT_FLAGS
},
552 {"DIRECTORY_INFO", "KEY", RAW_SEARCH_DIRECTORY_INFO
, CONT_RESUME_KEY
},
553 {"DIRECTORY_INFO", "NAME", RAW_SEARCH_DIRECTORY_INFO
, CONT_NAME
},
554 {"SEARCH", "ID", RAW_SEARCH_SEARCH
, CONT_RESUME_KEY
}
557 if (cli_deltree(cli
->tree
, BASEDIR
) == -1 ||
558 NT_STATUS_IS_ERR(cli_mkdir(cli
->tree
, BASEDIR
))) {
559 printf("Failed to create " BASEDIR
" - %s\n", cli_errstr(cli
->tree
));
563 printf("Creating %d files\n", num_files
);
565 for (i
=0;i
<num_files
;i
++) {
566 asprintf(&fname
, BASEDIR
"\\t%03d-%d.txt", i
, i
);
567 fnum
= cli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
, DENY_NONE
);
569 printf("Failed to create %s - %s\n", fname
, cli_errstr(cli
->tree
));
574 cli_close(cli
->tree
, fnum
);
578 for (t
=0;t
<ARRAY_SIZE(search_types
);t
++) {
580 result
.mem_ctx
= mem_ctx
;
582 printf("Continue %s via %s\n", search_types
[t
].name
, search_types
[t
].cont_name
);
584 status
= multiple_search(cli
, mem_ctx
, BASEDIR
"\\*.*",
585 search_types
[t
].level
,
586 search_types
[t
].cont_type
,
589 CHECK_STATUS(status
, NT_STATUS_OK
);
590 CHECK_VALUE(result
.count
, num_files
);
592 if (search_types
[t
].level
== RAW_SEARCH_BOTH_DIRECTORY_INFO
) {
593 qsort(result
.list
, result
.count
, sizeof(result
.list
[0]),
594 QSORT_CAST search_both_compare
);
595 } else if (search_types
[t
].level
== RAW_SEARCH_STANDARD
) {
596 qsort(result
.list
, result
.count
, sizeof(result
.list
[0]),
597 QSORT_CAST search_standard_compare
);
598 } else if (search_types
[t
].level
== RAW_SEARCH_EA_SIZE
) {
599 qsort(result
.list
, result
.count
, sizeof(result
.list
[0]),
600 QSORT_CAST search_ea_size_compare
);
601 } else if (search_types
[t
].level
== RAW_SEARCH_DIRECTORY_INFO
) {
602 qsort(result
.list
, result
.count
, sizeof(result
.list
[0]),
603 QSORT_CAST search_directory_info_compare
);
605 qsort(result
.list
, result
.count
, sizeof(result
.list
[0]),
606 QSORT_CAST search_old_compare
);
609 for (i
=0;i
<num_files
;i
++) {
611 if (search_types
[t
].level
== RAW_SEARCH_BOTH_DIRECTORY_INFO
) {
612 s
= result
.list
[i
].both_directory_info
.name
.s
;
613 } else if (search_types
[t
].level
== RAW_SEARCH_STANDARD
) {
614 s
= result
.list
[i
].standard
.name
.s
;
615 } else if (search_types
[t
].level
== RAW_SEARCH_EA_SIZE
) {
616 s
= result
.list
[i
].ea_size
.name
.s
;
617 } else if (search_types
[t
].level
== RAW_SEARCH_DIRECTORY_INFO
) {
618 s
= result
.list
[i
].directory_info
.name
.s
;
620 s
= result
.list
[i
].search
.name
;
622 asprintf(&fname
, "t%03d-%d.txt", i
, i
);
623 if (strcmp(fname
, s
)) {
624 printf("Incorrect name %s at entry %d\n", s
, i
);
633 smb_raw_exit(cli
->session
);
634 cli_deltree(cli
->tree
, BASEDIR
);
641 basic testing of all RAW_SEARCH_* calls using a single file
643 BOOL
torture_raw_search(int dummy
)
645 struct cli_state
*cli
;
649 if (!torture_open_connection(&cli
)) {
653 mem_ctx
= talloc_init("torture_search");
655 if (!test_one_file(cli
, mem_ctx
)) {
659 if (!test_many_files(cli
, mem_ctx
)) {
663 torture_close_connection(cli
);
664 talloc_destroy(mem_ctx
);