2 Unix SMB/CIFS implementation.
4 SMB2 dir list test suite
6 Copyright (C) Andrew Tridgell 2005
7 Copyright (C) Zachary Loafman 2009
8 Copyright (C) Aravind Srinivasan 2009
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "libcli/smb2/smb2.h"
26 #include "libcli/smb2/smb2_calls.h"
27 #include "libcli/smb_composite/smb_composite.h"
28 #include "libcli/raw/libcliraw.h"
29 #include "libcli/raw/raw_proto.h"
30 #include "libcli/libcli.h"
32 #include "torture/torture.h"
33 #include "torture/smb2/proto.h"
34 #include "torture/util.h"
36 #include "system/filesys.h"
38 #define DNAME "smb2_dir"
46 static NTSTATUS
populate_tree(struct torture_context
*tctx
,
48 struct smb2_tree
*tree
,
49 struct file_elem
*files
,
51 struct smb2_handle
*h_out
)
53 struct smb2_create create
;
59 smb2_deltree(tree
, DNAME
);
62 create
.in
.desired_access
= SEC_RIGHTS_DIR_ALL
;
63 create
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
64 create
.in
.file_attributes
= FILE_ATTRIBUTE_DIRECTORY
;
65 create
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
66 NTCREATEX_SHARE_ACCESS_WRITE
|
67 NTCREATEX_SHARE_ACCESS_DELETE
;
68 create
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
69 create
.in
.fname
= DNAME
;
71 status
= smb2_create(tree
, mem_ctx
, &create
);
72 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
73 *h_out
= create
.out
.file
.handle
;
76 create
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
77 create
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
78 create
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
80 strs
= generate_unique_strs(mem_ctx
, 8, nfiles
);
82 status
= NT_STATUS_OBJECT_NAME_COLLISION
;
85 for (i
= 0; i
< nfiles
; i
++) {
86 files
[i
].name
= strs
[i
];
87 create
.in
.fname
= talloc_asprintf(mem_ctx
, "%s\\%s",
88 DNAME
, files
[i
].name
);
89 status
= smb2_create(tree
, mem_ctx
, &create
);
90 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
91 smb2_util_close(tree
, create
.out
.file
.handle
);
101 static bool test_find(struct torture_context
*tctx
,
102 struct smb2_tree
*tree
)
104 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
105 struct smb2_handle h
;
107 union smb_search_data
*d
;
108 struct file_elem files
[NFILES
] = {};
112 int i
, j
, file_count
= 0;
114 status
= populate_tree(tctx
, mem_ctx
, tree
, files
, NFILES
, &h
);
117 f
.in
.file
.handle
= h
;
119 f
.in
.continue_flags
= SMB2_CONTINUE_FLAG_SINGLE
;
120 f
.in
.max_response_size
= 0x100;
121 f
.in
.level
= SMB2_FIND_BOTH_DIRECTORY_INFO
;
124 status
= smb2_find_level(tree
, tree
, &f
, &count
, &d
);
125 if (NT_STATUS_EQUAL(status
, STATUS_NO_MORE_FILES
))
127 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
129 for (i
= 0; i
< count
; i
++) {
131 const char *found
= d
[i
].both_directory_info
.name
.s
;
133 if (!strcmp(found
, ".") || !strcmp(found
, ".."))
137 for (j
= 0; j
< NFILES
; j
++) {
138 if (!strcmp(files
[j
].name
, found
)) {
139 files
[j
].found
= true;
148 torture_result(tctx
, TORTURE_FAIL
,
149 "(%s): didn't expect %s\n",
150 __location__
, found
);
155 file_count
= file_count
+ i
;
156 f
.in
.continue_flags
= 0;
157 f
.in
.max_response_size
= 4096;
158 } while (count
!= 0);
160 torture_assert_int_equal_goto(tctx
, file_count
, NFILES
+ 2, ret
, done
,
163 for (i
= 0; i
< NFILES
; i
++) {
167 torture_result(tctx
, TORTURE_FAIL
,
168 "(%s): expected to find %s, but didn't\n",
169 __location__
, files
[j
].name
);
175 smb2_deltree(tree
, DNAME
);
176 talloc_free(mem_ctx
);
182 test fixed enumeration
185 static bool test_fixed(struct torture_context
*tctx
,
186 struct smb2_tree
*tree
)
188 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
189 struct smb2_create create
;
190 struct smb2_handle h
, h2
;
192 union smb_search_data
*d
;
193 struct file_elem files
[NFILES
] = {};
199 status
= populate_tree(tctx
, mem_ctx
, tree
, files
, NFILES
, &h
);
202 create
.in
.desired_access
= SEC_RIGHTS_DIR_ALL
;
203 create
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
204 create
.in
.file_attributes
= FILE_ATTRIBUTE_DIRECTORY
;
205 create
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
206 NTCREATEX_SHARE_ACCESS_WRITE
|
207 NTCREATEX_SHARE_ACCESS_DELETE
;
208 create
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
209 create
.in
.fname
= DNAME
;
211 status
= smb2_create(tree
, mem_ctx
, &create
);
212 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
213 h2
= create
.out
.file
.handle
;
216 f
.in
.file
.handle
= h
;
218 f
.in
.continue_flags
= SMB2_CONTINUE_FLAG_SINGLE
;
219 f
.in
.max_response_size
= 0x100;
220 f
.in
.level
= SMB2_FIND_BOTH_DIRECTORY_INFO
;
222 /* Start enumeration on h, then delete all from h2 */
223 status
= smb2_find_level(tree
, tree
, &f
, &count
, &d
);
224 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
226 f
.in
.file
.handle
= h2
;
229 status
= smb2_find_level(tree
, tree
, &f
, &count
, &d
);
230 if (NT_STATUS_EQUAL(status
, STATUS_NO_MORE_FILES
))
232 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
234 for (i
= 0; i
< count
; i
++) {
235 const char *found
= d
[i
].both_directory_info
.name
.s
;
236 char *path
= talloc_asprintf(mem_ctx
, "%s\\%s",
239 if (!strcmp(found
, ".") || !strcmp(found
, ".."))
242 status
= smb2_util_unlink(tree
, path
);
243 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
249 f
.in
.continue_flags
= 0;
250 f
.in
.max_response_size
= 4096;
251 } while (count
!= 0);
253 /* Now finish h enumeration. */
254 f
.in
.file
.handle
= h
;
257 status
= smb2_find_level(tree
, tree
, &f
, &count
, &d
);
258 if (NT_STATUS_EQUAL(status
, STATUS_NO_MORE_FILES
))
260 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
262 for (i
= 0; i
< count
; i
++) {
263 const char *found
= d
[i
].both_directory_info
.name
.s
;
265 if (!strcmp(found
, ".") || !strcmp(found
, ".."))
268 torture_result(tctx
, TORTURE_FAIL
,
269 "(%s): didn't expect %s\n",
270 __location__
, found
);
275 f
.in
.continue_flags
= 0;
276 f
.in
.max_response_size
= 4096;
277 } while (count
!= 0);
280 smb2_util_close(tree
, h
);
281 smb2_util_close(tree
, h2
);
282 smb2_deltree(tree
, DNAME
);
283 talloc_free(mem_ctx
);
291 enum smb_search_data_level data_level
;
293 int resume_key_offset
;
294 uint32_t capability_mask
;
296 union smb_search_data data
;
298 {"SMB2_FIND_DIRECTORY_INFO",
299 SMB2_FIND_DIRECTORY_INFO
, RAW_SEARCH_DATA_DIRECTORY_INFO
,
300 offsetof(union smb_search_data
, directory_info
.name
.s
),
301 offsetof(union smb_search_data
, directory_info
.file_index
),
303 {"SMB2_FIND_FULL_DIRECTORY_INFO",
304 SMB2_FIND_FULL_DIRECTORY_INFO
, RAW_SEARCH_DATA_FULL_DIRECTORY_INFO
,
305 offsetof(union smb_search_data
, full_directory_info
.name
.s
),
306 offsetof(union smb_search_data
, full_directory_info
.file_index
),
308 {"SMB2_FIND_NAME_INFO",
309 SMB2_FIND_NAME_INFO
, RAW_SEARCH_DATA_NAME_INFO
,
310 offsetof(union smb_search_data
, name_info
.name
.s
),
311 offsetof(union smb_search_data
, name_info
.file_index
),
313 {"SMB2_FIND_BOTH_DIRECTORY_INFO",
314 SMB2_FIND_BOTH_DIRECTORY_INFO
, RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
,
315 offsetof(union smb_search_data
, both_directory_info
.name
.s
),
316 offsetof(union smb_search_data
, both_directory_info
.file_index
),
318 {"SMB2_FIND_ID_FULL_DIRECTORY_INFO",
319 SMB2_FIND_ID_FULL_DIRECTORY_INFO
, RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO
,
320 offsetof(union smb_search_data
, id_full_directory_info
.name
.s
),
321 offsetof(union smb_search_data
, id_full_directory_info
.file_index
),
323 {"SMB2_FIND_ID_BOTH_DIRECTORY_INFO",
324 SMB2_FIND_ID_BOTH_DIRECTORY_INFO
, RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO
,
325 offsetof(union smb_search_data
, id_both_directory_info
.name
.s
),
326 offsetof(union smb_search_data
, id_both_directory_info
.file_index
),
331 extract the name from a smb_data structure and level
333 static const char *extract_name(union smb_search_data
*data
,
335 enum smb_search_data_level data_level
)
338 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
339 if (level
== levels
[i
].level
&&
340 data_level
== levels
[i
].data_level
) {
341 return *(const char **)(levels
[i
].name_offset
+ (char *)data
);
347 /* find a level in the table by name */
348 static union smb_search_data
*find(const char *name
)
351 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
352 if (NT_STATUS_IS_OK(levels
[i
].status
) &&
353 strcmp(levels
[i
].name
, name
) == 0) {
354 return &levels
[i
].data
;
360 static bool fill_level_data(TALLOC_CTX
*mem_ctx
,
361 union smb_search_data
*data
,
362 union smb_search_data
*d
,
365 enum smb_search_data_level data_level
)
368 const char *sname
= NULL
;
369 for (i
=0; i
< count
; i
++) {
370 sname
= extract_name(&d
[i
], level
, data_level
);
373 if (!strcmp(sname
, ".") || !strcmp(sname
, ".."))
381 NTSTATUS
torture_single_file_search(struct smb2_tree
*tree
,
385 enum smb_search_data_level data_level
,
387 union smb_search_data
*d
,
389 struct smb2_handle
*h
)
395 f
.in
.file
.handle
= *h
;
396 f
.in
.pattern
= pattern
;
397 f
.in
.continue_flags
= SMB2_CONTINUE_FLAG_RESTART
;
398 f
.in
.max_response_size
= 0x100;
401 status
= smb2_find_level(tree
, tree
, &f
, count
, &d
);
402 if (NT_STATUS_IS_OK(status
))
403 fill_level_data(mem_ctx
, &levels
[idx
].data
, d
, *count
, level
,
409 basic testing of all File Information Classes using a single file
411 static bool test_one_file(struct torture_context
*tctx
,
412 struct smb2_tree
*tree
)
414 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
416 const char *fname
= "torture_search.txt";
420 union smb_fileinfo all_info2
, alt_info
, internal_info
;
421 union smb_search_data
*s
;
422 union smb_search_data d
;
423 struct smb2_handle h
, h2
;
425 status
= torture_smb2_testdir(tree
, DNAME
, &h
);
426 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
428 status
= smb2_create_complex_file(tree
, DNAME
"\\torture_search.txt",
430 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
432 /* call all the File Information Classes */
433 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
434 torture_comment(tctx
, "testing %s %d\n", levels
[i
].name
,
437 levels
[i
].status
= torture_single_file_search(tree
, mem_ctx
,
438 fname
, levels
[i
].level
, levels
[i
].data_level
,
440 torture_assert_ntstatus_ok_goto(tctx
, levels
[i
].status
, ret
,
444 /* get the all_info file into to check against */
445 all_info2
.generic
.level
= RAW_FILEINFO_SMB2_ALL_INFORMATION
;
446 all_info2
.generic
.in
.file
.handle
= h2
;
447 status
= smb2_getinfo_file(tree
, tctx
, &all_info2
);
448 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
449 "RAW_FILEINFO_ALL_INFO failed");
451 alt_info
.generic
.level
= RAW_FILEINFO_ALT_NAME_INFORMATION
;
452 alt_info
.generic
.in
.file
.handle
= h2
;
453 status
= smb2_getinfo_file(tree
, tctx
, &alt_info
);
454 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
455 "RAW_FILEINFO_ALT_NAME_INFO failed");
457 internal_info
.generic
.level
= RAW_FILEINFO_INTERNAL_INFORMATION
;
458 internal_info
.generic
.in
.file
.handle
= h2
;
459 status
= smb2_getinfo_file(tree
, tctx
, &internal_info
);
460 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
461 "RAW_FILEINFO_INTERNAL_INFORMATION "
464 #define CHECK_VAL(name, sname1, field1, v, sname2, field2) do { \
467 if ((s->sname1.field1) != (v.sname2.out.field2)) { \
468 torture_result(tctx, TORTURE_FAIL, \
469 "(%s) %s/%s [0x%x] != %s/%s [0x%x]\n", \
471 #sname1, #field1, (int)s->sname1.field1, \
472 #sname2, #field2, (int)v.sname2.out.field2); \
477 #define CHECK_TIME(name, sname1, field1, v, sname2, field2) do { \
480 if (s->sname1.field1 != \
481 (~1 & nt_time_to_unix(v.sname2.out.field2))) { \
482 torture_result(tctx, TORTURE_FAIL, \
483 "(%s) %s/%s [%s] != %s/%s [%s]\n", \
486 timestring(tctx, s->sname1.field1), \
488 nt_time_string(tctx, v.sname2.out.field2)); \
493 #define CHECK_NTTIME(name, sname1, field1, v, sname2, field2) do { \
496 if (s->sname1.field1 != v.sname2.out.field2) { \
497 torture_result(tctx, TORTURE_FAIL, \
498 "(%s) %s/%s [%s] != %s/%s [%s]\n", \
501 nt_time_string(tctx, s->sname1.field1), \
503 nt_time_string(tctx, v.sname2.out.field2)); \
508 #define CHECK_STR(name, sname1, field1, v, sname2, field2) do { \
511 if (!s->sname1.field1 || \
512 strcmp(s->sname1.field1, v.sname2.out.field2.s)) { \
513 torture_result(tctx, TORTURE_FAIL, \
514 "(%s) %s/%s [%s] != %s/%s [%s]\n", \
516 #sname1, #field1, s->sname1.field1, \
517 #sname2, #field2, v.sname2.out.field2.s); \
522 #define CHECK_WSTR(name, sname1, field1, v, sname2, field2, flags) do { \
525 if (!s->sname1.field1.s || \
526 strcmp(s->sname1.field1.s, v.sname2.out.field2.s)) { \
527 torture_result(tctx, TORTURE_FAIL, \
528 "(%s) %s/%s [%s] != %s/%s [%s]\n", \
530 #sname1, #field1, s->sname1.field1.s, \
531 #sname2, #field2, v.sname2.out.field2.s); \
536 #define CHECK_NAME(name, sname1, field1, fname, flags) do { \
539 if (!s->sname1.field1.s || \
540 strcmp(s->sname1.field1.s, fname)) { \
541 torture_result(tctx, TORTURE_FAIL, \
542 "(%s) %s/%s [%s] != %s\n", \
544 #sname1, #field1, s->sname1.field1.s, fname); \
549 #define CHECK_UNIX_NAME(name, sname1, field1, fname, flags) do { \
552 if (!s->sname1.field1 || \
553 strcmp(s->sname1.field1, fname)) { \
554 torture_result(tctx, TORTURE_FAIL, \
555 "(%s) %s/%s [%s] != %s\n", \
557 #sname1, #field1, s->sname1.field1, fname); \
562 /* check that all the results are as expected */
563 CHECK_VAL("SMB2_FIND_DIRECTORY_INFO", directory_info
, attrib
, all_info2
, all_info2
, attrib
);
564 CHECK_VAL("SMB2_FIND_FULL_DIRECTORY_INFO", full_directory_info
, attrib
, all_info2
, all_info2
, attrib
);
565 CHECK_VAL("SMB2_FIND_BOTH_DIRECTORY_INFO", both_directory_info
, attrib
, all_info2
, all_info2
, attrib
);
566 CHECK_VAL("SMB2_FIND_ID_FULL_DIRECTORY_INFO", id_full_directory_info
, attrib
, all_info2
, all_info2
, attrib
);
567 CHECK_VAL("SMB2_FIND_ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, attrib
, all_info2
, all_info2
, attrib
);
569 CHECK_NTTIME("SMB2_FIND_DIRECTORY_INFO", directory_info
, write_time
, all_info2
, all_info2
, write_time
);
570 CHECK_NTTIME("SMB2_FIND_FULL_DIRECTORY_INFO", full_directory_info
, write_time
, all_info2
, all_info2
, write_time
);
571 CHECK_NTTIME("SMB2_FIND_BOTH_DIRECTORY_INFO", both_directory_info
, write_time
, all_info2
, all_info2
, write_time
);
572 CHECK_NTTIME("SMB2_FIND_ID_FULL_DIRECTORY_INFO", id_full_directory_info
, write_time
, all_info2
, all_info2
, write_time
);
573 CHECK_NTTIME("SMB2_FIND_ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, write_time
, all_info2
, all_info2
, write_time
);
575 CHECK_NTTIME("SMB2_FIND_DIRECTORY_INFO", directory_info
, create_time
, all_info2
, all_info2
, create_time
);
576 CHECK_NTTIME("SMB2_FIND_FULL_DIRECTORY_INFO", full_directory_info
, create_time
, all_info2
, all_info2
, create_time
);
577 CHECK_NTTIME("SMB2_FIND_BOTH_DIRECTORY_INFO", both_directory_info
, create_time
, all_info2
, all_info2
, create_time
);
578 CHECK_NTTIME("SMB2_FIND_ID_FULL_DIRECTORY_INFO", id_full_directory_info
, create_time
, all_info2
, all_info2
, create_time
);
579 CHECK_NTTIME("SMB2_FIND_ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, create_time
, all_info2
, all_info2
, create_time
);
581 CHECK_NTTIME("SMB2_FIND_DIRECTORY_INFO", directory_info
, access_time
, all_info2
, all_info2
, access_time
);
582 CHECK_NTTIME("SMB2_FIND_FULL_DIRECTORY_INFO", full_directory_info
, access_time
, all_info2
, all_info2
, access_time
);
583 CHECK_NTTIME("SMB2_FIND_BOTH_DIRECTORY_INFO", both_directory_info
, access_time
, all_info2
, all_info2
, access_time
);
584 CHECK_NTTIME("SMB2_FIND_ID_FULL_DIRECTORY_INFO", id_full_directory_info
, access_time
, all_info2
, all_info2
, access_time
);
585 CHECK_NTTIME("SMB2_FIND_ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, access_time
, all_info2
, all_info2
, access_time
);
587 CHECK_NTTIME("SMB2_FIND_DIRECTORY_INFO", directory_info
, change_time
, all_info2
, all_info2
, change_time
);
588 CHECK_NTTIME("SMB2_FIND_FULL_DIRECTORY_INFO", full_directory_info
, change_time
, all_info2
, all_info2
, change_time
);
589 CHECK_NTTIME("SMB2_FIND_BOTH_DIRECTORY_INFO", both_directory_info
, change_time
, all_info2
, all_info2
, change_time
);
590 CHECK_NTTIME("SMB2_FIND_ID_FULL_DIRECTORY_INFO", id_full_directory_info
, change_time
, all_info2
, all_info2
, change_time
);
591 CHECK_NTTIME("SMB2_FIND_ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, change_time
, all_info2
, all_info2
, change_time
);
593 CHECK_VAL("SMB2_FIND_DIRECTORY_INFO", directory_info
, size
, all_info2
, all_info2
, size
);
594 CHECK_VAL("SMB2_FIND_FULL_DIRECTORY_INFO", full_directory_info
, size
, all_info2
, all_info2
, size
);
595 CHECK_VAL("SMB2_FIND_BOTH_DIRECTORY_INFO", both_directory_info
, size
, all_info2
, all_info2
, size
);
596 CHECK_VAL("SMB2_FIND_ID_FULL_DIRECTORY_INFO", id_full_directory_info
, size
, all_info2
, all_info2
, size
);
597 CHECK_VAL("SMB2_FIND_ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, size
, all_info2
, all_info2
, size
);
599 CHECK_VAL("SMB2_FIND_DIRECTORY_INFO", directory_info
, alloc_size
, all_info2
, all_info2
, alloc_size
);
600 CHECK_VAL("SMB2_FIND_FULL_DIRECTORY_INFO", full_directory_info
, alloc_size
, all_info2
, all_info2
, alloc_size
);
601 CHECK_VAL("SMB2_FIND_BOTH_DIRECTORY_INFO", both_directory_info
, alloc_size
, all_info2
, all_info2
, alloc_size
);
602 CHECK_VAL("SMB2_FIND_ID_FULL_DIRECTORY_INFO", id_full_directory_info
, alloc_size
, all_info2
, all_info2
, alloc_size
);
603 CHECK_VAL("SMB2_FIND_ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, alloc_size
, all_info2
, all_info2
, alloc_size
);
605 CHECK_VAL("SMB2_FIND_FULL_DIRECTORY_INFO", full_directory_info
, ea_size
, all_info2
, all_info2
, ea_size
);
606 CHECK_VAL("SMB2_FIND_BOTH_DIRECTORY_INFO", both_directory_info
, ea_size
, all_info2
, all_info2
, ea_size
);
607 CHECK_VAL("SMB2_FIND_ID_FULL_DIRECTORY_INFO", id_full_directory_info
, ea_size
, all_info2
, all_info2
, ea_size
);
608 CHECK_VAL("SMB2_FIND_ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, ea_size
, all_info2
, all_info2
, ea_size
);
610 CHECK_NAME("SMB2_FIND_DIRECTORY_INFO", directory_info
, name
, fname
, STR_TERMINATE_ASCII
);
611 CHECK_NAME("SMB2_FIND_FULL_DIRECTORY_INFO", full_directory_info
, name
, fname
, STR_TERMINATE_ASCII
);
612 CHECK_NAME("SMB2_FIND_NAME_INFO", name_info
, name
, fname
, STR_TERMINATE_ASCII
);
613 CHECK_NAME("SMB2_FIND_BOTH_DIRECTORY_INFO", both_directory_info
, name
, fname
, STR_TERMINATE_ASCII
);
614 CHECK_NAME("SMB2_FIND_ID_FULL_DIRECTORY_INFO", id_full_directory_info
, name
, fname
, STR_TERMINATE_ASCII
);
615 CHECK_NAME("SMB2_FIND_ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, name
, fname
, STR_TERMINATE_ASCII
);
617 CHECK_WSTR("SMB2_FIND_BOTH_DIRECTORY_INFO", both_directory_info
, short_name
, alt_info
, alt_name_info
, fname
, STR_UNICODE
);
619 CHECK_VAL("SMB2_FIND_ID_FULL_DIRECTORY_INFO", id_full_directory_info
, file_id
, internal_info
, internal_information
, file_id
);
620 CHECK_VAL("SMB2_FIND_ID_BOTH_DIRECTORY_INFO", id_both_directory_info
, file_id
, internal_info
, internal_information
, file_id
);
623 smb2_util_close(tree
, h
);
624 smb2_util_unlink(tree
, fname
);
625 talloc_free(mem_ctx
);
631 struct multiple_result
{
634 union smb_search_data
*list
;
637 bool fill_result(void *private_data
,
638 union smb_search_data
*file
,
641 enum smb_search_data_level data_level
)
645 struct multiple_result
*data
= (struct multiple_result
*)private_data
;
647 for (i
=0; i
<count
; i
++) {
648 sname
= extract_name(&file
[i
], level
, data_level
);
649 if (!strcmp(sname
, ".") || !(strcmp(sname
, "..")))
652 data
->list
= talloc_realloc(data
->tctx
,
654 union smb_search_data
,
656 data
->list
[data
->count
-1] = file
[i
];
661 enum continue_type
{CONT_SINGLE
, CONT_INDEX
, CONT_RESTART
};
663 static NTSTATUS
multiple_smb2_search(struct smb2_tree
*tree
,
667 enum smb_search_data_level data_level
,
668 enum continue_type cont_type
,
670 struct smb2_handle
*h
)
675 union smb_search_data
*d
;
677 struct multiple_result
*result
= (struct multiple_result
*)data
;
680 f
.in
.file
.handle
= *h
;
681 f
.in
.pattern
= pattern
;
682 f
.in
.max_response_size
= 0x1000;
685 /* The search should start from the beginning everytime */
686 f
.in
.continue_flags
= SMB2_CONTINUE_FLAG_RESTART
;
689 status
= smb2_find_level(tree
, tree
, &f
, &count
, &d
);
690 if (NT_STATUS_EQUAL(status
, STATUS_NO_MORE_FILES
))
692 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
693 if (!fill_result(result
, d
, count
, level
, data_level
)) {
694 return NT_STATUS_UNSUCCESSFUL
;
698 * After the first iteration is complete set the CONTINUE
699 * FLAGS appropriately
703 f
.in
.continue_flags
= SMB2_CONTINUE_FLAG_INDEX
;
706 f
.in
.continue_flags
= SMB2_CONTINUE_FLAG_SINGLE
;
710 /* we should prevent staying in the loop
712 f
.in
.continue_flags
= 0;
715 } while (count
!= 0);
721 static enum smb_search_data_level compare_data_level
;
724 static int search_compare(union smb_search_data
*d1
,
725 union smb_search_data
*d2
)
729 s1
= extract_name(d1
, level_sort
, compare_data_level
);
730 s2
= extract_name(d2
, level_sort
, compare_data_level
);
731 return strcmp_safe(s1
, s2
);
735 basic testing of search calls using many files
737 static bool test_many_files(struct torture_context
*tctx
,
738 struct smb2_tree
*tree
)
740 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
741 const int num_files
= 700;
746 struct multiple_result result
;
747 struct smb2_create create
;
748 struct smb2_handle h
;
751 const char *cont_name
;
753 enum smb_search_data_level data_level
;
754 enum continue_type cont_type
;
756 {"SMB2_FIND_BOTH_DIRECTORY_INFO", "SINGLE", SMB2_FIND_BOTH_DIRECTORY_INFO
, RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
, CONT_SINGLE
},
757 {"SMB2_FIND_BOTH_DIRECTORY_INFO", "INDEX", SMB2_FIND_BOTH_DIRECTORY_INFO
, RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
, CONT_INDEX
},
758 {"SMB2_FIND_BOTH_DIRECTORY_INFO", "RESTART", SMB2_FIND_BOTH_DIRECTORY_INFO
, RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
, CONT_RESTART
},
759 {"SMB2_FIND_DIRECTORY_INFO", "SINGLE", SMB2_FIND_DIRECTORY_INFO
, RAW_SEARCH_DATA_DIRECTORY_INFO
, CONT_SINGLE
},
760 {"SMB2_FIND_DIRECTORY_INFO", "INDEX", SMB2_FIND_DIRECTORY_INFO
, RAW_SEARCH_DATA_DIRECTORY_INFO
, CONT_INDEX
},
761 {"SMB2_FIND_DIRECTORY_INFO", "RESTART", SMB2_FIND_DIRECTORY_INFO
, RAW_SEARCH_DATA_DIRECTORY_INFO
, CONT_RESTART
},
762 {"SMB2_FIND_FULL_DIRECTORY_INFO", "SINGLE", SMB2_FIND_FULL_DIRECTORY_INFO
, RAW_SEARCH_DATA_FULL_DIRECTORY_INFO
, CONT_SINGLE
},
763 {"SMB2_FIND_FULL_DIRECTORY_INFO", "INDEX", SMB2_FIND_FULL_DIRECTORY_INFO
, RAW_SEARCH_DATA_FULL_DIRECTORY_INFO
, CONT_INDEX
},
764 {"SMB2_FIND_FULL_DIRECTORY_INFO", "RESTART", SMB2_FIND_FULL_DIRECTORY_INFO
, RAW_SEARCH_DATA_FULL_DIRECTORY_INFO
, CONT_RESTART
},
765 {"SMB2_FIND_ID_FULL_DIRECTORY_INFO", "SINGLE", SMB2_FIND_ID_FULL_DIRECTORY_INFO
, RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO
, CONT_SINGLE
},
766 {"SMB2_FIND_ID_FULL_DIRECTORY_INFO", "INDEX", SMB2_FIND_ID_FULL_DIRECTORY_INFO
, RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO
, CONT_INDEX
},
767 {"SMB2_FIND_ID_FULL_DIRECTORY_INFO", "RESTART", SMB2_FIND_ID_FULL_DIRECTORY_INFO
, RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO
, CONT_RESTART
},
768 {"SMB2_FIND_ID_BOTH_DIRECTORY_INFO", "SINGLE", SMB2_FIND_ID_BOTH_DIRECTORY_INFO
, RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO
, CONT_SINGLE
},
769 {"SMB2_FIND_ID_BOTH_DIRECTORY_INFO", "INDEX", SMB2_FIND_ID_BOTH_DIRECTORY_INFO
, RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO
, CONT_INDEX
},
770 {"SMB2_FIND_ID_BOTH_DIRECTORY_INFO", "RESTART", SMB2_FIND_ID_BOTH_DIRECTORY_INFO
, RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO
, CONT_RESTART
}
773 smb2_deltree(tree
, DNAME
);
774 status
= torture_smb2_testdir(tree
, DNAME
, &h
);
775 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
777 torture_comment(tctx
, "Testing with %d files\n", num_files
);
779 create
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
780 create
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
781 create
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
783 for (i
=num_files
-1;i
>=0;i
--) {
784 fname
= talloc_asprintf(mem_ctx
, DNAME
"\\t%03d-%d.txt", i
, i
);
785 create
.in
.fname
= talloc_asprintf(mem_ctx
, "%s", fname
);
786 status
= smb2_create(tree
, mem_ctx
, &create
);
787 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
788 smb2_util_close(tree
, create
.out
.file
.handle
);
792 for (t
=0;t
<ARRAY_SIZE(search_types
);t
++) {
794 result
.tctx
= talloc_new(tctx
);
796 torture_comment(tctx
,
797 "Continue %s via %s\n", search_types
[t
].name
,
798 search_types
[t
].cont_name
);
799 status
= multiple_smb2_search(tree
, tctx
, "*",
800 search_types
[t
].level
,
801 search_types
[t
].data_level
,
802 search_types
[t
].cont_type
,
805 torture_assert_int_equal_goto(tctx
, result
.count
, num_files
,
808 compare_data_level
= search_types
[t
].data_level
;
809 level_sort
= search_types
[t
].level
;
811 qsort(result
.list
, result
.count
, sizeof(result
.list
[0]),
812 QSORT_CAST search_compare
);
814 for (i
=0;i
<result
.count
;i
++) {
816 enum smb_search_level level
;
817 level
= RAW_SEARCH_SMB2
;
818 s
= extract_name(&result
.list
[i
],
819 search_types
[t
].level
,
821 fname
= talloc_asprintf(mem_ctx
, "t%03d-%d.txt", i
, i
);
822 torture_assert_str_equal_goto(tctx
, s
, fname
, ret
,
823 done
, "Incorrect name");
826 talloc_free(result
.tctx
);
830 smb2_util_close(tree
, h
);
831 smb2_deltree(tree
, DNAME
);
832 talloc_free(mem_ctx
);
838 check an individual file result
840 static bool check_result(struct torture_context
*tctx
,
841 struct multiple_result
*result
,
847 for (i
=0;i
<result
->count
;i
++) {
849 result
->list
[i
].both_directory_info
.name
.s
) == 0) {
853 if (i
== result
->count
) {
855 torture_result(tctx
, TORTURE_FAIL
,
856 "failed: '%s' should exist with attribute %s\n",
857 name
, attrib_string(result
->list
, attrib
));
864 torture_result(tctx
, TORTURE_FAIL
,
865 "failed: '%s' should NOT exist (has attribute %s)\n",
866 name
, attrib_string(result
->list
,
867 result
->list
[i
].both_directory_info
.attrib
));
871 if ((result
->list
[i
].both_directory_info
.attrib
&0xFFF) != attrib
) {
872 torture_result(tctx
, TORTURE_FAIL
,
873 "failed: '%s' should have attribute 0x%x (has 0x%x)\n",
874 name
, attrib
, result
->list
[i
].both_directory_info
.attrib
);
881 test what happens when the directory is modified during a search
883 static bool test_modify_search(struct torture_context
*tctx
,
884 struct smb2_tree
*tree
)
887 struct multiple_result result
;
888 union smb_setfileinfo sfinfo
;
889 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
890 struct smb2_create create
;
891 struct smb2_handle h
;
893 union smb_search_data
*d
;
894 struct file_elem files
[700] = {};
900 smb2_deltree(tree
, DNAME
);
902 status
= torture_smb2_testdir(tree
, DNAME
, &h
);
903 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
905 torture_comment(tctx
, "Creating %d files\n", num_files
);
908 create
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
909 create
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
910 create
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
912 for (i
= num_files
-1; i
>= 0; i
--) {
913 files
[i
].name
= talloc_asprintf(mem_ctx
, "t%03d-%d.txt", i
, i
);
914 create
.in
.fname
= talloc_asprintf(mem_ctx
, "%s\\%s",
915 DNAME
, files
[i
].name
);
916 status
= smb2_create(tree
, mem_ctx
, &create
);
917 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
918 smb2_util_close(tree
, create
.out
.file
.handle
);
921 torture_comment(tctx
, "pulling the first two files\n");
923 result
.tctx
= talloc_new(tctx
);
926 f
.in
.file
.handle
= h
;
928 f
.in
.continue_flags
= SMB2_CONTINUE_FLAG_SINGLE
;
929 f
.in
.max_response_size
= 0x100;
930 f
.in
.level
= SMB2_FIND_BOTH_DIRECTORY_INFO
;
933 status
= smb2_find_level(tree
, tree
, &f
, &count
, &d
);
934 if (NT_STATUS_EQUAL(status
, STATUS_NO_MORE_FILES
))
936 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
937 if (!fill_result(&result
, d
, count
, f
.in
.level
,
938 RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
)) {
942 } while (result
.count
< 2);
944 torture_comment(tctx
, "Changing attributes and deleting\n");
947 create
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
948 create
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
949 create
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
951 files
[num_files
].name
= talloc_asprintf(mem_ctx
, "T003-03.txt.2");
952 create
.in
.fname
= talloc_asprintf(mem_ctx
, "%s\\%s", DNAME
,
953 files
[num_files
].name
);
954 status
= smb2_create(tree
, mem_ctx
, &create
);
955 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
956 smb2_util_close(tree
, create
.out
.file
.handle
);
959 create
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
960 create
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
961 create
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
963 files
[num_files
+ 1].name
= talloc_asprintf(mem_ctx
, "T013-13.txt.2");
964 create
.in
.fname
= talloc_asprintf(mem_ctx
, "%s\\%s", DNAME
,
965 files
[num_files
+ 1].name
);
966 status
= smb2_create(tree
, mem_ctx
, &create
);
967 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
968 smb2_util_close(tree
, create
.out
.file
.handle
);
970 files
[num_files
+ 2].name
= talloc_asprintf(mem_ctx
, "T013-13.txt.3");
971 status
= smb2_create_complex_file(tree
, DNAME
"\\T013-13.txt.3", &h
);
972 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
974 smb2_util_unlink(tree
, DNAME
"\\T014-14.txt");
975 smb2_util_setatr(tree
, DNAME
"\\T015-15.txt", FILE_ATTRIBUTE_HIDDEN
);
976 smb2_util_setatr(tree
, DNAME
"\\T016-16.txt", FILE_ATTRIBUTE_NORMAL
);
977 smb2_util_setatr(tree
, DNAME
"\\T017-17.txt", FILE_ATTRIBUTE_SYSTEM
);
978 smb2_util_setatr(tree
, DNAME
"\\T018-18.txt", 0);
979 smb2_util_setatr(tree
, DNAME
"\\T039-39.txt", FILE_ATTRIBUTE_HIDDEN
);
980 smb2_util_setatr(tree
, DNAME
"\\T000-0.txt", FILE_ATTRIBUTE_HIDDEN
);
981 sfinfo
.generic
.level
= RAW_SFILEINFO_DISPOSITION_INFORMATION
;
982 sfinfo
.generic
.in
.file
.path
= DNAME
"\\T013-13.txt.3";
983 sfinfo
.disposition_info
.in
.delete_on_close
= 1;
984 status
= smb2_composite_setpathinfo(tree
, &sfinfo
);
985 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
987 /* Reset the numfiles to include the new files and start the
988 * search from the beginning */
989 num_files
= num_files
+ 2;
991 f
.in
.continue_flags
= SMB2_CONTINUE_FLAG_RESTART
;
995 status
= smb2_find_level(tree
, tree
, &f
, &count
, &d
);
996 if (NT_STATUS_EQUAL(status
, STATUS_NO_MORE_FILES
))
998 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
999 if (!fill_result(&result
, d
, count
, f
.in
.level
,
1000 RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
)) {
1004 f
.in
.continue_flags
= 0;
1005 f
.in
.max_response_size
= 4096;
1006 } while (count
!= 0);
1009 ret
&= check_result(tctx
, &result
, "t039-39.txt", true, FILE_ATTRIBUTE_HIDDEN
);
1010 ret
&= check_result(tctx
, &result
, "t000-0.txt", true, FILE_ATTRIBUTE_HIDDEN
);
1011 ret
&= check_result(tctx
, &result
, "t014-14.txt", false, 0);
1012 ret
&= check_result(tctx
, &result
, "t015-15.txt", true, FILE_ATTRIBUTE_HIDDEN
);
1013 ret
&= check_result(tctx
, &result
, "t016-16.txt", true, FILE_ATTRIBUTE_NORMAL
);
1014 ret
&= check_result(tctx
, &result
, "t017-17.txt", true, FILE_ATTRIBUTE_SYSTEM
);
1015 ret
&= check_result(tctx
, &result
, "t018-18.txt", true, FILE_ATTRIBUTE_ARCHIVE
);
1016 ret
&= check_result(tctx
, &result
, "t019-19.txt", true, FILE_ATTRIBUTE_ARCHIVE
);
1017 ret
&= check_result(tctx
, &result
, "T013-13.txt.2", true, FILE_ATTRIBUTE_ARCHIVE
);
1018 ret
&= check_result(tctx
, &result
, "T003-3.txt.2", false, 0);
1019 ret
&= check_result(tctx
, &result
, "T013-13.txt.3", true, FILE_ATTRIBUTE_NORMAL
);
1022 for (i
=0;i
<result
.count
;i
++) {
1023 torture_warning(tctx
, "%s %s (0x%x)\n",
1024 result
.list
[i
].both_directory_info
.name
.s
,
1026 result
.list
[i
].both_directory_info
.attrib
),
1027 result
.list
[i
].both_directory_info
.attrib
);
1031 smb2_util_close(tree
, h
);
1032 smb2_deltree(tree
, DNAME
);
1033 talloc_free(mem_ctx
);
1039 testing if directories always come back sorted
1041 static bool test_sorted(struct torture_context
*tctx
,
1042 struct smb2_tree
*tree
)
1044 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
1045 const int num_files
= 700;
1047 struct file_elem files
[700] = {};
1050 struct multiple_result result
;
1051 struct smb2_handle h
;
1053 torture_comment(tctx
, "Testing if directories always come back "
1055 status
= populate_tree(tctx
, mem_ctx
, tree
, files
, num_files
, &h
);
1056 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
1058 ZERO_STRUCT(result
);
1061 status
= multiple_smb2_search(tree
, tctx
, "*",
1062 SMB2_FIND_BOTH_DIRECTORY_INFO
,
1063 RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
,
1064 SMB2_CONTINUE_FLAG_SINGLE
,
1067 torture_assert_int_equal_goto(tctx
, result
.count
, num_files
, ret
, done
,
1070 for (i
=0;i
<num_files
-1;i
++) {
1071 const char *name1
, *name2
;
1072 name1
= result
.list
[i
].both_directory_info
.name
.s
;
1073 name2
= result
.list
[i
+1].both_directory_info
.name
.s
;
1074 if (strcasecmp_m(name1
, name2
) > 0) {
1075 torture_comment(tctx
, "non-alphabetical order at entry "
1076 "%d '%s' '%s'\n", i
, name1
, name2
);
1077 torture_comment(tctx
,
1078 "Server does not produce sorted directory listings"
1079 "(not an error)\n");
1083 talloc_free(result
.list
);
1085 smb2_util_close(tree
, h
);
1086 smb2_deltree(tree
, DNAME
);
1087 talloc_free(mem_ctx
);
1092 /* test the behavior of file_index field in the SMB2_FIND struct */
1093 static bool test_file_index(struct torture_context
*tctx
,
1094 struct smb2_tree
*tree
)
1096 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
1097 const int num_files
= 100;
1098 int resume_index
= 4;
1103 struct multiple_result result
;
1104 struct smb2_create create
;
1106 struct smb2_handle h
;
1107 union smb_search_data
*d
;
1110 smb2_deltree(tree
, DNAME
);
1112 status
= torture_smb2_testdir(tree
, DNAME
, &h
);
1113 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
1115 torture_comment(tctx
, "Testing the behavior of file_index flag\n");
1117 ZERO_STRUCT(create
);
1118 create
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
1119 create
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
1120 create
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
1121 for (i
= num_files
-1; i
>= 0; i
--) {
1122 fname
= talloc_asprintf(mem_ctx
, DNAME
"\\file%u.txt", i
);
1123 create
.in
.fname
= fname
;
1124 status
= smb2_create(tree
, mem_ctx
, &create
);
1125 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
1127 smb2_util_close(tree
, create
.out
.file
.handle
);
1130 ZERO_STRUCT(result
);
1134 f
.in
.file
.handle
= h
;
1136 f
.in
.continue_flags
= SMB2_CONTINUE_FLAG_SINGLE
;
1137 f
.in
.max_response_size
= 0x1000;
1138 f
.in
.level
= SMB2_FIND_FULL_DIRECTORY_INFO
;
1141 status
= smb2_find_level(tree
, tree
, &f
, &count
, &d
);
1142 if (NT_STATUS_EQUAL(status
, STATUS_NO_MORE_FILES
))
1144 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
1145 if (!fill_result(&result
, d
, count
, f
.in
.level
,
1146 RAW_SEARCH_DATA_FULL_DIRECTORY_INFO
)) {
1150 } while(result
.count
< 10);
1152 if (result
.list
[0].full_directory_info
.file_index
== 0) {
1153 torture_skip_goto(tctx
, done
,
1154 "Talking to a server that doesn't provide a "
1155 "file index.\nWindows servers using NTFS do "
1156 "not provide a file_index. Skipping test\n");
1158 /* We are not talking to a Windows based server. Windows
1159 * servers using NTFS do not provide a file_index. Windows
1160 * servers using FAT do provide a file index, however in both
1161 * cases they do not honor a file index on a resume request.
1162 * See MS-FSCC <62> and MS-SMB2 <54> for more information. */
1164 /* Set the file_index flag to point to the fifth file from the
1165 * previous enumeration and try to start the subsequent
1166 * searches from that point */
1168 result
.list
[resume_index
].full_directory_info
.file_index
;
1169 f
.in
.continue_flags
= SMB2_CONTINUE_FLAG_INDEX
;
1171 /* get the name of the next expected file */
1172 fname
= talloc_asprintf(mem_ctx
, DNAME
"\\%s",
1173 result
.list
[resume_index
].full_directory_info
.name
.s
);
1175 ZERO_STRUCT(result
);
1177 status
= smb2_find_level(tree
, tree
, &f
, &count
, &d
);
1178 if (NT_STATUS_EQUAL(status
, STATUS_NO_MORE_FILES
))
1180 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
1181 if (!fill_result(&result
, d
, count
, f
.in
.level
,
1182 RAW_SEARCH_DATA_FULL_DIRECTORY_INFO
)) {
1187 result
.list
[0].full_directory_info
.name
.s
)) {
1188 torture_comment(tctx
, "Next expected file: %s but the "
1189 "server returned %s\n", fname
,
1190 result
.list
[0].full_directory_info
.name
.s
);
1191 torture_comment(tctx
,
1192 "Not an error. Resuming using a file "
1193 "index is an optional feature of the "
1199 smb2_util_close(tree
, h
);
1200 smb2_deltree(tree
, DNAME
);
1201 talloc_free(mem_ctx
);
1207 * Tests directory enumeration in a directory containing >1000 files with
1208 * names of varying lengths.
1210 static bool test_large_files(struct torture_context
*tctx
,
1211 struct smb2_tree
*tree
)
1213 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
1214 const int num_files
= 2000;
1216 /* These should be evenly divisible */
1217 int num_at_len
= num_files
/ max_len
;
1218 struct file_elem files
[2000] = {};
1222 struct smb2_create create
;
1224 struct smb2_handle h
;
1225 union smb_search_data
*d
;
1226 int i
, j
, file_count
= 0;
1230 torture_comment(tctx
,
1231 "Testing directory enumeration in a directory with >1000 files\n");
1233 smb2_deltree(tree
, DNAME
);
1235 ZERO_STRUCT(create
);
1236 create
.in
.desired_access
= SEC_RIGHTS_DIR_ALL
;
1237 create
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1238 create
.in
.file_attributes
= FILE_ATTRIBUTE_DIRECTORY
;
1239 create
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1240 NTCREATEX_SHARE_ACCESS_WRITE
|
1241 NTCREATEX_SHARE_ACCESS_DELETE
;
1242 create
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
1243 create
.in
.fname
= DNAME
;
1245 status
= smb2_create(tree
, mem_ctx
, &create
);
1246 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
1247 h
= create
.out
.file
.handle
;
1249 ZERO_STRUCT(create
);
1250 create
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
1251 create
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
1252 create
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
1254 for (i
= 0; i
< num_files
; i
++) {
1255 if (i
% num_at_len
== 0) {
1256 strs
= generate_unique_strs(mem_ctx
, len
, num_at_len
);
1259 files
[i
].name
= strs
[i
% num_at_len
];
1260 create
.in
.fname
= talloc_asprintf(mem_ctx
, "%s\\%s",
1261 DNAME
, files
[i
].name
);
1262 status
= smb2_create(tree
, mem_ctx
, &create
);
1263 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
1264 smb2_util_close(tree
, create
.out
.file
.handle
);
1268 f
.in
.file
.handle
= h
;
1270 f
.in
.max_response_size
= 0x100;
1271 f
.in
.level
= SMB2_FIND_BOTH_DIRECTORY_INFO
;
1274 status
= smb2_find_level(tree
, tree
, &f
, &count
, &d
);
1275 if (NT_STATUS_EQUAL(status
, STATUS_NO_MORE_FILES
))
1277 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "");
1279 for (i
= 0; i
< count
; i
++) {
1281 const char *found
= d
[i
].both_directory_info
.name
.s
;
1283 if (!strcmp(found
, ".") || !strcmp(found
, ".."))
1287 for (j
= 0; j
< 2000; j
++) {
1288 if (!strcmp(files
[j
].name
, found
)) {
1289 files
[j
].found
= true;
1298 torture_result(tctx
, TORTURE_FAIL
,
1299 "(%s): didn't expect %s\n",
1300 __location__
, found
);
1304 file_count
= file_count
+ i
;
1305 f
.in
.continue_flags
= 0;
1306 f
.in
.max_response_size
= 4096;
1307 } while (count
!= 0);
1309 torture_assert_int_equal_goto(tctx
, file_count
, num_files
+ 2, ret
,
1312 for (i
= 0; i
< num_files
; i
++) {
1316 torture_result(tctx
, TORTURE_FAIL
,
1317 "(%s): expected to find %s, but didn't\n",
1318 __location__
, files
[j
].name
);
1323 smb2_util_close(tree
, h
);
1324 smb2_deltree(tree
, DNAME
);
1325 talloc_free(mem_ctx
);
1330 struct torture_suite
*torture_smb2_dir_init(void)
1332 struct torture_suite
*suite
=
1333 torture_suite_create(talloc_autofree_context(), "DIR");
1335 torture_suite_add_1smb2_test(suite
, "FIND", test_find
);
1336 torture_suite_add_1smb2_test(suite
, "FIXED", test_fixed
);
1337 torture_suite_add_1smb2_test(suite
, "ONE", test_one_file
);
1338 torture_suite_add_1smb2_test(suite
, "MANY", test_many_files
);
1339 torture_suite_add_1smb2_test(suite
, "MODIFY", test_modify_search
);
1340 torture_suite_add_1smb2_test(suite
, "SORTED", test_sorted
);
1341 torture_suite_add_1smb2_test(suite
, "FILE-INDEX", test_file_index
);
1342 torture_suite_add_1smb2_test(suite
, "LARGE-FILES", test_large_files
);
1343 suite
->description
= talloc_strdup(suite
, "SMB2-DIR tests");