2 Unix SMB/CIFS implementation.
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/>.
25 #include "../librpc/gen_ndr/ndr_lsa.h"
27 extern bool AllowDebugChange
;
31 #define CREATE_ACCESS_READ READ_CONTROL_ACCESS
33 /* numeric is set when the user wants numeric SIDs and ACEs rather
34 than going via LSA calls to resolve them */
39 enum acl_mode
{SMB_ACL_SET
, SMB_ACL_DELETE
, SMB_ACL_MODIFY
, SMB_ACL_ADD
};
40 enum chown_mode
{REQUEST_NONE
, REQUEST_CHOWN
, REQUEST_CHGRP
};
41 enum exit_values
{EXIT_OK
, EXIT_FAILED
, EXIT_PARSE_ERROR
};
48 /* These values discovered by inspection */
50 static const struct perm_value special_values
[] = {
60 static const struct perm_value standard_values
[] = {
61 { "READ", 0x001200a9 },
62 { "CHANGE", 0x001301bf },
63 { "FULL", 0x001f01ff },
67 /* Open cli connection and policy handle */
69 static NTSTATUS
cli_lsa_lookup_sid(struct cli_state
*cli
,
72 enum lsa_SidType
*type
,
73 char **domain
, char **name
)
75 uint16 orig_cnum
= cli
->cnum
;
76 struct rpc_pipe_client
*p
= NULL
;
77 struct policy_handle handle
;
79 TALLOC_CTX
*frame
= talloc_stackframe();
80 enum lsa_SidType
*types
;
84 status
= cli_tcon_andx(cli
, "IPC$", "?????", "", 0);
85 if (!NT_STATUS_IS_OK(status
)) {
89 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
91 if (!NT_STATUS_IS_OK(status
)) {
95 status
= rpccli_lsa_open_policy(p
, talloc_tos(), True
,
96 GENERIC_EXECUTE_ACCESS
, &handle
);
97 if (!NT_STATUS_IS_OK(status
)) {
101 status
= rpccli_lsa_lookup_sids(p
, talloc_tos(), &handle
, 1, sid
,
102 &domains
, &names
, &types
);
103 if (!NT_STATUS_IS_OK(status
)) {
108 *domain
= talloc_move(mem_ctx
, &domains
[0]);
109 *name
= talloc_move(mem_ctx
, &names
[0]);
111 status
= NT_STATUS_OK
;
115 cli
->cnum
= orig_cnum
;
120 static NTSTATUS
cli_lsa_lookup_name(struct cli_state
*cli
,
122 enum lsa_SidType
*type
,
125 uint16 orig_cnum
= cli
->cnum
;
126 struct rpc_pipe_client
*p
;
127 struct policy_handle handle
;
129 TALLOC_CTX
*frame
= talloc_stackframe();
131 enum lsa_SidType
*types
;
133 status
= cli_tcon_andx(cli
, "IPC$", "?????", "", 0);
134 if (!NT_STATUS_IS_OK(status
)) {
138 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
140 if (!NT_STATUS_IS_OK(status
)) {
144 status
= rpccli_lsa_open_policy(p
, talloc_tos(), True
,
145 GENERIC_EXECUTE_ACCESS
, &handle
);
146 if (!NT_STATUS_IS_OK(status
)) {
150 status
= rpccli_lsa_lookup_names(p
, talloc_tos(), &handle
, 1, &name
,
151 NULL
, 1, &sids
, &types
);
152 if (!NT_STATUS_IS_OK(status
)) {
159 status
= NT_STATUS_OK
;
163 cli
->cnum
= orig_cnum
;
168 /* convert a SID to a string, either numeric or username/group */
169 static void SidToString(struct cli_state
*cli
, fstring str
, const DOM_SID
*sid
)
173 enum lsa_SidType type
;
176 sid_to_fstring(str
, sid
);
182 status
= cli_lsa_lookup_sid(cli
, sid
, talloc_tos(), &type
,
185 if (!NT_STATUS_IS_OK(status
)) {
190 slprintf(str
, sizeof(fstring
) - 1, "%s%s%s",
191 domain
, lp_winbind_separator(), name
);
197 /* convert a string to a SID, either numeric or username/group */
198 static bool StringToSid(struct cli_state
*cli
, DOM_SID
*sid
, const char *str
)
200 enum lsa_SidType type
;
202 if (strncmp(str
, "S-", 2) == 0) {
203 return string_to_sid(sid
, str
);
206 return NT_STATUS_IS_OK(cli_lsa_lookup_name(cli
, str
, &type
, sid
));
209 static void print_ace_flags(FILE *f
, uint8_t flags
)
211 char *str
= talloc_strdup(NULL
, "");
217 if (flags
& SEC_ACE_FLAG_OBJECT_INHERIT
) {
218 str
= talloc_asprintf(str
, "%s%s",
224 if (flags
& SEC_ACE_FLAG_CONTAINER_INHERIT
) {
225 str
= talloc_asprintf(str
, "%s%s",
231 if (flags
& SEC_ACE_FLAG_NO_PROPAGATE_INHERIT
) {
232 str
= talloc_asprintf(str
, "%s%s",
238 if (flags
& SEC_ACE_FLAG_INHERIT_ONLY
) {
239 str
= talloc_asprintf(str
, "%s%s",
245 if (flags
& SEC_ACE_FLAG_INHERITED_ACE
) {
246 str
= talloc_asprintf(str
, "%s%s",
252 /* Ignore define SEC_ACE_FLAG_SUCCESSFUL_ACCESS ( 0x40 )
253 and SEC_ACE_FLAG_FAILED_ACCESS ( 0x80 ) as they're
256 if (str
[strlen(str
)-1] == '|') {
257 str
[strlen(str
)-1] = '\0';
258 fprintf(f
, "/%s/", str
);
260 fprintf(f
, "/0x%x/", flags
);
266 fprintf(f
, "/0x%x/", flags
);
269 /* print an ACE on a FILE, using either numeric or ascii representation */
270 static void print_ace(struct cli_state
*cli
, FILE *f
, SEC_ACE
*ace
)
272 const struct perm_value
*v
;
277 SidToString(cli
, sidstr
, &ace
->trustee
);
279 fprintf(f
, "%s:", sidstr
);
282 fprintf(f
, "%d/0x%x/0x%08x",
283 ace
->type
, ace
->flags
, ace
->access_mask
);
289 if (ace
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED
) {
290 fprintf(f
, "ALLOWED");
291 } else if (ace
->type
== SEC_ACE_TYPE_ACCESS_DENIED
) {
292 fprintf(f
, "DENIED");
294 fprintf(f
, "%d", ace
->type
);
297 print_ace_flags(f
, ace
->flags
);
299 /* Standard permissions */
301 for (v
= standard_values
; v
->perm
; v
++) {
302 if (ace
->access_mask
== v
->mask
) {
303 fprintf(f
, "%s", v
->perm
);
308 /* Special permissions. Print out a hex value if we have
309 leftover bits in the mask. */
311 got_mask
= ace
->access_mask
;
314 for (v
= special_values
; v
->perm
; v
++) {
315 if ((ace
->access_mask
& v
->mask
) == v
->mask
) {
317 fprintf(f
, "%s", v
->perm
);
319 got_mask
&= ~v
->mask
;
325 fprintf(f
, "0x%08x", ace
->access_mask
);
333 static bool parse_ace_flags(const char *str
, unsigned int *pflags
)
339 if (strnequal(p
, "OI", 2)) {
340 *pflags
|= SEC_ACE_FLAG_OBJECT_INHERIT
;
342 } else if (strnequal(p
, "CI", 2)) {
343 *pflags
|= SEC_ACE_FLAG_CONTAINER_INHERIT
;
345 } else if (strnequal(p
, "NP", 2)) {
346 *pflags
|= SEC_ACE_FLAG_NO_PROPAGATE_INHERIT
;
348 } else if (strnequal(p
, "IO", 2)) {
349 *pflags
|= SEC_ACE_FLAG_INHERIT_ONLY
;
351 } else if (*p
== 'I') {
352 *pflags
|= SEC_ACE_FLAG_INHERITED_ACE
;
358 if (*p
!= '|' && *p
!= '\0') {
365 /* parse an ACE in the same format as print_ace() */
366 static bool parse_ace(struct cli_state
*cli
, SEC_ACE
*ace
,
367 const char *orig_str
)
372 unsigned int atype
= 0;
373 unsigned int aflags
= 0;
374 unsigned int amask
= 0;
377 const struct perm_value
*v
;
378 char *str
= SMB_STRDUP(orig_str
);
379 TALLOC_CTX
*frame
= talloc_stackframe();
387 p
= strchr_m(str
,':');
389 printf("ACE '%s': missing ':'.\n", orig_str
);
396 /* Try to parse numeric form */
398 if (sscanf(p
, "%i/%i/%i", &atype
, &aflags
, &amask
) == 3 &&
399 StringToSid(cli
, &sid
, str
)) {
403 /* Try to parse text form */
405 if (!StringToSid(cli
, &sid
, str
)) {
406 printf("ACE '%s': failed to convert '%s' to SID\n",
414 if (!next_token_talloc(frame
, &cp
, &tok
, "/")) {
415 printf("ACE '%s': failed to find '/' character.\n",
422 if (strncmp(tok
, "ALLOWED", strlen("ALLOWED")) == 0) {
423 atype
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
424 } else if (strncmp(tok
, "DENIED", strlen("DENIED")) == 0) {
425 atype
= SEC_ACE_TYPE_ACCESS_DENIED
;
427 printf("ACE '%s': missing 'ALLOWED' or 'DENIED' entry at '%s'\n",
434 /* Only numeric form accepted for flags at present */
436 if (!next_token_talloc(frame
, &cp
, &tok
, "/")) {
437 printf("ACE '%s': bad flags entry at '%s'\n",
444 if (tok
[0] < '0' || tok
[0] > '9') {
445 if (!parse_ace_flags(tok
, &aflags
)) {
446 printf("ACE '%s': bad named flags entry at '%s'\n",
452 } else if (strnequal(tok
, "0x", 2)) {
453 if (!sscanf(tok
, "%x", &aflags
)) {
454 printf("ACE '%s': bad hex flags entry at '%s'\n",
461 if (!sscanf(tok
, "%i", &aflags
)) {
462 printf("ACE '%s': bad integer flags entry at '%s'\n",
470 if (!next_token_talloc(frame
, &cp
, &tok
, "/")) {
471 printf("ACE '%s': missing / at '%s'\n",
478 if (strncmp(tok
, "0x", 2) == 0) {
479 if (sscanf(tok
, "%i", &amask
) != 1) {
480 printf("ACE '%s': bad hex number at '%s'\n",
489 for (v
= standard_values
; v
->perm
; v
++) {
490 if (strcmp(tok
, v
->perm
) == 0) {
501 for (v
= special_values
; v
->perm
; v
++) {
502 if (v
->perm
[0] == *p
) {
509 printf("ACE '%s': bad permission value at '%s'\n",
526 init_sec_ace(ace
, &sid
, atype
, mask
, aflags
);
532 /* add an ACE to a list of ACEs in a SEC_ACL */
533 static bool add_ace(SEC_ACL
**the_acl
, SEC_ACE
*ace
)
538 return (((*the_acl
) = make_sec_acl(talloc_tos(), 3, 1, ace
))
542 if (!(aces
= SMB_CALLOC_ARRAY(SEC_ACE
, 1+(*the_acl
)->num_aces
))) {
545 memcpy(aces
, (*the_acl
)->aces
, (*the_acl
)->num_aces
* sizeof(SEC_ACE
));
546 memcpy(aces
+(*the_acl
)->num_aces
, ace
, sizeof(SEC_ACE
));
547 new_ace
= make_sec_acl(talloc_tos(),(*the_acl
)->revision
,1+(*the_acl
)->num_aces
, aces
);
549 (*the_acl
) = new_ace
;
553 /* parse a ascii version of a security descriptor */
554 static SEC_DESC
*sec_desc_parse(TALLOC_CTX
*ctx
, struct cli_state
*cli
, char *str
)
558 SEC_DESC
*ret
= NULL
;
560 DOM_SID
*grp_sid
=NULL
, *owner_sid
=NULL
;
564 while (next_token_talloc(ctx
, &p
, &tok
, "\t,\r\n")) {
565 if (strncmp(tok
,"REVISION:", 9) == 0) {
566 revision
= strtol(tok
+9, NULL
, 16);
570 if (strncmp(tok
,"OWNER:", 6) == 0) {
572 printf("Only specify owner once\n");
575 owner_sid
= SMB_CALLOC_ARRAY(DOM_SID
, 1);
577 !StringToSid(cli
, owner_sid
, tok
+6)) {
578 printf("Failed to parse owner sid\n");
584 if (strncmp(tok
,"GROUP:", 6) == 0) {
586 printf("Only specify group once\n");
589 grp_sid
= SMB_CALLOC_ARRAY(DOM_SID
, 1);
591 !StringToSid(cli
, grp_sid
, tok
+6)) {
592 printf("Failed to parse group sid\n");
598 if (strncmp(tok
,"ACL:", 4) == 0) {
600 if (!parse_ace(cli
, &ace
, tok
+4)) {
603 if(!add_ace(&dacl
, &ace
)) {
604 printf("Failed to add ACL %s\n", tok
);
610 printf("Failed to parse token '%s' in security descriptor,\n", tok
);
614 ret
= make_sec_desc(ctx
,revision
, SEC_DESC_SELF_RELATIVE
, owner_sid
, grp_sid
,
615 NULL
, dacl
, &sd_size
);
619 SAFE_FREE(owner_sid
);
625 /* print a ascii version of a security descriptor on a FILE handle */
626 static void sec_desc_print(struct cli_state
*cli
, FILE *f
, SEC_DESC
*sd
)
631 fprintf(f
, "REVISION:%d\n", sd
->revision
);
632 fprintf(f
, "CONTROL:0x%x\n", sd
->type
);
634 /* Print owner and group sid */
637 SidToString(cli
, sidstr
, sd
->owner_sid
);
642 fprintf(f
, "OWNER:%s\n", sidstr
);
645 SidToString(cli
, sidstr
, sd
->group_sid
);
650 fprintf(f
, "GROUP:%s\n", sidstr
);
653 for (i
= 0; sd
->dacl
&& i
< sd
->dacl
->num_aces
; i
++) {
654 SEC_ACE
*ace
= &sd
->dacl
->aces
[i
];
656 print_ace(cli
, f
, ace
);
662 /*****************************************************
663 get sec desc for filename
664 *******************************************************/
665 static SEC_DESC
*get_secdesc(struct cli_state
*cli
, const char *filename
)
667 uint16_t fnum
= (uint16_t)-1;
670 /* The desired access below is the only one I could find that works
671 with NT4, W2KP and Samba */
673 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, filename
, 0, CREATE_ACCESS_READ
,
674 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
675 FILE_OPEN
, 0x0, 0x0, &fnum
))) {
676 printf("Failed to open %s: %s\n", filename
, cli_errstr(cli
));
680 sd
= cli_query_secdesc(cli
, fnum
, talloc_tos());
682 cli_close(cli
, fnum
);
685 printf("Failed to get security descriptor\n");
691 /*****************************************************
692 set sec desc for filename
693 *******************************************************/
694 static bool set_secdesc(struct cli_state
*cli
, const char *filename
,
697 uint16_t fnum
= (uint16_t)-1;
700 /* The desired access below is the only one I could find that works
701 with NT4, W2KP and Samba */
703 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, filename
, 0,
704 WRITE_DAC_ACCESS
|WRITE_OWNER_ACCESS
,
705 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
706 FILE_OPEN
, 0x0, 0x0, &fnum
))) {
707 printf("Failed to open %s: %s\n", filename
, cli_errstr(cli
));
711 if (!cli_set_secdesc(cli
, fnum
, sd
)) {
712 printf("ERROR: security description set failed: %s\n",
717 cli_close(cli
, fnum
);
721 /*****************************************************
722 dump the acls for a file
723 *******************************************************/
724 static int cacl_dump(struct cli_state
*cli
, const char *filename
)
726 int result
= EXIT_FAILED
;
732 sd
= get_secdesc(cli
, filename
);
736 printf("%s\n", sddl_encode(talloc_tos(), sd
,
737 get_global_sam_sid()));
739 sec_desc_print(cli
, stdout
, sd
);
747 /*****************************************************
748 Change the ownership or group ownership of a file. Just
749 because the NT docs say this can't be done :-). JRA.
750 *******************************************************/
752 static int owner_set(struct cli_state
*cli
, enum chown_mode change_mode
,
753 const char *filename
, const char *new_username
)
759 if (!StringToSid(cli
, &sid
, new_username
))
760 return EXIT_PARSE_ERROR
;
762 old
= get_secdesc(cli
, filename
);
768 sd
= make_sec_desc(talloc_tos(),old
->revision
, old
->type
,
769 (change_mode
== REQUEST_CHOWN
) ? &sid
: NULL
,
770 (change_mode
== REQUEST_CHGRP
) ? &sid
: NULL
,
771 NULL
, NULL
, &sd_size
);
773 if (!set_secdesc(cli
, filename
, sd
)) {
781 /* The MSDN is contradictory over the ordering of ACE entries in an
782 ACL. However NT4 gives a "The information may have been modified
783 by a computer running Windows NT 5.0" if denied ACEs do not appear
784 before allowed ACEs. At
785 http://technet.microsoft.com/en-us/library/cc781716.aspx the
786 canonical order is specified as "Explicit Deny, Explicit Allow,
787 Inherited ACEs unchanged" */
789 static int ace_compare(SEC_ACE
*ace1
, SEC_ACE
*ace2
)
791 if (sec_ace_equal(ace1
, ace2
))
794 if ((ace1
->flags
& SEC_ACE_FLAG_INHERITED_ACE
) &&
795 !(ace2
->flags
& SEC_ACE_FLAG_INHERITED_ACE
))
797 if (!(ace1
->flags
& SEC_ACE_FLAG_INHERITED_ACE
) &&
798 (ace2
->flags
& SEC_ACE_FLAG_INHERITED_ACE
))
800 if ((ace1
->flags
& SEC_ACE_FLAG_INHERITED_ACE
) &&
801 (ace2
->flags
& SEC_ACE_FLAG_INHERITED_ACE
))
804 if (ace1
->type
!= ace2
->type
)
805 return ace2
->type
- ace1
->type
;
807 if (sid_compare(&ace1
->trustee
, &ace2
->trustee
))
808 return sid_compare(&ace1
->trustee
, &ace2
->trustee
);
810 if (ace1
->flags
!= ace2
->flags
)
811 return ace1
->flags
- ace2
->flags
;
813 if (ace1
->access_mask
!= ace2
->access_mask
)
814 return ace1
->access_mask
- ace2
->access_mask
;
816 if (ace1
->size
!= ace2
->size
)
817 return ace1
->size
- ace2
->size
;
819 return memcmp(ace1
, ace2
, sizeof(SEC_ACE
));
822 static void sort_acl(SEC_ACL
*the_acl
)
825 if (!the_acl
) return;
827 TYPESAFE_QSORT(the_acl
->aces
, the_acl
->num_aces
, ace_compare
);
829 for (i
=1;i
<the_acl
->num_aces
;) {
830 if (sec_ace_equal(&the_acl
->aces
[i
-1], &the_acl
->aces
[i
])) {
832 for (j
=i
; j
<the_acl
->num_aces
-1; j
++) {
833 the_acl
->aces
[j
] = the_acl
->aces
[j
+1];
842 /*****************************************************
843 set the ACLs on a file given an ascii description
844 *******************************************************/
846 static int cacl_set(struct cli_state
*cli
, const char *filename
,
847 char *the_acl
, enum acl_mode mode
)
852 int result
= EXIT_OK
;
855 sd
= sddl_decode(talloc_tos(), the_acl
, get_global_sam_sid());
857 sd
= sec_desc_parse(talloc_tos(), cli
, the_acl
);
860 if (!sd
) return EXIT_PARSE_ERROR
;
861 if (test_args
) return EXIT_OK
;
863 old
= get_secdesc(cli
, filename
);
869 /* the logic here is rather more complex than I would like */
872 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
875 for (j
=0;old
->dacl
&& j
<old
->dacl
->num_aces
;j
++) {
876 if (sec_ace_equal(&sd
->dacl
->aces
[i
],
877 &old
->dacl
->aces
[j
])) {
879 for (k
=j
; k
<old
->dacl
->num_aces
-1;k
++) {
880 old
->dacl
->aces
[k
] = old
->dacl
->aces
[k
+1];
882 old
->dacl
->num_aces
--;
889 printf("ACL for ACE:");
890 print_ace(cli
, stdout
, &sd
->dacl
->aces
[i
]);
891 printf(" not found\n");
897 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
900 for (j
=0;old
->dacl
&& j
<old
->dacl
->num_aces
;j
++) {
901 if (sid_equal(&sd
->dacl
->aces
[i
].trustee
,
902 &old
->dacl
->aces
[j
].trustee
)) {
903 old
->dacl
->aces
[j
] = sd
->dacl
->aces
[i
];
911 SidToString(cli
, str
,
912 &sd
->dacl
->aces
[i
].trustee
);
913 printf("ACL for SID %s not found\n", str
);
918 old
->owner_sid
= sd
->owner_sid
;
922 old
->group_sid
= sd
->group_sid
;
928 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
929 add_ace(&old
->dacl
, &sd
->dacl
->aces
[i
]);
938 /* Denied ACE entries must come before allowed ones */
941 /* Create new security descriptor and set it */
943 /* We used to just have "WRITE_DAC_ACCESS" without WRITE_OWNER.
944 But if we're sending an owner, even if it's the same as the one
945 that already exists then W2K3 insists we open with WRITE_OWNER access.
946 I need to check that setting a SD with no owner set works against WNT
950 sd
= make_sec_desc(talloc_tos(),old
->revision
, old
->type
,
951 old
->owner_sid
, old
->group_sid
,
952 NULL
, old
->dacl
, &sd_size
);
954 if (!set_secdesc(cli
, filename
, sd
)) {
955 result
= EXIT_FAILED
;
962 /*****************************************************
963 Return a connection to a server.
964 *******************************************************/
965 static struct cli_state
*connect_one(struct user_auth_info
*auth_info
,
966 const char *server
, const char *share
)
968 struct cli_state
*c
= NULL
;
969 struct sockaddr_storage ss
;
975 if (get_cmdline_auth_info_use_kerberos(auth_info
)) {
976 flags
|= CLI_FULL_CONNECTION_USE_KERBEROS
|
977 CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS
;
980 if (get_cmdline_auth_info_use_machine_account(auth_info
) &&
981 !set_cmdline_auth_info_machine_account_creds(auth_info
)) {
985 set_cmdline_auth_info_getpass(auth_info
);
987 nt_status
= cli_full_connection(&c
, global_myname(), server
,
990 get_cmdline_auth_info_username(auth_info
),
992 get_cmdline_auth_info_password(auth_info
),
994 get_cmdline_auth_info_signing_state(auth_info
),
996 if (!NT_STATUS_IS_OK(nt_status
)) {
997 DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status
)));
1001 if (get_cmdline_auth_info_smb_encrypt(auth_info
)) {
1002 nt_status
= cli_cm_force_encryption(c
,
1003 get_cmdline_auth_info_username(auth_info
),
1004 get_cmdline_auth_info_password(auth_info
),
1007 if (!NT_STATUS_IS_OK(nt_status
)) {
1016 /****************************************************************************
1018 ****************************************************************************/
1019 int main(int argc
, const char *argv
[])
1023 enum acl_mode mode
= SMB_ACL_SET
;
1024 static char *the_acl
= NULL
;
1025 enum chown_mode change_mode
= REQUEST_NONE
;
1028 char *filename
= NULL
;
1030 struct poptOption long_options
[] = {
1032 { "delete", 'D', POPT_ARG_STRING
, NULL
, 'D', "Delete an acl", "ACL" },
1033 { "modify", 'M', POPT_ARG_STRING
, NULL
, 'M', "Modify an acl", "ACL" },
1034 { "add", 'a', POPT_ARG_STRING
, NULL
, 'a', "Add an acl", "ACL" },
1035 { "set", 'S', POPT_ARG_STRING
, NULL
, 'S', "Set acls", "ACLS" },
1036 { "chown", 'C', POPT_ARG_STRING
, NULL
, 'C', "Change ownership of a file", "USERNAME" },
1037 { "chgrp", 'G', POPT_ARG_STRING
, NULL
, 'G', "Change group ownership of a file", "GROUPNAME" },
1038 { "numeric", 0, POPT_ARG_NONE
, &numeric
, 1, "Don't resolve sids or masks to names" },
1039 { "sddl", 0, POPT_ARG_NONE
, &sddl
, 1, "Output and input acls in sddl format" },
1040 { "test-args", 't', POPT_ARG_NONE
, &test_args
, 1, "Test arguments"},
1042 POPT_COMMON_CONNECTION
1043 POPT_COMMON_CREDENTIALS
1047 struct cli_state
*cli
;
1048 TALLOC_CTX
*frame
= talloc_stackframe();
1049 const char *owner_username
= "";
1051 struct user_auth_info
*auth_info
;
1056 /* set default debug level to 1 regardless of what smb.conf sets */
1057 setup_logging( "smbcacls", True
);
1058 DEBUGLEVEL_CLASS
[DBGC_ALL
] = 1;
1060 x_setbuf( x_stderr
, NULL
);
1061 AllowDebugChange
= false;
1065 lp_load(get_dyn_CONFIGFILE(),True
,False
,False
,True
);
1068 auth_info
= user_auth_info_init(frame
);
1069 if (auth_info
== NULL
) {
1072 popt_common_set_auth_info(auth_info
);
1074 pc
= poptGetContext("smbcacls", argc
, argv
, long_options
, 0);
1076 poptSetOtherOptionHelp(pc
, "//server1/share1 filename\nACLs look like: "
1077 "'ACL:user:[ALLOWED|DENIED]/flags/permissions'");
1079 while ((opt
= poptGetNextOpt(pc
)) != -1) {
1082 the_acl
= smb_xstrdup(poptGetOptArg(pc
));
1087 the_acl
= smb_xstrdup(poptGetOptArg(pc
));
1088 mode
= SMB_ACL_DELETE
;
1092 the_acl
= smb_xstrdup(poptGetOptArg(pc
));
1093 mode
= SMB_ACL_MODIFY
;
1097 the_acl
= smb_xstrdup(poptGetOptArg(pc
));
1102 owner_username
= poptGetOptArg(pc
);
1103 change_mode
= REQUEST_CHOWN
;
1107 owner_username
= poptGetOptArg(pc
);
1108 change_mode
= REQUEST_CHGRP
;
1113 /* Make connection to server */
1114 if(!poptPeekArg(pc
)) {
1115 poptPrintUsage(pc
, stderr
, 0);
1119 path
= talloc_strdup(frame
, poptGetArg(pc
));
1124 if(!poptPeekArg(pc
)) {
1125 poptPrintUsage(pc
, stderr
, 0);
1129 filename
= talloc_strdup(frame
, poptGetArg(pc
));
1134 string_replace(path
,'/','\\');
1136 server
= talloc_strdup(frame
, path
+2);
1140 share
= strchr_m(server
,'\\');
1142 printf("Invalid argument: %s\n", share
);
1150 cli
= connect_one(auth_info
, server
, share
);
1158 string_replace(filename
, '/', '\\');
1159 if (filename
[0] != '\\') {
1160 filename
= talloc_asprintf(frame
,
1168 /* Perform requested action */
1170 if (change_mode
!= REQUEST_NONE
) {
1171 result
= owner_set(cli
, change_mode
, filename
, owner_username
);
1172 } else if (the_acl
) {
1173 result
= cacl_set(cli
, filename
, the_acl
, mode
);
1175 result
= cacl_dump(cli
, filename
);