summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorZack Kirsch <zack.kirsch@isilon.com>2009-07-04 16:16:23 -0700
committerTim Prouty <tprouty@samba.org>2009-12-07 16:54:16 -0800
commitd252d23ff15577e2c7049181b5b30692c4bcd6bc (patch)
tree0fa17dedd67aa45046abc8639958537d27b6bdb3 /source4
parent8ceb428c5568bd690cb6811a0618f7866633705b (diff)
downloadsamba-d252d23ff15577e2c7049181b5b30692c4bcd6bc.tar.gz
samba-d252d23ff15577e2c7049181b5b30692c4bcd6bc.tar.bz2
samba-d252d23ff15577e2c7049181b5b30692c4bcd6bc.zip
s4 torture: Port RAW-ACLS tests to SMB2
- The smblsa calls had to be commented out for now and should be fixed later, but they aren't crucial to the test. - The first two tests from RAW-ACLS were already ported to torture_smb2_setinfo() and test_create_acl(). Modifications were made similar to the RAW-ACLS changes. - test_sd_get_set() was ported, but does not pass against XP or Vista; it is not added to the SMB2-ACLS test suite. - printf -> torture_comment / torture_warning / torture_result
Diffstat (limited to 'source4')
-rw-r--r--source4/torture/smb2/acls.c1874
-rw-r--r--source4/torture/smb2/config.mk1
-rw-r--r--source4/torture/smb2/create.c607
-rw-r--r--source4/torture/smb2/setinfo.c89
-rw-r--r--source4/torture/smb2/smb2.c1
-rw-r--r--source4/torture/smb2/util.c77
6 files changed, 2419 insertions, 230 deletions
diff --git a/source4/torture/smb2/acls.c b/source4/torture/smb2/acls.c
new file mode 100644
index 0000000000..b565a5bce9
--- /dev/null
+++ b/source4/torture/smb2/acls.c
@@ -0,0 +1,1874 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ test security descriptor operations for SMB2
+
+ Copyright (C) Zack Kirsch 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "libcli/smb2/smb2.h"
+#include "libcli/smb2/smb2_calls.h"
+#include "torture/torture.h"
+#include "torture/util.h"
+#include "torture/smb2/proto.h"
+#include "libcli/security/security.h"
+#include "librpc/gen_ndr/ndr_security.h"
+
+#define CHECK_STATUS(status, correct) do { \
+ if (!NT_STATUS_EQUAL(status, correct)) { \
+ torture_result(tctx, TORTURE_FAIL, "(%s) Incorrect status %s - should be %s\n", \
+ __location__, nt_errstr(status), nt_errstr(correct)); \
+ ret = false; \
+ goto done; \
+ }} while (0)
+
+#define BASEDIR "smb2-testsd"
+
+#define CHECK_ACCESS_IGNORE SEC_STD_SYNCHRONIZE
+
+#define CHECK_ACCESS_FLAGS(_fh, flags) do { \
+ union smb_fileinfo _q; \
+ _q.access_information.level = RAW_FILEINFO_ACCESS_INFORMATION; \
+ _q.access_information.in.file.handle = (_fh); \
+ status = smb2_getinfo_file(tree, tctx, &_q); \
+ CHECK_STATUS(status, NT_STATUS_OK); \
+ /* Handle a Vista bug where SEC_STD_SYNCHRONIZE doesn't come back. */ \
+ if (((flags & CHECK_ACCESS_IGNORE) == CHECK_ACCESS_IGNORE) && \
+ ((_q.access_information.out.access_flags & CHECK_ACCESS_IGNORE) != CHECK_ACCESS_IGNORE)) { \
+ torture_comment(tctx, "SKIPPING (Vista bug): (%s) Incorrect access_flags 0x%08x - should be 0x%08x\n", \
+ __location__, _q.access_information.out.access_flags, (flags)); \
+ } \
+ if ((_q.access_information.out.access_flags & ~CHECK_ACCESS_IGNORE) != \
+ ((flags & ~CHECK_ACCESS_IGNORE))) { \
+ torture_result(tctx, TORTURE_FAIL, "(%s) Incorrect access_flags 0x%08x - should be 0x%08x\n", \
+ __location__, _q.access_information.out.access_flags, (flags)); \
+ ret = false; \
+ goto done; \
+ } \
+} while (0)
+
+#define FAIL_UNLESS(__cond) \
+ do { \
+ if (__cond) {} else { \
+ torture_result(tctx, TORTURE_FAIL, "%s) condition violated: %s\n", \
+ __location__, #__cond); \
+ ret = false; goto done; \
+ } \
+ } while(0)
+
+#define CHECK_SECURITY_DESCRIPTOR(_sd1, _sd2) do { \
+ if (!security_descriptor_equal(_sd1, _sd2)) { \
+ torture_warning(tctx, "%s: security descriptors don't match!\n", __location__); \
+ torture_warning(tctx, "got:\n"); \
+ NDR_PRINT_DEBUG(security_descriptor, _sd1); \
+ torture_warning(tctx, "expected:\n"); \
+ NDR_PRINT_DEBUG(security_descriptor, _sd2); \
+ ret = false; \
+ } \
+} while (0)
+
+/*
+ test the behaviour of the well known SID_CREATOR_OWNER sid, and some generic
+ mapping bits
+ Note: This test was copied from raw/acls.c.
+*/
+static bool test_creator_sid(struct torture_context *tctx, struct smb2_tree *tree)
+{
+ NTSTATUS status;
+ struct smb2_create io;
+ const char *fname = BASEDIR "\\creator.txt";
+ bool ret = true;
+ struct smb2_handle handle;
+ union smb_fileinfo q;
+ union smb_setfileinfo set;
+ struct security_descriptor *sd, *sd_orig, *sd2;
+ const char *owner_sid;
+
+ if (!smb2_util_setup_dir(tctx, tree, BASEDIR))
+ return false;
+
+ torture_comment(tctx, "TESTING SID_CREATOR_OWNER\n");
+
+ ZERO_STRUCT(io);
+ io.level = RAW_OPEN_SMB2;
+ io.in.create_flags = 0;
+ io.in.desired_access = SEC_STD_READ_CONTROL | SEC_STD_WRITE_DAC | SEC_STD_WRITE_OWNER;
+ io.in.create_options = 0;
+ io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+ io.in.share_access = NTCREATEX_SHARE_ACCESS_DELETE |
+ NTCREATEX_SHARE_ACCESS_READ |
+ NTCREATEX_SHARE_ACCESS_WRITE;
+ io.in.alloc_size = 0;
+ io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
+ io.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.in.security_flags = 0;
+ io.in.fname = fname;
+
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle = io.out.file.handle;
+
+ torture_comment(tctx, "get the original sd\n");
+ q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ q.query_secdesc.in.file.handle = handle;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ sd_orig = q.query_secdesc.out.sd;
+
+ owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
+
+ torture_comment(tctx, "set a sec desc allowing no write by CREATOR_OWNER\n");
+ sd = security_descriptor_dacl_create(tctx,
+ 0, NULL, NULL,
+ SID_CREATOR_OWNER,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_RIGHTS_FILE_READ | SEC_STD_ALL,
+ 0,
+ NULL);
+
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ set.set_secdesc.in.sd = sd;
+
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ torture_comment(tctx, "try open for write\n");
+ io.in.desired_access = SEC_FILE_WRITE_DATA;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+ torture_comment(tctx, "try open for read\n");
+ io.in.desired_access = SEC_FILE_READ_DATA;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+ torture_comment(tctx, "try open for generic write\n");
+ io.in.desired_access = SEC_GENERIC_WRITE;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+ torture_comment(tctx, "try open for generic read\n");
+ io.in.desired_access = SEC_GENERIC_READ;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+ torture_comment(tctx, "set a sec desc allowing no write by owner\n");
+ sd = security_descriptor_dacl_create(tctx,
+ 0, owner_sid, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_RIGHTS_FILE_READ | SEC_STD_ALL,
+ 0,
+ NULL);
+
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ set.set_secdesc.in.sd = sd;
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ torture_comment(tctx, "check that sd has been mapped correctly\n");
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd);
+
+ torture_comment(tctx, "try open for write\n");
+ io.in.desired_access = SEC_FILE_WRITE_DATA;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+ torture_comment(tctx, "try open for read\n");
+ io.in.desired_access = SEC_FILE_READ_DATA;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle,
+ SEC_FILE_READ_DATA);
+ smb2_util_close(tree, io.out.file.handle);
+
+ torture_comment(tctx, "try open for generic write\n");
+ io.in.desired_access = SEC_GENERIC_WRITE;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+ torture_comment(tctx, "try open for generic read\n");
+ io.in.desired_access = SEC_GENERIC_READ;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle,
+ SEC_RIGHTS_FILE_READ);
+ smb2_util_close(tree, io.out.file.handle);
+
+ torture_comment(tctx, "set a sec desc allowing generic read by owner\n");
+ sd = security_descriptor_dacl_create(tctx,
+ 0, NULL, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_GENERIC_READ | SEC_STD_ALL,
+ 0,
+ NULL);
+
+ set.set_secdesc.in.sd = sd;
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ torture_comment(tctx, "check that generic read has been mapped correctly\n");
+ sd2 = security_descriptor_dacl_create(tctx,
+ 0, owner_sid, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_RIGHTS_FILE_READ | SEC_STD_ALL,
+ 0,
+ NULL);
+
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
+
+ torture_comment(tctx, "try open for write\n");
+ io.in.desired_access = SEC_FILE_WRITE_DATA;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+ torture_comment(tctx, "try open for read\n");
+ io.in.desired_access = SEC_FILE_READ_DATA;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle,
+ SEC_FILE_READ_DATA);
+ smb2_util_close(tree, io.out.file.handle);
+
+ torture_comment(tctx, "try open for generic write\n");
+ io.in.desired_access = SEC_GENERIC_WRITE;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+ torture_comment(tctx, "try open for generic read\n");
+ io.in.desired_access = SEC_GENERIC_READ;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle, SEC_RIGHTS_FILE_READ);
+ smb2_util_close(tree, io.out.file.handle);
+
+
+ torture_comment(tctx, "put back original sd\n");
+ set.set_secdesc.in.sd = sd_orig;
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+
+done:
+ smb2_util_close(tree, handle);
+ smb2_deltree(tree, BASEDIR);
+ smb2_tdis(tree);
+ smb2_logoff(tree->session);
+ return ret;
+}
+
+
+/*
+ test the mapping of the SEC_GENERIC_xx bits to SEC_STD_xx and
+ SEC_FILE_xx bits
+ Note: This test was copied from raw/acls.c.
+*/
+static bool test_generic_bits(struct torture_context *tctx, struct smb2_tree *tree)
+{
+ NTSTATUS status;
+ struct smb2_create io;
+ const char *fname = BASEDIR "\\generic.txt";
+ bool ret = true;
+ struct smb2_handle handle;
+ int i;
+ union smb_fileinfo q;
+ union smb_setfileinfo set;
+ struct security_descriptor *sd, *sd_orig, *sd2;
+ const char *owner_sid;
+ const struct {
+ uint32_t gen_bits;
+ uint32_t specific_bits;
+ } file_mappings[] = {
+ { 0, 0 },
+ { SEC_GENERIC_READ, SEC_RIGHTS_FILE_READ },
+ { SEC_GENERIC_WRITE, SEC_RIGHTS_FILE_WRITE },
+ { SEC_GENERIC_EXECUTE, SEC_RIGHTS_FILE_EXECUTE },
+ { SEC_GENERIC_ALL, SEC_RIGHTS_FILE_ALL },
+ { SEC_FILE_READ_DATA, SEC_FILE_READ_DATA },
+ { SEC_FILE_READ_ATTRIBUTE, SEC_FILE_READ_ATTRIBUTE }
+ };
+ const struct {
+ uint32_t gen_bits;
+ uint32_t specific_bits;
+ } dir_mappings[] = {
+ { 0, 0 },
+ { SEC_GENERIC_READ, SEC_RIGHTS_DIR_READ },
+ { SEC_GENERIC_WRITE, SEC_RIGHTS_DIR_WRITE },
+ { SEC_GENERIC_EXECUTE, SEC_RIGHTS_DIR_EXECUTE },
+ { SEC_GENERIC_ALL, SEC_RIGHTS_DIR_ALL }
+ };
+ bool has_restore_privilege = false;
+ bool has_take_ownership_privilege = false;
+
+ if (!smb2_util_setup_dir(tctx, tree, BASEDIR))
+ return false;
+
+ torture_comment(tctx, "TESTING FILE GENERIC BITS\n");
+
+ ZERO_STRUCT(io);
+ io.level = RAW_OPEN_SMB2;
+ io.in.create_flags = 0;
+ io.in.desired_access =
+ SEC_STD_READ_CONTROL |
+ SEC_STD_WRITE_DAC |
+ SEC_STD_WRITE_OWNER;
+ io.in.create_options = 0;
+ io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+ io.in.share_access =
+ NTCREATEX_SHARE_ACCESS_READ |
+ NTCREATEX_SHARE_ACCESS_WRITE;
+ io.in.alloc_size = 0;
+ io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
+ io.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.in.security_flags = 0;
+ io.in.fname = fname;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle = io.out.file.handle;
+
+ torture_comment(tctx, "get the original sd\n");
+ q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ q.query_secdesc.in.file.handle = handle;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ sd_orig = q.query_secdesc.out.sd;
+
+ owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
+
+/*
+ * XXX: The smblsa calls use SMB as their transport - need to get rid of
+ * dependency.
+ */
+/*
+ status = smblsa_sid_check_privilege(cli,
+ owner_sid,
+ sec_privilege_name(SEC_PRIV_RESTORE));
+ has_restore_privilege = NT_STATUS_IS_OK(status);
+ if (!NT_STATUS_IS_OK(status)) {
+ torture_warning(tctx, "smblsa_sid_check_privilege - %s\n", nt_errstr(status));
+ }
+ torture_comment(tctx, "SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
+
+ status = smblsa_sid_check_privilege(cli,
+ owner_sid,
+ sec_privilege_name(SEC_PRIV_TAKE_OWNERSHIP));
+ has_take_ownership_privilege = NT_STATUS_IS_OK(status);
+ if (!NT_STATUS_IS_OK(status)) {
+ torture_warning(tctx, "smblsa_sid_check_privilege - %s\n", nt_errstr(status));
+ }
+ torture_comment(tctx, "SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
+*/
+
+ for (i=0;i<ARRAY_SIZE(file_mappings);i++) {
+ uint32_t expected_mask =
+ SEC_STD_WRITE_DAC |
+ SEC_STD_READ_CONTROL |
+ SEC_FILE_READ_ATTRIBUTE |
+ SEC_STD_DELETE;
+ uint32_t expected_mask_anon = SEC_FILE_READ_ATTRIBUTE;
+
+ if (has_restore_privilege) {
+ expected_mask_anon |= SEC_STD_DELETE;
+ }
+
+ torture_comment(tctx, "testing generic bits 0x%08x\n",
+ file_mappings[i].gen_bits);
+ sd = security_descriptor_dacl_create(tctx,
+ 0, owner_sid, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ file_mappings[i].gen_bits,
+ 0,
+ NULL);
+
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ set.set_secdesc.in.sd = sd;
+
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ sd2 = security_descriptor_dacl_create(tctx,
+ 0, owner_sid, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ file_mappings[i].specific_bits,
+ 0,
+ NULL);
+
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
+
+ io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle,
+ expected_mask | file_mappings[i].specific_bits);
+ smb2_util_close(tree, io.out.file.handle);
+
+ if (!has_take_ownership_privilege) {
+ continue;
+ }
+
+ torture_comment(tctx, "testing generic bits 0x%08x (anonymous)\n",
+ file_mappings[i].gen_bits);
+ sd = security_descriptor_dacl_create(tctx,
+ 0, SID_NT_ANONYMOUS, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ file_mappings[i].gen_bits,
+ 0,
+ NULL);
+
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ set.set_secdesc.in.sd = sd;
+
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ sd2 = security_descriptor_dacl_create(tctx,
+ 0, SID_NT_ANONYMOUS, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ file_mappings[i].specific_bits,
+ 0,
+ NULL);
+
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
+
+ io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle,
+ expected_mask_anon | file_mappings[i].specific_bits);
+ smb2_util_close(tree, io.out.file.handle);
+ }
+
+ torture_comment(tctx, "put back original sd\n");
+ set.set_secdesc.in.sd = sd_orig;
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ smb2_util_close(tree, handle);
+ smb2_util_unlink(tree, fname);
+
+
+ torture_comment(tctx, "TESTING DIR GENERIC BITS\n");
+
+ ZERO_STRUCT(io);
+ io.level = RAW_OPEN_SMB2;
+ io.in.create_flags = 0;
+ io.in.desired_access =
+ SEC_STD_READ_CONTROL |
+ SEC_STD_WRITE_DAC |
+ SEC_STD_WRITE_OWNER;
+ io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+ io.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
+ io.in.share_access =
+ NTCREATEX_SHARE_ACCESS_READ |
+ NTCREATEX_SHARE_ACCESS_WRITE;
+ io.in.alloc_size = 0;
+ io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
+ io.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.in.security_flags = 0;
+ io.in.fname = fname;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle = io.out.file.handle;
+
+ torture_comment(tctx, "get the original sd\n");
+ q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ q.query_secdesc.in.file.handle = handle;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ sd_orig = q.query_secdesc.out.sd;
+
+ owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
+
+/*
+ * XXX: The smblsa calls use SMB as their transport - need to get rid of
+ * dependency.
+ */
+/*
+ status = smblsa_sid_check_privilege(cli,
+ owner_sid,
+ sec_privilege_name(SEC_PRIV_RESTORE));
+ has_restore_privilege = NT_STATUS_IS_OK(status);
+ if (!NT_STATUS_IS_OK(status)) {
+ torture_warning(tctx, "smblsa_sid_check_privilege - %s\n", nt_errstr(status));
+ }
+ torture_comment(tctx, "SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
+
+ status = smblsa_sid_check_privilege(cli,
+ owner_sid,
+ sec_privilege_name(SEC_PRIV_TAKE_OWNERSHIP));
+ has_take_ownership_privilege = NT_STATUS_IS_OK(status);
+ if (!NT_STATUS_IS_OK(status)) {
+ torture_warning(tctx, "smblsa_sid_check_privilege - %s\n", nt_errstr(status));
+ }
+ torture_comment(tctx, "SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
+
+*/
+ for (i=0;i<ARRAY_SIZE(dir_mappings);i++) {
+ uint32_t expected_mask =
+ SEC_STD_WRITE_DAC |
+ SEC_STD_READ_CONTROL |
+ SEC_FILE_READ_ATTRIBUTE |
+ SEC_STD_DELETE;
+ uint32_t expected_mask_anon = SEC_FILE_READ_ATTRIBUTE;
+
+ if (has_restore_privilege) {
+ expected_mask_anon |= SEC_STD_DELETE;
+ }
+
+ torture_comment(tctx, "testing generic bits 0x%08x\n",
+ file_mappings[i].gen_bits);
+ sd = security_descriptor_dacl_create(tctx,
+ 0, owner_sid, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ dir_mappings[i].gen_bits,
+ 0,
+ NULL);
+
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ set.set_secdesc.in.sd = sd;
+
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ sd2 = security_descriptor_dacl_create(tctx,
+ 0, owner_sid, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ dir_mappings[i].specific_bits,
+ 0,
+ NULL);
+
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
+
+ io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle,
+ expected_mask | dir_mappings[i].specific_bits);
+ smb2_util_close(tree, io.out.file.handle);
+
+ if (!has_take_ownership_privilege) {
+ continue;
+ }
+
+ torture_comment(tctx, "testing generic bits 0x%08x (anonymous)\n",
+ file_mappings[i].gen_bits);
+ sd = security_descriptor_dacl_create(tctx,
+ 0, SID_NT_ANONYMOUS, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ file_mappings[i].gen_bits,
+ 0,
+ NULL);
+
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ set.set_secdesc.in.sd = sd;
+
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ sd2 = security_descriptor_dacl_create(tctx,
+ 0, SID_NT_ANONYMOUS, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ file_mappings[i].specific_bits,
+ 0,
+ NULL);
+
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
+
+ io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle,
+ expected_mask_anon | dir_mappings[i].specific_bits);
+ smb2_util_close(tree, io.out.file.handle);
+ }
+
+ torture_comment(tctx, "put back original sd\n");
+ set.set_secdesc.in.sd = sd_orig;
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ smb2_util_close(tree, handle);
+ smb2_util_unlink(tree, fname);
+
+done:
+ smb2_util_close(tree, handle);
+ smb2_deltree(tree, BASEDIR);
+ smb2_tdis(tree);
+ smb2_logoff(tree->session);
+ return ret;
+}
+
+
+/*
+ see what access bits the owner of a file always gets
+ Note: This test was copied from raw/acls.c.
+*/
+static bool test_owner_bits(struct torture_context *tctx, struct smb2_tree *tree)
+{
+ NTSTATUS status;
+ struct smb2_create io;
+ const char *fname = BASEDIR "\\test_owner_bits.txt";
+ bool ret = true;
+ struct smb2_handle handle;
+ int i;
+ union smb_fileinfo q;
+ union smb_setfileinfo set;
+ struct security_descriptor *sd, *sd_orig;
+ const char *owner_sid;
+ bool has_restore_privilege = false;
+ bool has_take_ownership_privilege = false;
+ uint32_t expected_bits;
+
+ if (!smb2_util_setup_dir(tctx, tree, BASEDIR))
+ return false;
+
+ torture_comment(tctx, "TESTING FILE OWNER BITS\n");
+
+ ZERO_STRUCT(io);
+ io.level = RAW_OPEN_SMB2;
+ io.in.create_flags = 0;
+ io.in.desired_access =
+ SEC_STD_READ_CONTROL |
+ SEC_STD_WRITE_DAC |
+ SEC_STD_WRITE_OWNER;
+ io.in.create_options = 0;
+ io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+ io.in.share_access =
+ NTCREATEX_SHARE_ACCESS_READ |
+ NTCREATEX_SHARE_ACCESS_WRITE;
+ io.in.alloc_size = 0;
+ io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
+ io.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.in.security_flags = 0;
+ io.in.fname = fname;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle = io.out.file.handle;
+
+ torture_comment(tctx, "get the original sd\n");
+ q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ q.query_secdesc.in.file.handle = handle;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ sd_orig = q.query_secdesc.out.sd;
+
+ owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
+
+/*
+ * XXX: The smblsa calls use SMB as their transport - need to get rid of
+ * dependency.
+ */
+/*
+ status = smblsa_sid_check_privilege(cli,
+ owner_sid,
+ sec_privilege_name(SEC_PRIV_RESTORE));
+ has_restore_privilege = NT_STATUS_IS_OK(status);
+ if (!NT_STATUS_IS_OK(status)) {
+ torture_warning(tctx, "smblsa_sid_check_privilege - %s\n", nt_errstr(status));
+ }
+ torture_comment(tctx, "SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
+
+ status = smblsa_sid_check_privilege(cli,
+ owner_sid,
+ sec_privilege_name(SEC_PRIV_TAKE_OWNERSHIP));
+ has_take_ownership_privilege = NT_STATUS_IS_OK(status);
+ if (!NT_STATUS_IS_OK(status)) {
+ torture_warning(tctx, "smblsa_sid_check_privilege - %s\n", nt_errstr(status));
+ }
+ torture_comment(tctx, "SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
+*/
+
+ sd = security_descriptor_dacl_create(tctx,
+ 0, NULL, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_FILE_WRITE_DATA,
+ 0,
+ NULL);
+
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ set.set_secdesc.in.sd = sd;
+
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ expected_bits = SEC_FILE_WRITE_DATA | SEC_FILE_READ_ATTRIBUTE;
+
+ for (i=0;i<16;i++) {
+ uint32_t bit = (1<<i);
+ io.in.desired_access = bit;
+ status = smb2_create(tree, tctx, &io);
+ if (expected_bits & bit) {
+ if (!NT_STATUS_IS_OK(status)) {
+ torture_warning(tctx, "failed with access mask 0x%08x of expected 0x%08x\n",
+ bit, expected_bits);
+ }
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle, bit);
+ smb2_util_close(tree, io.out.file.handle);
+ } else {
+ if (NT_STATUS_IS_OK(status)) {
+ torture_warning(tctx, "open succeeded with access mask 0x%08x of "
+ "expected 0x%08x - should fail\n",
+ bit, expected_bits);
+ }
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+ }
+ }
+
+ torture_comment(tctx, "put back original sd\n");
+ set.set_secdesc.in.sd = sd_orig;
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+done:
+ smb2_util_close(tree, handle);
+ smb2_util_unlink(tree, fname);
+ smb2_deltree(tree, BASEDIR);
+ smb2_tdis(tree);
+ smb2_logoff(tree->session);
+ return ret;
+}
+
+
+
+/*
+ test the inheritance of ACL flags onto new files and directories
+ Note: This test was copied from raw/acls.c.
+*/
+static bool test_inheritance(struct torture_context *tctx, struct smb2_tree *tree)
+{
+ NTSTATUS status;
+ struct smb2_create io;
+ const char *dname = BASEDIR "\\inheritance";
+ const char *fname1 = BASEDIR "\\inheritance\\testfile";
+ const char *fname2 = BASEDIR "\\inheritance\\testdir";
+ bool ret = true;
+ struct smb2_handle handle, handle2;
+ int i;
+ union smb_fileinfo q;
+ union smb_setfileinfo set;
+ struct security_descriptor *sd, *sd2, *sd_orig=NULL, *sd_def1, *sd_def2;
+ const char *owner_sid;
+ const struct dom_sid *creator_owner;
+ const struct {
+ uint32_t parent_flags;
+ uint32_t file_flags;
+ uint32_t dir_flags;
+ } test_flags[] = {
+ {
+ 0,
+ 0,
+ 0
+ },
+ {
+ SEC_ACE_FLAG_OBJECT_INHERIT,
+ 0,
+ SEC_ACE_FLAG_OBJECT_INHERIT |
+ SEC_ACE_FLAG_INHERIT_ONLY,
+ },
+ {
+ SEC_ACE_FLAG_CONTAINER_INHERIT,
+ 0,
+ SEC_ACE_FLAG_CONTAINER_INHERIT,
+ },
+ {
+ SEC_ACE_FLAG_OBJECT_INHERIT |
+ SEC_ACE_FLAG_CONTAINER_INHERIT,
+ 0,
+ SEC_ACE_FLAG_OBJECT_INHERIT |
+ SEC_ACE_FLAG_CONTAINER_INHERIT,
+ },
+ {
+ SEC_ACE_FLAG_NO_PROPAGATE_INHERIT,
+ 0,
+ 0,
+ },
+ {
+ SEC_ACE_FLAG_NO_PROPAGATE_INHERIT |
+ SEC_ACE_FLAG_OBJECT_INHERIT,
+ 0,
+ 0,
+ },
+ {
+ SEC_ACE_FLAG_NO_PROPAGATE_INHERIT |
+ SEC_ACE_FLAG_CONTAINER_INHERIT,
+ 0,
+ 0,
+ },
+ {
+ SEC_ACE_FLAG_NO_PROPAGATE_INHERIT |
+ SEC_ACE_FLAG_CONTAINER_INHERIT |
+ SEC_ACE_FLAG_OBJECT_INHERIT,
+ 0,
+ 0,
+ },
+ {
+ SEC_ACE_FLAG_INHERIT_ONLY,
+ 0,
+ 0,
+ },
+ {
+ SEC_ACE_FLAG_INHERIT_ONLY |
+ SEC_ACE_FLAG_OBJECT_INHERIT,
+ 0,
+ SEC_ACE_FLAG_OBJECT_INHERIT |
+ SEC_ACE_FLAG_INHERIT_ONLY,
+ },
+ {
+ SEC_ACE_FLAG_INHERIT_ONLY |
+ SEC_ACE_FLAG_CONTAINER_INHERIT,
+ 0,
+ SEC_ACE_FLAG_CONTAINER_INHERIT,
+ },
+ {
+ SEC_ACE_FLAG_INHERIT_ONLY |
+ SEC_ACE_FLAG_CONTAINER_INHERIT |
+ SEC_ACE_FLAG_OBJECT_INHERIT,
+ 0,
+ SEC_ACE_FLAG_CONTAINER_INHERIT |
+ SEC_ACE_FLAG_OBJECT_INHERIT,
+ },
+ {
+ SEC_ACE_FLAG_INHERIT_ONLY |
+ SEC_ACE_FLAG_NO_PROPAGATE_INHERIT,
+ 0,
+ 0,
+ },
+ {
+ SEC_ACE_FLAG_INHERIT_ONLY |
+ SEC_ACE_FLAG_NO_PROPAGATE_INHERIT |
+ SEC_ACE_FLAG_OBJECT_INHERIT,
+ 0,
+ 0,
+ },
+ {
+ SEC_ACE_FLAG_INHERIT_ONLY |
+ SEC_ACE_FLAG_NO_PROPAGATE_INHERIT |
+ SEC_ACE_FLAG_CONTAINER_INHERIT,
+ 0,
+ 0,
+ },
+ {
+ SEC_ACE_FLAG_INHERIT_ONLY |
+ SEC_ACE_FLAG_NO_PROPAGATE_INHERIT |
+ SEC_ACE_FLAG_CONTAINER_INHERIT |
+ SEC_ACE_FLAG_OBJECT_INHERIT,
+ 0,
+ 0,
+ }
+ };
+
+ if (!smb2_util_setup_dir(tctx, tree, BASEDIR))
+ return false;
+
+ torture_comment(tctx, "TESTING ACL INHERITANCE\n");
+
+ ZERO_STRUCT(io);
+ io.level = RAW_OPEN_SMB2;
+ io.in.create_flags = 0;
+ io.in.desired_access = SEC_RIGHTS_FILE_ALL;
+ io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+ io.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
+ io.in.share_access = 0;
+ io.in.alloc_size = 0;
+ io.in.create_disposition = NTCREATEX_DISP_CREATE;
+ io.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.in.security_flags = 0;
+ io.in.fname = dname;
+
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle = io.out.file.handle;
+
+ torture_comment(tctx, "get the original sd\n");
+ q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ q.query_secdesc.in.file.handle = handle;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ sd_orig = q.query_secdesc.out.sd;
+
+ owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
+
+ torture_comment(tctx, "owner_sid is %s\n", owner_sid);
+
+ /*
+ * The Windows Default ACL for a new file, when there is no ACL to be
+ * inherited: FullControl for the owner and SYSTEM.
+ */
+ sd_def1 = security_descriptor_dacl_create(tctx,
+ 0, owner_sid, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_RIGHTS_FILE_ALL,
+ 0,
+ SID_NT_SYSTEM,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_RIGHTS_FILE_ALL,
+ 0,
+ NULL);
+
+ /*
+ * Use this in the case the system being tested does not add an ACE for
+ * the SYSTEM SID.
+ */
+ sd_def2 = security_descriptor_dacl_create(tctx,
+ 0, owner_sid, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_RIGHTS_FILE_ALL,
+ 0,
+ NULL);
+
+ creator_owner = dom_sid_parse_talloc(tctx, SID_CREATOR_OWNER);
+
+ for (i=0;i<ARRAY_SIZE(test_flags);i++) {
+ sd = security_descriptor_dacl_create(tctx,
+ 0, NULL, NULL,
+ SID_CREATOR_OWNER,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_FILE_WRITE_DATA,
+ test_flags[i].parent_flags,
+ SID_WORLD,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_FILE_ALL | SEC_STD_ALL,
+ 0,
+ NULL);
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ set.set_secdesc.in.sd = sd;
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ io.in.fname = fname1;
+ io.in.create_options = 0;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle2 = io.out.file.handle;
+
+ q.query_secdesc.in.file.handle = handle2;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ smb2_util_close(tree, handle2);
+ smb2_util_unlink(tree, fname1);
+
+ if (!(test_flags[i].parent_flags & SEC_ACE_FLAG_OBJECT_INHERIT)) {
+ if (!security_descriptor_equal(q.query_secdesc.out.sd, sd_def1) &&
+ !security_descriptor_equal(q.query_secdesc.out.sd, sd_def2)) {
+ torture_warning(tctx, "Expected default sd:\n");
+ NDR_PRINT_DEBUG(security_descriptor, sd_def1);
+ torture_warning(tctx, "at %d - got:\n", i);
+ NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
+ }
+ goto check_dir;
+ }
+
+ if (q.query_secdesc.out.sd->dacl == NULL ||
+ q.query_secdesc.out.sd->dacl->num_aces != 1 ||
+ q.query_secdesc.out.sd->dacl->aces[0].access_mask != SEC_FILE_WRITE_DATA ||
+ !dom_sid_equal(&q.query_secdesc.out.sd->dacl->aces[0].trustee,
+ sd_orig->owner_sid)) {
+ torture_warning(tctx, "Bad sd in child file at %d\n", i);
+ NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
+ ret = false;
+ goto check_dir;
+ }
+
+ if (q.query_secdesc.out.sd->dacl->aces[0].flags !=
+ test_flags[i].file_flags) {
+ torture_warning(tctx, "incorrect file_flags 0x%x - expected 0x%x for parent 0x%x with (i=%d)\n",
+ q.query_secdesc.out.sd->dacl->aces[0].flags,
+ test_flags[i].file_flags,
+ test_flags[i].parent_flags,
+ i);
+ ret = false;
+ }
+
+ check_dir:
+ io.in.fname = fname2;
+ io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle2 = io.out.file.handle;
+
+ q.query_secdesc.in.file.handle = handle2;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ smb2_util_close(tree, handle2);
+ smb2_util_rmdir(tree, fname2);
+
+ if (!(test_flags[i].parent_flags & SEC_ACE_FLAG_CONTAINER_INHERIT) &&
+ (!(test_flags[i].parent_flags & SEC_ACE_FLAG_OBJECT_INHERIT) ||
+ (test_flags[i].parent_flags & SEC_ACE_FLAG_NO_PROPAGATE_INHERIT))) {
+ if (!security_descriptor_equal(q.query_secdesc.out.sd, sd_def1) &&
+ !security_descriptor_equal(q.query_secdesc.out.sd, sd_def2)) {
+ torture_warning(tctx, "Expected default sd for dir at %d:\n", i);
+ NDR_PRINT_DEBUG(security_descriptor, sd_def1);
+ torture_warning(tctx, "got:\n");
+ NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
+ }
+ continue;
+ }
+
+ if ((test_flags[i].parent_flags & SEC_ACE_FLAG_CONTAINER_INHERIT) &&
+ (test_flags[i].parent_flags & SEC_ACE_FLAG_NO_PROPAGATE_INHERIT)) {
+ if (q.query_secdesc.out.sd->dacl == NULL ||
+ q.query_secdesc.out.sd->dacl->num_aces != 1 ||
+ q.query_secdesc.out.sd->dacl->aces[0].access_mask != SEC_FILE_WRITE_DATA ||
+ !dom_sid_equal(&q.query_secdesc.out.sd->dacl->aces[0].trustee,
+ sd_orig->owner_sid) ||
+ q.query_secdesc.out.sd->dacl->aces[0].flags != test_flags[i].dir_flags) {
+ torture_warning(tctx, "(CI & NP) Bad sd in child dir - expected 0x%x for parent 0x%x (i=%d)\n",
+ test_flags[i].dir_flags,
+ test_flags[i].parent_flags, i);
+ NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
+ torture_warning(tctx, "FYI, here is the parent sd:\n");
+ NDR_PRINT_DEBUG(security_descriptor, sd);
+ ret = false;
+ continue;
+ }
+ } else if (test_flags[i].parent_flags & SEC_ACE_FLAG_CONTAINER_INHERIT) {
+ if (q.query_secdesc.out.sd->dacl == NULL ||
+ q.query_secdesc.out.sd->dacl->num_aces != 2 ||
+ q.query_secdesc.out.sd->dacl->aces[0].access_mask != SEC_FILE_WRITE_DATA ||
+ !dom_sid_equal(&q.query_secdesc.out.sd->dacl->aces[0].trustee,
+ sd_orig->owner_sid) ||
+ q.query_secdesc.out.sd->dacl->aces[1].access_mask != SEC_FILE_WRITE_DATA ||
+ !dom_sid_equal(&q.query_secdesc.out.sd->dacl->aces[1].trustee,
+ creator_owner) ||
+ q.query_secdesc.out.sd->dacl->aces[0].flags != 0 ||
+ q.query_secdesc.out.sd->dacl->aces[1].flags !=
+ (test_flags[i].dir_flags | SEC_ACE_FLAG_INHERIT_ONLY)) {
+ torture_warning(tctx, "(CI) Bad sd in child dir - expected 0x%x for parent 0x%x (i=%d)\n",
+ test_flags[i].dir_flags,
+ test_flags[i].parent_flags, i);
+ NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
+ torture_warning(tctx, "FYI, here is the parent sd:\n");
+ NDR_PRINT_DEBUG(security_descriptor, sd);
+ ret = false;
+ continue;
+ }
+ } else {
+ if (q.query_secdesc.out.sd->dacl == NULL ||
+ q.query_secdesc.out.sd->dacl->num_aces != 1 ||
+ q.query_secdesc.out.sd->dacl->aces[0].access_mask != SEC_FILE_WRITE_DATA ||
+ !dom_sid_equal(&q.query_secdesc.out.sd->dacl->aces[0].trustee,
+ creator_owner) ||
+ q.query_secdesc.out.sd->dacl->aces[0].flags != test_flags[i].dir_flags) {
+ torture_warning(tctx, "(0) Bad sd in child dir - expected 0x%x for parent 0x%x (i=%d)\n",
+ test_flags[i].dir_flags,
+ test_flags[i].parent_flags, i);
+ NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
+ torture_warning(tctx, "FYI, here is the parent sd:\n");
+ NDR_PRINT_DEBUG(security_descriptor, sd);
+ ret = false;
+ continue;
+ }
+ }
+ }
+
+ torture_comment(tctx, "testing access checks on inherited create with %s\n", fname1);
+ sd = security_descriptor_dacl_create(tctx,
+ 0, NULL, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_FILE_WRITE_DATA | SEC_STD_WRITE_DAC,
+ SEC_ACE_FLAG_OBJECT_INHERIT,
+ SID_WORLD,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_FILE_ALL | SEC_STD_ALL,
+ 0,
+ NULL);
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ set.set_secdesc.in.sd = sd;
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ /* Check DACL we just set. */
+ torture_comment(tctx, "checking new sd\n");
+ q.query_secdesc.in.file.handle = handle;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd);
+
+ io.in.fname = fname1;
+ io.in.create_options = 0;
+ io.in.desired_access = SEC_RIGHTS_FILE_ALL;
+ io.in.create_disposition = NTCREATEX_DISP_CREATE;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle2 = io.out.file.handle;
+ CHECK_ACCESS_FLAGS(handle2, SEC_RIGHTS_FILE_ALL);
+
+ q.query_secdesc.in.file.handle = handle2;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ smb2_util_close(tree, handle2);
+
+ sd2 = security_descriptor_dacl_create(tctx,
+ 0, owner_sid, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_FILE_WRITE_DATA | SEC_STD_WRITE_DAC,
+ 0,
+ NULL);
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
+
+ io.in.create_disposition = NTCREATEX_DISP_OPEN;
+ io.in.desired_access = SEC_RIGHTS_FILE_ALL;
+ status = smb2_create(tree, tctx, &io);
+ if (NT_STATUS_IS_OK(status)) {
+ torture_warning(tctx, "failed: w2k3 ACL bug (allowed open when ACL should deny)\n");
+ ret = false;
+ handle2 = io.out.file.handle;
+ CHECK_ACCESS_FLAGS(handle2, SEC_RIGHTS_FILE_ALL);
+ smb2_util_close(tree, handle2);
+ } else {
+ if (TARGET_IS_WIN7(tctx)) {
+ CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+ } else {
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+ }
+ }
+
+ torture_comment(tctx, "trying without execute\n");
+ io.in.create_disposition = NTCREATEX_DISP_OPEN;
+ io.in.desired_access = SEC_RIGHTS_FILE_ALL & ~SEC_FILE_EXECUTE;
+ status = smb2_create(tree, tctx, &io);
+ if (TARGET_IS_WIN7(tctx)) {
+ CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+ } else {
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+ }
+
+ torture_comment(tctx, "and with full permissions again\n");
+ io.in.create_disposition = NTCREATEX_DISP_OPEN;
+ io.in.desired_access = SEC_RIGHTS_FILE_ALL;
+ status = smb2_create(tree, tctx, &io);
+ if (TARGET_IS_WIN7(tctx)) {
+ CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+ } else {
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+ }
+
+ io.in.desired_access = SEC_FILE_WRITE_DATA;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle2 = io.out.file.handle;
+ CHECK_ACCESS_FLAGS(handle2, SEC_FILE_WRITE_DATA);
+ smb2_util_close(tree, handle2);
+
+ torture_comment(tctx, "put back original sd\n");
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ set.set_secdesc.in.sd = sd_orig;
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ smb2_util_close(tree, handle);
+
+ io.in.desired_access = SEC_RIGHTS_FILE_ALL;
+ status = smb2_create(tree, tctx, &io);
+ if (TARGET_IS_WIN7(tctx)) {
+ CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+ } else {
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+ }
+
+ io.in.desired_access = SEC_FILE_WRITE_DATA;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle2 = io.out.file.handle;
+ CHECK_ACCESS_FLAGS(handle2, SEC_FILE_WRITE_DATA);
+ smb2_util_close(tree, handle2);
+
+ smb2_util_unlink(tree, fname1);
+ smb2_util_rmdir(tree, dname);
+
+done:
+ if (sd_orig != NULL) {
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ set.set_secdesc.in.sd = sd_orig;
+ status = smb2_setinfo_file(tree, &set);
+ }
+
+ smb2_util_close(tree, handle);
+ smb2_deltree(tree, BASEDIR);
+ smb2_tdis(tree);
+ smb2_logoff(tree->session);
+ return ret;
+}
+
+static bool test_inheritance_flags(struct torture_context *tctx,
+ struct smb2_tree *tree)
+{
+ NTSTATUS status;
+ struct smb2_create io;
+ const char *dname = BASEDIR "\\inheritance";
+ const char *fname1 = BASEDIR "\\inheritance\\testfile";
+ bool ret = true;
+ struct smb2_handle handle, handle2;
+ int i, j;
+ union smb_fileinfo q;
+ union smb_setfileinfo set;
+ struct security_descriptor *sd, *sd2, *sd_orig=NULL;
+ const char *owner_sid;
+ struct {
+ uint32_t parent_set_sd_type; /* 3 options */
+ uint32_t parent_set_ace_inherit; /* 1 option */
+ uint32_t parent_get_sd_type;
+ uint32_t parent_get_ace_inherit;
+ uint32_t child_get_sd_type;
+ uint32_t child_get_ace_inherit;
+ } tflags[16] = {0}; /* 2^4 */
+
+ for (i = 0; i < 15; i++) {
+ torture_comment(tctx, "i=%d:", i);
+
+ if (i & 1) {
+ tflags[i].parent_set_sd_type |=
+ SEC_DESC_DACL_AUTO_INHERITED;
+ torture_comment(tctx, "AUTO_INHERITED, ");
+ }
+ if (i & 2) {
+ tflags[i].parent_set_sd_type |=
+ SEC_DESC_DACL_AUTO_INHERIT_REQ;
+ torture_comment(tctx, "AUTO_INHERIT_REQ, ");
+ }
+ if (i & 4) {
+ tflags[i].parent_set_sd_type |=
+ SEC_DESC_DACL_PROTECTED;
+ torture_comment(tctx, "PROTECTED, ");
+ tflags[i].parent_get_sd_type |=
+ SEC_DESC_DACL_PROTECTED;
+ }
+ if (i & 8) {
+ tflags[i].parent_set_ace_inherit |=
+ SEC_ACE_FLAG_INHERITED_ACE;
+ torture_comment(tctx, "INHERITED, ");
+ tflags[i].parent_get_ace_inherit |=
+ SEC_ACE_FLAG_INHERITED_ACE;
+ }
+
+ if ((tflags[i].parent_set_sd_type &
+ (SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_DACL_AUTO_INHERIT_REQ)) ==
+ (SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_DACL_AUTO_INHERIT_REQ)) {
+ tflags[i].parent_get_sd_type |=
+ SEC_DESC_DACL_AUTO_INHERITED;
+ tflags[i].child_get_sd_type |=
+ SEC_DESC_DACL_AUTO_INHERITED;
+ tflags[i].child_get_ace_inherit |=
+ SEC_ACE_FLAG_INHERITED_ACE;
+ torture_comment(tctx, " ... parent is AUTO INHERITED");
+ }
+
+ if (tflags[i].parent_set_ace_inherit &
+ SEC_ACE_FLAG_INHERITED_ACE) {
+ tflags[i].parent_get_ace_inherit =
+ SEC_ACE_FLAG_INHERITED_ACE;
+ torture_comment(tctx, " ... parent ACE is INHERITED");
+ }
+
+ torture_comment(tctx, "\n");
+ }
+
+ if (!smb2_util_setup_dir(tctx, tree, BASEDIR))
+ return false;
+
+ torture_comment(tctx, "TESTING ACL INHERITANCE FLAGS\n");
+
+ ZERO_STRUCT(io);
+ io.level = RAW_OPEN_SMB2;
+ io.in.create_flags = 0;
+ io.in.desired_access = SEC_RIGHTS_FILE_ALL;
+ io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+ io.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
+ io.in.share_access = NTCREATEX_SHARE_ACCESS_MASK;
+ io.in.alloc_size = 0;
+ io.in.create_disposition = NTCREATEX_DISP_CREATE;
+ io.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.in.security_flags = 0;
+ io.in.fname = dname;
+
+ torture_comment(tctx, "creating initial directory %s\n", dname);
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle = io.out.file.handle;
+
+ torture_comment(tctx, "getting original sd\n");
+ q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ q.query_secdesc.in.file.handle = handle;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ sd_orig = q.query_secdesc.out.sd;
+
+ owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
+ torture_comment(tctx, "owner_sid is %s\n", owner_sid);
+
+ for (i=0; i < ARRAY_SIZE(tflags); i++) {
+ torture_comment(tctx, "setting a new sd on directory, pass #%d\n", i);
+
+ sd = security_descriptor_dacl_create(tctx,
+ tflags[i].parent_set_sd_type,
+ NULL, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_FILE_WRITE_DATA | SEC_STD_WRITE_DAC,
+ SEC_ACE_FLAG_OBJECT_INHERIT |
+ SEC_ACE_FLAG_CONTAINER_INHERIT |
+ tflags[i].parent_set_ace_inherit,
+ SID_WORLD,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_FILE_ALL | SEC_STD_ALL,
+ 0,
+ NULL);
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ set.set_secdesc.in.sd = sd;
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ /*
+ * Check DACL we just set, except change the bits to what they
+ * should be.
+ */
+ torture_comment(tctx, " checking new sd\n");
+
+ /* REQ bit should always be false. */
+ sd->type &= ~SEC_DESC_DACL_AUTO_INHERIT_REQ;
+
+ if ((tflags[i].parent_get_sd_type & SEC_DESC_DACL_AUTO_INHERITED) == 0)
+ sd->type &= ~SEC_DESC_DACL_AUTO_INHERITED;
+
+ q.query_secdesc.in.file.handle = handle;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd);
+
+ /* Create file. */
+ torture_comment(tctx, " creating file %s\n", fname1);
+ io.in.fname = fname1;
+ io.in.create_options = 0;
+ io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+ io.in.desired_access = SEC_RIGHTS_FILE_ALL;
+ io.in.create_disposition = NTCREATEX_DISP_CREATE;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle2 = io.out.file.handle;
+ CHECK_ACCESS_FLAGS(handle2, SEC_RIGHTS_FILE_ALL);
+
+ q.query_secdesc.in.file.handle = handle2;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ torture_comment(tctx, " checking sd on file %s\n", fname1);
+ sd2 = security_descriptor_dacl_create(tctx,
+ tflags[i].child_get_sd_type,
+ owner_sid, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_FILE_WRITE_DATA | SEC_STD_WRITE_DAC,
+ tflags[i].child_get_ace_inherit,
+ NULL);
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
+
+ /*
+ * Set new sd on file ... prove that the bits have nothing to
+ * do with the parents bits when manually setting an ACL. The
+ * _AUTO_INHERITED bit comes directly from the ACL set.
+ */
+ for (j = 0; j < ARRAY_SIZE(tflags); j++) {
+ torture_comment(tctx, " setting new file sd, pass #%d\n", j);
+
+ /* Change sd type. */
+ sd2->type &= ~(SEC_DESC_DACL_AUTO_INHERITED |
+ SEC_DESC_DACL_AUTO_INHERIT_REQ |
+ SEC_DESC_DACL_PROTECTED);
+ sd2->type |= tflags[j].parent_set_sd_type;
+
+ sd2->dacl->aces[0].flags &=
+ ~SEC_ACE_FLAG_INHERITED_ACE;
+ sd2->dacl->aces[0].flags |=
+ tflags[j].parent_set_ace_inherit;
+
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle2;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ set.set_secdesc.in.sd = sd2;
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ /* Check DACL we just set. */
+ sd2->type &= ~SEC_DESC_DACL_AUTO_INHERIT_REQ;
+ if ((tflags[j].parent_get_sd_type & SEC_DESC_DACL_AUTO_INHERITED) == 0)
+ sd2->type &= ~SEC_DESC_DACL_AUTO_INHERITED;
+
+ q.query_secdesc.in.file.handle = handle2;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
+ }
+
+ smb2_util_close(tree, handle2);
+ smb2_util_unlink(tree, fname1);
+ }
+
+done:
+ smb2_util_close(tree, handle);
+ smb2_deltree(tree, BASEDIR);
+ smb2_tdis(tree);
+ smb2_logoff(tree->session);
+ return ret;
+}
+
+/*
+ test dynamic acl inheritance
+ Note: This test was copied from raw/acls.c.
+*/
+static bool test_inheritance_dynamic(struct torture_context *tctx,
+ struct smb2_tree *tree)
+{
+ NTSTATUS status;
+ struct smb2_create io;
+ const char *dname = BASEDIR "\\inheritance";
+ const char *fname1 = BASEDIR "\\inheritance\\testfile";
+ bool ret = true;
+ struct smb2_handle handle, handle2;
+ union smb_fileinfo q;
+ union smb_setfileinfo set;
+ struct security_descriptor *sd, *sd_orig=NULL;
+ const char *owner_sid;
+
+ torture_comment(tctx, "TESTING DYNAMIC ACL INHERITANCE\n");
+
+ if (!smb2_util_setup_dir(tctx, tree, BASEDIR))
+ return false;
+
+ ZERO_STRUCT(io);
+ io.level = RAW_OPEN_SMB2;
+ io.in.create_flags = 0;
+ io.in.desired_access = SEC_RIGHTS_FILE_ALL;
+ io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+ io.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
+ io.in.share_access = 0;
+ io.in.alloc_size = 0;
+ io.in.create_disposition = NTCREATEX_DISP_CREATE;
+ io.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.in.security_flags = 0;
+ io.in.fname = dname;
+
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle = io.out.file.handle;
+
+ torture_comment(tctx, "get the original sd\n");
+ q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ q.query_secdesc.in.file.handle = handle;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ sd_orig = q.query_secdesc.out.sd;
+
+ owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
+
+ torture_comment(tctx, "owner_sid is %s\n", owner_sid);
+
+ sd = security_descriptor_dacl_create(tctx,
+ 0, NULL, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_FILE_WRITE_DATA | SEC_STD_DELETE | SEC_FILE_READ_ATTRIBUTE,
+ SEC_ACE_FLAG_OBJECT_INHERIT,
+ NULL);
+ sd->type |= SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_DACL_AUTO_INHERIT_REQ;
+
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ set.set_secdesc.in.sd = sd;
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ torture_comment(tctx, "create a file with an inherited acl\n");
+ io.in.fname = fname1;
+ io.in.create_options = 0;
+ io.in.desired_access = SEC_FILE_READ_ATTRIBUTE;
+ io.in.create_disposition = NTCREATEX_DISP_CREATE;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle2 = io.out.file.handle;
+ smb2_util_close(tree, handle2);
+
+ torture_comment(tctx, "try and access file with base rights - should be OK\n");
+ io.in.desired_access = SEC_FILE_WRITE_DATA;
+ io.in.create_disposition = NTCREATEX_DISP_OPEN;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle2 = io.out.file.handle;
+ smb2_util_close(tree, handle2);
+
+ torture_comment(tctx, "try and access file with extra rights - should be denied\n");
+ io.in.desired_access = SEC_FILE_WRITE_DATA | SEC_FILE_EXECUTE;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+ torture_comment(tctx, "update parent sd\n");
+ sd = security_descriptor_dacl_create(tctx,
+ 0, NULL, NULL,
+ owner_sid,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_FILE_WRITE_DATA | SEC_STD_DELETE | SEC_FILE_READ_ATTRIBUTE | SEC_FILE_EXECUTE,
+ SEC_ACE_FLAG_OBJECT_INHERIT,
+ NULL);
+ sd->type |= SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_DACL_AUTO_INHERIT_REQ;
+
+ set.set_secdesc.in.sd = sd;
+ status = smb2_setinfo_file(tree, &set);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ torture_comment(tctx, "try and access file with base rights - should be OK\n");
+ io.in.desired_access = SEC_FILE_WRITE_DATA;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle2 = io.out.file.handle;
+ smb2_util_close(tree, handle2);
+
+
+ torture_comment(tctx, "try and access now - should be OK if dynamic inheritance works\n");
+ io.in.desired_access = SEC_FILE_WRITE_DATA | SEC_FILE_EXECUTE;
+ status = smb2_create(tree, tctx, &io);
+ if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
+ torture_comment(tctx, "Server does not have dynamic inheritance\n");
+ }
+ if (NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
+ torture_comment(tctx, "Server does have dynamic inheritance\n");
+ }
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+ smb2_util_unlink(tree, fname1);
+
+done:
+ torture_comment(tctx, "put back original sd\n");
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.handle = handle;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ set.set_secdesc.in.sd = sd_orig;
+ status = smb2_setinfo_file(tree, &set);
+
+ smb2_util_close(tree, handle);
+ smb2_util_rmdir(tree, dname);
+ smb2_deltree(tree, BASEDIR);
+ smb2_tdis(tree);
+ smb2_logoff(tree->session);
+
+ return ret;
+}
+
+#define CHECK_STATUS_FOR_BIT_ACTION(status, bits, action) do { \
+ if (!(bits & desired_64)) {\
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED); \
+ action; \
+ } else { \
+ CHECK_STATUS(status, NT_STATUS_OK); \
+ } \
+} while (0)
+
+#define CHECK_STATUS_FOR_BIT(status, bits, access) do { \
+ if (NT_STATUS_IS_OK(status)) { \
+ if (!(granted & access)) {\
+ ret = false; \
+ torture_result(tctx, TORTURE_FAIL, "(%s) %s but flags 0x%08X are not granted! granted[0x%08X] desired[0x%08X]\n", \
+ __location__, nt_errstr(status), access, granted, desired); \
+ goto done; \
+ } \
+ } else { \
+ if (granted & access) {\
+ ret = false; \
+ torture_result(tctx, TORTURE_FAIL, "(%s) %s but flags 0x%08X are granted! granted[0x%08X] desired[0x%08X]\n", \
+ __location__, nt_errstr(status), access, granted, desired); \
+ goto done; \
+ } \
+ } \
+ CHECK_STATUS_FOR_BIT_ACTION(status, bits, do {} while (0)); \
+} while (0)
+
+/* test what access mask is needed for getting and setting security_descriptors */
+/* Note: This test was copied from raw/acls.c. */
+static bool test_sd_get_set(struct torture_context *tctx, struct smb2_tree *tree)
+{
+ NTSTATUS status;
+ bool ret = true;
+ struct smb2_create io;
+ union smb_fileinfo fi;
+ union smb_setfileinfo si;
+ struct security_descriptor *sd;
+ struct security_descriptor *sd_owner = NULL;
+ struct security_descriptor *sd_group = NULL;
+ struct security_descriptor *sd_dacl = NULL;
+ struct security_descriptor *sd_sacl = NULL;
+ struct smb2_handle handle;
+ const char *fname = BASEDIR "\\sd_get_set.txt";
+ uint64_t desired_64;
+ uint32_t desired = 0, granted;
+ int i = 0;
+#define NO_BITS_HACK (((uint64_t)1)<<32)
+ uint64_t open_bits =
+ SEC_MASK_GENERIC |
+ SEC_FLAG_SYSTEM_SECURITY |
+ SEC_FLAG_MAXIMUM_ALLOWED |
+ SEC_STD_ALL |
+ SEC_FILE_ALL |
+ NO_BITS_HACK;
+ uint64_t get_owner_bits = SEC_MASK_GENERIC | SEC_FLAG_MAXIMUM_ALLOWED | SEC_STD_READ_CONTROL;
+ uint64_t set_owner_bits = SEC_GENERIC_ALL | SEC_FLAG_MAXIMUM_ALLOWED | SEC_STD_WRITE_OWNER;
+ uint64_t get_group_bits = SEC_MASK_GENERIC | SEC_FLAG_MAXIMUM_ALLOWED | SEC_STD_READ_CONTROL;
+ uint64_t set_group_bits = SEC_GENERIC_ALL | SEC_FLAG_MAXIMUM_ALLOWED | SEC_STD_WRITE_OWNER;
+ uint64_t get_dacl_bits = SEC_MASK_GENERIC | SEC_FLAG_MAXIMUM_ALLOWED | SEC_STD_READ_CONTROL;
+ uint64_t set_dacl_bits = SEC_GENERIC_ALL | SEC_FLAG_MAXIMUM_ALLOWED | SEC_STD_WRITE_DAC;
+ uint64_t get_sacl_bits = SEC_FLAG_SYSTEM_SECURITY;
+ uint64_t set_sacl_bits = SEC_FLAG_SYSTEM_SECURITY;
+
+ if (!smb2_util_setup_dir(tctx, tree, BASEDIR))
+ return false;
+
+ torture_comment(tctx, "TESTING ACCESS MASKS FOR SD GET/SET\n");
+
+ /* first create a file with full access for everyone */
+ sd = security_descriptor_dacl_create(tctx,
+ 0, SID_NT_ANONYMOUS, SID_BUILTIN_USERS,
+ SID_WORLD,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_GENERIC_ALL,
+ 0,
+ NULL);
+ sd->type |= SEC_DESC_SACL_PRESENT;
+ sd->sacl = NULL;
+ ZERO_STRUCT(io);
+ io.level = RAW_OPEN_SMB2;
+ io.in.create_flags = 0;
+ io.in.desired_access = SEC_GENERIC_ALL;
+ io.in.create_options = 0;
+ io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+ io.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
+ io.in.alloc_size = 0;
+ io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
+ io.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.in.security_flags = 0;
+ io.in.fname = fname;
+ io.in.sec_desc = sd;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle = io.out.file.handle;
+
+ status = smb2_util_close(tree, handle);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ /*
+ * now try each access_mask bit and no bit at all in a loop
+ * and see what's allowed
+ * NOTE: if i == 32 it means access_mask = 0 (see NO_BITS_HACK above)
+ */
+ for (i=0; i <= 32; i++) {
+ desired_64 = ((uint64_t)1) << i;
+ desired = (uint32_t)desired_64;
+
+ /* first open the file with the desired access */
+ io.level = RAW_OPEN_SMB2;
+ io.in.desired_access = desired;
+ io.in.create_disposition = NTCREATEX_DISP_OPEN;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS_FOR_BIT_ACTION(status, open_bits, goto next);
+ handle = io.out.file.handle;
+
+ /* then check what access was granted */
+ fi.access_information.level = RAW_FILEINFO_ACCESS_INFORMATION;
+ fi.access_information.in.file.handle = handle;
+ status = smb2_getinfo_file(tree, tctx, &fi);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ granted = fi.access_information.out.access_flags;
+
+ /* test the owner */
+ ZERO_STRUCT(fi);
+ fi.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ fi.query_secdesc.in.file.handle = handle;
+ fi.query_secdesc.in.secinfo_flags = SECINFO_OWNER;
+ status = smb2_getinfo_file(tree, tctx, &fi);
+ CHECK_STATUS_FOR_BIT(status, get_owner_bits, SEC_STD_READ_CONTROL);
+ if (fi.query_secdesc.out.sd) {
+ sd_owner = fi.query_secdesc.out.sd;
+ } else if (!sd_owner) {
+ sd_owner = sd;
+ }
+ si.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ si.set_secdesc.in.file.handle = handle;
+ si.set_secdesc.in.secinfo_flags = SECINFO_OWNER;
+ si.set_secdesc.in.sd = sd_owner;
+ status = smb2_setinfo_file(tree, &si);
+ CHECK_STATUS_FOR_BIT(status, set_owner_bits, SEC_STD_WRITE_OWNER);
+
+ /* test the group */
+ ZERO_STRUCT(fi);
+ fi.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ fi.query_secdesc.in.file.handle = handle;
+ fi.query_secdesc.in.secinfo_flags = SECINFO_GROUP;
+ status = smb2_getinfo_file(tree, tctx, &fi);
+ CHECK_STATUS_FOR_BIT(status, get_group_bits, SEC_STD_READ_CONTROL);
+ if (fi.query_secdesc.out.sd) {
+ sd_group = fi.query_secdesc.out.sd;
+ } else if (!sd_group) {
+ sd_group = sd;
+ }
+ si.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ si.set_secdesc.in.file.handle = handle;
+ si.set_secdesc.in.secinfo_flags = SECINFO_GROUP;
+ si.set_secdesc.in.sd = sd_group;
+ status = smb2_setinfo_file(tree, &si);
+ CHECK_STATUS_FOR_BIT(status, set_group_bits, SEC_STD_WRITE_OWNER);
+
+ /* test the DACL */
+ ZERO_STRUCT(fi);
+ fi.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ fi.query_secdesc.in.file.handle = handle;
+ fi.query_secdesc.in.secinfo_flags = SECINFO_DACL;
+ status = smb2_getinfo_file(tree, tctx, &fi);
+ CHECK_STATUS_FOR_BIT(status, get_dacl_bits, SEC_STD_READ_CONTROL);
+ if (fi.query_secdesc.out.sd) {
+ sd_dacl = fi.query_secdesc.out.sd;
+ } else if (!sd_dacl) {
+ sd_dacl = sd;
+ }
+ si.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ si.set_secdesc.in.file.handle = handle;
+ si.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ si.set_secdesc.in.sd = sd_dacl;
+ status = smb2_setinfo_file(tree, &si);
+ CHECK_STATUS_FOR_BIT(status, set_dacl_bits, SEC_STD_WRITE_DAC);
+
+ /* test the SACL */
+ ZERO_STRUCT(fi);
+ fi.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ fi.query_secdesc.in.file.handle = handle;
+ fi.query_secdesc.in.secinfo_flags = SECINFO_SACL;
+ status = smb2_getinfo_file(tree, tctx, &fi);
+ CHECK_STATUS_FOR_BIT(status, get_sacl_bits, SEC_FLAG_SYSTEM_SECURITY);
+ if (fi.query_secdesc.out.sd) {
+ sd_sacl = fi.query_secdesc.out.sd;
+ } else if (!sd_sacl) {
+ sd_sacl = sd;
+ }
+ si.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ si.set_secdesc.in.file.handle = handle;
+ si.set_secdesc.in.secinfo_flags = SECINFO_SACL;
+ si.set_secdesc.in.sd = sd_sacl;
+ status = smb2_setinfo_file(tree, &si);
+ CHECK_STATUS_FOR_BIT(status, set_sacl_bits, SEC_FLAG_SYSTEM_SECURITY);
+
+ /* close the handle */
+ status = smb2_util_close(tree, handle);
+ CHECK_STATUS(status, NT_STATUS_OK);
+next:
+ continue;
+ }
+
+done:
+ smb2_util_close(tree, handle);
+ smb2_util_unlink(tree, fname);
+ smb2_deltree(tree, BASEDIR);
+ smb2_tdis(tree);
+ smb2_logoff(tree->session);
+
+ return ret;
+}
+
+/*
+ basic testing of SMB2 ACLs
+*/
+struct torture_suite *torture_smb2_acls_init(void)
+{
+ struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "ACLS");
+
+ torture_suite_add_1smb2_test(suite, "CREATOR", test_creator_sid);
+ torture_suite_add_1smb2_test(suite, "GENERIC", test_generic_bits);
+ torture_suite_add_1smb2_test(suite, "OWNER", test_owner_bits);
+ torture_suite_add_1smb2_test(suite, "INHERITANCE", test_inheritance);
+ torture_suite_add_1smb2_test(suite, "INHERITFLAGS", test_inheritance_flags);
+ torture_suite_add_1smb2_test(suite, "DYNAMIC", test_inheritance_dynamic);
+ /* XXX This test does not work against XP or Vista.
+ torture_suite_add_1smb2_test(suite, "GETSET", test_sd_get_set);
+ */
+
+ suite->description = talloc_strdup(suite, "SMB2-ACLS tests");
+
+ return suite;
+}
diff --git a/source4/torture/smb2/config.mk b/source4/torture/smb2/config.mk
index e26ad26e7f..8ff38bbf40 100644
--- a/source4/torture/smb2/config.mk
+++ b/source4/torture/smb2/config.mk
@@ -24,6 +24,7 @@ TORTURE_SMB2_OBJ_FILES = $(addprefix $(torturesrcdir)/smb2/, \
dir.o \
lease.o \
create.o \
+ acls.o \
read.o \
compound.o \
streams.o)
diff --git a/source4/torture/smb2/create.c b/source4/torture/smb2/create.c
index b006047e94..cf3731e9f1 100644
--- a/source4/torture/smb2/create.c
+++ b/source4/torture/smb2/create.c
@@ -39,7 +39,7 @@
#define CHECK_STATUS(status, correct) do { \
if (!NT_STATUS_EQUAL(status, correct)) { \
- torture_result(torture, TORTURE_FAIL, \
+ torture_result(tctx, TORTURE_FAIL, \
"(%s) Incorrect status %s - should be %s\n", \
__location__, nt_errstr(status), nt_errstr(correct)); \
return false; \
@@ -47,7 +47,7 @@
#define CHECK_EQUAL(v, correct) do { \
if (v != correct) { \
- torture_result(torture, TORTURE_FAIL, \
+ torture_result(tctx, TORTURE_FAIL, \
"(%s) Incorrect value for %s 0x%08llx - " \
"should be 0x%08llx\n", \
__location__, #v, \
@@ -60,17 +60,17 @@
time_t t1, t2; \
finfo.all_info.level = RAW_FILEINFO_ALL_INFORMATION; \
finfo.all_info.in.file.handle = h1; \
- status = smb2_getinfo_file(tree, torture, &finfo); \
+ status = smb2_getinfo_file(tree, tctx, &finfo); \
CHECK_STATUS(status, NT_STATUS_OK); \
t1 = t & ~1; \
t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
if (abs(t1-t2) > 2) { \
- torture_result(torture, TORTURE_FAIL, \
+ torture_result(tctx, TORTURE_FAIL, \
"(%s) wrong time for field %s %s - %s\n", \
__location__, #field, \
- timestring(torture, t1), \
- timestring(torture, t2)); \
- dump_all_info(torture, &finfo); \
+ timestring(tctx, t1), \
+ timestring(tctx, t2)); \
+ dump_all_info(tctx, &finfo); \
ret = false; \
}} while (0)
@@ -78,36 +78,36 @@
NTTIME t2; \
finfo.all_info.level = RAW_FILEINFO_ALL_INFORMATION; \
finfo.all_info.in.file.handle = h1; \
- status = smb2_getinfo_file(tree, torture, &finfo); \
+ status = smb2_getinfo_file(tree, tctx, &finfo); \
CHECK_STATUS(status, NT_STATUS_OK); \
t2 = finfo.all_info.out.field; \
if (t != t2) { \
- torture_result(torture, TORTURE_FAIL, \
+ torture_result(tctx, TORTURE_FAIL, \
"(%s) wrong time for field %s %s - %s\n", \
__location__, #field, \
- nt_time_string(torture, t), \
- nt_time_string(torture, t2)); \
- dump_all_info(torture, &finfo); \
+ nt_time_string(tctx, t), \
+ nt_time_string(tctx, t2)); \
+ dump_all_info(tctx, &finfo); \
ret = false; \
}} while (0)
#define CHECK_ALL_INFO(v, field) do { \
finfo.all_info.level = RAW_FILEINFO_ALL_INFORMATION; \
finfo.all_info.in.file.handle = h1; \
- status = smb2_getinfo_file(tree, torture, &finfo); \
+ status = smb2_getinfo_file(tree, tctx, &finfo); \
CHECK_STATUS(status, NT_STATUS_OK); \
if ((v) != (finfo.all_info.out.field)) { \
- torture_result(torture, TORTURE_FAIL, \
+ torture_result(tctx, TORTURE_FAIL, \
"(%s) wrong value for field %s 0x%x - 0x%x\n", \
__location__, #field, (int)v,\
(int)(finfo.all_info.out.field)); \
- dump_all_info(torture, &finfo); \
+ dump_all_info(tctx, &finfo); \
ret = false; \
}} while (0)
#define CHECK_VAL(v, correct) do { \
if ((v) != (correct)) { \
- torture_result(torture, TORTURE_FAIL, \
+ torture_result(tctx, TORTURE_FAIL, \
"(%s) wrong value for %s 0x%x - should be 0x%x\n", \
__location__, #v, (int)(v), (int)correct); \
ret = false; \
@@ -121,7 +121,7 @@
sfinfo.basic_info.in.attrib = sattrib; \
status = smb2_setinfo_file(tree, &sfinfo); \
if (!NT_STATUS_IS_OK(status)) { \
- torture_comment(torture, \
+ torture_comment(tctx, \
"(%s) Failed to set attrib 0x%x on %s\n", \
__location__, sattrib, fname); \
}} while (0)
@@ -129,11 +129,10 @@
/*
test some interesting combinations found by gentest
*/
-static bool test_create_gentest(struct torture_context *torture, struct smb2_tree *tree)
+static bool test_create_gentest(struct torture_context *tctx, struct smb2_tree *tree)
{
struct smb2_create io;
NTSTATUS status;
- TALLOC_CTX *tmp_ctx = talloc_new(tree);
uint32_t access_mask, file_attributes_set;
uint32_t ok_mask, not_supported_mask, invalid_parameter_mask;
uint32_t not_a_directory_mask, unexpected_mask;
@@ -150,38 +149,38 @@ static bool test_create_gentest(struct torture_context *torture, struct smb2_tre
io.in.create_options = 0;
io.in.fname = FNAME;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_util_close(tree, io.out.file.handle);
CHECK_STATUS(status, NT_STATUS_OK);
io.in.create_options = 0xF0000000;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
io.in.create_options = 0;
io.in.file_attributes = FILE_ATTRIBUTE_DEVICE;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
io.in.file_attributes = FILE_ATTRIBUTE_VOLUME;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
io.in.create_disposition = NTCREATEX_DISP_OPEN;
io.in.file_attributes = FILE_ATTRIBUTE_VOLUME;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
io.in.create_disposition = NTCREATEX_DISP_CREATE;
io.in.desired_access = 0x08000000;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
io.in.desired_access = 0x04000000;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
io.in.file_attributes = 0;
@@ -199,7 +198,7 @@ static bool test_create_gentest(struct torture_context *torture, struct smb2_tre
if (io.in.create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) {
continue;
}
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
not_supported_mask |= 1<<i;
} else if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
@@ -212,7 +211,7 @@ static bool test_create_gentest(struct torture_context *torture, struct smb2_tre
CHECK_STATUS(status, NT_STATUS_OK);
} else {
unexpected_mask |= 1<<i;
- torture_comment(torture,
+ torture_comment(tctx,
"create option 0x%08x returned %s\n",
1<<i, nt_errstr(status));
}
@@ -233,7 +232,7 @@ static bool test_create_gentest(struct torture_context *torture, struct smb2_tre
int i;
for (i=0;i<32;i++) {
io.in.desired_access = 1<<i;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
NT_STATUS_EQUAL(status, NT_STATUS_PRIVILEGE_NOT_HELD)) {
access_mask |= io.in.desired_access;
@@ -245,9 +244,9 @@ static bool test_create_gentest(struct torture_context *torture, struct smb2_tre
}
}
- if (TARGET_IS_WIN7(torture)) {
+ if (TARGET_IS_WIN7(tctx)) {
CHECK_EQUAL(access_mask, 0x0de0fe00);
- } else if (torture_setting_bool(torture, "samba4", false)) {
+ } else if (torture_setting_bool(tctx, "samba4", false)) {
CHECK_EQUAL(access_mask, 0x0cf0fe00);
} else {
CHECK_EQUAL(access_mask, 0x0df0fe00);
@@ -268,7 +267,7 @@ static bool test_create_gentest(struct torture_context *torture, struct smb2_tre
continue;
}
smb2_deltree(tree, FNAME);
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
invalid_parameter_mask |= 1<<i;
} else if (NT_STATUS_IS_OK(status)) {
@@ -283,7 +282,7 @@ static bool test_create_gentest(struct torture_context *torture, struct smb2_tre
CHECK_STATUS(status, NT_STATUS_OK);
} else {
unexpected_mask |= 1<<i;
- torture_comment(torture,
+ torture_comment(tctx,
"file attribute 0x%08x returned %s\n",
1<<i, nt_errstr(status));
}
@@ -301,9 +300,9 @@ static bool test_create_gentest(struct torture_context *torture, struct smb2_tre
* Standalone servers doesn't support encryption
*/
io.in.file_attributes = FILE_ATTRIBUTE_ENCRYPTED;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
- torture_comment(torture,
+ torture_comment(tctx,
"FILE_ATTRIBUTE_ENCRYPTED returned %s\n",
nt_errstr(status));
} else {
@@ -324,7 +323,7 @@ static bool test_create_gentest(struct torture_context *torture, struct smb2_tre
NTCREATEX_SHARE_ACCESS_WRITE;
io.in.create_options = 0;
io.in.fname = FNAME ":stream1";
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_util_close(tree, io.out.file.handle);
@@ -334,20 +333,20 @@ static bool test_create_gentest(struct torture_context *torture, struct smb2_tre
io.in.file_attributes = 0x8040;
io.in.share_access =
NTCREATEX_SHARE_ACCESS_READ;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
io.in.fname = FNAME;
io.in.file_attributes = 0;
io.in.desired_access = SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA | SEC_FILE_APPEND_DATA;
io.in.query_maximal_access = true;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_EQUAL(io.out.maximal_access, 0x001f01ff);
q.access_information.level = RAW_FILEINFO_ACCESS_INFORMATION;
q.access_information.in.file.handle = io.out.file.handle;
- status = smb2_getinfo_file(tree, tmp_ctx, &q);
+ status = smb2_getinfo_file(tree, tctx, &q);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_EQUAL(q.access_information.out.access_flags, io.in.desired_access);
@@ -355,13 +354,11 @@ static bool test_create_gentest(struct torture_context *torture, struct smb2_tre
io.in.desired_access = 0;
io.in.query_maximal_access = false;
io.in.share_access = 0;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- talloc_free(tmp_ctx);
-
smb2_deltree(tree, FNAME);
-
+
return true;
}
@@ -369,11 +366,10 @@ static bool test_create_gentest(struct torture_context *torture, struct smb2_tre
/*
try the various request blobs
*/
-static bool test_create_blob(struct torture_context *torture, struct smb2_tree *tree)
+static bool test_create_blob(struct torture_context *tctx, struct smb2_tree *tree)
{
struct smb2_create io;
NTSTATUS status;
- TALLOC_CTX *tmp_ctx = talloc_new(tree);
smb2_deltree(tree, FNAME);
@@ -391,108 +387,125 @@ static bool test_create_blob(struct torture_context *torture, struct smb2_tree *
0x00200000;
io.in.fname = FNAME;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_util_close(tree, io.out.file.handle);
CHECK_STATUS(status, NT_STATUS_OK);
- torture_comment(torture, "testing alloc size\n");
+ torture_comment(tctx, "testing alloc size\n");
io.in.alloc_size = 4096;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_EQUAL(io.out.alloc_size, io.in.alloc_size);
status = smb2_util_close(tree, io.out.file.handle);
CHECK_STATUS(status, NT_STATUS_OK);
- torture_comment(torture, "testing durable open\n");
+ torture_comment(tctx, "testing durable open\n");
io.in.durable_open = true;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_util_close(tree, io.out.file.handle);
CHECK_STATUS(status, NT_STATUS_OK);
- torture_comment(torture, "testing query maximal access\n");
+ torture_comment(tctx, "testing query maximal access\n");
io.in.query_maximal_access = true;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_EQUAL(io.out.maximal_access, 0x001f01ff);
status = smb2_util_close(tree, io.out.file.handle);
CHECK_STATUS(status, NT_STATUS_OK);
- torture_comment(torture, "testing timewarp\n");
+ torture_comment(tctx, "testing timewarp\n");
io.in.timewarp = 10000;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
io.in.timewarp = 0;
- torture_comment(torture, "testing query_on_disk\n");
+ torture_comment(tctx, "testing query_on_disk\n");
io.in.query_on_disk_id = true;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_util_close(tree, io.out.file.handle);
CHECK_STATUS(status, NT_STATUS_OK);
- torture_comment(torture, "testing unknown tag\n");
- status = smb2_create_blob_add(tmp_ctx, &io.in.blobs,
+ torture_comment(tctx, "testing unknown tag\n");
+ status = smb2_create_blob_add(tctx, &io.in.blobs,
"FooO", data_blob(NULL, 0));
CHECK_STATUS(status, NT_STATUS_OK);
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_util_close(tree, io.out.file.handle);
CHECK_STATUS(status, NT_STATUS_OK);
- torture_comment(torture, "testing bad tag length\n");
- status = smb2_create_blob_add(tmp_ctx, &io.in.blobs,
+ torture_comment(tctx, "testing bad tag length\n");
+ status = smb2_create_blob_add(tctx, &io.in.blobs,
"xxx", data_blob(NULL, 0));
CHECK_STATUS(status, NT_STATUS_OK);
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
- talloc_free(tmp_ctx);
-
smb2_deltree(tree, FNAME);
return true;
}
+#define FAIL_UNLESS(__cond) \
+ do { \
+ if (__cond) {} else { \
+ torture_result(tctx, TORTURE_FAIL, "%s) condition violated: %s\n", \
+ __location__, #__cond); \
+ ret = false; goto done; \
+ } \
+ } while(0)
+
/*
try creating with acls
*/
-static bool test_create_acl(struct torture_context *torture, struct smb2_tree *tree)
+static bool test_create_acl_ext(struct torture_context *tctx, struct smb2_tree *tree, bool test_dir)
{
+ bool ret = true;
struct smb2_create io;
NTSTATUS status;
- TALLOC_CTX *tmp_ctx = talloc_new(tree);
struct security_ace ace;
struct security_descriptor *sd, *sd2;
struct dom_sid *test_sid;
- union smb_fileinfo q;
+ union smb_fileinfo q = {};
+ uint32_t attrib =
+ FILE_ATTRIBUTE_HIDDEN |
+ FILE_ATTRIBUTE_SYSTEM |
+ (test_dir ? FILE_ATTRIBUTE_DIRECTORY : 0);
+ NTSTATUS (*delete_func)(struct smb2_tree *, const char *) =
+ test_dir ? smb2_util_rmdir : smb2_util_unlink;
smb2_deltree(tree, FNAME);
ZERO_STRUCT(io);
io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
- io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
+ io.in.create_disposition = NTCREATEX_DISP_CREATE;
io.in.share_access =
- NTCREATEX_SHARE_ACCESS_DELETE|
- NTCREATEX_SHARE_ACCESS_READ|
+ NTCREATEX_SHARE_ACCESS_DELETE |
+ NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE;
- io.in.create_options = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
- NTCREATEX_OPTIONS_ASYNC_ALERT |
- NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
- 0x00200000;
+ io.in.create_options = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
+ NTCREATEX_OPTIONS_ASYNC_ALERT |
+ 0x00200000 |
+ (test_dir ? NTCREATEX_OPTIONS_DIRECTORY :
+ NTCREATEX_OPTIONS_NON_DIRECTORY_FILE);
+
io.in.fname = FNAME;
- status = smb2_create(tree, tmp_ctx, &io);
+ torture_comment(tctx, "basic create\n");
+
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
@@ -501,17 +514,17 @@ static bool test_create_acl(struct torture_context *torture, struct smb2_tree *t
SECINFO_OWNER |
SECINFO_GROUP |
SECINFO_DACL;
- status = smb2_getinfo_file(tree, tmp_ctx, &q);
+ status = smb2_getinfo_file(tree, tctx, &q);
CHECK_STATUS(status, NT_STATUS_OK);
sd = q.query_secdesc.out.sd;
status = smb2_util_close(tree, io.out.file.handle);
CHECK_STATUS(status, NT_STATUS_OK);
+ status = delete_func(tree, FNAME);
+ CHECK_STATUS(status, NT_STATUS_OK);
- smb2_util_unlink(tree, FNAME);
-
- torture_comment(torture, "adding a new ACE\n");
- test_sid = dom_sid_parse_talloc(tmp_ctx, "S-1-5-32-1234-54321");
+ torture_comment(tctx, "adding a new ACE\n");
+ test_sid = dom_sid_parse_talloc(tctx, SID_NT_AUTHENTICATED_USERS);
ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
ace.flags = 0;
@@ -521,39 +534,80 @@ static bool test_create_acl(struct torture_context *torture, struct smb2_tree *t
status = security_descriptor_dacl_add(sd, &ace);
CHECK_STATUS(status, NT_STATUS_OK);
- torture_comment(torture, "creating a file with an initial ACL\n");
+ torture_comment(tctx, "creating a file with an initial ACL\n");
io.in.sec_desc = sd;
- status = smb2_create(tree, tmp_ctx, &io);
+ status = smb2_create(tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
- q.query_secdesc.in.file.handle = io.out.file.handle;
- status = smb2_getinfo_file(tree, tmp_ctx, &q);
+ FAIL_UNLESS(smb2_util_verify_sd(tctx, tree, io.out.file.handle, sd));
+
+ status = smb2_util_close(tree, io.out.file.handle);
CHECK_STATUS(status, NT_STATUS_OK);
- sd2 = q.query_secdesc.out.sd;
-
- if (!security_acl_equal(sd->dacl, sd2->dacl)) {
- torture_comment(torture,
- "%s: security descriptors don't match!\n", __location__);
- torture_comment(torture, "got:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd2);
- torture_comment(torture, "expected:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd);
- return false;
- }
+ status = delete_func(tree, FNAME);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ torture_comment(tctx, "creating with attributes\n");
+
+ io.in.sec_desc = NULL;
+ io.in.file_attributes = attrib;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ FAIL_UNLESS(smb2_util_verify_attrib(tctx, tree, io.out.file.handle, attrib));
+
+ status = smb2_util_close(tree, io.out.file.handle);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ status = delete_func(tree, FNAME);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ torture_comment(tctx, "creating with attributes and ACL\n");
- talloc_free(tmp_ctx);
+ io.in.sec_desc = sd;
+ io.in.file_attributes = attrib;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ FAIL_UNLESS(smb2_util_verify_sd(tctx, tree, io.out.file.handle, sd));
+ FAIL_UNLESS(smb2_util_verify_attrib(tctx, tree, io.out.file.handle, attrib));
- return true;
+ status = smb2_util_close(tree, io.out.file.handle);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ status = delete_func(tree, FNAME);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ torture_comment(tctx, "creating with attributes, ACL and owner\n");
+ sd = security_descriptor_dacl_create(tctx,
+ 0, SID_WORLD, SID_BUILTIN_USERS,
+ SID_WORLD,
+ SEC_ACE_TYPE_ACCESS_ALLOWED,
+ SEC_RIGHTS_FILE_READ | SEC_STD_ALL,
+ 0,
+ NULL);
+
+ io.in.sec_desc = sd;
+ io.in.file_attributes = attrib;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ FAIL_UNLESS(smb2_util_verify_sd(tctx, tree, io.out.file.handle, sd));
+ FAIL_UNLESS(smb2_util_verify_attrib(tctx, tree, io.out.file.handle, attrib));
+
+ done:
+ status = smb2_util_close(tree, io.out.file.handle);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ status = delete_func(tree, FNAME);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ return ret;
}
/*
test SMB2 open
*/
-static bool test_smb2_open(struct torture_context *torture,
+static bool test_smb2_open(struct torture_context *tctx,
struct smb2_tree *tree)
{
- TALLOC_CTX *mem_ctx = talloc_new(torture);
union smb_open io;
union smb_fileinfo finfo;
const char *fname = DNAME "\\torture_ntcreatex.txt";
@@ -583,7 +637,7 @@ static bool test_smb2_open(struct torture_context *torture,
{ 6, false, NT_STATUS_INVALID_PARAMETER },
};
- torture_comment(torture, "Checking SMB2 Open\n");
+ torture_comment(tctx, "Checking SMB2 Open\n");
smb2_util_unlink(tree, fname);
smb2_util_rmdir(tree, dname);
@@ -609,9 +663,9 @@ static bool test_smb2_open(struct torture_context *torture,
for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
if (open_funcs[i].with_file) {
io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
- status= smb2_create(tree, mem_ctx, &(io.smb2));
+ status= smb2_create(tree, tctx, &(io.smb2));
if (!NT_STATUS_IS_OK(status)) {
- torture_comment(torture,
+ torture_comment(tctx,
"Failed to create file %s status %s %d\n",
fname, nt_errstr(status), i);
@@ -621,9 +675,9 @@ static bool test_smb2_open(struct torture_context *torture,
smb2_util_close(tree, io.smb2.out.file.handle);
}
io.smb2.in.create_disposition = open_funcs[i].create_disp;
- status = smb2_create(tree, mem_ctx, &(io.smb2));
+ status = smb2_create(tree, tctx, &(io.smb2));
if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
- torture_comment(torture,
+ torture_comment(tctx,
"(%s) incorrect status %s should be %s (i=%d "
"with_file=%d open_disp=%d)\n",
__location__, nt_errstr(status),
@@ -643,7 +697,7 @@ static bool test_smb2_open(struct torture_context *torture,
/* basic field testing */
io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
- status = smb2_create(tree, mem_ctx, &(io.smb2));
+ status = smb2_create(tree, tctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
h1 = io.smb2.out.file.handle;
@@ -667,7 +721,7 @@ static bool test_smb2_open(struct torture_context *torture,
smb2_util_close(tree, h1);
io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
- status = smb2_create(tree, mem_ctx, &(io.smb2));
+ status = smb2_create(tree, tctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
h1 = io.smb2.out.file.handle;
@@ -701,7 +755,7 @@ static bool test_smb2_open(struct torture_context *torture,
io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE;
- status = smb2_create(tree, mem_ctx, &(io.smb2));
+ status = smb2_create(tree, tctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
h1 = io.smb2.out.file.handle;
@@ -724,7 +778,6 @@ done:
smb2_util_close(tree, h1);
smb2_util_unlink(tree, fname);
smb2_deltree(tree, DNAME);
- talloc_free(mem_ctx);
return ret;
}
@@ -732,7 +785,7 @@ done:
test with an already opened and byte range locked file
*/
-static bool test_smb2_open_brlocked(struct torture_context *torture,
+static bool test_smb2_open_brlocked(struct torture_context *tctx,
struct smb2_tree *tree)
{
union smb_open io, io1;
@@ -743,7 +796,7 @@ static bool test_smb2_open_brlocked(struct torture_context *torture,
bool ret = true;
struct smb2_handle h;
- torture_comment(torture,
+ torture_comment(tctx,
"Testing SMB2 open with a byte range locked file\n");
smb2_util_unlink(tree, fname);
@@ -765,7 +818,7 @@ static bool test_smb2_open_brlocked(struct torture_context *torture,
io.smb2.in.security_flags = SMB2_SECURITY_DYNAMIC_TRACKING;
io.smb2.in.fname = fname;
- status = smb2_create(tree, torture, &(io.smb2));
+ status = smb2_create(tree, tctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
ZERO_STRUCT(io2.smb2);
@@ -793,7 +846,7 @@ static bool test_smb2_open_brlocked(struct torture_context *torture,
io1.smb2.in.security_flags = SMB2_SECURITY_DYNAMIC_TRACKING;
io1.smb2.in.fname = fname;
- status = smb2_create(tree, torture, &(io1.smb2));
+ status = smb2_create(tree, tctx, &(io1.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
smb2_util_close(tree, io.smb2.out.file.handle);
@@ -806,10 +859,9 @@ static bool test_smb2_open_brlocked(struct torture_context *torture,
/* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
-static bool test_smb2_open_multi(struct torture_context *torture,
+static bool test_smb2_open_multi(struct torture_context *tctx,
struct smb2_tree *tree)
{
- TALLOC_CTX *mem_ctx = talloc_init("torture_test_oplock_multi");
const char *fname = "test_oplock.dat";
NTSTATUS status;
bool ret = true;
@@ -821,19 +873,14 @@ static bool test_smb2_open_multi(struct torture_context *torture,
int num_ok = 0;
int num_collision = 0;
- if (mem_ctx == NULL) {
- ret = false;
- goto done;
- }
-
- torture_comment(torture,
+ torture_comment(tctx,
"Testing SMB2 Open with multiple connections\n");
- trees = talloc_array(mem_ctx, struct smb2_tree *, num_files);
- requests = talloc_array(mem_ctx, struct smb2_request *, num_files);
- ios = talloc_array(mem_ctx, union smb_open, num_files);
- if ((torture->ev == NULL) || (trees == NULL) || (requests == NULL) ||
+ trees = talloc_array(tctx, struct smb2_tree *, num_files);
+ requests = talloc_array(tctx, struct smb2_request *, num_files);
+ ios = talloc_array(tctx, union smb_open, num_files);
+ if ((tctx->ev == NULL) || (trees == NULL) || (requests == NULL) ||
(ios == NULL)) {
- torture_comment(torture, ("talloc failed\n"));
+ torture_comment(tctx, ("talloc failed\n"));
ret = false;
goto done;
}
@@ -841,8 +888,8 @@ static bool test_smb2_open_multi(struct torture_context *torture,
tree->session->transport->options.request_timeout = 60;
for (i=0; i<num_files; i++) {
- if (!torture_smb2_connection(torture, &(trees[i]))) {
- torture_comment(torture,
+ if (!torture_smb2_connection(tctx, &(trees[i]))) {
+ torture_comment(tctx,
"Could not open %d'th connection\n", i);
ret = false;
goto done;
@@ -875,14 +922,14 @@ static bool test_smb2_open_multi(struct torture_context *torture,
ios[i] = io;
requests[i] = smb2_create_send(trees[i], &(ios[i].smb2));
if (requests[i] == NULL) {
- torture_comment(torture,
+ torture_comment(tctx,
"could not send %d'th request\n", i);
ret = false;
goto done;
}
}
- torture_comment(torture, "waiting for replies\n");
+ torture_comment(tctx, "waiting for replies\n");
while (1) {
bool unreplied = false;
for (i=0; i<num_files; i++) {
@@ -893,10 +940,10 @@ static bool test_smb2_open_multi(struct torture_context *torture,
unreplied = true;
break;
}
- status = smb2_create_recv(requests[i], mem_ctx,
+ status = smb2_create_recv(requests[i], tctx,
&(ios[i].smb2));
- torture_comment(torture,
+ torture_comment(tctx,
"File %d returned status %s\n", i,
nt_errstr(status));
@@ -915,8 +962,8 @@ static bool test_smb2_open_multi(struct torture_context *torture,
break;
}
- if (event_loop_once(torture->ev) != 0) {
- torture_comment(torture, "event_loop_once failed\n");
+ if (event_loop_once(tctx->ev) != 0) {
+ torture_comment(tctx, "event_loop_once failed\n");
ret = false;
goto done;
}
@@ -926,7 +973,6 @@ static bool test_smb2_open_multi(struct torture_context *torture,
ret = false;
}
done:
- talloc_free(mem_ctx);
smb2_deltree(tree, fname);
return ret;
@@ -936,7 +982,7 @@ done:
test opening for delete on a read-only attribute file.
*/
-static bool test_smb2_open_for_delete(struct torture_context *torture,
+static bool test_smb2_open_for_delete(struct torture_context *tctx,
struct smb2_tree *tree)
{
union smb_open io;
@@ -946,7 +992,7 @@ static bool test_smb2_open_for_delete(struct torture_context *torture,
struct smb2_handle h, h1;
bool ret = true;
- torture_comment(torture,
+ torture_comment(tctx,
"Checking SMB2_OPEN for delete on a readonly file.\n");
smb2_util_unlink(tree, fname);
smb2_deltree(tree, fname);
@@ -970,7 +1016,7 @@ static bool test_smb2_open_for_delete(struct torture_context *torture,
/* Create the readonly file. */
- status = smb2_create(tree, torture, &(io.smb2));
+ status = smb2_create(tree, tctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
h1 = io.smb2.out.file.handle;
@@ -987,7 +1033,7 @@ static bool test_smb2_open_for_delete(struct torture_context *torture,
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE;
io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
- status = smb2_create(tree, torture, &(io.smb2));
+ status = smb2_create(tree, tctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
smb2_util_unlink(tree, fname);
@@ -1004,7 +1050,7 @@ static bool test_smb2_open_for_delete(struct torture_context *torture,
Trying to create a directory with a leading slash
should give NT_STATUS_INVALID_PARAMETER error
*/
-static bool test_smb2_leading_slash(struct torture_context *torture,
+static bool test_smb2_leading_slash(struct torture_context *tctx,
struct smb2_tree *tree)
{
union smb_open io;
@@ -1012,7 +1058,7 @@ static bool test_smb2_leading_slash(struct torture_context *torture,
NTSTATUS status;
bool ret = true;
- torture_comment(torture,
+ torture_comment(tctx,
"Trying to create a directory with leading slash on path\n");
smb2_deltree(tree, dnameslash);
@@ -1036,6 +1082,283 @@ static bool test_smb2_leading_slash(struct torture_context *torture,
}
+static bool test_create_acl_file(struct torture_context *tctx,
+ struct smb2_tree *tree)
+{
+ torture_comment(tctx, "testing nttrans create with sec_desc on files\n");
+
+ return test_create_acl_ext(tctx, tree, false);
+}
+
+static bool test_create_acl_dir(struct torture_context *tctx,
+ struct smb2_tree *tree)
+{
+ torture_comment(tctx, "testing nttrans create with sec_desc on directories\n");
+
+ return test_create_acl_ext(tctx, tree, true);
+}
+
+#define CHECK_ACCESS_FLAGS(_fh, flags) do { \
+ union smb_fileinfo _q; \
+ _q.access_information.level = RAW_FILEINFO_ACCESS_INFORMATION; \
+ _q.access_information.in.file.handle = (_fh); \
+ status = smb2_getinfo_file(tree, tctx, &_q); \
+ CHECK_STATUS(status, NT_STATUS_OK); \
+ if (_q.access_information.out.access_flags != (flags)) { \
+ torture_result(tctx, TORTURE_FAIL, "(%s) Incorrect access_flags 0x%08x - should be 0x%08x\n", \
+ __location__, _q.access_information.out.access_flags, (flags)); \
+ ret = false; \
+ goto done; \
+ } \
+} while (0)
+
+/*
+ * Test creating a file with a NULL DACL.
+ */
+static bool test_create_null_dacl(struct torture_context *tctx,
+ struct smb2_tree *tree)
+{
+ NTSTATUS status;
+ struct smb2_create io;
+ const char *fname = "nulldacl.txt";
+ bool ret = true;
+ struct smb2_handle handle;
+ union smb_fileinfo q;
+ union smb_setfileinfo s;
+ struct security_descriptor *sd = security_descriptor_initialise(tctx);
+ struct security_acl dacl;
+
+ torture_comment(tctx, "TESTING SEC_DESC WITH A NULL DACL\n");
+
+ smb2_util_unlink(tree, fname);
+
+ ZERO_STRUCT(io);
+ io.level = RAW_OPEN_SMB2;
+ io.in.create_flags = 0;
+ io.in.desired_access = SEC_STD_READ_CONTROL | SEC_STD_WRITE_DAC
+ | SEC_STD_WRITE_OWNER;
+ io.in.create_options = 0;
+ io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+ io.in.share_access =
+ NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
+ io.in.alloc_size = 0;
+ io.in.create_disposition = NTCREATEX_DISP_CREATE;
+ io.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.in.security_flags = 0;
+ io.in.fname = fname;
+ io.in.sec_desc = sd;
+ /* XXX create_options ? */
+ io.in.create_options = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
+ NTCREATEX_OPTIONS_ASYNC_ALERT |
+ NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
+ 0x00200000;
+
+ torture_comment(tctx, "creating a file with a empty sd\n");
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ handle = io.out.file.handle;
+
+ torture_comment(tctx, "get the original sd\n");
+ q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ q.query_secdesc.in.file.handle = handle;
+ q.query_secdesc.in.secinfo_flags =
+ SECINFO_OWNER |
+ SECINFO_GROUP |
+ SECINFO_DACL;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ /*
+ * Testing the created DACL,
+ * the server should add the inherited DACL
+ * when SEC_DESC_DACL_PRESENT isn't specified
+ */
+ if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
+ ret = false;
+ torture_fail_goto(tctx, done, "DACL_PRESENT flag not set by the server!\n");
+ }
+ if (q.query_secdesc.out.sd->dacl == NULL) {
+ ret = false;
+ torture_fail_goto(tctx, done, "no DACL has been created on the server!\n");
+ }
+
+ torture_comment(tctx, "set NULL DACL\n");
+ sd->type |= SEC_DESC_DACL_PRESENT;
+
+ s.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ s.set_secdesc.in.file.handle = handle;
+ s.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ s.set_secdesc.in.sd = sd;
+ status = smb2_setinfo_file(tree, &s);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ torture_comment(tctx, "get the sd\n");
+ q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ q.query_secdesc.in.file.handle = handle;
+ q.query_secdesc.in.secinfo_flags =
+ SECINFO_OWNER |
+ SECINFO_GROUP |
+ SECINFO_DACL;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ /* Testing the modified DACL */
+ if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
+ ret = false;
+ torture_fail_goto(tctx, done, "DACL_PRESENT flag not set by the server!\n");
+ }
+ if (q.query_secdesc.out.sd->dacl != NULL) {
+ ret = false;
+ torture_fail_goto(tctx, done, "DACL has been created on the server!\n");
+ }
+
+ io.in.create_disposition = NTCREATEX_DISP_OPEN;
+
+ torture_comment(tctx, "try open for read control\n");
+ io.in.desired_access = SEC_STD_READ_CONTROL;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle,
+ SEC_STD_READ_CONTROL);
+ smb2_util_close(tree, io.out.file.handle);
+
+ torture_comment(tctx, "try open for write\n");
+ io.in.desired_access = SEC_FILE_WRITE_DATA;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle,
+ SEC_FILE_WRITE_DATA);
+ smb2_util_close(tree, io.out.file.handle);
+
+ torture_comment(tctx, "try open for read\n");
+ io.in.desired_access = SEC_FILE_READ_DATA;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle,
+ SEC_FILE_READ_DATA);
+ smb2_util_close(tree, io.out.file.handle);
+
+ torture_comment(tctx, "try open for generic write\n");
+ io.in.desired_access = SEC_GENERIC_WRITE;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle,
+ SEC_RIGHTS_FILE_WRITE);
+ smb2_util_close(tree, io.out.file.handle);
+
+ torture_comment(tctx, "try open for generic read\n");
+ io.in.desired_access = SEC_GENERIC_READ;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle,
+ SEC_RIGHTS_FILE_READ);
+ smb2_util_close(tree, io.out.file.handle);
+
+ torture_comment(tctx, "set DACL with 0 aces\n");
+ ZERO_STRUCT(dacl);
+ dacl.revision = SECURITY_ACL_REVISION_NT4;
+ dacl.num_aces = 0;
+ sd->dacl = &dacl;
+
+ s.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ s.set_secdesc.in.file.handle = handle;
+ s.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ s.set_secdesc.in.sd = sd;
+ status = smb2_setinfo_file(tree, &s);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ torture_comment(tctx, "get the sd\n");
+ q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ q.query_secdesc.in.file.handle = handle;
+ q.query_secdesc.in.secinfo_flags =
+ SECINFO_OWNER |
+ SECINFO_GROUP |
+ SECINFO_DACL;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ /* Testing the modified DACL */
+ if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
+ ret = false;
+ torture_fail_goto(tctx, done, "DACL_PRESENT flag not set by the server!\n");
+ }
+ if (q.query_secdesc.out.sd->dacl == NULL) {
+ ret = false;
+ torture_fail_goto(tctx, done, "no DACL has been created on the server!\n");
+ }
+ if (q.query_secdesc.out.sd->dacl->num_aces != 0) {
+ torture_result(tctx, TORTURE_FAIL, "DACL has %u aces!\n",
+ q.query_secdesc.out.sd->dacl->num_aces);
+ ret = false;
+ goto done;
+ }
+
+ torture_comment(tctx, "try open for read control\n");
+ io.in.desired_access = SEC_STD_READ_CONTROL;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_ACCESS_FLAGS(io.out.file.handle,
+ SEC_STD_READ_CONTROL);
+ smb2_util_close(tree, io.out.file.handle);
+
+ torture_comment(tctx, "try open for write => access_denied\n");
+ io.in.desired_access = SEC_FILE_WRITE_DATA;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+ torture_comment(tctx, "try open for read => access_denied\n");
+ io.in.desired_access = SEC_FILE_READ_DATA;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+ torture_comment(tctx, "try open for generic write => access_denied\n");
+ io.in.desired_access = SEC_GENERIC_WRITE;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+ torture_comment(tctx, "try open for generic read => access_denied\n");
+ io.in.desired_access = SEC_GENERIC_READ;
+ status = smb2_create(tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+ torture_comment(tctx, "set empty sd\n");
+ sd->type &= ~SEC_DESC_DACL_PRESENT;
+ sd->dacl = NULL;
+
+ s.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ s.set_secdesc.in.file.handle = handle;
+ s.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ s.set_secdesc.in.sd = sd;
+ status = smb2_setinfo_file(tree, &s);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ torture_comment(tctx, "get the sd\n");
+ q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ q.query_secdesc.in.file.handle = handle;
+ q.query_secdesc.in.secinfo_flags =
+ SECINFO_OWNER |
+ SECINFO_GROUP |
+ SECINFO_DACL;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ /* Testing the modified DACL */
+ if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
+ ret = false;
+ torture_fail_goto(tctx, done, "DACL_PRESENT flag not set by the server!\n");
+ }
+ if (q.query_secdesc.out.sd->dacl != NULL) {
+ ret = false;
+ torture_fail_goto(tctx, done, "DACL has been created on the server!\n");
+ }
+done:
+ smb2_util_close(tree, handle);
+ smb2_util_unlink(tree, fname);
+ smb2_tdis(tree);
+ smb2_logoff(tree->session);
+ return ret;
+}
+
/*
basic testing of SMB2 read
*/
@@ -1045,12 +1368,14 @@ struct torture_suite *torture_smb2_create_init(void)
torture_suite_add_1smb2_test(suite, "GENTEST", test_create_gentest);
torture_suite_add_1smb2_test(suite, "BLOB", test_create_blob);
- torture_suite_add_1smb2_test(suite, "ACL", test_create_acl);
torture_suite_add_1smb2_test(suite, "OPEN", test_smb2_open);
torture_suite_add_1smb2_test(suite, "BRLOCKED", test_smb2_open_brlocked);
torture_suite_add_1smb2_test(suite, "MULTI", test_smb2_open_multi);
torture_suite_add_1smb2_test(suite, "DELETE", test_smb2_open_for_delete);
torture_suite_add_1smb2_test(suite, "LEADING-SLASH", test_smb2_leading_slash);
+ torture_suite_add_1smb2_test(suite, "ACLFILE", test_create_acl_file);
+ torture_suite_add_1smb2_test(suite, "ACLDIR", test_create_acl_dir);
+ torture_suite_add_1smb2_test(suite, "NULLDACL", test_create_null_dacl);
suite->description = talloc_strdup(suite, "SMB2-CREATE tests");
diff --git a/source4/torture/smb2/setinfo.c b/source4/torture/smb2/setinfo.c
index 7a912b4989..38642a673d 100644
--- a/source4/torture/smb2/setinfo.c
+++ b/source4/torture/smb2/setinfo.c
@@ -32,11 +32,20 @@
#define BASEDIR ""
+#define FAIL_UNLESS(__cond) \
+ do { \
+ if (__cond) {} else { \
+ torture_result(tctx, TORTURE_FAIL, "%s) condition violated: %s\n", \
+ __location__, #__cond); \
+ ret = false; goto done; \
+ } \
+ } while(0)
+
/* basic testing of all SMB2 setinfo calls
for each call we test that it succeeds, and where possible test
for consistency between the calls.
*/
-bool torture_smb2_setinfo(struct torture_context *torture)
+bool torture_smb2_setinfo(struct torture_context *tctx)
{
struct smb2_tree *tree;
bool ret = true;
@@ -55,10 +64,10 @@ bool torture_smb2_setinfo(struct torture_context *torture)
ZERO_STRUCT(handle);
- fname = talloc_asprintf(torture, BASEDIR "fnum_test_%d.txt", n);
- fname_new = talloc_asprintf(torture, BASEDIR "fnum_test_new_%d.txt", n);
+ fname = talloc_asprintf(tctx, BASEDIR "fnum_test_%d.txt", n);
+ fname_new = talloc_asprintf(tctx, BASEDIR "fnum_test_new_%d.txt", n);
- if (!torture_smb2_connection(torture, &tree)) {
+ if (!torture_smb2_connection(tctx, &tree)) {
return false;
}
@@ -66,7 +75,7 @@ bool torture_smb2_setinfo(struct torture_context *torture)
smb2_util_close(tree, handle); \
status = smb2_create_complex_file(tree, fname, &handle); \
if (!NT_STATUS_IS_OK(status)) { \
- printf("(%s) ERROR: open of %s failed (%s)\n", \
+ torture_result(tctx, TORTURE_ERROR, "(%s) ERROR: open of %s failed (%s)\n", \
__location__, fname, nt_errstr(status)); \
ret = false; \
goto done; \
@@ -84,7 +93,7 @@ bool torture_smb2_setinfo(struct torture_context *torture)
sfinfo.generic.in.file.handle = handle; \
status = smb2_setinfo_file(tree, &sfinfo); \
if (!NT_STATUS_EQUAL(status, rightstatus)) { \
- printf("(%s) %s - %s (should be %s)\n", __location__, #call, \
+ torture_result(tctx, TORTURE_FAIL, "(%s) %s - %s (should be %s)\n", __location__, #call, \
nt_errstr(status), nt_errstr(rightstatus)); \
ret = false; \
goto done; \
@@ -95,9 +104,9 @@ bool torture_smb2_setinfo(struct torture_context *torture)
do { if (NT_STATUS_IS_OK(status)) { \
finfo2.generic.level = RAW_FILEINFO_ ## call; \
finfo2.generic.in.file.handle = handle; \
- status2 = smb2_getinfo_file(tree, torture, &finfo2); \
+ status2 = smb2_getinfo_file(tree, tctx, &finfo2); \
if (!NT_STATUS_IS_OK(status2)) { \
- printf("(%s) %s - %s\n", __location__, #call, nt_errstr(status2)); \
+ torture_result(tctx, TORTURE_FAIL, "(%s) %s - %s\n", __location__, #call, nt_errstr(status2)); \
ret = false; \
goto done; \
} \
@@ -106,7 +115,7 @@ bool torture_smb2_setinfo(struct torture_context *torture)
#define CHECK_VALUE(call, stype, field, value) do { \
CHECK1(call); \
if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && finfo2.stype.out.field != value) { \
- printf("(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
+ torture_result(tctx, TORTURE_FAIL, "(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
call_name, #stype, #field, \
(uint_t)value, (uint_t)finfo2.stype.out.field); \
torture_smb2_all_info(tree, handle); \
@@ -117,12 +126,12 @@ bool torture_smb2_setinfo(struct torture_context *torture)
#define CHECK_TIME(call, stype, field, value) do { \
CHECK1(call); \
if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && nt_time_to_unix(finfo2.stype.out.field) != value) { \
- printf("(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
+ torture_result(tctx, TORTURE_FAIL, "(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
call_name, #stype, #field, \
(uint_t)value, \
(uint_t)nt_time_to_unix(finfo2.stype.out.field)); \
- printf("\t%s", timestring(torture, value)); \
- printf("\t%s\n", nt_time_string(torture, finfo2.stype.out.field)); \
+ torture_warning(tctx, "\t%s", timestring(tctx, value)); \
+ torture_warning(tctx, "\t%s\n", nt_time_string(tctx, finfo2.stype.out.field)); \
torture_smb2_all_info(tree, handle); \
ret = false; \
goto done; \
@@ -130,7 +139,7 @@ bool torture_smb2_setinfo(struct torture_context *torture)
#define CHECK_STATUS(status, correct) do { \
if (!NT_STATUS_EQUAL(status, correct)) { \
- printf("(%s) Incorrect status %s - should be %s\n", \
+ torture_result(tctx, TORTURE_FAIL, "(%s) Incorrect status %s - should be %s\n", \
__location__, nt_errstr(status), nt_errstr(correct)); \
ret = false; \
goto done; \
@@ -138,7 +147,7 @@ bool torture_smb2_setinfo(struct torture_context *torture)
torture_smb2_all_info(tree, handle);
- printf("test basic_information level\n");
+ torture_comment(tctx, "test basic_information level\n");
basetime += 86400;
unix_to_nt_time(&sfinfo.basic_info.in.create_time, basetime + 100);
unix_to_nt_time(&sfinfo.basic_info.in.access_time, basetime + 200);
@@ -152,7 +161,7 @@ bool torture_smb2_setinfo(struct torture_context *torture)
CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, change_time, basetime + 400);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_READONLY);
- printf("a zero time means don't change\n");
+ torture_comment(tctx, "a zero time means don't change\n");
unix_to_nt_time(&sfinfo.basic_info.in.create_time, 0);
unix_to_nt_time(&sfinfo.basic_info.in.access_time, 0);
unix_to_nt_time(&sfinfo.basic_info.in.write_time, 0);
@@ -165,26 +174,26 @@ bool torture_smb2_setinfo(struct torture_context *torture)
CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, change_time, basetime + 400);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_NORMAL);
- printf("change the attribute\n");
+ torture_comment(tctx, "change the attribute\n");
sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_HIDDEN;
CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_HIDDEN);
- printf("zero attrib means don't change\n");
+ torture_comment(tctx, "zero attrib means don't change\n");
sfinfo.basic_info.in.attrib = 0;
CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_HIDDEN);
- printf("can't change a file to a directory\n");
+ torture_comment(tctx, "can't change a file to a directory\n");
sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
CHECK_CALL(BASIC_INFORMATION, NT_STATUS_INVALID_PARAMETER);
- printf("restore attribute\n");
+ torture_comment(tctx, "restore attribute\n");
sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_NORMAL);
- printf("test disposition_information level\n");
+ torture_comment(tctx, "test disposition_information level\n");
sfinfo.disposition_info.in.delete_on_close = 1;
CHECK_CALL(DISPOSITION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, delete_pending, 1);
@@ -195,7 +204,7 @@ bool torture_smb2_setinfo(struct torture_context *torture)
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, delete_pending, 0);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, nlink, 1);
- printf("test allocation_information level\n");
+ torture_comment(tctx, "test allocation_information level\n");
sfinfo.allocation_info.in.alloc_size = 0;
CHECK_CALL(ALLOCATION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 0);
@@ -206,7 +215,7 @@ bool torture_smb2_setinfo(struct torture_context *torture)
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, alloc_size, 4096);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 0);
- printf("test end_of_file_info level\n");
+ torture_comment(tctx, "test end_of_file_info level\n");
sfinfo.end_of_file_info.in.size = 37;
CHECK_CALL(END_OF_FILE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 37);
@@ -215,13 +224,13 @@ bool torture_smb2_setinfo(struct torture_context *torture)
CHECK_CALL(END_OF_FILE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 7);
- printf("test position_information level\n");
+ torture_comment(tctx, "test position_information level\n");
sfinfo.position_information.in.position = 123456;
CHECK_CALL(POSITION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(POSITION_INFORMATION, position_information, position, 123456);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, position, 123456);
- printf("test mode_information level\n");
+ torture_comment(tctx, "test mode_information level\n");
sfinfo.mode_information.in.mode = 2;
CHECK_CALL(MODE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 2);
@@ -234,7 +243,7 @@ bool torture_smb2_setinfo(struct torture_context *torture)
CHECK_CALL(MODE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 0);
- printf("test sec_desc level\n");
+ torture_comment(tctx, "test sec_desc level\n");
ZERO_STRUCT(finfo2);
finfo2.query_secdesc.in.secinfo_flags =
SECINFO_OWNER |
@@ -243,7 +252,7 @@ bool torture_smb2_setinfo(struct torture_context *torture)
CHECK1(SEC_DESC);
sd = finfo2.query_secdesc.out.sd;
- test_sid = dom_sid_parse_talloc(torture, "S-1-5-32-1234-5432");
+ test_sid = dom_sid_parse_talloc(tctx, SID_NT_AUTHENTICATED_USERS);
ZERO_STRUCT(ace);
ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
ace.flags = 0;
@@ -252,23 +261,14 @@ bool torture_smb2_setinfo(struct torture_context *torture)
status = security_descriptor_dacl_add(sd, &ace);
CHECK_STATUS(status, NT_STATUS_OK);
- printf("add a new ACE to the DACL\n");
+ torture_comment(tctx, "add a new ACE to the DACL\n");
sfinfo.set_secdesc.in.secinfo_flags = finfo2.query_secdesc.in.secinfo_flags;
sfinfo.set_secdesc.in.sd = sd;
CHECK_CALL(SEC_DESC, NT_STATUS_OK);
- CHECK1(SEC_DESC);
-
- if (!security_acl_equal(finfo2.query_secdesc.out.sd->dacl, sd->dacl)) {
- printf("%s: security descriptors don't match!\n", __location__);
- printf("got:\n");
- NDR_PRINT_DEBUG(security_descriptor, finfo2.query_secdesc.out.sd);
- printf("expected:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd);
- ret = false;
- }
+ FAIL_UNLESS(smb2_util_verify_sd(tctx, tree, handle, sd));
- printf("remove it again\n");
+ torture_comment(tctx, "remove it again\n");
status = security_descriptor_dacl_del(sd, test_sid);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -276,21 +276,12 @@ bool torture_smb2_setinfo(struct torture_context *torture)
sfinfo.set_secdesc.in.secinfo_flags = finfo2.query_secdesc.in.secinfo_flags;
sfinfo.set_secdesc.in.sd = sd;
CHECK_CALL(SEC_DESC, NT_STATUS_OK);
- CHECK1(SEC_DESC);
-
- if (!security_acl_equal(finfo2.query_secdesc.out.sd->dacl, sd->dacl)) {
- printf("%s: security descriptors don't match!\n", __location__);
- printf("got:\n");
- NDR_PRINT_DEBUG(security_descriptor, finfo2.query_secdesc.out.sd);
- printf("expected:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd);
- ret = false;
- }
+ FAIL_UNLESS(smb2_util_verify_sd(tctx, tree, handle, sd));
done:
status = smb2_util_close(tree, handle);
if (NT_STATUS_IS_ERR(status)) {
- printf("Failed to delete %s - %s\n", fname, nt_errstr(status));
+ torture_warning(tctx, "Failed to delete %s - %s\n", fname, nt_errstr(status));
}
smb2_util_unlink(tree, fname);
diff --git a/source4/torture/smb2/smb2.c b/source4/torture/smb2/smb2.c
index cff71f8053..da5d9b3e78 100644
--- a/source4/torture/smb2/smb2.c
+++ b/source4/torture/smb2/smb2.c
@@ -136,6 +136,7 @@ NTSTATUS torture_smb2_init(void)
torture_suite_add_suite(suite, torture_smb2_lock_init());
torture_suite_add_suite(suite, torture_smb2_read_init());
torture_suite_add_suite(suite, torture_smb2_create_init());
+ torture_suite_add_suite(suite, torture_smb2_acls_init());
torture_suite_add_suite(suite, torture_smb2_notify_init());
torture_suite_add_suite(suite, torture_smb2_durable_open_init());
torture_suite_add_suite(suite, torture_smb2_dir_init());
diff --git a/source4/torture/smb2/util.c b/source4/torture/smb2/util.c
index 4fb7cfbef2..1dc8fca2b0 100644
--- a/source4/torture/smb2/util.c
+++ b/source4/torture/smb2/util.c
@@ -20,6 +20,7 @@
*/
#include "includes.h"
+#include "libcli/security/security_descriptor.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "lib/cmdline/popt_common.h"
@@ -444,29 +445,27 @@ bool smb2_util_verify_sd(TALLOC_CTX *tctx, struct smb2_tree *tree,
{
NTSTATUS status;
bool ret = true;
- union smb_fileinfo q = {}, q2 = {};
-
- if (sd) {
- q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
- q.query_secdesc.in.file.handle = handle;
- q.query_secdesc.in.secinfo_flags =
- SECINFO_OWNER |
- SECINFO_GROUP |
- SECINFO_DACL;
- status = smb2_getinfo_file(tree, tctx, &q);
- CHECK_STATUS(status, NT_STATUS_OK);
-
- if (!security_acl_equal(
- q.query_secdesc.out.sd->dacl, sd->dacl)) {
- torture_warning(tctx, "%s: security descriptors don't match!\n",
- __location__);
- torture_warning(tctx, "got:\n");
- NDR_PRINT_DEBUG(security_descriptor,
- q.query_secdesc.out.sd);
- torture_warning(tctx, "expected:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd);
- ret = false;
- }
+ union smb_fileinfo q = {};
+
+ q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ q.query_secdesc.in.file.handle = handle;
+ q.query_secdesc.in.secinfo_flags =
+ SECINFO_OWNER |
+ SECINFO_GROUP |
+ SECINFO_DACL;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ if (!security_acl_equal(
+ q.query_secdesc.out.sd->dacl, sd->dacl)) {
+ torture_warning(tctx, "%s: security descriptors don't match!\n",
+ __location__);
+ torture_warning(tctx, "got:\n");
+ NDR_PRINT_DEBUG(security_descriptor,
+ q.query_secdesc.out.sd);
+ torture_warning(tctx, "expected:\n");
+ NDR_PRINT_DEBUG(security_descriptor, sd);
+ ret = false;
}
done:
@@ -482,23 +481,21 @@ bool smb2_util_verify_attrib(TALLOC_CTX *tctx, struct smb2_tree *tree,
{
NTSTATUS status;
bool ret = true;
- union smb_fileinfo q = {}, q2 = {};
-
- if (attrib) {
- q2.standard.level = RAW_FILEINFO_STANDARD;
- q2.standard.in.file.handle = handle;
- status = smb2_getinfo_file(tree, tctx, &q2);
- CHECK_STATUS(status, NT_STATUS_OK);
-
- q2.standard.out.attrib &= ~FILE_ATTRIBUTE_ARCHIVE;
-
- if (q2.standard.out.attrib != attrib) {
- torture_warning(tctx, "%s: attributes don't match! "
- "got %x, expected %x\n", __location__,
- (uint32_t)q2.standard.out.attrib,
- (uint32_t)attrib);
- ret = false;
- }
+ union smb_fileinfo q = {};
+
+ q.standard.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
+ q.standard.in.file.handle = handle;
+ status = smb2_getinfo_file(tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ q.all_info2.out.attrib &= ~FILE_ATTRIBUTE_ARCHIVE;
+
+ if (q.all_info2.out.attrib != attrib) {
+ torture_warning(tctx, "%s: attributes don't match! "
+ "got %x, expected %x\n", __location__,
+ (uint32_t)q.standard.out.attrib,
+ (uint32_t)attrib);
+ ret = false;
}
done: