| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
|
| 4 |
openattr tester |
| 5 |
|
| 6 |
Copyright (C) Andrew Tridgell 2003 |
| 7 |
|
| 8 |
This program is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3 of the License, or |
| 11 |
(at your option) any later version. |
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
GNU General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "includes.h" |
| 23 |
#include "libcli/libcli.h" |
| 24 |
#include "torture/util.h" |
| 25 |
#include "system/filesys.h" |
| 26 |
#include "libcli/security/security_descriptor.h" |
| 27 |
#include "torture/basic/proto.h" |
| 28 |
|
| 29 |
extern int torture_failures; |
| 30 |
|
| 31 |
#define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0) |
| 32 |
|
| 33 |
|
| 34 |
static const uint32_t open_attrs_table[] = { |
| 35 |
FILE_ATTRIBUTE_NORMAL, |
| 36 |
FILE_ATTRIBUTE_ARCHIVE, |
| 37 |
FILE_ATTRIBUTE_READONLY, |
| 38 |
FILE_ATTRIBUTE_HIDDEN, |
| 39 |
FILE_ATTRIBUTE_SYSTEM, |
| 40 |
|
| 41 |
FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, |
| 42 |
FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, |
| 43 |
FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, |
| 44 |
FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, |
| 45 |
FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, |
| 46 |
FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM, |
| 47 |
|
| 48 |
FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, |
| 49 |
FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, |
| 50 |
FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM, |
| 51 |
FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM, |
| 52 |
}; |
| 53 |
|
| 54 |
struct trunc_open_results { |
| 55 |
unsigned int num; |
| 56 |
uint32_t init_attr; |
| 57 |
uint32_t trunc_attr; |
| 58 |
uint32_t result_attr; |
| 59 |
}; |
| 60 |
|
| 61 |
static const struct trunc_open_results attr_results[] = { |
| 62 |
{ 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE }, |
| 63 |
{ 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE }, |
| 64 |
{ 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY }, |
| 65 |
{ 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE }, |
| 66 |
{ 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE }, |
| 67 |
{ 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY }, |
| 68 |
{ 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN }, |
| 69 |
{ 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN }, |
| 70 |
{ 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN }, |
| 71 |
{ 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM }, |
| 72 |
{ 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM }, |
| 73 |
{ 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }, |
| 74 |
{ 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN }, |
| 75 |
{ 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN }, |
| 76 |
{ 104, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN }, |
| 77 |
{ 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM }, |
| 78 |
{ 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM }, |
| 79 |
{ 121, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }, |
| 80 |
{ 170, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN }, |
| 81 |
{ 173, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM }, |
| 82 |
{ 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN }, |
| 83 |
{ 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN }, |
| 84 |
{ 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN }, |
| 85 |
{ 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM }, |
| 86 |
{ 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM }, |
| 87 |
{ 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM } |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 91 |
bool torture_openattrtest(struct torture_context *tctx, |
| 92 |
struct smbcli_state *cli1) |
| 93 |
{ |
| 94 |
const char *fname = "\\openattr.file"; |
| 95 |
int fnum1; |
| 96 |
uint16_t attr; |
| 97 |
unsigned int i, j, k, l; |
| 98 |
int failures = 0; |
| 99 |
|
| 100 |
for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32_t); i++) { |
| 101 |
smbcli_setatr(cli1->tree, fname, 0, 0); |
| 102 |
smbcli_unlink(cli1->tree, fname); |
| 103 |
fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, |
| 104 |
SEC_FILE_WRITE_DATA, |
| 105 |
open_attrs_table[i], |
| 106 |
NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); |
| 107 |
|
| 108 |
torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open %d (1) of %s failed (%s)", i, |
| 109 |
fname, smbcli_errstr(cli1->tree))); |
| 110 |
|
| 111 |
torture_assert_ntstatus_ok(tctx, |
| 112 |
smbcli_close(cli1->tree, fnum1), |
| 113 |
talloc_asprintf(tctx, "close %d (1) of %s failed (%s)", i, fname, |
| 114 |
smbcli_errstr(cli1->tree))); |
| 115 |
|
| 116 |
for (j = 0; j < ARRAY_SIZE(open_attrs_table); j++) { |
| 117 |
fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, |
| 118 |
SEC_FILE_READ_DATA| |
| 119 |
SEC_FILE_WRITE_DATA, |
| 120 |
open_attrs_table[j], |
| 121 |
NTCREATEX_SHARE_ACCESS_NONE, |
| 122 |
NTCREATEX_DISP_OVERWRITE, 0, 0); |
| 123 |
|
| 124 |
if (fnum1 == -1) { |
| 125 |
for (l = 0; l < ARRAY_SIZE(attr_results); l++) { |
| 126 |
if (attr_results[l].num == k) { |
| 127 |
torture_result(tctx, TORTURE_FAIL, |
| 128 |
"[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(%s)", |
| 129 |
k, open_attrs_table[i], |
| 130 |
open_attrs_table[j], |
| 131 |
fname, smbcli_errstr(cli1->tree)); |
| 132 |
CHECK_MAX_FAILURES(error_exit); |
| 133 |
} |
| 134 |
} |
| 135 |
if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_ACCESS_DENIED)) { |
| 136 |
torture_result(tctx, TORTURE_FAIL, |
| 137 |
"[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s", |
| 138 |
k, open_attrs_table[i], open_attrs_table[j], |
| 139 |
smbcli_errstr(cli1->tree)); |
| 140 |
CHECK_MAX_FAILURES(error_exit); |
| 141 |
} |
| 142 |
#if 0 |
| 143 |
torture_comment(tctx, "[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]); |
| 144 |
#endif |
| 145 |
k++; |
| 146 |
continue; |
| 147 |
} |
| 148 |
|
| 149 |
torture_assert_ntstatus_ok(tctx, |
| 150 |
smbcli_close(cli1->tree, fnum1), |
| 151 |
talloc_asprintf(tctx, "close %d (2) of %s failed (%s)", j, |
| 152 |
fname, smbcli_errstr(cli1->tree))); |
| 153 |
|
| 154 |
torture_assert_ntstatus_ok(tctx, |
| 155 |
smbcli_getatr(cli1->tree, fname, &attr, NULL, NULL), |
| 156 |
talloc_asprintf(tctx, "getatr(2) failed (%s)", smbcli_errstr(cli1->tree))); |
| 157 |
|
| 158 |
#if 0 |
| 159 |
torture_comment(tctx, "[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n", |
| 160 |
k, open_attrs_table[i], open_attrs_table[j], attr ); |
| 161 |
#endif |
| 162 |
|
| 163 |
for (l = 0; l < ARRAY_SIZE(attr_results); l++) { |
| 164 |
if (attr_results[l].num == k) { |
| 165 |
if (attr != attr_results[l].result_attr || |
| 166 |
open_attrs_table[i] != attr_results[l].init_attr || |
| 167 |
open_attrs_table[j] != attr_results[l].trunc_attr) { |
| 168 |
torture_result(tctx, TORTURE_FAIL, |
| 169 |
"[%d] getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x", |
| 170 |
k, open_attrs_table[i], |
| 171 |
open_attrs_table[j], |
| 172 |
(unsigned int)attr, |
| 173 |
attr_results[l].result_attr); |
| 174 |
CHECK_MAX_FAILURES(error_exit); |
| 175 |
} |
| 176 |
break; |
| 177 |
} |
| 178 |
} |
| 179 |
k++; |
| 180 |
} |
| 181 |
} |
| 182 |
error_exit: |
| 183 |
smbcli_setatr(cli1->tree, fname, 0, 0); |
| 184 |
smbcli_unlink(cli1->tree, fname); |
| 185 |
|
| 186 |
if (failures) { |
| 187 |
return false; |
| 188 |
} |
| 189 |
return true; |
| 190 |
} |
| 191 |
|
| 192 |
bool torture_winattrtest(struct torture_context *tctx, |
| 193 |
struct smbcli_state *cli1) |
| 194 |
{ |
| 195 |
const char *fname = "\\winattr1.file"; |
| 196 |
const char *dname = "\\winattr1.dir"; |
| 197 |
int fnum1; |
| 198 |
uint16_t attr; |
| 199 |
uint16_t j; |
| 200 |
uint32_t aceno; |
| 201 |
int failures = 0; |
| 202 |
union smb_fileinfo query, query_org; |
| 203 |
NTSTATUS status; |
| 204 |
struct security_descriptor *sd1, *sd2; |
| 205 |
ZERO_STRUCT(query); |
| 206 |
ZERO_STRUCT(query_org); |
| 207 |
|
| 208 |
/* Test winattrs for file */ |
| 209 |
smbcli_unlink(cli1->tree, fname); |
| 210 |
|
| 211 |
/* Open a file*/ |
| 212 |
fnum1 = smbcli_open(cli1->tree, fname, O_RDWR | O_CREAT | O_TRUNC, |
| 213 |
DENY_NONE); |
| 214 |
torture_assert(tctx, fnum1 != -1, |
| 215 |
talloc_asprintf(tctx, "open(1) of %s failed (%s)\n", |
| 216 |
fname, smbcli_errstr(cli1->tree))); |
| 217 |
|
| 218 |
|
| 219 |
/* Get security descriptor and store it*/ |
| 220 |
query_org.generic.level = RAW_FILEINFO_SEC_DESC; |
| 221 |
query_org.generic.in.file.fnum = fnum1; |
| 222 |
status = smb_raw_fileinfo(cli1->tree, tctx, &query_org); |
| 223 |
if(!NT_STATUS_IS_OK(status)){ |
| 224 |
torture_comment(tctx, "smb_raw_fileinfo(1) of %s failed (%s)\n", |
| 225 |
fname, nt_errstr(status)); |
| 226 |
torture_assert_ntstatus_ok(tctx, |
| 227 |
smbcli_close(cli1->tree, fnum1), |
| 228 |
talloc_asprintf(tctx, |
| 229 |
"close(1) of %s failed (%s)\n", |
| 230 |
fname, smbcli_errstr(cli1->tree))); |
| 231 |
CHECK_MAX_FAILURES(error_exit_file); |
| 232 |
} |
| 233 |
sd1 = query_org.query_secdesc.out.sd; |
| 234 |
|
| 235 |
torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), |
| 236 |
talloc_asprintf(tctx, "close(1) of %s failed (%s)\n", |
| 237 |
fname, smbcli_errstr(cli1->tree))); |
| 238 |
|
| 239 |
/*Set and get attributes*/ |
| 240 |
for (j = 0; j < ARRAY_SIZE(open_attrs_table); j++) { |
| 241 |
torture_assert_ntstatus_ok(tctx, |
| 242 |
smbcli_setatr(cli1->tree, fname, open_attrs_table[j],0), |
| 243 |
talloc_asprintf(tctx, "setatr(2) failed (%s)", |
| 244 |
smbcli_errstr(cli1->tree))); |
| 245 |
|
| 246 |
torture_assert_ntstatus_ok(tctx, |
| 247 |
smbcli_getatr(cli1->tree, fname, &attr, NULL, NULL), |
| 248 |
talloc_asprintf(tctx, "getatr(2) failed (%s)", |
| 249 |
smbcli_errstr(cli1->tree))); |
| 250 |
|
| 251 |
/* Check the result */ |
| 252 |
if((j == 0)&&(attr != FILE_ATTRIBUTE_ARCHIVE)){ |
| 253 |
torture_comment(tctx, "getatr check failed. \ |
| 254 |
Attr applied [0x%x], got attr [0x%x], \ |
| 255 |
should be [0x%x]", |
| 256 |
open_attrs_table[j], |
| 257 |
(uint16_t)attr,open_attrs_table[j +1]); |
| 258 |
CHECK_MAX_FAILURES(error_exit_file); |
| 259 |
}else{ |
| 260 |
|
| 261 |
if((j != 0) &&(attr != open_attrs_table[j])){ |
| 262 |
torture_comment(tctx, "getatr check failed. \ |
| 263 |
Attr applied [0x%x],got attr 0x%x, \ |
| 264 |
should be 0x%x ", |
| 265 |
open_attrs_table[j], (uint16_t)attr, |
| 266 |
open_attrs_table[j]); |
| 267 |
CHECK_MAX_FAILURES(error_exit_file); |
| 268 |
} |
| 269 |
|
| 270 |
} |
| 271 |
|
| 272 |
fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY | O_CREAT, |
| 273 |
DENY_NONE); |
| 274 |
torture_assert(tctx, fnum1 != -1, |
| 275 |
talloc_asprintf(tctx, "open(2) of %s failed (%s)\n", |
| 276 |
fname, smbcli_errstr(cli1->tree))); |
| 277 |
/*Get security descriptor */ |
| 278 |
query.query_secdesc.level = RAW_FILEINFO_SEC_DESC; |
| 279 |
query.query_secdesc.in.file.fnum = fnum1; |
| 280 |
status = smb_raw_fileinfo(cli1->tree, tctx, &query); |
| 281 |
if(!NT_STATUS_IS_OK(status)){ |
| 282 |
torture_comment(tctx, |
| 283 |
"smb_raw_fileinfo(2) of %s failed (%s)\n", |
| 284 |
fname, nt_errstr(status)); |
| 285 |
torture_assert_ntstatus_ok(tctx, |
| 286 |
smbcli_close(cli1->tree, fnum1), |
| 287 |
talloc_asprintf(tctx, |
| 288 |
"close(2) of %s failed (%s)\n", |
| 289 |
fname, smbcli_errstr(cli1->tree))); |
| 290 |
CHECK_MAX_FAILURES(error_exit_file); |
| 291 |
} |
| 292 |
sd2 = query.query_secdesc.out.sd; |
| 293 |
|
| 294 |
torture_assert_ntstatus_ok(tctx,smbcli_close(cli1->tree,fnum1), |
| 295 |
talloc_asprintf(tctx, "close(2) of %s failed (%s)\n", |
| 296 |
fname, smbcli_errstr(cli1->tree))); |
| 297 |
|
| 298 |
/*Compare security descriptors -- Must be same*/ |
| 299 |
for (aceno=0;(sd1->dacl&&aceno < sd1->dacl->num_aces);aceno++){ |
| 300 |
struct security_ace *ace1 = &sd1->dacl->aces[aceno]; |
| 301 |
struct security_ace *ace2 = &sd2->dacl->aces[aceno]; |
| 302 |
|
| 303 |
if (!security_ace_equal(ace1, ace2)) { |
| 304 |
torture_comment(tctx, |
| 305 |
"ACLs changed! Not expected!\n"); |
| 306 |
CHECK_MAX_FAILURES(error_exit_file); |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
torture_comment(tctx, "[%d] setattr = [0x%x] got attr 0x%x\n", |
| 311 |
j, open_attrs_table[j], attr ); |
| 312 |
|
| 313 |
} |
| 314 |
|
| 315 |
error_exit_file: |
| 316 |
smbcli_setatr(cli1->tree, fname, 0, 0); |
| 317 |
smbcli_unlink(cli1->tree, fname); |
| 318 |
|
| 319 |
/* Check for Directory. */ |
| 320 |
|
| 321 |
smbcli_deltree(cli1->tree, dname); |
| 322 |
smbcli_rmdir(cli1->tree,dname); |
| 323 |
|
| 324 |
/* Open a directory */ |
| 325 |
fnum1 = smbcli_nt_create_full(cli1->tree, dname, 0, |
| 326 |
SEC_RIGHTS_DIR_ALL, |
| 327 |
FILE_ATTRIBUTE_DIRECTORY, |
| 328 |
NTCREATEX_SHARE_ACCESS_NONE, |
| 329 |
NTCREATEX_DISP_OPEN_IF, |
| 330 |
NTCREATEX_OPTIONS_DIRECTORY, 0); |
| 331 |
/*smbcli_mkdir(cli1->tree,dname);*/ |
| 332 |
|
| 333 |
torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, |
| 334 |
"open (1) of %s failed (%s)", |
| 335 |
dname, smbcli_errstr(cli1->tree))); |
| 336 |
|
| 337 |
|
| 338 |
/* Get Security Descriptor */ |
| 339 |
query_org.generic.level = RAW_FILEINFO_SEC_DESC; |
| 340 |
query_org.generic.in.file.fnum = fnum1; |
| 341 |
status = smb_raw_fileinfo(cli1->tree, tctx, &query_org); |
| 342 |
if(!NT_STATUS_IS_OK(status)){ |
| 343 |
torture_comment(tctx, "smb_raw_fileinfo(1) of %s failed (%s)\n", |
| 344 |
dname, nt_errstr(status)); |
| 345 |
torture_assert_ntstatus_ok(tctx, |
| 346 |
smbcli_close(cli1->tree, fnum1), |
| 347 |
talloc_asprintf(tctx, |
| 348 |
"close(1) of %s failed (%s)\n", |
| 349 |
dname, smbcli_errstr(cli1->tree))); |
| 350 |
CHECK_MAX_FAILURES(error_exit_dir); |
| 351 |
} |
| 352 |
sd1 = query_org.query_secdesc.out.sd; |
| 353 |
|
| 354 |
torture_assert_ntstatus_ok(tctx, |
| 355 |
smbcli_close(cli1->tree, fnum1), |
| 356 |
talloc_asprintf(tctx, |
| 357 |
"close (1) of %s failed (%s)", dname, |
| 358 |
smbcli_errstr(cli1->tree))); |
| 359 |
|
| 360 |
/* Set and get win attributes*/ |
| 361 |
for (j = 1; j < ARRAY_SIZE(open_attrs_table); j++) { |
| 362 |
|
| 363 |
torture_assert_ntstatus_ok(tctx, |
| 364 |
smbcli_setatr(cli1->tree, dname, open_attrs_table[j], 0), |
| 365 |
talloc_asprintf(tctx, "setatr(2) failed (%s)", |
| 366 |
smbcli_errstr(cli1->tree))); |
| 367 |
|
| 368 |
torture_assert_ntstatus_ok(tctx, |
| 369 |
smbcli_getatr(cli1->tree, dname, &attr, NULL, NULL), |
| 370 |
talloc_asprintf(tctx, "getatr(2) failed (%s)", |
| 371 |
smbcli_errstr(cli1->tree))); |
| 372 |
|
| 373 |
torture_comment(tctx, "[%d] setatt = [0x%x] got attr 0x%x\n", |
| 374 |
j, open_attrs_table[j], attr ); |
| 375 |
|
| 376 |
/* Check the result */ |
| 377 |
if(attr != (open_attrs_table[j]|FILE_ATTRIBUTE_DIRECTORY)){ |
| 378 |
torture_comment(tctx, "getatr check failed. set attr \ |
| 379 |
[0x%x], got attr 0x%x, should be 0x%x\n", |
| 380 |
open_attrs_table[j], |
| 381 |
(uint16_t)attr, |
| 382 |
(unsigned int)(open_attrs_table[j]|FILE_ATTRIBUTE_DIRECTORY)); |
| 383 |
CHECK_MAX_FAILURES(error_exit_dir); |
| 384 |
} |
| 385 |
|
| 386 |
fnum1 = smbcli_nt_create_full(cli1->tree, dname, 0, |
| 387 |
SEC_RIGHTS_DIR_READ, |
| 388 |
FILE_ATTRIBUTE_DIRECTORY, |
| 389 |
NTCREATEX_SHARE_ACCESS_NONE, |
| 390 |
NTCREATEX_DISP_OPEN, |
| 391 |
0,0); |
| 392 |
|
| 393 |
torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, |
| 394 |
"open (2) of %s failed (%s)", |
| 395 |
dname, smbcli_errstr(cli1->tree))); |
| 396 |
/* Get security descriptor */ |
| 397 |
query.generic.level = RAW_FILEINFO_SEC_DESC; |
| 398 |
query.generic.in.file.fnum = fnum1; |
| 399 |
status = smb_raw_fileinfo(cli1->tree, tctx, &query); |
| 400 |
if(!NT_STATUS_IS_OK(status)){ |
| 401 |
torture_comment(tctx, "smb_raw_fileinfo(2) of %s failed\ |
| 402 |
(%s)\n", dname, nt_errstr(status)); |
| 403 |
torture_assert_ntstatus_ok(tctx, |
| 404 |
smbcli_close(cli1->tree, fnum1), |
| 405 |
talloc_asprintf(tctx, |
| 406 |
"close (2) of %s failed (%s)", dname, |
| 407 |
smbcli_errstr(cli1->tree))); |
| 408 |
CHECK_MAX_FAILURES(error_exit_dir); |
| 409 |
} |
| 410 |
sd2 = query.query_secdesc.out.sd; |
| 411 |
torture_assert_ntstatus_ok(tctx, |
| 412 |
smbcli_close(cli1->tree, fnum1), |
| 413 |
talloc_asprintf(tctx, |
| 414 |
"close (2) of %s failed (%s)", dname, |
| 415 |
smbcli_errstr(cli1->tree))); |
| 416 |
|
| 417 |
/* Security descriptor must be same*/ |
| 418 |
for (aceno=0;(sd1->dacl&&aceno < sd1->dacl->num_aces);aceno++){ |
| 419 |
struct security_ace *ace1 = &sd1->dacl->aces[aceno]; |
| 420 |
struct security_ace *ace2 = &sd2->dacl->aces[aceno]; |
| 421 |
|
| 422 |
if (!security_ace_equal(ace1, ace2)) { |
| 423 |
torture_comment(tctx, |
| 424 |
"ACLs changed! Not expected!\n"); |
| 425 |
CHECK_MAX_FAILURES(error_exit_dir); |
| 426 |
} |
| 427 |
} |
| 428 |
|
| 429 |
} |
| 430 |
error_exit_dir: |
| 431 |
smbcli_deltree(cli1->tree, dname); |
| 432 |
smbcli_rmdir(cli1->tree,dname); |
| 433 |
|
| 434 |
if(failures) |
| 435 |
return false; |
| 436 |
return true; |
| 437 |
} |