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; \
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 io
.in
.alloc_size
= 4096;
399 status
= smb2_create(tree
, tctx
, &io
);
400 CHECK_STATUS(status
, NT_STATUS_OK
);
401 CHECK_EQUAL(io
.out
.alloc_size
, io
.in
.alloc_size
);
403 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
404 CHECK_STATUS(status
, NT_STATUS_OK
);
406 torture_comment(tctx
, "Testing durable open\n");
407 io
.in
.durable_open
= true;
408 status
= smb2_create(tree
, tctx
, &io
);
409 CHECK_STATUS(status
, NT_STATUS_OK
);
411 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
412 CHECK_STATUS(status
, NT_STATUS_OK
);
414 torture_comment(tctx
, "Testing query maximal access\n");
415 io
.in
.query_maximal_access
= true;
416 status
= smb2_create(tree
, tctx
, &io
);
417 CHECK_STATUS(status
, NT_STATUS_OK
);
418 CHECK_EQUAL(io
.out
.maximal_access
, 0x001f01ff);
420 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
421 CHECK_STATUS(status
, NT_STATUS_OK
);
423 torture_comment(tctx
, "Testing timewarp\n");
424 io
.in
.timewarp
= 10000;
425 status
= smb2_create(tree
, tctx
, &io
);
426 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
429 torture_comment(tctx
, "Testing query_on_disk\n");
430 io
.in
.query_on_disk_id
= true;
431 status
= smb2_create(tree
, tctx
, &io
);
432 CHECK_STATUS(status
, NT_STATUS_OK
);
434 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
435 CHECK_STATUS(status
, NT_STATUS_OK
);
437 torture_comment(tctx
, "Testing unknown tag\n");
438 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
439 "FooO", data_blob(NULL
, 0));
440 CHECK_STATUS(status
, NT_STATUS_OK
);
442 status
= smb2_create(tree
, tctx
, &io
);
443 CHECK_STATUS(status
, NT_STATUS_OK
);
445 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
446 CHECK_STATUS(status
, NT_STATUS_OK
);
448 torture_comment(tctx
, "Testing bad tag length\n");
449 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
450 "xxx", data_blob(NULL
, 0));
451 CHECK_STATUS(status
, NT_STATUS_OK
);
453 status
= smb2_create(tree
, tctx
, &io
);
454 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
456 smb2_deltree(tree
, FNAME
);
461 #define FAIL_UNLESS(__cond) \
463 if (__cond) {} else { \
464 torture_result(tctx, TORTURE_FAIL, "%s) condition violated: %s\n", \
465 __location__, #__cond); \
466 ret = false; goto done; \
471 try creating with acls
473 static bool test_create_acl_ext(struct torture_context
*tctx
, struct smb2_tree
*tree
, bool test_dir
)
476 struct smb2_create io
;
478 struct security_ace ace
;
479 struct security_descriptor
*sd
;
480 struct dom_sid
*test_sid
;
481 union smb_fileinfo q
= {};
483 FILE_ATTRIBUTE_HIDDEN
|
484 FILE_ATTRIBUTE_SYSTEM
|
485 (test_dir
? FILE_ATTRIBUTE_DIRECTORY
: 0);
486 NTSTATUS (*delete_func
)(struct smb2_tree
*, const char *) =
487 test_dir
? smb2_util_rmdir
: smb2_util_unlink
;
489 smb2_deltree(tree
, FNAME
);
492 io
.in
.desired_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
493 io
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
494 io
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
496 NTCREATEX_SHARE_ACCESS_DELETE
|
497 NTCREATEX_SHARE_ACCESS_READ
|
498 NTCREATEX_SHARE_ACCESS_WRITE
;
499 io
.in
.create_options
= NTCREATEX_OPTIONS_ASYNC_ALERT
| 0x00200000 |
500 (test_dir
? NTCREATEX_OPTIONS_DIRECTORY
:
501 (NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
));
505 torture_comment(tctx
, "basic create\n");
507 status
= smb2_create(tree
, tctx
, &io
);
508 CHECK_STATUS(status
, NT_STATUS_OK
);
510 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
511 q
.query_secdesc
.in
.file
.handle
= io
.out
.file
.handle
;
512 q
.query_secdesc
.in
.secinfo_flags
=
516 status
= smb2_getinfo_file(tree
, tctx
, &q
);
517 CHECK_STATUS(status
, NT_STATUS_OK
);
518 sd
= q
.query_secdesc
.out
.sd
;
520 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
521 CHECK_STATUS(status
, NT_STATUS_OK
);
522 status
= delete_func(tree
, FNAME
);
523 CHECK_STATUS(status
, NT_STATUS_OK
);
525 torture_comment(tctx
, "adding a new ACE\n");
526 test_sid
= dom_sid_parse_talloc(tctx
, SID_NT_AUTHENTICATED_USERS
);
528 ace
.type
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
530 ace
.access_mask
= SEC_STD_ALL
;
531 ace
.trustee
= *test_sid
;
533 status
= security_descriptor_dacl_add(sd
, &ace
);
534 CHECK_STATUS(status
, NT_STATUS_OK
);
536 torture_comment(tctx
, "creating a file with an initial ACL\n");
539 status
= smb2_create(tree
, tctx
, &io
);
540 CHECK_STATUS(status
, NT_STATUS_OK
);
542 FAIL_UNLESS(smb2_util_verify_sd(tctx
, tree
, io
.out
.file
.handle
, sd
));
544 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
545 CHECK_STATUS(status
, NT_STATUS_OK
);
546 status
= delete_func(tree
, FNAME
);
547 CHECK_STATUS(status
, NT_STATUS_OK
);
549 torture_comment(tctx
, "creating with attributes\n");
551 io
.in
.sec_desc
= NULL
;
552 io
.in
.file_attributes
= attrib
;
553 status
= smb2_create(tree
, tctx
, &io
);
554 CHECK_STATUS(status
, NT_STATUS_OK
);
556 FAIL_UNLESS(smb2_util_verify_attrib(tctx
, tree
, io
.out
.file
.handle
, attrib
));
558 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
559 CHECK_STATUS(status
, NT_STATUS_OK
);
560 status
= delete_func(tree
, FNAME
);
561 CHECK_STATUS(status
, NT_STATUS_OK
);
563 torture_comment(tctx
, "creating with attributes and ACL\n");
566 io
.in
.file_attributes
= attrib
;
567 status
= smb2_create(tree
, tctx
, &io
);
568 CHECK_STATUS(status
, NT_STATUS_OK
);
570 FAIL_UNLESS(smb2_util_verify_sd(tctx
, tree
, io
.out
.file
.handle
, sd
));
571 FAIL_UNLESS(smb2_util_verify_attrib(tctx
, tree
, io
.out
.file
.handle
, attrib
));
573 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
574 CHECK_STATUS(status
, NT_STATUS_OK
);
575 status
= delete_func(tree
, FNAME
);
576 CHECK_STATUS(status
, NT_STATUS_OK
);
578 torture_comment(tctx
, "creating with attributes, ACL and owner\n");
579 sd
= security_descriptor_dacl_create(tctx
,
580 0, SID_WORLD
, SID_BUILTIN_USERS
,
582 SEC_ACE_TYPE_ACCESS_ALLOWED
,
583 SEC_RIGHTS_FILE_READ
| SEC_STD_ALL
,
588 io
.in
.file_attributes
= attrib
;
589 status
= smb2_create(tree
, tctx
, &io
);
590 CHECK_STATUS(status
, NT_STATUS_OK
);
592 FAIL_UNLESS(smb2_util_verify_sd(tctx
, tree
, io
.out
.file
.handle
, sd
));
593 FAIL_UNLESS(smb2_util_verify_attrib(tctx
, tree
, io
.out
.file
.handle
, attrib
));
596 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
597 CHECK_STATUS(status
, NT_STATUS_OK
);
598 status
= delete_func(tree
, FNAME
);
599 CHECK_STATUS(status
, NT_STATUS_OK
);
607 static bool test_smb2_open(struct torture_context
*tctx
,
608 struct smb2_tree
*tree
)
611 union smb_fileinfo finfo
;
612 const char *fname
= DNAME
"\\torture_ntcreatex.txt";
613 const char *dname
= DNAME
"\\torture_ntcreatex.dir";
615 struct smb2_handle h
, h1
;
619 uint32_t create_disp
;
621 NTSTATUS correct_status
;
623 { NTCREATEX_DISP_SUPERSEDE
, true, NT_STATUS_OK
},
624 { NTCREATEX_DISP_SUPERSEDE
, false, NT_STATUS_OK
},
625 { NTCREATEX_DISP_OPEN
, true, NT_STATUS_OK
},
626 { NTCREATEX_DISP_OPEN
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
627 { NTCREATEX_DISP_CREATE
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
628 { NTCREATEX_DISP_CREATE
, false, NT_STATUS_OK
},
629 { NTCREATEX_DISP_OPEN_IF
, true, NT_STATUS_OK
},
630 { NTCREATEX_DISP_OPEN_IF
, false, NT_STATUS_OK
},
631 { NTCREATEX_DISP_OVERWRITE
, true, NT_STATUS_OK
},
632 { NTCREATEX_DISP_OVERWRITE
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
633 { NTCREATEX_DISP_OVERWRITE_IF
, true, NT_STATUS_OK
},
634 { NTCREATEX_DISP_OVERWRITE_IF
, false, NT_STATUS_OK
},
635 { 6, true, NT_STATUS_INVALID_PARAMETER
},
636 { 6, false, NT_STATUS_INVALID_PARAMETER
},
639 torture_comment(tctx
, "Checking SMB2 Open\n");
641 smb2_util_unlink(tree
, fname
);
642 smb2_util_rmdir(tree
, dname
);
644 status
= torture_smb2_testdir(tree
, DNAME
, &h
);
645 CHECK_STATUS(status
, NT_STATUS_OK
);
647 ZERO_STRUCT(io
.smb2
);
648 /* reasonable default parameters */
649 io
.generic
.level
= RAW_OPEN_SMB2
;
650 io
.smb2
.in
.create_flags
= NTCREATEX_FLAGS_EXTENDED
;
651 io
.smb2
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
652 io
.smb2
.in
.alloc_size
= 1024*1024;
653 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
654 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
655 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
656 io
.smb2
.in
.create_options
= 0;
657 io
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_ANONYMOUS
;
658 io
.smb2
.in
.security_flags
= 0;
659 io
.smb2
.in
.fname
= fname
;
661 /* test the create disposition */
662 for (i
=0; i
<ARRAY_SIZE(open_funcs
); i
++) {
663 if (open_funcs
[i
].with_file
) {
664 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
665 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
666 if (!NT_STATUS_IS_OK(status
)) {
667 torture_comment(tctx
,
668 "Failed to create file %s status %s %d\n",
669 fname
, nt_errstr(status
), i
);
674 smb2_util_close(tree
, io
.smb2
.out
.file
.handle
);
676 io
.smb2
.in
.create_disposition
= open_funcs
[i
].create_disp
;
677 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
678 if (!NT_STATUS_EQUAL(status
, open_funcs
[i
].correct_status
)) {
679 torture_comment(tctx
,
680 "(%s) incorrect status %s should be %s (i=%d "
681 "with_file=%d open_disp=%d)\n",
682 __location__
, nt_errstr(status
),
683 nt_errstr(open_funcs
[i
].correct_status
),
684 i
, (int)open_funcs
[i
].with_file
,
685 (int)open_funcs
[i
].create_disp
);
690 if (NT_STATUS_IS_OK(status
) || open_funcs
[i
].with_file
) {
691 smb2_util_close(tree
, io
.smb2
.out
.file
.handle
);
692 smb2_util_unlink(tree
, fname
);
696 /* basic field testing */
697 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
699 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
700 CHECK_STATUS(status
, NT_STATUS_OK
);
701 h1
= io
.smb2
.out
.file
.handle
;
703 CHECK_VAL(io
.smb2
.out
.oplock_level
, 0);
704 CHECK_VAL(io
.smb2
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
705 CHECK_NTTIME(io
.smb2
.out
.create_time
, create_time
);
706 CHECK_NTTIME(io
.smb2
.out
.access_time
, access_time
);
707 CHECK_NTTIME(io
.smb2
.out
.write_time
, write_time
);
708 CHECK_NTTIME(io
.smb2
.out
.change_time
, change_time
);
709 CHECK_ALL_INFO(io
.smb2
.out
.file_attr
, attrib
);
710 CHECK_ALL_INFO(io
.smb2
.out
.alloc_size
, alloc_size
);
711 CHECK_ALL_INFO(io
.smb2
.out
.size
, size
);
713 /* check fields when the file already existed */
714 smb2_util_close(tree
, h1
);
715 smb2_util_unlink(tree
, fname
);
717 status
= smb2_create_complex_file(tree
, fname
, &h1
);
718 CHECK_STATUS(status
, NT_STATUS_OK
);
720 smb2_util_close(tree
, h1
);
722 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
723 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
724 CHECK_STATUS(status
, NT_STATUS_OK
);
725 h1
= io
.smb2
.out
.file
.handle
;
727 CHECK_VAL(io
.smb2
.out
.oplock_level
, 0);
728 CHECK_VAL(io
.smb2
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
729 CHECK_NTTIME(io
.smb2
.out
.create_time
, create_time
);
730 CHECK_NTTIME(io
.smb2
.out
.access_time
, access_time
);
731 CHECK_NTTIME(io
.smb2
.out
.write_time
, write_time
);
732 CHECK_NTTIME(io
.smb2
.out
.change_time
, change_time
);
733 CHECK_ALL_INFO(io
.smb2
.out
.file_attr
, attrib
);
734 CHECK_ALL_INFO(io
.smb2
.out
.alloc_size
, alloc_size
);
735 CHECK_ALL_INFO(io
.smb2
.out
.size
, size
);
736 smb2_util_close(tree
, h1
);
737 smb2_util_unlink(tree
, fname
);
739 /* create a directory */
740 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
741 io
.smb2
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
742 io
.smb2
.in
.alloc_size
= 0;
743 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_DIRECTORY
;
744 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
745 io
.smb2
.in
.create_options
= 0;
746 io
.smb2
.in
.fname
= dname
;
749 smb2_util_rmdir(tree
, fname
);
750 smb2_util_unlink(tree
, fname
);
752 io
.smb2
.in
.desired_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
753 io
.smb2
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
754 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
755 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
756 NTCREATEX_SHARE_ACCESS_WRITE
;
757 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
758 CHECK_STATUS(status
, NT_STATUS_OK
);
759 h1
= io
.smb2
.out
.file
.handle
;
761 CHECK_VAL(io
.smb2
.out
.oplock_level
, 0);
762 CHECK_VAL(io
.smb2
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
763 CHECK_NTTIME(io
.smb2
.out
.create_time
, create_time
);
764 CHECK_NTTIME(io
.smb2
.out
.access_time
, access_time
);
765 CHECK_NTTIME(io
.smb2
.out
.write_time
, write_time
);
766 CHECK_NTTIME(io
.smb2
.out
.change_time
, change_time
);
767 CHECK_ALL_INFO(io
.smb2
.out
.file_attr
, attrib
);
768 CHECK_VAL(io
.smb2
.out
.file_attr
& ~FILE_ATTRIBUTE_NONINDEXED
,
769 FILE_ATTRIBUTE_DIRECTORY
);
770 CHECK_ALL_INFO(io
.smb2
.out
.alloc_size
, alloc_size
);
771 CHECK_ALL_INFO(io
.smb2
.out
.size
, size
);
772 CHECK_VAL(io
.smb2
.out
.size
, 0);
773 CHECK_VAL(io
.smb2
.out
.alloc_size
, 0);
774 smb2_util_unlink(tree
, fname
);
777 smb2_util_close(tree
, h1
);
778 smb2_util_unlink(tree
, fname
);
779 smb2_deltree(tree
, DNAME
);
784 test with an already opened and byte range locked file
787 static bool test_smb2_open_brlocked(struct torture_context
*tctx
,
788 struct smb2_tree
*tree
)
790 union smb_open io
, io1
;
792 struct smb2_lock_element lock
[1];
793 const char *fname
= DNAME
"\\torture_ntcreatex.txt";
796 struct smb2_handle h
;
799 torture_comment(tctx
,
800 "Testing SMB2 open with a byte range locked file\n");
802 smb2_util_unlink(tree
, fname
);
804 status
= torture_smb2_testdir(tree
, DNAME
, &h
);
805 CHECK_STATUS(status
, NT_STATUS_OK
);
807 ZERO_STRUCT(io
.smb2
);
808 io
.generic
.level
= RAW_OPEN_SMB2
;
809 io
.smb2
.in
.create_flags
= NTCREATEX_FLAGS_EXTENDED
;
810 io
.smb2
.in
.desired_access
= 0x2019f;
811 io
.smb2
.in
.alloc_size
= 0;
812 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
813 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
814 NTCREATEX_SHARE_ACCESS_WRITE
;
815 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
816 io
.smb2
.in
.create_options
= NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
;
817 io
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
818 io
.smb2
.in
.security_flags
= SMB2_SECURITY_DYNAMIC_TRACKING
;
819 io
.smb2
.in
.fname
= fname
;
821 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
822 CHECK_STATUS(status
, NT_STATUS_OK
);
824 status
= smb2_util_write(tree
, io
.smb2
.out
.file
.handle
, &b
, 0, 1);
825 CHECK_STATUS(status
, NT_STATUS_OK
);
827 ZERO_STRUCT(io2
.smb2
);
828 io2
.smb2
.level
= RAW_LOCK_SMB2
;
829 io2
.smb2
.in
.file
.handle
= io
.smb2
.out
.file
.handle
;
830 io2
.smb2
.in
.lock_count
= 1;
835 lock
[0].flags
= SMB2_LOCK_FLAG_EXCLUSIVE
|
836 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY
;
837 io2
.smb2
.in
.locks
= &lock
[0];
838 status
= smb2_lock(tree
, &(io2
.smb2
));
839 CHECK_STATUS(status
, NT_STATUS_OK
);
841 ZERO_STRUCT(io1
.smb2
);
842 io1
.smb2
.in
.create_flags
= NTCREATEX_FLAGS_EXTENDED
;
843 io1
.smb2
.in
.desired_access
= 0x20196;
844 io1
.smb2
.in
.alloc_size
= 0;
845 io1
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
846 io1
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
847 NTCREATEX_SHARE_ACCESS_WRITE
;
848 io1
.smb2
.in
.create_disposition
= NTCREATEX_DISP_OVERWRITE_IF
;
849 io1
.smb2
.in
.create_options
= 0;
850 io1
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
851 io1
.smb2
.in
.security_flags
= SMB2_SECURITY_DYNAMIC_TRACKING
;
852 io1
.smb2
.in
.fname
= fname
;
854 status
= smb2_create(tree
, tctx
, &(io1
.smb2
));
855 CHECK_STATUS(status
, NT_STATUS_OK
);
857 smb2_util_close(tree
, io
.smb2
.out
.file
.handle
);
858 smb2_util_close(tree
, io1
.smb2
.out
.file
.handle
);
859 smb2_util_unlink(tree
, fname
);
860 smb2_deltree(tree
, DNAME
);
865 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
867 static bool test_smb2_open_multi(struct torture_context
*tctx
,
868 struct smb2_tree
*tree
)
870 const char *fname
= "test_oplock.dat";
874 struct smb2_tree
**trees
;
875 struct smb2_request
**requests
;
877 int i
, num_files
= 3;
879 int num_collision
= 0;
881 torture_comment(tctx
,
882 "Testing SMB2 Open with multiple connections\n");
883 trees
= talloc_array(tctx
, struct smb2_tree
*, num_files
);
884 requests
= talloc_array(tctx
, struct smb2_request
*, num_files
);
885 ios
= talloc_array(tctx
, union smb_open
, num_files
);
886 if ((tctx
->ev
== NULL
) || (trees
== NULL
) || (requests
== NULL
) ||
888 torture_comment(tctx
, ("talloc failed\n"));
893 tree
->session
->transport
->options
.request_timeout
= 60;
895 for (i
=0; i
<num_files
; i
++) {
896 if (!torture_smb2_connection(tctx
, &(trees
[i
]))) {
897 torture_comment(tctx
,
898 "Could not open %d'th connection\n", i
);
902 trees
[i
]->session
->transport
->options
.request_timeout
= 60;
906 smb2_util_unlink(tree
, fname
);
911 ZERO_STRUCT(io
.smb2
);
912 io
.generic
.level
= RAW_OPEN_SMB2
;
913 io
.smb2
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
914 io
.smb2
.in
.alloc_size
= 0;
915 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
916 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
917 NTCREATEX_SHARE_ACCESS_WRITE
|
918 NTCREATEX_SHARE_ACCESS_DELETE
;
919 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
920 io
.smb2
.in
.create_options
= 0;
921 io
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_ANONYMOUS
;
922 io
.smb2
.in
.security_flags
= 0;
923 io
.smb2
.in
.fname
= fname
;
924 io
.smb2
.in
.create_flags
= 0;
926 for (i
=0; i
<num_files
; i
++) {
928 requests
[i
] = smb2_create_send(trees
[i
], &(ios
[i
].smb2
));
929 if (requests
[i
] == NULL
) {
930 torture_comment(tctx
,
931 "could not send %d'th request\n", i
);
937 torture_comment(tctx
, "waiting for replies\n");
939 bool unreplied
= false;
940 for (i
=0; i
<num_files
; i
++) {
941 if (requests
[i
] == NULL
) {
944 if (requests
[i
]->state
< SMB2_REQUEST_DONE
) {
948 status
= smb2_create_recv(requests
[i
], tctx
,
951 torture_comment(tctx
,
952 "File %d returned status %s\n", i
,
955 if (NT_STATUS_IS_OK(status
)) {
959 if (NT_STATUS_EQUAL(status
,
960 NT_STATUS_OBJECT_NAME_COLLISION
)) {
970 if (tevent_loop_once(tctx
->ev
) != 0) {
971 torture_comment(tctx
, "tevent_loop_once failed\n");
977 if ((num_ok
!= 1) || (num_ok
+ num_collision
!= num_files
)) {
981 smb2_deltree(tree
, fname
);
987 test opening for delete on a read-only attribute file.
990 static bool test_smb2_open_for_delete(struct torture_context
*tctx
,
991 struct smb2_tree
*tree
)
994 union smb_fileinfo finfo
;
995 const char *fname
= DNAME
"\\torture_open_for_delete.txt";
997 struct smb2_handle h
, h1
;
1000 torture_comment(tctx
,
1001 "Checking SMB2_OPEN for delete on a readonly file.\n");
1002 smb2_util_unlink(tree
, fname
);
1003 smb2_deltree(tree
, fname
);
1005 status
= torture_smb2_testdir(tree
, DNAME
, &h
);
1006 CHECK_STATUS(status
, NT_STATUS_OK
);
1008 /* reasonable default parameters */
1009 ZERO_STRUCT(io
.smb2
);
1010 io
.generic
.level
= RAW_OPEN_SMB2
;
1011 io
.smb2
.in
.create_flags
= NTCREATEX_FLAGS_EXTENDED
;
1012 io
.smb2
.in
.alloc_size
= 0;
1013 io
.smb2
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
1014 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_READONLY
;
1015 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
1016 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
1017 io
.smb2
.in
.create_options
= 0;
1018 io
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_ANONYMOUS
;
1019 io
.smb2
.in
.security_flags
= 0;
1020 io
.smb2
.in
.fname
= fname
;
1022 /* Create the readonly file. */
1024 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
1025 CHECK_STATUS(status
, NT_STATUS_OK
);
1026 h1
= io
.smb2
.out
.file
.handle
;
1028 CHECK_VAL(io
.smb2
.out
.oplock_level
, 0);
1029 io
.smb2
.in
.create_options
= 0;
1030 CHECK_VAL(io
.smb2
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
1031 CHECK_ALL_INFO(io
.smb2
.out
.file_attr
, attrib
);
1032 smb2_util_close(tree
, h1
);
1034 /* Now try and open for delete only - should succeed. */
1035 io
.smb2
.in
.desired_access
= SEC_STD_DELETE
;
1036 io
.smb2
.in
.file_attributes
= 0;
1037 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1038 NTCREATEX_SHARE_ACCESS_WRITE
|
1039 NTCREATEX_SHARE_ACCESS_DELETE
;
1040 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
1041 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
1042 CHECK_STATUS(status
, NT_STATUS_OK
);
1044 smb2_util_unlink(tree
, fname
);
1046 smb2_util_close(tree
, h1
);
1047 smb2_util_unlink(tree
, fname
);
1048 smb2_deltree(tree
, DNAME
);
1054 test SMB2 open with a leading slash on the path.
1055 Trying to create a directory with a leading slash
1056 should give NT_STATUS_INVALID_PARAMETER error
1058 static bool test_smb2_leading_slash(struct torture_context
*tctx
,
1059 struct smb2_tree
*tree
)
1062 const char *dnameslash
= "\\"DNAME
;
1066 torture_comment(tctx
,
1067 "Trying to create a directory with leading slash on path\n");
1068 smb2_deltree(tree
, dnameslash
);
1070 ZERO_STRUCT(io
.smb2
);
1071 io
.generic
.level
= RAW_OPEN_SMB2
;
1072 io
.smb2
.in
.oplock_level
= 0;
1073 io
.smb2
.in
.desired_access
= SEC_RIGHTS_DIR_ALL
;
1074 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_DIRECTORY
;
1075 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
1076 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1077 NTCREATEX_SHARE_ACCESS_WRITE
|
1078 NTCREATEX_SHARE_ACCESS_DELETE
;
1079 io
.smb2
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1080 io
.smb2
.in
.fname
= dnameslash
;
1082 status
= smb2_create(tree
, tree
, &(io
.smb2
));
1083 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
1085 smb2_deltree(tree
, dnameslash
);
1090 static bool test_create_acl_file(struct torture_context
*tctx
,
1091 struct smb2_tree
*tree
)
1093 torture_comment(tctx
, "Testing nttrans create with sec_desc on files\n");
1095 return test_create_acl_ext(tctx
, tree
, false);
1098 static bool test_create_acl_dir(struct torture_context
*tctx
,
1099 struct smb2_tree
*tree
)
1101 torture_comment(tctx
, "Testing nttrans create with sec_desc on directories\n");
1103 return test_create_acl_ext(tctx
, tree
, true);
1106 #define CHECK_ACCESS_FLAGS(_fh, flags) do { \
1107 union smb_fileinfo _q; \
1108 _q.access_information.level = RAW_FILEINFO_ACCESS_INFORMATION; \
1109 _q.access_information.in.file.handle = (_fh); \
1110 status = smb2_getinfo_file(tree, tctx, &_q); \
1111 CHECK_STATUS(status, NT_STATUS_OK); \
1112 if (_q.access_information.out.access_flags != (flags)) { \
1113 torture_result(tctx, TORTURE_FAIL, "(%s) Incorrect access_flags 0x%08x - should be 0x%08x\n", \
1114 __location__, _q.access_information.out.access_flags, (flags)); \
1121 * Test creating a file with a NULL DACL.
1123 static bool test_create_null_dacl(struct torture_context
*tctx
,
1124 struct smb2_tree
*tree
)
1127 struct smb2_create io
;
1128 const char *fname
= "nulldacl.txt";
1130 struct smb2_handle handle
;
1131 union smb_fileinfo q
;
1132 union smb_setfileinfo s
;
1133 struct security_descriptor
*sd
= security_descriptor_initialise(tctx
);
1134 struct security_acl dacl
;
1136 torture_comment(tctx
, "TESTING SEC_DESC WITH A NULL DACL\n");
1138 smb2_util_unlink(tree
, fname
);
1141 io
.level
= RAW_OPEN_SMB2
;
1142 io
.in
.create_flags
= 0;
1143 io
.in
.desired_access
= SEC_STD_READ_CONTROL
| SEC_STD_WRITE_DAC
1144 | SEC_STD_WRITE_OWNER
;
1145 io
.in
.create_options
= 0;
1146 io
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
1147 io
.in
.share_access
=
1148 NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1149 io
.in
.alloc_size
= 0;
1150 io
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
1151 io
.in
.impersonation_level
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1152 io
.in
.security_flags
= 0;
1153 io
.in
.fname
= fname
;
1154 io
.in
.sec_desc
= sd
;
1155 /* XXX create_options ? */
1156 io
.in
.create_options
= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY
|
1157 NTCREATEX_OPTIONS_ASYNC_ALERT
|
1158 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
|
1161 torture_comment(tctx
, "creating a file with a empty sd\n");
1162 status
= smb2_create(tree
, tctx
, &io
);
1163 CHECK_STATUS(status
, NT_STATUS_OK
);
1164 handle
= io
.out
.file
.handle
;
1166 torture_comment(tctx
, "get the original sd\n");
1167 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
1168 q
.query_secdesc
.in
.file
.handle
= handle
;
1169 q
.query_secdesc
.in
.secinfo_flags
=
1173 status
= smb2_getinfo_file(tree
, tctx
, &q
);
1174 CHECK_STATUS(status
, NT_STATUS_OK
);
1177 * Testing the created DACL,
1178 * the server should add the inherited DACL
1179 * when SEC_DESC_DACL_PRESENT isn't specified
1181 if (!(q
.query_secdesc
.out
.sd
->type
& SEC_DESC_DACL_PRESENT
)) {
1183 torture_fail_goto(tctx
, done
, "DACL_PRESENT flag not set by the server!\n");
1185 if (q
.query_secdesc
.out
.sd
->dacl
== NULL
) {
1187 torture_fail_goto(tctx
, done
, "no DACL has been created on the server!\n");
1190 torture_comment(tctx
, "set NULL DACL\n");
1191 sd
->type
|= SEC_DESC_DACL_PRESENT
;
1193 s
.set_secdesc
.level
= RAW_SFILEINFO_SEC_DESC
;
1194 s
.set_secdesc
.in
.file
.handle
= handle
;
1195 s
.set_secdesc
.in
.secinfo_flags
= SECINFO_DACL
;
1196 s
.set_secdesc
.in
.sd
= sd
;
1197 status
= smb2_setinfo_file(tree
, &s
);
1198 CHECK_STATUS(status
, NT_STATUS_OK
);
1200 torture_comment(tctx
, "get the sd\n");
1201 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
1202 q
.query_secdesc
.in
.file
.handle
= handle
;
1203 q
.query_secdesc
.in
.secinfo_flags
=
1207 status
= smb2_getinfo_file(tree
, tctx
, &q
);
1208 CHECK_STATUS(status
, NT_STATUS_OK
);
1210 /* Testing the modified DACL */
1211 if (!(q
.query_secdesc
.out
.sd
->type
& SEC_DESC_DACL_PRESENT
)) {
1213 torture_fail_goto(tctx
, done
, "DACL_PRESENT flag not set by the server!\n");
1215 if (q
.query_secdesc
.out
.sd
->dacl
!= NULL
) {
1217 torture_fail_goto(tctx
, done
, "DACL has been created on the server!\n");
1220 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
1222 torture_comment(tctx
, "try open for read control\n");
1223 io
.in
.desired_access
= SEC_STD_READ_CONTROL
;
1224 status
= smb2_create(tree
, tctx
, &io
);
1225 CHECK_STATUS(status
, NT_STATUS_OK
);
1226 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1227 SEC_STD_READ_CONTROL
);
1228 smb2_util_close(tree
, io
.out
.file
.handle
);
1230 torture_comment(tctx
, "try open for write\n");
1231 io
.in
.desired_access
= SEC_FILE_WRITE_DATA
;
1232 status
= smb2_create(tree
, tctx
, &io
);
1233 CHECK_STATUS(status
, NT_STATUS_OK
);
1234 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1235 SEC_FILE_WRITE_DATA
);
1236 smb2_util_close(tree
, io
.out
.file
.handle
);
1238 torture_comment(tctx
, "try open for read\n");
1239 io
.in
.desired_access
= SEC_FILE_READ_DATA
;
1240 status
= smb2_create(tree
, tctx
, &io
);
1241 CHECK_STATUS(status
, NT_STATUS_OK
);
1242 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1243 SEC_FILE_READ_DATA
);
1244 smb2_util_close(tree
, io
.out
.file
.handle
);
1246 torture_comment(tctx
, "try open for generic write\n");
1247 io
.in
.desired_access
= SEC_GENERIC_WRITE
;
1248 status
= smb2_create(tree
, tctx
, &io
);
1249 CHECK_STATUS(status
, NT_STATUS_OK
);
1250 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1251 SEC_RIGHTS_FILE_WRITE
);
1252 smb2_util_close(tree
, io
.out
.file
.handle
);
1254 torture_comment(tctx
, "try open for generic read\n");
1255 io
.in
.desired_access
= SEC_GENERIC_READ
;
1256 status
= smb2_create(tree
, tctx
, &io
);
1257 CHECK_STATUS(status
, NT_STATUS_OK
);
1258 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1259 SEC_RIGHTS_FILE_READ
);
1260 smb2_util_close(tree
, io
.out
.file
.handle
);
1262 torture_comment(tctx
, "set DACL with 0 aces\n");
1264 dacl
.revision
= SECURITY_ACL_REVISION_NT4
;
1268 s
.set_secdesc
.level
= RAW_SFILEINFO_SEC_DESC
;
1269 s
.set_secdesc
.in
.file
.handle
= handle
;
1270 s
.set_secdesc
.in
.secinfo_flags
= SECINFO_DACL
;
1271 s
.set_secdesc
.in
.sd
= sd
;
1272 status
= smb2_setinfo_file(tree
, &s
);
1273 CHECK_STATUS(status
, NT_STATUS_OK
);
1275 torture_comment(tctx
, "get the sd\n");
1276 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
1277 q
.query_secdesc
.in
.file
.handle
= handle
;
1278 q
.query_secdesc
.in
.secinfo_flags
=
1282 status
= smb2_getinfo_file(tree
, tctx
, &q
);
1283 CHECK_STATUS(status
, NT_STATUS_OK
);
1285 /* Testing the modified DACL */
1286 if (!(q
.query_secdesc
.out
.sd
->type
& SEC_DESC_DACL_PRESENT
)) {
1288 torture_fail_goto(tctx
, done
, "DACL_PRESENT flag not set by the server!\n");
1290 if (q
.query_secdesc
.out
.sd
->dacl
== NULL
) {
1292 torture_fail_goto(tctx
, done
, "no DACL has been created on the server!\n");
1294 if (q
.query_secdesc
.out
.sd
->dacl
->num_aces
!= 0) {
1295 torture_result(tctx
, TORTURE_FAIL
, "DACL has %u aces!\n",
1296 q
.query_secdesc
.out
.sd
->dacl
->num_aces
);
1301 torture_comment(tctx
, "try open for read control\n");
1302 io
.in
.desired_access
= SEC_STD_READ_CONTROL
;
1303 status
= smb2_create(tree
, tctx
, &io
);
1304 CHECK_STATUS(status
, NT_STATUS_OK
);
1305 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1306 SEC_STD_READ_CONTROL
);
1307 smb2_util_close(tree
, io
.out
.file
.handle
);
1309 torture_comment(tctx
, "try open for write => access_denied\n");
1310 io
.in
.desired_access
= SEC_FILE_WRITE_DATA
;
1311 status
= smb2_create(tree
, tctx
, &io
);
1312 if (torture_setting_bool(tctx
, "hide_on_access_denied", false)) {
1313 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1315 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
1318 torture_comment(tctx
, "try open for read => access_denied\n");
1319 io
.in
.desired_access
= SEC_FILE_READ_DATA
;
1320 status
= smb2_create(tree
, tctx
, &io
);
1321 if (torture_setting_bool(tctx
, "hide_on_access_denied", false)) {
1322 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1324 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
1327 torture_comment(tctx
, "try open for generic write => access_denied\n");
1328 io
.in
.desired_access
= SEC_GENERIC_WRITE
;
1329 status
= smb2_create(tree
, tctx
, &io
);
1330 if (torture_setting_bool(tctx
, "hide_on_access_denied", false)) {
1331 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1333 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
1336 torture_comment(tctx
, "try open for generic read => access_denied\n");
1337 io
.in
.desired_access
= SEC_GENERIC_READ
;
1338 status
= smb2_create(tree
, tctx
, &io
);
1339 if (torture_setting_bool(tctx
, "hide_on_access_denied", false)) {
1340 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1342 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
1345 torture_comment(tctx
, "set empty sd\n");
1346 sd
->type
&= ~SEC_DESC_DACL_PRESENT
;
1349 s
.set_secdesc
.level
= RAW_SFILEINFO_SEC_DESC
;
1350 s
.set_secdesc
.in
.file
.handle
= handle
;
1351 s
.set_secdesc
.in
.secinfo_flags
= SECINFO_DACL
;
1352 s
.set_secdesc
.in
.sd
= sd
;
1353 status
= smb2_setinfo_file(tree
, &s
);
1354 CHECK_STATUS(status
, NT_STATUS_OK
);
1356 torture_comment(tctx
, "get the sd\n");
1357 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
1358 q
.query_secdesc
.in
.file
.handle
= handle
;
1359 q
.query_secdesc
.in
.secinfo_flags
=
1363 status
= smb2_getinfo_file(tree
, tctx
, &q
);
1364 CHECK_STATUS(status
, NT_STATUS_OK
);
1366 /* Testing the modified DACL */
1367 if (!(q
.query_secdesc
.out
.sd
->type
& SEC_DESC_DACL_PRESENT
)) {
1369 torture_fail_goto(tctx
, done
, "DACL_PRESENT flag not set by the server!\n");
1371 if (q
.query_secdesc
.out
.sd
->dacl
!= NULL
) {
1373 torture_fail_goto(tctx
, done
, "DACL has been created on the server!\n");
1376 smb2_util_close(tree
, handle
);
1377 smb2_util_unlink(tree
, fname
);
1379 smb2_logoff(tree
->session
);
1384 basic testing of SMB2 read
1386 struct torture_suite
*torture_smb2_create_init(void)
1388 struct torture_suite
*suite
= torture_suite_create(talloc_autofree_context(), "create");
1390 torture_suite_add_1smb2_test(suite
, "gentest", test_create_gentest
);
1391 torture_suite_add_1smb2_test(suite
, "blob", test_create_blob
);
1392 torture_suite_add_1smb2_test(suite
, "open", test_smb2_open
);
1393 torture_suite_add_1smb2_test(suite
, "brlocked", test_smb2_open_brlocked
);
1394 torture_suite_add_1smb2_test(suite
, "multi", test_smb2_open_multi
);
1395 torture_suite_add_1smb2_test(suite
, "delete", test_smb2_open_for_delete
);
1396 torture_suite_add_1smb2_test(suite
, "leading-slash", test_smb2_leading_slash
);
1397 torture_suite_add_1smb2_test(suite
, "aclfile", test_create_acl_file
);
1398 torture_suite_add_1smb2_test(suite
, "acldir", test_create_acl_dir
);
1399 torture_suite_add_1smb2_test(suite
, "nulldacl", test_create_null_dacl
);
1401 suite
->description
= talloc_strdup(suite
, "SMB2-CREATE tests");