s3: smbd - smb1 - fix read of deleted memory in reply_writeclose().
[Samba.git] / source3 / utils / smbcacls.c
blob11b7388303cd7acacf7bb3e9b7d3dc8fa967d925
1 /*
2 Unix SMB/CIFS implementation.
3 ACL get/set utility
5 Copyright (C) Andrew Tridgell 2000
6 Copyright (C) Tim Potter 2000
7 Copyright (C) Jeremy Allison 2000
8 Copyright (C) Jelmer Vernooij 2003
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "popt_common.h"
26 #include "rpc_client/cli_pipe.h"
27 #include "../librpc/gen_ndr/ndr_lsa.h"
28 #include "rpc_client/cli_lsarpc.h"
29 #include "../libcli/security/security.h"
30 #include "libsmb/libsmb.h"
31 #include "libsmb/clirap.h"
32 #include "passdb/machine_sid.h"
33 #include "../librpc/gen_ndr/ndr_lsa_c.h"
35 static int test_args;
37 #define CREATE_ACCESS_READ READ_CONTROL_ACCESS
39 /* numeric is set when the user wants numeric SIDs and ACEs rather
40 than going via LSA calls to resolve them */
41 static int numeric;
43 static int sddl;
44 static int query_sec_info = -1;
45 static int set_sec_info = -1;
47 static const char *domain_sid = NULL;
49 enum acl_mode {SMB_ACL_SET, SMB_ACL_DELETE, SMB_ACL_MODIFY, SMB_ACL_ADD };
50 enum chown_mode {REQUEST_NONE, REQUEST_CHOWN, REQUEST_CHGRP, REQUEST_INHERIT};
51 enum exit_values {EXIT_OK, EXIT_FAILED, EXIT_PARSE_ERROR};
53 struct perm_value {
54 const char *perm;
55 uint32 mask;
58 /* These values discovered by inspection */
60 static const struct perm_value special_values[] = {
61 { "R", 0x00120089 },
62 { "W", 0x00120116 },
63 { "X", 0x001200a0 },
64 { "D", 0x00010000 },
65 { "P", 0x00040000 },
66 { "O", 0x00080000 },
67 { NULL, 0 },
70 static const struct perm_value standard_values[] = {
71 { "READ", 0x001200a9 },
72 { "CHANGE", 0x001301bf },
73 { "FULL", 0x001f01ff },
74 { NULL, 0 },
77 /* Open cli connection and policy handle */
79 static NTSTATUS cli_lsa_lookup_sid(struct cli_state *cli,
80 const struct dom_sid *sid,
81 TALLOC_CTX *mem_ctx,
82 enum lsa_SidType *type,
83 char **domain, char **name)
85 uint16 orig_cnum = cli_state_get_tid(cli);
86 struct rpc_pipe_client *p = NULL;
87 struct policy_handle handle;
88 NTSTATUS status;
89 TALLOC_CTX *frame = talloc_stackframe();
90 enum lsa_SidType *types;
91 char **domains;
92 char **names;
94 status = cli_tree_connect(cli, "IPC$", "?????", "", 0);
95 if (!NT_STATUS_IS_OK(status)) {
96 goto tcon_fail;
99 status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc,
100 &p);
101 if (!NT_STATUS_IS_OK(status)) {
102 goto fail;
105 status = rpccli_lsa_open_policy(p, talloc_tos(), True,
106 GENERIC_EXECUTE_ACCESS, &handle);
107 if (!NT_STATUS_IS_OK(status)) {
108 goto fail;
111 status = rpccli_lsa_lookup_sids(p, talloc_tos(), &handle, 1, sid,
112 &domains, &names, &types);
113 if (!NT_STATUS_IS_OK(status)) {
114 goto fail;
117 *type = types[0];
118 *domain = talloc_move(mem_ctx, &domains[0]);
119 *name = talloc_move(mem_ctx, &names[0]);
121 status = NT_STATUS_OK;
122 fail:
123 TALLOC_FREE(p);
124 cli_tdis(cli);
125 tcon_fail:
126 cli_state_set_tid(cli, orig_cnum);
127 TALLOC_FREE(frame);
128 return status;
131 static NTSTATUS cli_lsa_lookup_name(struct cli_state *cli,
132 const char *name,
133 enum lsa_SidType *type,
134 struct dom_sid *sid)
136 uint16 orig_cnum = cli_state_get_tid(cli);
137 struct rpc_pipe_client *p;
138 struct policy_handle handle;
139 NTSTATUS status;
140 TALLOC_CTX *frame = talloc_stackframe();
141 struct dom_sid *sids;
142 enum lsa_SidType *types;
144 status = cli_tree_connect(cli, "IPC$", "?????", "", 0);
145 if (!NT_STATUS_IS_OK(status)) {
146 goto tcon_fail;
149 status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc,
150 &p);
151 if (!NT_STATUS_IS_OK(status)) {
152 goto fail;
155 status = rpccli_lsa_open_policy(p, talloc_tos(), True,
156 GENERIC_EXECUTE_ACCESS, &handle);
157 if (!NT_STATUS_IS_OK(status)) {
158 goto fail;
161 status = rpccli_lsa_lookup_names(p, talloc_tos(), &handle, 1, &name,
162 NULL, 1, &sids, &types);
163 if (!NT_STATUS_IS_OK(status)) {
164 goto fail;
167 *type = types[0];
168 *sid = sids[0];
170 status = NT_STATUS_OK;
171 fail:
172 TALLOC_FREE(p);
173 cli_tdis(cli);
174 tcon_fail:
175 cli_state_set_tid(cli, orig_cnum);
176 TALLOC_FREE(frame);
177 return status;
181 static NTSTATUS cli_lsa_lookup_domain_sid(struct cli_state *cli,
182 struct dom_sid *sid)
184 union lsa_PolicyInformation *info = NULL;
185 uint16 orig_cnum = cli_state_get_tid(cli);
186 struct rpc_pipe_client *rpc_pipe = NULL;
187 struct policy_handle handle;
188 NTSTATUS status, result;
189 TALLOC_CTX *frame = talloc_stackframe();
191 status = cli_tree_connect(cli, "IPC$", "?????", "", 0);
192 if (!NT_STATUS_IS_OK(status)) {
193 goto done;
196 status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc, &rpc_pipe);
197 if (!NT_STATUS_IS_OK(status)) {
198 goto tdis;
201 status = rpccli_lsa_open_policy(rpc_pipe, frame, True,
202 GENERIC_EXECUTE_ACCESS, &handle);
203 if (!NT_STATUS_IS_OK(status)) {
204 goto tdis;
207 status = dcerpc_lsa_QueryInfoPolicy2(rpc_pipe->binding_handle,
208 frame, &handle,
209 LSA_POLICY_INFO_DOMAIN,
210 &info, &result);
212 if (any_nt_status_not_ok(status, result, &status)) {
213 goto tdis;
216 *sid = *info->domain.sid;
218 tdis:
219 TALLOC_FREE(rpc_pipe);
220 cli_tdis(cli);
221 done:
222 cli_state_set_tid(cli, orig_cnum);
223 TALLOC_FREE(frame);
224 return status;
227 static struct dom_sid *get_domain_sid(struct cli_state *cli)
229 NTSTATUS status;
231 struct dom_sid *sid = talloc(talloc_tos(), struct dom_sid);
232 if (sid == NULL) {
233 DEBUG(0, ("Out of memory\n"));
234 return NULL;
237 if (domain_sid) {
238 if (!dom_sid_parse(domain_sid, sid)) {
239 DEBUG(0,("failed to parse domain sid\n"));
240 TALLOC_FREE(sid);
242 } else {
243 status = cli_lsa_lookup_domain_sid(cli, sid);
245 if (!NT_STATUS_IS_OK(status)) {
246 DEBUG(0,("failed to lookup domain sid: %s\n", nt_errstr(status)));
247 TALLOC_FREE(sid);
252 DEBUG(2,("Domain SID: %s\n", sid_string_dbg(sid)));
253 return sid;
257 /* convert a SID to a string, either numeric or username/group */
258 static void SidToString(struct cli_state *cli, fstring str, const struct dom_sid *sid)
260 char *domain = NULL;
261 char *name = NULL;
262 enum lsa_SidType type;
263 NTSTATUS status;
265 sid_to_fstring(str, sid);
267 if (numeric) {
268 return;
271 status = cli_lsa_lookup_sid(cli, sid, talloc_tos(), &type,
272 &domain, &name);
274 if (!NT_STATUS_IS_OK(status)) {
275 return;
278 if (*domain) {
279 slprintf(str, sizeof(fstring) - 1, "%s%s%s",
280 domain, lp_winbind_separator(), name);
281 } else {
282 fstrcpy(str, name);
286 /* convert a string to a SID, either numeric or username/group */
287 static bool StringToSid(struct cli_state *cli, struct dom_sid *sid, const char *str)
289 enum lsa_SidType type;
291 if (string_to_sid(sid, str)) {
292 return true;
295 return NT_STATUS_IS_OK(cli_lsa_lookup_name(cli, str, &type, sid));
298 static void print_ace_flags(FILE *f, uint8_t flags)
300 char *str = talloc_strdup(NULL, "");
302 if (!str) {
303 goto out;
306 if (flags & SEC_ACE_FLAG_OBJECT_INHERIT) {
307 str = talloc_asprintf(str, "%s%s",
308 str, "OI|");
309 if (!str) {
310 goto out;
313 if (flags & SEC_ACE_FLAG_CONTAINER_INHERIT) {
314 str = talloc_asprintf(str, "%s%s",
315 str, "CI|");
316 if (!str) {
317 goto out;
320 if (flags & SEC_ACE_FLAG_NO_PROPAGATE_INHERIT) {
321 str = talloc_asprintf(str, "%s%s",
322 str, "NP|");
323 if (!str) {
324 goto out;
327 if (flags & SEC_ACE_FLAG_INHERIT_ONLY) {
328 str = talloc_asprintf(str, "%s%s",
329 str, "IO|");
330 if (!str) {
331 goto out;
334 if (flags & SEC_ACE_FLAG_INHERITED_ACE) {
335 str = talloc_asprintf(str, "%s%s",
336 str, "I|");
337 if (!str) {
338 goto out;
341 /* Ignore define SEC_ACE_FLAG_SUCCESSFUL_ACCESS ( 0x40 )
342 and SEC_ACE_FLAG_FAILED_ACCESS ( 0x80 ) as they're
343 audit ace flags. */
345 if (str[strlen(str)-1] == '|') {
346 str[strlen(str)-1] = '\0';
347 fprintf(f, "/%s/", str);
348 } else {
349 fprintf(f, "/0x%x/", flags);
351 TALLOC_FREE(str);
352 return;
354 out:
355 fprintf(f, "/0x%x/", flags);
358 /* print an ACE on a FILE, using either numeric or ascii representation */
359 static void print_ace(struct cli_state *cli, FILE *f, struct security_ace *ace)
361 const struct perm_value *v;
362 fstring sidstr;
363 int do_print = 0;
364 uint32 got_mask;
366 SidToString(cli, sidstr, &ace->trustee);
368 fprintf(f, "%s:", sidstr);
370 if (numeric) {
371 fprintf(f, "%d/0x%x/0x%08x",
372 ace->type, ace->flags, ace->access_mask);
373 return;
376 /* Ace type */
378 if (ace->type == SEC_ACE_TYPE_ACCESS_ALLOWED) {
379 fprintf(f, "ALLOWED");
380 } else if (ace->type == SEC_ACE_TYPE_ACCESS_DENIED) {
381 fprintf(f, "DENIED");
382 } else {
383 fprintf(f, "%d", ace->type);
386 print_ace_flags(f, ace->flags);
388 /* Standard permissions */
390 for (v = standard_values; v->perm; v++) {
391 if (ace->access_mask == v->mask) {
392 fprintf(f, "%s", v->perm);
393 return;
397 /* Special permissions. Print out a hex value if we have
398 leftover bits in the mask. */
400 got_mask = ace->access_mask;
402 again:
403 for (v = special_values; v->perm; v++) {
404 if ((ace->access_mask & v->mask) == v->mask) {
405 if (do_print) {
406 fprintf(f, "%s", v->perm);
408 got_mask &= ~v->mask;
412 if (!do_print) {
413 if (got_mask != 0) {
414 fprintf(f, "0x%08x", ace->access_mask);
415 } else {
416 do_print = 1;
417 goto again;
422 static bool parse_ace_flags(const char *str, unsigned int *pflags)
424 const char *p = str;
425 *pflags = 0;
427 while (*p) {
428 if (strnequal(p, "OI", 2)) {
429 *pflags |= SEC_ACE_FLAG_OBJECT_INHERIT;
430 p += 2;
431 } else if (strnequal(p, "CI", 2)) {
432 *pflags |= SEC_ACE_FLAG_CONTAINER_INHERIT;
433 p += 2;
434 } else if (strnequal(p, "NP", 2)) {
435 *pflags |= SEC_ACE_FLAG_NO_PROPAGATE_INHERIT;
436 p += 2;
437 } else if (strnequal(p, "IO", 2)) {
438 *pflags |= SEC_ACE_FLAG_INHERIT_ONLY;
439 p += 2;
440 } else if (*p == 'I') {
441 *pflags |= SEC_ACE_FLAG_INHERITED_ACE;
442 p += 1;
443 } else if (*p) {
444 return false;
447 switch (*p) {
448 case '|':
449 p++;
450 case '\0':
451 continue;
452 default:
453 return false;
456 return true;
459 /* parse an ACE in the same format as print_ace() */
460 static bool parse_ace(struct cli_state *cli, struct security_ace *ace,
461 const char *orig_str)
463 char *p;
464 const char *cp;
465 char *tok;
466 unsigned int atype = 0;
467 unsigned int aflags = 0;
468 unsigned int amask = 0;
469 struct dom_sid sid;
470 uint32_t mask;
471 const struct perm_value *v;
472 char *str = SMB_STRDUP(orig_str);
473 TALLOC_CTX *frame = talloc_stackframe();
475 if (!str) {
476 TALLOC_FREE(frame);
477 return False;
480 ZERO_STRUCTP(ace);
481 p = strchr_m(str,':');
482 if (!p) {
483 printf("ACE '%s': missing ':'.\n", orig_str);
484 SAFE_FREE(str);
485 TALLOC_FREE(frame);
486 return False;
488 *p = '\0';
489 p++;
490 /* Try to parse numeric form */
492 if (sscanf(p, "%u/%u/%u", &atype, &aflags, &amask) == 3 &&
493 StringToSid(cli, &sid, str)) {
494 goto done;
497 /* Try to parse text form */
499 if (!StringToSid(cli, &sid, str)) {
500 printf("ACE '%s': failed to convert '%s' to SID\n",
501 orig_str, str);
502 SAFE_FREE(str);
503 TALLOC_FREE(frame);
504 return False;
507 cp = p;
508 if (!next_token_talloc(frame, &cp, &tok, "/")) {
509 printf("ACE '%s': failed to find '/' character.\n",
510 orig_str);
511 SAFE_FREE(str);
512 TALLOC_FREE(frame);
513 return False;
516 if (strncmp(tok, "ALLOWED", strlen("ALLOWED")) == 0) {
517 atype = SEC_ACE_TYPE_ACCESS_ALLOWED;
518 } else if (strncmp(tok, "DENIED", strlen("DENIED")) == 0) {
519 atype = SEC_ACE_TYPE_ACCESS_DENIED;
520 } else {
521 printf("ACE '%s': missing 'ALLOWED' or 'DENIED' entry at '%s'\n",
522 orig_str, tok);
523 SAFE_FREE(str);
524 TALLOC_FREE(frame);
525 return False;
528 /* Only numeric form accepted for flags at present */
530 if (!next_token_talloc(frame, &cp, &tok, "/")) {
531 printf("ACE '%s': bad flags entry at '%s'\n",
532 orig_str, tok);
533 SAFE_FREE(str);
534 TALLOC_FREE(frame);
535 return False;
538 if (tok[0] < '0' || tok[0] > '9') {
539 if (!parse_ace_flags(tok, &aflags)) {
540 printf("ACE '%s': bad named flags entry at '%s'\n",
541 orig_str, tok);
542 SAFE_FREE(str);
543 TALLOC_FREE(frame);
544 return False;
546 } else if (strnequal(tok, "0x", 2)) {
547 if (!sscanf(tok, "%x", &aflags)) {
548 printf("ACE '%s': bad hex flags entry at '%s'\n",
549 orig_str, tok);
550 SAFE_FREE(str);
551 TALLOC_FREE(frame);
552 return False;
554 } else {
555 if (!sscanf(tok, "%u", &aflags)) {
556 printf("ACE '%s': bad integer flags entry at '%s'\n",
557 orig_str, tok);
558 SAFE_FREE(str);
559 TALLOC_FREE(frame);
560 return False;
564 if (!next_token_talloc(frame, &cp, &tok, "/")) {
565 printf("ACE '%s': missing / at '%s'\n",
566 orig_str, tok);
567 SAFE_FREE(str);
568 TALLOC_FREE(frame);
569 return False;
572 if (strncmp(tok, "0x", 2) == 0) {
573 if (sscanf(tok, "%u", &amask) != 1) {
574 printf("ACE '%s': bad hex number at '%s'\n",
575 orig_str, tok);
576 SAFE_FREE(str);
577 TALLOC_FREE(frame);
578 return False;
580 goto done;
583 for (v = standard_values; v->perm; v++) {
584 if (strcmp(tok, v->perm) == 0) {
585 amask = v->mask;
586 goto done;
590 p = tok;
592 while(*p) {
593 bool found = False;
595 for (v = special_values; v->perm; v++) {
596 if (v->perm[0] == *p) {
597 amask |= v->mask;
598 found = True;
602 if (!found) {
603 printf("ACE '%s': bad permission value at '%s'\n",
604 orig_str, p);
605 SAFE_FREE(str);
606 TALLOC_FREE(frame);
607 return False;
609 p++;
612 if (*p) {
613 TALLOC_FREE(frame);
614 SAFE_FREE(str);
615 return False;
618 done:
619 mask = amask;
620 init_sec_ace(ace, &sid, atype, mask, aflags);
621 TALLOC_FREE(frame);
622 SAFE_FREE(str);
623 return True;
626 /* add an ACE to a list of ACEs in a struct security_acl */
627 static bool add_ace(struct security_acl **the_acl, struct security_ace *ace)
629 struct security_acl *new_ace;
630 struct security_ace *aces;
631 if (! *the_acl) {
632 return (((*the_acl) = make_sec_acl(talloc_tos(), 3, 1, ace))
633 != NULL);
636 if (!(aces = SMB_CALLOC_ARRAY(struct security_ace, 1+(*the_acl)->num_aces))) {
637 return False;
639 memcpy(aces, (*the_acl)->aces, (*the_acl)->num_aces * sizeof(struct
640 security_ace));
641 memcpy(aces+(*the_acl)->num_aces, ace, sizeof(struct security_ace));
642 new_ace = make_sec_acl(talloc_tos(),(*the_acl)->revision,1+(*the_acl)->num_aces, aces);
643 SAFE_FREE(aces);
644 (*the_acl) = new_ace;
645 return True;
648 /* parse a ascii version of a security descriptor */
649 static struct security_descriptor *sec_desc_parse(TALLOC_CTX *ctx, struct cli_state *cli, char *str)
651 const char *p = str;
652 char *tok;
653 struct security_descriptor *ret = NULL;
654 size_t sd_size;
655 struct dom_sid *grp_sid=NULL, *owner_sid=NULL;
656 struct security_acl *dacl=NULL;
657 int revision=1;
659 while (next_token_talloc(ctx, &p, &tok, "\t,\r\n")) {
660 if (strncmp(tok,"REVISION:", 9) == 0) {
661 revision = strtol(tok+9, NULL, 16);
662 continue;
665 if (strncmp(tok,"OWNER:", 6) == 0) {
666 if (owner_sid) {
667 printf("Only specify owner once\n");
668 goto done;
670 owner_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1);
671 if (!owner_sid ||
672 !StringToSid(cli, owner_sid, tok+6)) {
673 printf("Failed to parse owner sid\n");
674 goto done;
676 continue;
679 if (strncmp(tok,"GROUP:", 6) == 0) {
680 if (grp_sid) {
681 printf("Only specify group once\n");
682 goto done;
684 grp_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1);
685 if (!grp_sid ||
686 !StringToSid(cli, grp_sid, tok+6)) {
687 printf("Failed to parse group sid\n");
688 goto done;
690 continue;
693 if (strncmp(tok,"ACL:", 4) == 0) {
694 struct security_ace ace;
695 if (!parse_ace(cli, &ace, tok+4)) {
696 goto done;
698 if(!add_ace(&dacl, &ace)) {
699 printf("Failed to add ACL %s\n", tok);
700 goto done;
702 continue;
705 printf("Failed to parse token '%s' in security descriptor,\n", tok);
706 goto done;
709 ret = make_sec_desc(ctx,revision, SEC_DESC_SELF_RELATIVE, owner_sid, grp_sid,
710 NULL, dacl, &sd_size);
712 done:
713 SAFE_FREE(grp_sid);
714 SAFE_FREE(owner_sid);
716 return ret;
719 static const struct {
720 uint16_t mask;
721 const char *str;
722 const char *desc;
723 } sec_desc_ctrl_bits[] = {
724 {SEC_DESC_OWNER_DEFAULTED, "OD", "Owner Defaulted"},
725 {SEC_DESC_GROUP_DEFAULTED, "GD", "Group Defaulted"},
726 {SEC_DESC_DACL_PRESENT, "DP", "DACL Present"},
727 {SEC_DESC_DACL_DEFAULTED, "DD", "DACL Defaulted"},
728 {SEC_DESC_SACL_PRESENT, "SP", "SACL Present"},
729 {SEC_DESC_SACL_DEFAULTED, "SD", "SACL Defaulted"},
730 {SEC_DESC_DACL_TRUSTED, "DT", "DACL Trusted"},
731 {SEC_DESC_SERVER_SECURITY, "SS", "Server Security"},
732 {SEC_DESC_DACL_AUTO_INHERIT_REQ, "DR", "DACL Inheritance Required"},
733 {SEC_DESC_SACL_AUTO_INHERIT_REQ, "SR", "SACL Inheritance Required"},
734 {SEC_DESC_DACL_AUTO_INHERITED, "DI", "DACL Auto Inherited"},
735 {SEC_DESC_SACL_AUTO_INHERITED, "SI", "SACL Auto Inherited"},
736 {SEC_DESC_DACL_PROTECTED, "PD", "DACL Protected"},
737 {SEC_DESC_SACL_PROTECTED, "PS", "SACL Protected"},
738 {SEC_DESC_RM_CONTROL_VALID, "RM", "RM Control Valid"},
739 {SEC_DESC_SELF_RELATIVE , "SR", "Self Relative"},
742 static void print_acl_ctrl(FILE *file, uint16_t ctrl)
744 int i;
745 const char* separator = "";
747 fprintf(file, "CONTROL:");
748 if (numeric) {
749 fprintf(file, "0x%x\n", ctrl);
750 return;
753 for (i = ARRAY_SIZE(sec_desc_ctrl_bits) - 1; i >= 0; i--) {
754 if (ctrl & sec_desc_ctrl_bits[i].mask) {
755 fprintf(file, "%s%s", separator, sec_desc_ctrl_bits[i].str);
756 separator = "|";
759 fputc('\n', file);
762 /* print a ascii version of a security descriptor on a FILE handle */
763 static void sec_desc_print(struct cli_state *cli, FILE *f, struct security_descriptor *sd)
765 fstring sidstr;
766 uint32 i;
768 fprintf(f, "REVISION:%d\n", sd->revision);
769 print_acl_ctrl(f, sd->type);
771 /* Print owner and group sid */
773 if (sd->owner_sid) {
774 SidToString(cli, sidstr, sd->owner_sid);
775 } else {
776 fstrcpy(sidstr, "");
779 fprintf(f, "OWNER:%s\n", sidstr);
781 if (sd->group_sid) {
782 SidToString(cli, sidstr, sd->group_sid);
783 } else {
784 fstrcpy(sidstr, "");
787 fprintf(f, "GROUP:%s\n", sidstr);
789 /* Print aces */
790 for (i = 0; sd->dacl && i < sd->dacl->num_aces; i++) {
791 struct security_ace *ace = &sd->dacl->aces[i];
792 fprintf(f, "ACL:");
793 print_ace(cli, f, ace);
794 fprintf(f, "\n");
799 /*****************************************************
800 get fileinfo for filename
801 *******************************************************/
802 static uint16 get_fileinfo(struct cli_state *cli, const char *filename)
804 uint16_t fnum = (uint16_t)-1;
805 uint16 mode = 0;
806 NTSTATUS status;
808 /* The desired access below is the only one I could find that works
809 with NT4, W2KP and Samba */
811 status = cli_ntcreate(cli, filename, 0, CREATE_ACCESS_READ,
812 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
813 FILE_OPEN, 0x0, 0x0, &fnum);
814 if (!NT_STATUS_IS_OK(status)) {
815 printf("Failed to open %s: %s\n", filename, nt_errstr(status));
816 return 0;
819 status = cli_qfileinfo_basic(cli, fnum, &mode, NULL, NULL, NULL,
820 NULL, NULL, NULL);
821 if (!NT_STATUS_IS_OK(status)) {
822 printf("Failed to file info %s: %s\n", filename,
823 nt_errstr(status));
826 cli_close(cli, fnum);
828 return mode;
831 /*****************************************************
832 get sec desc for filename
833 *******************************************************/
834 static struct security_descriptor *get_secdesc(struct cli_state *cli, const char *filename)
836 uint16_t fnum = (uint16_t)-1;
837 struct security_descriptor *sd;
838 NTSTATUS status;
839 uint32_t sec_info;
840 uint32_t desired_access = 0;
842 if (query_sec_info == -1) {
843 sec_info = SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL;
844 } else {
845 sec_info = query_sec_info;
848 if (sec_info & (SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL)) {
849 desired_access |= SEC_STD_READ_CONTROL;
851 if (sec_info & SECINFO_SACL) {
852 desired_access |= SEC_FLAG_SYSTEM_SECURITY;
855 if (desired_access == 0) {
856 desired_access |= SEC_STD_READ_CONTROL;
859 status = cli_ntcreate(cli, filename, 0, desired_access,
860 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
861 FILE_OPEN, 0x0, 0x0, &fnum);
862 if (!NT_STATUS_IS_OK(status)) {
863 printf("Failed to open %s: %s\n", filename, nt_errstr(status));
864 return NULL;
867 status = cli_query_security_descriptor(cli, fnum, sec_info,
868 talloc_tos(), &sd);
870 cli_close(cli, fnum);
872 if (!NT_STATUS_IS_OK(status)) {
873 printf("Failed to get security descriptor: %s\n",
874 nt_errstr(status));
875 return NULL;
877 return sd;
880 /*****************************************************
881 set sec desc for filename
882 *******************************************************/
883 static bool set_secdesc(struct cli_state *cli, const char *filename,
884 struct security_descriptor *sd)
886 uint16_t fnum = (uint16_t)-1;
887 bool result=true;
888 NTSTATUS status;
889 uint32_t desired_access = 0;
890 uint32_t sec_info;
892 if (set_sec_info == -1) {
893 sec_info = 0;
895 if (sd->dacl || (sd->type & SEC_DESC_DACL_PRESENT)) {
896 sec_info |= SECINFO_DACL;
898 if (sd->sacl || (sd->type & SEC_DESC_SACL_PRESENT)) {
899 sec_info |= SECINFO_SACL;
901 if (sd->owner_sid) {
902 sec_info |= SECINFO_OWNER;
904 if (sd->group_sid) {
905 sec_info |= SECINFO_GROUP;
907 } else {
908 sec_info = set_sec_info;
911 /* Make the desired_access more specific. */
912 if (sec_info & SECINFO_DACL) {
913 desired_access |= SEC_STD_WRITE_DAC;
915 if (sec_info & SECINFO_SACL) {
916 desired_access |= SEC_FLAG_SYSTEM_SECURITY;
918 if (sec_info & (SECINFO_OWNER | SECINFO_GROUP)) {
919 desired_access |= SEC_STD_WRITE_OWNER;
922 status = cli_ntcreate(cli, filename, 0,
923 desired_access,
924 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
925 FILE_OPEN, 0x0, 0x0, &fnum);
926 if (!NT_STATUS_IS_OK(status)) {
927 printf("Failed to open %s: %s\n", filename, nt_errstr(status));
928 return false;
931 status = cli_set_security_descriptor(cli, fnum, sec_info, sd);
932 if (!NT_STATUS_IS_OK(status)) {
933 printf("ERROR: security description set failed: %s\n",
934 nt_errstr(status));
935 result=false;
938 cli_close(cli, fnum);
939 return result;
942 /*****************************************************
943 dump the acls for a file
944 *******************************************************/
945 static int cacl_dump(struct cli_state *cli, const char *filename)
947 struct security_descriptor *sd;
949 if (test_args) {
950 return EXIT_OK;
953 sd = get_secdesc(cli, filename);
954 if (sd == NULL) {
955 return EXIT_FAILED;
958 if (sddl) {
959 char *str = sddl_encode(talloc_tos(), sd, get_domain_sid(cli));
960 if (str == NULL) {
961 return EXIT_FAILED;
963 printf("%s\n", str);
964 TALLOC_FREE(str);
965 } else {
966 sec_desc_print(cli, stdout, sd);
969 return EXIT_OK;
972 /*****************************************************
973 Change the ownership or group ownership of a file. Just
974 because the NT docs say this can't be done :-). JRA.
975 *******************************************************/
977 static int owner_set(struct cli_state *cli, enum chown_mode change_mode,
978 const char *filename, const char *new_username)
980 struct dom_sid sid;
981 struct security_descriptor *sd, *old;
982 size_t sd_size;
984 if (!StringToSid(cli, &sid, new_username))
985 return EXIT_PARSE_ERROR;
987 old = get_secdesc(cli, filename);
989 if (!old) {
990 return EXIT_FAILED;
993 sd = make_sec_desc(talloc_tos(),old->revision, old->type,
994 (change_mode == REQUEST_CHOWN) ? &sid : NULL,
995 (change_mode == REQUEST_CHGRP) ? &sid : NULL,
996 NULL, NULL, &sd_size);
998 if (!set_secdesc(cli, filename, sd)) {
999 return EXIT_FAILED;
1002 return EXIT_OK;
1006 /* The MSDN is contradictory over the ordering of ACE entries in an
1007 ACL. However NT4 gives a "The information may have been modified
1008 by a computer running Windows NT 5.0" if denied ACEs do not appear
1009 before allowed ACEs. At
1010 http://technet.microsoft.com/en-us/library/cc781716.aspx the
1011 canonical order is specified as "Explicit Deny, Explicit Allow,
1012 Inherited ACEs unchanged" */
1014 static int ace_compare(struct security_ace *ace1, struct security_ace *ace2)
1016 if (sec_ace_equal(ace1, ace2))
1017 return 0;
1019 if ((ace1->flags & SEC_ACE_FLAG_INHERITED_ACE) &&
1020 !(ace2->flags & SEC_ACE_FLAG_INHERITED_ACE))
1021 return 1;
1022 if (!(ace1->flags & SEC_ACE_FLAG_INHERITED_ACE) &&
1023 (ace2->flags & SEC_ACE_FLAG_INHERITED_ACE))
1024 return -1;
1025 if ((ace1->flags & SEC_ACE_FLAG_INHERITED_ACE) &&
1026 (ace2->flags & SEC_ACE_FLAG_INHERITED_ACE))
1027 return ace1 - ace2;
1029 if (ace1->type != ace2->type)
1030 return ace2->type - ace1->type;
1032 if (dom_sid_compare(&ace1->trustee, &ace2->trustee))
1033 return dom_sid_compare(&ace1->trustee, &ace2->trustee);
1035 if (ace1->flags != ace2->flags)
1036 return ace1->flags - ace2->flags;
1038 if (ace1->access_mask != ace2->access_mask)
1039 return ace1->access_mask - ace2->access_mask;
1041 if (ace1->size != ace2->size)
1042 return ace1->size - ace2->size;
1044 return memcmp(ace1, ace2, sizeof(struct security_ace));
1047 static void sort_acl(struct security_acl *the_acl)
1049 uint32 i;
1050 if (!the_acl) return;
1052 TYPESAFE_QSORT(the_acl->aces, the_acl->num_aces, ace_compare);
1054 for (i=1;i<the_acl->num_aces;) {
1055 if (sec_ace_equal(&the_acl->aces[i-1], &the_acl->aces[i])) {
1056 int j;
1057 for (j=i; j<the_acl->num_aces-1; j++) {
1058 the_acl->aces[j] = the_acl->aces[j+1];
1060 the_acl->num_aces--;
1061 } else {
1062 i++;
1067 /*****************************************************
1068 set the ACLs on a file given an ascii description
1069 *******************************************************/
1071 static int cacl_set(struct cli_state *cli, const char *filename,
1072 char *the_acl, enum acl_mode mode)
1074 struct security_descriptor *sd, *old;
1075 uint32 i, j;
1076 size_t sd_size;
1077 int result = EXIT_OK;
1079 if (sddl) {
1080 sd = sddl_decode(talloc_tos(), the_acl, get_domain_sid(cli));
1081 } else {
1082 sd = sec_desc_parse(talloc_tos(), cli, the_acl);
1085 if (!sd) return EXIT_PARSE_ERROR;
1086 if (test_args) return EXIT_OK;
1088 old = get_secdesc(cli, filename);
1090 if (!old) {
1091 return EXIT_FAILED;
1094 /* the logic here is rather more complex than I would like */
1095 switch (mode) {
1096 case SMB_ACL_DELETE:
1097 for (i=0;sd->dacl && i<sd->dacl->num_aces;i++) {
1098 bool found = False;
1100 for (j=0;old->dacl && j<old->dacl->num_aces;j++) {
1101 if (sec_ace_equal(&sd->dacl->aces[i],
1102 &old->dacl->aces[j])) {
1103 uint32 k;
1104 for (k=j; k<old->dacl->num_aces-1;k++) {
1105 old->dacl->aces[k] = old->dacl->aces[k+1];
1107 old->dacl->num_aces--;
1108 found = True;
1109 break;
1113 if (!found) {
1114 printf("ACL for ACE:");
1115 print_ace(cli, stdout, &sd->dacl->aces[i]);
1116 printf(" not found\n");
1119 break;
1121 case SMB_ACL_MODIFY:
1122 for (i=0;sd->dacl && i<sd->dacl->num_aces;i++) {
1123 bool found = False;
1125 for (j=0;old->dacl && j<old->dacl->num_aces;j++) {
1126 if (dom_sid_equal(&sd->dacl->aces[i].trustee,
1127 &old->dacl->aces[j].trustee)) {
1128 old->dacl->aces[j] = sd->dacl->aces[i];
1129 found = True;
1133 if (!found) {
1134 fstring str;
1136 SidToString(cli, str,
1137 &sd->dacl->aces[i].trustee);
1138 printf("ACL for SID %s not found\n", str);
1142 if (sd->owner_sid) {
1143 old->owner_sid = sd->owner_sid;
1146 if (sd->group_sid) {
1147 old->group_sid = sd->group_sid;
1150 break;
1152 case SMB_ACL_ADD:
1153 for (i=0;sd->dacl && i<sd->dacl->num_aces;i++) {
1154 add_ace(&old->dacl, &sd->dacl->aces[i]);
1156 break;
1158 case SMB_ACL_SET:
1159 old = sd;
1160 break;
1163 /* Denied ACE entries must come before allowed ones */
1164 sort_acl(old->dacl);
1166 /* Create new security descriptor and set it */
1168 /* We used to just have "WRITE_DAC_ACCESS" without WRITE_OWNER.
1169 But if we're sending an owner, even if it's the same as the one
1170 that already exists then W2K3 insists we open with WRITE_OWNER access.
1171 I need to check that setting a SD with no owner set works against WNT
1172 and W2K. JRA.
1175 sd = make_sec_desc(talloc_tos(),old->revision, old->type,
1176 old->owner_sid, old->group_sid,
1177 NULL, old->dacl, &sd_size);
1179 if (!set_secdesc(cli, filename, sd)) {
1180 result = EXIT_FAILED;
1183 return result;
1186 /*****************************************************
1187 set the inherit on a file
1188 *******************************************************/
1189 static int inherit(struct cli_state *cli, const char *filename,
1190 const char *type)
1192 struct security_descriptor *old,*sd;
1193 uint32 oldattr;
1194 size_t sd_size;
1195 int result = EXIT_OK;
1197 old = get_secdesc(cli, filename);
1199 if (!old) {
1200 return EXIT_FAILED;
1203 oldattr = get_fileinfo(cli,filename);
1205 if (strcmp(type,"allow")==0) {
1206 if ((old->type & SEC_DESC_DACL_PROTECTED) ==
1207 SEC_DESC_DACL_PROTECTED) {
1208 int i;
1209 char *parentname,*temp;
1210 struct security_descriptor *parent;
1211 temp = talloc_strdup(talloc_tos(), filename);
1213 old->type=old->type & (~SEC_DESC_DACL_PROTECTED);
1215 /* look at parent and copy in all its inheritable ACL's. */
1216 string_replace(temp, '\\', '/');
1217 if (!parent_dirname(talloc_tos(),temp,&parentname,NULL)) {
1218 return EXIT_FAILED;
1220 string_replace(parentname, '/', '\\');
1221 parent = get_secdesc(cli,parentname);
1222 if (parent == NULL) {
1223 return EXIT_FAILED;
1225 for (i=0;i<parent->dacl->num_aces;i++) {
1226 struct security_ace *ace=&parent->dacl->aces[i];
1227 /* Add inherited flag to all aces */
1228 ace->flags=ace->flags|
1229 SEC_ACE_FLAG_INHERITED_ACE;
1230 if ((oldattr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) {
1231 if ((ace->flags & SEC_ACE_FLAG_CONTAINER_INHERIT) ==
1232 SEC_ACE_FLAG_CONTAINER_INHERIT) {
1233 add_ace(&old->dacl, ace);
1235 } else {
1236 if ((ace->flags & SEC_ACE_FLAG_OBJECT_INHERIT) ==
1237 SEC_ACE_FLAG_OBJECT_INHERIT) {
1238 /* clear flags for files */
1239 ace->flags=0;
1240 add_ace(&old->dacl, ace);
1244 } else {
1245 printf("Already set to inheritable permissions.\n");
1246 return EXIT_FAILED;
1248 } else if (strcmp(type,"remove")==0) {
1249 if ((old->type & SEC_DESC_DACL_PROTECTED) !=
1250 SEC_DESC_DACL_PROTECTED) {
1251 old->type=old->type | SEC_DESC_DACL_PROTECTED;
1253 /* remove all inherited ACL's. */
1254 if (old->dacl) {
1255 int i;
1256 struct security_acl *temp=old->dacl;
1257 old->dacl=make_sec_acl(talloc_tos(), 3, 0, NULL);
1258 for (i=temp->num_aces-1;i>=0;i--) {
1259 struct security_ace *ace=&temp->aces[i];
1260 /* Remove all ace with INHERITED flag set */
1261 if ((ace->flags & SEC_ACE_FLAG_INHERITED_ACE) !=
1262 SEC_ACE_FLAG_INHERITED_ACE) {
1263 add_ace(&old->dacl,ace);
1267 } else {
1268 printf("Already set to no inheritable permissions.\n");
1269 return EXIT_FAILED;
1271 } else if (strcmp(type,"copy")==0) {
1272 if ((old->type & SEC_DESC_DACL_PROTECTED) !=
1273 SEC_DESC_DACL_PROTECTED) {
1274 old->type=old->type | SEC_DESC_DACL_PROTECTED;
1276 /* convert all inherited ACL's to non inherated ACL's. */
1277 if (old->dacl) {
1278 int i;
1279 for (i=0;i<old->dacl->num_aces;i++) {
1280 struct security_ace *ace=&old->dacl->aces[i];
1281 /* Remove INHERITED FLAG from all aces */
1282 ace->flags=ace->flags&(~SEC_ACE_FLAG_INHERITED_ACE);
1285 } else {
1286 printf("Already set to no inheritable permissions.\n");
1287 return EXIT_FAILED;
1291 /* Denied ACE entries must come before allowed ones */
1292 sort_acl(old->dacl);
1294 sd = make_sec_desc(talloc_tos(),old->revision, old->type,
1295 old->owner_sid, old->group_sid,
1296 NULL, old->dacl, &sd_size);
1298 if (!set_secdesc(cli, filename, sd)) {
1299 result = EXIT_FAILED;
1302 return result;
1305 /*****************************************************
1306 Return a connection to a server.
1307 *******************************************************/
1308 static struct cli_state *connect_one(struct user_auth_info *auth_info,
1309 const char *server, const char *share)
1311 struct cli_state *c = NULL;
1312 NTSTATUS nt_status;
1313 uint32_t flags = 0;
1315 if (get_cmdline_auth_info_use_kerberos(auth_info)) {
1316 flags |= CLI_FULL_CONNECTION_USE_KERBEROS |
1317 CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS;
1320 if (get_cmdline_auth_info_use_machine_account(auth_info) &&
1321 !set_cmdline_auth_info_machine_account_creds(auth_info)) {
1322 return NULL;
1325 set_cmdline_auth_info_getpass(auth_info);
1327 nt_status = cli_full_connection(&c, lp_netbios_name(), server,
1328 NULL, 0,
1329 share, "?????",
1330 get_cmdline_auth_info_username(auth_info),
1331 lp_workgroup(),
1332 get_cmdline_auth_info_password(auth_info),
1333 flags,
1334 get_cmdline_auth_info_signing_state(auth_info));
1335 if (!NT_STATUS_IS_OK(nt_status)) {
1336 DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status)));
1337 return NULL;
1340 if (get_cmdline_auth_info_smb_encrypt(auth_info)) {
1341 nt_status = cli_cm_force_encryption(c,
1342 get_cmdline_auth_info_username(auth_info),
1343 get_cmdline_auth_info_password(auth_info),
1344 lp_workgroup(),
1345 share);
1346 if (!NT_STATUS_IS_OK(nt_status)) {
1347 cli_shutdown(c);
1348 c = NULL;
1352 return c;
1355 /****************************************************************************
1356 main program
1357 ****************************************************************************/
1358 int main(int argc, const char *argv[])
1360 char *share;
1361 int opt;
1362 enum acl_mode mode = SMB_ACL_SET;
1363 static char *the_acl = NULL;
1364 enum chown_mode change_mode = REQUEST_NONE;
1365 int result;
1366 char *path;
1367 char *filename = NULL;
1368 poptContext pc;
1369 struct poptOption long_options[] = {
1370 POPT_AUTOHELP
1371 { "delete", 'D', POPT_ARG_STRING, NULL, 'D', "Delete an acl", "ACL" },
1372 { "modify", 'M', POPT_ARG_STRING, NULL, 'M', "Modify an acl", "ACL" },
1373 { "add", 'a', POPT_ARG_STRING, NULL, 'a', "Add an acl", "ACL" },
1374 { "set", 'S', POPT_ARG_STRING, NULL, 'S', "Set acls", "ACLS" },
1375 { "chown", 'C', POPT_ARG_STRING, NULL, 'C', "Change ownership of a file", "USERNAME" },
1376 { "chgrp", 'G', POPT_ARG_STRING, NULL, 'G', "Change group ownership of a file", "GROUPNAME" },
1377 { "inherit", 'I', POPT_ARG_STRING, NULL, 'I', "Inherit allow|remove|copy" },
1378 { "numeric", 0, POPT_ARG_NONE, &numeric, 1, "Don't resolve sids or masks to names" },
1379 { "sddl", 0, POPT_ARG_NONE, &sddl, 1, "Output and input acls in sddl format" },
1380 { "query-security-info", 0, POPT_ARG_INT, &query_sec_info, 1,
1381 "The security-info flags for queries"
1383 { "set-security-info", 0, POPT_ARG_INT, &set_sec_info, 1,
1384 "The security-info flags for modifications"
1386 { "test-args", 't', POPT_ARG_NONE, &test_args, 1, "Test arguments"},
1387 { "domain-sid", 0, POPT_ARG_STRING, &domain_sid, 0, "Domain SID for sddl", "SID"},
1388 { "max-protocol", 'm', POPT_ARG_STRING, NULL, 'm', "Set the max protocol level", "LEVEL" },
1389 POPT_COMMON_SAMBA
1390 POPT_COMMON_CONNECTION
1391 POPT_COMMON_CREDENTIALS
1392 POPT_TABLEEND
1395 struct cli_state *cli;
1396 TALLOC_CTX *frame = talloc_stackframe();
1397 const char *owner_username = "";
1398 char *server;
1399 struct user_auth_info *auth_info;
1401 load_case_tables();
1403 /* set default debug level to 1 regardless of what smb.conf sets */
1404 setup_logging( "smbcacls", DEBUG_STDERR);
1405 lp_set_cmdline("log level", "1");
1407 setlinebuf(stdout);
1409 lp_load_global(get_dyn_CONFIGFILE());
1410 load_interfaces();
1412 auth_info = user_auth_info_init(frame);
1413 if (auth_info == NULL) {
1414 exit(1);
1416 popt_common_set_auth_info(auth_info);
1418 pc = poptGetContext("smbcacls", argc, argv, long_options, 0);
1420 poptSetOtherOptionHelp(pc, "//server1/share1 filename\nACLs look like: "
1421 "'ACL:user:[ALLOWED|DENIED]/flags/permissions'");
1423 while ((opt = poptGetNextOpt(pc)) != -1) {
1424 switch (opt) {
1425 case 'S':
1426 the_acl = smb_xstrdup(poptGetOptArg(pc));
1427 mode = SMB_ACL_SET;
1428 break;
1430 case 'D':
1431 the_acl = smb_xstrdup(poptGetOptArg(pc));
1432 mode = SMB_ACL_DELETE;
1433 break;
1435 case 'M':
1436 the_acl = smb_xstrdup(poptGetOptArg(pc));
1437 mode = SMB_ACL_MODIFY;
1438 break;
1440 case 'a':
1441 the_acl = smb_xstrdup(poptGetOptArg(pc));
1442 mode = SMB_ACL_ADD;
1443 break;
1445 case 'C':
1446 owner_username = poptGetOptArg(pc);
1447 change_mode = REQUEST_CHOWN;
1448 break;
1450 case 'G':
1451 owner_username = poptGetOptArg(pc);
1452 change_mode = REQUEST_CHGRP;
1453 break;
1455 case 'I':
1456 owner_username = poptGetOptArg(pc);
1457 change_mode = REQUEST_INHERIT;
1458 break;
1459 case 'm':
1460 lp_set_cmdline("client max protocol", poptGetOptArg(pc));
1461 break;
1465 /* Make connection to server */
1466 if(!poptPeekArg(pc)) {
1467 poptPrintUsage(pc, stderr, 0);
1468 return -1;
1471 path = talloc_strdup(frame, poptGetArg(pc));
1472 if (!path) {
1473 return -1;
1476 if(!poptPeekArg(pc)) {
1477 poptPrintUsage(pc, stderr, 0);
1478 return -1;
1481 filename = talloc_strdup(frame, poptGetArg(pc));
1482 if (!filename) {
1483 return -1;
1486 poptFreeContext(pc);
1487 popt_burn_cmdline_password(argc, argv);
1489 string_replace(path,'/','\\');
1491 server = talloc_strdup(frame, path+2);
1492 if (!server) {
1493 return -1;
1495 share = strchr_m(server,'\\');
1496 if (!share) {
1497 printf("Invalid argument: %s\n", share);
1498 return -1;
1501 *share = 0;
1502 share++;
1504 if (!test_args) {
1505 cli = connect_one(auth_info, server, share);
1506 if (!cli) {
1507 exit(EXIT_FAILED);
1509 } else {
1510 exit(0);
1513 string_replace(filename, '/', '\\');
1514 if (filename[0] != '\\') {
1515 filename = talloc_asprintf(frame,
1516 "\\%s",
1517 filename);
1518 if (!filename) {
1519 return -1;
1523 /* Perform requested action */
1525 if (change_mode == REQUEST_INHERIT) {
1526 result = inherit(cli, filename, owner_username);
1527 } else if (change_mode != REQUEST_NONE) {
1528 result = owner_set(cli, change_mode, filename, owner_username);
1529 } else if (the_acl) {
1530 result = cacl_set(cli, filename, the_acl, mode);
1531 } else {
1532 result = cacl_dump(cli, filename);
1535 TALLOC_FREE(frame);
1537 return result;