| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
|
| 4 |
Copyright (C) Ralph Boehme 2016 |
| 5 |
|
| 6 |
This program is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 3 of the License, or |
| 9 |
(at your option) any later version. |
| 10 |
|
| 11 |
This program is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "includes.h" |
| 21 |
#include "lib/cmdline/cmdline.h" |
| 22 |
#include "libcli/smb2/smb2.h" |
| 23 |
#include "libcli/smb2/smb2_calls.h" |
| 24 |
#include "libcli/smb/smbXcli_base.h" |
| 25 |
#include "torture/torture.h" |
| 26 |
#include "torture/vfs/proto.h" |
| 27 |
#include "libcli/resolve/resolve.h" |
| 28 |
#include "torture/util.h" |
| 29 |
#include "torture/smb2/proto.h" |
| 30 |
#include "libcli/security/security.h" |
| 31 |
#include "librpc/gen_ndr/ndr_security.h" |
| 32 |
#include "lib/param/param.h" |
| 33 |
|
| 34 |
#define BASEDIR "smb2-testsd" |
| 35 |
|
| 36 |
#define CHECK_SECURITY_DESCRIPTOR(_sd1, _sd2) do { \ |
| 37 |
if (!security_descriptor_equal(_sd1, _sd2)) { \ |
| 38 |
torture_warning(tctx, "security descriptors don't match!\n"); \ |
| 39 |
torture_warning(tctx, "got:\n"); \ |
| 40 |
NDR_PRINT_DEBUG(security_descriptor, _sd1); \ |
| 41 |
torture_warning(tctx, "expected:\n"); \ |
| 42 |
NDR_PRINT_DEBUG(security_descriptor, _sd2); \ |
| 43 |
torture_result(tctx, TORTURE_FAIL, \ |
| 44 |
"%s: security descriptors don't match!\n", \ |
| 45 |
__location__); \ |
| 46 |
ret = false; \ |
| 47 |
} \ |
| 48 |
} while (0) |
| 49 |
|
| 50 |
static bool test_default_acl_posix(struct torture_context *tctx, |
| 51 |
struct smb2_tree *tree_unused) |
| 52 |
{ |
| 53 |
struct smb2_tree *tree = NULL; |
| 54 |
NTSTATUS status; |
| 55 |
bool ok; |
| 56 |
bool ret = true; |
| 57 |
const char *dname = BASEDIR "\\testdir"; |
| 58 |
const char *fname = BASEDIR "\\testdir\\testfile"; |
| 59 |
struct smb2_handle fhandle = {{0}}; |
| 60 |
struct smb2_handle dhandle = {{0}}; |
| 61 |
union smb_fileinfo q; |
| 62 |
union smb_setfileinfo set; |
| 63 |
struct security_descriptor *sd = NULL; |
| 64 |
struct security_descriptor *exp_sd = NULL; |
| 65 |
char *owner_sid = NULL; |
| 66 |
char *group_sid = NULL; |
| 67 |
|
| 68 |
ok = torture_smb2_con_share(tctx, "acl_xattr_ign_sysacl_posix", &tree); |
| 69 |
torture_assert_goto(tctx, ok == true, ret, done, |
| 70 |
"Unable to connect to 'acl_xattr_ign_sysacl_posix'\n"); |
| 71 |
|
| 72 |
ok = smb2_util_setup_dir(tctx, tree, BASEDIR); |
| 73 |
torture_assert_goto(tctx, ok == true, ret, done, "Unable to setup testdir\n"); |
| 74 |
|
| 75 |
ZERO_STRUCT(dhandle); |
| 76 |
status = torture_smb2_testdir(tree, dname, &dhandle); |
| 77 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "torture_smb2_testdir\n"); |
| 78 |
|
| 79 |
torture_comment(tctx, "Get the original sd\n"); |
| 80 |
|
| 81 |
ZERO_STRUCT(q); |
| 82 |
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC; |
| 83 |
q.query_secdesc.in.file.handle = dhandle; |
| 84 |
q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER | SECINFO_GROUP; |
| 85 |
status = smb2_getinfo_file(tree, tctx, &q); |
| 86 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_getinfo_file\n"); |
| 87 |
|
| 88 |
sd = q.query_secdesc.out.sd; |
| 89 |
owner_sid = dom_sid_string(tctx, sd->owner_sid); |
| 90 |
group_sid = dom_sid_string(tctx, sd->group_sid); |
| 91 |
torture_comment(tctx, "owner [%s] group [%s]\n", owner_sid, group_sid); |
| 92 |
|
| 93 |
torture_comment(tctx, "Set ACL with no inheritable ACE\n"); |
| 94 |
|
| 95 |
sd = security_descriptor_dacl_create(tctx, |
| 96 |
0, NULL, NULL, |
| 97 |
owner_sid, |
| 98 |
SEC_ACE_TYPE_ACCESS_ALLOWED, |
| 99 |
SEC_RIGHTS_DIR_ALL, |
| 100 |
0, |
| 101 |
NULL); |
| 102 |
|
| 103 |
ZERO_STRUCT(set); |
| 104 |
set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC; |
| 105 |
set.set_secdesc.in.file.handle = dhandle; |
| 106 |
set.set_secdesc.in.secinfo_flags = SECINFO_DACL; |
| 107 |
set.set_secdesc.in.sd = sd; |
| 108 |
status = smb2_setinfo_file(tree, &set); |
| 109 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_setinfo_file\n"); |
| 110 |
|
| 111 |
TALLOC_FREE(sd); |
| 112 |
smb2_util_close(tree, dhandle); |
| 113 |
|
| 114 |
torture_comment(tctx, "Create file\n"); |
| 115 |
|
| 116 |
ZERO_STRUCT(fhandle); |
| 117 |
status = torture_smb2_testfile(tree, fname, &fhandle); |
| 118 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_create_complex_file\n"); |
| 119 |
|
| 120 |
torture_comment(tctx, "Query file SD\n"); |
| 121 |
|
| 122 |
ZERO_STRUCT(q); |
| 123 |
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC; |
| 124 |
q.query_secdesc.in.file.handle = fhandle; |
| 125 |
q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER | SECINFO_GROUP; |
| 126 |
status = smb2_getinfo_file(tree, tctx, &q); |
| 127 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_getinfo_file\n"); |
| 128 |
sd = q.query_secdesc.out.sd; |
| 129 |
|
| 130 |
smb2_util_close(tree, fhandle); |
| 131 |
ZERO_STRUCT(fhandle); |
| 132 |
|
| 133 |
torture_comment(tctx, "Checking actual file SD against expected SD\n"); |
| 134 |
|
| 135 |
exp_sd = security_descriptor_dacl_create( |
| 136 |
tctx, 0, owner_sid, group_sid, |
| 137 |
owner_sid, SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_RIGHTS_FILE_ALL, 0, |
| 138 |
group_sid, SEC_ACE_TYPE_ACCESS_ALLOWED, FILE_GENERIC_READ|FILE_GENERIC_WRITE|FILE_GENERIC_EXECUTE, 0, |
| 139 |
SID_WORLD, SEC_ACE_TYPE_ACCESS_ALLOWED, FILE_GENERIC_READ|FILE_GENERIC_WRITE|FILE_GENERIC_EXECUTE, 0, |
| 140 |
SID_NT_SYSTEM, SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_RIGHTS_FILE_ALL, 0, |
| 141 |
NULL); |
| 142 |
|
| 143 |
CHECK_SECURITY_DESCRIPTOR(sd, exp_sd); |
| 144 |
|
| 145 |
done: |
| 146 |
if (!smb2_util_handle_empty(fhandle)) { |
| 147 |
smb2_util_close(tree, fhandle); |
| 148 |
} |
| 149 |
if (!smb2_util_handle_empty(dhandle)) { |
| 150 |
smb2_util_close(tree, dhandle); |
| 151 |
} |
| 152 |
if (tree != NULL) { |
| 153 |
smb2_deltree(tree, BASEDIR); |
| 154 |
smb2_tdis(tree); |
| 155 |
} |
| 156 |
|
| 157 |
return ret; |
| 158 |
} |
| 159 |
|
| 160 |
static bool test_default_acl_win(struct torture_context *tctx, |
| 161 |
struct smb2_tree *tree_unused) |
| 162 |
{ |
| 163 |
struct smb2_tree *tree = NULL; |
| 164 |
NTSTATUS status; |
| 165 |
bool ok; |
| 166 |
bool ret = true; |
| 167 |
const char *dname = BASEDIR "\\testdir"; |
| 168 |
const char *fname = BASEDIR "\\testdir\\testfile"; |
| 169 |
struct smb2_handle fhandle = {{0}}; |
| 170 |
struct smb2_handle dhandle = {{0}}; |
| 171 |
union smb_fileinfo q; |
| 172 |
union smb_setfileinfo set; |
| 173 |
struct security_descriptor *sd = NULL; |
| 174 |
struct security_descriptor *exp_sd = NULL; |
| 175 |
char *owner_sid = NULL; |
| 176 |
char *group_sid = NULL; |
| 177 |
|
| 178 |
ok = torture_smb2_con_share(tctx, "acl_xattr_ign_sysacl_windows", &tree); |
| 179 |
torture_assert_goto(tctx, ok == true, ret, done, |
| 180 |
"Unable to connect to 'acl_xattr_ign_sysacl_windows'\n"); |
| 181 |
|
| 182 |
ok = smb2_util_setup_dir(tctx, tree, BASEDIR); |
| 183 |
torture_assert_goto(tctx, ok == true, ret, done, "Unable to setup testdir\n"); |
| 184 |
|
| 185 |
ZERO_STRUCT(dhandle); |
| 186 |
status = torture_smb2_testdir(tree, dname, &dhandle); |
| 187 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "torture_smb2_testdir\n"); |
| 188 |
|
| 189 |
torture_comment(tctx, "Get the original sd\n"); |
| 190 |
|
| 191 |
ZERO_STRUCT(q); |
| 192 |
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC; |
| 193 |
q.query_secdesc.in.file.handle = dhandle; |
| 194 |
q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER | SECINFO_GROUP; |
| 195 |
status = smb2_getinfo_file(tree, tctx, &q); |
| 196 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_getinfo_file\n"); |
| 197 |
|
| 198 |
sd = q.query_secdesc.out.sd; |
| 199 |
owner_sid = dom_sid_string(tctx, sd->owner_sid); |
| 200 |
group_sid = dom_sid_string(tctx, sd->group_sid); |
| 201 |
torture_comment(tctx, "owner [%s] group [%s]\n", owner_sid, group_sid); |
| 202 |
|
| 203 |
torture_comment(tctx, "Set ACL with no inheritable ACE\n"); |
| 204 |
|
| 205 |
sd = security_descriptor_dacl_create(tctx, |
| 206 |
0, NULL, NULL, |
| 207 |
owner_sid, |
| 208 |
SEC_ACE_TYPE_ACCESS_ALLOWED, |
| 209 |
SEC_RIGHTS_DIR_ALL, |
| 210 |
0, |
| 211 |
NULL); |
| 212 |
|
| 213 |
ZERO_STRUCT(set); |
| 214 |
set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC; |
| 215 |
set.set_secdesc.in.file.handle = dhandle; |
| 216 |
set.set_secdesc.in.secinfo_flags = SECINFO_DACL; |
| 217 |
set.set_secdesc.in.sd = sd; |
| 218 |
status = smb2_setinfo_file(tree, &set); |
| 219 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_setinfo_file\n"); |
| 220 |
|
| 221 |
TALLOC_FREE(sd); |
| 222 |
smb2_util_close(tree, dhandle); |
| 223 |
|
| 224 |
torture_comment(tctx, "Create file\n"); |
| 225 |
|
| 226 |
ZERO_STRUCT(fhandle); |
| 227 |
status = torture_smb2_testfile(tree, fname, &fhandle); |
| 228 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_create_complex_file\n"); |
| 229 |
|
| 230 |
torture_comment(tctx, "Query file SD\n"); |
| 231 |
|
| 232 |
ZERO_STRUCT(q); |
| 233 |
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC; |
| 234 |
q.query_secdesc.in.file.handle = fhandle; |
| 235 |
q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER | SECINFO_GROUP; |
| 236 |
status = smb2_getinfo_file(tree, tctx, &q); |
| 237 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_getinfo_file\n"); |
| 238 |
sd = q.query_secdesc.out.sd; |
| 239 |
|
| 240 |
smb2_util_close(tree, fhandle); |
| 241 |
ZERO_STRUCT(fhandle); |
| 242 |
|
| 243 |
torture_comment(tctx, "Checking actual file SD against expected SD\n"); |
| 244 |
|
| 245 |
exp_sd = security_descriptor_dacl_create( |
| 246 |
tctx, 0, owner_sid, group_sid, |
| 247 |
owner_sid, SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_RIGHTS_FILE_ALL, 0, |
| 248 |
SID_NT_SYSTEM, SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_RIGHTS_FILE_ALL, 0, |
| 249 |
NULL); |
| 250 |
|
| 251 |
CHECK_SECURITY_DESCRIPTOR(sd, exp_sd); |
| 252 |
|
| 253 |
done: |
| 254 |
if (!smb2_util_handle_empty(fhandle)) { |
| 255 |
smb2_util_close(tree, fhandle); |
| 256 |
} |
| 257 |
if (!smb2_util_handle_empty(dhandle)) { |
| 258 |
smb2_util_close(tree, dhandle); |
| 259 |
} |
| 260 |
if (tree != NULL) { |
| 261 |
smb2_deltree(tree, BASEDIR); |
| 262 |
smb2_tdis(tree); |
| 263 |
} |
| 264 |
|
| 265 |
return ret; |
| 266 |
} |
| 267 |
|
| 268 |
/* |
| 269 |
basic testing of vfs_acl_xattr |
| 270 |
*/ |
| 271 |
struct torture_suite *torture_acl_xattr(TALLOC_CTX *ctx) |
| 272 |
{ |
| 273 |
struct torture_suite *suite = torture_suite_create(ctx, "acl_xattr"); |
| 274 |
|
| 275 |
torture_suite_add_1smb2_test(suite, "default-acl-style-posix", test_default_acl_posix); |
| 276 |
torture_suite_add_1smb2_test(suite, "default-acl-style-windows", test_default_acl_win); |
| 277 |
|
| 278 |
suite->description = talloc_strdup(suite, "vfs_acl_xattr tests"); |
| 279 |
|
| 280 |
return suite; |
| 281 |
} |