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"
33 #include "lib/util/string_wrappers.h"
36 * Find an lsa pipe handle associated with a cli struct.
38 static struct rpc_pipe_client
*
39 find_lsa_pipe_hnd(struct cli_state
*ipc_cli
)
41 struct rpc_pipe_client
*pipe_hnd
;
43 for (pipe_hnd
= ipc_cli
->pipe_list
;
45 pipe_hnd
= pipe_hnd
->next
) {
46 struct dcerpc_binding_handle
*bh
= NULL
;
47 const struct dcerpc_binding
*bd
= NULL
;
48 struct ndr_syntax_id syntax
;
50 bh
= pipe_hnd
->binding_handle
;
51 bd
= dcerpc_binding_handle_get_binding(bh
);
52 syntax
= dcerpc_binding_get_abstract_syntax(bd
);
54 if (ndr_syntax_id_equal(&syntax
,
55 &ndr_table_lsarpc
.syntax_id
)) {
63 * Sort ACEs according to the documentation at
64 * http://support.microsoft.com/kb/269175, at least as far as it defines the
69 ace_compare(struct security_ace
*ace1
,
70 struct security_ace
*ace2
)
75 /* If the ACEs are equal, we have nothing more to do. */
76 if (security_ace_equal(ace1
, ace2
)) {
80 /* Inherited follow non-inherited */
81 b1
= ((ace1
->flags
& SEC_ACE_FLAG_INHERITED_ACE
) != 0);
82 b2
= ((ace2
->flags
& SEC_ACE_FLAG_INHERITED_ACE
) != 0);
88 * What shall we do with AUDITs and ALARMs? It's undefined. We'll
89 * sort them after DENY and ALLOW.
91 b1
= (ace1
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED
&&
92 ace1
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
&&
93 ace1
->type
!= SEC_ACE_TYPE_ACCESS_DENIED
&&
94 ace1
->type
!= SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
95 b2
= (ace2
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED
&&
96 ace2
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
&&
97 ace2
->type
!= SEC_ACE_TYPE_ACCESS_DENIED
&&
98 ace2
->type
!= SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
100 return (b1
? 1 : -1);
103 /* Allowed ACEs follow denied ACEs */
104 b1
= (ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED
||
105 ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
);
106 b2
= (ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED
||
107 ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
);
109 return (b1
? 1 : -1);
113 * ACEs applying to an entity's object follow those applying to the
116 b1
= (ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
||
117 ace1
->type
== SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
118 b2
= (ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
||
119 ace2
->type
== SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
121 return (b1
? 1 : -1);
125 * If we get this far, the ACEs are similar as far as the
126 * characteristics we typically care about (those defined by the
127 * referenced MS document). We'll now sort by characteristics that
128 * just seems reasonable.
131 if (ace1
->type
!= ace2
->type
) {
133 * ace2 and ace1 are reversed here, so that
134 * ACCESS_DENIED_ACE_TYPE (1) sorts before
135 * ACCESS_ALLOWED_ACE_TYPE (0), which is the order you
138 return NUMERIC_CMP(ace2
->type
, ace1
->type
);
141 if (dom_sid_compare(&ace1
->trustee
, &ace2
->trustee
)) {
142 return dom_sid_compare(&ace1
->trustee
, &ace2
->trustee
);
145 if (ace1
->flags
!= ace2
->flags
) {
146 return NUMERIC_CMP(ace1
->flags
, ace2
->flags
);
149 if (ace1
->access_mask
!= ace2
->access_mask
) {
150 return NUMERIC_CMP(ace1
->access_mask
, ace2
->access_mask
);
153 if (ace1
->size
!= ace2
->size
) {
154 return NUMERIC_CMP(ace1
->size
, ace2
->size
);
157 return memcmp(ace1
, ace2
, sizeof(struct security_ace
));
162 sort_acl(struct security_acl
*the_acl
)
165 if (!the_acl
) return;
167 TYPESAFE_QSORT(the_acl
->aces
, the_acl
->num_aces
, ace_compare
);
169 for (i
=1;i
<the_acl
->num_aces
;) {
170 if (security_ace_equal(&the_acl
->aces
[i
-1],
171 &the_acl
->aces
[i
])) {
173 the_acl
->aces
, i
, the_acl
->num_aces
);
181 /* convert a SID to a string, either numeric or username/group */
183 convert_sid_to_string(struct cli_state
*ipc_cli
,
184 struct policy_handle
*pol
,
189 char **domains
= NULL
;
191 enum lsa_SidType
*types
= NULL
;
192 struct rpc_pipe_client
*pipe_hnd
= find_lsa_pipe_hnd(ipc_cli
);
195 sid_to_fstring(str
, sid
);
198 return; /* no lookup desired */
205 /* Ask LSA to convert the sid to a name */
207 ctx
= talloc_stackframe();
209 if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_sids(pipe_hnd
, ctx
,
210 pol
, 1, sid
, &domains
,
212 !domains
|| !domains
[0] || !names
|| !names
[0]) {
219 fstr_sprintf(str
, "%s%s%s",
220 domains
[0], lp_winbind_separator(), names
[0]);
225 /* convert a string to a SID, either numeric or username/group */
227 convert_string_to_sid(struct cli_state
*ipc_cli
,
228 struct policy_handle
*pol
,
233 enum lsa_SidType
*types
= NULL
;
234 struct dom_sid
*sids
= NULL
;
236 TALLOC_CTX
*ctx
= NULL
;
237 struct rpc_pipe_client
*pipe_hnd
= find_lsa_pipe_hnd(ipc_cli
);
244 if (strncmp(str
, "S-", 2) == 0) {
245 return string_to_sid(sid
, str
);
252 ctx
= talloc_stackframe();
253 if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_names(pipe_hnd
, ctx
,
261 sid_copy(sid
, &sids
[0]);
268 /* parse an struct security_ace in the same format as print_ace() */
270 parse_ace(struct cli_state
*ipc_cli
,
271 struct policy_handle
*pol
,
272 struct security_ace
*ace
,
289 TALLOC_CTX
*frame
= talloc_stackframe();
291 /* These values discovered by inspection */
292 static const struct perm_value special_values
[] = {
301 static const struct perm_value standard_values
[] = {
302 { "READ", 0x001200a9 },
303 { "CHANGE", 0x001301bf },
304 { "FULL", 0x001f01ff },
308 p
= strchr_m(str
,':');
315 /* Try to parse numeric form */
317 if (sscanf(p
, "%u/%u/%u", &atype
, &aflags
, &amask
) == 3 &&
318 convert_string_to_sid(ipc_cli
, pol
, numeric
, &sid
, str
)) {
322 /* Try to parse text form */
324 if (!convert_string_to_sid(ipc_cli
, pol
, numeric
, &sid
, str
)) {
330 if (!next_token_talloc(frame
, &cp
, &tok
, "/")) {
335 if (strncasecmp_m(tok
, "ALLOWED", strlen("ALLOWED")) == 0) {
336 atype
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
337 } else if (strncasecmp_m(tok
, "DENIED", strlen("DENIED")) == 0) {
338 atype
= SEC_ACE_TYPE_ACCESS_DENIED
;
344 /* Only numeric form accepted for flags at present */
346 if (!(next_token_talloc(frame
, &cp
, &tok
, "/") &&
347 sscanf(tok
, "%u", &aflags
))) {
352 if (!next_token_talloc(frame
, &cp
, &tok
, "/")) {
357 if (strncmp(tok
, "0x", 2) == 0) {
358 if (sscanf(tok
, "%u", &amask
) != 1) {
365 for (i
= 0; i
< ARRAY_SIZE(standard_values
); i
++) {
366 const struct perm_value
*v
= &standard_values
[i
];
367 if (strcmp(tok
, v
->perm
) == 0) {
378 for (i
= 0; i
< ARRAY_SIZE(special_values
); i
++) {
379 const struct perm_value
*v
= &special_values
[i
];
380 if (v
->perm
[0] == *p
) {
400 init_sec_ace(ace
, &sid
, atype
, mask
, aflags
);
405 /* add an struct security_ace to a list of struct security_aces in a struct security_acl */
407 add_ace(struct security_acl
**the_acl
,
408 const struct security_ace
*ace
,
411 struct security_acl
*acl
= *the_acl
;
414 acl
= make_sec_acl(ctx
, 3, 0, NULL
);
420 if (acl
->num_aces
== UINT32_MAX
) {
424 acl
, struct security_ace
, *ace
, &acl
->aces
, &acl
->num_aces
);
430 /* parse a ascii version of a security descriptor */
431 static struct security_descriptor
*
432 sec_desc_parse(TALLOC_CTX
*ctx
,
433 struct cli_state
*ipc_cli
,
434 struct policy_handle
*pol
,
440 struct security_descriptor
*ret
= NULL
;
442 struct dom_sid owner_sid
= { .num_auths
= 0 };
443 struct dom_sid group_sid
= { .num_auths
= 0 };
444 bool have_owner
= false, have_group
= false;
445 struct security_acl
*dacl
=NULL
;
448 while (next_token_talloc(ctx
, &p
, &tok
, "\t,\r\n")) {
450 if (strncasecmp_m(tok
,"REVISION:", 9) == 0) {
451 revision
= strtol(tok
+9, NULL
, 16);
455 if (strncasecmp_m(tok
,"OWNER:", 6) == 0) {
457 DEBUG(5,("OWNER specified more than once!\n"));
460 if (!convert_string_to_sid(ipc_cli
, pol
,
462 &owner_sid
, tok
+6)) {
463 DEBUG(5, ("Failed to parse owner sid\n"));
470 if (strncasecmp_m(tok
,"OWNER+:", 7) == 0) {
472 DEBUG(5,("OWNER specified more than once!\n"));
475 if (!convert_string_to_sid(ipc_cli
, pol
,
477 &owner_sid
, tok
+7)) {
478 DEBUG(5, ("Failed to parse owner sid\n"));
485 if (strncasecmp_m(tok
,"GROUP:", 6) == 0) {
487 DEBUG(5,("GROUP specified more than once!\n"));
490 if (!convert_string_to_sid(ipc_cli
, pol
,
492 &group_sid
, tok
+6)) {
493 DEBUG(5, ("Failed to parse group sid\n"));
500 if (strncasecmp_m(tok
,"GROUP+:", 7) == 0) {
502 DEBUG(5,("GROUP specified more than once!\n"));
505 if (!convert_string_to_sid(ipc_cli
, pol
,
507 &group_sid
, tok
+6)) {
508 DEBUG(5, ("Failed to parse group sid\n"));
515 if (strncasecmp_m(tok
,"ACL:", 4) == 0) {
516 struct security_ace ace
;
517 if (!parse_ace(ipc_cli
, pol
, &ace
, numeric
, tok
+4)) {
518 DEBUG(5, ("Failed to parse ACL %s\n", tok
));
521 if(!add_ace(&dacl
, &ace
, ctx
)) {
522 DEBUG(5, ("Failed to add ACL %s\n", tok
));
528 if (strncasecmp_m(tok
,"ACL+:", 5) == 0) {
529 struct security_ace ace
;
530 if (!parse_ace(ipc_cli
, pol
, &ace
, False
, tok
+5)) {
531 DEBUG(5, ("Failed to parse ACL %s\n", tok
));
534 if(!add_ace(&dacl
, &ace
, ctx
)) {
535 DEBUG(5, ("Failed to add ACL %s\n", tok
));
541 DEBUG(5, ("Failed to parse security descriptor\n"));
548 SEC_DESC_SELF_RELATIVE
,
549 have_owner
? &owner_sid
: NULL
,
550 have_group
? &group_sid
: NULL
,
560 /* Obtain the current dos attributes */
561 static struct DOS_ATTR_DESC
*
562 dos_attr_query(SMBCCTX
*context
,
564 const char *filename
,
567 struct stat sb
= {0};
568 struct DOS_ATTR_DESC
*ret
= NULL
;
571 ret
= talloc(ctx
, struct DOS_ATTR_DESC
);
577 /* Obtain the DOS attributes */
578 status
= SMBC_getatr(context
, srv
, filename
, &sb
);
579 if (!NT_STATUS_IS_OK(status
)) {
580 DEBUG(5, ("dos_attr_query Failed to query old attributes\n"));
582 errno
= cli_status_to_errno(status
);
586 ret
->mode
= sb
.st_mode
;
587 ret
->size
= sb
.st_size
;
588 ret
->create_time
= sb
.st_ctime
;
589 ret
->access_time
= sb
.st_atime
;
590 ret
->write_time
= sb
.st_mtime
;
591 ret
->change_time
= sb
.st_mtime
;
592 ret
->inode
= sb
.st_ino
;
598 /* parse a ascii version of a security descriptor */
600 dos_attr_parse(SMBCCTX
*context
,
601 struct DOS_ATTR_DESC
*dad
,
608 TALLOC_CTX
*frame
= NULL
;
610 const char * create_time_attr
;
611 const char * access_time_attr
;
612 const char * write_time_attr
;
613 const char * change_time_attr
;
616 /* Determine whether to use old-style or new-style attribute names */
617 if (context
->internal
->full_time_names
) {
618 /* new-style names */
619 attr_strings
.create_time_attr
= "CREATE_TIME";
620 attr_strings
.access_time_attr
= "ACCESS_TIME";
621 attr_strings
.write_time_attr
= "WRITE_TIME";
622 attr_strings
.change_time_attr
= "CHANGE_TIME";
624 /* old-style names */
625 attr_strings
.create_time_attr
= NULL
;
626 attr_strings
.access_time_attr
= "A_TIME";
627 attr_strings
.write_time_attr
= "M_TIME";
628 attr_strings
.change_time_attr
= "C_TIME";
631 /* if this is to set the entire ACL... */
633 /* ... then increment past the first colon if there is one */
634 if ((p
= strchr(str
, ':')) != NULL
) {
641 frame
= talloc_stackframe();
642 while (next_token_talloc(frame
, &p
, &tok
, "\t,\r\n")) {
643 if (strncasecmp_m(tok
, "MODE:", 5) == 0) {
644 long request
= strtol(tok
+5, NULL
, 16);
647 (dad
->mode
& FILE_ATTRIBUTE_DIRECTORY
)
648 ? FILE_ATTRIBUTE_DIRECTORY
649 : FILE_ATTRIBUTE_NORMAL
;
656 if (strncasecmp_m(tok
, "SIZE:", 5) == 0) {
657 dad
->size
= (off_t
)atof(tok
+5);
661 n
= strlen(attr_strings
.access_time_attr
);
662 if (strncasecmp_m(tok
, attr_strings
.access_time_attr
, n
) == 0) {
663 dad
->access_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
667 n
= strlen(attr_strings
.change_time_attr
);
668 if (strncasecmp_m(tok
, attr_strings
.change_time_attr
, n
) == 0) {
669 dad
->change_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
673 n
= strlen(attr_strings
.write_time_attr
);
674 if (strncasecmp_m(tok
, attr_strings
.write_time_attr
, n
) == 0) {
675 dad
->write_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
679 if (attr_strings
.create_time_attr
!= NULL
) {
680 n
= strlen(attr_strings
.create_time_attr
);
681 if (strncasecmp_m(tok
, attr_strings
.create_time_attr
,
683 dad
->create_time
= (time_t)strtol(tok
+n
+1,
689 if (strncasecmp_m(tok
, "INODE:", 6) == 0) {
690 dad
->inode
= (SMB_INO_T
)atof(tok
+6);
697 /*****************************************************
698 Retrieve the acls for a file.
699 *******************************************************/
702 cacl_get(SMBCCTX
*context
,
705 struct cli_state
*ipc_cli
,
706 struct policy_handle
*pol
,
707 const char *filename
,
708 const char *attr_name
,
721 bool exclude_nt_revision
= False
;
722 bool exclude_nt_owner
= False
;
723 bool exclude_nt_group
= False
;
724 bool exclude_nt_acl
= False
;
725 bool exclude_dos_mode
= False
;
726 bool exclude_dos_size
= False
;
727 bool exclude_dos_create_time
= False
;
728 bool exclude_dos_access_time
= False
;
729 bool exclude_dos_write_time
= False
;
730 bool exclude_dos_change_time
= False
;
731 bool exclude_dos_inode
= False
;
733 bool determine_size
= (bufsize
== 0);
735 struct security_descriptor
*sd
;
737 fstring name_sandbox
;
741 struct cli_state
*cli
= srv
->cli
;
743 const char * create_time_attr
;
744 const char * access_time_attr
;
745 const char * write_time_attr
;
746 const char * change_time_attr
;
749 const char * create_time_attr
;
750 const char * access_time_attr
;
751 const char * write_time_attr
;
752 const char * change_time_attr
;
755 /* Determine whether to use old-style or new-style attribute names */
756 if (context
->internal
->full_time_names
) {
757 /* new-style names */
758 attr_strings
.create_time_attr
= "CREATE_TIME";
759 attr_strings
.access_time_attr
= "ACCESS_TIME";
760 attr_strings
.write_time_attr
= "WRITE_TIME";
761 attr_strings
.change_time_attr
= "CHANGE_TIME";
763 excl_attr_strings
.create_time_attr
= "CREATE_TIME";
764 excl_attr_strings
.access_time_attr
= "ACCESS_TIME";
765 excl_attr_strings
.write_time_attr
= "WRITE_TIME";
766 excl_attr_strings
.change_time_attr
= "CHANGE_TIME";
768 /* old-style names */
769 attr_strings
.create_time_attr
= NULL
;
770 attr_strings
.access_time_attr
= "A_TIME";
771 attr_strings
.write_time_attr
= "M_TIME";
772 attr_strings
.change_time_attr
= "C_TIME";
774 excl_attr_strings
.create_time_attr
= NULL
;
775 excl_attr_strings
.access_time_attr
= "dos_attr.A_TIME";
776 excl_attr_strings
.write_time_attr
= "dos_attr.M_TIME";
777 excl_attr_strings
.change_time_attr
= "dos_attr.C_TIME";
780 /* Copy name so we can strip off exclusions (if any are specified) */
781 fstrcpy(name_sandbox
, attr_name
);
783 /* Ensure name is null terminated */
784 name_sandbox
[sizeof(name_sandbox
) - 1] = '\0';
786 /* Play in the sandbox */
789 /* If there are any exclusions, point to them and mask them from name */
790 if ((pExclude
= strchr(name
, '!')) != NULL
)
795 all
= (strncasecmp_m(name
, "system.*", 8) == 0);
796 all_nt
= (strncasecmp_m(name
, "system.nt_sec_desc.*", 20) == 0);
797 all_nt_acls
= (strncasecmp_m(name
, "system.nt_sec_desc.acl.*", 24) == 0);
798 all_dos
= (strncasecmp_m(name
, "system.dos_attr.*", 17) == 0);
799 some_nt
= (strncasecmp_m(name
, "system.nt_sec_desc.", 19) == 0);
800 some_dos
= (strncasecmp_m(name
, "system.dos_attr.", 16) == 0);
801 numeric
= (* (name
+ strlen(name
) - 1) != '+');
803 /* Look for exclusions from "all" requests */
804 if (all
|| all_nt
|| all_dos
) {
805 /* Exclusions are delimited by '!' */
808 pExclude
= (p
== NULL
? NULL
: p
+ 1)) {
810 /* Find end of this exclusion name */
811 if ((p
= strchr(pExclude
, '!')) != NULL
)
816 /* Which exclusion name is this? */
817 if (strcasecmp_m(pExclude
,
818 "nt_sec_desc.revision") == 0) {
819 exclude_nt_revision
= True
;
821 else if (strcasecmp_m(pExclude
,
822 "nt_sec_desc.owner") == 0) {
823 exclude_nt_owner
= True
;
825 else if (strcasecmp_m(pExclude
,
826 "nt_sec_desc.group") == 0) {
827 exclude_nt_group
= True
;
829 else if (strcasecmp_m(pExclude
,
830 "nt_sec_desc.acl") == 0) {
831 exclude_nt_acl
= True
;
833 else if (strcasecmp_m(pExclude
,
834 "dos_attr.mode") == 0) {
835 exclude_dos_mode
= True
;
837 else if (strcasecmp_m(pExclude
,
838 "dos_attr.size") == 0) {
839 exclude_dos_size
= True
;
841 else if (excl_attr_strings
.create_time_attr
!= NULL
&&
842 strcasecmp_m(pExclude
,
843 excl_attr_strings
.change_time_attr
) == 0) {
844 exclude_dos_create_time
= True
;
846 else if (strcasecmp_m(pExclude
,
847 excl_attr_strings
.access_time_attr
) == 0) {
848 exclude_dos_access_time
= True
;
850 else if (strcasecmp_m(pExclude
,
851 excl_attr_strings
.write_time_attr
) == 0) {
852 exclude_dos_write_time
= True
;
854 else if (strcasecmp_m(pExclude
,
855 excl_attr_strings
.change_time_attr
) == 0) {
856 exclude_dos_change_time
= True
;
858 else if (strcasecmp_m(pExclude
, "dos_attr.inode") == 0) {
859 exclude_dos_inode
= True
;
862 DEBUG(5, ("cacl_get received unknown exclusion: %s\n",
873 * If we are (possibly) talking to an NT or new system and some NT
874 * attributes have been requested...
876 if (ipc_cli
&& (all
|| some_nt
|| all_nt_acls
)) {
877 char *targetpath
= NULL
;
878 struct cli_state
*targetcli
= NULL
;
879 struct cli_credentials
*creds
= NULL
;
882 /* Point to the portion after "system.nt_sec_desc." */
883 name
+= 19; /* if (all) this will be invalid but unused */
885 creds
= context
->internal
->creds
;
887 status
= cli_resolve_path(
890 cli
, filename
, &targetcli
, &targetpath
);
891 if (!NT_STATUS_IS_OK(status
)) {
892 DEBUG(5, ("cacl_get Could not resolve %s\n",
898 /* ... then obtain any NT attributes which were requested */
899 status
= cli_ntcreate(
901 targetpath
, /* fname */
903 READ_CONTROL_ACCESS
, /* DesiredAccess */
904 0, /* FileAttributes */
906 FILE_SHARE_WRITE
, /* ShareAccess */
907 FILE_OPEN
, /* CreateDisposition */
908 0x0, /* CreateOptions */
909 0x0, /* SecurityFlags */
912 if (!NT_STATUS_IS_OK(status
)) {
913 DEBUG(5, ("cacl_get failed to open %s: %s\n",
914 targetpath
, nt_errstr(status
)));
915 errno
= cli_status_to_errno(status
);
919 status
= cli_query_secdesc(targetcli
, fnum
, ctx
, &sd
);
920 if (!NT_STATUS_IS_OK(status
)) {
921 DEBUG(5,("cacl_get Failed to query old descriptor "
923 targetpath
, nt_errstr(status
)));
924 errno
= cli_status_to_errno(status
);
928 cli_close(targetcli
, fnum
);
930 if (! exclude_nt_revision
) {
932 if (determine_size
) {
933 p
= talloc_asprintf(ctx
,
942 n
= snprintf(buf
, bufsize
,
946 } else if (strcasecmp_m(name
, "revision") == 0) {
947 if (determine_size
) {
948 p
= talloc_asprintf(ctx
, "%d",
956 n
= snprintf(buf
, bufsize
, "%d",
961 if (!determine_size
&& n
> bufsize
) {
971 if (! exclude_nt_owner
) {
972 /* Get owner and group sid */
974 convert_sid_to_string(ipc_cli
, pol
,
983 if (determine_size
) {
984 p
= talloc_asprintf(ctx
, ",OWNER:%s",
991 } else if (sidstr
[0] != '\0') {
992 n
= snprintf(buf
, bufsize
,
993 ",OWNER:%s", sidstr
);
995 } else if (strncasecmp_m(name
, "owner", 5) == 0) {
996 if (determine_size
) {
997 p
= talloc_asprintf(ctx
, "%s", sidstr
);
1004 n
= snprintf(buf
, bufsize
, "%s",
1009 if (!determine_size
&& n
> bufsize
) {
1019 if (! exclude_nt_group
) {
1020 if (sd
->group_sid
) {
1021 convert_sid_to_string(ipc_cli
, pol
,
1025 fstrcpy(sidstr
, "");
1028 if (all
|| all_nt
) {
1029 if (determine_size
) {
1030 p
= talloc_asprintf(ctx
, ",GROUP:%s",
1037 } else if (sidstr
[0] != '\0') {
1038 n
= snprintf(buf
, bufsize
,
1039 ",GROUP:%s", sidstr
);
1041 } else if (strncasecmp_m(name
, "group", 5) == 0) {
1042 if (determine_size
) {
1043 p
= talloc_asprintf(ctx
, "%s", sidstr
);
1050 n
= snprintf(buf
, bufsize
,
1055 if (!determine_size
&& n
> bufsize
) {
1065 if (! exclude_nt_acl
) {
1066 /* Add aces to value buffer */
1067 for (i
= 0; sd
->dacl
&& i
< sd
->dacl
->num_aces
; i
++) {
1069 struct security_ace
*ace
= &sd
->dacl
->aces
[i
];
1070 convert_sid_to_string(ipc_cli
, pol
,
1074 if (all
|| all_nt
) {
1075 if (determine_size
) {
1076 p
= talloc_asprintf(
1092 ",ACL:%s:%d/%d/0x%08x",
1098 } else if ((strncasecmp_m(name
, "acl", 3) == 0 &&
1099 strcasecmp_m(name
+3, sidstr
) == 0) ||
1100 (strncasecmp_m(name
, "acl+", 4) == 0 &&
1101 strcasecmp_m(name
+4, sidstr
) == 0)) {
1102 if (determine_size
) {
1103 p
= talloc_asprintf(
1115 n
= snprintf(buf
, bufsize
,
1121 } else if (all_nt_acls
) {
1122 if (determine_size
) {
1123 p
= talloc_asprintf(
1125 "%s%s:%d/%d/0x%08x",
1137 n
= snprintf(buf
, bufsize
,
1138 "%s%s:%d/%d/0x%08x",
1146 if (!determine_size
&& n
> bufsize
) {
1157 /* Restore name pointer to its original value */
1161 if (all
|| some_dos
) {
1162 struct stat sb
= {0};
1163 time_t create_time
= (time_t)0;
1164 time_t write_time
= (time_t)0;
1165 time_t access_time
= (time_t)0;
1166 time_t change_time
= (time_t)0;
1172 /* Point to the portion after "system.dos_attr." */
1173 name
+= 16; /* if (all) this will be invalid but unused */
1175 /* Obtain the DOS attributes */
1176 status
= SMBC_getatr(context
, srv
, filename
, &sb
);
1177 if (!NT_STATUS_IS_OK(status
)) {
1178 errno
= cli_status_to_errno(status
);
1182 create_time
= sb
.st_ctime
;
1183 access_time
= sb
.st_atime
;
1184 write_time
= sb
.st_mtime
;
1185 change_time
= sb
.st_mtime
;
1190 if (! exclude_dos_mode
) {
1191 if (all
|| all_dos
) {
1192 if (determine_size
) {
1193 p
= talloc_asprintf(ctx
,
1206 n
= snprintf(buf
, bufsize
,
1214 } else if (strcasecmp_m(name
, "mode") == 0) {
1215 if (determine_size
) {
1216 p
= talloc_asprintf(ctx
, "0x%x", mode
);
1223 n
= snprintf(buf
, bufsize
,
1228 if (!determine_size
&& n
> bufsize
) {
1238 if (! exclude_dos_size
) {
1239 if (all
|| all_dos
) {
1240 if (determine_size
) {
1241 p
= talloc_asprintf(
1251 n
= snprintf(buf
, bufsize
,
1255 } else if (strcasecmp_m(name
, "size") == 0) {
1256 if (determine_size
) {
1257 p
= talloc_asprintf(
1267 n
= snprintf(buf
, bufsize
,
1273 if (!determine_size
&& n
> bufsize
) {
1283 if (! exclude_dos_create_time
&&
1284 attr_strings
.create_time_attr
!= NULL
) {
1285 if (all
|| all_dos
) {
1286 if (determine_size
) {
1287 p
= talloc_asprintf(ctx
,
1289 attr_strings
.create_time_attr
,
1290 (unsigned long) create_time
);
1297 n
= snprintf(buf
, bufsize
,
1299 attr_strings
.create_time_attr
,
1300 (unsigned long) create_time
);
1302 } else if (strcasecmp_m(name
, attr_strings
.create_time_attr
) == 0) {
1303 if (determine_size
) {
1304 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) create_time
);
1311 n
= snprintf(buf
, bufsize
,
1312 "%lu", (unsigned long) create_time
);
1316 if (!determine_size
&& n
> bufsize
) {
1326 if (! exclude_dos_access_time
) {
1327 if (all
|| all_dos
) {
1328 if (determine_size
) {
1329 p
= talloc_asprintf(ctx
,
1331 attr_strings
.access_time_attr
,
1332 (unsigned long) access_time
);
1339 n
= snprintf(buf
, bufsize
,
1341 attr_strings
.access_time_attr
,
1342 (unsigned long) access_time
);
1344 } else if (strcasecmp_m(name
, attr_strings
.access_time_attr
) == 0) {
1345 if (determine_size
) {
1346 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) access_time
);
1353 n
= snprintf(buf
, bufsize
,
1354 "%lu", (unsigned long) access_time
);
1358 if (!determine_size
&& n
> bufsize
) {
1368 if (! exclude_dos_write_time
) {
1369 if (all
|| all_dos
) {
1370 if (determine_size
) {
1371 p
= talloc_asprintf(ctx
,
1373 attr_strings
.write_time_attr
,
1374 (unsigned long) write_time
);
1381 n
= snprintf(buf
, bufsize
,
1383 attr_strings
.write_time_attr
,
1384 (unsigned long) write_time
);
1386 } else if (strcasecmp_m(name
, attr_strings
.write_time_attr
) == 0) {
1387 if (determine_size
) {
1388 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) write_time
);
1395 n
= snprintf(buf
, bufsize
,
1396 "%lu", (unsigned long) write_time
);
1400 if (!determine_size
&& n
> bufsize
) {
1410 if (! exclude_dos_change_time
) {
1411 if (all
|| all_dos
) {
1412 if (determine_size
) {
1413 p
= talloc_asprintf(ctx
,
1415 attr_strings
.change_time_attr
,
1416 (unsigned long) change_time
);
1423 n
= snprintf(buf
, bufsize
,
1425 attr_strings
.change_time_attr
,
1426 (unsigned long) change_time
);
1428 } else if (strcasecmp_m(name
, attr_strings
.change_time_attr
) == 0) {
1429 if (determine_size
) {
1430 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) change_time
);
1437 n
= snprintf(buf
, bufsize
,
1438 "%lu", (unsigned long) change_time
);
1442 if (!determine_size
&& n
> bufsize
) {
1452 if (! exclude_dos_inode
) {
1453 if (all
|| all_dos
) {
1454 if (determine_size
) {
1455 p
= talloc_asprintf(
1465 n
= snprintf(buf
, bufsize
,
1469 } else if (strcasecmp_m(name
, "inode") == 0) {
1470 if (determine_size
) {
1471 p
= talloc_asprintf(
1481 n
= snprintf(buf
, bufsize
,
1487 if (!determine_size
&& n
> bufsize
) {
1497 /* Restore name pointer to its original value */
1509 /*****************************************************
1510 set the ACLs on a file given an ascii description
1511 *******************************************************/
1513 cacl_set(SMBCCTX
*context
,
1515 struct cli_state
*cli
,
1516 struct cli_state
*ipc_cli
,
1517 struct policy_handle
*pol
,
1518 const char *filename
,
1523 uint16_t fnum
= (uint16_t)-1;
1525 struct security_descriptor
*sd
= NULL
, *old
;
1526 struct security_acl
*dacl
= NULL
;
1527 struct dom_sid
*owner_sid
= NULL
;
1528 struct dom_sid
*group_sid
= NULL
;
1533 bool numeric
= True
;
1534 char *targetpath
= NULL
;
1535 struct cli_state
*targetcli
= NULL
;
1536 struct cli_credentials
*creds
= NULL
;
1539 /* the_acl will be null for REMOVE_ALL operations */
1541 numeric
= ((p
= strchr(the_acl
, ':')) != NULL
&&
1545 /* if this is to set the entire ACL... */
1546 if (*the_acl
== '*') {
1547 /* ... then increment past the first colon */
1551 sd
= sec_desc_parse(ctx
, ipc_cli
, pol
, numeric
, the_acl
);
1558 /* SMBC_XATTR_MODE_REMOVE_ALL is the only caller
1559 that doesn't deref sd */
1561 if (!sd
&& (mode
!= SMBC_XATTR_MODE_REMOVE_ALL
)) {
1566 creds
= context
->internal
->creds
;
1568 status
= cli_resolve_path(ctx
, "",
1570 cli
, filename
, &targetcli
, &targetpath
);
1571 if (!NT_STATUS_IS_OK(status
)) {
1572 DEBUG(5,("cacl_set: Could not resolve %s\n", filename
));
1577 /* The desired access below is the only one I could find that works
1578 with NT4, W2KP and Samba */
1580 status
= cli_ntcreate(
1581 targetcli
, /* cli */
1582 targetpath
, /* fname */
1584 READ_CONTROL_ACCESS
, /* DesiredAccess */
1585 0, /* FileAttributes */
1587 FILE_SHARE_WRITE
, /* ShareAccess */
1588 FILE_OPEN
, /* CreateDisposition */
1589 0x0, /* CreateOptions */
1590 0x0, /* SecurityFlags */
1593 if (!NT_STATUS_IS_OK(status
)) {
1594 DEBUG(5, ("cacl_set failed to open %s: %s\n",
1595 targetpath
, nt_errstr(status
)));
1600 status
= cli_query_secdesc(targetcli
, fnum
, ctx
, &old
);
1601 if (!NT_STATUS_IS_OK(status
)) {
1602 DEBUG(5,("cacl_set Failed to query old descriptor of %s: %s\n",
1603 targetpath
, nt_errstr(status
)));
1608 cli_close(targetcli
, fnum
);
1611 case SMBC_XATTR_MODE_REMOVE_ALL
:
1612 old
->dacl
->num_aces
= 0;
1616 case SMBC_XATTR_MODE_REMOVE
:
1617 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1620 for (j
=0;old
->dacl
&& j
<old
->dacl
->num_aces
;j
++) {
1621 if (security_ace_equal(&sd
->dacl
->aces
[i
],
1622 &old
->dacl
->aces
[j
])) {
1624 for (k
=j
; k
<old
->dacl
->num_aces
-1;k
++) {
1625 old
->dacl
->aces
[k
] =
1626 old
->dacl
->aces
[k
+1];
1628 old
->dacl
->num_aces
--;
1643 case SMBC_XATTR_MODE_ADD
:
1644 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1647 for (j
=0;old
->dacl
&& j
<old
->dacl
->num_aces
;j
++) {
1648 if (dom_sid_equal(&sd
->dacl
->aces
[i
].trustee
,
1649 &old
->dacl
->aces
[j
].trustee
)) {
1650 if (!(flags
& SMBC_XATTR_FLAG_CREATE
)) {
1655 old
->dacl
->aces
[j
] = sd
->dacl
->aces
[i
];
1661 if (!found
&& (flags
& SMBC_XATTR_FLAG_REPLACE
)) {
1667 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1668 add_ace(&old
->dacl
, &sd
->dacl
->aces
[i
], ctx
);
1674 case SMBC_XATTR_MODE_SET
:
1676 owner_sid
= old
->owner_sid
;
1677 group_sid
= old
->group_sid
;
1681 case SMBC_XATTR_MODE_CHOWN
:
1682 owner_sid
= sd
->owner_sid
;
1685 case SMBC_XATTR_MODE_CHGRP
:
1686 group_sid
= sd
->group_sid
;
1690 /* Denied ACE entries must come before allowed ones */
1691 sort_acl(old
->dacl
);
1693 /* Create new security descriptor and set it */
1694 sd
= make_sec_desc(ctx
, old
->revision
, SEC_DESC_SELF_RELATIVE
,
1695 owner_sid
, group_sid
, NULL
, dacl
, &sd_size
);
1697 status
= cli_ntcreate(targetcli
, targetpath
, 0,
1698 WRITE_DAC_ACCESS
| WRITE_OWNER_ACCESS
, 0,
1699 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
,
1700 0x0, 0x0, &fnum
, NULL
);
1701 if (!NT_STATUS_IS_OK(status
)) {
1702 DEBUG(5, ("cacl_set failed to open %s: %s\n",
1703 targetpath
, nt_errstr(status
)));
1708 status
= cli_set_secdesc(targetcli
, fnum
, sd
);
1709 if (!NT_STATUS_IS_OK(status
)) {
1710 DEBUG(5, ("ERROR: secdesc set failed: %s\n",
1711 nt_errstr(status
)));
1718 cli_close(targetcli
, fnum
);
1729 SMBC_setxattr_ctx(SMBCCTX
*context
,
1738 SMBCSRV
*srv
= NULL
;
1739 SMBCSRV
*ipc_srv
= NULL
;
1740 char *server
= NULL
;
1743 char *password
= NULL
;
1744 char *workgroup
= NULL
;
1746 struct DOS_ATTR_DESC
*dad
= NULL
;
1748 const char * create_time_attr
;
1749 const char * access_time_attr
;
1750 const char * write_time_attr
;
1751 const char * change_time_attr
;
1754 TALLOC_CTX
*frame
= talloc_stackframe();
1756 if (!context
|| !context
->internal
->initialized
) {
1757 errno
= EINVAL
; /* Best I can think of ... */
1768 DEBUG(4, ("smbc_setxattr(%s, %s, %.*s)\n",
1769 fname
, name
, (int) size
, (const char*)value
));
1771 if (SMBC_parse_path(frame
,
1787 if (!user
|| user
[0] == (char)0) {
1788 user
= talloc_strdup(frame
, smbc_getUser(context
));
1796 srv
= SMBC_server(frame
, context
, True
,
1797 server
, port
, share
, &workgroup
, &user
, &password
);
1800 return -1; /* errno set by SMBC_server */
1803 if (! srv
->no_nt_session
) {
1804 ipc_srv
= SMBC_attr_server(frame
, context
, server
, port
, share
,
1805 &workgroup
, &user
, &password
);
1807 srv
->no_nt_session
= True
;
1814 * Are they asking to set the entire set of known attributes?
1816 if (strcasecmp_m(name
, "system.*") == 0 ||
1817 strcasecmp_m(name
, "system.*+") == 0) {
1820 talloc_asprintf(talloc_tos(), "%s:%s",
1821 name
+7, (const char *) value
);
1830 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1831 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1834 ? SMBC_XATTR_MODE_SET
1835 : SMBC_XATTR_MODE_ADD
),
1841 /* get a DOS Attribute Descriptor with current attributes */
1842 dad
= dos_attr_query(context
, talloc_tos(), path
, srv
);
1846 /* Overwrite old with new, using what was provided */
1847 dos_attr_parse(context
, dad
, srv
, namevalue
);
1849 /* Set the new DOS attributes */
1855 .tv_sec
= dad
->create_time
},
1857 .tv_sec
= dad
->access_time
},
1859 .tv_sec
= dad
->write_time
},
1861 .tv_sec
= dad
->change_time
},
1864 /* cause failure if NT failed too */
1869 /* we only fail if both NT and DOS sets failed */
1870 if (ret
< 0 && ! dad
) {
1871 ret
= -1; /* in case dad was null */
1882 * Are they asking to set an access control element or to set
1883 * the entire access control list?
1885 if (strcasecmp_m(name
, "system.nt_sec_desc.*") == 0 ||
1886 strcasecmp_m(name
, "system.nt_sec_desc.*+") == 0 ||
1887 strcasecmp_m(name
, "system.nt_sec_desc.revision") == 0 ||
1888 strncasecmp_m(name
, "system.nt_sec_desc.acl", 22) == 0 ||
1889 strncasecmp_m(name
, "system.nt_sec_desc.acl+", 23) == 0) {
1893 talloc_asprintf(talloc_tos(), "%s:%s",
1894 name
+19, (const char *) value
);
1897 ret
= -1; /* errno set by SMBC_server() */
1899 else if (! namevalue
) {
1903 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1904 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1907 ? SMBC_XATTR_MODE_SET
1908 : SMBC_XATTR_MODE_ADD
),
1916 * Are they asking to set the owner?
1918 if (strcasecmp_m(name
, "system.nt_sec_desc.owner") == 0 ||
1919 strcasecmp_m(name
, "system.nt_sec_desc.owner+") == 0) {
1923 talloc_asprintf(talloc_tos(), "%s:%s",
1924 name
+19, (const char *) value
);
1927 ret
= -1; /* errno set by SMBC_server() */
1929 else if (! namevalue
) {
1933 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1934 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1935 namevalue
, SMBC_XATTR_MODE_CHOWN
, 0);
1942 * Are they asking to set the group?
1944 if (strcasecmp_m(name
, "system.nt_sec_desc.group") == 0 ||
1945 strcasecmp_m(name
, "system.nt_sec_desc.group+") == 0) {
1949 talloc_asprintf(talloc_tos(), "%s:%s",
1950 name
+19, (const char *) value
);
1953 /* errno set by SMBC_server() */
1956 else if (! namevalue
) {
1960 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1961 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1962 namevalue
, SMBC_XATTR_MODE_CHGRP
, 0);
1968 /* Determine whether to use old-style or new-style attribute names */
1969 if (context
->internal
->full_time_names
) {
1970 /* new-style names */
1971 attr_strings
.create_time_attr
= "system.dos_attr.CREATE_TIME";
1972 attr_strings
.access_time_attr
= "system.dos_attr.ACCESS_TIME";
1973 attr_strings
.write_time_attr
= "system.dos_attr.WRITE_TIME";
1974 attr_strings
.change_time_attr
= "system.dos_attr.CHANGE_TIME";
1976 /* old-style names */
1977 attr_strings
.create_time_attr
= NULL
;
1978 attr_strings
.access_time_attr
= "system.dos_attr.A_TIME";
1979 attr_strings
.write_time_attr
= "system.dos_attr.M_TIME";
1980 attr_strings
.change_time_attr
= "system.dos_attr.C_TIME";
1984 * Are they asking to set a DOS attribute?
1986 if (strcasecmp_m(name
, "system.dos_attr.*") == 0 ||
1987 strcasecmp_m(name
, "system.dos_attr.mode") == 0 ||
1988 (attr_strings
.create_time_attr
!= NULL
&&
1989 strcasecmp_m(name
, attr_strings
.create_time_attr
) == 0) ||
1990 strcasecmp_m(name
, attr_strings
.access_time_attr
) == 0 ||
1991 strcasecmp_m(name
, attr_strings
.write_time_attr
) == 0 ||
1992 strcasecmp_m(name
, attr_strings
.change_time_attr
) == 0) {
1994 /* get a DOS Attribute Descriptor with current attributes */
1995 dad
= dos_attr_query(context
, talloc_tos(), path
, srv
);
1998 talloc_asprintf(talloc_tos(), "%s:%s",
1999 name
+16, (const char *) value
);
2004 /* Overwrite old with provided new params */
2005 dos_attr_parse(context
, dad
, srv
, namevalue
);
2007 /* Set the new DOS attributes */
2013 .tv_sec
= dad
->create_time
},
2015 .tv_sec
= dad
->access_time
},
2017 .tv_sec
= dad
->write_time
},
2019 .tv_sec
= dad
->change_time
},
2022 /* ret2 has True (success) / False (failure) */
2037 /* Unsupported attribute name */
2044 SMBC_getxattr_ctx(SMBCCTX
*context
,
2051 SMBCSRV
*srv
= NULL
;
2052 SMBCSRV
*ipc_srv
= NULL
;
2053 char *server
= NULL
;
2056 char *password
= NULL
;
2057 char *workgroup
= NULL
;
2060 const char * create_time_attr
;
2061 const char * access_time_attr
;
2062 const char * write_time_attr
;
2063 const char * change_time_attr
;
2066 TALLOC_CTX
*frame
= talloc_stackframe();
2068 if (!context
|| !context
->internal
->initialized
) {
2069 errno
= EINVAL
; /* Best I can think of ... */
2080 DEBUG(4, ("smbc_getxattr(%s, %s)\n", fname
, name
));
2082 if (SMBC_parse_path(frame
,
2098 if (!user
|| user
[0] == '\0') {
2099 user
= talloc_strdup(frame
, smbc_getUser(context
));
2107 srv
= SMBC_server(frame
, context
, True
,
2108 server
, port
, share
, &workgroup
, &user
, &password
);
2111 return -1; /* errno set by SMBC_server */
2114 if (! srv
->no_nt_session
) {
2115 ipc_srv
= SMBC_attr_server(frame
, context
, server
, port
, share
,
2116 &workgroup
, &user
, &password
);
2118 * SMBC_attr_server() can cause the original
2119 * server to be removed from the cache.
2120 * If so we must error out here as the srv
2121 * pointer has been freed.
2123 if (smbc_getFunctionGetCachedServer(context
)(context
,
2128 #if defined(ECONNRESET)
2137 srv
->no_nt_session
= True
;
2143 /* Determine whether to use old-style or new-style attribute names */
2144 if (context
->internal
->full_time_names
) {
2145 /* new-style names */
2146 attr_strings
.create_time_attr
= "system.dos_attr.CREATE_TIME";
2147 attr_strings
.access_time_attr
= "system.dos_attr.ACCESS_TIME";
2148 attr_strings
.write_time_attr
= "system.dos_attr.WRITE_TIME";
2149 attr_strings
.change_time_attr
= "system.dos_attr.CHANGE_TIME";
2151 /* old-style names */
2152 attr_strings
.create_time_attr
= NULL
;
2153 attr_strings
.access_time_attr
= "system.dos_attr.A_TIME";
2154 attr_strings
.write_time_attr
= "system.dos_attr.M_TIME";
2155 attr_strings
.change_time_attr
= "system.dos_attr.C_TIME";
2158 /* Are they requesting a supported attribute? */
2159 if (strcasecmp_m(name
, "system.*") == 0 ||
2160 strncasecmp_m(name
, "system.*!", 9) == 0 ||
2161 strcasecmp_m(name
, "system.*+") == 0 ||
2162 strncasecmp_m(name
, "system.*+!", 10) == 0 ||
2163 strcasecmp_m(name
, "system.nt_sec_desc.*") == 0 ||
2164 strncasecmp_m(name
, "system.nt_sec_desc.*!", 21) == 0 ||
2165 strcasecmp_m(name
, "system.nt_sec_desc.*+") == 0 ||
2166 strncasecmp_m(name
, "system.nt_sec_desc.*+!", 22) == 0 ||
2167 strcasecmp_m(name
, "system.nt_sec_desc.revision") == 0 ||
2168 strcasecmp_m(name
, "system.nt_sec_desc.owner") == 0 ||
2169 strcasecmp_m(name
, "system.nt_sec_desc.owner+") == 0 ||
2170 strcasecmp_m(name
, "system.nt_sec_desc.group") == 0 ||
2171 strcasecmp_m(name
, "system.nt_sec_desc.group+") == 0 ||
2172 strncasecmp_m(name
, "system.nt_sec_desc.acl", 22) == 0 ||
2173 strncasecmp_m(name
, "system.nt_sec_desc.acl+", 23) == 0 ||
2174 strcasecmp_m(name
, "system.dos_attr.*") == 0 ||
2175 strncasecmp_m(name
, "system.dos_attr.*!", 18) == 0 ||
2176 strcasecmp_m(name
, "system.dos_attr.mode") == 0 ||
2177 strcasecmp_m(name
, "system.dos_attr.size") == 0 ||
2178 (attr_strings
.create_time_attr
!= NULL
&&
2179 strcasecmp_m(name
, attr_strings
.create_time_attr
) == 0) ||
2180 strcasecmp_m(name
, attr_strings
.access_time_attr
) == 0 ||
2181 strcasecmp_m(name
, attr_strings
.write_time_attr
) == 0 ||
2182 strcasecmp_m(name
, attr_strings
.change_time_attr
) == 0 ||
2183 strcasecmp_m(name
, "system.dos_attr.inode") == 0) {
2186 const char *filename
= name
;
2187 ret
= cacl_get(context
, talloc_tos(), srv
,
2188 ipc_srv
== NULL
? NULL
: ipc_srv
->cli
,
2189 &ipc_srv
->pol
, path
,
2191 discard_const_p(char, value
),
2195 * static function cacl_get returns a value greater than zero
2196 * which is needed buffer size needed when size_t is 0.
2201 /* Unsupported attribute name */
2209 SMBC_removexattr_ctx(SMBCCTX
*context
,
2214 SMBCSRV
*srv
= NULL
;
2215 SMBCSRV
*ipc_srv
= NULL
;
2216 char *server
= NULL
;
2219 char *password
= NULL
;
2220 char *workgroup
= NULL
;
2223 TALLOC_CTX
*frame
= talloc_stackframe();
2225 if (!context
|| !context
->internal
->initialized
) {
2226 errno
= EINVAL
; /* Best I can think of ... */
2237 DEBUG(4, ("smbc_removexattr(%s, %s)\n", fname
, name
));
2239 if (SMBC_parse_path(frame
,
2255 if (!user
|| user
[0] == (char)0) {
2256 user
= talloc_strdup(frame
, smbc_getUser(context
));
2264 srv
= SMBC_server(frame
, context
, True
,
2265 server
, port
, share
, &workgroup
, &user
, &password
);
2268 return -1; /* errno set by SMBC_server */
2271 if (! srv
->no_nt_session
) {
2273 ipc_srv
= SMBC_attr_server(frame
, context
, server
, port
, share
,
2274 &workgroup
, &user
, &password
);
2275 saved_errno
= errno
;
2277 * SMBC_attr_server() can cause the original
2278 * server to be removed from the cache.
2279 * If so we must error out here as the srv
2280 * pointer has been freed.
2282 if (smbc_getFunctionGetCachedServer(context
)(context
,
2287 #if defined(ECONNRESET)
2296 errno
= saved_errno
;
2297 srv
->no_nt_session
= True
;
2305 return -1; /* errno set by SMBC_attr_server */
2308 /* Are they asking to set the entire ACL? */
2309 if (strcasecmp_m(name
, "system.nt_sec_desc.*") == 0 ||
2310 strcasecmp_m(name
, "system.nt_sec_desc.*+") == 0) {
2313 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
2314 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
2315 NULL
, SMBC_XATTR_MODE_REMOVE_ALL
, 0);
2321 * Are they asking to remove one or more specific security descriptor
2324 if (strcasecmp_m(name
, "system.nt_sec_desc.revision") == 0 ||
2325 strcasecmp_m(name
, "system.nt_sec_desc.owner") == 0 ||
2326 strcasecmp_m(name
, "system.nt_sec_desc.owner+") == 0 ||
2327 strcasecmp_m(name
, "system.nt_sec_desc.group") == 0 ||
2328 strcasecmp_m(name
, "system.nt_sec_desc.group+") == 0 ||
2329 strncasecmp_m(name
, "system.nt_sec_desc.acl", 22) == 0 ||
2330 strncasecmp_m(name
, "system.nt_sec_desc.acl+", 23) == 0) {
2333 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
2334 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
2335 discard_const_p(char, name
) + 19,
2336 SMBC_XATTR_MODE_REMOVE
, 0);
2341 /* Unsupported attribute name */
2348 SMBC_listxattr_ctx(SMBCCTX
*context
,
2354 * This isn't quite what listxattr() is supposed to do. This returns
2355 * the complete set of attribute names, always, rather than only those
2356 * attribute names which actually exist for a file. Hmmm...
2359 static const char supported_old
[] =
2362 "system.nt_sec_desc.revision\0"
2363 "system.nt_sec_desc.owner\0"
2364 "system.nt_sec_desc.owner+\0"
2365 "system.nt_sec_desc.group\0"
2366 "system.nt_sec_desc.group+\0"
2367 "system.nt_sec_desc.acl.*\0"
2368 "system.nt_sec_desc.acl\0"
2369 "system.nt_sec_desc.acl+\0"
2370 "system.nt_sec_desc.*\0"
2371 "system.nt_sec_desc.*+\0"
2372 "system.dos_attr.*\0"
2373 "system.dos_attr.mode\0"
2374 "system.dos_attr.c_time\0"
2375 "system.dos_attr.a_time\0"
2376 "system.dos_attr.m_time\0"
2378 static const char supported_new
[] =
2381 "system.nt_sec_desc.revision\0"
2382 "system.nt_sec_desc.owner\0"
2383 "system.nt_sec_desc.owner+\0"
2384 "system.nt_sec_desc.group\0"
2385 "system.nt_sec_desc.group+\0"
2386 "system.nt_sec_desc.acl.*\0"
2387 "system.nt_sec_desc.acl\0"
2388 "system.nt_sec_desc.acl+\0"
2389 "system.nt_sec_desc.*\0"
2390 "system.nt_sec_desc.*+\0"
2391 "system.dos_attr.*\0"
2392 "system.dos_attr.mode\0"
2393 "system.dos_attr.create_time\0"
2394 "system.dos_attr.access_time\0"
2395 "system.dos_attr.write_time\0"
2396 "system.dos_attr.change_time\0"
2398 const char * supported
;
2400 if (context
->internal
->full_time_names
) {
2401 supported
= supported_new
;
2402 retsize
= sizeof(supported_new
);
2404 supported
= supported_old
;
2405 retsize
= sizeof(supported_old
);
2412 if (retsize
> size
) {
2417 /* this can't be strcpy() because there are embedded null characters */
2418 memcpy(list
, supported
, retsize
);