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 (security_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 (security_ace_equal(&the_acl
->aces
[i
-1],
156 &the_acl
->aces
[i
])) {
158 for (j
=i
; j
<the_acl
->num_aces
-1; j
++) {
159 the_acl
->aces
[j
] = the_acl
->aces
[j
+1];
168 /* convert a SID to a string, either numeric or username/group */
170 convert_sid_to_string(struct cli_state
*ipc_cli
,
171 struct policy_handle
*pol
,
176 char **domains
= NULL
;
178 enum lsa_SidType
*types
= NULL
;
179 struct rpc_pipe_client
*pipe_hnd
= find_lsa_pipe_hnd(ipc_cli
);
182 sid_to_fstring(str
, sid
);
185 return; /* no lookup desired */
192 /* Ask LSA to convert the sid to a name */
194 ctx
= talloc_stackframe();
196 if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_sids(pipe_hnd
, ctx
,
197 pol
, 1, sid
, &domains
,
199 !domains
|| !domains
[0] || !names
|| !names
[0]) {
206 slprintf(str
, sizeof(fstring
) - 1, "%s%s%s",
207 domains
[0], lp_winbind_separator(),
213 /* convert a string to a SID, either numeric or username/group */
215 convert_string_to_sid(struct cli_state
*ipc_cli
,
216 struct policy_handle
*pol
,
221 enum lsa_SidType
*types
= NULL
;
222 struct dom_sid
*sids
= NULL
;
224 TALLOC_CTX
*ctx
= NULL
;
225 struct rpc_pipe_client
*pipe_hnd
= find_lsa_pipe_hnd(ipc_cli
);
232 if (strncmp(str
, "S-", 2) == 0) {
233 return string_to_sid(sid
, str
);
240 ctx
= talloc_stackframe();
241 if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_names(pipe_hnd
, ctx
,
249 sid_copy(sid
, &sids
[0]);
256 /* parse an struct security_ace in the same format as print_ace() */
258 parse_ace(struct cli_state
*ipc_cli
,
259 struct policy_handle
*pol
,
260 struct security_ace
*ace
,
272 const struct perm_value
*v
;
277 TALLOC_CTX
*frame
= talloc_stackframe();
279 /* These values discovered by inspection */
280 static const struct perm_value special_values
[] = {
290 static const struct perm_value standard_values
[] = {
291 { "READ", 0x001200a9 },
292 { "CHANGE", 0x001301bf },
293 { "FULL", 0x001f01ff },
298 p
= strchr_m(str
,':');
305 /* Try to parse numeric form */
307 if (sscanf(p
, "%u/%u/%u", &atype
, &aflags
, &amask
) == 3 &&
308 convert_string_to_sid(ipc_cli
, pol
, numeric
, &sid
, str
)) {
312 /* Try to parse text form */
314 if (!convert_string_to_sid(ipc_cli
, pol
, numeric
, &sid
, str
)) {
320 if (!next_token_talloc(frame
, &cp
, &tok
, "/")) {
325 if (strncasecmp_m(tok
, "ALLOWED", strlen("ALLOWED")) == 0) {
326 atype
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
327 } else if (strncasecmp_m(tok
, "DENIED", strlen("DENIED")) == 0) {
328 atype
= SEC_ACE_TYPE_ACCESS_DENIED
;
334 /* Only numeric form accepted for flags at present */
336 if (!(next_token_talloc(frame
, &cp
, &tok
, "/") &&
337 sscanf(tok
, "%u", &aflags
))) {
342 if (!next_token_talloc(frame
, &cp
, &tok
, "/")) {
347 if (strncmp(tok
, "0x", 2) == 0) {
348 if (sscanf(tok
, "%u", &amask
) != 1) {
355 for (v
= standard_values
; v
!= NULL
; v
++) {
356 if (strcmp(tok
, v
->perm
) == 0) {
367 for (v
= special_values
; v
!= NULL
; v
++) {
368 if (v
->perm
[0] == *p
) {
388 init_sec_ace(ace
, &sid
, atype
, mask
, aflags
);
393 /* add an struct security_ace to a list of struct security_aces in a struct security_acl */
395 add_ace(struct security_acl
**the_acl
,
396 struct security_ace
*ace
,
399 struct security_acl
*newacl
;
400 struct security_ace
*aces
;
403 (*the_acl
) = make_sec_acl(ctx
, 3, 1, ace
);
407 if ((aces
= SMB_CALLOC_ARRAY(struct security_ace
,
408 1+(*the_acl
)->num_aces
)) == NULL
) {
411 memcpy(aces
, (*the_acl
)->aces
, (*the_acl
)->num_aces
* sizeof(struct security_ace
));
412 memcpy(aces
+(*the_acl
)->num_aces
, ace
, sizeof(struct security_ace
));
413 newacl
= make_sec_acl(ctx
, (*the_acl
)->revision
,
414 1+(*the_acl
)->num_aces
, aces
);
421 /* parse a ascii version of a security descriptor */
422 static struct security_descriptor
*
423 sec_desc_parse(TALLOC_CTX
*ctx
,
424 struct cli_state
*ipc_cli
,
425 struct policy_handle
*pol
,
431 struct security_descriptor
*ret
= NULL
;
433 struct dom_sid
*group_sid
=NULL
;
434 struct dom_sid
*owner_sid
=NULL
;
435 struct security_acl
*dacl
=NULL
;
438 while (next_token_talloc(ctx
, &p
, &tok
, "\t,\r\n")) {
440 if (strncasecmp_m(tok
,"REVISION:", 9) == 0) {
441 revision
= strtol(tok
+9, NULL
, 16);
445 if (strncasecmp_m(tok
,"OWNER:", 6) == 0) {
447 DEBUG(5,("OWNER specified more than once!\n"));
450 owner_sid
= SMB_CALLOC_ARRAY(struct dom_sid
, 1);
452 !convert_string_to_sid(ipc_cli
, pol
,
455 DEBUG(5, ("Failed to parse owner sid\n"));
461 if (strncasecmp_m(tok
,"OWNER+:", 7) == 0) {
463 DEBUG(5,("OWNER specified more than once!\n"));
466 owner_sid
= SMB_CALLOC_ARRAY(struct dom_sid
, 1);
468 !convert_string_to_sid(ipc_cli
, pol
,
471 DEBUG(5, ("Failed to parse owner sid\n"));
477 if (strncasecmp_m(tok
,"GROUP:", 6) == 0) {
479 DEBUG(5,("GROUP specified more than once!\n"));
482 group_sid
= SMB_CALLOC_ARRAY(struct dom_sid
, 1);
484 !convert_string_to_sid(ipc_cli
, pol
,
487 DEBUG(5, ("Failed to parse group sid\n"));
493 if (strncasecmp_m(tok
,"GROUP+:", 7) == 0) {
495 DEBUG(5,("GROUP specified more than once!\n"));
498 group_sid
= SMB_CALLOC_ARRAY(struct dom_sid
, 1);
500 !convert_string_to_sid(ipc_cli
, pol
,
503 DEBUG(5, ("Failed to parse group sid\n"));
509 if (strncasecmp_m(tok
,"ACL:", 4) == 0) {
510 struct security_ace ace
;
511 if (!parse_ace(ipc_cli
, pol
, &ace
, numeric
, tok
+4)) {
512 DEBUG(5, ("Failed to parse ACL %s\n", tok
));
515 if(!add_ace(&dacl
, &ace
, ctx
)) {
516 DEBUG(5, ("Failed to add ACL %s\n", tok
));
522 if (strncasecmp_m(tok
,"ACL+:", 5) == 0) {
523 struct security_ace ace
;
524 if (!parse_ace(ipc_cli
, pol
, &ace
, False
, tok
+5)) {
525 DEBUG(5, ("Failed to parse ACL %s\n", tok
));
528 if(!add_ace(&dacl
, &ace
, ctx
)) {
529 DEBUG(5, ("Failed to add ACL %s\n", tok
));
535 DEBUG(5, ("Failed to parse security descriptor\n"));
539 ret
= make_sec_desc(ctx
, revision
, SEC_DESC_SELF_RELATIVE
,
540 owner_sid
, group_sid
, NULL
, dacl
, &sd_size
);
543 SAFE_FREE(group_sid
);
544 SAFE_FREE(owner_sid
);
549 /* Obtain the current dos attributes */
550 static DOS_ATTR_DESC
*
551 dos_attr_query(SMBCCTX
*context
,
553 const char *filename
,
556 struct timespec create_time_ts
;
557 struct timespec write_time_ts
;
558 struct timespec access_time_ts
;
559 struct timespec change_time_ts
;
565 ret
= talloc(ctx
, DOS_ATTR_DESC
);
571 /* Obtain the DOS attributes */
572 if (!SMBC_getatr(context
, srv
, filename
,
579 errno
= SMBC_errno(context
, srv
->cli
);
580 DEBUG(5, ("dos_attr_query Failed to query old attributes\n"));
587 ret
->create_time
= convert_timespec_to_time_t(create_time_ts
);
588 ret
->access_time
= convert_timespec_to_time_t(access_time_ts
);
589 ret
->write_time
= convert_timespec_to_time_t(write_time_ts
);
590 ret
->change_time
= convert_timespec_to_time_t(change_time_ts
);
597 /* parse a ascii version of a security descriptor */
599 dos_attr_parse(SMBCCTX
*context
,
607 TALLOC_CTX
*frame
= NULL
;
609 const char * create_time_attr
;
610 const char * access_time_attr
;
611 const char * write_time_attr
;
612 const char * change_time_attr
;
615 /* Determine whether to use old-style or new-style attribute names */
616 if (context
->internal
->full_time_names
) {
617 /* new-style names */
618 attr_strings
.create_time_attr
= "CREATE_TIME";
619 attr_strings
.access_time_attr
= "ACCESS_TIME";
620 attr_strings
.write_time_attr
= "WRITE_TIME";
621 attr_strings
.change_time_attr
= "CHANGE_TIME";
623 /* old-style names */
624 attr_strings
.create_time_attr
= NULL
;
625 attr_strings
.access_time_attr
= "A_TIME";
626 attr_strings
.write_time_attr
= "M_TIME";
627 attr_strings
.change_time_attr
= "C_TIME";
630 /* if this is to set the entire ACL... */
632 /* ... then increment past the first colon if there is one */
633 if ((p
= strchr(str
, ':')) != NULL
) {
640 frame
= talloc_stackframe();
641 while (next_token_talloc(frame
, &p
, &tok
, "\t,\r\n")) {
642 if (strncasecmp_m(tok
, "MODE:", 5) == 0) {
643 long request
= strtol(tok
+5, NULL
, 16);
645 dad
->mode
= (request
|
646 (IS_DOS_DIR(dad
->mode
)
647 ? FILE_ATTRIBUTE_DIRECTORY
648 : FILE_ATTRIBUTE_NORMAL
));
655 if (strncasecmp_m(tok
, "SIZE:", 5) == 0) {
656 dad
->size
= (off_t
)atof(tok
+5);
660 n
= strlen(attr_strings
.access_time_attr
);
661 if (strncasecmp_m(tok
, attr_strings
.access_time_attr
, n
) == 0) {
662 dad
->access_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
666 n
= strlen(attr_strings
.change_time_attr
);
667 if (strncasecmp_m(tok
, attr_strings
.change_time_attr
, n
) == 0) {
668 dad
->change_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
672 n
= strlen(attr_strings
.write_time_attr
);
673 if (strncasecmp_m(tok
, attr_strings
.write_time_attr
, n
) == 0) {
674 dad
->write_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
678 if (attr_strings
.create_time_attr
!= NULL
) {
679 n
= strlen(attr_strings
.create_time_attr
);
680 if (strncasecmp_m(tok
, attr_strings
.create_time_attr
,
682 dad
->create_time
= (time_t)strtol(tok
+n
+1,
688 if (strncasecmp_m(tok
, "INODE:", 6) == 0) {
689 dad
->inode
= (SMB_INO_T
)atof(tok
+6);
696 /*****************************************************
697 Retrieve the acls for a file.
698 *******************************************************/
701 cacl_get(SMBCCTX
*context
,
704 struct cli_state
*ipc_cli
,
705 struct policy_handle
*pol
,
706 const char *filename
,
707 const char *attr_name
,
720 bool exclude_nt_revision
= False
;
721 bool exclude_nt_owner
= False
;
722 bool exclude_nt_group
= False
;
723 bool exclude_nt_acl
= False
;
724 bool exclude_dos_mode
= False
;
725 bool exclude_dos_size
= False
;
726 bool exclude_dos_create_time
= False
;
727 bool exclude_dos_access_time
= False
;
728 bool exclude_dos_write_time
= False
;
729 bool exclude_dos_change_time
= False
;
730 bool exclude_dos_inode
= False
;
732 bool determine_size
= (bufsize
== 0);
734 struct security_descriptor
*sd
;
736 fstring name_sandbox
;
740 struct timespec create_time_ts
;
741 struct timespec write_time_ts
;
742 struct timespec access_time_ts
;
743 struct timespec change_time_ts
;
744 time_t create_time
= (time_t)0;
745 time_t write_time
= (time_t)0;
746 time_t access_time
= (time_t)0;
747 time_t change_time
= (time_t)0;
751 struct cli_state
*cli
= srv
->cli
;
753 const char * create_time_attr
;
754 const char * access_time_attr
;
755 const char * write_time_attr
;
756 const char * change_time_attr
;
759 const char * create_time_attr
;
760 const char * access_time_attr
;
761 const char * write_time_attr
;
762 const char * change_time_attr
;
765 /* Determine whether to use old-style or new-style attribute names */
766 if (context
->internal
->full_time_names
) {
767 /* new-style names */
768 attr_strings
.create_time_attr
= "CREATE_TIME";
769 attr_strings
.access_time_attr
= "ACCESS_TIME";
770 attr_strings
.write_time_attr
= "WRITE_TIME";
771 attr_strings
.change_time_attr
= "CHANGE_TIME";
773 excl_attr_strings
.create_time_attr
= "CREATE_TIME";
774 excl_attr_strings
.access_time_attr
= "ACCESS_TIME";
775 excl_attr_strings
.write_time_attr
= "WRITE_TIME";
776 excl_attr_strings
.change_time_attr
= "CHANGE_TIME";
778 /* old-style names */
779 attr_strings
.create_time_attr
= NULL
;
780 attr_strings
.access_time_attr
= "A_TIME";
781 attr_strings
.write_time_attr
= "M_TIME";
782 attr_strings
.change_time_attr
= "C_TIME";
784 excl_attr_strings
.create_time_attr
= NULL
;
785 excl_attr_strings
.access_time_attr
= "dos_attr.A_TIME";
786 excl_attr_strings
.write_time_attr
= "dos_attr.M_TIME";
787 excl_attr_strings
.change_time_attr
= "dos_attr.C_TIME";
790 /* Copy name so we can strip off exclusions (if any are specified) */
791 strncpy(name_sandbox
, attr_name
, sizeof(name_sandbox
) - 1);
793 /* Ensure name is null terminated */
794 name_sandbox
[sizeof(name_sandbox
) - 1] = '\0';
796 /* Play in the sandbox */
799 /* If there are any exclusions, point to them and mask them from name */
800 if ((pExclude
= strchr(name
, '!')) != NULL
)
805 all
= (strncasecmp_m(name
, "system.*", 8) == 0);
806 all_nt
= (strncasecmp_m(name
, "system.nt_sec_desc.*", 20) == 0);
807 all_nt_acls
= (strncasecmp_m(name
, "system.nt_sec_desc.acl.*", 24) == 0);
808 all_dos
= (strncasecmp_m(name
, "system.dos_attr.*", 17) == 0);
809 some_nt
= (strncasecmp_m(name
, "system.nt_sec_desc.", 19) == 0);
810 some_dos
= (strncasecmp_m(name
, "system.dos_attr.", 16) == 0);
811 numeric
= (* (name
+ strlen(name
) - 1) != '+');
813 /* Look for exclusions from "all" requests */
814 if (all
|| all_nt
|| all_dos
) {
815 /* Exclusions are delimited by '!' */
818 pExclude
= (p
== NULL
? NULL
: p
+ 1)) {
820 /* Find end of this exclusion name */
821 if ((p
= strchr(pExclude
, '!')) != NULL
)
826 /* Which exclusion name is this? */
827 if (strcasecmp_m(pExclude
,
828 "nt_sec_desc.revision") == 0) {
829 exclude_nt_revision
= True
;
831 else if (strcasecmp_m(pExclude
,
832 "nt_sec_desc.owner") == 0) {
833 exclude_nt_owner
= True
;
835 else if (strcasecmp_m(pExclude
,
836 "nt_sec_desc.group") == 0) {
837 exclude_nt_group
= True
;
839 else if (strcasecmp_m(pExclude
,
840 "nt_sec_desc.acl") == 0) {
841 exclude_nt_acl
= True
;
843 else if (strcasecmp_m(pExclude
,
844 "dos_attr.mode") == 0) {
845 exclude_dos_mode
= True
;
847 else if (strcasecmp_m(pExclude
,
848 "dos_attr.size") == 0) {
849 exclude_dos_size
= True
;
851 else if (excl_attr_strings
.create_time_attr
!= NULL
&&
852 strcasecmp_m(pExclude
,
853 excl_attr_strings
.change_time_attr
) == 0) {
854 exclude_dos_create_time
= True
;
856 else if (strcasecmp_m(pExclude
,
857 excl_attr_strings
.access_time_attr
) == 0) {
858 exclude_dos_access_time
= True
;
860 else if (strcasecmp_m(pExclude
,
861 excl_attr_strings
.write_time_attr
) == 0) {
862 exclude_dos_write_time
= True
;
864 else if (strcasecmp_m(pExclude
,
865 excl_attr_strings
.change_time_attr
) == 0) {
866 exclude_dos_change_time
= True
;
868 else if (strcasecmp_m(pExclude
, "dos_attr.inode") == 0) {
869 exclude_dos_inode
= True
;
872 DEBUG(5, ("cacl_get received unknown exclusion: %s\n",
883 * If we are (possibly) talking to an NT or new system and some NT
884 * attributes have been requested...
886 if (ipc_cli
&& (all
|| some_nt
|| all_nt_acls
)) {
887 char *targetpath
= NULL
;
888 struct cli_state
*targetcli
= NULL
;
891 /* Point to the portion after "system.nt_sec_desc." */
892 name
+= 19; /* if (all) this will be invalid but unused */
894 status
= cli_resolve_path(
895 ctx
, "", context
->internal
->auth_info
,
896 cli
, filename
, &targetcli
, &targetpath
);
897 if (!NT_STATUS_IS_OK(status
)) {
898 DEBUG(5, ("cacl_get Could not resolve %s\n",
904 /* ... then obtain any NT attributes which were requested */
905 status
= cli_ntcreate(targetcli
, targetpath
, 0,
906 CREATE_ACCESS_READ
, 0,
907 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
908 FILE_OPEN
, 0x0, 0x0, &fnum
, NULL
);
909 if (!NT_STATUS_IS_OK(status
)) {
910 DEBUG(5, ("cacl_get failed to open %s: %s\n",
911 targetpath
, nt_errstr(status
)));
916 status
= cli_query_secdesc(targetcli
, fnum
, ctx
, &sd
);
917 if (!NT_STATUS_IS_OK(status
)) {
918 DEBUG(5,("cacl_get Failed to query old descriptor "
920 targetpath
, nt_errstr(status
)));
925 cli_close(targetcli
, fnum
);
927 if (! exclude_nt_revision
) {
929 if (determine_size
) {
930 p
= talloc_asprintf(ctx
,
939 n
= snprintf(buf
, bufsize
,
943 } else if (strcasecmp_m(name
, "revision") == 0) {
944 if (determine_size
) {
945 p
= talloc_asprintf(ctx
, "%d",
953 n
= snprintf(buf
, bufsize
, "%d",
958 if (!determine_size
&& n
> bufsize
) {
968 if (! exclude_nt_owner
) {
969 /* Get owner and group sid */
971 convert_sid_to_string(ipc_cli
, pol
,
980 if (determine_size
) {
981 p
= talloc_asprintf(ctx
, ",OWNER:%s",
988 } else if (sidstr
[0] != '\0') {
989 n
= snprintf(buf
, bufsize
,
990 ",OWNER:%s", sidstr
);
992 } else if (strncasecmp_m(name
, "owner", 5) == 0) {
993 if (determine_size
) {
994 p
= talloc_asprintf(ctx
, "%s", sidstr
);
1001 n
= snprintf(buf
, bufsize
, "%s",
1006 if (!determine_size
&& n
> bufsize
) {
1016 if (! exclude_nt_group
) {
1017 if (sd
->group_sid
) {
1018 convert_sid_to_string(ipc_cli
, pol
,
1022 fstrcpy(sidstr
, "");
1025 if (all
|| all_nt
) {
1026 if (determine_size
) {
1027 p
= talloc_asprintf(ctx
, ",GROUP:%s",
1034 } else if (sidstr
[0] != '\0') {
1035 n
= snprintf(buf
, bufsize
,
1036 ",GROUP:%s", sidstr
);
1038 } else if (strncasecmp_m(name
, "group", 5) == 0) {
1039 if (determine_size
) {
1040 p
= talloc_asprintf(ctx
, "%s", sidstr
);
1047 n
= snprintf(buf
, bufsize
,
1052 if (!determine_size
&& n
> bufsize
) {
1062 if (! exclude_nt_acl
) {
1063 /* Add aces to value buffer */
1064 for (i
= 0; sd
->dacl
&& i
< sd
->dacl
->num_aces
; i
++) {
1066 struct security_ace
*ace
= &sd
->dacl
->aces
[i
];
1067 convert_sid_to_string(ipc_cli
, pol
,
1071 if (all
|| all_nt
) {
1072 if (determine_size
) {
1073 p
= talloc_asprintf(
1089 ",ACL:%s:%d/%d/0x%08x",
1095 } else if ((strncasecmp_m(name
, "acl", 3) == 0 &&
1096 strcasecmp_m(name
+3, sidstr
) == 0) ||
1097 (strncasecmp_m(name
, "acl+", 4) == 0 &&
1098 strcasecmp_m(name
+4, sidstr
) == 0)) {
1099 if (determine_size
) {
1100 p
= talloc_asprintf(
1112 n
= snprintf(buf
, bufsize
,
1118 } else if (all_nt_acls
) {
1119 if (determine_size
) {
1120 p
= talloc_asprintf(
1122 "%s%s:%d/%d/0x%08x",
1134 n
= snprintf(buf
, bufsize
,
1135 "%s%s:%d/%d/0x%08x",
1143 if (!determine_size
&& n
> bufsize
) {
1154 /* Restore name pointer to its original value */
1158 if (all
|| some_dos
) {
1159 /* Point to the portion after "system.dos_attr." */
1160 name
+= 16; /* if (all) this will be invalid but unused */
1162 /* Obtain the DOS attributes */
1163 if (!SMBC_getatr(context
, srv
, filename
, &mode
, &size
,
1170 errno
= SMBC_errno(context
, srv
->cli
);
1174 create_time
= convert_timespec_to_time_t(create_time_ts
);
1175 access_time
= convert_timespec_to_time_t(access_time_ts
);
1176 write_time
= convert_timespec_to_time_t(write_time_ts
);
1177 change_time
= convert_timespec_to_time_t(change_time_ts
);
1179 if (! exclude_dos_mode
) {
1180 if (all
|| all_dos
) {
1181 if (determine_size
) {
1182 p
= talloc_asprintf(ctx
,
1195 n
= snprintf(buf
, bufsize
,
1203 } else if (strcasecmp_m(name
, "mode") == 0) {
1204 if (determine_size
) {
1205 p
= talloc_asprintf(ctx
, "0x%x", mode
);
1212 n
= snprintf(buf
, bufsize
,
1217 if (!determine_size
&& n
> bufsize
) {
1227 if (! exclude_dos_size
) {
1228 if (all
|| all_dos
) {
1229 if (determine_size
) {
1230 p
= talloc_asprintf(
1240 n
= snprintf(buf
, bufsize
,
1244 } else if (strcasecmp_m(name
, "size") == 0) {
1245 if (determine_size
) {
1246 p
= talloc_asprintf(
1256 n
= snprintf(buf
, bufsize
,
1262 if (!determine_size
&& n
> bufsize
) {
1272 if (! exclude_dos_create_time
&&
1273 attr_strings
.create_time_attr
!= NULL
) {
1274 if (all
|| all_dos
) {
1275 if (determine_size
) {
1276 p
= talloc_asprintf(ctx
,
1278 attr_strings
.create_time_attr
,
1279 (unsigned long) create_time
);
1286 n
= snprintf(buf
, bufsize
,
1288 attr_strings
.create_time_attr
,
1289 (unsigned long) create_time
);
1291 } else if (strcasecmp_m(name
, attr_strings
.create_time_attr
) == 0) {
1292 if (determine_size
) {
1293 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) create_time
);
1300 n
= snprintf(buf
, bufsize
,
1301 "%lu", (unsigned long) create_time
);
1305 if (!determine_size
&& n
> bufsize
) {
1315 if (! exclude_dos_access_time
) {
1316 if (all
|| all_dos
) {
1317 if (determine_size
) {
1318 p
= talloc_asprintf(ctx
,
1320 attr_strings
.access_time_attr
,
1321 (unsigned long) access_time
);
1328 n
= snprintf(buf
, bufsize
,
1330 attr_strings
.access_time_attr
,
1331 (unsigned long) access_time
);
1333 } else if (strcasecmp_m(name
, attr_strings
.access_time_attr
) == 0) {
1334 if (determine_size
) {
1335 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) access_time
);
1342 n
= snprintf(buf
, bufsize
,
1343 "%lu", (unsigned long) access_time
);
1347 if (!determine_size
&& n
> bufsize
) {
1357 if (! exclude_dos_write_time
) {
1358 if (all
|| all_dos
) {
1359 if (determine_size
) {
1360 p
= talloc_asprintf(ctx
,
1362 attr_strings
.write_time_attr
,
1363 (unsigned long) write_time
);
1370 n
= snprintf(buf
, bufsize
,
1372 attr_strings
.write_time_attr
,
1373 (unsigned long) write_time
);
1375 } else if (strcasecmp_m(name
, attr_strings
.write_time_attr
) == 0) {
1376 if (determine_size
) {
1377 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) write_time
);
1384 n
= snprintf(buf
, bufsize
,
1385 "%lu", (unsigned long) write_time
);
1389 if (!determine_size
&& n
> bufsize
) {
1399 if (! exclude_dos_change_time
) {
1400 if (all
|| all_dos
) {
1401 if (determine_size
) {
1402 p
= talloc_asprintf(ctx
,
1404 attr_strings
.change_time_attr
,
1405 (unsigned long) change_time
);
1412 n
= snprintf(buf
, bufsize
,
1414 attr_strings
.change_time_attr
,
1415 (unsigned long) change_time
);
1417 } else if (strcasecmp_m(name
, attr_strings
.change_time_attr
) == 0) {
1418 if (determine_size
) {
1419 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) change_time
);
1426 n
= snprintf(buf
, bufsize
,
1427 "%lu", (unsigned long) change_time
);
1431 if (!determine_size
&& n
> bufsize
) {
1441 if (! exclude_dos_inode
) {
1442 if (all
|| all_dos
) {
1443 if (determine_size
) {
1444 p
= talloc_asprintf(
1454 n
= snprintf(buf
, bufsize
,
1458 } else if (strcasecmp_m(name
, "inode") == 0) {
1459 if (determine_size
) {
1460 p
= talloc_asprintf(
1470 n
= snprintf(buf
, bufsize
,
1476 if (!determine_size
&& n
> bufsize
) {
1486 /* Restore name pointer to its original value */
1498 /*****************************************************
1499 set the ACLs on a file given an ascii description
1500 *******************************************************/
1502 cacl_set(SMBCCTX
*context
,
1504 struct cli_state
*cli
,
1505 struct cli_state
*ipc_cli
,
1506 struct policy_handle
*pol
,
1507 const char *filename
,
1512 uint16_t fnum
= (uint16_t)-1;
1514 struct security_descriptor
*sd
= NULL
, *old
;
1515 struct security_acl
*dacl
= NULL
;
1516 struct dom_sid
*owner_sid
= NULL
;
1517 struct dom_sid
*group_sid
= NULL
;
1522 bool numeric
= True
;
1523 char *targetpath
= NULL
;
1524 struct cli_state
*targetcli
= NULL
;
1527 /* the_acl will be null for REMOVE_ALL operations */
1529 numeric
= ((p
= strchr(the_acl
, ':')) != NULL
&&
1533 /* if this is to set the entire ACL... */
1534 if (*the_acl
== '*') {
1535 /* ... then increment past the first colon */
1539 sd
= sec_desc_parse(ctx
, ipc_cli
, pol
, numeric
, the_acl
);
1546 /* SMBC_XATTR_MODE_REMOVE_ALL is the only caller
1547 that doesn't deref sd */
1549 if (!sd
&& (mode
!= SMBC_XATTR_MODE_REMOVE_ALL
)) {
1554 status
= cli_resolve_path(ctx
, "", context
->internal
->auth_info
,
1555 cli
, filename
, &targetcli
, &targetpath
);
1556 if (!NT_STATUS_IS_OK(status
)) {
1557 DEBUG(5,("cacl_set: Could not resolve %s\n", filename
));
1562 /* The desired access below is the only one I could find that works
1563 with NT4, W2KP and Samba */
1565 status
= cli_ntcreate(targetcli
, targetpath
, 0, CREATE_ACCESS_READ
, 0,
1566 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
,
1567 0x0, 0x0, &fnum
, NULL
);
1568 if (!NT_STATUS_IS_OK(status
)) {
1569 DEBUG(5, ("cacl_set failed to open %s: %s\n",
1570 targetpath
, nt_errstr(status
)));
1575 status
= cli_query_secdesc(targetcli
, fnum
, ctx
, &old
);
1576 if (!NT_STATUS_IS_OK(status
)) {
1577 DEBUG(5,("cacl_set Failed to query old descriptor of %s: %s\n",
1578 targetpath
, nt_errstr(status
)));
1583 cli_close(targetcli
, fnum
);
1586 case SMBC_XATTR_MODE_REMOVE_ALL
:
1587 old
->dacl
->num_aces
= 0;
1591 case SMBC_XATTR_MODE_REMOVE
:
1592 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1595 for (j
=0;old
->dacl
&& j
<old
->dacl
->num_aces
;j
++) {
1596 if (security_ace_equal(&sd
->dacl
->aces
[i
],
1597 &old
->dacl
->aces
[j
])) {
1599 for (k
=j
; k
<old
->dacl
->num_aces
-1;k
++) {
1600 old
->dacl
->aces
[k
] =
1601 old
->dacl
->aces
[k
+1];
1603 old
->dacl
->num_aces
--;
1618 case SMBC_XATTR_MODE_ADD
:
1619 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1622 for (j
=0;old
->dacl
&& j
<old
->dacl
->num_aces
;j
++) {
1623 if (dom_sid_equal(&sd
->dacl
->aces
[i
].trustee
,
1624 &old
->dacl
->aces
[j
].trustee
)) {
1625 if (!(flags
& SMBC_XATTR_FLAG_CREATE
)) {
1630 old
->dacl
->aces
[j
] = sd
->dacl
->aces
[i
];
1636 if (!found
&& (flags
& SMBC_XATTR_FLAG_REPLACE
)) {
1642 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1643 add_ace(&old
->dacl
, &sd
->dacl
->aces
[i
], ctx
);
1649 case SMBC_XATTR_MODE_SET
:
1651 owner_sid
= old
->owner_sid
;
1652 group_sid
= old
->group_sid
;
1656 case SMBC_XATTR_MODE_CHOWN
:
1657 owner_sid
= sd
->owner_sid
;
1660 case SMBC_XATTR_MODE_CHGRP
:
1661 group_sid
= sd
->group_sid
;
1665 /* Denied ACE entries must come before allowed ones */
1666 sort_acl(old
->dacl
);
1668 /* Create new security descriptor and set it */
1669 sd
= make_sec_desc(ctx
, old
->revision
, SEC_DESC_SELF_RELATIVE
,
1670 owner_sid
, group_sid
, NULL
, dacl
, &sd_size
);
1672 status
= cli_ntcreate(targetcli
, targetpath
, 0,
1673 WRITE_DAC_ACCESS
| WRITE_OWNER_ACCESS
, 0,
1674 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
,
1675 0x0, 0x0, &fnum
, NULL
);
1676 if (!NT_STATUS_IS_OK(status
)) {
1677 DEBUG(5, ("cacl_set failed to open %s: %s\n",
1678 targetpath
, nt_errstr(status
)));
1683 status
= cli_set_secdesc(targetcli
, fnum
, sd
);
1684 if (!NT_STATUS_IS_OK(status
)) {
1685 DEBUG(5, ("ERROR: secdesc set failed: %s\n",
1686 nt_errstr(status
)));
1693 cli_close(targetcli
, fnum
);
1704 SMBC_setxattr_ctx(SMBCCTX
*context
,
1713 SMBCSRV
*srv
= NULL
;
1714 SMBCSRV
*ipc_srv
= NULL
;
1715 char *server
= NULL
;
1718 char *password
= NULL
;
1719 char *workgroup
= NULL
;
1721 DOS_ATTR_DESC
*dad
= NULL
;
1723 const char * create_time_attr
;
1724 const char * access_time_attr
;
1725 const char * write_time_attr
;
1726 const char * change_time_attr
;
1729 TALLOC_CTX
*frame
= talloc_stackframe();
1731 if (!context
|| !context
->internal
->initialized
) {
1732 errno
= EINVAL
; /* Best I can think of ... */
1743 DEBUG(4, ("smbc_setxattr(%s, %s, %.*s)\n",
1744 fname
, name
, (int) size
, (const char*)value
));
1746 if (SMBC_parse_path(frame
,
1762 if (!user
|| user
[0] == (char)0) {
1763 user
= talloc_strdup(frame
, smbc_getUser(context
));
1771 srv
= SMBC_server(frame
, context
, True
,
1772 server
, port
, share
, &workgroup
, &user
, &password
);
1775 return -1; /* errno set by SMBC_server */
1778 if (! srv
->no_nt_session
) {
1779 ipc_srv
= SMBC_attr_server(frame
, context
, server
, port
, share
,
1780 &workgroup
, &user
, &password
);
1782 srv
->no_nt_session
= True
;
1789 * Are they asking to set the entire set of known attributes?
1791 if (strcasecmp_m(name
, "system.*") == 0 ||
1792 strcasecmp_m(name
, "system.*+") == 0) {
1795 talloc_asprintf(talloc_tos(), "%s:%s",
1796 name
+7, (const char *) value
);
1805 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1806 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1809 ? SMBC_XATTR_MODE_SET
1810 : SMBC_XATTR_MODE_ADD
),
1816 /* get a DOS Attribute Descriptor with current attributes */
1817 dad
= dos_attr_query(context
, talloc_tos(), path
, srv
);
1819 /* Overwrite old with new, using what was provided */
1820 dos_attr_parse(context
, dad
, srv
, namevalue
);
1822 /* Set the new DOS attributes */
1823 if (! SMBC_setatr(context
, srv
, path
,
1830 /* cause failure if NT failed too */
1835 /* we only fail if both NT and DOS sets failed */
1836 if (ret
< 0 && ! dad
) {
1837 ret
= -1; /* in case dad was null */
1848 * Are they asking to set an access control element or to set
1849 * the entire access control list?
1851 if (strcasecmp_m(name
, "system.nt_sec_desc.*") == 0 ||
1852 strcasecmp_m(name
, "system.nt_sec_desc.*+") == 0 ||
1853 strcasecmp_m(name
, "system.nt_sec_desc.revision") == 0 ||
1854 strncasecmp_m(name
, "system.nt_sec_desc.acl", 22) == 0 ||
1855 strncasecmp_m(name
, "system.nt_sec_desc.acl+", 23) == 0) {
1859 talloc_asprintf(talloc_tos(), "%s:%s",
1860 name
+19, (const char *) value
);
1863 ret
= -1; /* errno set by SMBC_server() */
1865 else if (! namevalue
) {
1869 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1870 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1873 ? SMBC_XATTR_MODE_SET
1874 : SMBC_XATTR_MODE_ADD
),
1882 * Are they asking to set the owner?
1884 if (strcasecmp_m(name
, "system.nt_sec_desc.owner") == 0 ||
1885 strcasecmp_m(name
, "system.nt_sec_desc.owner+") == 0) {
1889 talloc_asprintf(talloc_tos(), "%s:%s",
1890 name
+19, (const char *) value
);
1893 ret
= -1; /* errno set by SMBC_server() */
1895 else if (! namevalue
) {
1899 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1900 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1901 namevalue
, SMBC_XATTR_MODE_CHOWN
, 0);
1908 * Are they asking to set the group?
1910 if (strcasecmp_m(name
, "system.nt_sec_desc.group") == 0 ||
1911 strcasecmp_m(name
, "system.nt_sec_desc.group+") == 0) {
1915 talloc_asprintf(talloc_tos(), "%s:%s",
1916 name
+19, (const char *) value
);
1919 /* errno set by SMBC_server() */
1922 else if (! namevalue
) {
1926 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1927 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1928 namevalue
, SMBC_XATTR_MODE_CHGRP
, 0);
1934 /* Determine whether to use old-style or new-style attribute names */
1935 if (context
->internal
->full_time_names
) {
1936 /* new-style names */
1937 attr_strings
.create_time_attr
= "system.dos_attr.CREATE_TIME";
1938 attr_strings
.access_time_attr
= "system.dos_attr.ACCESS_TIME";
1939 attr_strings
.write_time_attr
= "system.dos_attr.WRITE_TIME";
1940 attr_strings
.change_time_attr
= "system.dos_attr.CHANGE_TIME";
1942 /* old-style names */
1943 attr_strings
.create_time_attr
= NULL
;
1944 attr_strings
.access_time_attr
= "system.dos_attr.A_TIME";
1945 attr_strings
.write_time_attr
= "system.dos_attr.M_TIME";
1946 attr_strings
.change_time_attr
= "system.dos_attr.C_TIME";
1950 * Are they asking to set a DOS attribute?
1952 if (strcasecmp_m(name
, "system.dos_attr.*") == 0 ||
1953 strcasecmp_m(name
, "system.dos_attr.mode") == 0 ||
1954 (attr_strings
.create_time_attr
!= NULL
&&
1955 strcasecmp_m(name
, attr_strings
.create_time_attr
) == 0) ||
1956 strcasecmp_m(name
, attr_strings
.access_time_attr
) == 0 ||
1957 strcasecmp_m(name
, attr_strings
.write_time_attr
) == 0 ||
1958 strcasecmp_m(name
, attr_strings
.change_time_attr
) == 0) {
1960 /* get a DOS Attribute Descriptor with current attributes */
1961 dad
= dos_attr_query(context
, talloc_tos(), path
, srv
);
1964 talloc_asprintf(talloc_tos(), "%s:%s",
1965 name
+16, (const char *) value
);
1970 /* Overwrite old with provided new params */
1971 dos_attr_parse(context
, dad
, srv
, namevalue
);
1973 /* Set the new DOS attributes */
1974 ret2
= SMBC_setatr(context
, srv
, path
,
1981 /* ret2 has True (success) / False (failure) */
1996 /* Unsupported attribute name */
2003 SMBC_getxattr_ctx(SMBCCTX
*context
,
2010 SMBCSRV
*srv
= NULL
;
2011 SMBCSRV
*ipc_srv
= NULL
;
2012 char *server
= NULL
;
2015 char *password
= NULL
;
2016 char *workgroup
= NULL
;
2019 const char * create_time_attr
;
2020 const char * access_time_attr
;
2021 const char * write_time_attr
;
2022 const char * change_time_attr
;
2025 TALLOC_CTX
*frame
= talloc_stackframe();
2027 if (!context
|| !context
->internal
->initialized
) {
2028 errno
= EINVAL
; /* Best I can think of ... */
2039 DEBUG(4, ("smbc_getxattr(%s, %s)\n", fname
, name
));
2041 if (SMBC_parse_path(frame
,
2057 if (!user
|| user
[0] == (char)0) {
2058 user
= talloc_strdup(frame
, smbc_getUser(context
));
2066 srv
= SMBC_server(frame
, context
, True
,
2067 server
, port
, share
, &workgroup
, &user
, &password
);
2070 return -1; /* errno set by SMBC_server */
2073 if (! srv
->no_nt_session
) {
2074 ipc_srv
= SMBC_attr_server(frame
, context
, server
, port
, share
,
2075 &workgroup
, &user
, &password
);
2077 srv
->no_nt_session
= True
;
2083 /* Determine whether to use old-style or new-style attribute names */
2084 if (context
->internal
->full_time_names
) {
2085 /* new-style names */
2086 attr_strings
.create_time_attr
= "system.dos_attr.CREATE_TIME";
2087 attr_strings
.access_time_attr
= "system.dos_attr.ACCESS_TIME";
2088 attr_strings
.write_time_attr
= "system.dos_attr.WRITE_TIME";
2089 attr_strings
.change_time_attr
= "system.dos_attr.CHANGE_TIME";
2091 /* old-style names */
2092 attr_strings
.create_time_attr
= NULL
;
2093 attr_strings
.access_time_attr
= "system.dos_attr.A_TIME";
2094 attr_strings
.write_time_attr
= "system.dos_attr.M_TIME";
2095 attr_strings
.change_time_attr
= "system.dos_attr.C_TIME";
2098 /* Are they requesting a supported attribute? */
2099 if (strcasecmp_m(name
, "system.*") == 0 ||
2100 strncasecmp_m(name
, "system.*!", 9) == 0 ||
2101 strcasecmp_m(name
, "system.*+") == 0 ||
2102 strncasecmp_m(name
, "system.*+!", 10) == 0 ||
2103 strcasecmp_m(name
, "system.nt_sec_desc.*") == 0 ||
2104 strncasecmp_m(name
, "system.nt_sec_desc.*!", 21) == 0 ||
2105 strcasecmp_m(name
, "system.nt_sec_desc.*+") == 0 ||
2106 strncasecmp_m(name
, "system.nt_sec_desc.*+!", 22) == 0 ||
2107 strcasecmp_m(name
, "system.nt_sec_desc.revision") == 0 ||
2108 strcasecmp_m(name
, "system.nt_sec_desc.owner") == 0 ||
2109 strcasecmp_m(name
, "system.nt_sec_desc.owner+") == 0 ||
2110 strcasecmp_m(name
, "system.nt_sec_desc.group") == 0 ||
2111 strcasecmp_m(name
, "system.nt_sec_desc.group+") == 0 ||
2112 strncasecmp_m(name
, "system.nt_sec_desc.acl", 22) == 0 ||
2113 strncasecmp_m(name
, "system.nt_sec_desc.acl+", 23) == 0 ||
2114 strcasecmp_m(name
, "system.dos_attr.*") == 0 ||
2115 strncasecmp_m(name
, "system.dos_attr.*!", 18) == 0 ||
2116 strcasecmp_m(name
, "system.dos_attr.mode") == 0 ||
2117 strcasecmp_m(name
, "system.dos_attr.size") == 0 ||
2118 (attr_strings
.create_time_attr
!= NULL
&&
2119 strcasecmp_m(name
, attr_strings
.create_time_attr
) == 0) ||
2120 strcasecmp_m(name
, attr_strings
.access_time_attr
) == 0 ||
2121 strcasecmp_m(name
, attr_strings
.write_time_attr
) == 0 ||
2122 strcasecmp_m(name
, attr_strings
.change_time_attr
) == 0 ||
2123 strcasecmp_m(name
, "system.dos_attr.inode") == 0) {
2126 const char *filename
= name
;
2127 ret
= cacl_get(context
, talloc_tos(), srv
,
2128 ipc_srv
== NULL
? NULL
: ipc_srv
->cli
,
2129 &ipc_srv
->pol
, path
,
2131 discard_const_p(char, value
),
2133 if (ret
< 0 && errno
== 0) {
2134 errno
= SMBC_errno(context
, srv
->cli
);
2140 /* Unsupported attribute name */
2148 SMBC_removexattr_ctx(SMBCCTX
*context
,
2153 SMBCSRV
*srv
= NULL
;
2154 SMBCSRV
*ipc_srv
= NULL
;
2155 char *server
= NULL
;
2158 char *password
= NULL
;
2159 char *workgroup
= NULL
;
2162 TALLOC_CTX
*frame
= talloc_stackframe();
2164 if (!context
|| !context
->internal
->initialized
) {
2165 errno
= EINVAL
; /* Best I can think of ... */
2176 DEBUG(4, ("smbc_removexattr(%s, %s)\n", fname
, name
));
2178 if (SMBC_parse_path(frame
,
2194 if (!user
|| user
[0] == (char)0) {
2195 user
= talloc_strdup(frame
, smbc_getUser(context
));
2203 srv
= SMBC_server(frame
, context
, True
,
2204 server
, port
, share
, &workgroup
, &user
, &password
);
2207 return -1; /* errno set by SMBC_server */
2210 if (! srv
->no_nt_session
) {
2211 ipc_srv
= SMBC_attr_server(frame
, context
, server
, port
, share
,
2212 &workgroup
, &user
, &password
);
2214 srv
->no_nt_session
= True
;
2222 return -1; /* errno set by SMBC_attr_server */
2225 /* Are they asking to set the entire ACL? */
2226 if (strcasecmp_m(name
, "system.nt_sec_desc.*") == 0 ||
2227 strcasecmp_m(name
, "system.nt_sec_desc.*+") == 0) {
2230 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
2231 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
2232 NULL
, SMBC_XATTR_MODE_REMOVE_ALL
, 0);
2238 * Are they asking to remove one or more spceific security descriptor
2241 if (strcasecmp_m(name
, "system.nt_sec_desc.revision") == 0 ||
2242 strcasecmp_m(name
, "system.nt_sec_desc.owner") == 0 ||
2243 strcasecmp_m(name
, "system.nt_sec_desc.owner+") == 0 ||
2244 strcasecmp_m(name
, "system.nt_sec_desc.group") == 0 ||
2245 strcasecmp_m(name
, "system.nt_sec_desc.group+") == 0 ||
2246 strncasecmp_m(name
, "system.nt_sec_desc.acl", 22) == 0 ||
2247 strncasecmp_m(name
, "system.nt_sec_desc.acl+", 23) == 0) {
2250 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
2251 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
2252 discard_const_p(char, name
) + 19,
2253 SMBC_XATTR_MODE_REMOVE
, 0);
2258 /* Unsupported attribute name */
2265 SMBC_listxattr_ctx(SMBCCTX
*context
,
2271 * This isn't quite what listxattr() is supposed to do. This returns
2272 * the complete set of attribute names, always, rather than only those
2273 * attribute names which actually exist for a file. Hmmm...
2276 const char supported_old
[] =
2279 "system.nt_sec_desc.revision\0"
2280 "system.nt_sec_desc.owner\0"
2281 "system.nt_sec_desc.owner+\0"
2282 "system.nt_sec_desc.group\0"
2283 "system.nt_sec_desc.group+\0"
2284 "system.nt_sec_desc.acl.*\0"
2285 "system.nt_sec_desc.acl\0"
2286 "system.nt_sec_desc.acl+\0"
2287 "system.nt_sec_desc.*\0"
2288 "system.nt_sec_desc.*+\0"
2289 "system.dos_attr.*\0"
2290 "system.dos_attr.mode\0"
2291 "system.dos_attr.c_time\0"
2292 "system.dos_attr.a_time\0"
2293 "system.dos_attr.m_time\0"
2295 const char supported_new
[] =
2298 "system.nt_sec_desc.revision\0"
2299 "system.nt_sec_desc.owner\0"
2300 "system.nt_sec_desc.owner+\0"
2301 "system.nt_sec_desc.group\0"
2302 "system.nt_sec_desc.group+\0"
2303 "system.nt_sec_desc.acl.*\0"
2304 "system.nt_sec_desc.acl\0"
2305 "system.nt_sec_desc.acl+\0"
2306 "system.nt_sec_desc.*\0"
2307 "system.nt_sec_desc.*+\0"
2308 "system.dos_attr.*\0"
2309 "system.dos_attr.mode\0"
2310 "system.dos_attr.create_time\0"
2311 "system.dos_attr.access_time\0"
2312 "system.dos_attr.write_time\0"
2313 "system.dos_attr.change_time\0"
2315 const char * supported
;
2317 if (context
->internal
->full_time_names
) {
2318 supported
= supported_new
;
2319 retsize
= sizeof(supported_new
);
2321 supported
= supported_old
;
2322 retsize
= sizeof(supported_old
);
2329 if (retsize
> size
) {
2334 /* this can't be strcpy() because there are embedded null characters */
2335 memcpy(list
, supported
, retsize
);