summaryrefslogtreecommitdiff
path: root/source4/torture/raw
diff options
context:
space:
mode:
authorZack Kirsch <zack.kirsch@isilon.com>2009-07-02 14:08:41 -0700
committerTim Prouty <tprouty@samba.org>2009-12-07 16:54:16 -0800
commit1724273ab94269783ddbe367c5c9ec2bf690b70b (patch)
tree62e28fcf4e5434a41c2bf0b23300515af9908b9e /source4/torture/raw
parent919440a2aa19b8e0eeb6387fea99dd049132b7dd (diff)
downloadsamba-1724273ab94269783ddbe367c5c9ec2bf690b70b.tar.gz
samba-1724273ab94269783ddbe367c5c9ec2bf690b70b.tar.bz2
samba-1724273ab94269783ddbe367c5c9ec2bf690b70b.zip
s4 torture: RAW-ACL Improvements
- Change RAW-ACLS test suite so each test can be run individually. - Add verify_sd() and verify_attrib() helper functions. - Change test_nttrans_create() to work for both files and directories. - Fix a segfault in test_inheritance() when the test errors out early. - test_sd_get_set() does not pass against XP or Vista, so it is no longer added to the RAW-ACLS test suite. - Minor fixes to test_inheritance(). - New INHERITFLAGS test, which tests the auto inheritance flags a bit more. - printf -> torture_comment / torture_warning / torture_result
Diffstat (limited to 'source4/torture/raw')
-rw-r--r--source4/torture/raw/acls.c939
-rw-r--r--source4/torture/raw/raw.c2
2 files changed, 672 insertions, 269 deletions
diff --git a/source4/torture/raw/acls.c b/source4/torture/raw/acls.c
index 8fde373dce..94274237af 100644
--- a/source4/torture/raw/acls.c
+++ b/source4/torture/raw/acls.c
@@ -33,15 +33,102 @@
#define CHECK_STATUS(status, correct) do { \
if (!NT_STATUS_EQUAL(status, correct)) { \
- printf("(%s) Incorrect status %s - should be %s\n", \
- __location__, nt_errstr(status), nt_errstr(correct)); \
ret = false; \
+ torture_result(tctx, TORTURE_FAIL, "(%s) Incorrect status %s - should be %s\n", \
+ __location__, nt_errstr(status), nt_errstr(correct)); \
goto done; \
}} while (0)
+#define FAIL_UNLESS(__cond) \
+ do { \
+ if (__cond) {} else { \
+ ret = false; \
+ torture_result(tctx, TORTURE_FAIL, "%s) condition violated: %s\n", \
+ __location__, #__cond); \
+ 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)
-static bool test_sd(struct torture_context *tctx,
- struct smbcli_state *cli)
+/*
+ * Helper function to verify a security descriptor, by querying
+ * and comparing against the passed in sd.
+ * Copied to smb2_util_verify_sd() for SMB2.
+ */
+static bool verify_sd(TALLOC_CTX *tctx, struct smbcli_state *cli,
+ int fnum, struct security_descriptor *sd)
+{
+ NTSTATUS status;
+ bool ret = true;
+ union smb_fileinfo q = {};
+
+ if (sd) {
+ q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ q.query_secdesc.in.file.fnum = fnum;
+ q.query_secdesc.in.secinfo_flags =
+ SECINFO_OWNER |
+ SECINFO_GROUP |
+ SECINFO_DACL;
+ status = smb_raw_fileinfo(cli->tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ /* sd->type &= ~SEC_DESC_DACL_AUTO_INHERITED; */
+
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd);
+ }
+
+ done:
+ return ret;
+}
+
+/*
+ * Helper function to verify attributes, by querying
+ * and comparing against the passed attrib.
+ * Copied to smb2_util_verify_attrib() for SMB2.
+ */
+static bool verify_attrib(TALLOC_CTX *tctx, struct smbcli_state *cli,
+ int fnum, uint32_t attrib)
+{
+ NTSTATUS status;
+ bool ret = true;
+ union smb_fileinfo q2 = {};
+
+ if (attrib) {
+ q2.standard.level = RAW_FILEINFO_STANDARD;
+ q2.standard.in.file.fnum = fnum;
+ status = smb_raw_fileinfo(cli->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;
+ }
+ }
+
+ done:
+ return ret;
+}
+
+/**
+ * Test setting and removing a DACL.
+ * Test copied to torture_smb2_setinfo() for SMB2.
+ */
+static bool test_sd(struct torture_context *tctx, struct smbcli_state *cli)
{
NTSTATUS status;
union smb_open io;
@@ -54,7 +141,10 @@ static bool test_sd(struct torture_context *tctx,
struct security_descriptor *sd;
struct dom_sid *test_sid;
- printf("TESTING SETFILEINFO EA_SET\n");
+ if (!torture_setup_dir(cli, BASEDIR))
+ return false;
+
+ torture_comment(tctx, "TESTING SETFILEINFO EA_SET\n");
io.generic.level = RAW_OPEN_NTCREATEX;
io.ntcreatex.in.root_fid.fnum = 0;
@@ -84,9 +174,9 @@ static bool test_sd(struct torture_context *tctx,
CHECK_STATUS(status, NT_STATUS_OK);
sd = q.query_secdesc.out.sd;
- printf("add a new ACE to the DACL\n");
+ torture_comment(tctx, "add a new ACE to the DACL\n");
- test_sid = dom_sid_parse_talloc(tctx, "S-1-5-32-1234-5432");
+ test_sid = dom_sid_parse_talloc(tctx, SID_NT_AUTHENTICATED_USERS);
ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
ace.flags = 0;
@@ -103,68 +193,58 @@ static bool test_sd(struct torture_context *tctx,
status = smb_raw_setfileinfo(cli->tree, &set);
CHECK_STATUS(status, NT_STATUS_OK);
+ FAIL_UNLESS(verify_sd(tctx, cli, fnum, sd));
- status = smb_raw_fileinfo(cli->tree, tctx, &q);
- CHECK_STATUS(status, NT_STATUS_OK);
-
- if (!security_acl_equal(q.query_secdesc.out.sd->dacl, sd->dacl)) {
- printf("%s: security descriptors don't match!\n", __location__);
- printf("got:\n");
- NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
- printf("expected:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd);
- ret = false;
- }
-
- 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);
status = smb_raw_setfileinfo(cli->tree, &set);
CHECK_STATUS(status, NT_STATUS_OK);
-
- status = smb_raw_fileinfo(cli->tree, tctx, &q);
- CHECK_STATUS(status, NT_STATUS_OK);
-
- if (!security_acl_equal(q.query_secdesc.out.sd->dacl, sd->dacl)) {
- printf("%s: security descriptors don't match!\n", __location__);
- printf("got:\n");
- NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
- printf("expected:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd);
- ret = false;
- }
+ FAIL_UNLESS(verify_sd(tctx, cli, fnum, sd));
done:
smbcli_close(cli->tree, fnum);
+ smb_raw_exit(cli->session);
+ smbcli_deltree(cli->tree, BASEDIR);
+
return ret;
}
/*
test using nttrans create to create a file with an initial acl set
+ Test copied to test_create_acl() for SMB2.
*/
-static bool test_nttrans_create(struct torture_context *tctx,
- struct smbcli_state *cli)
+static bool test_nttrans_create_ext(struct torture_context *tctx,
+ struct smbcli_state *cli, bool test_dir)
{
NTSTATUS status;
union smb_open io;
const char *fname = BASEDIR "\\acl2.txt";
bool ret = true;
int fnum = -1;
- union smb_fileinfo q;
+ union smb_fileinfo q = {};
struct security_ace ace;
struct security_descriptor *sd;
struct dom_sid *test_sid;
-
- printf("testing nttrans create with sec_desc\n");
+ uint32_t attrib =
+ FILE_ATTRIBUTE_HIDDEN |
+ FILE_ATTRIBUTE_SYSTEM |
+ (test_dir ? FILE_ATTRIBUTE_DIRECTORY : 0);
+ NTSTATUS (*delete_func)(struct smbcli_tree *, const char *) =
+ test_dir ? smbcli_rmdir : smbcli_unlink;
+
+ if (!torture_setup_dir(cli, BASEDIR))
+ return false;
io.generic.level = RAW_OPEN_NTTRANS_CREATE;
io.ntcreatex.in.root_fid.fnum = 0;
io.ntcreatex.in.flags = 0;
io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
- io.ntcreatex.in.create_options = 0;
+ io.ntcreatex.in.create_options =
+ test_dir ? NTCREATEX_OPTIONS_DIRECTORY : 0;
io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
io.ntcreatex.in.share_access =
NTCREATEX_SHARE_ACCESS_READ |
@@ -177,13 +257,13 @@ static bool test_nttrans_create(struct torture_context *tctx,
io.ntcreatex.in.sec_desc = NULL;
io.ntcreatex.in.ea_list = NULL;
- printf("creating normal file\n");
+ torture_comment(tctx, "basic create\n");
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.ntcreatex.out.file.fnum;
- printf("querying ACL\n");
+ torture_comment(tctx, "querying ACL\n");
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
q.query_secdesc.in.file.fnum = fnum;
@@ -195,11 +275,14 @@ static bool test_nttrans_create(struct torture_context *tctx,
CHECK_STATUS(status, NT_STATUS_OK);
sd = q.query_secdesc.out.sd;
- smbcli_close(cli->tree, fnum);
- smbcli_unlink(cli->tree, fname);
+ status = smbcli_close(cli->tree, fnum);
+ CHECK_STATUS(status, NT_STATUS_OK);
- printf("adding a new ACE\n");
- test_sid = dom_sid_parse_talloc(tctx, "S-1-5-32-1234-54321");
+ status = delete_func(cli->tree, fname);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ 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;
@@ -209,31 +292,99 @@ static bool test_nttrans_create(struct torture_context *tctx,
status = security_descriptor_dacl_add(sd, &ace);
CHECK_STATUS(status, NT_STATUS_OK);
- printf("creating a file with an initial ACL\n");
+ torture_comment(tctx, "creating with an initial ACL\n");
io.ntcreatex.in.sec_desc = sd;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.ntcreatex.out.file.fnum;
- q.query_secdesc.in.file.fnum = fnum;
- status = smb_raw_fileinfo(cli->tree, tctx, &q);
+ FAIL_UNLESS(verify_sd(tctx, cli, fnum, sd));
+
+ status = smbcli_close(cli->tree, fnum);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ status = delete_func(cli->tree, fname);
CHECK_STATUS(status, NT_STATUS_OK);
- if (!security_acl_equal(q.query_secdesc.out.sd->dacl, sd->dacl)) {
- printf("%s: security descriptors don't match!\n", __location__);
- printf("got:\n");
- NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
- printf("expected:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd);
- ret = false;
- }
+ torture_comment(tctx, "creating with attributes\n");
-done:
+ io.ntcreatex.in.sec_desc = NULL;
+ io.ntcreatex.in.file_attr = attrib;
+ status = smb_raw_open(cli->tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ fnum = io.ntcreatex.out.file.fnum;
+
+ FAIL_UNLESS(verify_attrib(tctx, cli, fnum, attrib));
+
+ status = smbcli_close(cli->tree, fnum);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ status = delete_func(cli->tree, fname);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ torture_comment(tctx, "creating with attributes and ACL\n");
+
+ io.ntcreatex.in.sec_desc = sd;
+ io.ntcreatex.in.file_attr = attrib;
+ status = smb_raw_open(cli->tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ fnum = io.ntcreatex.out.file.fnum;
+
+ FAIL_UNLESS(verify_sd(tctx, cli, fnum, sd));
+ FAIL_UNLESS(verify_attrib(tctx, cli, fnum, attrib));
+
+ status = smbcli_close(cli->tree, fnum);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ status = delete_func(cli->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.ntcreatex.in.sec_desc = sd;
+ io.ntcreatex.in.file_attr = attrib;
+ status = smb_raw_open(cli->tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ fnum = io.ntcreatex.out.file.fnum;
+
+ FAIL_UNLESS(verify_sd(tctx, cli, fnum, sd));
+ FAIL_UNLESS(verify_attrib(tctx, cli, fnum, attrib));
+
+ status = smbcli_close(cli->tree, fnum);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ status = delete_func(cli->tree, fname);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ done:
smbcli_close(cli->tree, fnum);
+ smb_raw_exit(cli->session);
+ smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
+static bool test_nttrans_create_file(struct torture_context *tctx,
+ struct smbcli_state *cli)
+{
+ torture_comment(tctx, "testing nttrans create with sec_desc on files\n");
+
+ return test_nttrans_create_ext(tctx, cli, false);
+}
+
+static bool test_nttrans_create_dir(struct torture_context *tctx,
+ struct smbcli_state *cli)
+{
+ torture_comment(tctx, "testing nttrans create with sec_desc on directories\n");
+
+ return test_nttrans_create_ext(tctx, cli, true);
+}
+
#define CHECK_ACCESS_FLAGS(_fnum, flags) do { \
union smb_fileinfo _q; \
_q.access_information.level = RAW_FILEINFO_ACCESS_INFORMATION; \
@@ -241,22 +392,23 @@ done:
status = smb_raw_fileinfo(cli->tree, tctx, &_q); \
CHECK_STATUS(status, NT_STATUS_OK); \
if (_q.access_information.out.access_flags != (flags)) { \
- printf("(%s) Incorrect access_flags 0x%08x - should be 0x%08x\n", \
- __location__, _q.access_information.out.access_flags, (flags)); \
ret = false; \
+ torture_result(tctx, TORTURE_FAIL, "(%s) Incorrect access_flags 0x%08x - should be 0x%08x\n", \
+ __location__, _q.access_information.out.access_flags, (flags)); \
goto done; \
} \
} while (0)
/*
test using NTTRANS CREATE to create a file with a null ACL set
+ Test copied to test_create_null_dacl() for SMB2.
*/
static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
struct smbcli_state *cli)
{
NTSTATUS status;
union smb_open io;
- const char *fname = BASEDIR "\\acl3.txt";
+ const char *fname = BASEDIR "\\nulldacl.txt";
bool ret = true;
int fnum = -1;
union smb_fileinfo q;
@@ -264,7 +416,10 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
struct security_descriptor *sd = security_descriptor_initialise(tctx);
struct security_acl dacl;
- printf("TESTING SEC_DESC WITH A NULL DACL\n");
+ if (!torture_setup_dir(cli, BASEDIR))
+ return false;
+
+ torture_comment(tctx, "TESTING SEC_DESC WITH A NULL DACL\n");
io.generic.level = RAW_OPEN_NTTRANS_CREATE;
io.ntcreatex.in.root_fid.fnum = 0;
@@ -283,12 +438,12 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
io.ntcreatex.in.sec_desc = sd;
io.ntcreatex.in.ea_list = NULL;
- printf("creating a file with a empty sd\n");
+ torture_comment(tctx, "creating a file with a empty sd\n");
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.ntcreatex.out.file.fnum;
- printf("get the original sd\n");
+ torture_comment(tctx, "get the original sd\n");
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
q.query_secdesc.in.file.fnum = fnum;
q.query_secdesc.in.secinfo_flags =
@@ -304,17 +459,17 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
* when SEC_DESC_DACL_PRESENT isn't specified
*/
if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
- printf("DACL_PRESENT flag not set by the server!\n");
ret = false;
+ torture_result(tctx, TORTURE_FAIL, "DACL_PRESENT flag not set by the server!\n");
goto done;
}
if (q.query_secdesc.out.sd->dacl == NULL) {
- printf("no DACL has been created on the server!\n");
ret = false;
+ torture_result(tctx, TORTURE_FAIL, "no DACL has been created on the server!\n");
goto done;
}
- printf("set NULL DACL\n");
+ torture_comment(tctx, "set NULL DACL\n");
sd->type |= SEC_DESC_DACL_PRESENT;
s.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
@@ -324,7 +479,7 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
status = smb_raw_setfileinfo(cli->tree, &s);
CHECK_STATUS(status, NT_STATUS_OK);
- printf("get the sd\n");
+ torture_comment(tctx, "get the sd\n");
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
q.query_secdesc.in.file.fnum = fnum;
q.query_secdesc.in.secinfo_flags =
@@ -336,17 +491,17 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
/* Testing the modified DACL */
if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
- printf("DACL_PRESENT flag not set by the server!\n");
ret = false;
+ torture_result(tctx, TORTURE_FAIL, "DACL_PRESENT flag not set by the server!\n");
goto done;
}
if (q.query_secdesc.out.sd->dacl != NULL) {
- printf("DACL has been created on the server!\n");
ret = false;
+ torture_result(tctx, TORTURE_FAIL, "DACL has been created on the server!\n");
goto done;
}
- printf("try open for read control\n");
+ torture_comment(tctx, "try open for read control\n");
io.ntcreatex.in.access_mask = SEC_STD_READ_CONTROL;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -354,7 +509,7 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
SEC_STD_READ_CONTROL | SEC_FILE_READ_ATTRIBUTE);
smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
- printf("try open for write\n");
+ torture_comment(tctx, "try open for write\n");
io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -362,7 +517,7 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
SEC_FILE_WRITE_DATA | SEC_FILE_READ_ATTRIBUTE);
smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
- printf("try open for read\n");
+ torture_comment(tctx, "try open for read\n");
io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -370,7 +525,7 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
SEC_FILE_READ_DATA | SEC_FILE_READ_ATTRIBUTE);
smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
- printf("try open for generic write\n");
+ torture_comment(tctx, "try open for generic write\n");
io.ntcreatex.in.access_mask = SEC_GENERIC_WRITE;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -378,7 +533,7 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
SEC_RIGHTS_FILE_WRITE | SEC_FILE_READ_ATTRIBUTE);
smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
- printf("try open for generic read\n");
+ torture_comment(tctx, "try open for generic read\n");
io.ntcreatex.in.access_mask = SEC_GENERIC_READ;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -386,7 +541,7 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
SEC_RIGHTS_FILE_READ | SEC_FILE_READ_ATTRIBUTE);
smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
- printf("set DACL with 0 aces\n");
+ torture_comment(tctx, "set DACL with 0 aces\n");
ZERO_STRUCT(dacl);
dacl.revision = SECURITY_ACL_REVISION_NT4;
dacl.num_aces = 0;
@@ -399,7 +554,7 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
status = smb_raw_setfileinfo(cli->tree, &s);
CHECK_STATUS(status, NT_STATUS_OK);
- printf("get the sd\n");
+ torture_comment(tctx, "get the sd\n");
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
q.query_secdesc.in.file.fnum = fnum;
q.query_secdesc.in.secinfo_flags =
@@ -411,23 +566,23 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
/* Testing the modified DACL */
if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
- printf("DACL_PRESENT flag not set by the server!\n");
ret = false;
+ torture_result(tctx, TORTURE_FAIL, "DACL_PRESENT flag not set by the server!\n");
goto done;
}
if (q.query_secdesc.out.sd->dacl == NULL) {
- printf("no DACL has been created on the server!\n");
ret = false;
+ torture_result(tctx, TORTURE_FAIL, "no DACL has been created on the server!\n");
goto done;
}
if (q.query_secdesc.out.sd->dacl->num_aces != 0) {
- printf("DACL has %u aces!\n",
- q.query_secdesc.out.sd->dacl->num_aces);
ret = false;
+ torture_result(tctx, TORTURE_FAIL, "DACL has %u aces!\n",
+ q.query_secdesc.out.sd->dacl->num_aces);
goto done;
}
- printf("try open for read control\n");
+ torture_comment(tctx, "try open for read control\n");
io.ntcreatex.in.access_mask = SEC_STD_READ_CONTROL;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -435,27 +590,27 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
SEC_STD_READ_CONTROL | SEC_FILE_READ_ATTRIBUTE);
smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
- printf("try open for write => access_denied\n");
+ torture_comment(tctx, "try open for write => access_denied\n");
io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- printf("try open for read => access_denied\n");
+ torture_comment(tctx, "try open for read => access_denied\n");
io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- printf("try open for generic write => access_denied\n");
+ torture_comment(tctx, "try open for generic write => access_denied\n");
io.ntcreatex.in.access_mask = SEC_GENERIC_WRITE;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- printf("try open for generic read => access_denied\n");
+ torture_comment(tctx, "try open for generic read => access_denied\n");
io.ntcreatex.in.access_mask = SEC_GENERIC_READ;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- printf("set empty sd\n");
+ torture_comment(tctx, "set empty sd\n");
sd->type &= ~SEC_DESC_DACL_PRESENT;
sd->dacl = NULL;
@@ -466,7 +621,7 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
status = smb_raw_setfileinfo(cli->tree, &s);
CHECK_STATUS(status, NT_STATUS_OK);
- printf("get the sd\n");
+ torture_comment(tctx, "get the sd\n");
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
q.query_secdesc.in.file.fnum = fnum;
q.query_secdesc.in.secinfo_flags =
@@ -478,23 +633,26 @@ static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
/* Testing the modified DACL */
if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
- printf("DACL_PRESENT flag not set by the server!\n");
ret = false;
+ torture_result(tctx, TORTURE_FAIL, "DACL_PRESENT flag not set by the server!\n");
goto done;
}
if (q.query_secdesc.out.sd->dacl != NULL) {
- printf("DACL has been created on the server!\n");
ret = false;
+ torture_result(tctx, TORTURE_FAIL, "DACL has been created on the server!\n");
goto done;
}
done:
smbcli_close(cli->tree, fnum);
+ smb_raw_exit(cli->session);
+ smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/*
test the behaviour of the well known SID_CREATOR_OWNER sid, and some generic
mapping bits
+ Test copied to smb2/acls.c for SMB2.
*/
static bool test_creator_sid(struct torture_context *tctx,
struct smbcli_state *cli)
@@ -509,7 +667,10 @@ static bool test_creator_sid(struct torture_context *tctx,
struct security_descriptor *sd, *sd_orig, *sd2;
const char *owner_sid;
- printf("TESTING SID_CREATOR_OWNER\n");
+ if (!torture_setup_dir(cli, BASEDIR))
+ return false;
+
+ torture_comment(tctx, "TESTING SID_CREATOR_OWNER\n");
io.generic.level = RAW_OPEN_NTCREATEX;
io.ntcreatex.in.root_fid.fnum = 0;
@@ -529,7 +690,7 @@ static bool test_creator_sid(struct torture_context *tctx,
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.ntcreatex.out.file.fnum;
- printf("get the original sd\n");
+ torture_comment(tctx, "get the original sd\n");
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
q.query_secdesc.in.file.fnum = fnum;
q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
@@ -539,7 +700,7 @@ static bool test_creator_sid(struct torture_context *tctx,
owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
- printf("set a sec desc allowing no write by CREATOR_OWNER\n");
+ 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,
@@ -556,27 +717,27 @@ static bool test_creator_sid(struct torture_context *tctx,
status = smb_raw_setfileinfo(cli->tree, &set);
CHECK_STATUS(status, NT_STATUS_OK);
- printf("try open for write\n");
+ torture_comment(tctx, "try open for write\n");
io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- printf("try open for read\n");
+ torture_comment(tctx, "try open for read\n");
io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- printf("try open for generic write\n");
+ torture_comment(tctx, "try open for generic write\n");
io.ntcreatex.in.access_mask = SEC_GENERIC_WRITE;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- printf("try open for generic read\n");
+ torture_comment(tctx, "try open for generic read\n");
io.ntcreatex.in.access_mask = SEC_GENERIC_READ;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- printf("set a sec desc allowing no write by owner\n");
+ 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,
@@ -592,24 +753,17 @@ static bool test_creator_sid(struct torture_context *tctx,
status = smb_raw_setfileinfo(cli->tree, &set);
CHECK_STATUS(status, NT_STATUS_OK);
- printf("check that sd has been mapped correctly\n");
+ torture_comment(tctx, "check that sd has been mapped correctly\n");
status = smb_raw_fileinfo(cli->tree, tctx, &q);
CHECK_STATUS(status, NT_STATUS_OK);
- if (!security_descriptor_equal(q.query_secdesc.out.sd, sd)) {
- printf("%s: security descriptors don't match!\n", __location__);
- printf("got:\n");
- NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
- printf("expected:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd);
- ret = false;
- }
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd);
- printf("try open for write\n");
+ torture_comment(tctx, "try open for write\n");
io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- printf("try open for read\n");
+ torture_comment(tctx, "try open for read\n");
io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -618,12 +772,12 @@ static bool test_creator_sid(struct torture_context *tctx,
SEC_FILE_READ_ATTRIBUTE);
smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
- printf("try open for generic write\n");
+ torture_comment(tctx, "try open for generic write\n");
io.ntcreatex.in.access_mask = SEC_GENERIC_WRITE;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- printf("try open for generic read\n");
+ torture_comment(tctx, "try open for generic read\n");
io.ntcreatex.in.access_mask = SEC_GENERIC_READ;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -631,7 +785,7 @@ static bool test_creator_sid(struct torture_context *tctx,
SEC_RIGHTS_FILE_READ);
smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
- printf("set a sec desc allowing generic read by owner\n");
+ torture_comment(tctx, "set a sec desc allowing generic read by owner\n");
sd = security_descriptor_dacl_create(tctx,
0, NULL, NULL,
owner_sid,
@@ -644,7 +798,7 @@ static bool test_creator_sid(struct torture_context *tctx,
status = smb_raw_setfileinfo(cli->tree, &set);
CHECK_STATUS(status, NT_STATUS_OK);
- printf("check that generic read has been mapped correctly\n");
+ torture_comment(tctx, "check that generic read has been mapped correctly\n");
sd2 = security_descriptor_dacl_create(tctx,
0, owner_sid, NULL,
owner_sid,
@@ -655,22 +809,14 @@ static bool test_creator_sid(struct torture_context *tctx,
status = smb_raw_fileinfo(cli->tree, tctx, &q);
CHECK_STATUS(status, NT_STATUS_OK);
- if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
- printf("%s: security descriptors don't match!\n", __location__);
- printf("got:\n");
- NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
- printf("expected:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd2);
- ret = false;
- }
-
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
- printf("try open for write\n");
+ torture_comment(tctx, "try open for write\n");
io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- printf("try open for read\n");
+ torture_comment(tctx, "try open for read\n");
io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -679,12 +825,12 @@ static bool test_creator_sid(struct torture_context *tctx,
SEC_FILE_READ_ATTRIBUTE);
smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
- printf("try open for generic write\n");
+ torture_comment(tctx, "try open for generic write\n");
io.ntcreatex.in.access_mask = SEC_GENERIC_WRITE;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- printf("try open for generic read\n");
+ torture_comment(tctx, "try open for generic read\n");
io.ntcreatex.in.access_mask = SEC_GENERIC_READ;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -692,7 +838,7 @@ static bool test_creator_sid(struct torture_context *tctx,
smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
- printf("put back original sd\n");
+ torture_comment(tctx, "put back original sd\n");
set.set_secdesc.in.sd = sd_orig;
status = smb_raw_setfileinfo(cli->tree, &set);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -700,6 +846,8 @@ static bool test_creator_sid(struct torture_context *tctx,
done:
smbcli_close(cli->tree, fnum);
+ smb_raw_exit(cli->session);
+ smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
@@ -707,6 +855,7 @@ done:
/*
test the mapping of the SEC_GENERIC_xx bits to SEC_STD_xx and
SEC_FILE_xx bits
+ Test copied to smb2/acls.c for SMB2.
*/
static bool test_generic_bits(struct torture_context *tctx,
struct smbcli_state *cli)
@@ -745,7 +894,10 @@ static bool test_generic_bits(struct torture_context *tctx,
bool has_restore_privilege;
bool has_take_ownership_privilege;
- printf("TESTING FILE GENERIC BITS\n");
+ if (!torture_setup_dir(cli, BASEDIR))
+ return false;
+
+ torture_comment(tctx, "TESTING FILE GENERIC BITS\n");
io.generic.level = RAW_OPEN_NTCREATEX;
io.ntcreatex.in.root_fid.fnum = 0;
@@ -768,7 +920,7 @@ static bool test_generic_bits(struct torture_context *tctx,
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.ntcreatex.out.file.fnum;
- printf("get the original sd\n");
+ torture_comment(tctx, "get the original sd\n");
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
q.query_secdesc.in.file.fnum = fnum;
q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
@@ -783,18 +935,20 @@ static bool test_generic_bits(struct torture_context *tctx,
sec_privilege_name(SEC_PRIV_RESTORE));
has_restore_privilege = NT_STATUS_IS_OK(status);
if (!NT_STATUS_IS_OK(status)) {
- printf("torture_check_privilege - %s\n", nt_errstr(status));
+ torture_warning(tctx, "torture_check_privilege - %s\n",
+ nt_errstr(status));
}
- printf("SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
+ torture_comment(tctx, "SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
status = torture_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)) {
- printf("torture_check_privilege - %s\n", nt_errstr(status));
+ torture_warning(tctx, "torture_check_privilege - %s\n",
+ nt_errstr(status));
}
- printf("SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
+ 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 =
@@ -808,7 +962,7 @@ static bool test_generic_bits(struct torture_context *tctx,
expected_mask_anon |= SEC_STD_DELETE;
}
- printf("testing generic bits 0x%08x\n",
+ torture_comment(tctx, "testing generic bits 0x%08x\n",
file_mappings[i].gen_bits);
sd = security_descriptor_dacl_create(tctx,
0, owner_sid, NULL,
@@ -836,14 +990,7 @@ static bool test_generic_bits(struct torture_context *tctx,
status = smb_raw_fileinfo(cli->tree, tctx, &q);
CHECK_STATUS(status, NT_STATUS_OK);
- if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
- printf("%s: security descriptors don't match!\n", __location__);
- printf("got:\n");
- NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
- printf("expected:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd2);
- ret = false;
- }
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
status = smb_raw_open(cli->tree, tctx, &io);
@@ -856,7 +1003,7 @@ static bool test_generic_bits(struct torture_context *tctx,
continue;
}
- printf("testing generic bits 0x%08x (anonymous)\n",
+ 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,
@@ -884,14 +1031,7 @@ static bool test_generic_bits(struct torture_context *tctx,
status = smb_raw_fileinfo(cli->tree, tctx, &q);
CHECK_STATUS(status, NT_STATUS_OK);
- if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
- printf("%s: security descriptors don't match!\n", __location__);
- printf("got:\n");
- NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
- printf("expected:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd2);
- ret = false;
- }
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
status = smb_raw_open(cli->tree, tctx, &io);
@@ -901,7 +1041,7 @@ static bool test_generic_bits(struct torture_context *tctx,
smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
}
- printf("put back original sd\n");
+ torture_comment(tctx, "put back original sd\n");
set.set_secdesc.in.sd = sd_orig;
status = smb_raw_setfileinfo(cli->tree, &set);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -910,7 +1050,7 @@ static bool test_generic_bits(struct torture_context *tctx,
smbcli_unlink(cli->tree, fname);
- printf("TESTING DIR GENERIC BITS\n");
+ torture_comment(tctx, "TESTING DIR GENERIC BITS\n");
io.generic.level = RAW_OPEN_NTCREATEX;
io.ntcreatex.in.root_fid.fnum = 0;
@@ -933,7 +1073,7 @@ static bool test_generic_bits(struct torture_context *tctx,
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.ntcreatex.out.file.fnum;
- printf("get the original sd\n");
+ torture_comment(tctx, "get the original sd\n");
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
q.query_secdesc.in.file.fnum = fnum;
q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
@@ -948,18 +1088,20 @@ static bool test_generic_bits(struct torture_context *tctx,
sec_privilege_name(SEC_PRIV_RESTORE));
has_restore_privilege = NT_STATUS_IS_OK(status);
if (!NT_STATUS_IS_OK(status)) {
- printf("torture_check_privilege - %s\n", nt_errstr(status));
+ torture_warning(tctx, "torture_check_privilege - %s\n",
+ nt_errstr(status));
}
- printf("SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
+ torture_comment(tctx, "SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
status = torture_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)) {
- printf("torture_check_privilege - %s\n", nt_errstr(status));
+ torture_warning(tctx, "torture_check_privilege - %s\n",
+ nt_errstr(status));
}
- printf("SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
+ 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 =
@@ -973,7 +1115,7 @@ static bool test_generic_bits(struct torture_context *tctx,
expected_mask_anon |= SEC_STD_DELETE;
}
- printf("testing generic bits 0x%08x\n",
+ torture_comment(tctx, "testing generic bits 0x%08x\n",
file_mappings[i].gen_bits);
sd = security_descriptor_dacl_create(tctx,
0, owner_sid, NULL,
@@ -1001,14 +1143,7 @@ static bool test_generic_bits(struct torture_context *tctx,
status = smb_raw_fileinfo(cli->tree, tctx, &q);
CHECK_STATUS(status, NT_STATUS_OK);
- if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
- printf("%s: security descriptors don't match!\n", __location__);
- printf("got:\n");
- NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
- printf("expected:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd2);
- ret = false;
- }
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
status = smb_raw_open(cli->tree, tctx, &io);
@@ -1021,7 +1156,7 @@ static bool test_generic_bits(struct torture_context *tctx,
continue;
}
- printf("testing generic bits 0x%08x (anonymous)\n",
+ 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,
@@ -1049,14 +1184,7 @@ static bool test_generic_bits(struct torture_context *tctx,
status = smb_raw_fileinfo(cli->tree, tctx, &q);
CHECK_STATUS(status, NT_STATUS_OK);
- if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
- printf("%s: security descriptors don't match!\n", __location__);
- printf("got:\n");
- NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
- printf("expected:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd2);
- ret = false;
- }
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
status = smb_raw_open(cli->tree, tctx, &io);
@@ -1066,7 +1194,7 @@ static bool test_generic_bits(struct torture_context *tctx,
smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
}
- printf("put back original sd\n");
+ torture_comment(tctx, "put back original sd\n");
set.set_secdesc.in.sd = sd_orig;
status = smb_raw_setfileinfo(cli->tree, &set);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -1076,12 +1204,15 @@ static bool test_generic_bits(struct torture_context *tctx,
done:
smbcli_close(cli->tree, fnum);
+ smb_raw_exit(cli->session);
+ smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/*
see what access bits the owner of a file always gets
+ Test copied to smb2/acls.c for SMB2.
*/
static bool test_owner_bits(struct torture_context *tctx,
struct smbcli_state *cli)
@@ -1099,7 +1230,10 @@ static bool test_owner_bits(struct torture_context *tctx,
bool has_take_ownership_privilege;
uint32_t expected_bits;
- printf("TESTING FILE OWNER BITS\n");
+ if (!torture_setup_dir(cli, BASEDIR))
+ return false;
+
+ torture_comment(tctx, "TESTING FILE OWNER BITS\n");
io.generic.level = RAW_OPEN_NTCREATEX;
io.ntcreatex.in.root_fid.fnum = 0;
@@ -1122,7 +1256,7 @@ static bool test_owner_bits(struct torture_context *tctx,
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.ntcreatex.out.file.fnum;
- printf("get the original sd\n");
+ torture_comment(tctx, "get the original sd\n");
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
q.query_secdesc.in.file.fnum = fnum;
q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
@@ -1137,18 +1271,18 @@ static bool test_owner_bits(struct torture_context *tctx,
sec_privilege_name(SEC_PRIV_RESTORE));
has_restore_privilege = NT_STATUS_IS_OK(status);
if (!NT_STATUS_IS_OK(status)) {
- printf("torture_check_privilege - %s\n", nt_errstr(status));
+ torture_warning(tctx, "torture_check_privilege - %s\n", nt_errstr(status));
}
- printf("SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
+ torture_comment(tctx, "SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
status = torture_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)) {
- printf("torture_check_privilege - %s\n", nt_errstr(status));
+ torture_warning(tctx, "torture_check_privilege - %s\n", nt_errstr(status));
}
- printf("SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
+ torture_comment(tctx, "SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
sd = security_descriptor_dacl_create(tctx,
0, NULL, NULL,
@@ -1174,7 +1308,7 @@ static bool test_owner_bits(struct torture_context *tctx,
status = smb_raw_open(cli->tree, tctx, &io);
if (expected_bits & bit) {
if (!NT_STATUS_IS_OK(status)) {
- printf("failed with access mask 0x%08x of expected 0x%08x\n",
+ torture_warning(tctx, "failed with access mask 0x%08x of expected 0x%08x\n",
bit, expected_bits);
}
CHECK_STATUS(status, NT_STATUS_OK);
@@ -1182,7 +1316,7 @@ static bool test_owner_bits(struct torture_context *tctx,
smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
} else {
if (NT_STATUS_IS_OK(status)) {
- printf("open succeeded with access mask 0x%08x of "
+ torture_warning(tctx, "open succeeded with access mask 0x%08x of "
"expected 0x%08x - should fail\n",
bit, expected_bits);
}
@@ -1190,7 +1324,7 @@ static bool test_owner_bits(struct torture_context *tctx,
}
}
- printf("put back original sd\n");
+ torture_comment(tctx, "put back original sd\n");
set.set_secdesc.in.sd = sd_orig;
status = smb_raw_setfileinfo(cli->tree, &set);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -1198,6 +1332,8 @@ static bool test_owner_bits(struct torture_context *tctx,
done:
smbcli_close(cli->tree, fnum);
smbcli_unlink(cli->tree, fname);
+ smb_raw_exit(cli->session);
+ smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
@@ -1205,6 +1341,7 @@ done:
/*
test the inheritance of ACL flags onto new files and directories
+ Test copied to smb2/acls.c for SMB2.
*/
static bool test_inheritance(struct torture_context *tctx,
struct smbcli_state *cli)
@@ -1218,7 +1355,7 @@ static bool test_inheritance(struct torture_context *tctx,
int fnum=0, fnum2, i;
union smb_fileinfo q;
union smb_setfileinfo set;
- struct security_descriptor *sd, *sd2, *sd_orig=NULL, *sd_def;
+ struct security_descriptor *sd, *sd2, *sd_orig=NULL, *sd_def1, *sd_def2;
const char *owner_sid, *group_sid;
const struct dom_sid *creator_owner;
const struct {
@@ -1329,9 +1466,10 @@ static bool test_inheritance(struct torture_context *tctx,
}
};
- smbcli_rmdir(cli->tree, dname);
+ if (!torture_setup_dir(cli, BASEDIR))
+ return false;
- printf("TESTING ACL INHERITANCE\n");
+ torture_comment(tctx, "TESTING ACL INHERITANCE\n");
io.generic.level = RAW_OPEN_NTCREATEX;
io.ntcreatex.in.root_fid.fnum = 0;
@@ -1350,7 +1488,7 @@ static bool test_inheritance(struct torture_context *tctx,
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.ntcreatex.out.file.fnum;
- printf("get the original sd\n");
+ torture_comment(tctx, "get the original sd\n");
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
q.query_secdesc.in.file.fnum = fnum;
q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER | SECINFO_GROUP;
@@ -1361,15 +1499,15 @@ static bool test_inheritance(struct torture_context *tctx,
owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
group_sid = dom_sid_string(tctx, sd_orig->group_sid);
- printf("owner_sid is %s\n", owner_sid);
- printf("group_sid is %s\n", group_sid);
+ torture_comment(tctx, "owner_sid is %s\n", owner_sid);
+ torture_comment(tctx, "group_sid is %s\n", group_sid);
q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
if (torture_setting_bool(tctx, "samba4", false)) {
/* the default ACL in Samba4 includes the group and
other permissions */
- sd_def = security_descriptor_dacl_create(tctx,
+ sd_def1 = security_descriptor_dacl_create(tctx,
0, owner_sid, NULL,
owner_sid,
SEC_ACE_TYPE_ACCESS_ALLOWED,
@@ -1389,7 +1527,11 @@ static bool test_inheritance(struct torture_context *tctx,
0,
NULL);
} else {
- sd_def = security_descriptor_dacl_create(tctx,
+ /*
+ * 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,
@@ -1402,6 +1544,18 @@ static bool test_inheritance(struct torture_context *tctx,
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++) {
@@ -1437,10 +1591,12 @@ static bool test_inheritance(struct torture_context *tctx,
smbcli_unlink(cli->tree, fname1);
if (!(test_flags[i].parent_flags & SEC_ACE_FLAG_OBJECT_INHERIT)) {
- if (!security_descriptor_equal(q.query_secdesc.out.sd, sd_def)) {
- printf(__location__ ": Expected default sd for i=%d:\n", i);
- NDR_PRINT_DEBUG(security_descriptor, sd_def);
- printf("at %d - got:\n", i);
+ 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 i=%d:\n", i);
+ 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;
@@ -1451,15 +1607,15 @@ static bool test_inheritance(struct torture_context *tctx,
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)) {
- printf("Bad sd in child file at %d\n", i);
- NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
ret = false;
+ torture_warning(tctx, "Bad sd in child file at %d\n", i);
+ NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
goto check_dir;
}
if (q.query_secdesc.out.sd->dacl->aces[0].flags !=
test_flags[i].file_flags) {
- printf("incorrect file_flags 0x%x - expected 0x%x for parent 0x%x with (i=%d)\n",
+ 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,
@@ -1484,10 +1640,11 @@ static bool test_inheritance(struct torture_context *tctx,
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_def)) {
- printf("Expected default sd for dir at %d:\n", i);
- NDR_PRINT_DEBUG(security_descriptor, sd_def);
- printf("got:\n");
+ 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;
@@ -1501,9 +1658,12 @@ static bool test_inheritance(struct torture_context *tctx,
!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) {
- printf("(CI & NP) Bad sd in child dir at %d (parent 0x%x)\n",
- i, test_flags[i].parent_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_comment(tctx, "FYI, here is the parent sd:\n");
+ NDR_PRINT_DEBUG(security_descriptor, sd);
ret = false;
continue;
}
@@ -1519,9 +1679,12 @@ static bool test_inheritance(struct torture_context *tctx,
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)) {
- printf("(CI) Bad sd in child dir at %d (parent 0x%x)\n",
- i, test_flags[i].parent_flags);
+ 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_comment(tctx, "FYI, here is the parent sd:\n");
+ NDR_PRINT_DEBUG(security_descriptor, sd);
ret = false;
continue;
}
@@ -1532,16 +1695,19 @@ static bool test_inheritance(struct torture_context *tctx,
!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) {
- printf("(0) Bad sd in child dir at %d (parent 0x%x)\n",
- i, test_flags[i].parent_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_comment(tctx, "FYI, here is the parent sd:\n");
+ NDR_PRINT_DEBUG(security_descriptor, sd);
ret = false;
continue;
}
}
}
- printf("testing access checks on inherited create with %s\n", fname1);
+ torture_comment(tctx, "testing access checks on inherited create with %s\n", fname1);
sd = security_descriptor_dacl_create(tctx,
0, NULL, NULL,
owner_sid,
@@ -1560,6 +1726,14 @@ static bool test_inheritance(struct torture_context *tctx,
status = smb_raw_setfileinfo(cli->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.fnum = fnum;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL;
+ status = smb_raw_fileinfo(cli->tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd);
+
io.ntcreatex.in.fname = fname1;
io.ntcreatex.in.create_options = 0;
io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
@@ -1582,20 +1756,13 @@ static bool test_inheritance(struct torture_context *tctx,
SEC_FILE_WRITE_DATA | SEC_STD_WRITE_DAC,
0,
NULL);
- if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
- printf("%s: security descriptors don't match!\n", __location__);
- printf("got:\n");
- NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
- printf("expected:\n");
- NDR_PRINT_DEBUG(security_descriptor, sd2);
- ret = false;
- }
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
status = smb_raw_open(cli->tree, tctx, &io);
if (NT_STATUS_IS_OK(status)) {
- printf("failed: w2k3 ACL bug (allowed open when ACL should deny)\n");
+ torture_warning(tctx, "failed: w2k3 ACL bug (allowed open when ACL should deny)\n");
ret = false;
fnum2 = io.ntcreatex.out.file.fnum;
CHECK_ACCESS_FLAGS(fnum2, SEC_RIGHTS_FILE_ALL);
@@ -1604,13 +1771,13 @@ static bool test_inheritance(struct torture_context *tctx,
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
}
- printf("trying without execute\n");
+ torture_comment(tctx, "trying without execute\n");
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL & ~SEC_FILE_EXECUTE;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- printf("and with full permissions again\n");
+ torture_comment(tctx, "and with full permissions again\n");
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
status = smb_raw_open(cli->tree, tctx, &io);
@@ -1623,7 +1790,7 @@ static bool test_inheritance(struct torture_context *tctx,
CHECK_ACCESS_FLAGS(fnum2, SEC_FILE_WRITE_DATA | SEC_FILE_READ_ATTRIBUTE);
smbcli_close(cli->tree, fnum2);
- printf("put back original sd\n");
+ torture_comment(tctx, "put back original sd\n");
set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
set.set_secdesc.in.file.fnum = fnum;
set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
@@ -1648,19 +1815,251 @@ static bool test_inheritance(struct torture_context *tctx,
smbcli_rmdir(cli->tree, dname);
done:
- set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
- set.set_secdesc.in.file.fnum = fnum;
- set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
- set.set_secdesc.in.sd = sd_orig;
- status = smb_raw_setfileinfo(cli->tree, &set);
+ if (sd_orig != NULL) {
+ set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+ set.set_secdesc.in.file.fnum = fnum;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ set.set_secdesc.in.sd = sd_orig;
+ status = smb_raw_setfileinfo(cli->tree, &set);
+ }
smbcli_close(cli->tree, fnum);
+ smb_raw_exit(cli->session);
+ smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
+static bool test_inheritance_flags(struct torture_context *tctx,
+ struct smbcli_state *cli)
+{
+ NTSTATUS status;
+ union smb_open io;
+ const char *dname = BASEDIR "\\inheritance";
+ const char *fname1 = BASEDIR "\\inheritance\\testfile";
+ bool ret = true;
+ int fnum=0, fnum2, 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]; /* 2^4 */
+
+ for (i = 0; i < 15; i++) {
+ torture_comment(tctx, "i=%d:", i);
+
+ ZERO_STRUCT(tflags[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;
+ tflags[i].parent_get_sd_type |=
+ SEC_DESC_DACL_PROTECTED;
+ torture_comment(tctx, "PROTECTED, ");
+ }
+ if (i & 8) {
+ 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, "INHERITED, ");
+ }
+
+ 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 (!torture_setup_dir(cli, BASEDIR))
+ return false;
+
+ torture_comment(tctx, "TESTING ACL INHERITANCE FLAGS\n");
+
+ io.generic.level = RAW_OPEN_NTCREATEX;
+ io.ntcreatex.in.root_fid.fnum = 0;
+ io.ntcreatex.in.flags = 0;
+ io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+ io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+ io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
+ io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_MASK;
+ io.ntcreatex.in.alloc_size = 0;
+ io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
+ io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.ntcreatex.in.security_flags = 0;
+ io.ntcreatex.in.fname = dname;
+
+ torture_comment(tctx, "creating initial directory %s\n", dname);
+ status = smb_raw_open(cli->tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ fnum = io.ntcreatex.out.file.fnum;
+
+ torture_comment(tctx, "getting original sd\n");
+ q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ q.query_secdesc.in.file.fnum = fnum;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ status = smb_raw_fileinfo(cli->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.fnum = fnum;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ set.set_secdesc.in.sd = sd;
+ status = smb_raw_setfileinfo(cli->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.fnum = fnum;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL;
+ status = smb_raw_fileinfo(cli->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.ntcreatex.in.fname = fname1;
+ io.ntcreatex.in.create_options = 0;
+ io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+ io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+ io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
+ status = smb_raw_open(cli->tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ fnum2 = io.ntcreatex.out.file.fnum;
+ CHECK_ACCESS_FLAGS(fnum2, SEC_RIGHTS_FILE_ALL);
+
+ q.query_secdesc.in.file.fnum = fnum2;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ status = smb_raw_fileinfo(cli->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.fnum = fnum2;
+ set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
+ set.set_secdesc.in.sd = sd2;
+ status = smb_raw_setfileinfo(cli->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.fnum = fnum2;
+ q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
+ status = smb_raw_fileinfo(cli->tree, tctx, &q);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
+ }
+
+ smbcli_close(cli->tree, fnum2);
+ smbcli_unlink(cli->tree, fname1);
+ }
+
+done:
+ smbcli_close(cli->tree, fnum);
+ smb_raw_exit(cli->session);
+ smbcli_deltree(cli->tree, BASEDIR);
+ return ret;
+}
/*
test dynamic acl inheritance
+ Test copied to smb2/acls.c for SMB2.
*/
static bool test_inheritance_dynamic(struct torture_context *tctx,
struct smbcli_state *cli)
@@ -1676,11 +2075,10 @@ static bool test_inheritance_dynamic(struct torture_context *tctx,
struct security_descriptor *sd, *sd_orig=NULL;
const char *owner_sid;
- printf("TESTING DYNAMIC ACL INHERITANCE\n");
+ torture_comment(tctx, "TESTING DYNAMIC ACL INHERITANCE\n");
- if (!torture_setup_dir(cli, BASEDIR)) {
+ if (!torture_setup_dir(cli, BASEDIR))
return false;
- }
io.generic.level = RAW_OPEN_NTCREATEX;
io.ntcreatex.in.root_fid.fnum = 0;
@@ -1699,7 +2097,7 @@ static bool test_inheritance_dynamic(struct torture_context *tctx,
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.ntcreatex.out.file.fnum;
- printf("get the original sd\n");
+ torture_comment(tctx, "get the original sd\n");
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
q.query_secdesc.in.file.fnum = fnum;
q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
@@ -1709,7 +2107,7 @@ static bool test_inheritance_dynamic(struct torture_context *tctx,
owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
- printf("owner_sid is %s\n", owner_sid);
+ torture_comment(tctx, "owner_sid is %s\n", owner_sid);
sd = security_descriptor_dacl_create(tctx,
0, NULL, NULL,
@@ -1727,7 +2125,7 @@ static bool test_inheritance_dynamic(struct torture_context *tctx,
status = smb_raw_setfileinfo(cli->tree, &set);
CHECK_STATUS(status, NT_STATUS_OK);
- printf("create a file with an inherited acl\n");
+ torture_comment(tctx, "create a file with an inherited acl\n");
io.ntcreatex.in.fname = fname1;
io.ntcreatex.in.create_options = 0;
io.ntcreatex.in.access_mask = SEC_FILE_READ_ATTRIBUTE;
@@ -1737,7 +2135,7 @@ static bool test_inheritance_dynamic(struct torture_context *tctx,
fnum2 = io.ntcreatex.out.file.fnum;
smbcli_close(cli->tree, fnum2);
- printf("try and access file with base rights - should be OK\n");
+ torture_comment(tctx, "try and access file with base rights - should be OK\n");
io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
status = smb_raw_open(cli->tree, tctx, &io);
@@ -1745,12 +2143,12 @@ static bool test_inheritance_dynamic(struct torture_context *tctx,
fnum2 = io.ntcreatex.out.file.fnum;
smbcli_close(cli->tree, fnum2);
- printf("try and access file with extra rights - should be denied\n");
+ torture_comment(tctx, "try and access file with extra rights - should be denied\n");
io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA | SEC_FILE_EXECUTE;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
- printf("update parent sd\n");
+ torture_comment(tctx, "update parent sd\n");
sd = security_descriptor_dacl_create(tctx,
0, NULL, NULL,
owner_sid,
@@ -1764,7 +2162,7 @@ static bool test_inheritance_dynamic(struct torture_context *tctx,
status = smb_raw_setfileinfo(cli->tree, &set);
CHECK_STATUS(status, NT_STATUS_OK);
- printf("try and access file with base rights - should be OK\n");
+ torture_comment(tctx, "try and access file with base rights - should be OK\n");
io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
status = smb_raw_open(cli->tree, tctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
@@ -1772,21 +2170,21 @@ static bool test_inheritance_dynamic(struct torture_context *tctx,
smbcli_close(cli->tree, fnum2);
- printf("try and access now - should be OK if dynamic inheritance works\n");
+ torture_comment(tctx, "try and access now - should be OK if dynamic inheritance works\n");
io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA | SEC_FILE_EXECUTE;
status = smb_raw_open(cli->tree, tctx, &io);
if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
- printf("Server does not have dynamic inheritance\n");
+ torture_comment(tctx, "Server does not have dynamic inheritance\n");
}
if (NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
- printf("Server does have dynamic inheritance\n");
+ torture_comment(tctx, "Server does have dynamic inheritance\n");
}
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
smbcli_unlink(cli->tree, fname1);
done:
- printf("put back original sd\n");
+ torture_comment(tctx, "put back original sd\n");
set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
set.set_secdesc.in.file.fnum = fnum;
set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
@@ -1795,6 +2193,8 @@ done:
smbcli_close(cli->tree, fnum);
smbcli_rmdir(cli->tree, dname);
+ smb_raw_exit(cli->session);
+ smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
@@ -1811,23 +2211,24 @@ done:
#define CHECK_STATUS_FOR_BIT(status, bits, access) do { \
if (NT_STATUS_IS_OK(status)) { \
if (!(granted & access)) {\
- printf("(%s) %s but flags 0x%08X are not granted! granted[0x%08X] desired[0x%08X]\n", \
- __location__, nt_errstr(status), access, granted, desired); \
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) {\
- printf("(%s) %s but flags 0x%08X are granted! granted[0x%08X] desired[0x%08X]\n", \
- __location__, nt_errstr(status), access, granted, desired); \
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 */
+/* test what access mask is needed for getting and setting security_descriptors
+ Test copied to smb2/acls.c for SMB2. */
static bool test_sd_get_set(struct torture_context *tctx,
struct smbcli_state *cli)
{
@@ -1863,7 +2264,10 @@ static bool test_sd_get_set(struct torture_context *tctx,
uint64_t get_sacl_bits = SEC_FLAG_SYSTEM_SECURITY;
uint64_t set_sacl_bits = SEC_FLAG_SYSTEM_SECURITY;
- printf("TESTING ACCESS MASKS FOR SD GET/SET\n");
+ if (!torture_setup_dir(cli, 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,
@@ -2006,6 +2410,8 @@ next:
done:
smbcli_close(cli->tree, fnum);
smbcli_unlink(cli->tree, fname);
+ smb_raw_exit(cli->session);
+ smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
@@ -2014,26 +2420,23 @@ done:
/*
basic testing of security descriptor calls
*/
-bool torture_raw_acls(struct torture_context *tctx, struct smbcli_state *cli)
+struct torture_suite *torture_raw_acls(TALLOC_CTX *mem_ctx)
{
- bool ret = true;
-
- if (!torture_setup_dir(cli, BASEDIR)) {
- return false;
- }
-
- ret &= test_sd(tctx, cli);
- ret &= test_nttrans_create(tctx, cli);
- ret &= test_nttrans_create_null_dacl(tctx, cli);
- ret &= test_creator_sid(tctx, cli);
- ret &= test_generic_bits(tctx, cli);
- ret &= test_owner_bits(tctx, cli);
- ret &= test_inheritance(tctx, cli);
- ret &= test_inheritance_dynamic(tctx, cli);
- ret &= test_sd_get_set(tctx, cli);
-
- smb_raw_exit(cli->session);
- smbcli_deltree(cli->tree, BASEDIR);
-
- return ret;
+ struct torture_suite *suite = torture_suite_create(mem_ctx, "ACLS");
+
+ torture_suite_add_1smb_test(suite, "SD", test_sd);
+ torture_suite_add_1smb_test(suite, "CREATE_FILE", test_nttrans_create_file);
+ torture_suite_add_1smb_test(suite, "CREATE_DIR", test_nttrans_create_dir);
+ torture_suite_add_1smb_test(suite, "NULLDACL", test_nttrans_create_null_dacl);
+ torture_suite_add_1smb_test(suite, "CREATOR", test_creator_sid);
+ torture_suite_add_1smb_test(suite, "GENERIC", test_generic_bits);
+ torture_suite_add_1smb_test(suite, "OWNER", test_owner_bits);
+ torture_suite_add_1smb_test(suite, "INHERITANCE", test_inheritance);
+ torture_suite_add_1smb_test(suite, "INHERITFLAGS", test_inheritance_flags);
+ torture_suite_add_1smb_test(suite, "DYNAMIC", test_inheritance_dynamic);
+ /* XXX This test does not work against XP or Vista.
+ torture_suite_add_1smb_test(suite, "GETSET", test_sd_get_set);
+ */
+
+ return suite;
}
diff --git a/source4/torture/raw/raw.c b/source4/torture/raw/raw.c
index c47ad92cc9..2aa3d0d3ef 100644
--- a/source4/torture/raw/raw.c
+++ b/source4/torture/raw/raw.c
@@ -61,7 +61,7 @@ NTSTATUS torture_raw_init(void)
torture_suite_add_1smb_test(suite, "SEEK", torture_raw_seek);
torture_suite_add_1smb_test(suite, "EAS", torture_raw_eas);
torture_suite_add_suite(suite, torture_raw_streams(suite));
- torture_suite_add_1smb_test(suite, "ACLS", torture_raw_acls);
+ torture_suite_add_suite(suite, torture_raw_acls(suite));
torture_suite_add_1smb_test(suite, "COMPOSITE", torture_raw_composite);
torture_suite_add_simple_test(suite, "SAMBA3HIDE", torture_samba3_hide);
torture_suite_add_simple_test(suite, "SAMBA3CLOSEERR", torture_samba3_closeerr);