2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2008
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
25 #include "torture/torture.h"
26 #include "torture/util.h"
27 #include "torture/smb2/proto.h"
28 #include "librpc/gen_ndr/ndr_security.h"
29 #include "libcli/security/security.h"
31 #include "system/filesys.h"
32 #include "auth/credentials/credentials.h"
33 #include "lib/cmdline/popt_common.h"
34 #include "librpc/gen_ndr/security.h"
35 #include "lib/events/events.h"
37 #define FNAME "test_create.dat"
38 #define DNAME "smb2_open"
40 #define CHECK_STATUS(status, correct) do { \
41 if (!NT_STATUS_EQUAL(status, correct)) { \
42 torture_result(tctx, TORTURE_FAIL, \
43 "(%s) Incorrect status %s - should be %s\n", \
44 __location__, nt_errstr(status), nt_errstr(correct)); \
48 #define CHECK_EQUAL(v, correct) do { \
50 torture_result(tctx, TORTURE_FAIL, \
51 "(%s) Incorrect value for %s 0x%08llx - " \
52 "should be 0x%08llx\n", \
54 (unsigned long long)v, \
55 (unsigned long long)correct); \
59 #define CHECK_TIME(t, field) do { \
61 finfo.all_info.level = RAW_FILEINFO_ALL_INFORMATION; \
62 finfo.all_info.in.file.handle = h1; \
63 status = smb2_getinfo_file(tree, tctx, &finfo); \
64 CHECK_STATUS(status, NT_STATUS_OK); \
66 t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
67 if (abs(t1-t2) > 2) { \
68 torture_result(tctx, TORTURE_FAIL, \
69 "(%s) wrong time for field %s %s - %s\n", \
70 __location__, #field, \
71 timestring(tctx, t1), \
72 timestring(tctx, t2)); \
73 dump_all_info(tctx, &finfo); \
77 #define CHECK_NTTIME(t, field) do { \
79 finfo.all_info.level = RAW_FILEINFO_ALL_INFORMATION; \
80 finfo.all_info.in.file.handle = h1; \
81 status = smb2_getinfo_file(tree, tctx, &finfo); \
82 CHECK_STATUS(status, NT_STATUS_OK); \
83 t2 = finfo.all_info.out.field; \
84 if (abs(t-t2) > 20000) { \
85 torture_result(tctx, TORTURE_FAIL, \
86 "(%s) wrong time for field %s %s - %s\n", \
87 __location__, #field, \
88 nt_time_string(tctx, t), \
89 nt_time_string(tctx, t2)); \
90 dump_all_info(tctx, &finfo); \
94 #define CHECK_ALL_INFO(v, field) do { \
95 finfo.all_info.level = RAW_FILEINFO_ALL_INFORMATION; \
96 finfo.all_info.in.file.handle = h1; \
97 status = smb2_getinfo_file(tree, tctx, &finfo); \
98 CHECK_STATUS(status, NT_STATUS_OK); \
99 if ((v) != (finfo.all_info.out.field)) { \
100 torture_result(tctx, TORTURE_FAIL, \
101 "(%s) wrong value for field %s 0x%x - 0x%x\n", \
102 __location__, #field, (int)v,\
103 (int)(finfo.all_info.out.field)); \
104 dump_all_info(tctx, &finfo); \
108 #define CHECK_VAL(v, correct) do { \
109 if ((v) != (correct)) { \
110 torture_result(tctx, TORTURE_FAIL, \
111 "(%s) wrong value for %s 0x%x - should be 0x%x\n", \
112 __location__, #v, (int)(v), (int)correct); \
116 #define SET_ATTRIB(sattrib) do { \
117 union smb_setfileinfo sfinfo; \
118 ZERO_STRUCT(sfinfo.basic_info.in); \
119 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION; \
120 sfinfo.basic_info.in.file.handle = h1; \
121 sfinfo.basic_info.in.attrib = sattrib; \
122 status = smb2_setinfo_file(tree, &sfinfo); \
123 if (!NT_STATUS_IS_OK(status)) { \
124 torture_comment(tctx, \
125 "(%s) Failed to set attrib 0x%x on %s\n", \
126 __location__, sattrib, fname); \
130 test some interesting combinations found by gentest
132 static bool test_create_gentest(struct torture_context
*tctx
, struct smb2_tree
*tree
)
134 struct smb2_create io
;
136 uint32_t access_mask
, file_attributes_set
;
137 uint32_t ok_mask
, not_supported_mask
, invalid_parameter_mask
;
138 uint32_t not_a_directory_mask
, unexpected_mask
;
139 union smb_fileinfo q
;
142 io
.in
.desired_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
143 io
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
144 io
.in
.create_disposition
= NTCREATEX_DISP_OVERWRITE_IF
;
146 NTCREATEX_SHARE_ACCESS_DELETE
|
147 NTCREATEX_SHARE_ACCESS_READ
|
148 NTCREATEX_SHARE_ACCESS_WRITE
;
149 io
.in
.create_options
= 0;
152 status
= smb2_create(tree
, tctx
, &io
);
153 CHECK_STATUS(status
, NT_STATUS_OK
);
155 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
156 CHECK_STATUS(status
, NT_STATUS_OK
);
158 io
.in
.create_options
= 0xF0000000;
159 status
= smb2_create(tree
, tctx
, &io
);
160 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
162 io
.in
.create_options
= 0;
164 io
.in
.file_attributes
= FILE_ATTRIBUTE_DEVICE
;
165 status
= smb2_create(tree
, tctx
, &io
);
166 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
168 io
.in
.file_attributes
= FILE_ATTRIBUTE_VOLUME
;
169 status
= smb2_create(tree
, tctx
, &io
);
170 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
172 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
173 io
.in
.file_attributes
= FILE_ATTRIBUTE_VOLUME
;
174 status
= smb2_create(tree
, tctx
, &io
);
175 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
177 io
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
178 io
.in
.desired_access
= 0x08000000;
179 status
= smb2_create(tree
, tctx
, &io
);
180 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
182 io
.in
.desired_access
= 0x04000000;
183 status
= smb2_create(tree
, tctx
, &io
);
184 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
186 io
.in
.file_attributes
= 0;
187 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
188 io
.in
.desired_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
190 not_supported_mask
= 0;
191 invalid_parameter_mask
= 0;
192 not_a_directory_mask
= 0;
197 io
.in
.create_options
= 1<<i
;
198 if (io
.in
.create_options
& NTCREATEX_OPTIONS_DELETE_ON_CLOSE
) {
201 status
= smb2_create(tree
, tctx
, &io
);
202 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_SUPPORTED
)) {
203 not_supported_mask
|= 1<<i
;
204 } else if (NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
)) {
205 invalid_parameter_mask
|= 1<<i
;
206 } else if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_A_DIRECTORY
)) {
207 not_a_directory_mask
|= 1<<i
;
208 } else if (NT_STATUS_EQUAL(status
, NT_STATUS_OK
)) {
210 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
211 CHECK_STATUS(status
, NT_STATUS_OK
);
213 unexpected_mask
|= 1<<i
;
214 torture_comment(tctx
,
215 "create option 0x%08x returned %s\n",
216 1<<i
, nt_errstr(status
));
220 io
.in
.create_options
= 0;
222 CHECK_EQUAL(ok_mask
, 0x00efcf7e);
223 CHECK_EQUAL(not_a_directory_mask
, 0x00000001);
224 CHECK_EQUAL(not_supported_mask
, 0x00102080);
225 CHECK_EQUAL(invalid_parameter_mask
, 0xff000000);
226 CHECK_EQUAL(unexpected_mask
, 0x00000000);
228 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
229 io
.in
.file_attributes
= 0;
234 io
.in
.desired_access
= 1<<i
;
235 status
= smb2_create(tree
, tctx
, &io
);
236 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) ||
237 NT_STATUS_EQUAL(status
, NT_STATUS_PRIVILEGE_NOT_HELD
)) {
238 access_mask
|= io
.in
.desired_access
;
240 CHECK_STATUS(status
, NT_STATUS_OK
);
241 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
242 CHECK_STATUS(status
, NT_STATUS_OK
);
247 if (TARGET_IS_WIN7(tctx
)) {
248 CHECK_EQUAL(access_mask
, 0x0de0fe00);
249 } else if (torture_setting_bool(tctx
, "samba4", false)) {
250 CHECK_EQUAL(access_mask
, 0x0cf0fe00);
252 CHECK_EQUAL(access_mask
, 0x0df0fe00);
255 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
256 io
.in
.desired_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
257 io
.in
.file_attributes
= 0;
259 invalid_parameter_mask
= 0;
261 file_attributes_set
= 0;
265 io
.in
.file_attributes
= 1<<i
;
266 if (io
.in
.file_attributes
& FILE_ATTRIBUTE_ENCRYPTED
) {
269 smb2_deltree(tree
, FNAME
);
270 status
= smb2_create(tree
, tctx
, &io
);
271 if (NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
)) {
272 invalid_parameter_mask
|= 1<<i
;
273 } else if (NT_STATUS_IS_OK(status
)) {
277 expected
= (io
.in
.file_attributes
| FILE_ATTRIBUTE_ARCHIVE
) & 0x00005127;
278 io
.out
.file_attr
&= ~FILE_ATTRIBUTE_NONINDEXED
;
279 CHECK_EQUAL(io
.out
.file_attr
, expected
);
280 file_attributes_set
|= io
.out
.file_attr
;
282 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
283 CHECK_STATUS(status
, NT_STATUS_OK
);
285 unexpected_mask
|= 1<<i
;
286 torture_comment(tctx
,
287 "file attribute 0x%08x returned %s\n",
288 1<<i
, nt_errstr(status
));
293 CHECK_EQUAL(ok_mask
, 0x00003fb7);
294 CHECK_EQUAL(invalid_parameter_mask
, 0xffff8048);
295 CHECK_EQUAL(unexpected_mask
, 0x00000000);
296 CHECK_EQUAL(file_attributes_set
, 0x00001127);
298 smb2_deltree(tree
, FNAME
);
301 * Standalone servers doesn't support encryption
303 io
.in
.file_attributes
= FILE_ATTRIBUTE_ENCRYPTED
;
304 status
= smb2_create(tree
, tctx
, &io
);
305 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
306 torture_comment(tctx
,
307 "FILE_ATTRIBUTE_ENCRYPTED returned %s\n",
310 CHECK_STATUS(status
, NT_STATUS_OK
);
311 CHECK_EQUAL(io
.out
.file_attr
, (FILE_ATTRIBUTE_ENCRYPTED
| FILE_ATTRIBUTE_ARCHIVE
));
312 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
313 CHECK_STATUS(status
, NT_STATUS_OK
);
316 smb2_deltree(tree
, FNAME
);
319 io
.in
.desired_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
320 io
.in
.file_attributes
= 0;
321 io
.in
.create_disposition
= NTCREATEX_DISP_OVERWRITE_IF
;
323 NTCREATEX_SHARE_ACCESS_READ
|
324 NTCREATEX_SHARE_ACCESS_WRITE
;
325 io
.in
.create_options
= 0;
326 io
.in
.fname
= FNAME
":stream1";
327 status
= smb2_create(tree
, tctx
, &io
);
328 CHECK_STATUS(status
, NT_STATUS_OK
);
330 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
331 CHECK_STATUS(status
, NT_STATUS_OK
);
334 io
.in
.file_attributes
= 0x8040;
336 NTCREATEX_SHARE_ACCESS_READ
;
337 status
= smb2_create(tree
, tctx
, &io
);
338 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
341 io
.in
.file_attributes
= 0;
342 io
.in
.desired_access
= SEC_FILE_READ_DATA
| SEC_FILE_WRITE_DATA
| SEC_FILE_APPEND_DATA
;
343 io
.in
.query_maximal_access
= true;
344 status
= smb2_create(tree
, tctx
, &io
);
345 CHECK_STATUS(status
, NT_STATUS_OK
);
346 CHECK_EQUAL(io
.out
.maximal_access
, 0x001f01ff);
348 q
.access_information
.level
= RAW_FILEINFO_ACCESS_INFORMATION
;
349 q
.access_information
.in
.file
.handle
= io
.out
.file
.handle
;
350 status
= smb2_getinfo_file(tree
, tctx
, &q
);
351 CHECK_STATUS(status
, NT_STATUS_OK
);
352 CHECK_EQUAL(q
.access_information
.out
.access_flags
, io
.in
.desired_access
);
354 io
.in
.file_attributes
= 0;
355 io
.in
.desired_access
= 0;
356 io
.in
.query_maximal_access
= false;
357 io
.in
.share_access
= 0;
358 status
= smb2_create(tree
, tctx
, &io
);
359 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
361 smb2_deltree(tree
, FNAME
);
368 try the various request blobs
370 static bool test_create_blob(struct torture_context
*tctx
, struct smb2_tree
*tree
)
372 struct smb2_create io
;
375 smb2_deltree(tree
, FNAME
);
378 io
.in
.desired_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
379 io
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
380 io
.in
.create_disposition
= NTCREATEX_DISP_OVERWRITE_IF
;
382 NTCREATEX_SHARE_ACCESS_DELETE
|
383 NTCREATEX_SHARE_ACCESS_READ
|
384 NTCREATEX_SHARE_ACCESS_WRITE
;
385 io
.in
.create_options
= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY
|
386 NTCREATEX_OPTIONS_ASYNC_ALERT
|
387 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
|
391 status
= smb2_create(tree
, tctx
, &io
);
392 CHECK_STATUS(status
, NT_STATUS_OK
);
394 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
395 CHECK_STATUS(status
, NT_STATUS_OK
);
397 torture_comment(tctx
, "Testing alloc size\n");
398 /* FIXME We use 1M cause that's the rounded size of Samba.
399 * We should ask the server for the cluser size and calulate it
401 io
.in
.alloc_size
= 0x00100000;
402 status
= smb2_create(tree
, tctx
, &io
);
403 CHECK_STATUS(status
, NT_STATUS_OK
);
404 CHECK_EQUAL(io
.out
.alloc_size
, io
.in
.alloc_size
);
406 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
407 CHECK_STATUS(status
, NT_STATUS_OK
);
409 torture_comment(tctx
, "Testing durable open\n");
410 io
.in
.durable_open
= true;
411 status
= smb2_create(tree
, tctx
, &io
);
412 CHECK_STATUS(status
, NT_STATUS_OK
);
414 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
415 CHECK_STATUS(status
, NT_STATUS_OK
);
417 torture_comment(tctx
, "Testing query maximal access\n");
418 io
.in
.query_maximal_access
= true;
419 status
= smb2_create(tree
, tctx
, &io
);
420 CHECK_STATUS(status
, NT_STATUS_OK
);
421 CHECK_EQUAL(io
.out
.maximal_access
, 0x001f01ff);
423 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
424 CHECK_STATUS(status
, NT_STATUS_OK
);
426 torture_comment(tctx
, "Testing timewarp\n");
427 io
.in
.timewarp
= 10000;
428 status
= smb2_create(tree
, tctx
, &io
);
429 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
432 torture_comment(tctx
, "Testing query_on_disk\n");
433 io
.in
.query_on_disk_id
= true;
434 status
= smb2_create(tree
, tctx
, &io
);
435 CHECK_STATUS(status
, NT_STATUS_OK
);
437 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
438 CHECK_STATUS(status
, NT_STATUS_OK
);
440 torture_comment(tctx
, "Testing unknown tag\n");
441 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
442 "FooO", data_blob(NULL
, 0));
443 CHECK_STATUS(status
, NT_STATUS_OK
);
445 status
= smb2_create(tree
, tctx
, &io
);
446 CHECK_STATUS(status
, NT_STATUS_OK
);
448 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
449 CHECK_STATUS(status
, NT_STATUS_OK
);
451 torture_comment(tctx
, "Testing bad tag length 0\n");
452 ZERO_STRUCT(io
.in
.blobs
);
453 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
454 "x", data_blob(NULL
, 0));
455 CHECK_STATUS(status
, NT_STATUS_OK
);
456 status
= smb2_create(tree
, tctx
, &io
);
457 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
459 torture_comment(tctx
, "Testing bad tag length 1\n");
460 ZERO_STRUCT(io
.in
.blobs
);
461 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
462 "x", data_blob(NULL
, 0));
463 CHECK_STATUS(status
, NT_STATUS_OK
);
464 status
= smb2_create(tree
, tctx
, &io
);
465 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
467 torture_comment(tctx
, "Testing bad tag length 2\n");
468 ZERO_STRUCT(io
.in
.blobs
);
469 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
470 "xx", data_blob(NULL
, 0));
471 CHECK_STATUS(status
, NT_STATUS_OK
);
472 status
= smb2_create(tree
, tctx
, &io
);
473 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
475 torture_comment(tctx
, "Testing bad tag length 3\n");
476 ZERO_STRUCT(io
.in
.blobs
);
477 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
478 "xxx", data_blob(NULL
, 0));
479 CHECK_STATUS(status
, NT_STATUS_OK
);
480 status
= smb2_create(tree
, tctx
, &io
);
481 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
483 torture_comment(tctx
, "Testing tag length 4\n");
484 ZERO_STRUCT(io
.in
.blobs
);
485 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
486 "xxxx", data_blob(NULL
, 0));
487 CHECK_STATUS(status
, NT_STATUS_OK
);
488 status
= smb2_create(tree
, tctx
, &io
);
489 CHECK_STATUS(status
, NT_STATUS_OK
);
491 torture_comment(tctx
, "Testing tag length 5\n");
492 ZERO_STRUCT(io
.in
.blobs
);
493 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
494 "xxxxx", data_blob(NULL
, 0));
495 CHECK_STATUS(status
, NT_STATUS_OK
);
496 status
= smb2_create(tree
, tctx
, &io
);
497 CHECK_STATUS(status
, NT_STATUS_OK
);
499 torture_comment(tctx
, "Testing tag length 6\n");
500 ZERO_STRUCT(io
.in
.blobs
);
501 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
502 "xxxxxx", data_blob(NULL
, 0));
503 CHECK_STATUS(status
, NT_STATUS_OK
);
504 status
= smb2_create(tree
, tctx
, &io
);
505 CHECK_STATUS(status
, NT_STATUS_OK
);
507 torture_comment(tctx
, "Testing tag length 7\n");
508 ZERO_STRUCT(io
.in
.blobs
);
509 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
510 "xxxxxxx", data_blob(NULL
, 0));
511 CHECK_STATUS(status
, NT_STATUS_OK
);
512 status
= smb2_create(tree
, tctx
, &io
);
513 CHECK_STATUS(status
, NT_STATUS_OK
);
515 torture_comment(tctx
, "Testing tag length 8\n");
516 ZERO_STRUCT(io
.in
.blobs
);
517 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
518 "xxxxxxxx", data_blob(NULL
, 0));
519 CHECK_STATUS(status
, NT_STATUS_OK
);
520 status
= smb2_create(tree
, tctx
, &io
);
521 CHECK_STATUS(status
, NT_STATUS_OK
);
523 torture_comment(tctx
, "Testing tag length 16\n");
524 ZERO_STRUCT(io
.in
.blobs
);
525 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
526 "xxxxxxxxxxxxxxxx", data_blob(NULL
, 0));
527 CHECK_STATUS(status
, NT_STATUS_OK
);
528 status
= smb2_create(tree
, tctx
, &io
);
529 CHECK_STATUS(status
, NT_STATUS_OK
);
531 torture_comment(tctx
, "Testing tag length 17\n");
532 ZERO_STRUCT(io
.in
.blobs
);
533 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
534 "xxxxxxxxxxxxxxxxx", data_blob(NULL
, 0));
535 CHECK_STATUS(status
, NT_STATUS_OK
);
536 status
= smb2_create(tree
, tctx
, &io
);
537 CHECK_STATUS(status
, NT_STATUS_OK
);
539 torture_comment(tctx
, "Testing tag length 34\n");
540 ZERO_STRUCT(io
.in
.blobs
);
541 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
542 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
544 CHECK_STATUS(status
, NT_STATUS_OK
);
545 status
= smb2_create(tree
, tctx
, &io
);
546 CHECK_STATUS(status
, NT_STATUS_OK
);
548 smb2_deltree(tree
, FNAME
);
553 #define FAIL_UNLESS(__cond) \
555 if (__cond) {} else { \
556 torture_result(tctx, TORTURE_FAIL, "%s) condition violated: %s\n", \
557 __location__, #__cond); \
558 ret = false; goto done; \
563 try creating with acls
565 static bool test_create_acl_ext(struct torture_context
*tctx
, struct smb2_tree
*tree
, bool test_dir
)
568 struct smb2_create io
;
570 struct security_ace ace
;
571 struct security_descriptor
*sd
;
572 struct dom_sid
*test_sid
;
573 union smb_fileinfo q
= {};
575 FILE_ATTRIBUTE_HIDDEN
|
576 FILE_ATTRIBUTE_SYSTEM
|
577 (test_dir
? FILE_ATTRIBUTE_DIRECTORY
: 0);
578 NTSTATUS (*delete_func
)(struct smb2_tree
*, const char *) =
579 test_dir
? smb2_util_rmdir
: smb2_util_unlink
;
583 smb2_deltree(tree
, FNAME
);
586 io
.in
.desired_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
587 io
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
588 io
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
590 NTCREATEX_SHARE_ACCESS_DELETE
|
591 NTCREATEX_SHARE_ACCESS_READ
|
592 NTCREATEX_SHARE_ACCESS_WRITE
;
593 io
.in
.create_options
= NTCREATEX_OPTIONS_ASYNC_ALERT
| 0x00200000 |
594 (test_dir
? NTCREATEX_OPTIONS_DIRECTORY
:
595 (NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
));
599 torture_comment(tctx
, "basic create\n");
601 status
= smb2_create(tree
, tctx
, &io
);
602 CHECK_STATUS(status
, NT_STATUS_OK
);
604 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
605 q
.query_secdesc
.in
.file
.handle
= io
.out
.file
.handle
;
606 q
.query_secdesc
.in
.secinfo_flags
=
610 status
= smb2_getinfo_file(tree
, tctx
, &q
);
611 CHECK_STATUS(status
, NT_STATUS_OK
);
612 sd
= q
.query_secdesc
.out
.sd
;
614 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
615 CHECK_STATUS(status
, NT_STATUS_OK
);
616 status
= delete_func(tree
, FNAME
);
617 CHECK_STATUS(status
, NT_STATUS_OK
);
619 torture_comment(tctx
, "adding a new ACE\n");
620 test_sid
= dom_sid_parse_talloc(tctx
, SID_NT_AUTHENTICATED_USERS
);
622 ace
.type
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
624 ace
.access_mask
= SEC_STD_ALL
;
625 ace
.trustee
= *test_sid
;
627 status
= security_descriptor_dacl_add(sd
, &ace
);
628 CHECK_STATUS(status
, NT_STATUS_OK
);
630 torture_comment(tctx
, "creating a file with an initial ACL\n");
633 status
= smb2_create(tree
, tctx
, &io
);
634 CHECK_STATUS(status
, NT_STATUS_OK
);
636 FAIL_UNLESS(smb2_util_verify_sd(tctx
, tree
, io
.out
.file
.handle
, sd
));
638 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
639 CHECK_STATUS(status
, NT_STATUS_OK
);
640 status
= delete_func(tree
, FNAME
);
641 CHECK_STATUS(status
, NT_STATUS_OK
);
643 torture_comment(tctx
, "creating with attributes\n");
645 io
.in
.sec_desc
= NULL
;
646 io
.in
.file_attributes
= attrib
;
647 status
= smb2_create(tree
, tctx
, &io
);
648 CHECK_STATUS(status
, NT_STATUS_OK
);
650 FAIL_UNLESS(smb2_util_verify_attrib(tctx
, tree
, io
.out
.file
.handle
, attrib
));
652 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
653 CHECK_STATUS(status
, NT_STATUS_OK
);
654 status
= delete_func(tree
, FNAME
);
655 CHECK_STATUS(status
, NT_STATUS_OK
);
657 torture_comment(tctx
, "creating with attributes and ACL\n");
660 io
.in
.file_attributes
= attrib
;
661 status
= smb2_create(tree
, tctx
, &io
);
662 CHECK_STATUS(status
, NT_STATUS_OK
);
664 FAIL_UNLESS(smb2_util_verify_sd(tctx
, tree
, io
.out
.file
.handle
, sd
));
665 FAIL_UNLESS(smb2_util_verify_attrib(tctx
, tree
, io
.out
.file
.handle
, attrib
));
667 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
668 CHECK_STATUS(status
, NT_STATUS_OK
);
669 status
= delete_func(tree
, FNAME
);
670 CHECK_STATUS(status
, NT_STATUS_OK
);
672 torture_comment(tctx
, "creating with attributes, ACL and owner\n");
673 sd
= security_descriptor_dacl_create(tctx
,
674 0, SID_WORLD
, SID_BUILTIN_USERS
,
676 SEC_ACE_TYPE_ACCESS_ALLOWED
,
677 SEC_RIGHTS_FILE_READ
| SEC_STD_ALL
,
682 io
.in
.file_attributes
= attrib
;
683 status
= smb2_create(tree
, tctx
, &io
);
684 CHECK_STATUS(status
, NT_STATUS_OK
);
686 FAIL_UNLESS(smb2_util_verify_sd(tctx
, tree
, io
.out
.file
.handle
, sd
));
687 FAIL_UNLESS(smb2_util_verify_attrib(tctx
, tree
, io
.out
.file
.handle
, attrib
));
690 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
691 CHECK_STATUS(status
, NT_STATUS_OK
);
692 status
= delete_func(tree
, FNAME
);
693 CHECK_STATUS(status
, NT_STATUS_OK
);
701 static bool test_smb2_open(struct torture_context
*tctx
,
702 struct smb2_tree
*tree
)
705 union smb_fileinfo finfo
;
706 const char *fname
= DNAME
"\\torture_ntcreatex.txt";
707 const char *dname
= DNAME
"\\torture_ntcreatex.dir";
709 struct smb2_handle h
= {{0}};
710 struct smb2_handle h1
= {{0}};
714 uint32_t create_disp
;
716 NTSTATUS correct_status
;
718 { NTCREATEX_DISP_SUPERSEDE
, true, NT_STATUS_OK
},
719 { NTCREATEX_DISP_SUPERSEDE
, false, NT_STATUS_OK
},
720 { NTCREATEX_DISP_OPEN
, true, NT_STATUS_OK
},
721 { NTCREATEX_DISP_OPEN
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
722 { NTCREATEX_DISP_CREATE
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
723 { NTCREATEX_DISP_CREATE
, false, NT_STATUS_OK
},
724 { NTCREATEX_DISP_OPEN_IF
, true, NT_STATUS_OK
},
725 { NTCREATEX_DISP_OPEN_IF
, false, NT_STATUS_OK
},
726 { NTCREATEX_DISP_OVERWRITE
, true, NT_STATUS_OK
},
727 { NTCREATEX_DISP_OVERWRITE
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
728 { NTCREATEX_DISP_OVERWRITE_IF
, true, NT_STATUS_OK
},
729 { NTCREATEX_DISP_OVERWRITE_IF
, false, NT_STATUS_OK
},
730 { 6, true, NT_STATUS_INVALID_PARAMETER
},
731 { 6, false, NT_STATUS_INVALID_PARAMETER
},
734 torture_comment(tctx
, "Checking SMB2 Open\n");
736 smb2_util_unlink(tree
, fname
);
737 smb2_util_rmdir(tree
, dname
);
739 status
= torture_smb2_testdir(tree
, DNAME
, &h
);
740 CHECK_STATUS(status
, NT_STATUS_OK
);
742 ZERO_STRUCT(io
.smb2
);
743 /* reasonable default parameters */
744 io
.generic
.level
= RAW_OPEN_SMB2
;
745 io
.smb2
.in
.create_flags
= NTCREATEX_FLAGS_EXTENDED
;
746 io
.smb2
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
747 io
.smb2
.in
.alloc_size
= 1024*1024;
748 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
749 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
750 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
751 io
.smb2
.in
.create_options
= 0;
752 io
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_ANONYMOUS
;
753 io
.smb2
.in
.security_flags
= 0;
754 io
.smb2
.in
.fname
= fname
;
756 /* test the create disposition */
757 for (i
=0; i
<ARRAY_SIZE(open_funcs
); i
++) {
758 if (open_funcs
[i
].with_file
) {
759 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
760 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
761 if (!NT_STATUS_IS_OK(status
)) {
762 torture_comment(tctx
,
763 "Failed to create file %s status %s %d\n",
764 fname
, nt_errstr(status
), i
);
769 smb2_util_close(tree
, io
.smb2
.out
.file
.handle
);
771 io
.smb2
.in
.create_disposition
= open_funcs
[i
].create_disp
;
772 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
773 if (!NT_STATUS_EQUAL(status
, open_funcs
[i
].correct_status
)) {
774 torture_comment(tctx
,
775 "(%s) incorrect status %s should be %s (i=%d "
776 "with_file=%d open_disp=%d)\n",
777 __location__
, nt_errstr(status
),
778 nt_errstr(open_funcs
[i
].correct_status
),
779 i
, (int)open_funcs
[i
].with_file
,
780 (int)open_funcs
[i
].create_disp
);
785 if (NT_STATUS_IS_OK(status
) || open_funcs
[i
].with_file
) {
786 smb2_util_close(tree
, io
.smb2
.out
.file
.handle
);
787 smb2_util_unlink(tree
, fname
);
791 /* basic field testing */
792 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
794 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
795 CHECK_STATUS(status
, NT_STATUS_OK
);
796 h1
= io
.smb2
.out
.file
.handle
;
798 CHECK_VAL(io
.smb2
.out
.oplock_level
, 0);
799 CHECK_VAL(io
.smb2
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
800 CHECK_NTTIME(io
.smb2
.out
.create_time
, create_time
);
801 CHECK_NTTIME(io
.smb2
.out
.access_time
, access_time
);
802 CHECK_NTTIME(io
.smb2
.out
.write_time
, write_time
);
803 CHECK_NTTIME(io
.smb2
.out
.change_time
, change_time
);
804 CHECK_ALL_INFO(io
.smb2
.out
.file_attr
, attrib
);
805 CHECK_ALL_INFO(io
.smb2
.out
.alloc_size
, alloc_size
);
806 CHECK_ALL_INFO(io
.smb2
.out
.size
, size
);
808 /* check fields when the file already existed */
809 smb2_util_close(tree
, h1
);
810 smb2_util_unlink(tree
, fname
);
812 status
= smb2_create_complex_file(tctx
, tree
, fname
, &h1
);
813 CHECK_STATUS(status
, NT_STATUS_OK
);
815 smb2_util_close(tree
, h1
);
817 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
818 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
819 CHECK_STATUS(status
, NT_STATUS_OK
);
820 h1
= io
.smb2
.out
.file
.handle
;
822 CHECK_VAL(io
.smb2
.out
.oplock_level
, 0);
823 CHECK_VAL(io
.smb2
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
824 CHECK_NTTIME(io
.smb2
.out
.create_time
, create_time
);
825 CHECK_NTTIME(io
.smb2
.out
.access_time
, access_time
);
826 CHECK_NTTIME(io
.smb2
.out
.write_time
, write_time
);
827 CHECK_NTTIME(io
.smb2
.out
.change_time
, change_time
);
828 CHECK_ALL_INFO(io
.smb2
.out
.file_attr
, attrib
);
829 CHECK_ALL_INFO(io
.smb2
.out
.alloc_size
, alloc_size
);
830 CHECK_ALL_INFO(io
.smb2
.out
.size
, size
);
831 smb2_util_close(tree
, h1
);
832 smb2_util_unlink(tree
, fname
);
834 /* create a directory */
835 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
836 io
.smb2
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
837 io
.smb2
.in
.alloc_size
= 0;
838 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_DIRECTORY
;
839 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
840 io
.smb2
.in
.create_options
= 0;
841 io
.smb2
.in
.fname
= dname
;
844 smb2_util_rmdir(tree
, fname
);
845 smb2_util_unlink(tree
, fname
);
847 io
.smb2
.in
.desired_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
848 io
.smb2
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
849 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
850 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
851 NTCREATEX_SHARE_ACCESS_WRITE
;
852 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
853 CHECK_STATUS(status
, NT_STATUS_OK
);
854 h1
= io
.smb2
.out
.file
.handle
;
856 CHECK_VAL(io
.smb2
.out
.oplock_level
, 0);
857 CHECK_VAL(io
.smb2
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
858 CHECK_NTTIME(io
.smb2
.out
.create_time
, create_time
);
859 CHECK_NTTIME(io
.smb2
.out
.access_time
, access_time
);
860 CHECK_NTTIME(io
.smb2
.out
.write_time
, write_time
);
861 CHECK_NTTIME(io
.smb2
.out
.change_time
, change_time
);
862 CHECK_ALL_INFO(io
.smb2
.out
.file_attr
, attrib
);
863 CHECK_VAL(io
.smb2
.out
.file_attr
& ~FILE_ATTRIBUTE_NONINDEXED
,
864 FILE_ATTRIBUTE_DIRECTORY
);
865 CHECK_ALL_INFO(io
.smb2
.out
.alloc_size
, alloc_size
);
866 CHECK_ALL_INFO(io
.smb2
.out
.size
, size
);
867 CHECK_VAL(io
.smb2
.out
.size
, 0);
868 CHECK_VAL(io
.smb2
.out
.alloc_size
, 0);
869 smb2_util_unlink(tree
, fname
);
872 smb2_util_close(tree
, h1
);
873 smb2_util_unlink(tree
, fname
);
874 smb2_deltree(tree
, DNAME
);
879 test with an already opened and byte range locked file
882 static bool test_smb2_open_brlocked(struct torture_context
*tctx
,
883 struct smb2_tree
*tree
)
885 union smb_open io
, io1
;
887 struct smb2_lock_element lock
[1];
888 const char *fname
= DNAME
"\\torture_ntcreatex.txt";
891 struct smb2_handle h
;
894 torture_comment(tctx
,
895 "Testing SMB2 open with a byte range locked file\n");
897 smb2_util_unlink(tree
, fname
);
899 status
= torture_smb2_testdir(tree
, DNAME
, &h
);
900 CHECK_STATUS(status
, NT_STATUS_OK
);
902 ZERO_STRUCT(io
.smb2
);
903 io
.generic
.level
= RAW_OPEN_SMB2
;
904 io
.smb2
.in
.create_flags
= NTCREATEX_FLAGS_EXTENDED
;
905 io
.smb2
.in
.desired_access
= 0x2019f;
906 io
.smb2
.in
.alloc_size
= 0;
907 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
908 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
909 NTCREATEX_SHARE_ACCESS_WRITE
;
910 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
911 io
.smb2
.in
.create_options
= NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
;
912 io
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
913 io
.smb2
.in
.security_flags
= SMB2_SECURITY_DYNAMIC_TRACKING
;
914 io
.smb2
.in
.fname
= fname
;
916 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
917 CHECK_STATUS(status
, NT_STATUS_OK
);
919 status
= smb2_util_write(tree
, io
.smb2
.out
.file
.handle
, &b
, 0, 1);
920 CHECK_STATUS(status
, NT_STATUS_OK
);
922 ZERO_STRUCT(io2
.smb2
);
923 io2
.smb2
.level
= RAW_LOCK_SMB2
;
924 io2
.smb2
.in
.file
.handle
= io
.smb2
.out
.file
.handle
;
925 io2
.smb2
.in
.lock_count
= 1;
930 lock
[0].flags
= SMB2_LOCK_FLAG_EXCLUSIVE
|
931 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY
;
932 io2
.smb2
.in
.locks
= &lock
[0];
933 status
= smb2_lock(tree
, &(io2
.smb2
));
934 CHECK_STATUS(status
, NT_STATUS_OK
);
936 ZERO_STRUCT(io1
.smb2
);
937 io1
.smb2
.in
.create_flags
= NTCREATEX_FLAGS_EXTENDED
;
938 io1
.smb2
.in
.desired_access
= 0x20196;
939 io1
.smb2
.in
.alloc_size
= 0;
940 io1
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
941 io1
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
942 NTCREATEX_SHARE_ACCESS_WRITE
;
943 io1
.smb2
.in
.create_disposition
= NTCREATEX_DISP_OVERWRITE_IF
;
944 io1
.smb2
.in
.create_options
= 0;
945 io1
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
946 io1
.smb2
.in
.security_flags
= SMB2_SECURITY_DYNAMIC_TRACKING
;
947 io1
.smb2
.in
.fname
= fname
;
949 status
= smb2_create(tree
, tctx
, &(io1
.smb2
));
950 CHECK_STATUS(status
, NT_STATUS_OK
);
952 smb2_util_close(tree
, io
.smb2
.out
.file
.handle
);
953 smb2_util_close(tree
, io1
.smb2
.out
.file
.handle
);
954 smb2_util_unlink(tree
, fname
);
955 smb2_deltree(tree
, DNAME
);
960 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
962 static bool test_smb2_open_multi(struct torture_context
*tctx
,
963 struct smb2_tree
*tree
)
965 const char *fname
= "test_oplock.dat";
969 struct smb2_tree
**trees
;
970 struct smb2_request
**requests
;
972 int i
, num_files
= 3;
974 int num_collision
= 0;
976 torture_comment(tctx
,
977 "Testing SMB2 Open with multiple connections\n");
978 trees
= talloc_array(tctx
, struct smb2_tree
*, num_files
);
979 requests
= talloc_array(tctx
, struct smb2_request
*, num_files
);
980 ios
= talloc_array(tctx
, union smb_open
, num_files
);
981 if ((tctx
->ev
== NULL
) || (trees
== NULL
) || (requests
== NULL
) ||
983 torture_comment(tctx
, ("talloc failed\n"));
988 tree
->session
->transport
->options
.request_timeout
= 60;
990 for (i
=0; i
<num_files
; i
++) {
991 if (!torture_smb2_connection(tctx
, &(trees
[i
]))) {
992 torture_comment(tctx
,
993 "Could not open %d'th connection\n", i
);
997 trees
[i
]->session
->transport
->options
.request_timeout
= 60;
1001 smb2_util_unlink(tree
, fname
);
1004 base ntcreatex parms
1006 ZERO_STRUCT(io
.smb2
);
1007 io
.generic
.level
= RAW_OPEN_SMB2
;
1008 io
.smb2
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
1009 io
.smb2
.in
.alloc_size
= 0;
1010 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
1011 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1012 NTCREATEX_SHARE_ACCESS_WRITE
|
1013 NTCREATEX_SHARE_ACCESS_DELETE
;
1014 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
1015 io
.smb2
.in
.create_options
= 0;
1016 io
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_ANONYMOUS
;
1017 io
.smb2
.in
.security_flags
= 0;
1018 io
.smb2
.in
.fname
= fname
;
1019 io
.smb2
.in
.create_flags
= 0;
1021 for (i
=0; i
<num_files
; i
++) {
1023 requests
[i
] = smb2_create_send(trees
[i
], &(ios
[i
].smb2
));
1024 if (requests
[i
] == NULL
) {
1025 torture_comment(tctx
,
1026 "could not send %d'th request\n", i
);
1032 torture_comment(tctx
, "waiting for replies\n");
1034 bool unreplied
= false;
1035 for (i
=0; i
<num_files
; i
++) {
1036 if (requests
[i
] == NULL
) {
1039 if (requests
[i
]->state
< SMB2_REQUEST_DONE
) {
1043 status
= smb2_create_recv(requests
[i
], tctx
,
1046 torture_comment(tctx
,
1047 "File %d returned status %s\n", i
,
1050 if (NT_STATUS_IS_OK(status
)) {
1054 if (NT_STATUS_EQUAL(status
,
1055 NT_STATUS_OBJECT_NAME_COLLISION
)) {
1065 if (tevent_loop_once(tctx
->ev
) != 0) {
1066 torture_comment(tctx
, "tevent_loop_once failed\n");
1072 if ((num_ok
!= 1) || (num_ok
+ num_collision
!= num_files
)) {
1076 smb2_deltree(tree
, fname
);
1082 test opening for delete on a read-only attribute file.
1085 static bool test_smb2_open_for_delete(struct torture_context
*tctx
,
1086 struct smb2_tree
*tree
)
1089 union smb_fileinfo finfo
;
1090 const char *fname
= DNAME
"\\torture_open_for_delete.txt";
1092 struct smb2_handle h
, h1
;
1095 torture_comment(tctx
,
1096 "Checking SMB2_OPEN for delete on a readonly file.\n");
1097 smb2_util_unlink(tree
, fname
);
1098 smb2_deltree(tree
, fname
);
1100 status
= torture_smb2_testdir(tree
, DNAME
, &h
);
1101 CHECK_STATUS(status
, NT_STATUS_OK
);
1103 /* reasonable default parameters */
1104 ZERO_STRUCT(io
.smb2
);
1105 io
.generic
.level
= RAW_OPEN_SMB2
;
1106 io
.smb2
.in
.create_flags
= NTCREATEX_FLAGS_EXTENDED
;
1107 io
.smb2
.in
.alloc_size
= 0;
1108 io
.smb2
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
1109 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_READONLY
;
1110 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
1111 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
1112 io
.smb2
.in
.create_options
= 0;
1113 io
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_ANONYMOUS
;
1114 io
.smb2
.in
.security_flags
= 0;
1115 io
.smb2
.in
.fname
= fname
;
1117 /* Create the readonly file. */
1119 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
1120 CHECK_STATUS(status
, NT_STATUS_OK
);
1121 h1
= io
.smb2
.out
.file
.handle
;
1123 CHECK_VAL(io
.smb2
.out
.oplock_level
, 0);
1124 io
.smb2
.in
.create_options
= 0;
1125 CHECK_VAL(io
.smb2
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
1126 CHECK_ALL_INFO(io
.smb2
.out
.file_attr
, attrib
);
1127 smb2_util_close(tree
, h1
);
1129 /* Now try and open for delete only - should succeed. */
1130 io
.smb2
.in
.desired_access
= SEC_STD_DELETE
;
1131 io
.smb2
.in
.file_attributes
= 0;
1132 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1133 NTCREATEX_SHARE_ACCESS_WRITE
|
1134 NTCREATEX_SHARE_ACCESS_DELETE
;
1135 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
1136 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
1137 CHECK_STATUS(status
, NT_STATUS_OK
);
1139 smb2_util_unlink(tree
, fname
);
1141 smb2_util_close(tree
, h1
);
1142 smb2_util_unlink(tree
, fname
);
1143 smb2_deltree(tree
, DNAME
);
1149 test SMB2 open with a leading slash on the path.
1150 Trying to create a directory with a leading slash
1151 should give NT_STATUS_INVALID_PARAMETER error
1153 static bool test_smb2_leading_slash(struct torture_context
*tctx
,
1154 struct smb2_tree
*tree
)
1157 const char *dnameslash
= "\\"DNAME
;
1161 torture_comment(tctx
,
1162 "Trying to create a directory with leading slash on path\n");
1163 smb2_deltree(tree
, dnameslash
);
1165 ZERO_STRUCT(io
.smb2
);
1166 io
.generic
.level
= RAW_OPEN_SMB2
;
1167 io
.smb2
.in
.oplock_level
= 0;
1168 io
.smb2
.in
.desired_access
= SEC_RIGHTS_DIR_ALL
;
1169 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_DIRECTORY
;
1170 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
1171 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1172 NTCREATEX_SHARE_ACCESS_WRITE
|
1173 NTCREATEX_SHARE_ACCESS_DELETE
;
1174 io
.smb2
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1175 io
.smb2
.in
.fname
= dnameslash
;
1177 status
= smb2_create(tree
, tree
, &(io
.smb2
));
1178 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
1180 smb2_deltree(tree
, dnameslash
);
1185 test SMB2 open with an invalid impersonation level.
1186 Should give NT_STATUS_BAD_IMPERSONATION_LEVEL error
1188 static bool test_smb2_impersonation_level(struct torture_context
*tctx
,
1189 struct smb2_tree
*tree
)
1192 const char *fname
= DNAME
"\\torture_invalid_impersonation_level.txt";
1194 struct smb2_handle h
;
1197 torture_comment(tctx
,
1198 "Testing SMB2 open with an invalid impersonation level.\n");
1200 smb2_util_unlink(tree
, fname
);
1201 smb2_util_rmdir(tree
, DNAME
);
1203 status
= torture_smb2_testdir(tree
, DNAME
, &h
);
1204 CHECK_STATUS(status
, NT_STATUS_OK
);
1206 ZERO_STRUCT(io
.smb2
);
1207 io
.generic
.level
= RAW_OPEN_SMB2
;
1208 io
.smb2
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
1209 io
.smb2
.in
.alloc_size
= 0;
1210 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
1211 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1212 NTCREATEX_SHARE_ACCESS_WRITE
|
1213 NTCREATEX_SHARE_ACCESS_DELETE
;
1214 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
1215 io
.smb2
.in
.create_options
= 0;
1216 io
.smb2
.in
.impersonation_level
= 0x12345678;
1217 io
.smb2
.in
.security_flags
= 0;
1218 io
.smb2
.in
.fname
= fname
;
1219 io
.smb2
.in
.create_flags
= 0;
1221 status
= smb2_create(tree
, tree
, &(io
.smb2
));
1222 CHECK_STATUS(status
, NT_STATUS_BAD_IMPERSONATION_LEVEL
);
1224 smb2_util_close(tree
, h
);
1225 smb2_util_unlink(tree
, fname
);
1226 smb2_deltree(tree
, DNAME
);
1230 static bool test_create_acl_file(struct torture_context
*tctx
,
1231 struct smb2_tree
*tree
)
1233 torture_comment(tctx
, "Testing nttrans create with sec_desc on files\n");
1235 return test_create_acl_ext(tctx
, tree
, false);
1238 static bool test_create_acl_dir(struct torture_context
*tctx
,
1239 struct smb2_tree
*tree
)
1241 torture_comment(tctx
, "Testing nttrans create with sec_desc on directories\n");
1243 return test_create_acl_ext(tctx
, tree
, true);
1246 #define CHECK_ACCESS_FLAGS(_fh, flags) do { \
1247 union smb_fileinfo _q; \
1248 _q.access_information.level = RAW_FILEINFO_ACCESS_INFORMATION; \
1249 _q.access_information.in.file.handle = (_fh); \
1250 status = smb2_getinfo_file(tree, tctx, &_q); \
1251 CHECK_STATUS(status, NT_STATUS_OK); \
1252 if (_q.access_information.out.access_flags != (flags)) { \
1253 torture_result(tctx, TORTURE_FAIL, "(%s) Incorrect access_flags 0x%08x - should be 0x%08x\n", \
1254 __location__, _q.access_information.out.access_flags, (flags)); \
1261 * Test creating a file with a NULL DACL.
1263 static bool test_create_null_dacl(struct torture_context
*tctx
,
1264 struct smb2_tree
*tree
)
1267 struct smb2_create io
;
1268 const char *fname
= "nulldacl.txt";
1270 struct smb2_handle handle
;
1271 union smb_fileinfo q
;
1272 union smb_setfileinfo s
;
1273 struct security_descriptor
*sd
= security_descriptor_initialise(tctx
);
1274 struct security_acl dacl
;
1276 torture_comment(tctx
, "TESTING SEC_DESC WITH A NULL DACL\n");
1278 smb2_util_unlink(tree
, fname
);
1281 io
.level
= RAW_OPEN_SMB2
;
1282 io
.in
.create_flags
= 0;
1283 io
.in
.desired_access
= SEC_STD_READ_CONTROL
| SEC_STD_WRITE_DAC
1284 | SEC_STD_WRITE_OWNER
;
1285 io
.in
.create_options
= 0;
1286 io
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
1287 io
.in
.share_access
=
1288 NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1289 io
.in
.alloc_size
= 0;
1290 io
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
1291 io
.in
.impersonation_level
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1292 io
.in
.security_flags
= 0;
1293 io
.in
.fname
= fname
;
1294 io
.in
.sec_desc
= sd
;
1295 /* XXX create_options ? */
1296 io
.in
.create_options
= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY
|
1297 NTCREATEX_OPTIONS_ASYNC_ALERT
|
1298 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
|
1301 torture_comment(tctx
, "creating a file with a empty sd\n");
1302 status
= smb2_create(tree
, tctx
, &io
);
1303 CHECK_STATUS(status
, NT_STATUS_OK
);
1304 handle
= io
.out
.file
.handle
;
1306 torture_comment(tctx
, "get the original sd\n");
1307 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
1308 q
.query_secdesc
.in
.file
.handle
= handle
;
1309 q
.query_secdesc
.in
.secinfo_flags
=
1313 status
= smb2_getinfo_file(tree
, tctx
, &q
);
1314 CHECK_STATUS(status
, NT_STATUS_OK
);
1317 * Testing the created DACL,
1318 * the server should add the inherited DACL
1319 * when SEC_DESC_DACL_PRESENT isn't specified
1321 if (!(q
.query_secdesc
.out
.sd
->type
& SEC_DESC_DACL_PRESENT
)) {
1323 torture_fail_goto(tctx
, done
, "DACL_PRESENT flag not set by the server!\n");
1325 if (q
.query_secdesc
.out
.sd
->dacl
== NULL
) {
1327 torture_fail_goto(tctx
, done
, "no DACL has been created on the server!\n");
1330 torture_comment(tctx
, "set NULL DACL\n");
1331 sd
->type
|= SEC_DESC_DACL_PRESENT
;
1333 s
.set_secdesc
.level
= RAW_SFILEINFO_SEC_DESC
;
1334 s
.set_secdesc
.in
.file
.handle
= handle
;
1335 s
.set_secdesc
.in
.secinfo_flags
= SECINFO_DACL
;
1336 s
.set_secdesc
.in
.sd
= sd
;
1337 status
= smb2_setinfo_file(tree
, &s
);
1338 CHECK_STATUS(status
, NT_STATUS_OK
);
1340 torture_comment(tctx
, "get the sd\n");
1341 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
1342 q
.query_secdesc
.in
.file
.handle
= handle
;
1343 q
.query_secdesc
.in
.secinfo_flags
=
1347 status
= smb2_getinfo_file(tree
, tctx
, &q
);
1348 CHECK_STATUS(status
, NT_STATUS_OK
);
1350 /* Testing the modified DACL */
1351 if (!(q
.query_secdesc
.out
.sd
->type
& SEC_DESC_DACL_PRESENT
)) {
1353 torture_fail_goto(tctx
, done
, "DACL_PRESENT flag not set by the server!\n");
1355 if (q
.query_secdesc
.out
.sd
->dacl
!= NULL
) {
1357 torture_fail_goto(tctx
, done
, "DACL has been created on the server!\n");
1360 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
1362 torture_comment(tctx
, "try open for read control\n");
1363 io
.in
.desired_access
= SEC_STD_READ_CONTROL
;
1364 status
= smb2_create(tree
, tctx
, &io
);
1365 CHECK_STATUS(status
, NT_STATUS_OK
);
1366 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1367 SEC_STD_READ_CONTROL
);
1368 smb2_util_close(tree
, io
.out
.file
.handle
);
1370 torture_comment(tctx
, "try open for write\n");
1371 io
.in
.desired_access
= SEC_FILE_WRITE_DATA
;
1372 status
= smb2_create(tree
, tctx
, &io
);
1373 CHECK_STATUS(status
, NT_STATUS_OK
);
1374 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1375 SEC_FILE_WRITE_DATA
);
1376 smb2_util_close(tree
, io
.out
.file
.handle
);
1378 torture_comment(tctx
, "try open for read\n");
1379 io
.in
.desired_access
= SEC_FILE_READ_DATA
;
1380 status
= smb2_create(tree
, tctx
, &io
);
1381 CHECK_STATUS(status
, NT_STATUS_OK
);
1382 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1383 SEC_FILE_READ_DATA
);
1384 smb2_util_close(tree
, io
.out
.file
.handle
);
1386 torture_comment(tctx
, "try open for generic write\n");
1387 io
.in
.desired_access
= SEC_GENERIC_WRITE
;
1388 status
= smb2_create(tree
, tctx
, &io
);
1389 CHECK_STATUS(status
, NT_STATUS_OK
);
1390 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1391 SEC_RIGHTS_FILE_WRITE
);
1392 smb2_util_close(tree
, io
.out
.file
.handle
);
1394 torture_comment(tctx
, "try open for generic read\n");
1395 io
.in
.desired_access
= SEC_GENERIC_READ
;
1396 status
= smb2_create(tree
, tctx
, &io
);
1397 CHECK_STATUS(status
, NT_STATUS_OK
);
1398 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1399 SEC_RIGHTS_FILE_READ
);
1400 smb2_util_close(tree
, io
.out
.file
.handle
);
1402 torture_comment(tctx
, "set DACL with 0 aces\n");
1404 dacl
.revision
= SECURITY_ACL_REVISION_NT4
;
1408 s
.set_secdesc
.level
= RAW_SFILEINFO_SEC_DESC
;
1409 s
.set_secdesc
.in
.file
.handle
= handle
;
1410 s
.set_secdesc
.in
.secinfo_flags
= SECINFO_DACL
;
1411 s
.set_secdesc
.in
.sd
= sd
;
1412 status
= smb2_setinfo_file(tree
, &s
);
1413 CHECK_STATUS(status
, NT_STATUS_OK
);
1415 torture_comment(tctx
, "get the sd\n");
1416 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
1417 q
.query_secdesc
.in
.file
.handle
= handle
;
1418 q
.query_secdesc
.in
.secinfo_flags
=
1422 status
= smb2_getinfo_file(tree
, tctx
, &q
);
1423 CHECK_STATUS(status
, NT_STATUS_OK
);
1425 /* Testing the modified DACL */
1426 if (!(q
.query_secdesc
.out
.sd
->type
& SEC_DESC_DACL_PRESENT
)) {
1428 torture_fail_goto(tctx
, done
, "DACL_PRESENT flag not set by the server!\n");
1430 if (q
.query_secdesc
.out
.sd
->dacl
== NULL
) {
1432 torture_fail_goto(tctx
, done
, "no DACL has been created on the server!\n");
1434 if (q
.query_secdesc
.out
.sd
->dacl
->num_aces
!= 0) {
1435 torture_result(tctx
, TORTURE_FAIL
, "DACL has %u aces!\n",
1436 q
.query_secdesc
.out
.sd
->dacl
->num_aces
);
1441 torture_comment(tctx
, "try open for read control\n");
1442 io
.in
.desired_access
= SEC_STD_READ_CONTROL
;
1443 status
= smb2_create(tree
, tctx
, &io
);
1444 CHECK_STATUS(status
, NT_STATUS_OK
);
1445 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1446 SEC_STD_READ_CONTROL
);
1447 smb2_util_close(tree
, io
.out
.file
.handle
);
1449 torture_comment(tctx
, "try open for write => access_denied\n");
1450 io
.in
.desired_access
= SEC_FILE_WRITE_DATA
;
1451 status
= smb2_create(tree
, tctx
, &io
);
1452 if (torture_setting_bool(tctx
, "hide_on_access_denied", false)) {
1453 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1455 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
1458 torture_comment(tctx
, "try open for read => access_denied\n");
1459 io
.in
.desired_access
= SEC_FILE_READ_DATA
;
1460 status
= smb2_create(tree
, tctx
, &io
);
1461 if (torture_setting_bool(tctx
, "hide_on_access_denied", false)) {
1462 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1464 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
1467 torture_comment(tctx
, "try open for generic write => access_denied\n");
1468 io
.in
.desired_access
= SEC_GENERIC_WRITE
;
1469 status
= smb2_create(tree
, tctx
, &io
);
1470 if (torture_setting_bool(tctx
, "hide_on_access_denied", false)) {
1471 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1473 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
1476 torture_comment(tctx
, "try open for generic read => access_denied\n");
1477 io
.in
.desired_access
= SEC_GENERIC_READ
;
1478 status
= smb2_create(tree
, tctx
, &io
);
1479 if (torture_setting_bool(tctx
, "hide_on_access_denied", false)) {
1480 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1482 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
1485 torture_comment(tctx
, "set empty sd\n");
1486 sd
->type
&= ~SEC_DESC_DACL_PRESENT
;
1489 s
.set_secdesc
.level
= RAW_SFILEINFO_SEC_DESC
;
1490 s
.set_secdesc
.in
.file
.handle
= handle
;
1491 s
.set_secdesc
.in
.secinfo_flags
= SECINFO_DACL
;
1492 s
.set_secdesc
.in
.sd
= sd
;
1493 status
= smb2_setinfo_file(tree
, &s
);
1494 CHECK_STATUS(status
, NT_STATUS_OK
);
1496 torture_comment(tctx
, "get the sd\n");
1497 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
1498 q
.query_secdesc
.in
.file
.handle
= handle
;
1499 q
.query_secdesc
.in
.secinfo_flags
=
1503 status
= smb2_getinfo_file(tree
, tctx
, &q
);
1504 CHECK_STATUS(status
, NT_STATUS_OK
);
1506 /* Testing the modified DACL */
1507 if (!(q
.query_secdesc
.out
.sd
->type
& SEC_DESC_DACL_PRESENT
)) {
1509 torture_fail_goto(tctx
, done
, "DACL_PRESENT flag not set by the server!\n");
1511 if (q
.query_secdesc
.out
.sd
->dacl
!= NULL
) {
1513 torture_fail_goto(tctx
, done
, "DACL has been created on the server!\n");
1516 smb2_util_close(tree
, handle
);
1517 smb2_util_unlink(tree
, fname
);
1519 smb2_logoff(tree
->session
);
1524 test SMB2 mkdir with OPEN_IF on the same name twice.
1525 Must use 2 connections to hit the race.
1528 static bool test_mkdir_dup(struct torture_context
*tctx
,
1529 struct smb2_tree
*tree
)
1531 const char *fname
= "mkdir_dup";
1535 struct smb2_tree
**trees
;
1536 struct smb2_request
**requests
;
1537 union smb_open
*ios
;
1538 int i
, num_files
= 2;
1540 int num_created
= 0;
1541 int num_existed
= 0;
1543 torture_comment(tctx
,
1544 "Testing SMB2 Create Directory with multiple connections\n");
1545 trees
= talloc_array(tctx
, struct smb2_tree
*, num_files
);
1546 requests
= talloc_array(tctx
, struct smb2_request
*, num_files
);
1547 ios
= talloc_array(tctx
, union smb_open
, num_files
);
1548 if ((tctx
->ev
== NULL
) || (trees
== NULL
) || (requests
== NULL
) ||
1550 torture_fail(tctx
, ("talloc failed\n"));
1555 tree
->session
->transport
->options
.request_timeout
= 60;
1557 for (i
=0; i
<num_files
; i
++) {
1558 if (!torture_smb2_connection(tctx
, &(trees
[i
]))) {
1560 talloc_asprintf(tctx
,
1561 "Could not open %d'th connection\n", i
));
1565 trees
[i
]->session
->transport
->options
.request_timeout
= 60;
1569 smb2_util_unlink(tree
, fname
);
1570 smb2_util_rmdir(tree
, fname
);
1573 base ntcreatex parms
1575 ZERO_STRUCT(io
.smb2
);
1576 io
.generic
.level
= RAW_OPEN_SMB2
;
1577 io
.smb2
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
1578 io
.smb2
.in
.alloc_size
= 0;
1579 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
1580 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1581 NTCREATEX_SHARE_ACCESS_WRITE
|
1582 NTCREATEX_SHARE_ACCESS_DELETE
;
1583 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
1584 io
.smb2
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1585 io
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_ANONYMOUS
;
1586 io
.smb2
.in
.security_flags
= 0;
1587 io
.smb2
.in
.fname
= fname
;
1588 io
.smb2
.in
.create_flags
= 0;
1590 for (i
=0; i
<num_files
; i
++) {
1592 requests
[i
] = smb2_create_send(trees
[i
], &(ios
[i
].smb2
));
1593 if (requests
[i
] == NULL
) {
1595 talloc_asprintf(tctx
,
1596 "could not send %d'th request\n", i
));
1602 torture_comment(tctx
, "waiting for replies\n");
1604 bool unreplied
= false;
1605 for (i
=0; i
<num_files
; i
++) {
1606 if (requests
[i
] == NULL
) {
1609 if (requests
[i
]->state
< SMB2_REQUEST_DONE
) {
1613 status
= smb2_create_recv(requests
[i
], tctx
,
1616 if (NT_STATUS_IS_OK(status
)) {
1619 if (ios
[i
].smb2
.out
.create_action
==
1620 NTCREATEX_ACTION_CREATED
) {
1623 if (ios
[i
].smb2
.out
.create_action
==
1624 NTCREATEX_ACTION_EXISTED
) {
1629 talloc_asprintf(tctx
,
1630 "File %d returned status %s\n", i
,
1631 nt_errstr(status
)));
1641 if (tevent_loop_once(tctx
->ev
) != 0) {
1642 torture_fail(tctx
, "tevent_loop_once failed\n");
1650 talloc_asprintf(tctx
,
1651 "num_ok == %d\n", num_ok
));
1654 if (num_created
!= 1) {
1656 talloc_asprintf(tctx
,
1657 "num_created == %d\n", num_created
));
1660 if (num_existed
!= 1) {
1662 talloc_asprintf(tctx
,
1663 "num_existed == %d\n", num_existed
));
1667 smb2_deltree(tree
, fname
);
1673 test directory creation with an initial allocation size > 0
1675 static bool test_dir_alloc_size(struct torture_context
*tctx
,
1676 struct smb2_tree
*tree
)
1679 const char *dname
= DNAME
"\\torture_alloc_size.dir";
1681 struct smb2_create c
;
1682 struct smb2_handle h1
= {{0}}, h2
;
1684 torture_comment(tctx
, "Checking initial allocation size on directories\n");
1686 smb2_deltree(tree
, dname
);
1688 status
= torture_smb2_testdir(tree
, DNAME
, &h1
);
1689 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
, "torture_smb2_testdir failed");
1692 c
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
1693 c
.in
.desired_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
1694 c
.in
.file_attributes
= FILE_ATTRIBUTE_DIRECTORY
;
1695 c
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
1696 c
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1699 * An insanely large value so we can check the value is
1700 * ignored: Samba either returns 0 (current behaviour), or,
1701 * once vfswrap_get_alloc_size() is fixed to allow retrieving
1702 * the allocated size for directories, returns
1703 * smb_roundup(..., stat.st_size) which would be 1 MB by
1706 * Windows returns 0 for emtpy directories, once directories
1707 * have a few entries it starts replying with values > 0.
1709 c
.in
.alloc_size
= 1024*1024*1024;
1711 status
= smb2_create(tree
, tctx
, &c
);
1712 h2
= c
.out
.file
.handle
;
1713 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1714 "dir create with initial alloc size failed");
1716 smb2_util_close(tree
, h2
);
1718 torture_comment(tctx
, "Got directory alloc size: %ju\n", (uintmax_t)c
.out
.alloc_size
);
1721 * See above for the rational for this test
1723 if (c
.out
.alloc_size
> 1024*1024) {
1724 torture_fail_goto(tctx
, done
, talloc_asprintf(tctx
, "bad alloc size: %ju",
1725 (uintmax_t)c
.out
.alloc_size
));
1729 if (!smb2_util_handle_empty(h1
)) {
1730 smb2_util_close(tree
, h1
);
1732 smb2_deltree(tree
, DNAME
);
1737 basic testing of SMB2 read
1739 struct torture_suite
*torture_smb2_create_init(TALLOC_CTX
*ctx
)
1741 struct torture_suite
*suite
= torture_suite_create(ctx
, "create");
1743 torture_suite_add_1smb2_test(suite
, "gentest", test_create_gentest
);
1744 torture_suite_add_1smb2_test(suite
, "blob", test_create_blob
);
1745 torture_suite_add_1smb2_test(suite
, "open", test_smb2_open
);
1746 torture_suite_add_1smb2_test(suite
, "brlocked", test_smb2_open_brlocked
);
1747 torture_suite_add_1smb2_test(suite
, "multi", test_smb2_open_multi
);
1748 torture_suite_add_1smb2_test(suite
, "delete", test_smb2_open_for_delete
);
1749 torture_suite_add_1smb2_test(suite
, "leading-slash", test_smb2_leading_slash
);
1750 torture_suite_add_1smb2_test(suite
, "impersonation", test_smb2_impersonation_level
);
1751 torture_suite_add_1smb2_test(suite
, "aclfile", test_create_acl_file
);
1752 torture_suite_add_1smb2_test(suite
, "acldir", test_create_acl_dir
);
1753 torture_suite_add_1smb2_test(suite
, "nulldacl", test_create_null_dacl
);
1754 torture_suite_add_1smb2_test(suite
, "mkdir-dup", test_mkdir_dup
);
1755 torture_suite_add_1smb2_test(suite
, "dir-alloc-size", test_dir_alloc_size
);
1757 suite
->description
= talloc_strdup(suite
, "SMB2-CREATE tests");