2 Unix SMB/Netbios implementation.
3 SMB client library implementation
4 Copyright (C) Andrew Tridgell 1998
5 Copyright (C) Richard Sharpe 2000, 2002
6 Copyright (C) John Terpstra 2000
7 Copyright (C) Tom Jansen (Ninja ISD) 2002
8 Copyright (C) Derrell Lipman 2003-2008
9 Copyright (C) Jeremy Allison 2007, 2008
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "libsmb/libsmb.h"
27 #include "libsmbclient.h"
28 #include "libsmb_internal.h"
29 #include "../librpc/gen_ndr/ndr_lsa.h"
30 #include "rpc_client/rpc_client.h"
31 #include "rpc_client/cli_lsarpc.h"
32 #include "../libcli/security/security.h"
35 * Find an lsa pipe handle associated with a cli struct.
37 static struct rpc_pipe_client
*
38 find_lsa_pipe_hnd(struct cli_state
*ipc_cli
)
40 struct rpc_pipe_client
*pipe_hnd
;
42 for (pipe_hnd
= ipc_cli
->pipe_list
;
44 pipe_hnd
= pipe_hnd
->next
) {
45 if (ndr_syntax_id_equal(&pipe_hnd
->abstract_syntax
,
46 &ndr_table_lsarpc
.syntax_id
)) {
54 * Sort ACEs according to the documentation at
55 * http://support.microsoft.com/kb/269175, at least as far as it defines the
60 ace_compare(struct security_ace
*ace1
,
61 struct security_ace
*ace2
)
66 /* If the ACEs are equal, we have nothing more to do. */
67 if (sec_ace_equal(ace1
, ace2
)) {
71 /* Inherited follow non-inherited */
72 b1
= ((ace1
->flags
& SEC_ACE_FLAG_INHERITED_ACE
) != 0);
73 b2
= ((ace2
->flags
& SEC_ACE_FLAG_INHERITED_ACE
) != 0);
79 * What shall we do with AUDITs and ALARMs? It's undefined. We'll
80 * sort them after DENY and ALLOW.
82 b1
= (ace1
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED
&&
83 ace1
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
&&
84 ace1
->type
!= SEC_ACE_TYPE_ACCESS_DENIED
&&
85 ace1
->type
!= SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
86 b2
= (ace2
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED
&&
87 ace2
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
&&
88 ace2
->type
!= SEC_ACE_TYPE_ACCESS_DENIED
&&
89 ace2
->type
!= SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
94 /* Allowed ACEs follow denied ACEs */
95 b1
= (ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED
||
96 ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
);
97 b2
= (ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED
||
98 ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
);
100 return (b1
? 1 : -1);
104 * ACEs applying to an entity's object follow those applying to the
107 b1
= (ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
||
108 ace1
->type
== SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
109 b2
= (ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
||
110 ace2
->type
== SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
112 return (b1
? 1 : -1);
116 * If we get this far, the ACEs are similar as far as the
117 * characteristics we typically care about (those defined by the
118 * referenced MS document). We'll now sort by characteristics that
119 * just seems reasonable.
122 if (ace1
->type
!= ace2
->type
) {
123 return ace2
->type
- ace1
->type
;
126 if (dom_sid_compare(&ace1
->trustee
, &ace2
->trustee
)) {
127 return dom_sid_compare(&ace1
->trustee
, &ace2
->trustee
);
130 if (ace1
->flags
!= ace2
->flags
) {
131 return ace1
->flags
- ace2
->flags
;
134 if (ace1
->access_mask
!= ace2
->access_mask
) {
135 return ace1
->access_mask
- ace2
->access_mask
;
138 if (ace1
->size
!= ace2
->size
) {
139 return ace1
->size
- ace2
->size
;
142 return memcmp(ace1
, ace2
, sizeof(struct security_ace
));
147 sort_acl(struct security_acl
*the_acl
)
150 if (!the_acl
) return;
152 TYPESAFE_QSORT(the_acl
->aces
, the_acl
->num_aces
, ace_compare
);
154 for (i
=1;i
<the_acl
->num_aces
;) {
155 if (sec_ace_equal(&the_acl
->aces
[i
-1], &the_acl
->aces
[i
])) {
157 for (j
=i
; j
<the_acl
->num_aces
-1; j
++) {
158 the_acl
->aces
[j
] = the_acl
->aces
[j
+1];
167 /* convert a SID to a string, either numeric or username/group */
169 convert_sid_to_string(struct cli_state
*ipc_cli
,
170 struct policy_handle
*pol
,
175 char **domains
= NULL
;
177 enum lsa_SidType
*types
= NULL
;
178 struct rpc_pipe_client
*pipe_hnd
= find_lsa_pipe_hnd(ipc_cli
);
181 sid_to_fstring(str
, sid
);
184 return; /* no lookup desired */
191 /* Ask LSA to convert the sid to a name */
193 ctx
= talloc_stackframe();
195 if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_sids(pipe_hnd
, ctx
,
196 pol
, 1, sid
, &domains
,
198 !domains
|| !domains
[0] || !names
|| !names
[0]) {
205 slprintf(str
, sizeof(fstring
) - 1, "%s%s%s",
206 domains
[0], lp_winbind_separator(),
212 /* convert a string to a SID, either numeric or username/group */
214 convert_string_to_sid(struct cli_state
*ipc_cli
,
215 struct policy_handle
*pol
,
220 enum lsa_SidType
*types
= NULL
;
221 struct dom_sid
*sids
= NULL
;
223 TALLOC_CTX
*ctx
= NULL
;
224 struct rpc_pipe_client
*pipe_hnd
= find_lsa_pipe_hnd(ipc_cli
);
231 if (strncmp(str
, "S-", 2) == 0) {
232 return string_to_sid(sid
, str
);
239 ctx
= talloc_stackframe();
240 if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_names(pipe_hnd
, ctx
,
248 sid_copy(sid
, &sids
[0]);
255 /* parse an struct security_ace in the same format as print_ace() */
257 parse_ace(struct cli_state
*ipc_cli
,
258 struct policy_handle
*pol
,
259 struct security_ace
*ace
,
271 const struct perm_value
*v
;
276 TALLOC_CTX
*frame
= talloc_stackframe();
278 /* These values discovered by inspection */
279 static const struct perm_value special_values
[] = {
289 static const struct perm_value standard_values
[] = {
290 { "READ", 0x001200a9 },
291 { "CHANGE", 0x001301bf },
292 { "FULL", 0x001f01ff },
297 p
= strchr_m(str
,':');
304 /* Try to parse numeric form */
306 if (sscanf(p
, "%i/%i/%i", &atype
, &aflags
, &amask
) == 3 &&
307 convert_string_to_sid(ipc_cli
, pol
, numeric
, &sid
, str
)) {
311 /* Try to parse text form */
313 if (!convert_string_to_sid(ipc_cli
, pol
, numeric
, &sid
, str
)) {
319 if (!next_token_talloc(frame
, &cp
, &tok
, "/")) {
324 if (strncasecmp_m(tok
, "ALLOWED", strlen("ALLOWED")) == 0) {
325 atype
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
326 } else if (strncasecmp_m(tok
, "DENIED", strlen("DENIED")) == 0) {
327 atype
= SEC_ACE_TYPE_ACCESS_DENIED
;
333 /* Only numeric form accepted for flags at present */
335 if (!(next_token_talloc(frame
, &cp
, &tok
, "/") &&
336 sscanf(tok
, "%i", &aflags
))) {
341 if (!next_token_talloc(frame
, &cp
, &tok
, "/")) {
346 if (strncmp(tok
, "0x", 2) == 0) {
347 if (sscanf(tok
, "%i", &amask
) != 1) {
354 for (v
= standard_values
; v
->perm
; v
++) {
355 if (strcmp(tok
, v
->perm
) == 0) {
366 for (v
= special_values
; v
->perm
; v
++) {
367 if (v
->perm
[0] == *p
) {
387 init_sec_ace(ace
, &sid
, atype
, mask
, aflags
);
392 /* add an struct security_ace to a list of struct security_aces in a struct security_acl */
394 add_ace(struct security_acl
**the_acl
,
395 struct security_ace
*ace
,
398 struct security_acl
*newacl
;
399 struct security_ace
*aces
;
402 (*the_acl
) = make_sec_acl(ctx
, 3, 1, ace
);
406 if ((aces
= SMB_CALLOC_ARRAY(struct security_ace
,
407 1+(*the_acl
)->num_aces
)) == NULL
) {
410 memcpy(aces
, (*the_acl
)->aces
, (*the_acl
)->num_aces
* sizeof(struct security_ace
));
411 memcpy(aces
+(*the_acl
)->num_aces
, ace
, sizeof(struct security_ace
));
412 newacl
= make_sec_acl(ctx
, (*the_acl
)->revision
,
413 1+(*the_acl
)->num_aces
, aces
);
420 /* parse a ascii version of a security descriptor */
421 static struct security_descriptor
*
422 sec_desc_parse(TALLOC_CTX
*ctx
,
423 struct cli_state
*ipc_cli
,
424 struct policy_handle
*pol
,
430 struct security_descriptor
*ret
= NULL
;
432 struct dom_sid
*group_sid
=NULL
;
433 struct dom_sid
*owner_sid
=NULL
;
434 struct security_acl
*dacl
=NULL
;
437 while (next_token_talloc(ctx
, &p
, &tok
, "\t,\r\n")) {
439 if (strncasecmp_m(tok
,"REVISION:", 9) == 0) {
440 revision
= strtol(tok
+9, NULL
, 16);
444 if (strncasecmp_m(tok
,"OWNER:", 6) == 0) {
446 DEBUG(5,("OWNER specified more than once!\n"));
449 owner_sid
= SMB_CALLOC_ARRAY(struct dom_sid
, 1);
451 !convert_string_to_sid(ipc_cli
, pol
,
454 DEBUG(5, ("Failed to parse owner sid\n"));
460 if (strncasecmp_m(tok
,"OWNER+:", 7) == 0) {
462 DEBUG(5,("OWNER specified more than once!\n"));
465 owner_sid
= SMB_CALLOC_ARRAY(struct dom_sid
, 1);
467 !convert_string_to_sid(ipc_cli
, pol
,
470 DEBUG(5, ("Failed to parse owner sid\n"));
476 if (strncasecmp_m(tok
,"GROUP:", 6) == 0) {
478 DEBUG(5,("GROUP specified more than once!\n"));
481 group_sid
= SMB_CALLOC_ARRAY(struct dom_sid
, 1);
483 !convert_string_to_sid(ipc_cli
, pol
,
486 DEBUG(5, ("Failed to parse group sid\n"));
492 if (strncasecmp_m(tok
,"GROUP+:", 7) == 0) {
494 DEBUG(5,("GROUP specified more than once!\n"));
497 group_sid
= SMB_CALLOC_ARRAY(struct dom_sid
, 1);
499 !convert_string_to_sid(ipc_cli
, pol
,
502 DEBUG(5, ("Failed to parse group sid\n"));
508 if (strncasecmp_m(tok
,"ACL:", 4) == 0) {
509 struct security_ace ace
;
510 if (!parse_ace(ipc_cli
, pol
, &ace
, numeric
, tok
+4)) {
511 DEBUG(5, ("Failed to parse ACL %s\n", tok
));
514 if(!add_ace(&dacl
, &ace
, ctx
)) {
515 DEBUG(5, ("Failed to add ACL %s\n", tok
));
521 if (strncasecmp_m(tok
,"ACL+:", 5) == 0) {
522 struct security_ace ace
;
523 if (!parse_ace(ipc_cli
, pol
, &ace
, False
, tok
+5)) {
524 DEBUG(5, ("Failed to parse ACL %s\n", tok
));
527 if(!add_ace(&dacl
, &ace
, ctx
)) {
528 DEBUG(5, ("Failed to add ACL %s\n", tok
));
534 DEBUG(5, ("Failed to parse security descriptor\n"));
538 ret
= make_sec_desc(ctx
, revision
, SEC_DESC_SELF_RELATIVE
,
539 owner_sid
, group_sid
, NULL
, dacl
, &sd_size
);
542 SAFE_FREE(group_sid
);
543 SAFE_FREE(owner_sid
);
548 /* Obtain the current dos attributes */
549 static DOS_ATTR_DESC
*
550 dos_attr_query(SMBCCTX
*context
,
552 const char *filename
,
555 struct timespec create_time_ts
;
556 struct timespec write_time_ts
;
557 struct timespec access_time_ts
;
558 struct timespec change_time_ts
;
564 ret
= talloc(ctx
, DOS_ATTR_DESC
);
570 /* Obtain the DOS attributes */
571 if (!SMBC_getatr(context
, srv
, filename
,
578 errno
= SMBC_errno(context
, srv
->cli
);
579 DEBUG(5, ("dos_attr_query Failed to query old attributes\n"));
586 ret
->create_time
= convert_timespec_to_time_t(create_time_ts
);
587 ret
->access_time
= convert_timespec_to_time_t(access_time_ts
);
588 ret
->write_time
= convert_timespec_to_time_t(write_time_ts
);
589 ret
->change_time
= convert_timespec_to_time_t(change_time_ts
);
596 /* parse a ascii version of a security descriptor */
598 dos_attr_parse(SMBCCTX
*context
,
606 TALLOC_CTX
*frame
= NULL
;
608 const char * create_time_attr
;
609 const char * access_time_attr
;
610 const char * write_time_attr
;
611 const char * change_time_attr
;
614 /* Determine whether to use old-style or new-style attribute names */
615 if (context
->internal
->full_time_names
) {
616 /* new-style names */
617 attr_strings
.create_time_attr
= "CREATE_TIME";
618 attr_strings
.access_time_attr
= "ACCESS_TIME";
619 attr_strings
.write_time_attr
= "WRITE_TIME";
620 attr_strings
.change_time_attr
= "CHANGE_TIME";
622 /* old-style names */
623 attr_strings
.create_time_attr
= NULL
;
624 attr_strings
.access_time_attr
= "A_TIME";
625 attr_strings
.write_time_attr
= "M_TIME";
626 attr_strings
.change_time_attr
= "C_TIME";
629 /* if this is to set the entire ACL... */
631 /* ... then increment past the first colon if there is one */
632 if ((p
= strchr(str
, ':')) != NULL
) {
639 frame
= talloc_stackframe();
640 while (next_token_talloc(frame
, &p
, &tok
, "\t,\r\n")) {
641 if (strncasecmp_m(tok
, "MODE:", 5) == 0) {
642 long request
= strtol(tok
+5, NULL
, 16);
644 dad
->mode
= (request
|
645 (IS_DOS_DIR(dad
->mode
)
646 ? FILE_ATTRIBUTE_DIRECTORY
647 : FILE_ATTRIBUTE_NORMAL
));
654 if (strncasecmp_m(tok
, "SIZE:", 5) == 0) {
655 dad
->size
= (off_t
)atof(tok
+5);
659 n
= strlen(attr_strings
.access_time_attr
);
660 if (strncasecmp_m(tok
, attr_strings
.access_time_attr
, n
) == 0) {
661 dad
->access_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
665 n
= strlen(attr_strings
.change_time_attr
);
666 if (strncasecmp_m(tok
, attr_strings
.change_time_attr
, n
) == 0) {
667 dad
->change_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
671 n
= strlen(attr_strings
.write_time_attr
);
672 if (strncasecmp_m(tok
, attr_strings
.write_time_attr
, n
) == 0) {
673 dad
->write_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
677 if (attr_strings
.create_time_attr
!= NULL
) {
678 n
= strlen(attr_strings
.create_time_attr
);
679 if (strncasecmp_m(tok
, attr_strings
.create_time_attr
,
681 dad
->create_time
= (time_t)strtol(tok
+n
+1,
687 if (strncasecmp_m(tok
, "INODE:", 6) == 0) {
688 dad
->inode
= (SMB_INO_T
)atof(tok
+6);
695 /*****************************************************
696 Retrieve the acls for a file.
697 *******************************************************/
700 cacl_get(SMBCCTX
*context
,
703 struct cli_state
*ipc_cli
,
704 struct policy_handle
*pol
,
705 const char *filename
,
706 const char *attr_name
,
719 bool exclude_nt_revision
= False
;
720 bool exclude_nt_owner
= False
;
721 bool exclude_nt_group
= False
;
722 bool exclude_nt_acl
= False
;
723 bool exclude_dos_mode
= False
;
724 bool exclude_dos_size
= False
;
725 bool exclude_dos_create_time
= False
;
726 bool exclude_dos_access_time
= False
;
727 bool exclude_dos_write_time
= False
;
728 bool exclude_dos_change_time
= False
;
729 bool exclude_dos_inode
= False
;
731 bool determine_size
= (bufsize
== 0);
733 struct security_descriptor
*sd
;
735 fstring name_sandbox
;
739 struct timespec create_time_ts
;
740 struct timespec write_time_ts
;
741 struct timespec access_time_ts
;
742 struct timespec change_time_ts
;
743 time_t create_time
= (time_t)0;
744 time_t write_time
= (time_t)0;
745 time_t access_time
= (time_t)0;
746 time_t change_time
= (time_t)0;
750 struct cli_state
*cli
= srv
->cli
;
752 const char * create_time_attr
;
753 const char * access_time_attr
;
754 const char * write_time_attr
;
755 const char * change_time_attr
;
758 const char * create_time_attr
;
759 const char * access_time_attr
;
760 const char * write_time_attr
;
761 const char * change_time_attr
;
764 /* Determine whether to use old-style or new-style attribute names */
765 if (context
->internal
->full_time_names
) {
766 /* new-style names */
767 attr_strings
.create_time_attr
= "CREATE_TIME";
768 attr_strings
.access_time_attr
= "ACCESS_TIME";
769 attr_strings
.write_time_attr
= "WRITE_TIME";
770 attr_strings
.change_time_attr
= "CHANGE_TIME";
772 excl_attr_strings
.create_time_attr
= "CREATE_TIME";
773 excl_attr_strings
.access_time_attr
= "ACCESS_TIME";
774 excl_attr_strings
.write_time_attr
= "WRITE_TIME";
775 excl_attr_strings
.change_time_attr
= "CHANGE_TIME";
777 /* old-style names */
778 attr_strings
.create_time_attr
= NULL
;
779 attr_strings
.access_time_attr
= "A_TIME";
780 attr_strings
.write_time_attr
= "M_TIME";
781 attr_strings
.change_time_attr
= "C_TIME";
783 excl_attr_strings
.create_time_attr
= NULL
;
784 excl_attr_strings
.access_time_attr
= "dos_attr.A_TIME";
785 excl_attr_strings
.write_time_attr
= "dos_attr.M_TIME";
786 excl_attr_strings
.change_time_attr
= "dos_attr.C_TIME";
789 /* Copy name so we can strip off exclusions (if any are specified) */
790 strncpy(name_sandbox
, attr_name
, sizeof(name_sandbox
) - 1);
792 /* Ensure name is null terminated */
793 name_sandbox
[sizeof(name_sandbox
) - 1] = '\0';
795 /* Play in the sandbox */
798 /* If there are any exclusions, point to them and mask them from name */
799 if ((pExclude
= strchr(name
, '!')) != NULL
)
804 all
= (strncasecmp_m(name
, "system.*", 8) == 0);
805 all_nt
= (strncasecmp_m(name
, "system.nt_sec_desc.*", 20) == 0);
806 all_nt_acls
= (strncasecmp_m(name
, "system.nt_sec_desc.acl.*", 24) == 0);
807 all_dos
= (strncasecmp_m(name
, "system.dos_attr.*", 17) == 0);
808 some_nt
= (strncasecmp_m(name
, "system.nt_sec_desc.", 19) == 0);
809 some_dos
= (strncasecmp_m(name
, "system.dos_attr.", 16) == 0);
810 numeric
= (* (name
+ strlen(name
) - 1) != '+');
812 /* Look for exclusions from "all" requests */
813 if (all
|| all_nt
|| all_dos
) {
814 /* Exclusions are delimited by '!' */
817 pExclude
= (p
== NULL
? NULL
: p
+ 1)) {
819 /* Find end of this exclusion name */
820 if ((p
= strchr(pExclude
, '!')) != NULL
)
825 /* Which exclusion name is this? */
826 if (strcasecmp_m(pExclude
,
827 "nt_sec_desc.revision") == 0) {
828 exclude_nt_revision
= True
;
830 else if (strcasecmp_m(pExclude
,
831 "nt_sec_desc.owner") == 0) {
832 exclude_nt_owner
= True
;
834 else if (strcasecmp_m(pExclude
,
835 "nt_sec_desc.group") == 0) {
836 exclude_nt_group
= True
;
838 else if (strcasecmp_m(pExclude
,
839 "nt_sec_desc.acl") == 0) {
840 exclude_nt_acl
= True
;
842 else if (strcasecmp_m(pExclude
,
843 "dos_attr.mode") == 0) {
844 exclude_dos_mode
= True
;
846 else if (strcasecmp_m(pExclude
,
847 "dos_attr.size") == 0) {
848 exclude_dos_size
= True
;
850 else if (excl_attr_strings
.create_time_attr
!= NULL
&&
851 strcasecmp_m(pExclude
,
852 excl_attr_strings
.change_time_attr
) == 0) {
853 exclude_dos_create_time
= True
;
855 else if (strcasecmp_m(pExclude
,
856 excl_attr_strings
.access_time_attr
) == 0) {
857 exclude_dos_access_time
= True
;
859 else if (strcasecmp_m(pExclude
,
860 excl_attr_strings
.write_time_attr
) == 0) {
861 exclude_dos_write_time
= True
;
863 else if (strcasecmp_m(pExclude
,
864 excl_attr_strings
.change_time_attr
) == 0) {
865 exclude_dos_change_time
= True
;
867 else if (strcasecmp_m(pExclude
, "dos_attr.inode") == 0) {
868 exclude_dos_inode
= True
;
871 DEBUG(5, ("cacl_get received unknown exclusion: %s\n",
882 * If we are (possibly) talking to an NT or new system and some NT
883 * attributes have been requested...
885 if (ipc_cli
&& (all
|| some_nt
|| all_nt_acls
)) {
886 char *targetpath
= NULL
;
887 struct cli_state
*targetcli
= NULL
;
890 /* Point to the portion after "system.nt_sec_desc." */
891 name
+= 19; /* if (all) this will be invalid but unused */
893 status
= cli_resolve_path(
894 ctx
, "", context
->internal
->auth_info
,
895 cli
, filename
, &targetcli
, &targetpath
);
896 if (!NT_STATUS_IS_OK(status
)) {
897 DEBUG(5, ("cacl_get Could not resolve %s\n",
903 /* ... then obtain any NT attributes which were requested */
904 status
= cli_ntcreate(targetcli
, targetpath
, 0,
905 CREATE_ACCESS_READ
, 0,
906 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
907 FILE_OPEN
, 0x0, 0x0, &fnum
);
908 if (!NT_STATUS_IS_OK(status
)) {
909 DEBUG(5, ("cacl_get failed to open %s: %s\n",
910 targetpath
, nt_errstr(status
)));
915 status
= cli_query_secdesc(targetcli
, fnum
, ctx
, &sd
);
916 if (!NT_STATUS_IS_OK(status
)) {
917 DEBUG(5,("cacl_get Failed to query old descriptor "
919 targetpath
, nt_errstr(status
)));
924 cli_close(targetcli
, fnum
);
926 if (! exclude_nt_revision
) {
928 if (determine_size
) {
929 p
= talloc_asprintf(ctx
,
938 n
= snprintf(buf
, bufsize
,
942 } else if (strcasecmp_m(name
, "revision") == 0) {
943 if (determine_size
) {
944 p
= talloc_asprintf(ctx
, "%d",
952 n
= snprintf(buf
, bufsize
, "%d",
957 if (!determine_size
&& n
> bufsize
) {
967 if (! exclude_nt_owner
) {
968 /* Get owner and group sid */
970 convert_sid_to_string(ipc_cli
, pol
,
979 if (determine_size
) {
980 p
= talloc_asprintf(ctx
, ",OWNER:%s",
987 } else if (sidstr
[0] != '\0') {
988 n
= snprintf(buf
, bufsize
,
989 ",OWNER:%s", sidstr
);
991 } else if (strncasecmp_m(name
, "owner", 5) == 0) {
992 if (determine_size
) {
993 p
= talloc_asprintf(ctx
, "%s", sidstr
);
1000 n
= snprintf(buf
, bufsize
, "%s",
1005 if (!determine_size
&& n
> bufsize
) {
1015 if (! exclude_nt_group
) {
1016 if (sd
->group_sid
) {
1017 convert_sid_to_string(ipc_cli
, pol
,
1021 fstrcpy(sidstr
, "");
1024 if (all
|| all_nt
) {
1025 if (determine_size
) {
1026 p
= talloc_asprintf(ctx
, ",GROUP:%s",
1033 } else if (sidstr
[0] != '\0') {
1034 n
= snprintf(buf
, bufsize
,
1035 ",GROUP:%s", sidstr
);
1037 } else if (strncasecmp_m(name
, "group", 5) == 0) {
1038 if (determine_size
) {
1039 p
= talloc_asprintf(ctx
, "%s", sidstr
);
1046 n
= snprintf(buf
, bufsize
,
1051 if (!determine_size
&& n
> bufsize
) {
1061 if (! exclude_nt_acl
) {
1062 /* Add aces to value buffer */
1063 for (i
= 0; sd
->dacl
&& i
< sd
->dacl
->num_aces
; i
++) {
1065 struct security_ace
*ace
= &sd
->dacl
->aces
[i
];
1066 convert_sid_to_string(ipc_cli
, pol
,
1070 if (all
|| all_nt
) {
1071 if (determine_size
) {
1072 p
= talloc_asprintf(
1088 ",ACL:%s:%d/%d/0x%08x",
1094 } else if ((strncasecmp_m(name
, "acl", 3) == 0 &&
1095 strcasecmp_m(name
+3, sidstr
) == 0) ||
1096 (strncasecmp_m(name
, "acl+", 4) == 0 &&
1097 strcasecmp_m(name
+4, sidstr
) == 0)) {
1098 if (determine_size
) {
1099 p
= talloc_asprintf(
1111 n
= snprintf(buf
, bufsize
,
1117 } else if (all_nt_acls
) {
1118 if (determine_size
) {
1119 p
= talloc_asprintf(
1121 "%s%s:%d/%d/0x%08x",
1133 n
= snprintf(buf
, bufsize
,
1134 "%s%s:%d/%d/0x%08x",
1142 if (!determine_size
&& n
> bufsize
) {
1153 /* Restore name pointer to its original value */
1157 if (all
|| some_dos
) {
1158 /* Point to the portion after "system.dos_attr." */
1159 name
+= 16; /* if (all) this will be invalid but unused */
1161 /* Obtain the DOS attributes */
1162 if (!SMBC_getatr(context
, srv
, filename
, &mode
, &size
,
1169 errno
= SMBC_errno(context
, srv
->cli
);
1173 create_time
= convert_timespec_to_time_t(create_time_ts
);
1174 access_time
= convert_timespec_to_time_t(access_time_ts
);
1175 write_time
= convert_timespec_to_time_t(write_time_ts
);
1176 change_time
= convert_timespec_to_time_t(change_time_ts
);
1178 if (! exclude_dos_mode
) {
1179 if (all
|| all_dos
) {
1180 if (determine_size
) {
1181 p
= talloc_asprintf(ctx
,
1194 n
= snprintf(buf
, bufsize
,
1202 } else if (strcasecmp_m(name
, "mode") == 0) {
1203 if (determine_size
) {
1204 p
= talloc_asprintf(ctx
, "0x%x", mode
);
1211 n
= snprintf(buf
, bufsize
,
1216 if (!determine_size
&& n
> bufsize
) {
1226 if (! exclude_dos_size
) {
1227 if (all
|| all_dos
) {
1228 if (determine_size
) {
1229 p
= talloc_asprintf(
1239 n
= snprintf(buf
, bufsize
,
1243 } else if (strcasecmp_m(name
, "size") == 0) {
1244 if (determine_size
) {
1245 p
= talloc_asprintf(
1255 n
= snprintf(buf
, bufsize
,
1261 if (!determine_size
&& n
> bufsize
) {
1271 if (! exclude_dos_create_time
&&
1272 attr_strings
.create_time_attr
!= NULL
) {
1273 if (all
|| all_dos
) {
1274 if (determine_size
) {
1275 p
= talloc_asprintf(ctx
,
1277 attr_strings
.create_time_attr
,
1278 (unsigned long) create_time
);
1285 n
= snprintf(buf
, bufsize
,
1287 attr_strings
.create_time_attr
,
1288 (unsigned long) create_time
);
1290 } else if (strcasecmp_m(name
, attr_strings
.create_time_attr
) == 0) {
1291 if (determine_size
) {
1292 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) create_time
);
1299 n
= snprintf(buf
, bufsize
,
1300 "%lu", (unsigned long) create_time
);
1304 if (!determine_size
&& n
> bufsize
) {
1314 if (! exclude_dos_access_time
) {
1315 if (all
|| all_dos
) {
1316 if (determine_size
) {
1317 p
= talloc_asprintf(ctx
,
1319 attr_strings
.access_time_attr
,
1320 (unsigned long) access_time
);
1327 n
= snprintf(buf
, bufsize
,
1329 attr_strings
.access_time_attr
,
1330 (unsigned long) access_time
);
1332 } else if (strcasecmp_m(name
, attr_strings
.access_time_attr
) == 0) {
1333 if (determine_size
) {
1334 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) access_time
);
1341 n
= snprintf(buf
, bufsize
,
1342 "%lu", (unsigned long) access_time
);
1346 if (!determine_size
&& n
> bufsize
) {
1356 if (! exclude_dos_write_time
) {
1357 if (all
|| all_dos
) {
1358 if (determine_size
) {
1359 p
= talloc_asprintf(ctx
,
1361 attr_strings
.write_time_attr
,
1362 (unsigned long) write_time
);
1369 n
= snprintf(buf
, bufsize
,
1371 attr_strings
.write_time_attr
,
1372 (unsigned long) write_time
);
1374 } else if (strcasecmp_m(name
, attr_strings
.write_time_attr
) == 0) {
1375 if (determine_size
) {
1376 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) write_time
);
1383 n
= snprintf(buf
, bufsize
,
1384 "%lu", (unsigned long) write_time
);
1388 if (!determine_size
&& n
> bufsize
) {
1398 if (! exclude_dos_change_time
) {
1399 if (all
|| all_dos
) {
1400 if (determine_size
) {
1401 p
= talloc_asprintf(ctx
,
1403 attr_strings
.change_time_attr
,
1404 (unsigned long) change_time
);
1411 n
= snprintf(buf
, bufsize
,
1413 attr_strings
.change_time_attr
,
1414 (unsigned long) change_time
);
1416 } else if (strcasecmp_m(name
, attr_strings
.change_time_attr
) == 0) {
1417 if (determine_size
) {
1418 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) change_time
);
1425 n
= snprintf(buf
, bufsize
,
1426 "%lu", (unsigned long) change_time
);
1430 if (!determine_size
&& n
> bufsize
) {
1440 if (! exclude_dos_inode
) {
1441 if (all
|| all_dos
) {
1442 if (determine_size
) {
1443 p
= talloc_asprintf(
1453 n
= snprintf(buf
, bufsize
,
1457 } else if (strcasecmp_m(name
, "inode") == 0) {
1458 if (determine_size
) {
1459 p
= talloc_asprintf(
1469 n
= snprintf(buf
, bufsize
,
1475 if (!determine_size
&& n
> bufsize
) {
1485 /* Restore name pointer to its original value */
1497 /*****************************************************
1498 set the ACLs on a file given an ascii description
1499 *******************************************************/
1501 cacl_set(SMBCCTX
*context
,
1503 struct cli_state
*cli
,
1504 struct cli_state
*ipc_cli
,
1505 struct policy_handle
*pol
,
1506 const char *filename
,
1511 uint16_t fnum
= (uint16_t)-1;
1513 struct security_descriptor
*sd
= NULL
, *old
;
1514 struct security_acl
*dacl
= NULL
;
1515 struct dom_sid
*owner_sid
= NULL
;
1516 struct dom_sid
*group_sid
= NULL
;
1521 bool numeric
= True
;
1522 char *targetpath
= NULL
;
1523 struct cli_state
*targetcli
= NULL
;
1526 /* the_acl will be null for REMOVE_ALL operations */
1528 numeric
= ((p
= strchr(the_acl
, ':')) != NULL
&&
1532 /* if this is to set the entire ACL... */
1533 if (*the_acl
== '*') {
1534 /* ... then increment past the first colon */
1538 sd
= sec_desc_parse(ctx
, ipc_cli
, pol
, numeric
, the_acl
);
1545 /* SMBC_XATTR_MODE_REMOVE_ALL is the only caller
1546 that doesn't deref sd */
1548 if (!sd
&& (mode
!= SMBC_XATTR_MODE_REMOVE_ALL
)) {
1553 status
= cli_resolve_path(ctx
, "", context
->internal
->auth_info
,
1554 cli
, filename
, &targetcli
, &targetpath
);
1555 if (!NT_STATUS_IS_OK(status
)) {
1556 DEBUG(5,("cacl_set: Could not resolve %s\n", filename
));
1561 /* The desired access below is the only one I could find that works
1562 with NT4, W2KP and Samba */
1564 status
= cli_ntcreate(targetcli
, targetpath
, 0, CREATE_ACCESS_READ
, 0,
1565 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
,
1567 if (!NT_STATUS_IS_OK(status
)) {
1568 DEBUG(5, ("cacl_set failed to open %s: %s\n",
1569 targetpath
, nt_errstr(status
)));
1574 status
= cli_query_secdesc(targetcli
, fnum
, ctx
, &old
);
1575 if (!NT_STATUS_IS_OK(status
)) {
1576 DEBUG(5,("cacl_set Failed to query old descriptor of %s: %s\n",
1577 targetpath
, nt_errstr(status
)));
1582 cli_close(targetcli
, fnum
);
1585 case SMBC_XATTR_MODE_REMOVE_ALL
:
1586 old
->dacl
->num_aces
= 0;
1590 case SMBC_XATTR_MODE_REMOVE
:
1591 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1594 for (j
=0;old
->dacl
&& j
<old
->dacl
->num_aces
;j
++) {
1595 if (sec_ace_equal(&sd
->dacl
->aces
[i
],
1596 &old
->dacl
->aces
[j
])) {
1598 for (k
=j
; k
<old
->dacl
->num_aces
-1;k
++) {
1599 old
->dacl
->aces
[k
] =
1600 old
->dacl
->aces
[k
+1];
1602 old
->dacl
->num_aces
--;
1617 case SMBC_XATTR_MODE_ADD
:
1618 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1621 for (j
=0;old
->dacl
&& j
<old
->dacl
->num_aces
;j
++) {
1622 if (dom_sid_equal(&sd
->dacl
->aces
[i
].trustee
,
1623 &old
->dacl
->aces
[j
].trustee
)) {
1624 if (!(flags
& SMBC_XATTR_FLAG_CREATE
)) {
1629 old
->dacl
->aces
[j
] = sd
->dacl
->aces
[i
];
1635 if (!found
&& (flags
& SMBC_XATTR_FLAG_REPLACE
)) {
1641 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1642 add_ace(&old
->dacl
, &sd
->dacl
->aces
[i
], ctx
);
1648 case SMBC_XATTR_MODE_SET
:
1650 owner_sid
= old
->owner_sid
;
1651 group_sid
= old
->group_sid
;
1655 case SMBC_XATTR_MODE_CHOWN
:
1656 owner_sid
= sd
->owner_sid
;
1659 case SMBC_XATTR_MODE_CHGRP
:
1660 group_sid
= sd
->group_sid
;
1664 /* Denied ACE entries must come before allowed ones */
1665 sort_acl(old
->dacl
);
1667 /* Create new security descriptor and set it */
1668 sd
= make_sec_desc(ctx
, old
->revision
, SEC_DESC_SELF_RELATIVE
,
1669 owner_sid
, group_sid
, NULL
, dacl
, &sd_size
);
1671 status
= cli_ntcreate(targetcli
, targetpath
, 0,
1672 WRITE_DAC_ACCESS
| WRITE_OWNER_ACCESS
, 0,
1673 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
,
1675 if (!NT_STATUS_IS_OK(status
)) {
1676 DEBUG(5, ("cacl_set failed to open %s: %s\n",
1677 targetpath
, nt_errstr(status
)));
1682 status
= cli_set_secdesc(targetcli
, fnum
, sd
);
1683 if (!NT_STATUS_IS_OK(status
)) {
1684 DEBUG(5, ("ERROR: secdesc set failed: %s\n",
1685 nt_errstr(status
)));
1692 cli_close(targetcli
, fnum
);
1703 SMBC_setxattr_ctx(SMBCCTX
*context
,
1712 SMBCSRV
*srv
= NULL
;
1713 SMBCSRV
*ipc_srv
= NULL
;
1714 char *server
= NULL
;
1717 char *password
= NULL
;
1718 char *workgroup
= NULL
;
1720 DOS_ATTR_DESC
*dad
= NULL
;
1722 const char * create_time_attr
;
1723 const char * access_time_attr
;
1724 const char * write_time_attr
;
1725 const char * change_time_attr
;
1727 TALLOC_CTX
*frame
= talloc_stackframe();
1729 if (!context
|| !context
->internal
->initialized
) {
1730 errno
= EINVAL
; /* Best I can think of ... */
1741 DEBUG(4, ("smbc_setxattr(%s, %s, %.*s)\n",
1742 fname
, name
, (int) size
, (const char*)value
));
1744 if (SMBC_parse_path(frame
,
1759 if (!user
|| user
[0] == (char)0) {
1760 user
= talloc_strdup(frame
, smbc_getUser(context
));
1768 srv
= SMBC_server(frame
, context
, True
,
1769 server
, share
, &workgroup
, &user
, &password
);
1772 return -1; /* errno set by SMBC_server */
1775 if (! srv
->no_nt_session
) {
1776 ipc_srv
= SMBC_attr_server(frame
, context
, server
, share
,
1777 &workgroup
, &user
, &password
);
1779 srv
->no_nt_session
= True
;
1786 * Are they asking to set the entire set of known attributes?
1788 if (strcasecmp_m(name
, "system.*") == 0 ||
1789 strcasecmp_m(name
, "system.*+") == 0) {
1792 talloc_asprintf(talloc_tos(), "%s:%s",
1793 name
+7, (const char *) value
);
1802 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1803 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1806 ? SMBC_XATTR_MODE_SET
1807 : SMBC_XATTR_MODE_ADD
),
1813 /* get a DOS Attribute Descriptor with current attributes */
1814 dad
= dos_attr_query(context
, talloc_tos(), path
, srv
);
1816 /* Overwrite old with new, using what was provided */
1817 dos_attr_parse(context
, dad
, srv
, namevalue
);
1819 /* Set the new DOS attributes */
1820 if (! SMBC_setatr(context
, srv
, path
,
1827 /* cause failure if NT failed too */
1832 /* we only fail if both NT and DOS sets failed */
1833 if (ret
< 0 && ! dad
) {
1834 ret
= -1; /* in case dad was null */
1845 * Are they asking to set an access control element or to set
1846 * the entire access control list?
1848 if (strcasecmp_m(name
, "system.nt_sec_desc.*") == 0 ||
1849 strcasecmp_m(name
, "system.nt_sec_desc.*+") == 0 ||
1850 strcasecmp_m(name
, "system.nt_sec_desc.revision") == 0 ||
1851 strncasecmp_m(name
, "system.nt_sec_desc.acl", 22) == 0 ||
1852 strncasecmp_m(name
, "system.nt_sec_desc.acl+", 23) == 0) {
1856 talloc_asprintf(talloc_tos(), "%s:%s",
1857 name
+19, (const char *) value
);
1860 ret
= -1; /* errno set by SMBC_server() */
1862 else if (! namevalue
) {
1866 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1867 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1870 ? SMBC_XATTR_MODE_SET
1871 : SMBC_XATTR_MODE_ADD
),
1879 * Are they asking to set the owner?
1881 if (strcasecmp_m(name
, "system.nt_sec_desc.owner") == 0 ||
1882 strcasecmp_m(name
, "system.nt_sec_desc.owner+") == 0) {
1886 talloc_asprintf(talloc_tos(), "%s:%s",
1887 name
+19, (const char *) value
);
1890 ret
= -1; /* errno set by SMBC_server() */
1892 else if (! namevalue
) {
1896 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1897 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1898 namevalue
, SMBC_XATTR_MODE_CHOWN
, 0);
1905 * Are they asking to set the group?
1907 if (strcasecmp_m(name
, "system.nt_sec_desc.group") == 0 ||
1908 strcasecmp_m(name
, "system.nt_sec_desc.group+") == 0) {
1912 talloc_asprintf(talloc_tos(), "%s:%s",
1913 name
+19, (const char *) value
);
1916 /* errno set by SMBC_server() */
1919 else if (! namevalue
) {
1923 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1924 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1925 namevalue
, SMBC_XATTR_MODE_CHGRP
, 0);
1931 /* Determine whether to use old-style or new-style attribute names */
1932 if (context
->internal
->full_time_names
) {
1933 /* new-style names */
1934 attr_strings
.create_time_attr
= "system.dos_attr.CREATE_TIME";
1935 attr_strings
.access_time_attr
= "system.dos_attr.ACCESS_TIME";
1936 attr_strings
.write_time_attr
= "system.dos_attr.WRITE_TIME";
1937 attr_strings
.change_time_attr
= "system.dos_attr.CHANGE_TIME";
1939 /* old-style names */
1940 attr_strings
.create_time_attr
= NULL
;
1941 attr_strings
.access_time_attr
= "system.dos_attr.A_TIME";
1942 attr_strings
.write_time_attr
= "system.dos_attr.M_TIME";
1943 attr_strings
.change_time_attr
= "system.dos_attr.C_TIME";
1947 * Are they asking to set a DOS attribute?
1949 if (strcasecmp_m(name
, "system.dos_attr.*") == 0 ||
1950 strcasecmp_m(name
, "system.dos_attr.mode") == 0 ||
1951 (attr_strings
.create_time_attr
!= NULL
&&
1952 strcasecmp_m(name
, attr_strings
.create_time_attr
) == 0) ||
1953 strcasecmp_m(name
, attr_strings
.access_time_attr
) == 0 ||
1954 strcasecmp_m(name
, attr_strings
.write_time_attr
) == 0 ||
1955 strcasecmp_m(name
, attr_strings
.change_time_attr
) == 0) {
1957 /* get a DOS Attribute Descriptor with current attributes */
1958 dad
= dos_attr_query(context
, talloc_tos(), path
, srv
);
1961 talloc_asprintf(talloc_tos(), "%s:%s",
1962 name
+16, (const char *) value
);
1967 /* Overwrite old with provided new params */
1968 dos_attr_parse(context
, dad
, srv
, namevalue
);
1970 /* Set the new DOS attributes */
1971 ret2
= SMBC_setatr(context
, srv
, path
,
1978 /* ret2 has True (success) / False (failure) */
1993 /* Unsupported attribute name */
2000 SMBC_getxattr_ctx(SMBCCTX
*context
,
2007 SMBCSRV
*srv
= NULL
;
2008 SMBCSRV
*ipc_srv
= NULL
;
2009 char *server
= NULL
;
2012 char *password
= NULL
;
2013 char *workgroup
= NULL
;
2016 const char * create_time_attr
;
2017 const char * access_time_attr
;
2018 const char * write_time_attr
;
2019 const char * change_time_attr
;
2021 TALLOC_CTX
*frame
= talloc_stackframe();
2023 if (!context
|| !context
->internal
->initialized
) {
2024 errno
= EINVAL
; /* Best I can think of ... */
2035 DEBUG(4, ("smbc_getxattr(%s, %s)\n", fname
, name
));
2037 if (SMBC_parse_path(frame
,
2052 if (!user
|| user
[0] == (char)0) {
2053 user
= talloc_strdup(frame
, smbc_getUser(context
));
2061 srv
= SMBC_server(frame
, context
, True
,
2062 server
, share
, &workgroup
, &user
, &password
);
2065 return -1; /* errno set by SMBC_server */
2068 if (! srv
->no_nt_session
) {
2069 ipc_srv
= SMBC_attr_server(frame
, context
, server
, share
,
2070 &workgroup
, &user
, &password
);
2072 srv
->no_nt_session
= True
;
2078 /* Determine whether to use old-style or new-style attribute names */
2079 if (context
->internal
->full_time_names
) {
2080 /* new-style names */
2081 attr_strings
.create_time_attr
= "system.dos_attr.CREATE_TIME";
2082 attr_strings
.access_time_attr
= "system.dos_attr.ACCESS_TIME";
2083 attr_strings
.write_time_attr
= "system.dos_attr.WRITE_TIME";
2084 attr_strings
.change_time_attr
= "system.dos_attr.CHANGE_TIME";
2086 /* old-style names */
2087 attr_strings
.create_time_attr
= NULL
;
2088 attr_strings
.access_time_attr
= "system.dos_attr.A_TIME";
2089 attr_strings
.write_time_attr
= "system.dos_attr.M_TIME";
2090 attr_strings
.change_time_attr
= "system.dos_attr.C_TIME";
2093 /* Are they requesting a supported attribute? */
2094 if (strcasecmp_m(name
, "system.*") == 0 ||
2095 strncasecmp_m(name
, "system.*!", 9) == 0 ||
2096 strcasecmp_m(name
, "system.*+") == 0 ||
2097 strncasecmp_m(name
, "system.*+!", 10) == 0 ||
2098 strcasecmp_m(name
, "system.nt_sec_desc.*") == 0 ||
2099 strncasecmp_m(name
, "system.nt_sec_desc.*!", 21) == 0 ||
2100 strcasecmp_m(name
, "system.nt_sec_desc.*+") == 0 ||
2101 strncasecmp_m(name
, "system.nt_sec_desc.*+!", 22) == 0 ||
2102 strcasecmp_m(name
, "system.nt_sec_desc.revision") == 0 ||
2103 strcasecmp_m(name
, "system.nt_sec_desc.owner") == 0 ||
2104 strcasecmp_m(name
, "system.nt_sec_desc.owner+") == 0 ||
2105 strcasecmp_m(name
, "system.nt_sec_desc.group") == 0 ||
2106 strcasecmp_m(name
, "system.nt_sec_desc.group+") == 0 ||
2107 strncasecmp_m(name
, "system.nt_sec_desc.acl", 22) == 0 ||
2108 strncasecmp_m(name
, "system.nt_sec_desc.acl+", 23) == 0 ||
2109 strcasecmp_m(name
, "system.dos_attr.*") == 0 ||
2110 strncasecmp_m(name
, "system.dos_attr.*!", 18) == 0 ||
2111 strcasecmp_m(name
, "system.dos_attr.mode") == 0 ||
2112 strcasecmp_m(name
, "system.dos_attr.size") == 0 ||
2113 (attr_strings
.create_time_attr
!= NULL
&&
2114 strcasecmp_m(name
, attr_strings
.create_time_attr
) == 0) ||
2115 strcasecmp_m(name
, attr_strings
.access_time_attr
) == 0 ||
2116 strcasecmp_m(name
, attr_strings
.write_time_attr
) == 0 ||
2117 strcasecmp_m(name
, attr_strings
.change_time_attr
) == 0 ||
2118 strcasecmp_m(name
, "system.dos_attr.inode") == 0) {
2121 const char *filename
= name
;
2122 ret
= cacl_get(context
, talloc_tos(), srv
,
2123 ipc_srv
== NULL
? NULL
: ipc_srv
->cli
,
2124 &ipc_srv
->pol
, path
,
2126 discard_const_p(char, value
),
2128 if (ret
< 0 && errno
== 0) {
2129 errno
= SMBC_errno(context
, srv
->cli
);
2135 /* Unsupported attribute name */
2143 SMBC_removexattr_ctx(SMBCCTX
*context
,
2148 SMBCSRV
*srv
= NULL
;
2149 SMBCSRV
*ipc_srv
= NULL
;
2150 char *server
= NULL
;
2153 char *password
= NULL
;
2154 char *workgroup
= NULL
;
2156 TALLOC_CTX
*frame
= talloc_stackframe();
2158 if (!context
|| !context
->internal
->initialized
) {
2159 errno
= EINVAL
; /* Best I can think of ... */
2170 DEBUG(4, ("smbc_removexattr(%s, %s)\n", fname
, name
));
2172 if (SMBC_parse_path(frame
,
2187 if (!user
|| user
[0] == (char)0) {
2188 user
= talloc_strdup(frame
, smbc_getUser(context
));
2196 srv
= SMBC_server(frame
, context
, True
,
2197 server
, share
, &workgroup
, &user
, &password
);
2200 return -1; /* errno set by SMBC_server */
2203 if (! srv
->no_nt_session
) {
2204 ipc_srv
= SMBC_attr_server(frame
, context
, server
, share
,
2205 &workgroup
, &user
, &password
);
2207 srv
->no_nt_session
= True
;
2215 return -1; /* errno set by SMBC_attr_server */
2218 /* Are they asking to set the entire ACL? */
2219 if (strcasecmp_m(name
, "system.nt_sec_desc.*") == 0 ||
2220 strcasecmp_m(name
, "system.nt_sec_desc.*+") == 0) {
2223 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
2224 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
2225 NULL
, SMBC_XATTR_MODE_REMOVE_ALL
, 0);
2231 * Are they asking to remove one or more spceific security descriptor
2234 if (strcasecmp_m(name
, "system.nt_sec_desc.revision") == 0 ||
2235 strcasecmp_m(name
, "system.nt_sec_desc.owner") == 0 ||
2236 strcasecmp_m(name
, "system.nt_sec_desc.owner+") == 0 ||
2237 strcasecmp_m(name
, "system.nt_sec_desc.group") == 0 ||
2238 strcasecmp_m(name
, "system.nt_sec_desc.group+") == 0 ||
2239 strncasecmp_m(name
, "system.nt_sec_desc.acl", 22) == 0 ||
2240 strncasecmp_m(name
, "system.nt_sec_desc.acl+", 23) == 0) {
2243 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
2244 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
2245 discard_const_p(char, name
) + 19,
2246 SMBC_XATTR_MODE_REMOVE
, 0);
2251 /* Unsupported attribute name */
2258 SMBC_listxattr_ctx(SMBCCTX
*context
,
2264 * This isn't quite what listxattr() is supposed to do. This returns
2265 * the complete set of attribute names, always, rather than only those
2266 * attribute names which actually exist for a file. Hmmm...
2269 const char supported_old
[] =
2272 "system.nt_sec_desc.revision\0"
2273 "system.nt_sec_desc.owner\0"
2274 "system.nt_sec_desc.owner+\0"
2275 "system.nt_sec_desc.group\0"
2276 "system.nt_sec_desc.group+\0"
2277 "system.nt_sec_desc.acl.*\0"
2278 "system.nt_sec_desc.acl\0"
2279 "system.nt_sec_desc.acl+\0"
2280 "system.nt_sec_desc.*\0"
2281 "system.nt_sec_desc.*+\0"
2282 "system.dos_attr.*\0"
2283 "system.dos_attr.mode\0"
2284 "system.dos_attr.c_time\0"
2285 "system.dos_attr.a_time\0"
2286 "system.dos_attr.m_time\0"
2288 const char supported_new
[] =
2291 "system.nt_sec_desc.revision\0"
2292 "system.nt_sec_desc.owner\0"
2293 "system.nt_sec_desc.owner+\0"
2294 "system.nt_sec_desc.group\0"
2295 "system.nt_sec_desc.group+\0"
2296 "system.nt_sec_desc.acl.*\0"
2297 "system.nt_sec_desc.acl\0"
2298 "system.nt_sec_desc.acl+\0"
2299 "system.nt_sec_desc.*\0"
2300 "system.nt_sec_desc.*+\0"
2301 "system.dos_attr.*\0"
2302 "system.dos_attr.mode\0"
2303 "system.dos_attr.create_time\0"
2304 "system.dos_attr.access_time\0"
2305 "system.dos_attr.write_time\0"
2306 "system.dos_attr.change_time\0"
2308 const char * supported
;
2310 if (context
->internal
->full_time_names
) {
2311 supported
= supported_new
;
2312 retsize
= sizeof(supported_new
);
2314 supported
= supported_old
;
2315 retsize
= sizeof(supported_old
);
2322 if (retsize
> size
) {
2327 /* this can't be strcpy() because there are embedded null characters */
2328 memcpy(list
, supported
, retsize
);