2 Unix SMB/CIFS implementation.
4 test security descriptor operations
6 Copyright (C) Andrew Tridgell 2004
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 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "torture/torture.h"
25 #include "libcli/raw/libcliraw.h"
26 #include "libcli/libcli.h"
27 #include "librpc/gen_ndr/lsa.h"
28 #include "libcli/util/clilsa.h"
29 #include "libcli/security/security.h"
30 #include "torture/util.h"
31 #include "librpc/gen_ndr/ndr_security.h"
33 #define BASEDIR "\\testsd"
35 #define CHECK_STATUS(status, correct) do { \
36 if (!NT_STATUS_EQUAL(status, correct)) { \
37 printf("(%s) Incorrect status %s - should be %s\n", \
38 __location__, nt_errstr(status), nt_errstr(correct)); \
44 static BOOL test_sd(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
48 const char *fname = BASEDIR "\\sd.txt";
52 union smb_setfileinfo set;
53 struct security_ace ace;
54 struct security_descriptor *sd;
55 struct dom_sid *test_sid;
57 printf("TESTING SETFILEINFO EA_SET\n");
59 io.generic.level = RAW_OPEN_NTCREATEX;
60 io.ntcreatex.in.root_fid = 0;
61 io.ntcreatex.in.flags = 0;
62 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
63 io.ntcreatex.in.create_options = 0;
64 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
65 io.ntcreatex.in.share_access =
66 NTCREATEX_SHARE_ACCESS_READ |
67 NTCREATEX_SHARE_ACCESS_WRITE;
68 io.ntcreatex.in.alloc_size = 0;
69 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
70 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
71 io.ntcreatex.in.security_flags = 0;
72 io.ntcreatex.in.fname = fname;
73 status = smb_raw_open(cli->tree, mem_ctx, &io);
74 CHECK_STATUS(status, NT_STATUS_OK);
75 fnum = io.ntcreatex.out.file.fnum;
77 q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
78 q.query_secdesc.in.file.fnum = fnum;
79 q.query_secdesc.in.secinfo_flags =
83 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
84 CHECK_STATUS(status, NT_STATUS_OK);
85 sd = q.query_secdesc.out.sd;
87 printf("add a new ACE to the DACL\n");
89 test_sid = dom_sid_parse_talloc(mem_ctx, "S-1-5-32-1234-5432");
91 ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
93 ace.access_mask = SEC_STD_ALL;
94 ace.trustee = *test_sid;
96 status = security_descriptor_dacl_add(sd, &ace);
97 CHECK_STATUS(status, NT_STATUS_OK);
99 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
100 set.set_secdesc.in.file.fnum = fnum;
101 set.set_secdesc.in.secinfo_flags = q.query_secdesc.in.secinfo_flags;
102 set.set_secdesc.in.sd = sd;
104 status = smb_raw_setfileinfo(cli->tree, &set);
105 CHECK_STATUS(status, NT_STATUS_OK);
107 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
108 CHECK_STATUS(status, NT_STATUS_OK);
110 if (!security_acl_equal(q.query_secdesc.out.sd->dacl, sd->dacl)) {
111 printf("%s: security descriptors don't match!\n", __location__);
113 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
114 printf("expected:\n");
115 NDR_PRINT_DEBUG(security_descriptor, sd);
119 printf("remove it again\n");
121 status = security_descriptor_dacl_del(sd, test_sid);
122 CHECK_STATUS(status, NT_STATUS_OK);
124 status = smb_raw_setfileinfo(cli->tree, &set);
125 CHECK_STATUS(status, NT_STATUS_OK);
127 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
128 CHECK_STATUS(status, NT_STATUS_OK);
130 if (!security_acl_equal(q.query_secdesc.out.sd->dacl, sd->dacl)) {
131 printf("%s: security descriptors don't match!\n", __location__);
133 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
134 printf("expected:\n");
135 NDR_PRINT_DEBUG(security_descriptor, sd);
140 smbcli_close(cli->tree, fnum);
146 test using NTTRANS CREATE to create a file with an initial ACL set
148 static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
152 const char *fname = BASEDIR "\\acl2.txt";
155 union smb_fileinfo q;
156 struct security_ace ace;
157 struct security_descriptor *sd;
158 struct dom_sid *test_sid;
160 printf("TESTING NTTRANS CREATE WITH SEC_DESC\n");
162 io.generic.level = RAW_OPEN_NTTRANS_CREATE;
163 io.ntcreatex.in.root_fid = 0;
164 io.ntcreatex.in.flags = 0;
165 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
166 io.ntcreatex.in.create_options = 0;
167 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
168 io.ntcreatex.in.share_access =
169 NTCREATEX_SHARE_ACCESS_READ |
170 NTCREATEX_SHARE_ACCESS_WRITE;
171 io.ntcreatex.in.alloc_size = 0;
172 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
173 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
174 io.ntcreatex.in.security_flags = 0;
175 io.ntcreatex.in.fname = fname;
176 io.ntcreatex.in.sec_desc = NULL;
177 io.ntcreatex.in.ea_list = NULL;
179 printf("creating normal file\n");
181 status = smb_raw_open(cli->tree, mem_ctx, &io);
182 CHECK_STATUS(status, NT_STATUS_OK);
183 fnum = io.ntcreatex.out.file.fnum;
185 printf("querying ACL\n");
187 q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
188 q.query_secdesc.in.file.fnum = fnum;
189 q.query_secdesc.in.secinfo_flags =
193 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
194 CHECK_STATUS(status, NT_STATUS_OK);
195 sd = q.query_secdesc.out.sd;
197 smbcli_close(cli->tree, fnum);
198 smbcli_unlink(cli->tree, fname);
200 printf("adding a new ACE\n");
201 test_sid = dom_sid_parse_talloc(mem_ctx, "S-1-5-32-1234-54321");
203 ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
205 ace.access_mask = SEC_STD_ALL;
206 ace.trustee = *test_sid;
208 status = security_descriptor_dacl_add(sd, &ace);
209 CHECK_STATUS(status, NT_STATUS_OK);
211 printf("creating a file with an initial ACL\n");
213 io.ntcreatex.in.sec_desc = sd;
214 status = smb_raw_open(cli->tree, mem_ctx, &io);
215 CHECK_STATUS(status, NT_STATUS_OK);
216 fnum = io.ntcreatex.out.file.fnum;
218 q.query_secdesc.in.file.fnum = fnum;
219 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
220 CHECK_STATUS(status, NT_STATUS_OK);
222 if (!security_acl_equal(q.query_secdesc.out.sd->dacl, sd->dacl)) {
223 printf("%s: security descriptors don't match!\n", __location__);
225 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
226 printf("expected:\n");
227 NDR_PRINT_DEBUG(security_descriptor, sd);
232 smbcli_close(cli->tree, fnum);
236 #define CHECK_ACCESS_FLAGS(_fnum, flags) do { \
237 union smb_fileinfo _q; \
238 _q.access_information.level = RAW_FILEINFO_ACCESS_INFORMATION; \
239 _q.access_information.in.file.fnum = (_fnum); \
240 status = smb_raw_fileinfo(cli->tree, mem_ctx, &_q); \
241 CHECK_STATUS(status, NT_STATUS_OK); \
242 if (_q.access_information.out.access_flags != (flags)) { \
243 printf("(%s) Incorrect access_flags 0x%08x - should be 0x%08x\n", \
244 __location__, _q.access_information.out.access_flags, (flags)); \
252 test the behaviour of the well known SID_CREATOR_OWNER sid, and some generic
255 static BOOL test_creator_sid(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
259 const char *fname = BASEDIR "\\creator.txt";
262 union smb_fileinfo q;
263 union smb_setfileinfo set;
264 struct security_descriptor *sd, *sd_orig, *sd2;
265 const char *owner_sid;
267 printf("TESTING SID_CREATOR_OWNER\n");
269 io.generic.level = RAW_OPEN_NTCREATEX;
270 io.ntcreatex.in.root_fid = 0;
271 io.ntcreatex.in.flags = 0;
272 io.ntcreatex.in.access_mask = SEC_STD_READ_CONTROL | SEC_STD_WRITE_DAC | SEC_STD_WRITE_OWNER;
273 io.ntcreatex.in.create_options = 0;
274 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
275 io.ntcreatex.in.share_access =
276 NTCREATEX_SHARE_ACCESS_READ |
277 NTCREATEX_SHARE_ACCESS_WRITE;
278 io.ntcreatex.in.alloc_size = 0;
279 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
280 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
281 io.ntcreatex.in.security_flags = 0;
282 io.ntcreatex.in.fname = fname;
283 status = smb_raw_open(cli->tree, mem_ctx, &io);
284 CHECK_STATUS(status, NT_STATUS_OK);
285 fnum = io.ntcreatex.out.file.fnum;
287 printf("get the original sd\n");
288 q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
289 q.query_secdesc.in.file.fnum = fnum;
290 q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
291 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
292 CHECK_STATUS(status, NT_STATUS_OK);
293 sd_orig = q.query_secdesc.out.sd;
295 owner_sid = dom_sid_string(mem_ctx, sd_orig->owner_sid);
297 printf("set a sec desc allowing no write by CREATOR_OWNER\n");
298 sd = security_descriptor_create(mem_ctx,
301 SEC_ACE_TYPE_ACCESS_ALLOWED,
302 SEC_RIGHTS_FILE_READ | SEC_STD_ALL,
306 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
307 set.set_secdesc.in.file.fnum = fnum;
308 set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
309 set.set_secdesc.in.sd = sd;
311 status = smb_raw_setfileinfo(cli->tree, &set);
312 CHECK_STATUS(status, NT_STATUS_OK);
314 printf("try open for write\n");
315 io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
316 status = smb_raw_open(cli->tree, mem_ctx, &io);
317 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
319 printf("try open for read\n");
320 io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
321 status = smb_raw_open(cli->tree, mem_ctx, &io);
322 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
324 printf("try open for generic write\n");
325 io.ntcreatex.in.access_mask = SEC_GENERIC_WRITE;
326 status = smb_raw_open(cli->tree, mem_ctx, &io);
327 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
329 printf("try open for generic read\n");
330 io.ntcreatex.in.access_mask = SEC_GENERIC_READ;
331 status = smb_raw_open(cli->tree, mem_ctx, &io);
332 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
334 printf("set a sec desc allowing no write by owner\n");
335 sd = security_descriptor_create(mem_ctx,
338 SEC_ACE_TYPE_ACCESS_ALLOWED,
339 SEC_RIGHTS_FILE_READ | SEC_STD_ALL,
343 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
344 set.set_secdesc.in.file.fnum = fnum;
345 set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
346 set.set_secdesc.in.sd = sd;
347 status = smb_raw_setfileinfo(cli->tree, &set);
348 CHECK_STATUS(status, NT_STATUS_OK);
350 printf("check that sd has been mapped correctly\n");
351 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
352 CHECK_STATUS(status, NT_STATUS_OK);
353 if (!security_descriptor_equal(q.query_secdesc.out.sd, sd)) {
354 printf("%s: security descriptors don't match!\n", __location__);
356 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
357 printf("expected:\n");
358 NDR_PRINT_DEBUG(security_descriptor, sd);
362 printf("try open for write\n");
363 io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
364 status = smb_raw_open(cli->tree, mem_ctx, &io);
365 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
367 printf("try open for read\n");
368 io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
369 status = smb_raw_open(cli->tree, mem_ctx, &io);
370 CHECK_STATUS(status, NT_STATUS_OK);
371 CHECK_ACCESS_FLAGS(io.ntcreatex.out.file.fnum,
373 SEC_FILE_READ_ATTRIBUTE);
374 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
376 printf("try open for generic write\n");
377 io.ntcreatex.in.access_mask = SEC_GENERIC_WRITE;
378 status = smb_raw_open(cli->tree, mem_ctx, &io);
379 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
381 printf("try open for generic read\n");
382 io.ntcreatex.in.access_mask = SEC_GENERIC_READ;
383 status = smb_raw_open(cli->tree, mem_ctx, &io);
384 CHECK_STATUS(status, NT_STATUS_OK);
385 CHECK_ACCESS_FLAGS(io.ntcreatex.out.file.fnum,
386 SEC_RIGHTS_FILE_READ);
387 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
389 printf("set a sec desc allowing generic read by owner\n");
390 sd = security_descriptor_create(mem_ctx,
393 SEC_ACE_TYPE_ACCESS_ALLOWED,
394 SEC_GENERIC_READ | SEC_STD_ALL,
398 set.set_secdesc.in.sd = sd;
399 status = smb_raw_setfileinfo(cli->tree, &set);
400 CHECK_STATUS(status, NT_STATUS_OK);
402 printf("check that generic read has been mapped correctly\n");
403 sd2 = security_descriptor_create(mem_ctx,
406 SEC_ACE_TYPE_ACCESS_ALLOWED,
407 SEC_RIGHTS_FILE_READ | SEC_STD_ALL,
411 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
412 CHECK_STATUS(status, NT_STATUS_OK);
413 if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
414 printf("%s: security descriptors don't match!\n", __location__);
416 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
417 printf("expected:\n");
418 NDR_PRINT_DEBUG(security_descriptor, sd2);
423 printf("try open for write\n");
424 io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
425 status = smb_raw_open(cli->tree, mem_ctx, &io);
426 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
428 printf("try open for read\n");
429 io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
430 status = smb_raw_open(cli->tree, mem_ctx, &io);
431 CHECK_STATUS(status, NT_STATUS_OK);
432 CHECK_ACCESS_FLAGS(io.ntcreatex.out.file.fnum,
434 SEC_FILE_READ_ATTRIBUTE);
435 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
437 printf("try open for generic write\n");
438 io.ntcreatex.in.access_mask = SEC_GENERIC_WRITE;
439 status = smb_raw_open(cli->tree, mem_ctx, &io);
440 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
442 printf("try open for generic read\n");
443 io.ntcreatex.in.access_mask = SEC_GENERIC_READ;
444 status = smb_raw_open(cli->tree, mem_ctx, &io);
445 CHECK_STATUS(status, NT_STATUS_OK);
446 CHECK_ACCESS_FLAGS(io.ntcreatex.out.file.fnum, SEC_RIGHTS_FILE_READ);
447 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
450 printf("put back original sd\n");
451 set.set_secdesc.in.sd = sd_orig;
452 status = smb_raw_setfileinfo(cli->tree, &set);
453 CHECK_STATUS(status, NT_STATUS_OK);
457 smbcli_close(cli->tree, fnum);
463 test the mapping of the SEC_GENERIC_xx bits to SEC_STD_xx and
466 static BOOL test_generic_bits(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
470 const char *fname = BASEDIR "\\generic.txt";
473 union smb_fileinfo q;
474 union smb_setfileinfo set;
475 struct security_descriptor *sd, *sd_orig, *sd2;
476 const char *owner_sid;
479 uint32_t specific_bits;
480 } file_mappings[] = {
482 { SEC_GENERIC_READ, SEC_RIGHTS_FILE_READ },
483 { SEC_GENERIC_WRITE, SEC_RIGHTS_FILE_WRITE },
484 { SEC_GENERIC_EXECUTE, SEC_RIGHTS_FILE_EXECUTE },
485 { SEC_GENERIC_ALL, SEC_RIGHTS_FILE_ALL },
486 { SEC_FILE_READ_DATA, SEC_FILE_READ_DATA },
487 { SEC_FILE_READ_ATTRIBUTE, SEC_FILE_READ_ATTRIBUTE }
491 uint32_t specific_bits;
494 { SEC_GENERIC_READ, SEC_RIGHTS_DIR_READ },
495 { SEC_GENERIC_WRITE, SEC_RIGHTS_DIR_WRITE },
496 { SEC_GENERIC_EXECUTE, SEC_RIGHTS_DIR_EXECUTE },
497 { SEC_GENERIC_ALL, SEC_RIGHTS_DIR_ALL }
499 BOOL has_restore_privilege;
500 BOOL has_take_ownership_privilege;
502 printf("TESTING FILE GENERIC BITS\n");
504 io.generic.level = RAW_OPEN_NTCREATEX;
505 io.ntcreatex.in.root_fid = 0;
506 io.ntcreatex.in.flags = 0;
507 io.ntcreatex.in.access_mask =
508 SEC_STD_READ_CONTROL |
511 io.ntcreatex.in.create_options = 0;
512 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
513 io.ntcreatex.in.share_access =
514 NTCREATEX_SHARE_ACCESS_READ |
515 NTCREATEX_SHARE_ACCESS_WRITE;
516 io.ntcreatex.in.alloc_size = 0;
517 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
518 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
519 io.ntcreatex.in.security_flags = 0;
520 io.ntcreatex.in.fname = fname;
521 status = smb_raw_open(cli->tree, mem_ctx, &io);
522 CHECK_STATUS(status, NT_STATUS_OK);
523 fnum = io.ntcreatex.out.file.fnum;
525 printf("get the original sd\n");
526 q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
527 q.query_secdesc.in.file.fnum = fnum;
528 q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
529 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
530 CHECK_STATUS(status, NT_STATUS_OK);
531 sd_orig = q.query_secdesc.out.sd;
533 owner_sid = dom_sid_string(mem_ctx, sd_orig->owner_sid);
535 status = smblsa_sid_check_privilege(cli,
537 sec_privilege_name(SEC_PRIV_RESTORE));
538 has_restore_privilege = NT_STATUS_IS_OK(status);
539 if (!NT_STATUS_IS_OK(status)) {
540 printf("smblsa_sid_check_privilege - %s\n", nt_errstr(status));
542 printf("SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
544 status = smblsa_sid_check_privilege(cli,
546 sec_privilege_name(SEC_PRIV_TAKE_OWNERSHIP));
547 has_take_ownership_privilege = NT_STATUS_IS_OK(status);
548 if (!NT_STATUS_IS_OK(status)) {
549 printf("smblsa_sid_check_privilege - %s\n", nt_errstr(status));
551 printf("SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
553 for (i=0;i<ARRAY_SIZE(file_mappings);i++) {
554 uint32_t expected_mask =
556 SEC_STD_READ_CONTROL |
557 SEC_FILE_READ_ATTRIBUTE |
559 uint32_t expected_mask_anon = SEC_FILE_READ_ATTRIBUTE;
561 if (has_restore_privilege) {
562 expected_mask_anon |= SEC_STD_DELETE;
565 printf("testing generic bits 0x%08x\n",
566 file_mappings[i].gen_bits);
567 sd = security_descriptor_create(mem_ctx,
570 SEC_ACE_TYPE_ACCESS_ALLOWED,
571 file_mappings[i].gen_bits,
575 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
576 set.set_secdesc.in.file.fnum = fnum;
577 set.set_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
578 set.set_secdesc.in.sd = sd;
580 status = smb_raw_setfileinfo(cli->tree, &set);
581 CHECK_STATUS(status, NT_STATUS_OK);
583 sd2 = security_descriptor_create(mem_ctx,
586 SEC_ACE_TYPE_ACCESS_ALLOWED,
587 file_mappings[i].specific_bits,
591 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
592 CHECK_STATUS(status, NT_STATUS_OK);
593 if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
594 printf("%s: security descriptors don't match!\n", __location__);
596 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
597 printf("expected:\n");
598 NDR_PRINT_DEBUG(security_descriptor, sd2);
602 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
603 status = smb_raw_open(cli->tree, mem_ctx, &io);
604 CHECK_STATUS(status, NT_STATUS_OK);
605 CHECK_ACCESS_FLAGS(io.ntcreatex.out.file.fnum,
606 expected_mask | file_mappings[i].specific_bits);
607 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
609 if (!has_take_ownership_privilege) {
613 printf("testing generic bits 0x%08x (anonymous)\n",
614 file_mappings[i].gen_bits);
615 sd = security_descriptor_create(mem_ctx,
616 SID_NT_ANONYMOUS, NULL,
618 SEC_ACE_TYPE_ACCESS_ALLOWED,
619 file_mappings[i].gen_bits,
623 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
624 set.set_secdesc.in.file.fnum = fnum;
625 set.set_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
626 set.set_secdesc.in.sd = sd;
628 status = smb_raw_setfileinfo(cli->tree, &set);
629 CHECK_STATUS(status, NT_STATUS_OK);
631 sd2 = security_descriptor_create(mem_ctx,
632 SID_NT_ANONYMOUS, NULL,
634 SEC_ACE_TYPE_ACCESS_ALLOWED,
635 file_mappings[i].specific_bits,
639 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
640 CHECK_STATUS(status, NT_STATUS_OK);
641 if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
642 printf("%s: security descriptors don't match!\n", __location__);
644 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
645 printf("expected:\n");
646 NDR_PRINT_DEBUG(security_descriptor, sd2);
650 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
651 status = smb_raw_open(cli->tree, mem_ctx, &io);
652 CHECK_STATUS(status, NT_STATUS_OK);
653 CHECK_ACCESS_FLAGS(io.ntcreatex.out.file.fnum,
654 expected_mask_anon | file_mappings[i].specific_bits);
655 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
658 printf("put back original sd\n");
659 set.set_secdesc.in.sd = sd_orig;
660 status = smb_raw_setfileinfo(cli->tree, &set);
661 CHECK_STATUS(status, NT_STATUS_OK);
663 smbcli_close(cli->tree, fnum);
664 smbcli_unlink(cli->tree, fname);
667 printf("TESTING DIR GENERIC BITS\n");
669 io.generic.level = RAW_OPEN_NTCREATEX;
670 io.ntcreatex.in.root_fid = 0;
671 io.ntcreatex.in.flags = 0;
672 io.ntcreatex.in.access_mask =
673 SEC_STD_READ_CONTROL |
676 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
677 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
678 io.ntcreatex.in.share_access =
679 NTCREATEX_SHARE_ACCESS_READ |
680 NTCREATEX_SHARE_ACCESS_WRITE;
681 io.ntcreatex.in.alloc_size = 0;
682 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
683 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
684 io.ntcreatex.in.security_flags = 0;
685 io.ntcreatex.in.fname = fname;
686 status = smb_raw_open(cli->tree, mem_ctx, &io);
687 CHECK_STATUS(status, NT_STATUS_OK);
688 fnum = io.ntcreatex.out.file.fnum;
690 printf("get the original sd\n");
691 q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
692 q.query_secdesc.in.file.fnum = fnum;
693 q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
694 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
695 CHECK_STATUS(status, NT_STATUS_OK);
696 sd_orig = q.query_secdesc.out.sd;
698 owner_sid = dom_sid_string(mem_ctx, sd_orig->owner_sid);
700 status = smblsa_sid_check_privilege(cli,
702 sec_privilege_name(SEC_PRIV_RESTORE));
703 has_restore_privilege = NT_STATUS_IS_OK(status);
704 if (!NT_STATUS_IS_OK(status)) {
705 printf("smblsa_sid_check_privilege - %s\n", nt_errstr(status));
707 printf("SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
709 status = smblsa_sid_check_privilege(cli,
711 sec_privilege_name(SEC_PRIV_TAKE_OWNERSHIP));
712 has_take_ownership_privilege = NT_STATUS_IS_OK(status);
713 if (!NT_STATUS_IS_OK(status)) {
714 printf("smblsa_sid_check_privilege - %s\n", nt_errstr(status));
716 printf("SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
718 for (i=0;i<ARRAY_SIZE(dir_mappings);i++) {
719 uint32_t expected_mask =
721 SEC_STD_READ_CONTROL |
722 SEC_FILE_READ_ATTRIBUTE |
724 uint32_t expected_mask_anon = SEC_FILE_READ_ATTRIBUTE;
726 if (has_restore_privilege) {
727 expected_mask_anon |= SEC_STD_DELETE;
730 printf("testing generic bits 0x%08x\n",
731 file_mappings[i].gen_bits);
732 sd = security_descriptor_create(mem_ctx,
735 SEC_ACE_TYPE_ACCESS_ALLOWED,
736 dir_mappings[i].gen_bits,
740 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
741 set.set_secdesc.in.file.fnum = fnum;
742 set.set_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
743 set.set_secdesc.in.sd = sd;
745 status = smb_raw_setfileinfo(cli->tree, &set);
746 CHECK_STATUS(status, NT_STATUS_OK);
748 sd2 = security_descriptor_create(mem_ctx,
751 SEC_ACE_TYPE_ACCESS_ALLOWED,
752 dir_mappings[i].specific_bits,
756 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
757 CHECK_STATUS(status, NT_STATUS_OK);
758 if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
759 printf("%s: security descriptors don't match!\n", __location__);
761 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
762 printf("expected:\n");
763 NDR_PRINT_DEBUG(security_descriptor, sd2);
767 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
768 status = smb_raw_open(cli->tree, mem_ctx, &io);
769 CHECK_STATUS(status, NT_STATUS_OK);
770 CHECK_ACCESS_FLAGS(io.ntcreatex.out.file.fnum,
771 expected_mask | dir_mappings[i].specific_bits);
772 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
774 if (!has_take_ownership_privilege) {
778 printf("testing generic bits 0x%08x (anonymous)\n",
779 file_mappings[i].gen_bits);
780 sd = security_descriptor_create(mem_ctx,
781 SID_NT_ANONYMOUS, NULL,
783 SEC_ACE_TYPE_ACCESS_ALLOWED,
784 file_mappings[i].gen_bits,
788 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
789 set.set_secdesc.in.file.fnum = fnum;
790 set.set_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
791 set.set_secdesc.in.sd = sd;
793 status = smb_raw_setfileinfo(cli->tree, &set);
794 CHECK_STATUS(status, NT_STATUS_OK);
796 sd2 = security_descriptor_create(mem_ctx,
797 SID_NT_ANONYMOUS, NULL,
799 SEC_ACE_TYPE_ACCESS_ALLOWED,
800 file_mappings[i].specific_bits,
804 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
805 CHECK_STATUS(status, NT_STATUS_OK);
806 if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
807 printf("%s: security descriptors don't match!\n", __location__);
809 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
810 printf("expected:\n");
811 NDR_PRINT_DEBUG(security_descriptor, sd2);
815 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
816 status = smb_raw_open(cli->tree, mem_ctx, &io);
817 CHECK_STATUS(status, NT_STATUS_OK);
818 CHECK_ACCESS_FLAGS(io.ntcreatex.out.file.fnum,
819 expected_mask_anon | dir_mappings[i].specific_bits);
820 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
823 printf("put back original sd\n");
824 set.set_secdesc.in.sd = sd_orig;
825 status = smb_raw_setfileinfo(cli->tree, &set);
826 CHECK_STATUS(status, NT_STATUS_OK);
828 smbcli_close(cli->tree, fnum);
829 smbcli_unlink(cli->tree, fname);
832 smbcli_close(cli->tree, fnum);
838 see what access bits the owner of a file always gets
840 static BOOL test_owner_bits(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
844 const char *fname = BASEDIR "\\generic.txt";
847 union smb_fileinfo q;
848 union smb_setfileinfo set;
849 struct security_descriptor *sd, *sd_orig;
850 const char *owner_sid;
851 BOOL has_restore_privilege;
852 BOOL has_take_ownership_privilege;
853 uint32_t expected_bits;
855 printf("TESTING FILE OWNER BITS\n");
857 io.generic.level = RAW_OPEN_NTCREATEX;
858 io.ntcreatex.in.root_fid = 0;
859 io.ntcreatex.in.flags = 0;
860 io.ntcreatex.in.access_mask =
861 SEC_STD_READ_CONTROL |
864 io.ntcreatex.in.create_options = 0;
865 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
866 io.ntcreatex.in.share_access =
867 NTCREATEX_SHARE_ACCESS_READ |
868 NTCREATEX_SHARE_ACCESS_WRITE;
869 io.ntcreatex.in.alloc_size = 0;
870 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
871 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
872 io.ntcreatex.in.security_flags = 0;
873 io.ntcreatex.in.fname = fname;
874 status = smb_raw_open(cli->tree, mem_ctx, &io);
875 CHECK_STATUS(status, NT_STATUS_OK);
876 fnum = io.ntcreatex.out.file.fnum;
878 printf("get the original sd\n");
879 q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
880 q.query_secdesc.in.file.fnum = fnum;
881 q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
882 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
883 CHECK_STATUS(status, NT_STATUS_OK);
884 sd_orig = q.query_secdesc.out.sd;
886 owner_sid = dom_sid_string(mem_ctx, sd_orig->owner_sid);
888 status = smblsa_sid_check_privilege(cli,
890 sec_privilege_name(SEC_PRIV_RESTORE));
891 has_restore_privilege = NT_STATUS_IS_OK(status);
892 if (!NT_STATUS_IS_OK(status)) {
893 printf("smblsa_sid_check_privilege - %s\n", nt_errstr(status));
895 printf("SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
897 status = smblsa_sid_check_privilege(cli,
899 sec_privilege_name(SEC_PRIV_TAKE_OWNERSHIP));
900 has_take_ownership_privilege = NT_STATUS_IS_OK(status);
901 if (!NT_STATUS_IS_OK(status)) {
902 printf("smblsa_sid_check_privilege - %s\n", nt_errstr(status));
904 printf("SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
906 sd = security_descriptor_create(mem_ctx,
909 SEC_ACE_TYPE_ACCESS_ALLOWED,
914 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
915 set.set_secdesc.in.file.fnum = fnum;
916 set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
917 set.set_secdesc.in.sd = sd;
919 status = smb_raw_setfileinfo(cli->tree, &set);
920 CHECK_STATUS(status, NT_STATUS_OK);
922 expected_bits = SEC_FILE_WRITE_DATA | SEC_FILE_READ_ATTRIBUTE;
925 uint32_t bit = (1<<i);
926 io.ntcreatex.in.access_mask = bit;
927 status = smb_raw_open(cli->tree, mem_ctx, &io);
928 if (expected_bits & bit) {
929 if (!NT_STATUS_IS_OK(status)) {
930 printf("failed with access mask 0x%08x of expected 0x%08x\n",
933 CHECK_STATUS(status, NT_STATUS_OK);
934 CHECK_ACCESS_FLAGS(io.ntcreatex.out.file.fnum, bit | SEC_FILE_READ_ATTRIBUTE);
935 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
937 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
941 printf("put back original sd\n");
942 set.set_secdesc.in.sd = sd_orig;
943 status = smb_raw_setfileinfo(cli->tree, &set);
944 CHECK_STATUS(status, NT_STATUS_OK);
947 smbcli_close(cli->tree, fnum);
948 smbcli_unlink(cli->tree, fname);
955 test the inheritance of ACL flags onto new files and directories
957 static BOOL test_inheritance(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
961 const char *dname = BASEDIR "\\inheritance";
962 const char *fname1 = BASEDIR "\\inheritance\\testfile";
963 const char *fname2 = BASEDIR "\\inheritance\\testdir";
966 union smb_fileinfo q;
967 union smb_setfileinfo set;
968 struct security_descriptor *sd, *sd2, *sd_orig, *sd_def;
969 const char *owner_sid;
970 const struct dom_sid *creator_owner;
972 uint32_t parent_flags;
982 SEC_ACE_FLAG_OBJECT_INHERIT,
984 SEC_ACE_FLAG_OBJECT_INHERIT |
985 SEC_ACE_FLAG_INHERIT_ONLY,
988 SEC_ACE_FLAG_CONTAINER_INHERIT,
990 SEC_ACE_FLAG_CONTAINER_INHERIT,
993 SEC_ACE_FLAG_OBJECT_INHERIT |
994 SEC_ACE_FLAG_CONTAINER_INHERIT,
996 SEC_ACE_FLAG_OBJECT_INHERIT |
997 SEC_ACE_FLAG_CONTAINER_INHERIT,
1000 SEC_ACE_FLAG_NO_PROPAGATE_INHERIT,
1005 SEC_ACE_FLAG_NO_PROPAGATE_INHERIT |
1006 SEC_ACE_FLAG_OBJECT_INHERIT,
1011 SEC_ACE_FLAG_NO_PROPAGATE_INHERIT |
1012 SEC_ACE_FLAG_CONTAINER_INHERIT,
1017 SEC_ACE_FLAG_NO_PROPAGATE_INHERIT |
1018 SEC_ACE_FLAG_CONTAINER_INHERIT |
1019 SEC_ACE_FLAG_OBJECT_INHERIT,
1024 SEC_ACE_FLAG_INHERIT_ONLY,
1029 SEC_ACE_FLAG_INHERIT_ONLY |
1030 SEC_ACE_FLAG_OBJECT_INHERIT,
1032 SEC_ACE_FLAG_OBJECT_INHERIT |
1033 SEC_ACE_FLAG_INHERIT_ONLY,
1036 SEC_ACE_FLAG_INHERIT_ONLY |
1037 SEC_ACE_FLAG_CONTAINER_INHERIT,
1039 SEC_ACE_FLAG_CONTAINER_INHERIT,
1042 SEC_ACE_FLAG_INHERIT_ONLY |
1043 SEC_ACE_FLAG_CONTAINER_INHERIT |
1044 SEC_ACE_FLAG_OBJECT_INHERIT,
1046 SEC_ACE_FLAG_CONTAINER_INHERIT |
1047 SEC_ACE_FLAG_OBJECT_INHERIT,
1050 SEC_ACE_FLAG_INHERIT_ONLY |
1051 SEC_ACE_FLAG_NO_PROPAGATE_INHERIT,
1056 SEC_ACE_FLAG_INHERIT_ONLY |
1057 SEC_ACE_FLAG_NO_PROPAGATE_INHERIT |
1058 SEC_ACE_FLAG_OBJECT_INHERIT,
1063 SEC_ACE_FLAG_INHERIT_ONLY |
1064 SEC_ACE_FLAG_NO_PROPAGATE_INHERIT |
1065 SEC_ACE_FLAG_CONTAINER_INHERIT,
1070 SEC_ACE_FLAG_INHERIT_ONLY |
1071 SEC_ACE_FLAG_NO_PROPAGATE_INHERIT |
1072 SEC_ACE_FLAG_CONTAINER_INHERIT |
1073 SEC_ACE_FLAG_OBJECT_INHERIT,
1079 smbcli_rmdir(cli->tree, dname);
1081 printf("TESTING ACL INHERITANCE\n");
1083 io.generic.level = RAW_OPEN_NTCREATEX;
1084 io.ntcreatex.in.root_fid = 0;
1085 io.ntcreatex.in.flags = 0;
1086 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1087 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1088 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
1089 io.ntcreatex.in.share_access = 0;
1090 io.ntcreatex.in.alloc_size = 0;
1091 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1092 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1093 io.ntcreatex.in.security_flags = 0;
1094 io.ntcreatex.in.fname = dname;
1096 status = smb_raw_open(cli->tree, mem_ctx, &io);
1097 CHECK_STATUS(status, NT_STATUS_OK);
1098 fnum = io.ntcreatex.out.file.fnum;
1100 printf("get the original sd\n");
1101 q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
1102 q.query_secdesc.in.file.fnum = fnum;
1103 q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
1104 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
1105 CHECK_STATUS(status, NT_STATUS_OK);
1106 sd_orig = q.query_secdesc.out.sd;
1108 owner_sid = dom_sid_string(mem_ctx, sd_orig->owner_sid);
1110 printf("owner_sid is %s\n", owner_sid);
1112 sd_def = security_descriptor_create(mem_ctx,
1115 SEC_ACE_TYPE_ACCESS_ALLOWED,
1116 SEC_RIGHTS_FILE_ALL,
1119 SEC_ACE_TYPE_ACCESS_ALLOWED,
1120 SEC_RIGHTS_FILE_ALL,
1124 creator_owner = dom_sid_parse_talloc(mem_ctx, SID_CREATOR_OWNER);
1126 for (i=0;i<ARRAY_SIZE(test_flags);i++) {
1127 sd = security_descriptor_create(mem_ctx,
1130 SEC_ACE_TYPE_ACCESS_ALLOWED,
1131 SEC_FILE_WRITE_DATA,
1132 test_flags[i].parent_flags,
1134 SEC_ACE_TYPE_ACCESS_ALLOWED,
1135 SEC_FILE_ALL | SEC_STD_ALL,
1138 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
1139 set.set_secdesc.in.file.fnum = fnum;
1140 set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
1141 set.set_secdesc.in.sd = sd;
1142 status = smb_raw_setfileinfo(cli->tree, &set);
1143 CHECK_STATUS(status, NT_STATUS_OK);
1145 io.ntcreatex.in.fname = fname1;
1146 io.ntcreatex.in.create_options = 0;
1147 status = smb_raw_open(cli->tree, mem_ctx, &io);
1148 CHECK_STATUS(status, NT_STATUS_OK);
1149 fnum2 = io.ntcreatex.out.file.fnum;
1151 q.query_secdesc.in.file.fnum = fnum2;
1152 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
1153 CHECK_STATUS(status, NT_STATUS_OK);
1155 smbcli_close(cli->tree, fnum2);
1156 smbcli_unlink(cli->tree, fname1);
1158 if (!(test_flags[i].parent_flags & SEC_ACE_FLAG_OBJECT_INHERIT)) {
1159 if (!security_descriptor_equal(q.query_secdesc.out.sd, sd_def)) {
1160 printf("Expected default sd at %d - got:\n", i);
1161 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
1166 if (q.query_secdesc.out.sd->dacl == NULL ||
1167 q.query_secdesc.out.sd->dacl->num_aces != 1 ||
1168 q.query_secdesc.out.sd->dacl->aces[0].access_mask != SEC_FILE_WRITE_DATA ||
1169 !dom_sid_equal(&q.query_secdesc.out.sd->dacl->aces[0].trustee,
1170 sd_orig->owner_sid)) {
1171 printf("Bad sd in child file at %d\n", i);
1172 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
1177 if (q.query_secdesc.out.sd->dacl->aces[0].flags !=
1178 test_flags[i].file_flags) {
1179 printf("incorrect file_flags 0x%x - expected 0x%x for parent 0x%x with (i=%d)\n",
1180 q.query_secdesc.out.sd->dacl->aces[0].flags,
1181 test_flags[i].file_flags,
1182 test_flags[i].parent_flags,
1188 io.ntcreatex.in.fname = fname2;
1189 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1190 status = smb_raw_open(cli->tree, mem_ctx, &io);
1191 CHECK_STATUS(status, NT_STATUS_OK);
1192 fnum2 = io.ntcreatex.out.file.fnum;
1194 q.query_secdesc.in.file.fnum = fnum2;
1195 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
1196 CHECK_STATUS(status, NT_STATUS_OK);
1198 smbcli_close(cli->tree, fnum2);
1199 smbcli_rmdir(cli->tree, fname2);
1201 if (!(test_flags[i].parent_flags & SEC_ACE_FLAG_CONTAINER_INHERIT) &&
1202 (!(test_flags[i].parent_flags & SEC_ACE_FLAG_OBJECT_INHERIT) ||
1203 (test_flags[i].parent_flags & SEC_ACE_FLAG_NO_PROPAGATE_INHERIT))) {
1204 if (!security_descriptor_equal(q.query_secdesc.out.sd, sd_def)) {
1205 printf("Expected default sd for dir at %d - got:\n", i);
1206 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
1211 if ((test_flags[i].parent_flags & SEC_ACE_FLAG_CONTAINER_INHERIT) &&
1212 (test_flags[i].parent_flags & SEC_ACE_FLAG_NO_PROPAGATE_INHERIT)) {
1213 if (q.query_secdesc.out.sd->dacl == NULL ||
1214 q.query_secdesc.out.sd->dacl->num_aces != 1 ||
1215 q.query_secdesc.out.sd->dacl->aces[0].access_mask != SEC_FILE_WRITE_DATA ||
1216 !dom_sid_equal(&q.query_secdesc.out.sd->dacl->aces[0].trustee,
1217 sd_orig->owner_sid) ||
1218 q.query_secdesc.out.sd->dacl->aces[0].flags != test_flags[i].dir_flags) {
1219 printf("Bad sd in child dir at %d (parent 0x%x)\n",
1220 i, test_flags[i].parent_flags);
1221 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
1225 } else if (test_flags[i].parent_flags & SEC_ACE_FLAG_CONTAINER_INHERIT) {
1226 if (q.query_secdesc.out.sd->dacl == NULL ||
1227 q.query_secdesc.out.sd->dacl->num_aces != 2 ||
1228 q.query_secdesc.out.sd->dacl->aces[0].access_mask != SEC_FILE_WRITE_DATA ||
1229 !dom_sid_equal(&q.query_secdesc.out.sd->dacl->aces[0].trustee,
1230 sd_orig->owner_sid) ||
1231 q.query_secdesc.out.sd->dacl->aces[1].access_mask != SEC_FILE_WRITE_DATA ||
1232 !dom_sid_equal(&q.query_secdesc.out.sd->dacl->aces[1].trustee,
1234 q.query_secdesc.out.sd->dacl->aces[0].flags != 0 ||
1235 q.query_secdesc.out.sd->dacl->aces[1].flags !=
1236 (test_flags[i].dir_flags | SEC_ACE_FLAG_INHERIT_ONLY)) {
1237 printf("Bad sd in child dir at %d (parent 0x%x)\n",
1238 i, test_flags[i].parent_flags);
1239 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
1244 if (q.query_secdesc.out.sd->dacl == NULL ||
1245 q.query_secdesc.out.sd->dacl->num_aces != 1 ||
1246 q.query_secdesc.out.sd->dacl->aces[0].access_mask != SEC_FILE_WRITE_DATA ||
1247 !dom_sid_equal(&q.query_secdesc.out.sd->dacl->aces[0].trustee,
1249 q.query_secdesc.out.sd->dacl->aces[0].flags != test_flags[i].dir_flags) {
1250 printf("Bad sd in child dir at %d (parent 0x%x)\n",
1251 i, test_flags[i].parent_flags);
1252 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
1259 printf("testing access checks on inherited create with %s\n", fname1);
1260 sd = security_descriptor_create(mem_ctx,
1263 SEC_ACE_TYPE_ACCESS_ALLOWED,
1264 SEC_FILE_WRITE_DATA | SEC_STD_WRITE_DAC,
1265 SEC_ACE_FLAG_OBJECT_INHERIT,
1267 SEC_ACE_TYPE_ACCESS_ALLOWED,
1268 SEC_FILE_ALL | SEC_STD_ALL,
1271 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
1272 set.set_secdesc.in.file.fnum = fnum;
1273 set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
1274 set.set_secdesc.in.sd = sd;
1275 status = smb_raw_setfileinfo(cli->tree, &set);
1276 CHECK_STATUS(status, NT_STATUS_OK);
1278 io.ntcreatex.in.fname = fname1;
1279 io.ntcreatex.in.create_options = 0;
1280 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1281 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1282 status = smb_raw_open(cli->tree, mem_ctx, &io);
1283 CHECK_STATUS(status, NT_STATUS_OK);
1284 fnum2 = io.ntcreatex.out.file.fnum;
1285 CHECK_ACCESS_FLAGS(fnum2, SEC_RIGHTS_FILE_ALL);
1287 q.query_secdesc.in.file.fnum = fnum2;
1288 q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
1289 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
1290 CHECK_STATUS(status, NT_STATUS_OK);
1291 smbcli_close(cli->tree, fnum2);
1293 sd2 = security_descriptor_create(mem_ctx,
1296 SEC_ACE_TYPE_ACCESS_ALLOWED,
1297 SEC_FILE_WRITE_DATA | SEC_STD_WRITE_DAC,
1300 if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
1301 printf("%s: security descriptors don't match!\n", __location__);
1303 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
1304 printf("expected:\n");
1305 NDR_PRINT_DEBUG(security_descriptor, sd2);
1309 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1310 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1311 status = smb_raw_open(cli->tree, mem_ctx, &io);
1312 if (NT_STATUS_IS_OK(status)) {
1313 printf("failed: w2k3 ACL bug (allowed open when ACL should deny)\n");
1315 fnum2 = io.ntcreatex.out.file.fnum;
1316 CHECK_ACCESS_FLAGS(fnum2, SEC_RIGHTS_FILE_ALL);
1317 smbcli_close(cli->tree, fnum2);
1319 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
1322 printf("trying without execute\n");
1323 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1324 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL & ~SEC_FILE_EXECUTE;
1325 status = smb_raw_open(cli->tree, mem_ctx, &io);
1326 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
1328 printf("and with full permissions again\n");
1329 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1330 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1331 status = smb_raw_open(cli->tree, mem_ctx, &io);
1332 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
1334 io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
1335 status = smb_raw_open(cli->tree, mem_ctx, &io);
1336 CHECK_STATUS(status, NT_STATUS_OK);
1337 fnum2 = io.ntcreatex.out.file.fnum;
1338 CHECK_ACCESS_FLAGS(fnum2, SEC_FILE_WRITE_DATA | SEC_FILE_READ_ATTRIBUTE);
1339 smbcli_close(cli->tree, fnum2);
1341 printf("put back original sd\n");
1342 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
1343 set.set_secdesc.in.file.fnum = fnum;
1344 set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
1345 set.set_secdesc.in.sd = sd_orig;
1346 status = smb_raw_setfileinfo(cli->tree, &set);
1347 CHECK_STATUS(status, NT_STATUS_OK);
1349 smbcli_close(cli->tree, fnum);
1351 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1352 status = smb_raw_open(cli->tree, mem_ctx, &io);
1353 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
1355 io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
1356 status = smb_raw_open(cli->tree, mem_ctx, &io);
1357 CHECK_STATUS(status, NT_STATUS_OK);
1358 fnum2 = io.ntcreatex.out.file.fnum;
1359 CHECK_ACCESS_FLAGS(fnum2, SEC_FILE_WRITE_DATA | SEC_FILE_READ_ATTRIBUTE);
1360 smbcli_close(cli->tree, fnum2);
1362 smbcli_unlink(cli->tree, fname1);
1363 smbcli_rmdir(cli->tree, dname);
1366 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
1367 set.set_secdesc.in.file.fnum = fnum;
1368 set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
1369 set.set_secdesc.in.sd = sd_orig;
1370 status = smb_raw_setfileinfo(cli->tree, &set);
1372 smbcli_close(cli->tree, fnum);
1378 test dynamic acl inheritance
1380 static BOOL test_inheritance_dynamic(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1384 const char *dname = BASEDIR "\\inheritance";
1385 const char *fname1 = BASEDIR "\\inheritance\\testfile";
1388 union smb_fileinfo q;
1389 union smb_setfileinfo set;
1390 struct security_descriptor *sd, *sd_orig;
1391 const char *owner_sid;
1393 printf("TESTING DYNAMIC ACL INHERITANCE\n");
1395 if (!torture_setup_dir(cli, BASEDIR)) {
1399 io.generic.level = RAW_OPEN_NTCREATEX;
1400 io.ntcreatex.in.root_fid = 0;
1401 io.ntcreatex.in.flags = 0;
1402 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1403 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1404 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
1405 io.ntcreatex.in.share_access = 0;
1406 io.ntcreatex.in.alloc_size = 0;
1407 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1408 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1409 io.ntcreatex.in.security_flags = 0;
1410 io.ntcreatex.in.fname = dname;
1412 status = smb_raw_open(cli->tree, mem_ctx, &io);
1413 CHECK_STATUS(status, NT_STATUS_OK);
1414 fnum = io.ntcreatex.out.file.fnum;
1416 printf("get the original sd\n");
1417 q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
1418 q.query_secdesc.in.file.fnum = fnum;
1419 q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
1420 status = smb_raw_fileinfo(cli->tree, mem_ctx, &q);
1421 CHECK_STATUS(status, NT_STATUS_OK);
1422 sd_orig = q.query_secdesc.out.sd;
1424 owner_sid = dom_sid_string(mem_ctx, sd_orig->owner_sid);
1426 printf("owner_sid is %s\n", owner_sid);
1428 sd = security_descriptor_create(mem_ctx,
1431 SEC_ACE_TYPE_ACCESS_ALLOWED,
1432 SEC_FILE_WRITE_DATA | SEC_STD_DELETE | SEC_FILE_READ_ATTRIBUTE,
1433 SEC_ACE_FLAG_OBJECT_INHERIT,
1435 sd->type |= SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_DACL_AUTO_INHERIT_REQ;
1437 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
1438 set.set_secdesc.in.file.fnum = fnum;
1439 set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
1440 set.set_secdesc.in.sd = sd;
1441 status = smb_raw_setfileinfo(cli->tree, &set);
1442 CHECK_STATUS(status, NT_STATUS_OK);
1444 printf("create a file with an inherited acl\n");
1445 io.ntcreatex.in.fname = fname1;
1446 io.ntcreatex.in.create_options = 0;
1447 io.ntcreatex.in.access_mask = SEC_FILE_READ_ATTRIBUTE;
1448 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1449 status = smb_raw_open(cli->tree, mem_ctx, &io);
1450 CHECK_STATUS(status, NT_STATUS_OK);
1451 fnum2 = io.ntcreatex.out.file.fnum;
1452 smbcli_close(cli->tree, fnum2);
1454 printf("try and access file with base rights - should be OK\n");
1455 io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
1456 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1457 status = smb_raw_open(cli->tree, mem_ctx, &io);
1458 CHECK_STATUS(status, NT_STATUS_OK);
1459 fnum2 = io.ntcreatex.out.file.fnum;
1460 smbcli_close(cli->tree, fnum2);
1462 printf("try and access file with extra rights - should be denied\n");
1463 io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA | SEC_FILE_EXECUTE;
1464 status = smb_raw_open(cli->tree, mem_ctx, &io);
1465 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
1467 printf("update parent sd\n");
1468 sd = security_descriptor_create(mem_ctx,
1471 SEC_ACE_TYPE_ACCESS_ALLOWED,
1472 SEC_FILE_WRITE_DATA | SEC_STD_DELETE | SEC_FILE_READ_ATTRIBUTE | SEC_FILE_EXECUTE,
1473 SEC_ACE_FLAG_OBJECT_INHERIT,
1475 sd->type |= SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_DACL_AUTO_INHERIT_REQ;
1477 set.set_secdesc.in.sd = sd;
1478 status = smb_raw_setfileinfo(cli->tree, &set);
1479 CHECK_STATUS(status, NT_STATUS_OK);
1481 printf("try and access file with base rights - should be OK\n");
1482 io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
1483 status = smb_raw_open(cli->tree, mem_ctx, &io);
1484 CHECK_STATUS(status, NT_STATUS_OK);
1485 fnum2 = io.ntcreatex.out.file.fnum;
1486 smbcli_close(cli->tree, fnum2);
1489 printf("try and access now - should be OK if dynamic inheritance works\n");
1490 io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA | SEC_FILE_EXECUTE;
1491 status = smb_raw_open(cli->tree, mem_ctx, &io);
1492 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
1493 printf("Server does not have dynamic inheritance\n");
1495 if (NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
1496 printf("Server does have dynamic inheritance\n");
1498 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
1500 smbcli_unlink(cli->tree, fname1);
1503 printf("put back original sd\n");
1504 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
1505 set.set_secdesc.in.file.fnum = fnum;
1506 set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
1507 set.set_secdesc.in.sd = sd_orig;
1508 status = smb_raw_setfileinfo(cli->tree, &set);
1510 smbcli_close(cli->tree, fnum);
1511 smbcli_rmdir(cli->tree, dname);
1516 #define CHECK_STATUS_FOR_BIT_ACTION(status, bits, action) do { \
1517 if (!(bits & desired_64)) {\
1518 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED); \
1521 CHECK_STATUS(status, NT_STATUS_OK); \
1525 #define CHECK_STATUS_FOR_BIT(status, bits, access) do { \
1526 if (NT_STATUS_IS_OK(status)) { \
1527 if (!(granted & access)) {\
1528 printf("(%s) %s but flags 0x%08X are not granted! granted[0x%08X] desired[0x%08X]\n", \
1529 __location__, nt_errstr(status), access, granted, desired); \
1534 if (granted & access) {\
1535 printf("(%s) %s but flags 0x%08X are granted! granted[0x%08X] desired[0x%08X]\n", \
1536 __location__, nt_errstr(status), access, granted, desired); \
1541 CHECK_STATUS_FOR_BIT_ACTION(status, bits, do {} while (0)); \
1544 /* test what access mask is needed for getting and setting security_descriptors */
1545 static BOOL test_sd_get_set(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1550 union smb_fileinfo fi;
1551 union smb_setfileinfo si;
1552 struct security_descriptor *sd;
1553 struct security_descriptor *sd_owner = NULL;
1554 struct security_descriptor *sd_group = NULL;
1555 struct security_descriptor *sd_dacl = NULL;
1556 struct security_descriptor *sd_sacl = NULL;
1558 const char *fname = BASEDIR "\\sd_get_set.txt";
1559 uint64_t desired_64;
1560 uint32_t desired = 0, granted;
1562 #define NO_BITS_HACK (((uint64_t)1)<<32)
1563 uint64_t open_bits =
1565 SEC_FLAG_SYSTEM_SECURITY |
1566 SEC_FLAG_MAXIMUM_ALLOWED |
1570 uint64_t get_owner_bits = SEC_MASK_GENERIC | SEC_FLAG_MAXIMUM_ALLOWED | SEC_STD_READ_CONTROL;
1571 uint64_t set_owner_bits = SEC_GENERIC_ALL | SEC_FLAG_MAXIMUM_ALLOWED | SEC_STD_WRITE_OWNER;
1572 uint64_t get_group_bits = SEC_MASK_GENERIC | SEC_FLAG_MAXIMUM_ALLOWED | SEC_STD_READ_CONTROL;
1573 uint64_t set_group_bits = SEC_GENERIC_ALL | SEC_FLAG_MAXIMUM_ALLOWED | SEC_STD_WRITE_OWNER;
1574 uint64_t get_dacl_bits = SEC_MASK_GENERIC | SEC_FLAG_MAXIMUM_ALLOWED | SEC_STD_READ_CONTROL;
1575 uint64_t set_dacl_bits = SEC_GENERIC_ALL | SEC_FLAG_MAXIMUM_ALLOWED | SEC_STD_WRITE_DAC;
1576 uint64_t get_sacl_bits = SEC_FLAG_SYSTEM_SECURITY;
1577 uint64_t set_sacl_bits = SEC_FLAG_SYSTEM_SECURITY;
1579 printf("TESTING ACCESS MASKS FOR SD GET/SET\n");
1581 /* first create a file with full access for everyone */
1582 sd = security_descriptor_create(mem_ctx,
1583 SID_NT_ANONYMOUS, SID_BUILTIN_USERS,
1585 SEC_ACE_TYPE_ACCESS_ALLOWED,
1589 sd->type |= SEC_DESC_SACL_PRESENT;
1591 io.ntcreatex.level = RAW_OPEN_NTTRANS_CREATE;
1592 io.ntcreatex.in.root_fid = 0;
1593 io.ntcreatex.in.flags = 0;
1594 io.ntcreatex.in.access_mask = SEC_GENERIC_ALL;
1595 io.ntcreatex.in.create_options = 0;
1596 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1597 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1598 io.ntcreatex.in.alloc_size = 0;
1599 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
1600 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1601 io.ntcreatex.in.security_flags = 0;
1602 io.ntcreatex.in.fname = fname;
1603 io.ntcreatex.in.sec_desc = sd;
1604 io.ntcreatex.in.ea_list = NULL;
1605 status = smb_raw_open(cli->tree, mem_ctx, &io);
1606 CHECK_STATUS(status, NT_STATUS_OK);
1607 fnum = io.ntcreatex.out.file.fnum;
1609 status = smbcli_close(cli->tree, fnum);
1610 CHECK_STATUS(status, NT_STATUS_OK);
1613 * now try each access_mask bit and no bit at all in a loop
1614 * and see what's allowed
1615 * NOTE: if i == 32 it means access_mask = 0 (see NO_BITS_HACK above)
1617 for (i=0; i <= 32; i++) {
1618 desired_64 = ((uint64_t)1) << i;
1619 desired = (uint32_t)desired_64;
1621 /* first open the file with the desired access */
1622 io.ntcreatex.level = RAW_OPEN_NTCREATEX;
1623 io.ntcreatex.in.access_mask = desired;
1624 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1625 status = smb_raw_open(cli->tree, mem_ctx, &io);
1626 CHECK_STATUS_FOR_BIT_ACTION(status, open_bits, goto next);
1627 fnum = io.ntcreatex.out.file.fnum;
1629 /* then check what access was granted */
1630 fi.access_information.level = RAW_FILEINFO_ACCESS_INFORMATION;
1631 fi.access_information.in.file.fnum = fnum;
1632 status = smb_raw_fileinfo(cli->tree, mem_ctx, &fi);
1633 CHECK_STATUS(status, NT_STATUS_OK);
1634 granted = fi.access_information.out.access_flags;
1636 /* test the owner */
1638 fi.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
1639 fi.query_secdesc.in.file.fnum = fnum;
1640 fi.query_secdesc.in.secinfo_flags = SECINFO_OWNER;
1641 status = smb_raw_fileinfo(cli->tree, mem_ctx, &fi);
1642 CHECK_STATUS_FOR_BIT(status, get_owner_bits, SEC_STD_READ_CONTROL);
1643 if (fi.query_secdesc.out.sd) {
1644 sd_owner = fi.query_secdesc.out.sd;
1645 } else if (!sd_owner) {
1648 si.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
1649 si.set_secdesc.in.file.fnum = fnum;
1650 si.set_secdesc.in.secinfo_flags = SECINFO_OWNER;
1651 si.set_secdesc.in.sd = sd_owner;
1652 status = smb_raw_setfileinfo(cli->tree, &si);
1653 CHECK_STATUS_FOR_BIT(status, set_owner_bits, SEC_STD_WRITE_OWNER);
1655 /* test the group */
1657 fi.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
1658 fi.query_secdesc.in.file.fnum = fnum;
1659 fi.query_secdesc.in.secinfo_flags = SECINFO_GROUP;
1660 status = smb_raw_fileinfo(cli->tree, mem_ctx, &fi);
1661 CHECK_STATUS_FOR_BIT(status, get_group_bits, SEC_STD_READ_CONTROL);
1662 if (fi.query_secdesc.out.sd) {
1663 sd_group = fi.query_secdesc.out.sd;
1664 } else if (!sd_group) {
1667 si.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
1668 si.set_secdesc.in.file.fnum = fnum;
1669 si.set_secdesc.in.secinfo_flags = SECINFO_GROUP;
1670 si.set_secdesc.in.sd = sd_group;
1671 status = smb_raw_setfileinfo(cli->tree, &si);
1672 CHECK_STATUS_FOR_BIT(status, set_group_bits, SEC_STD_WRITE_OWNER);
1676 fi.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
1677 fi.query_secdesc.in.file.fnum = fnum;
1678 fi.query_secdesc.in.secinfo_flags = SECINFO_DACL;
1679 status = smb_raw_fileinfo(cli->tree, mem_ctx, &fi);
1680 CHECK_STATUS_FOR_BIT(status, get_dacl_bits, SEC_STD_READ_CONTROL);
1681 if (fi.query_secdesc.out.sd) {
1682 sd_dacl = fi.query_secdesc.out.sd;
1683 } else if (!sd_dacl) {
1686 si.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
1687 si.set_secdesc.in.file.fnum = fnum;
1688 si.set_secdesc.in.secinfo_flags = SECINFO_DACL;
1689 si.set_secdesc.in.sd = sd_dacl;
1690 status = smb_raw_setfileinfo(cli->tree, &si);
1691 CHECK_STATUS_FOR_BIT(status, set_dacl_bits, SEC_STD_WRITE_DAC);
1695 fi.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
1696 fi.query_secdesc.in.file.fnum = fnum;
1697 fi.query_secdesc.in.secinfo_flags = SECINFO_SACL;
1698 status = smb_raw_fileinfo(cli->tree, mem_ctx, &fi);
1699 CHECK_STATUS_FOR_BIT(status, get_sacl_bits, SEC_FLAG_SYSTEM_SECURITY);
1700 if (fi.query_secdesc.out.sd) {
1701 sd_sacl = fi.query_secdesc.out.sd;
1702 } else if (!sd_sacl) {
1705 si.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
1706 si.set_secdesc.in.file.fnum = fnum;
1707 si.set_secdesc.in.secinfo_flags = SECINFO_SACL;
1708 si.set_secdesc.in.sd = sd_sacl;
1709 status = smb_raw_setfileinfo(cli->tree, &si);
1710 CHECK_STATUS_FOR_BIT(status, set_sacl_bits, SEC_FLAG_SYSTEM_SECURITY);
1712 /* close the handle */
1713 status = smbcli_close(cli->tree, fnum);
1714 CHECK_STATUS(status, NT_STATUS_OK);
1720 smbcli_close(cli->tree, fnum);
1721 smbcli_unlink(cli->tree, fname);
1728 basic testing of security descriptor calls
1730 BOOL torture_raw_acls(struct torture_context *torture)
1732 struct smbcli_state *cli;
1734 TALLOC_CTX *mem_ctx;
1736 if (!torture_open_connection(&cli, 0)) {
1740 mem_ctx = talloc_init("torture_raw_acls");
1742 if (!torture_setup_dir(cli, BASEDIR)) {
1746 ret &= test_sd(cli, mem_ctx);
1747 ret &= test_nttrans_create(cli, mem_ctx);
1748 ret &= test_creator_sid(cli, mem_ctx);
1749 ret &= test_generic_bits(cli, mem_ctx);
1750 ret &= test_owner_bits(cli, mem_ctx);
1751 ret &= test_inheritance(cli, mem_ctx);
1752 ret &= test_inheritance_dynamic(cli, mem_ctx);
1753 ret &= test_sd_get_set(cli, mem_ctx);
1755 smb_raw_exit(cli->session);
1756 smbcli_deltree(cli->tree, BASEDIR);
1758 torture_close_connection(cli);
1759 talloc_free(mem_ctx);