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 CHECK_EQUAL(io
.out
.file_attr
, expected
);
279 file_attributes_set
|= io
.out
.file_attr
;
281 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
282 CHECK_STATUS(status
, NT_STATUS_OK
);
284 unexpected_mask
|= 1<<i
;
285 torture_comment(tctx
,
286 "file attribute 0x%08x returned %s\n",
287 1<<i
, nt_errstr(status
));
292 CHECK_EQUAL(ok_mask
, 0x00003fb7);
293 CHECK_EQUAL(invalid_parameter_mask
, 0xffff8048);
294 CHECK_EQUAL(unexpected_mask
, 0x00000000);
295 CHECK_EQUAL(file_attributes_set
, 0x00001127);
297 smb2_deltree(tree
, FNAME
);
300 * Standalone servers doesn't support encryption
302 io
.in
.file_attributes
= FILE_ATTRIBUTE_ENCRYPTED
;
303 status
= smb2_create(tree
, tctx
, &io
);
304 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
305 torture_comment(tctx
,
306 "FILE_ATTRIBUTE_ENCRYPTED returned %s\n",
309 CHECK_STATUS(status
, NT_STATUS_OK
);
310 CHECK_EQUAL(io
.out
.file_attr
, (FILE_ATTRIBUTE_ENCRYPTED
| FILE_ATTRIBUTE_ARCHIVE
));
311 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
312 CHECK_STATUS(status
, NT_STATUS_OK
);
315 smb2_deltree(tree
, FNAME
);
318 io
.in
.desired_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
319 io
.in
.file_attributes
= 0;
320 io
.in
.create_disposition
= NTCREATEX_DISP_OVERWRITE_IF
;
322 NTCREATEX_SHARE_ACCESS_READ
|
323 NTCREATEX_SHARE_ACCESS_WRITE
;
324 io
.in
.create_options
= 0;
325 io
.in
.fname
= FNAME
":stream1";
326 status
= smb2_create(tree
, tctx
, &io
);
327 CHECK_STATUS(status
, NT_STATUS_OK
);
329 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
330 CHECK_STATUS(status
, NT_STATUS_OK
);
333 io
.in
.file_attributes
= 0x8040;
335 NTCREATEX_SHARE_ACCESS_READ
;
336 status
= smb2_create(tree
, tctx
, &io
);
337 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
340 io
.in
.file_attributes
= 0;
341 io
.in
.desired_access
= SEC_FILE_READ_DATA
| SEC_FILE_WRITE_DATA
| SEC_FILE_APPEND_DATA
;
342 io
.in
.query_maximal_access
= true;
343 status
= smb2_create(tree
, tctx
, &io
);
344 CHECK_STATUS(status
, NT_STATUS_OK
);
345 CHECK_EQUAL(io
.out
.maximal_access
, 0x001f01ff);
347 q
.access_information
.level
= RAW_FILEINFO_ACCESS_INFORMATION
;
348 q
.access_information
.in
.file
.handle
= io
.out
.file
.handle
;
349 status
= smb2_getinfo_file(tree
, tctx
, &q
);
350 CHECK_STATUS(status
, NT_STATUS_OK
);
351 CHECK_EQUAL(q
.access_information
.out
.access_flags
, io
.in
.desired_access
);
353 io
.in
.file_attributes
= 0;
354 io
.in
.desired_access
= 0;
355 io
.in
.query_maximal_access
= false;
356 io
.in
.share_access
= 0;
357 status
= smb2_create(tree
, tctx
, &io
);
358 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
360 smb2_deltree(tree
, FNAME
);
367 try the various request blobs
369 static bool test_create_blob(struct torture_context
*tctx
, struct smb2_tree
*tree
)
371 struct smb2_create io
;
374 smb2_deltree(tree
, FNAME
);
377 io
.in
.desired_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
378 io
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
379 io
.in
.create_disposition
= NTCREATEX_DISP_OVERWRITE_IF
;
381 NTCREATEX_SHARE_ACCESS_DELETE
|
382 NTCREATEX_SHARE_ACCESS_READ
|
383 NTCREATEX_SHARE_ACCESS_WRITE
;
384 io
.in
.create_options
= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY
|
385 NTCREATEX_OPTIONS_ASYNC_ALERT
|
386 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
|
390 status
= smb2_create(tree
, tctx
, &io
);
391 CHECK_STATUS(status
, NT_STATUS_OK
);
393 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
394 CHECK_STATUS(status
, NT_STATUS_OK
);
396 torture_comment(tctx
, "Testing alloc size\n");
397 io
.in
.alloc_size
= 4096;
398 status
= smb2_create(tree
, tctx
, &io
);
399 CHECK_STATUS(status
, NT_STATUS_OK
);
400 CHECK_EQUAL(io
.out
.alloc_size
, io
.in
.alloc_size
);
402 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
403 CHECK_STATUS(status
, NT_STATUS_OK
);
405 torture_comment(tctx
, "Testing durable open\n");
406 io
.in
.durable_open
= true;
407 status
= smb2_create(tree
, tctx
, &io
);
408 CHECK_STATUS(status
, NT_STATUS_OK
);
410 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
411 CHECK_STATUS(status
, NT_STATUS_OK
);
413 torture_comment(tctx
, "Testing query maximal access\n");
414 io
.in
.query_maximal_access
= true;
415 status
= smb2_create(tree
, tctx
, &io
);
416 CHECK_STATUS(status
, NT_STATUS_OK
);
417 CHECK_EQUAL(io
.out
.maximal_access
, 0x001f01ff);
419 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
420 CHECK_STATUS(status
, NT_STATUS_OK
);
422 torture_comment(tctx
, "Testing timewarp\n");
423 io
.in
.timewarp
= 10000;
424 status
= smb2_create(tree
, tctx
, &io
);
425 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
428 torture_comment(tctx
, "Testing query_on_disk\n");
429 io
.in
.query_on_disk_id
= true;
430 status
= smb2_create(tree
, tctx
, &io
);
431 CHECK_STATUS(status
, NT_STATUS_OK
);
433 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
434 CHECK_STATUS(status
, NT_STATUS_OK
);
436 torture_comment(tctx
, "Testing unknown tag\n");
437 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
438 "FooO", data_blob(NULL
, 0));
439 CHECK_STATUS(status
, NT_STATUS_OK
);
441 status
= smb2_create(tree
, tctx
, &io
);
442 CHECK_STATUS(status
, NT_STATUS_OK
);
444 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
445 CHECK_STATUS(status
, NT_STATUS_OK
);
447 torture_comment(tctx
, "Testing bad tag length\n");
448 status
= smb2_create_blob_add(tctx
, &io
.in
.blobs
,
449 "xxx", data_blob(NULL
, 0));
450 CHECK_STATUS(status
, NT_STATUS_OK
);
452 status
= smb2_create(tree
, tctx
, &io
);
453 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
455 smb2_deltree(tree
, FNAME
);
460 #define FAIL_UNLESS(__cond) \
462 if (__cond) {} else { \
463 torture_result(tctx, TORTURE_FAIL, "%s) condition violated: %s\n", \
464 __location__, #__cond); \
465 ret = false; goto done; \
470 try creating with acls
472 static bool test_create_acl_ext(struct torture_context
*tctx
, struct smb2_tree
*tree
, bool test_dir
)
475 struct smb2_create io
;
477 struct security_ace ace
;
478 struct security_descriptor
*sd
;
479 struct dom_sid
*test_sid
;
480 union smb_fileinfo q
= {};
482 FILE_ATTRIBUTE_HIDDEN
|
483 FILE_ATTRIBUTE_SYSTEM
|
484 (test_dir
? FILE_ATTRIBUTE_DIRECTORY
: 0);
485 NTSTATUS (*delete_func
)(struct smb2_tree
*, const char *) =
486 test_dir
? smb2_util_rmdir
: smb2_util_unlink
;
488 smb2_deltree(tree
, FNAME
);
491 io
.in
.desired_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
492 io
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
493 io
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
495 NTCREATEX_SHARE_ACCESS_DELETE
|
496 NTCREATEX_SHARE_ACCESS_READ
|
497 NTCREATEX_SHARE_ACCESS_WRITE
;
498 io
.in
.create_options
= NTCREATEX_OPTIONS_ASYNC_ALERT
| 0x00200000 |
499 (test_dir
? NTCREATEX_OPTIONS_DIRECTORY
:
500 (NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
));
504 torture_comment(tctx
, "basic create\n");
506 status
= smb2_create(tree
, tctx
, &io
);
507 CHECK_STATUS(status
, NT_STATUS_OK
);
509 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
510 q
.query_secdesc
.in
.file
.handle
= io
.out
.file
.handle
;
511 q
.query_secdesc
.in
.secinfo_flags
=
515 status
= smb2_getinfo_file(tree
, tctx
, &q
);
516 CHECK_STATUS(status
, NT_STATUS_OK
);
517 sd
= q
.query_secdesc
.out
.sd
;
519 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
520 CHECK_STATUS(status
, NT_STATUS_OK
);
521 status
= delete_func(tree
, FNAME
);
522 CHECK_STATUS(status
, NT_STATUS_OK
);
524 torture_comment(tctx
, "adding a new ACE\n");
525 test_sid
= dom_sid_parse_talloc(tctx
, SID_NT_AUTHENTICATED_USERS
);
527 ace
.type
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
529 ace
.access_mask
= SEC_STD_ALL
;
530 ace
.trustee
= *test_sid
;
532 status
= security_descriptor_dacl_add(sd
, &ace
);
533 CHECK_STATUS(status
, NT_STATUS_OK
);
535 torture_comment(tctx
, "creating a file with an initial ACL\n");
538 status
= smb2_create(tree
, tctx
, &io
);
539 CHECK_STATUS(status
, NT_STATUS_OK
);
541 FAIL_UNLESS(smb2_util_verify_sd(tctx
, tree
, io
.out
.file
.handle
, sd
));
543 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
544 CHECK_STATUS(status
, NT_STATUS_OK
);
545 status
= delete_func(tree
, FNAME
);
546 CHECK_STATUS(status
, NT_STATUS_OK
);
548 torture_comment(tctx
, "creating with attributes\n");
550 io
.in
.sec_desc
= NULL
;
551 io
.in
.file_attributes
= attrib
;
552 status
= smb2_create(tree
, tctx
, &io
);
553 CHECK_STATUS(status
, NT_STATUS_OK
);
555 FAIL_UNLESS(smb2_util_verify_attrib(tctx
, tree
, io
.out
.file
.handle
, attrib
));
557 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
558 CHECK_STATUS(status
, NT_STATUS_OK
);
559 status
= delete_func(tree
, FNAME
);
560 CHECK_STATUS(status
, NT_STATUS_OK
);
562 torture_comment(tctx
, "creating with attributes and ACL\n");
565 io
.in
.file_attributes
= attrib
;
566 status
= smb2_create(tree
, tctx
, &io
);
567 CHECK_STATUS(status
, NT_STATUS_OK
);
569 FAIL_UNLESS(smb2_util_verify_sd(tctx
, tree
, io
.out
.file
.handle
, sd
));
570 FAIL_UNLESS(smb2_util_verify_attrib(tctx
, tree
, io
.out
.file
.handle
, attrib
));
572 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
573 CHECK_STATUS(status
, NT_STATUS_OK
);
574 status
= delete_func(tree
, FNAME
);
575 CHECK_STATUS(status
, NT_STATUS_OK
);
577 torture_comment(tctx
, "creating with attributes, ACL and owner\n");
578 sd
= security_descriptor_dacl_create(tctx
,
579 0, SID_WORLD
, SID_BUILTIN_USERS
,
581 SEC_ACE_TYPE_ACCESS_ALLOWED
,
582 SEC_RIGHTS_FILE_READ
| SEC_STD_ALL
,
587 io
.in
.file_attributes
= attrib
;
588 status
= smb2_create(tree
, tctx
, &io
);
589 CHECK_STATUS(status
, NT_STATUS_OK
);
591 FAIL_UNLESS(smb2_util_verify_sd(tctx
, tree
, io
.out
.file
.handle
, sd
));
592 FAIL_UNLESS(smb2_util_verify_attrib(tctx
, tree
, io
.out
.file
.handle
, attrib
));
595 status
= smb2_util_close(tree
, io
.out
.file
.handle
);
596 CHECK_STATUS(status
, NT_STATUS_OK
);
597 status
= delete_func(tree
, FNAME
);
598 CHECK_STATUS(status
, NT_STATUS_OK
);
606 static bool test_smb2_open(struct torture_context
*tctx
,
607 struct smb2_tree
*tree
)
610 union smb_fileinfo finfo
;
611 const char *fname
= DNAME
"\\torture_ntcreatex.txt";
612 const char *dname
= DNAME
"\\torture_ntcreatex.dir";
614 struct smb2_handle h
, h1
;
618 uint32_t create_disp
;
620 NTSTATUS correct_status
;
622 { NTCREATEX_DISP_SUPERSEDE
, true, NT_STATUS_OK
},
623 { NTCREATEX_DISP_SUPERSEDE
, false, NT_STATUS_OK
},
624 { NTCREATEX_DISP_OPEN
, true, NT_STATUS_OK
},
625 { NTCREATEX_DISP_OPEN
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
626 { NTCREATEX_DISP_CREATE
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
627 { NTCREATEX_DISP_CREATE
, false, NT_STATUS_OK
},
628 { NTCREATEX_DISP_OPEN_IF
, true, NT_STATUS_OK
},
629 { NTCREATEX_DISP_OPEN_IF
, false, NT_STATUS_OK
},
630 { NTCREATEX_DISP_OVERWRITE
, true, NT_STATUS_OK
},
631 { NTCREATEX_DISP_OVERWRITE
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
632 { NTCREATEX_DISP_OVERWRITE_IF
, true, NT_STATUS_OK
},
633 { NTCREATEX_DISP_OVERWRITE_IF
, false, NT_STATUS_OK
},
634 { 6, true, NT_STATUS_INVALID_PARAMETER
},
635 { 6, false, NT_STATUS_INVALID_PARAMETER
},
638 torture_comment(tctx
, "Checking SMB2 Open\n");
640 smb2_util_unlink(tree
, fname
);
641 smb2_util_rmdir(tree
, dname
);
643 status
= torture_smb2_testdir(tree
, DNAME
, &h
);
644 CHECK_STATUS(status
, NT_STATUS_OK
);
646 ZERO_STRUCT(io
.smb2
);
647 /* reasonable default parameters */
648 io
.generic
.level
= RAW_OPEN_SMB2
;
649 io
.smb2
.in
.create_flags
= NTCREATEX_FLAGS_EXTENDED
;
650 io
.smb2
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
651 io
.smb2
.in
.alloc_size
= 1024*1024;
652 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
653 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
654 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
655 io
.smb2
.in
.create_options
= 0;
656 io
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_ANONYMOUS
;
657 io
.smb2
.in
.security_flags
= 0;
658 io
.smb2
.in
.fname
= fname
;
660 /* test the create disposition */
661 for (i
=0; i
<ARRAY_SIZE(open_funcs
); i
++) {
662 if (open_funcs
[i
].with_file
) {
663 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
664 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
665 if (!NT_STATUS_IS_OK(status
)) {
666 torture_comment(tctx
,
667 "Failed to create file %s status %s %d\n",
668 fname
, nt_errstr(status
), i
);
673 smb2_util_close(tree
, io
.smb2
.out
.file
.handle
);
675 io
.smb2
.in
.create_disposition
= open_funcs
[i
].create_disp
;
676 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
677 if (!NT_STATUS_EQUAL(status
, open_funcs
[i
].correct_status
)) {
678 torture_comment(tctx
,
679 "(%s) incorrect status %s should be %s (i=%d "
680 "with_file=%d open_disp=%d)\n",
681 __location__
, nt_errstr(status
),
682 nt_errstr(open_funcs
[i
].correct_status
),
683 i
, (int)open_funcs
[i
].with_file
,
684 (int)open_funcs
[i
].create_disp
);
689 if (NT_STATUS_IS_OK(status
) || open_funcs
[i
].with_file
) {
690 smb2_util_close(tree
, io
.smb2
.out
.file
.handle
);
691 smb2_util_unlink(tree
, fname
);
695 /* basic field testing */
696 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
698 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
699 CHECK_STATUS(status
, NT_STATUS_OK
);
700 h1
= io
.smb2
.out
.file
.handle
;
702 CHECK_VAL(io
.smb2
.out
.oplock_level
, 0);
703 CHECK_VAL(io
.smb2
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
704 CHECK_NTTIME(io
.smb2
.out
.create_time
, create_time
);
705 CHECK_NTTIME(io
.smb2
.out
.access_time
, access_time
);
706 CHECK_NTTIME(io
.smb2
.out
.write_time
, write_time
);
707 CHECK_NTTIME(io
.smb2
.out
.change_time
, change_time
);
708 CHECK_ALL_INFO(io
.smb2
.out
.file_attr
, attrib
);
709 CHECK_ALL_INFO(io
.smb2
.out
.alloc_size
, alloc_size
);
710 CHECK_ALL_INFO(io
.smb2
.out
.size
, size
);
712 /* check fields when the file already existed */
713 smb2_util_close(tree
, h1
);
714 smb2_util_unlink(tree
, fname
);
716 status
= smb2_create_complex_file(tree
, fname
, &h1
);
717 CHECK_STATUS(status
, NT_STATUS_OK
);
719 smb2_util_close(tree
, h1
);
721 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
722 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
723 CHECK_STATUS(status
, NT_STATUS_OK
);
724 h1
= io
.smb2
.out
.file
.handle
;
726 CHECK_VAL(io
.smb2
.out
.oplock_level
, 0);
727 CHECK_VAL(io
.smb2
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
728 CHECK_NTTIME(io
.smb2
.out
.create_time
, create_time
);
729 CHECK_NTTIME(io
.smb2
.out
.access_time
, access_time
);
730 CHECK_NTTIME(io
.smb2
.out
.write_time
, write_time
);
731 CHECK_NTTIME(io
.smb2
.out
.change_time
, change_time
);
732 CHECK_ALL_INFO(io
.smb2
.out
.file_attr
, attrib
);
733 CHECK_ALL_INFO(io
.smb2
.out
.alloc_size
, alloc_size
);
734 CHECK_ALL_INFO(io
.smb2
.out
.size
, size
);
735 smb2_util_close(tree
, h1
);
736 smb2_util_unlink(tree
, fname
);
738 /* create a directory */
739 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
740 io
.smb2
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
741 io
.smb2
.in
.alloc_size
= 0;
742 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_DIRECTORY
;
743 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
744 io
.smb2
.in
.create_options
= 0;
745 io
.smb2
.in
.fname
= dname
;
748 smb2_util_rmdir(tree
, fname
);
749 smb2_util_unlink(tree
, fname
);
751 io
.smb2
.in
.desired_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
752 io
.smb2
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
753 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
754 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
755 NTCREATEX_SHARE_ACCESS_WRITE
;
756 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
757 CHECK_STATUS(status
, NT_STATUS_OK
);
758 h1
= io
.smb2
.out
.file
.handle
;
760 CHECK_VAL(io
.smb2
.out
.oplock_level
, 0);
761 CHECK_VAL(io
.smb2
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
762 CHECK_NTTIME(io
.smb2
.out
.create_time
, create_time
);
763 CHECK_NTTIME(io
.smb2
.out
.access_time
, access_time
);
764 CHECK_NTTIME(io
.smb2
.out
.write_time
, write_time
);
765 CHECK_NTTIME(io
.smb2
.out
.change_time
, change_time
);
766 CHECK_ALL_INFO(io
.smb2
.out
.file_attr
, attrib
);
767 CHECK_VAL(io
.smb2
.out
.file_attr
& ~FILE_ATTRIBUTE_NONINDEXED
,
768 FILE_ATTRIBUTE_DIRECTORY
);
769 CHECK_ALL_INFO(io
.smb2
.out
.alloc_size
, alloc_size
);
770 CHECK_ALL_INFO(io
.smb2
.out
.size
, size
);
771 CHECK_VAL(io
.smb2
.out
.size
, 0);
772 CHECK_VAL(io
.smb2
.out
.alloc_size
, 0);
773 smb2_util_unlink(tree
, fname
);
776 smb2_util_close(tree
, h1
);
777 smb2_util_unlink(tree
, fname
);
778 smb2_deltree(tree
, DNAME
);
783 test with an already opened and byte range locked file
786 static bool test_smb2_open_brlocked(struct torture_context
*tctx
,
787 struct smb2_tree
*tree
)
789 union smb_open io
, io1
;
791 struct smb2_lock_element lock
[1];
792 const char *fname
= DNAME
"\\torture_ntcreatex.txt";
795 struct smb2_handle h
;
798 torture_comment(tctx
,
799 "Testing SMB2 open with a byte range locked file\n");
801 smb2_util_unlink(tree
, fname
);
803 status
= torture_smb2_testdir(tree
, DNAME
, &h
);
804 CHECK_STATUS(status
, NT_STATUS_OK
);
806 ZERO_STRUCT(io
.smb2
);
807 io
.generic
.level
= RAW_OPEN_SMB2
;
808 io
.smb2
.in
.create_flags
= NTCREATEX_FLAGS_EXTENDED
;
809 io
.smb2
.in
.desired_access
= 0x2019f;
810 io
.smb2
.in
.alloc_size
= 0;
811 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
812 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
813 NTCREATEX_SHARE_ACCESS_WRITE
;
814 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
815 io
.smb2
.in
.create_options
= NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
;
816 io
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
817 io
.smb2
.in
.security_flags
= SMB2_SECURITY_DYNAMIC_TRACKING
;
818 io
.smb2
.in
.fname
= fname
;
820 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
821 CHECK_STATUS(status
, NT_STATUS_OK
);
823 status
= smb2_util_write(tree
, io
.smb2
.out
.file
.handle
, &b
, 0, 1);
824 CHECK_STATUS(status
, NT_STATUS_OK
);
826 ZERO_STRUCT(io2
.smb2
);
827 io2
.smb2
.level
= RAW_LOCK_SMB2
;
828 io2
.smb2
.in
.file
.handle
= io
.smb2
.out
.file
.handle
;
829 io2
.smb2
.in
.lock_count
= 1;
834 lock
[0].flags
= SMB2_LOCK_FLAG_EXCLUSIVE
|
835 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY
;
836 io2
.smb2
.in
.locks
= &lock
[0];
837 status
= smb2_lock(tree
, &(io2
.smb2
));
838 CHECK_STATUS(status
, NT_STATUS_OK
);
840 ZERO_STRUCT(io1
.smb2
);
841 io1
.smb2
.in
.create_flags
= NTCREATEX_FLAGS_EXTENDED
;
842 io1
.smb2
.in
.desired_access
= 0x20196;
843 io1
.smb2
.in
.alloc_size
= 0;
844 io1
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
845 io1
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
846 NTCREATEX_SHARE_ACCESS_WRITE
;
847 io1
.smb2
.in
.create_disposition
= NTCREATEX_DISP_OVERWRITE_IF
;
848 io1
.smb2
.in
.create_options
= 0;
849 io1
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
850 io1
.smb2
.in
.security_flags
= SMB2_SECURITY_DYNAMIC_TRACKING
;
851 io1
.smb2
.in
.fname
= fname
;
853 status
= smb2_create(tree
, tctx
, &(io1
.smb2
));
854 CHECK_STATUS(status
, NT_STATUS_OK
);
856 smb2_util_close(tree
, io
.smb2
.out
.file
.handle
);
857 smb2_util_close(tree
, io1
.smb2
.out
.file
.handle
);
858 smb2_util_unlink(tree
, fname
);
859 smb2_deltree(tree
, DNAME
);
864 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
866 static bool test_smb2_open_multi(struct torture_context
*tctx
,
867 struct smb2_tree
*tree
)
869 const char *fname
= "test_oplock.dat";
873 struct smb2_tree
**trees
;
874 struct smb2_request
**requests
;
876 int i
, num_files
= 3;
878 int num_collision
= 0;
880 torture_comment(tctx
,
881 "Testing SMB2 Open with multiple connections\n");
882 trees
= talloc_array(tctx
, struct smb2_tree
*, num_files
);
883 requests
= talloc_array(tctx
, struct smb2_request
*, num_files
);
884 ios
= talloc_array(tctx
, union smb_open
, num_files
);
885 if ((tctx
->ev
== NULL
) || (trees
== NULL
) || (requests
== NULL
) ||
887 torture_comment(tctx
, ("talloc failed\n"));
892 tree
->session
->transport
->options
.request_timeout
= 60;
894 for (i
=0; i
<num_files
; i
++) {
895 if (!torture_smb2_connection(tctx
, &(trees
[i
]))) {
896 torture_comment(tctx
,
897 "Could not open %d'th connection\n", i
);
901 trees
[i
]->session
->transport
->options
.request_timeout
= 60;
905 smb2_util_unlink(tree
, fname
);
910 ZERO_STRUCT(io
.smb2
);
911 io
.generic
.level
= RAW_OPEN_SMB2
;
912 io
.smb2
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
913 io
.smb2
.in
.alloc_size
= 0;
914 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
915 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
916 NTCREATEX_SHARE_ACCESS_WRITE
|
917 NTCREATEX_SHARE_ACCESS_DELETE
;
918 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
919 io
.smb2
.in
.create_options
= 0;
920 io
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_ANONYMOUS
;
921 io
.smb2
.in
.security_flags
= 0;
922 io
.smb2
.in
.fname
= fname
;
923 io
.smb2
.in
.create_flags
= 0;
925 for (i
=0; i
<num_files
; i
++) {
927 requests
[i
] = smb2_create_send(trees
[i
], &(ios
[i
].smb2
));
928 if (requests
[i
] == NULL
) {
929 torture_comment(tctx
,
930 "could not send %d'th request\n", i
);
936 torture_comment(tctx
, "waiting for replies\n");
938 bool unreplied
= false;
939 for (i
=0; i
<num_files
; i
++) {
940 if (requests
[i
] == NULL
) {
943 if (requests
[i
]->state
< SMB2_REQUEST_DONE
) {
947 status
= smb2_create_recv(requests
[i
], tctx
,
950 torture_comment(tctx
,
951 "File %d returned status %s\n", i
,
954 if (NT_STATUS_IS_OK(status
)) {
958 if (NT_STATUS_EQUAL(status
,
959 NT_STATUS_OBJECT_NAME_COLLISION
)) {
969 if (tevent_loop_once(tctx
->ev
) != 0) {
970 torture_comment(tctx
, "tevent_loop_once failed\n");
976 if ((num_ok
!= 1) || (num_ok
+ num_collision
!= num_files
)) {
980 smb2_deltree(tree
, fname
);
986 test opening for delete on a read-only attribute file.
989 static bool test_smb2_open_for_delete(struct torture_context
*tctx
,
990 struct smb2_tree
*tree
)
993 union smb_fileinfo finfo
;
994 const char *fname
= DNAME
"\\torture_open_for_delete.txt";
996 struct smb2_handle h
, h1
;
999 torture_comment(tctx
,
1000 "Checking SMB2_OPEN for delete on a readonly file.\n");
1001 smb2_util_unlink(tree
, fname
);
1002 smb2_deltree(tree
, fname
);
1004 status
= torture_smb2_testdir(tree
, DNAME
, &h
);
1005 CHECK_STATUS(status
, NT_STATUS_OK
);
1007 /* reasonable default parameters */
1008 ZERO_STRUCT(io
.smb2
);
1009 io
.generic
.level
= RAW_OPEN_SMB2
;
1010 io
.smb2
.in
.create_flags
= NTCREATEX_FLAGS_EXTENDED
;
1011 io
.smb2
.in
.alloc_size
= 0;
1012 io
.smb2
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
1013 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_READONLY
;
1014 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
1015 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
1016 io
.smb2
.in
.create_options
= 0;
1017 io
.smb2
.in
.impersonation_level
= SMB2_IMPERSONATION_ANONYMOUS
;
1018 io
.smb2
.in
.security_flags
= 0;
1019 io
.smb2
.in
.fname
= fname
;
1021 /* Create the readonly file. */
1023 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
1024 CHECK_STATUS(status
, NT_STATUS_OK
);
1025 h1
= io
.smb2
.out
.file
.handle
;
1027 CHECK_VAL(io
.smb2
.out
.oplock_level
, 0);
1028 io
.smb2
.in
.create_options
= 0;
1029 CHECK_VAL(io
.smb2
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
1030 CHECK_ALL_INFO(io
.smb2
.out
.file_attr
, attrib
);
1031 smb2_util_close(tree
, h1
);
1033 /* Now try and open for delete only - should succeed. */
1034 io
.smb2
.in
.desired_access
= SEC_STD_DELETE
;
1035 io
.smb2
.in
.file_attributes
= 0;
1036 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1037 NTCREATEX_SHARE_ACCESS_WRITE
|
1038 NTCREATEX_SHARE_ACCESS_DELETE
;
1039 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
1040 status
= smb2_create(tree
, tctx
, &(io
.smb2
));
1041 CHECK_STATUS(status
, NT_STATUS_OK
);
1043 smb2_util_unlink(tree
, fname
);
1045 smb2_util_close(tree
, h1
);
1046 smb2_util_unlink(tree
, fname
);
1047 smb2_deltree(tree
, DNAME
);
1053 test SMB2 open with a leading slash on the path.
1054 Trying to create a directory with a leading slash
1055 should give NT_STATUS_INVALID_PARAMETER error
1057 static bool test_smb2_leading_slash(struct torture_context
*tctx
,
1058 struct smb2_tree
*tree
)
1061 const char *dnameslash
= "\\"DNAME
;
1065 torture_comment(tctx
,
1066 "Trying to create a directory with leading slash on path\n");
1067 smb2_deltree(tree
, dnameslash
);
1069 ZERO_STRUCT(io
.smb2
);
1070 io
.generic
.level
= RAW_OPEN_SMB2
;
1071 io
.smb2
.in
.oplock_level
= 0;
1072 io
.smb2
.in
.desired_access
= SEC_RIGHTS_DIR_ALL
;
1073 io
.smb2
.in
.file_attributes
= FILE_ATTRIBUTE_DIRECTORY
;
1074 io
.smb2
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
1075 io
.smb2
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1076 NTCREATEX_SHARE_ACCESS_WRITE
|
1077 NTCREATEX_SHARE_ACCESS_DELETE
;
1078 io
.smb2
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1079 io
.smb2
.in
.fname
= dnameslash
;
1081 status
= smb2_create(tree
, tree
, &(io
.smb2
));
1082 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
1084 smb2_deltree(tree
, dnameslash
);
1089 static bool test_create_acl_file(struct torture_context
*tctx
,
1090 struct smb2_tree
*tree
)
1092 torture_comment(tctx
, "Testing nttrans create with sec_desc on files\n");
1094 return test_create_acl_ext(tctx
, tree
, false);
1097 static bool test_create_acl_dir(struct torture_context
*tctx
,
1098 struct smb2_tree
*tree
)
1100 torture_comment(tctx
, "Testing nttrans create with sec_desc on directories\n");
1102 return test_create_acl_ext(tctx
, tree
, true);
1105 #define CHECK_ACCESS_FLAGS(_fh, flags) do { \
1106 union smb_fileinfo _q; \
1107 _q.access_information.level = RAW_FILEINFO_ACCESS_INFORMATION; \
1108 _q.access_information.in.file.handle = (_fh); \
1109 status = smb2_getinfo_file(tree, tctx, &_q); \
1110 CHECK_STATUS(status, NT_STATUS_OK); \
1111 if (_q.access_information.out.access_flags != (flags)) { \
1112 torture_result(tctx, TORTURE_FAIL, "(%s) Incorrect access_flags 0x%08x - should be 0x%08x\n", \
1113 __location__, _q.access_information.out.access_flags, (flags)); \
1120 * Test creating a file with a NULL DACL.
1122 static bool test_create_null_dacl(struct torture_context
*tctx
,
1123 struct smb2_tree
*tree
)
1126 struct smb2_create io
;
1127 const char *fname
= "nulldacl.txt";
1129 struct smb2_handle handle
;
1130 union smb_fileinfo q
;
1131 union smb_setfileinfo s
;
1132 struct security_descriptor
*sd
= security_descriptor_initialise(tctx
);
1133 struct security_acl dacl
;
1135 torture_comment(tctx
, "TESTING SEC_DESC WITH A NULL DACL\n");
1137 smb2_util_unlink(tree
, fname
);
1140 io
.level
= RAW_OPEN_SMB2
;
1141 io
.in
.create_flags
= 0;
1142 io
.in
.desired_access
= SEC_STD_READ_CONTROL
| SEC_STD_WRITE_DAC
1143 | SEC_STD_WRITE_OWNER
;
1144 io
.in
.create_options
= 0;
1145 io
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
1146 io
.in
.share_access
=
1147 NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1148 io
.in
.alloc_size
= 0;
1149 io
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
1150 io
.in
.impersonation_level
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1151 io
.in
.security_flags
= 0;
1152 io
.in
.fname
= fname
;
1153 io
.in
.sec_desc
= sd
;
1154 /* XXX create_options ? */
1155 io
.in
.create_options
= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY
|
1156 NTCREATEX_OPTIONS_ASYNC_ALERT
|
1157 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
|
1160 torture_comment(tctx
, "creating a file with a empty sd\n");
1161 status
= smb2_create(tree
, tctx
, &io
);
1162 CHECK_STATUS(status
, NT_STATUS_OK
);
1163 handle
= io
.out
.file
.handle
;
1165 torture_comment(tctx
, "get the original sd\n");
1166 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
1167 q
.query_secdesc
.in
.file
.handle
= handle
;
1168 q
.query_secdesc
.in
.secinfo_flags
=
1172 status
= smb2_getinfo_file(tree
, tctx
, &q
);
1173 CHECK_STATUS(status
, NT_STATUS_OK
);
1176 * Testing the created DACL,
1177 * the server should add the inherited DACL
1178 * when SEC_DESC_DACL_PRESENT isn't specified
1180 if (!(q
.query_secdesc
.out
.sd
->type
& SEC_DESC_DACL_PRESENT
)) {
1182 torture_fail_goto(tctx
, done
, "DACL_PRESENT flag not set by the server!\n");
1184 if (q
.query_secdesc
.out
.sd
->dacl
== NULL
) {
1186 torture_fail_goto(tctx
, done
, "no DACL has been created on the server!\n");
1189 torture_comment(tctx
, "set NULL DACL\n");
1190 sd
->type
|= SEC_DESC_DACL_PRESENT
;
1192 s
.set_secdesc
.level
= RAW_SFILEINFO_SEC_DESC
;
1193 s
.set_secdesc
.in
.file
.handle
= handle
;
1194 s
.set_secdesc
.in
.secinfo_flags
= SECINFO_DACL
;
1195 s
.set_secdesc
.in
.sd
= sd
;
1196 status
= smb2_setinfo_file(tree
, &s
);
1197 CHECK_STATUS(status
, NT_STATUS_OK
);
1199 torture_comment(tctx
, "get the sd\n");
1200 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
1201 q
.query_secdesc
.in
.file
.handle
= handle
;
1202 q
.query_secdesc
.in
.secinfo_flags
=
1206 status
= smb2_getinfo_file(tree
, tctx
, &q
);
1207 CHECK_STATUS(status
, NT_STATUS_OK
);
1209 /* Testing the modified DACL */
1210 if (!(q
.query_secdesc
.out
.sd
->type
& SEC_DESC_DACL_PRESENT
)) {
1212 torture_fail_goto(tctx
, done
, "DACL_PRESENT flag not set by the server!\n");
1214 if (q
.query_secdesc
.out
.sd
->dacl
!= NULL
) {
1216 torture_fail_goto(tctx
, done
, "DACL has been created on the server!\n");
1219 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
1221 torture_comment(tctx
, "try open for read control\n");
1222 io
.in
.desired_access
= SEC_STD_READ_CONTROL
;
1223 status
= smb2_create(tree
, tctx
, &io
);
1224 CHECK_STATUS(status
, NT_STATUS_OK
);
1225 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1226 SEC_STD_READ_CONTROL
);
1227 smb2_util_close(tree
, io
.out
.file
.handle
);
1229 torture_comment(tctx
, "try open for write\n");
1230 io
.in
.desired_access
= SEC_FILE_WRITE_DATA
;
1231 status
= smb2_create(tree
, tctx
, &io
);
1232 CHECK_STATUS(status
, NT_STATUS_OK
);
1233 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1234 SEC_FILE_WRITE_DATA
);
1235 smb2_util_close(tree
, io
.out
.file
.handle
);
1237 torture_comment(tctx
, "try open for read\n");
1238 io
.in
.desired_access
= SEC_FILE_READ_DATA
;
1239 status
= smb2_create(tree
, tctx
, &io
);
1240 CHECK_STATUS(status
, NT_STATUS_OK
);
1241 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1242 SEC_FILE_READ_DATA
);
1243 smb2_util_close(tree
, io
.out
.file
.handle
);
1245 torture_comment(tctx
, "try open for generic write\n");
1246 io
.in
.desired_access
= SEC_GENERIC_WRITE
;
1247 status
= smb2_create(tree
, tctx
, &io
);
1248 CHECK_STATUS(status
, NT_STATUS_OK
);
1249 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1250 SEC_RIGHTS_FILE_WRITE
);
1251 smb2_util_close(tree
, io
.out
.file
.handle
);
1253 torture_comment(tctx
, "try open for generic read\n");
1254 io
.in
.desired_access
= SEC_GENERIC_READ
;
1255 status
= smb2_create(tree
, tctx
, &io
);
1256 CHECK_STATUS(status
, NT_STATUS_OK
);
1257 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1258 SEC_RIGHTS_FILE_READ
);
1259 smb2_util_close(tree
, io
.out
.file
.handle
);
1261 torture_comment(tctx
, "set DACL with 0 aces\n");
1263 dacl
.revision
= SECURITY_ACL_REVISION_NT4
;
1267 s
.set_secdesc
.level
= RAW_SFILEINFO_SEC_DESC
;
1268 s
.set_secdesc
.in
.file
.handle
= handle
;
1269 s
.set_secdesc
.in
.secinfo_flags
= SECINFO_DACL
;
1270 s
.set_secdesc
.in
.sd
= sd
;
1271 status
= smb2_setinfo_file(tree
, &s
);
1272 CHECK_STATUS(status
, NT_STATUS_OK
);
1274 torture_comment(tctx
, "get the sd\n");
1275 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
1276 q
.query_secdesc
.in
.file
.handle
= handle
;
1277 q
.query_secdesc
.in
.secinfo_flags
=
1281 status
= smb2_getinfo_file(tree
, tctx
, &q
);
1282 CHECK_STATUS(status
, NT_STATUS_OK
);
1284 /* Testing the modified DACL */
1285 if (!(q
.query_secdesc
.out
.sd
->type
& SEC_DESC_DACL_PRESENT
)) {
1287 torture_fail_goto(tctx
, done
, "DACL_PRESENT flag not set by the server!\n");
1289 if (q
.query_secdesc
.out
.sd
->dacl
== NULL
) {
1291 torture_fail_goto(tctx
, done
, "no DACL has been created on the server!\n");
1293 if (q
.query_secdesc
.out
.sd
->dacl
->num_aces
!= 0) {
1294 torture_result(tctx
, TORTURE_FAIL
, "DACL has %u aces!\n",
1295 q
.query_secdesc
.out
.sd
->dacl
->num_aces
);
1300 torture_comment(tctx
, "try open for read control\n");
1301 io
.in
.desired_access
= SEC_STD_READ_CONTROL
;
1302 status
= smb2_create(tree
, tctx
, &io
);
1303 CHECK_STATUS(status
, NT_STATUS_OK
);
1304 CHECK_ACCESS_FLAGS(io
.out
.file
.handle
,
1305 SEC_STD_READ_CONTROL
);
1306 smb2_util_close(tree
, io
.out
.file
.handle
);
1308 torture_comment(tctx
, "try open for write => access_denied\n");
1309 io
.in
.desired_access
= SEC_FILE_WRITE_DATA
;
1310 status
= smb2_create(tree
, tctx
, &io
);
1311 if (torture_setting_bool(tctx
, "hide_on_access_denied", false)) {
1312 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1314 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
1317 torture_comment(tctx
, "try open for read => access_denied\n");
1318 io
.in
.desired_access
= SEC_FILE_READ_DATA
;
1319 status
= smb2_create(tree
, tctx
, &io
);
1320 if (torture_setting_bool(tctx
, "hide_on_access_denied", false)) {
1321 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1323 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
1326 torture_comment(tctx
, "try open for generic write => access_denied\n");
1327 io
.in
.desired_access
= SEC_GENERIC_WRITE
;
1328 status
= smb2_create(tree
, tctx
, &io
);
1329 if (torture_setting_bool(tctx
, "hide_on_access_denied", false)) {
1330 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1332 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
1335 torture_comment(tctx
, "try open for generic read => access_denied\n");
1336 io
.in
.desired_access
= SEC_GENERIC_READ
;
1337 status
= smb2_create(tree
, tctx
, &io
);
1338 if (torture_setting_bool(tctx
, "hide_on_access_denied", false)) {
1339 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1341 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
1344 torture_comment(tctx
, "set empty sd\n");
1345 sd
->type
&= ~SEC_DESC_DACL_PRESENT
;
1348 s
.set_secdesc
.level
= RAW_SFILEINFO_SEC_DESC
;
1349 s
.set_secdesc
.in
.file
.handle
= handle
;
1350 s
.set_secdesc
.in
.secinfo_flags
= SECINFO_DACL
;
1351 s
.set_secdesc
.in
.sd
= sd
;
1352 status
= smb2_setinfo_file(tree
, &s
);
1353 CHECK_STATUS(status
, NT_STATUS_OK
);
1355 torture_comment(tctx
, "get the sd\n");
1356 q
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
1357 q
.query_secdesc
.in
.file
.handle
= handle
;
1358 q
.query_secdesc
.in
.secinfo_flags
=
1362 status
= smb2_getinfo_file(tree
, tctx
, &q
);
1363 CHECK_STATUS(status
, NT_STATUS_OK
);
1365 /* Testing the modified DACL */
1366 if (!(q
.query_secdesc
.out
.sd
->type
& SEC_DESC_DACL_PRESENT
)) {
1368 torture_fail_goto(tctx
, done
, "DACL_PRESENT flag not set by the server!\n");
1370 if (q
.query_secdesc
.out
.sd
->dacl
!= NULL
) {
1372 torture_fail_goto(tctx
, done
, "DACL has been created on the server!\n");
1375 smb2_util_close(tree
, handle
);
1376 smb2_util_unlink(tree
, fname
);
1378 smb2_logoff(tree
->session
);
1383 basic testing of SMB2 read
1385 struct torture_suite
*torture_smb2_create_init(void)
1387 struct torture_suite
*suite
= torture_suite_create(talloc_autofree_context(), "create");
1389 torture_suite_add_1smb2_test(suite
, "gentest", test_create_gentest
);
1390 torture_suite_add_1smb2_test(suite
, "blob", test_create_blob
);
1391 torture_suite_add_1smb2_test(suite
, "open", test_smb2_open
);
1392 torture_suite_add_1smb2_test(suite
, "brlocked", test_smb2_open_brlocked
);
1393 torture_suite_add_1smb2_test(suite
, "multi", test_smb2_open_multi
);
1394 torture_suite_add_1smb2_test(suite
, "delete", test_smb2_open_for_delete
);
1395 torture_suite_add_1smb2_test(suite
, "leading-slash", test_smb2_leading_slash
);
1396 torture_suite_add_1smb2_test(suite
, "aclfile", test_create_acl_file
);
1397 torture_suite_add_1smb2_test(suite
, "acldir", test_create_acl_dir
);
1398 torture_suite_add_1smb2_test(suite
, "nulldacl", test_create_null_dacl
);
1400 suite
->description
= talloc_strdup(suite
, "SMB2-CREATE tests");