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 "libsmbclient.h"
27 #include "libsmb_internal.h"
28 #include "../librpc/gen_ndr/ndr_lsa.h"
32 * Find an lsa pipe handle associated with a cli struct.
34 static struct rpc_pipe_client
*
35 find_lsa_pipe_hnd(struct cli_state
*ipc_cli
)
37 struct rpc_pipe_client
*pipe_hnd
;
39 for (pipe_hnd
= ipc_cli
->pipe_list
;
41 pipe_hnd
= pipe_hnd
->next
) {
42 if (ndr_syntax_id_equal(&pipe_hnd
->abstract_syntax
,
43 &ndr_table_lsarpc
.syntax_id
)) {
51 * Sort ACEs according to the documentation at
52 * http://support.microsoft.com/kb/269175, at least as far as it defines the
57 ace_compare(SEC_ACE
*ace1
,
63 /* If the ACEs are equal, we have nothing more to do. */
64 if (sec_ace_equal(ace1
, ace2
)) {
68 /* Inherited follow non-inherited */
69 b1
= ((ace1
->flags
& SEC_ACE_FLAG_INHERITED_ACE
) != 0);
70 b2
= ((ace2
->flags
& SEC_ACE_FLAG_INHERITED_ACE
) != 0);
76 * What shall we do with AUDITs and ALARMs? It's undefined. We'll
77 * sort them after DENY and ALLOW.
79 b1
= (ace1
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED
&&
80 ace1
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
&&
81 ace1
->type
!= SEC_ACE_TYPE_ACCESS_DENIED
&&
82 ace1
->type
!= SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
83 b2
= (ace2
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED
&&
84 ace2
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
&&
85 ace2
->type
!= SEC_ACE_TYPE_ACCESS_DENIED
&&
86 ace2
->type
!= SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
91 /* Allowed ACEs follow denied ACEs */
92 b1
= (ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED
||
93 ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
);
94 b2
= (ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED
||
95 ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
);
101 * ACEs applying to an entity's object follow those applying to the
104 b1
= (ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
||
105 ace1
->type
== SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
106 b2
= (ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
||
107 ace2
->type
== SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
109 return (b1
? 1 : -1);
113 * If we get this far, the ACEs are similar as far as the
114 * characteristics we typically care about (those defined by the
115 * referenced MS document). We'll now sort by characteristics that
116 * just seems reasonable.
119 if (ace1
->type
!= ace2
->type
) {
120 return ace2
->type
- ace1
->type
;
123 if (sid_compare(&ace1
->trustee
, &ace2
->trustee
)) {
124 return sid_compare(&ace1
->trustee
, &ace2
->trustee
);
127 if (ace1
->flags
!= ace2
->flags
) {
128 return ace1
->flags
- ace2
->flags
;
131 if (ace1
->access_mask
!= ace2
->access_mask
) {
132 return ace1
->access_mask
- ace2
->access_mask
;
135 if (ace1
->size
!= ace2
->size
) {
136 return ace1
->size
- ace2
->size
;
139 return memcmp(ace1
, ace2
, sizeof(SEC_ACE
));
144 sort_acl(SEC_ACL
*the_acl
)
147 if (!the_acl
) return;
149 TYPESAFE_QSORT(the_acl
->aces
, the_acl
->num_aces
, ace_compare
);
151 for (i
=1;i
<the_acl
->num_aces
;) {
152 if (sec_ace_equal(&the_acl
->aces
[i
-1], &the_acl
->aces
[i
])) {
154 for (j
=i
; j
<the_acl
->num_aces
-1; j
++) {
155 the_acl
->aces
[j
] = the_acl
->aces
[j
+1];
164 /* convert a SID to a string, either numeric or username/group */
166 convert_sid_to_string(struct cli_state
*ipc_cli
,
167 struct policy_handle
*pol
,
172 char **domains
= NULL
;
174 enum lsa_SidType
*types
= NULL
;
175 struct rpc_pipe_client
*pipe_hnd
= find_lsa_pipe_hnd(ipc_cli
);
178 sid_to_fstring(str
, sid
);
181 return; /* no lookup desired */
188 /* Ask LSA to convert the sid to a name */
190 ctx
= talloc_stackframe();
192 if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_sids(pipe_hnd
, ctx
,
193 pol
, 1, sid
, &domains
,
195 !domains
|| !domains
[0] || !names
|| !names
[0]) {
202 slprintf(str
, sizeof(fstring
) - 1, "%s%s%s",
203 domains
[0], lp_winbind_separator(),
209 /* convert a string to a SID, either numeric or username/group */
211 convert_string_to_sid(struct cli_state
*ipc_cli
,
212 struct policy_handle
*pol
,
217 enum lsa_SidType
*types
= NULL
;
218 DOM_SID
*sids
= NULL
;
220 TALLOC_CTX
*ctx
= NULL
;
221 struct rpc_pipe_client
*pipe_hnd
= find_lsa_pipe_hnd(ipc_cli
);
228 if (strncmp(str
, "S-", 2) == 0) {
229 return string_to_sid(sid
, str
);
236 ctx
= talloc_stackframe();
237 if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_names(pipe_hnd
, ctx
,
245 sid_copy(sid
, &sids
[0]);
252 /* parse an ACE in the same format as print_ace() */
254 parse_ace(struct cli_state
*ipc_cli
,
255 struct policy_handle
*pol
,
268 const struct perm_value
*v
;
273 TALLOC_CTX
*frame
= talloc_stackframe();
275 /* These values discovered by inspection */
276 static const struct perm_value special_values
[] = {
286 static const struct perm_value standard_values
[] = {
287 { "READ", 0x001200a9 },
288 { "CHANGE", 0x001301bf },
289 { "FULL", 0x001f01ff },
294 p
= strchr_m(str
,':');
301 /* Try to parse numeric form */
303 if (sscanf(p
, "%i/%i/%i", &atype
, &aflags
, &amask
) == 3 &&
304 convert_string_to_sid(ipc_cli
, pol
, numeric
, &sid
, str
)) {
308 /* Try to parse text form */
310 if (!convert_string_to_sid(ipc_cli
, pol
, numeric
, &sid
, str
)) {
316 if (!next_token_talloc(frame
, &cp
, &tok
, "/")) {
321 if (StrnCaseCmp(tok
, "ALLOWED", strlen("ALLOWED")) == 0) {
322 atype
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
323 } else if (StrnCaseCmp(tok
, "DENIED", strlen("DENIED")) == 0) {
324 atype
= SEC_ACE_TYPE_ACCESS_DENIED
;
330 /* Only numeric form accepted for flags at present */
332 if (!(next_token_talloc(frame
, &cp
, &tok
, "/") &&
333 sscanf(tok
, "%i", &aflags
))) {
338 if (!next_token_talloc(frame
, &cp
, &tok
, "/")) {
343 if (strncmp(tok
, "0x", 2) == 0) {
344 if (sscanf(tok
, "%i", &amask
) != 1) {
351 for (v
= standard_values
; v
->perm
; v
++) {
352 if (strcmp(tok
, v
->perm
) == 0) {
363 for (v
= special_values
; v
->perm
; v
++) {
364 if (v
->perm
[0] == *p
) {
384 init_sec_ace(ace
, &sid
, atype
, mask
, aflags
);
389 /* add an ACE to a list of ACEs in a SEC_ACL */
391 add_ace(SEC_ACL
**the_acl
,
399 (*the_acl
) = make_sec_acl(ctx
, 3, 1, ace
);
403 if ((aces
= SMB_CALLOC_ARRAY(SEC_ACE
,
404 1+(*the_acl
)->num_aces
)) == NULL
) {
407 memcpy(aces
, (*the_acl
)->aces
, (*the_acl
)->num_aces
* sizeof(SEC_ACE
));
408 memcpy(aces
+(*the_acl
)->num_aces
, ace
, sizeof(SEC_ACE
));
409 newacl
= make_sec_acl(ctx
, (*the_acl
)->revision
,
410 1+(*the_acl
)->num_aces
, aces
);
417 /* parse a ascii version of a security descriptor */
419 sec_desc_parse(TALLOC_CTX
*ctx
,
420 struct cli_state
*ipc_cli
,
421 struct policy_handle
*pol
,
427 SEC_DESC
*ret
= NULL
;
429 DOM_SID
*group_sid
=NULL
;
430 DOM_SID
*owner_sid
=NULL
;
434 while (next_token_talloc(ctx
, &p
, &tok
, "\t,\r\n")) {
436 if (StrnCaseCmp(tok
,"REVISION:", 9) == 0) {
437 revision
= strtol(tok
+9, NULL
, 16);
441 if (StrnCaseCmp(tok
,"OWNER:", 6) == 0) {
443 DEBUG(5,("OWNER specified more than once!\n"));
446 owner_sid
= SMB_CALLOC_ARRAY(DOM_SID
, 1);
448 !convert_string_to_sid(ipc_cli
, pol
,
451 DEBUG(5, ("Failed to parse owner sid\n"));
457 if (StrnCaseCmp(tok
,"OWNER+:", 7) == 0) {
459 DEBUG(5,("OWNER specified more than once!\n"));
462 owner_sid
= SMB_CALLOC_ARRAY(DOM_SID
, 1);
464 !convert_string_to_sid(ipc_cli
, pol
,
467 DEBUG(5, ("Failed to parse owner sid\n"));
473 if (StrnCaseCmp(tok
,"GROUP:", 6) == 0) {
475 DEBUG(5,("GROUP specified more than once!\n"));
478 group_sid
= SMB_CALLOC_ARRAY(DOM_SID
, 1);
480 !convert_string_to_sid(ipc_cli
, pol
,
483 DEBUG(5, ("Failed to parse group sid\n"));
489 if (StrnCaseCmp(tok
,"GROUP+:", 7) == 0) {
491 DEBUG(5,("GROUP specified more than once!\n"));
494 group_sid
= SMB_CALLOC_ARRAY(DOM_SID
, 1);
496 !convert_string_to_sid(ipc_cli
, pol
,
499 DEBUG(5, ("Failed to parse group sid\n"));
505 if (StrnCaseCmp(tok
,"ACL:", 4) == 0) {
507 if (!parse_ace(ipc_cli
, pol
, &ace
, numeric
, tok
+4)) {
508 DEBUG(5, ("Failed to parse ACL %s\n", tok
));
511 if(!add_ace(&dacl
, &ace
, ctx
)) {
512 DEBUG(5, ("Failed to add ACL %s\n", tok
));
518 if (StrnCaseCmp(tok
,"ACL+:", 5) == 0) {
520 if (!parse_ace(ipc_cli
, pol
, &ace
, False
, tok
+5)) {
521 DEBUG(5, ("Failed to parse ACL %s\n", tok
));
524 if(!add_ace(&dacl
, &ace
, ctx
)) {
525 DEBUG(5, ("Failed to add ACL %s\n", tok
));
531 DEBUG(5, ("Failed to parse security descriptor\n"));
535 ret
= make_sec_desc(ctx
, revision
, SEC_DESC_SELF_RELATIVE
,
536 owner_sid
, group_sid
, NULL
, dacl
, &sd_size
);
539 SAFE_FREE(group_sid
);
540 SAFE_FREE(owner_sid
);
545 /* Obtain the current dos attributes */
546 static DOS_ATTR_DESC
*
547 dos_attr_query(SMBCCTX
*context
,
549 const char *filename
,
552 struct timespec create_time_ts
;
553 struct timespec write_time_ts
;
554 struct timespec access_time_ts
;
555 struct timespec change_time_ts
;
561 ret
= TALLOC_P(ctx
, DOS_ATTR_DESC
);
567 /* Obtain the DOS attributes */
568 if (!SMBC_getatr(context
, srv
, CONST_DISCARD(char *, filename
),
575 errno
= SMBC_errno(context
, srv
->cli
);
576 DEBUG(5, ("dos_attr_query Failed to query old attributes\n"));
582 ret
->create_time
= convert_timespec_to_time_t(create_time_ts
);
583 ret
->access_time
= convert_timespec_to_time_t(access_time_ts
);
584 ret
->write_time
= convert_timespec_to_time_t(write_time_ts
);
585 ret
->change_time
= convert_timespec_to_time_t(change_time_ts
);
592 /* parse a ascii version of a security descriptor */
594 dos_attr_parse(SMBCCTX
*context
,
602 TALLOC_CTX
*frame
= NULL
;
604 const char * create_time_attr
;
605 const char * access_time_attr
;
606 const char * write_time_attr
;
607 const char * change_time_attr
;
610 /* Determine whether to use old-style or new-style attribute names */
611 if (context
->internal
->full_time_names
) {
612 /* new-style names */
613 attr_strings
.create_time_attr
= "CREATE_TIME";
614 attr_strings
.access_time_attr
= "ACCESS_TIME";
615 attr_strings
.write_time_attr
= "WRITE_TIME";
616 attr_strings
.change_time_attr
= "CHANGE_TIME";
618 /* old-style names */
619 attr_strings
.create_time_attr
= NULL
;
620 attr_strings
.access_time_attr
= "A_TIME";
621 attr_strings
.write_time_attr
= "M_TIME";
622 attr_strings
.change_time_attr
= "C_TIME";
625 /* if this is to set the entire ACL... */
627 /* ... then increment past the first colon if there is one */
628 if ((p
= strchr(str
, ':')) != NULL
) {
635 frame
= talloc_stackframe();
636 while (next_token_talloc(frame
, &p
, &tok
, "\t,\r\n")) {
637 if (StrnCaseCmp(tok
, "MODE:", 5) == 0) {
638 long request
= strtol(tok
+5, NULL
, 16);
640 dad
->mode
= (request
|
641 (IS_DOS_DIR(dad
->mode
)
642 ? FILE_ATTRIBUTE_DIRECTORY
643 : FILE_ATTRIBUTE_NORMAL
));
650 if (StrnCaseCmp(tok
, "SIZE:", 5) == 0) {
651 dad
->size
= (SMB_OFF_T
)atof(tok
+5);
655 n
= strlen(attr_strings
.access_time_attr
);
656 if (StrnCaseCmp(tok
, attr_strings
.access_time_attr
, n
) == 0) {
657 dad
->access_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
661 n
= strlen(attr_strings
.change_time_attr
);
662 if (StrnCaseCmp(tok
, attr_strings
.change_time_attr
, n
) == 0) {
663 dad
->change_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
667 n
= strlen(attr_strings
.write_time_attr
);
668 if (StrnCaseCmp(tok
, attr_strings
.write_time_attr
, n
) == 0) {
669 dad
->write_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
673 if (attr_strings
.create_time_attr
!= NULL
) {
674 n
= strlen(attr_strings
.create_time_attr
);
675 if (StrnCaseCmp(tok
, attr_strings
.create_time_attr
,
677 dad
->create_time
= (time_t)strtol(tok
+n
+1,
683 if (StrnCaseCmp(tok
, "INODE:", 6) == 0) {
684 dad
->inode
= (SMB_INO_T
)atof(tok
+6);
691 /*****************************************************
692 Retrieve the acls for a file.
693 *******************************************************/
696 cacl_get(SMBCCTX
*context
,
699 struct cli_state
*ipc_cli
,
700 struct policy_handle
*pol
,
715 bool exclude_nt_revision
= False
;
716 bool exclude_nt_owner
= False
;
717 bool exclude_nt_group
= False
;
718 bool exclude_nt_acl
= False
;
719 bool exclude_dos_mode
= False
;
720 bool exclude_dos_size
= False
;
721 bool exclude_dos_create_time
= False
;
722 bool exclude_dos_access_time
= False
;
723 bool exclude_dos_write_time
= False
;
724 bool exclude_dos_change_time
= False
;
725 bool exclude_dos_inode
= False
;
727 bool determine_size
= (bufsize
== 0);
731 fstring name_sandbox
;
735 struct timespec create_time_ts
;
736 struct timespec write_time_ts
;
737 struct timespec access_time_ts
;
738 struct timespec change_time_ts
;
739 time_t create_time
= (time_t)0;
740 time_t write_time
= (time_t)0;
741 time_t access_time
= (time_t)0;
742 time_t change_time
= (time_t)0;
746 struct cli_state
*cli
= srv
->cli
;
748 const char * create_time_attr
;
749 const char * access_time_attr
;
750 const char * write_time_attr
;
751 const char * change_time_attr
;
754 const char * create_time_attr
;
755 const char * access_time_attr
;
756 const char * write_time_attr
;
757 const char * change_time_attr
;
760 /* Determine whether to use old-style or new-style attribute names */
761 if (context
->internal
->full_time_names
) {
762 /* new-style names */
763 attr_strings
.create_time_attr
= "CREATE_TIME";
764 attr_strings
.access_time_attr
= "ACCESS_TIME";
765 attr_strings
.write_time_attr
= "WRITE_TIME";
766 attr_strings
.change_time_attr
= "CHANGE_TIME";
768 excl_attr_strings
.create_time_attr
= "CREATE_TIME";
769 excl_attr_strings
.access_time_attr
= "ACCESS_TIME";
770 excl_attr_strings
.write_time_attr
= "WRITE_TIME";
771 excl_attr_strings
.change_time_attr
= "CHANGE_TIME";
773 /* old-style names */
774 attr_strings
.create_time_attr
= NULL
;
775 attr_strings
.access_time_attr
= "A_TIME";
776 attr_strings
.write_time_attr
= "M_TIME";
777 attr_strings
.change_time_attr
= "C_TIME";
779 excl_attr_strings
.create_time_attr
= NULL
;
780 excl_attr_strings
.access_time_attr
= "dos_attr.A_TIME";
781 excl_attr_strings
.write_time_attr
= "dos_attr.M_TIME";
782 excl_attr_strings
.change_time_attr
= "dos_attr.C_TIME";
785 /* Copy name so we can strip off exclusions (if any are specified) */
786 strncpy(name_sandbox
, attr_name
, sizeof(name_sandbox
) - 1);
788 /* Ensure name is null terminated */
789 name_sandbox
[sizeof(name_sandbox
) - 1] = '\0';
791 /* Play in the sandbox */
794 /* If there are any exclusions, point to them and mask them from name */
795 if ((pExclude
= strchr(name
, '!')) != NULL
)
800 all
= (StrnCaseCmp(name
, "system.*", 8) == 0);
801 all_nt
= (StrnCaseCmp(name
, "system.nt_sec_desc.*", 20) == 0);
802 all_nt_acls
= (StrnCaseCmp(name
, "system.nt_sec_desc.acl.*", 24) == 0);
803 all_dos
= (StrnCaseCmp(name
, "system.dos_attr.*", 17) == 0);
804 some_nt
= (StrnCaseCmp(name
, "system.nt_sec_desc.", 19) == 0);
805 some_dos
= (StrnCaseCmp(name
, "system.dos_attr.", 16) == 0);
806 numeric
= (* (name
+ strlen(name
) - 1) != '+');
808 /* Look for exclusions from "all" requests */
809 if (all
|| all_nt
|| all_dos
) {
810 /* Exclusions are delimited by '!' */
813 pExclude
= (p
== NULL
? NULL
: p
+ 1)) {
815 /* Find end of this exclusion name */
816 if ((p
= strchr(pExclude
, '!')) != NULL
)
821 /* Which exclusion name is this? */
822 if (StrCaseCmp(pExclude
,
823 "nt_sec_desc.revision") == 0) {
824 exclude_nt_revision
= True
;
826 else if (StrCaseCmp(pExclude
,
827 "nt_sec_desc.owner") == 0) {
828 exclude_nt_owner
= True
;
830 else if (StrCaseCmp(pExclude
,
831 "nt_sec_desc.group") == 0) {
832 exclude_nt_group
= True
;
834 else if (StrCaseCmp(pExclude
,
835 "nt_sec_desc.acl") == 0) {
836 exclude_nt_acl
= True
;
838 else if (StrCaseCmp(pExclude
,
839 "dos_attr.mode") == 0) {
840 exclude_dos_mode
= True
;
842 else if (StrCaseCmp(pExclude
,
843 "dos_attr.size") == 0) {
844 exclude_dos_size
= True
;
846 else if (excl_attr_strings
.create_time_attr
!= NULL
&&
848 excl_attr_strings
.change_time_attr
) == 0) {
849 exclude_dos_create_time
= True
;
851 else if (StrCaseCmp(pExclude
,
852 excl_attr_strings
.access_time_attr
) == 0) {
853 exclude_dos_access_time
= True
;
855 else if (StrCaseCmp(pExclude
,
856 excl_attr_strings
.write_time_attr
) == 0) {
857 exclude_dos_write_time
= True
;
859 else if (StrCaseCmp(pExclude
,
860 excl_attr_strings
.change_time_attr
) == 0) {
861 exclude_dos_change_time
= True
;
863 else if (StrCaseCmp(pExclude
, "dos_attr.inode") == 0) {
864 exclude_dos_inode
= True
;
867 DEBUG(5, ("cacl_get received unknown exclusion: %s\n",
878 * If we are (possibly) talking to an NT or new system and some NT
879 * attributes have been requested...
881 if (ipc_cli
&& (all
|| some_nt
|| all_nt_acls
)) {
882 char *targetpath
= NULL
;
883 struct cli_state
*targetcli
= NULL
;
885 /* Point to the portion after "system.nt_sec_desc." */
886 name
+= 19; /* if (all) this will be invalid but unused */
888 if (!cli_resolve_path(ctx
, "", context
->internal
->auth_info
,
890 &targetcli
, &targetpath
)) {
891 DEBUG(5, ("cacl_get Could not resolve %s\n",
897 /* ... then obtain any NT attributes which were requested */
898 if (!NT_STATUS_IS_OK(cli_ntcreate(targetcli
, targetpath
, 0, CREATE_ACCESS_READ
, 0,
899 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum
))) {
900 DEBUG(5, ("cacl_get failed to open %s: %s\n",
901 targetpath
, cli_errstr(targetcli
)));
906 sd
= cli_query_secdesc(targetcli
, fnum
, ctx
);
910 ("cacl_get Failed to query old descriptor\n"));
915 cli_close(targetcli
, fnum
);
917 if (! exclude_nt_revision
) {
919 if (determine_size
) {
920 p
= talloc_asprintf(ctx
,
929 n
= snprintf(buf
, bufsize
,
933 } else if (StrCaseCmp(name
, "revision") == 0) {
934 if (determine_size
) {
935 p
= talloc_asprintf(ctx
, "%d",
943 n
= snprintf(buf
, bufsize
, "%d",
948 if (!determine_size
&& n
> bufsize
) {
958 if (! exclude_nt_owner
) {
959 /* Get owner and group sid */
961 convert_sid_to_string(ipc_cli
, pol
,
970 if (determine_size
) {
971 p
= talloc_asprintf(ctx
, ",OWNER:%s",
978 } else if (sidstr
[0] != '\0') {
979 n
= snprintf(buf
, bufsize
,
980 ",OWNER:%s", sidstr
);
982 } else if (StrnCaseCmp(name
, "owner", 5) == 0) {
983 if (determine_size
) {
984 p
= talloc_asprintf(ctx
, "%s", sidstr
);
991 n
= snprintf(buf
, bufsize
, "%s",
996 if (!determine_size
&& n
> bufsize
) {
1006 if (! exclude_nt_group
) {
1007 if (sd
->group_sid
) {
1008 convert_sid_to_string(ipc_cli
, pol
,
1012 fstrcpy(sidstr
, "");
1015 if (all
|| all_nt
) {
1016 if (determine_size
) {
1017 p
= talloc_asprintf(ctx
, ",GROUP:%s",
1024 } else if (sidstr
[0] != '\0') {
1025 n
= snprintf(buf
, bufsize
,
1026 ",GROUP:%s", sidstr
);
1028 } else if (StrnCaseCmp(name
, "group", 5) == 0) {
1029 if (determine_size
) {
1030 p
= talloc_asprintf(ctx
, "%s", sidstr
);
1037 n
= snprintf(buf
, bufsize
,
1042 if (!determine_size
&& n
> bufsize
) {
1052 if (! exclude_nt_acl
) {
1053 /* Add aces to value buffer */
1054 for (i
= 0; sd
->dacl
&& i
< sd
->dacl
->num_aces
; i
++) {
1056 SEC_ACE
*ace
= &sd
->dacl
->aces
[i
];
1057 convert_sid_to_string(ipc_cli
, pol
,
1061 if (all
|| all_nt
) {
1062 if (determine_size
) {
1063 p
= talloc_asprintf(
1079 ",ACL:%s:%d/%d/0x%08x",
1085 } else if ((StrnCaseCmp(name
, "acl", 3) == 0 &&
1086 StrCaseCmp(name
+3, sidstr
) == 0) ||
1087 (StrnCaseCmp(name
, "acl+", 4) == 0 &&
1088 StrCaseCmp(name
+4, sidstr
) == 0)) {
1089 if (determine_size
) {
1090 p
= talloc_asprintf(
1102 n
= snprintf(buf
, bufsize
,
1108 } else if (all_nt_acls
) {
1109 if (determine_size
) {
1110 p
= talloc_asprintf(
1112 "%s%s:%d/%d/0x%08x",
1124 n
= snprintf(buf
, bufsize
,
1125 "%s%s:%d/%d/0x%08x",
1133 if (!determine_size
&& n
> bufsize
) {
1144 /* Restore name pointer to its original value */
1148 if (all
|| some_dos
) {
1149 /* Point to the portion after "system.dos_attr." */
1150 name
+= 16; /* if (all) this will be invalid but unused */
1152 /* Obtain the DOS attributes */
1153 if (!SMBC_getatr(context
, srv
, filename
, &mode
, &size
,
1160 errno
= SMBC_errno(context
, srv
->cli
);
1164 create_time
= convert_timespec_to_time_t(create_time_ts
);
1165 access_time
= convert_timespec_to_time_t(access_time_ts
);
1166 write_time
= convert_timespec_to_time_t(write_time_ts
);
1167 change_time
= convert_timespec_to_time_t(change_time_ts
);
1169 if (! exclude_dos_mode
) {
1170 if (all
|| all_dos
) {
1171 if (determine_size
) {
1172 p
= talloc_asprintf(ctx
,
1185 n
= snprintf(buf
, bufsize
,
1193 } else if (StrCaseCmp(name
, "mode") == 0) {
1194 if (determine_size
) {
1195 p
= talloc_asprintf(ctx
, "0x%x", mode
);
1202 n
= snprintf(buf
, bufsize
,
1207 if (!determine_size
&& n
> bufsize
) {
1217 if (! exclude_dos_size
) {
1218 if (all
|| all_dos
) {
1219 if (determine_size
) {
1220 p
= talloc_asprintf(
1230 n
= snprintf(buf
, bufsize
,
1234 } else if (StrCaseCmp(name
, "size") == 0) {
1235 if (determine_size
) {
1236 p
= talloc_asprintf(
1246 n
= snprintf(buf
, bufsize
,
1252 if (!determine_size
&& n
> bufsize
) {
1262 if (! exclude_dos_create_time
&&
1263 attr_strings
.create_time_attr
!= NULL
) {
1264 if (all
|| all_dos
) {
1265 if (determine_size
) {
1266 p
= talloc_asprintf(ctx
,
1268 attr_strings
.create_time_attr
,
1269 (unsigned long) create_time
);
1276 n
= snprintf(buf
, bufsize
,
1278 attr_strings
.create_time_attr
,
1279 (unsigned long) create_time
);
1281 } else if (StrCaseCmp(name
, attr_strings
.create_time_attr
) == 0) {
1282 if (determine_size
) {
1283 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) create_time
);
1290 n
= snprintf(buf
, bufsize
,
1291 "%lu", (unsigned long) create_time
);
1295 if (!determine_size
&& n
> bufsize
) {
1305 if (! exclude_dos_access_time
) {
1306 if (all
|| all_dos
) {
1307 if (determine_size
) {
1308 p
= talloc_asprintf(ctx
,
1310 attr_strings
.access_time_attr
,
1311 (unsigned long) access_time
);
1318 n
= snprintf(buf
, bufsize
,
1320 attr_strings
.access_time_attr
,
1321 (unsigned long) access_time
);
1323 } else if (StrCaseCmp(name
, attr_strings
.access_time_attr
) == 0) {
1324 if (determine_size
) {
1325 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) access_time
);
1332 n
= snprintf(buf
, bufsize
,
1333 "%lu", (unsigned long) access_time
);
1337 if (!determine_size
&& n
> bufsize
) {
1347 if (! exclude_dos_write_time
) {
1348 if (all
|| all_dos
) {
1349 if (determine_size
) {
1350 p
= talloc_asprintf(ctx
,
1352 attr_strings
.write_time_attr
,
1353 (unsigned long) write_time
);
1360 n
= snprintf(buf
, bufsize
,
1362 attr_strings
.write_time_attr
,
1363 (unsigned long) write_time
);
1365 } else if (StrCaseCmp(name
, attr_strings
.write_time_attr
) == 0) {
1366 if (determine_size
) {
1367 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) write_time
);
1374 n
= snprintf(buf
, bufsize
,
1375 "%lu", (unsigned long) write_time
);
1379 if (!determine_size
&& n
> bufsize
) {
1389 if (! exclude_dos_change_time
) {
1390 if (all
|| all_dos
) {
1391 if (determine_size
) {
1392 p
= talloc_asprintf(ctx
,
1394 attr_strings
.change_time_attr
,
1395 (unsigned long) change_time
);
1402 n
= snprintf(buf
, bufsize
,
1404 attr_strings
.change_time_attr
,
1405 (unsigned long) change_time
);
1407 } else if (StrCaseCmp(name
, attr_strings
.change_time_attr
) == 0) {
1408 if (determine_size
) {
1409 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) change_time
);
1416 n
= snprintf(buf
, bufsize
,
1417 "%lu", (unsigned long) change_time
);
1421 if (!determine_size
&& n
> bufsize
) {
1431 if (! exclude_dos_inode
) {
1432 if (all
|| all_dos
) {
1433 if (determine_size
) {
1434 p
= talloc_asprintf(
1444 n
= snprintf(buf
, bufsize
,
1448 } else if (StrCaseCmp(name
, "inode") == 0) {
1449 if (determine_size
) {
1450 p
= talloc_asprintf(
1460 n
= snprintf(buf
, bufsize
,
1466 if (!determine_size
&& n
> bufsize
) {
1476 /* Restore name pointer to its original value */
1488 /*****************************************************
1489 set the ACLs on a file given an ascii description
1490 *******************************************************/
1492 cacl_set(SMBCCTX
*context
,
1494 struct cli_state
*cli
,
1495 struct cli_state
*ipc_cli
,
1496 struct policy_handle
*pol
,
1497 const char *filename
,
1502 uint16_t fnum
= (uint16_t)-1;
1504 SEC_DESC
*sd
= NULL
, *old
;
1505 SEC_ACL
*dacl
= NULL
;
1506 DOM_SID
*owner_sid
= NULL
;
1507 DOM_SID
*group_sid
= NULL
;
1512 bool numeric
= True
;
1513 char *targetpath
= NULL
;
1514 struct cli_state
*targetcli
= NULL
;
1516 /* the_acl will be null for REMOVE_ALL operations */
1518 numeric
= ((p
= strchr(the_acl
, ':')) != NULL
&&
1522 /* if this is to set the entire ACL... */
1523 if (*the_acl
== '*') {
1524 /* ... then increment past the first colon */
1528 sd
= sec_desc_parse(ctx
, ipc_cli
, pol
, numeric
, the_acl
);
1535 /* SMBC_XATTR_MODE_REMOVE_ALL is the only caller
1536 that doesn't deref sd */
1538 if (!sd
&& (mode
!= SMBC_XATTR_MODE_REMOVE_ALL
)) {
1543 if (!cli_resolve_path(ctx
, "", context
->internal
->auth_info
,
1545 &targetcli
, &targetpath
)) {
1546 DEBUG(5,("cacl_set: Could not resolve %s\n", filename
));
1551 /* The desired access below is the only one I could find that works
1552 with NT4, W2KP and Samba */
1554 if (!NT_STATUS_IS_OK(cli_ntcreate(targetcli
, targetpath
, 0, CREATE_ACCESS_READ
, 0,
1555 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum
))) {
1556 DEBUG(5, ("cacl_set failed to open %s: %s\n",
1557 targetpath
, cli_errstr(targetcli
)));
1562 old
= cli_query_secdesc(targetcli
, fnum
, ctx
);
1565 DEBUG(5, ("cacl_set Failed to query old descriptor\n"));
1570 cli_close(targetcli
, fnum
);
1573 case SMBC_XATTR_MODE_REMOVE_ALL
:
1574 old
->dacl
->num_aces
= 0;
1578 case SMBC_XATTR_MODE_REMOVE
:
1579 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1582 for (j
=0;old
->dacl
&& j
<old
->dacl
->num_aces
;j
++) {
1583 if (sec_ace_equal(&sd
->dacl
->aces
[i
],
1584 &old
->dacl
->aces
[j
])) {
1586 for (k
=j
; k
<old
->dacl
->num_aces
-1;k
++) {
1587 old
->dacl
->aces
[k
] =
1588 old
->dacl
->aces
[k
+1];
1590 old
->dacl
->num_aces
--;
1605 case SMBC_XATTR_MODE_ADD
:
1606 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1609 for (j
=0;old
->dacl
&& j
<old
->dacl
->num_aces
;j
++) {
1610 if (sid_equal(&sd
->dacl
->aces
[i
].trustee
,
1611 &old
->dacl
->aces
[j
].trustee
)) {
1612 if (!(flags
& SMBC_XATTR_FLAG_CREATE
)) {
1617 old
->dacl
->aces
[j
] = sd
->dacl
->aces
[i
];
1623 if (!found
&& (flags
& SMBC_XATTR_FLAG_REPLACE
)) {
1629 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1630 add_ace(&old
->dacl
, &sd
->dacl
->aces
[i
], ctx
);
1636 case SMBC_XATTR_MODE_SET
:
1638 owner_sid
= old
->owner_sid
;
1639 group_sid
= old
->group_sid
;
1643 case SMBC_XATTR_MODE_CHOWN
:
1644 owner_sid
= sd
->owner_sid
;
1647 case SMBC_XATTR_MODE_CHGRP
:
1648 group_sid
= sd
->group_sid
;
1652 /* Denied ACE entries must come before allowed ones */
1653 sort_acl(old
->dacl
);
1655 /* Create new security descriptor and set it */
1656 sd
= make_sec_desc(ctx
, old
->revision
, SEC_DESC_SELF_RELATIVE
,
1657 owner_sid
, group_sid
, NULL
, dacl
, &sd_size
);
1659 if (!NT_STATUS_IS_OK(cli_ntcreate(targetcli
, targetpath
, 0,
1660 WRITE_DAC_ACCESS
| WRITE_OWNER_ACCESS
, 0,
1661 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum
))) {
1662 DEBUG(5, ("cacl_set failed to open %s: %s\n",
1663 targetpath
, cli_errstr(targetcli
)));
1668 if (!cli_set_secdesc(targetcli
, fnum
, sd
)) {
1669 DEBUG(5, ("ERROR: secdesc set failed: %s\n",
1670 cli_errstr(targetcli
)));
1677 cli_close(targetcli
, fnum
);
1688 SMBC_setxattr_ctx(SMBCCTX
*context
,
1697 SMBCSRV
*srv
= NULL
;
1698 SMBCSRV
*ipc_srv
= NULL
;
1699 char *server
= NULL
;
1702 char *password
= NULL
;
1703 char *workgroup
= NULL
;
1705 DOS_ATTR_DESC
*dad
= NULL
;
1707 const char * create_time_attr
;
1708 const char * access_time_attr
;
1709 const char * write_time_attr
;
1710 const char * change_time_attr
;
1712 TALLOC_CTX
*frame
= talloc_stackframe();
1714 if (!context
|| !context
->internal
->initialized
) {
1715 errno
= EINVAL
; /* Best I can think of ... */
1726 DEBUG(4, ("smbc_setxattr(%s, %s, %.*s)\n",
1727 fname
, name
, (int) size
, (const char*)value
));
1729 if (SMBC_parse_path(frame
,
1744 if (!user
|| user
[0] == (char)0) {
1745 user
= talloc_strdup(frame
, smbc_getUser(context
));
1753 srv
= SMBC_server(frame
, context
, True
,
1754 server
, share
, &workgroup
, &user
, &password
);
1757 return -1; /* errno set by SMBC_server */
1760 if (! srv
->no_nt_session
) {
1761 ipc_srv
= SMBC_attr_server(frame
, context
, server
, share
,
1762 &workgroup
, &user
, &password
);
1764 srv
->no_nt_session
= True
;
1771 * Are they asking to set the entire set of known attributes?
1773 if (StrCaseCmp(name
, "system.*") == 0 ||
1774 StrCaseCmp(name
, "system.*+") == 0) {
1777 talloc_asprintf(talloc_tos(), "%s:%s",
1778 name
+7, (const char *) value
);
1787 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1788 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1791 ? SMBC_XATTR_MODE_SET
1792 : SMBC_XATTR_MODE_ADD
),
1798 /* get a DOS Attribute Descriptor with current attributes */
1799 dad
= dos_attr_query(context
, talloc_tos(), path
, srv
);
1801 /* Overwrite old with new, using what was provided */
1802 dos_attr_parse(context
, dad
, srv
, namevalue
);
1804 /* Set the new DOS attributes */
1805 if (! SMBC_setatr(context
, srv
, path
,
1812 /* cause failure if NT failed too */
1817 /* we only fail if both NT and DOS sets failed */
1818 if (ret
< 0 && ! dad
) {
1819 ret
= -1; /* in case dad was null */
1830 * Are they asking to set an access control element or to set
1831 * the entire access control list?
1833 if (StrCaseCmp(name
, "system.nt_sec_desc.*") == 0 ||
1834 StrCaseCmp(name
, "system.nt_sec_desc.*+") == 0 ||
1835 StrCaseCmp(name
, "system.nt_sec_desc.revision") == 0 ||
1836 StrnCaseCmp(name
, "system.nt_sec_desc.acl", 22) == 0 ||
1837 StrnCaseCmp(name
, "system.nt_sec_desc.acl+", 23) == 0) {
1841 talloc_asprintf(talloc_tos(), "%s:%s",
1842 name
+19, (const char *) value
);
1845 ret
= -1; /* errno set by SMBC_server() */
1847 else if (! namevalue
) {
1851 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1852 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1855 ? SMBC_XATTR_MODE_SET
1856 : SMBC_XATTR_MODE_ADD
),
1864 * Are they asking to set the owner?
1866 if (StrCaseCmp(name
, "system.nt_sec_desc.owner") == 0 ||
1867 StrCaseCmp(name
, "system.nt_sec_desc.owner+") == 0) {
1871 talloc_asprintf(talloc_tos(), "%s:%s",
1872 name
+19, (const char *) value
);
1875 ret
= -1; /* errno set by SMBC_server() */
1877 else if (! namevalue
) {
1881 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1882 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1883 namevalue
, SMBC_XATTR_MODE_CHOWN
, 0);
1890 * Are they asking to set the group?
1892 if (StrCaseCmp(name
, "system.nt_sec_desc.group") == 0 ||
1893 StrCaseCmp(name
, "system.nt_sec_desc.group+") == 0) {
1897 talloc_asprintf(talloc_tos(), "%s:%s",
1898 name
+19, (const char *) value
);
1901 /* errno set by SMBC_server() */
1904 else if (! namevalue
) {
1908 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1909 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1910 namevalue
, SMBC_XATTR_MODE_CHGRP
, 0);
1916 /* Determine whether to use old-style or new-style attribute names */
1917 if (context
->internal
->full_time_names
) {
1918 /* new-style names */
1919 attr_strings
.create_time_attr
= "system.dos_attr.CREATE_TIME";
1920 attr_strings
.access_time_attr
= "system.dos_attr.ACCESS_TIME";
1921 attr_strings
.write_time_attr
= "system.dos_attr.WRITE_TIME";
1922 attr_strings
.change_time_attr
= "system.dos_attr.CHANGE_TIME";
1924 /* old-style names */
1925 attr_strings
.create_time_attr
= NULL
;
1926 attr_strings
.access_time_attr
= "system.dos_attr.A_TIME";
1927 attr_strings
.write_time_attr
= "system.dos_attr.M_TIME";
1928 attr_strings
.change_time_attr
= "system.dos_attr.C_TIME";
1932 * Are they asking to set a DOS attribute?
1934 if (StrCaseCmp(name
, "system.dos_attr.*") == 0 ||
1935 StrCaseCmp(name
, "system.dos_attr.mode") == 0 ||
1936 (attr_strings
.create_time_attr
!= NULL
&&
1937 StrCaseCmp(name
, attr_strings
.create_time_attr
) == 0) ||
1938 StrCaseCmp(name
, attr_strings
.access_time_attr
) == 0 ||
1939 StrCaseCmp(name
, attr_strings
.write_time_attr
) == 0 ||
1940 StrCaseCmp(name
, attr_strings
.change_time_attr
) == 0) {
1942 /* get a DOS Attribute Descriptor with current attributes */
1943 dad
= dos_attr_query(context
, talloc_tos(), path
, srv
);
1946 talloc_asprintf(talloc_tos(), "%s:%s",
1947 name
+16, (const char *) value
);
1952 /* Overwrite old with provided new params */
1953 dos_attr_parse(context
, dad
, srv
, namevalue
);
1955 /* Set the new DOS attributes */
1956 ret2
= SMBC_setatr(context
, srv
, path
,
1963 /* ret2 has True (success) / False (failure) */
1978 /* Unsupported attribute name */
1985 SMBC_getxattr_ctx(SMBCCTX
*context
,
1992 SMBCSRV
*srv
= NULL
;
1993 SMBCSRV
*ipc_srv
= NULL
;
1994 char *server
= NULL
;
1997 char *password
= NULL
;
1998 char *workgroup
= NULL
;
2001 const char * create_time_attr
;
2002 const char * access_time_attr
;
2003 const char * write_time_attr
;
2004 const char * change_time_attr
;
2006 TALLOC_CTX
*frame
= talloc_stackframe();
2008 if (!context
|| !context
->internal
->initialized
) {
2009 errno
= EINVAL
; /* Best I can think of ... */
2020 DEBUG(4, ("smbc_getxattr(%s, %s)\n", fname
, name
));
2022 if (SMBC_parse_path(frame
,
2037 if (!user
|| user
[0] == (char)0) {
2038 user
= talloc_strdup(frame
, smbc_getUser(context
));
2046 srv
= SMBC_server(frame
, context
, True
,
2047 server
, share
, &workgroup
, &user
, &password
);
2050 return -1; /* errno set by SMBC_server */
2053 if (! srv
->no_nt_session
) {
2054 ipc_srv
= SMBC_attr_server(frame
, context
, server
, share
,
2055 &workgroup
, &user
, &password
);
2057 srv
->no_nt_session
= True
;
2063 /* Determine whether to use old-style or new-style attribute names */
2064 if (context
->internal
->full_time_names
) {
2065 /* new-style names */
2066 attr_strings
.create_time_attr
= "system.dos_attr.CREATE_TIME";
2067 attr_strings
.access_time_attr
= "system.dos_attr.ACCESS_TIME";
2068 attr_strings
.write_time_attr
= "system.dos_attr.WRITE_TIME";
2069 attr_strings
.change_time_attr
= "system.dos_attr.CHANGE_TIME";
2071 /* old-style names */
2072 attr_strings
.create_time_attr
= NULL
;
2073 attr_strings
.access_time_attr
= "system.dos_attr.A_TIME";
2074 attr_strings
.write_time_attr
= "system.dos_attr.M_TIME";
2075 attr_strings
.change_time_attr
= "system.dos_attr.C_TIME";
2078 /* Are they requesting a supported attribute? */
2079 if (StrCaseCmp(name
, "system.*") == 0 ||
2080 StrnCaseCmp(name
, "system.*!", 9) == 0 ||
2081 StrCaseCmp(name
, "system.*+") == 0 ||
2082 StrnCaseCmp(name
, "system.*+!", 10) == 0 ||
2083 StrCaseCmp(name
, "system.nt_sec_desc.*") == 0 ||
2084 StrnCaseCmp(name
, "system.nt_sec_desc.*!", 21) == 0 ||
2085 StrCaseCmp(name
, "system.nt_sec_desc.*+") == 0 ||
2086 StrnCaseCmp(name
, "system.nt_sec_desc.*+!", 22) == 0 ||
2087 StrCaseCmp(name
, "system.nt_sec_desc.revision") == 0 ||
2088 StrCaseCmp(name
, "system.nt_sec_desc.owner") == 0 ||
2089 StrCaseCmp(name
, "system.nt_sec_desc.owner+") == 0 ||
2090 StrCaseCmp(name
, "system.nt_sec_desc.group") == 0 ||
2091 StrCaseCmp(name
, "system.nt_sec_desc.group+") == 0 ||
2092 StrnCaseCmp(name
, "system.nt_sec_desc.acl", 22) == 0 ||
2093 StrnCaseCmp(name
, "system.nt_sec_desc.acl+", 23) == 0 ||
2094 StrCaseCmp(name
, "system.dos_attr.*") == 0 ||
2095 StrnCaseCmp(name
, "system.dos_attr.*!", 18) == 0 ||
2096 StrCaseCmp(name
, "system.dos_attr.mode") == 0 ||
2097 StrCaseCmp(name
, "system.dos_attr.size") == 0 ||
2098 (attr_strings
.create_time_attr
!= NULL
&&
2099 StrCaseCmp(name
, attr_strings
.create_time_attr
) == 0) ||
2100 StrCaseCmp(name
, attr_strings
.access_time_attr
) == 0 ||
2101 StrCaseCmp(name
, attr_strings
.write_time_attr
) == 0 ||
2102 StrCaseCmp(name
, attr_strings
.change_time_attr
) == 0 ||
2103 StrCaseCmp(name
, "system.dos_attr.inode") == 0) {
2106 char *filename
= (char *) name
;
2107 ret
= cacl_get(context
, talloc_tos(), srv
,
2108 ipc_srv
== NULL
? NULL
: ipc_srv
->cli
,
2109 &ipc_srv
->pol
, path
,
2111 CONST_DISCARD(char *, value
),
2113 if (ret
< 0 && errno
== 0) {
2114 errno
= SMBC_errno(context
, srv
->cli
);
2120 /* Unsupported attribute name */
2128 SMBC_removexattr_ctx(SMBCCTX
*context
,
2133 SMBCSRV
*srv
= NULL
;
2134 SMBCSRV
*ipc_srv
= NULL
;
2135 char *server
= NULL
;
2138 char *password
= NULL
;
2139 char *workgroup
= NULL
;
2141 TALLOC_CTX
*frame
= talloc_stackframe();
2143 if (!context
|| !context
->internal
->initialized
) {
2144 errno
= EINVAL
; /* Best I can think of ... */
2155 DEBUG(4, ("smbc_removexattr(%s, %s)\n", fname
, name
));
2157 if (SMBC_parse_path(frame
,
2172 if (!user
|| user
[0] == (char)0) {
2173 user
= talloc_strdup(frame
, smbc_getUser(context
));
2181 srv
= SMBC_server(frame
, context
, True
,
2182 server
, share
, &workgroup
, &user
, &password
);
2185 return -1; /* errno set by SMBC_server */
2188 if (! srv
->no_nt_session
) {
2189 ipc_srv
= SMBC_attr_server(frame
, context
, server
, share
,
2190 &workgroup
, &user
, &password
);
2192 srv
->no_nt_session
= True
;
2200 return -1; /* errno set by SMBC_attr_server */
2203 /* Are they asking to set the entire ACL? */
2204 if (StrCaseCmp(name
, "system.nt_sec_desc.*") == 0 ||
2205 StrCaseCmp(name
, "system.nt_sec_desc.*+") == 0) {
2208 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
2209 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
2210 NULL
, SMBC_XATTR_MODE_REMOVE_ALL
, 0);
2216 * Are they asking to remove one or more spceific security descriptor
2219 if (StrCaseCmp(name
, "system.nt_sec_desc.revision") == 0 ||
2220 StrCaseCmp(name
, "system.nt_sec_desc.owner") == 0 ||
2221 StrCaseCmp(name
, "system.nt_sec_desc.owner+") == 0 ||
2222 StrCaseCmp(name
, "system.nt_sec_desc.group") == 0 ||
2223 StrCaseCmp(name
, "system.nt_sec_desc.group+") == 0 ||
2224 StrnCaseCmp(name
, "system.nt_sec_desc.acl", 22) == 0 ||
2225 StrnCaseCmp(name
, "system.nt_sec_desc.acl+", 23) == 0) {
2228 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
2229 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
2230 CONST_DISCARD(char *, name
) + 19,
2231 SMBC_XATTR_MODE_REMOVE
, 0);
2236 /* Unsupported attribute name */
2243 SMBC_listxattr_ctx(SMBCCTX
*context
,
2249 * This isn't quite what listxattr() is supposed to do. This returns
2250 * the complete set of attribute names, always, rather than only those
2251 * attribute names which actually exist for a file. Hmmm...
2254 const char supported_old
[] =
2257 "system.nt_sec_desc.revision\0"
2258 "system.nt_sec_desc.owner\0"
2259 "system.nt_sec_desc.owner+\0"
2260 "system.nt_sec_desc.group\0"
2261 "system.nt_sec_desc.group+\0"
2262 "system.nt_sec_desc.acl.*\0"
2263 "system.nt_sec_desc.acl\0"
2264 "system.nt_sec_desc.acl+\0"
2265 "system.nt_sec_desc.*\0"
2266 "system.nt_sec_desc.*+\0"
2267 "system.dos_attr.*\0"
2268 "system.dos_attr.mode\0"
2269 "system.dos_attr.c_time\0"
2270 "system.dos_attr.a_time\0"
2271 "system.dos_attr.m_time\0"
2273 const char supported_new
[] =
2276 "system.nt_sec_desc.revision\0"
2277 "system.nt_sec_desc.owner\0"
2278 "system.nt_sec_desc.owner+\0"
2279 "system.nt_sec_desc.group\0"
2280 "system.nt_sec_desc.group+\0"
2281 "system.nt_sec_desc.acl.*\0"
2282 "system.nt_sec_desc.acl\0"
2283 "system.nt_sec_desc.acl+\0"
2284 "system.nt_sec_desc.*\0"
2285 "system.nt_sec_desc.*+\0"
2286 "system.dos_attr.*\0"
2287 "system.dos_attr.mode\0"
2288 "system.dos_attr.create_time\0"
2289 "system.dos_attr.access_time\0"
2290 "system.dos_attr.write_time\0"
2291 "system.dos_attr.change_time\0"
2293 const char * supported
;
2295 if (context
->internal
->full_time_names
) {
2296 supported
= supported_new
;
2297 retsize
= sizeof(supported_new
);
2299 supported
= supported_old
;
2300 retsize
= sizeof(supported_old
);
2307 if (retsize
> size
) {
2312 /* this can't be strcpy() because there are embedded null characters */
2313 memcpy(list
, supported
, retsize
);