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"
31 * Find an lsa pipe handle associated with a cli struct.
33 static struct rpc_pipe_client
*
34 find_lsa_pipe_hnd(struct cli_state
*ipc_cli
)
36 struct rpc_pipe_client
*pipe_hnd
;
38 for (pipe_hnd
= ipc_cli
->pipe_list
;
40 pipe_hnd
= pipe_hnd
->next
) {
42 if (ndr_syntax_id_equal(&pipe_hnd
->abstract_syntax
,
43 &ndr_table_lsarpc
.syntax_id
)) {
52 * Sort ACEs according to the documentation at
53 * http://support.microsoft.com/kb/269175, at least as far as it defines the
58 ace_compare(SEC_ACE
*ace1
,
64 /* If the ACEs are equal, we have nothing more to do. */
65 if (sec_ace_equal(ace1
, ace2
)) {
69 /* Inherited follow non-inherited */
70 b1
= ((ace1
->flags
& SEC_ACE_FLAG_INHERITED_ACE
) != 0);
71 b2
= ((ace2
->flags
& SEC_ACE_FLAG_INHERITED_ACE
) != 0);
77 * What shall we do with AUDITs and ALARMs? It's undefined. We'll
78 * sort them after DENY and ALLOW.
80 b1
= (ace1
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED
&&
81 ace1
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
&&
82 ace1
->type
!= SEC_ACE_TYPE_ACCESS_DENIED
&&
83 ace1
->type
!= SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
84 b2
= (ace2
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED
&&
85 ace2
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
&&
86 ace2
->type
!= SEC_ACE_TYPE_ACCESS_DENIED
&&
87 ace2
->type
!= SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
92 /* Allowed ACEs follow denied ACEs */
93 b1
= (ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED
||
94 ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
);
95 b2
= (ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED
||
96 ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
);
102 * ACEs applying to an entity's object follow those applying to the
105 b1
= (ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
||
106 ace1
->type
== SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
107 b2
= (ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
||
108 ace2
->type
== SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
110 return (b1
? 1 : -1);
114 * If we get this far, the ACEs are similar as far as the
115 * characteristics we typically care about (those defined by the
116 * referenced MS document). We'll now sort by characteristics that
117 * just seems reasonable.
120 if (ace1
->type
!= ace2
->type
) {
121 return ace2
->type
- ace1
->type
;
124 if (sid_compare(&ace1
->trustee
, &ace2
->trustee
)) {
125 return sid_compare(&ace1
->trustee
, &ace2
->trustee
);
128 if (ace1
->flags
!= ace2
->flags
) {
129 return ace1
->flags
- ace2
->flags
;
132 if (ace1
->access_mask
!= ace2
->access_mask
) {
133 return ace1
->access_mask
- ace2
->access_mask
;
136 if (ace1
->size
!= ace2
->size
) {
137 return ace1
->size
- ace2
->size
;
140 return memcmp(ace1
, ace2
, sizeof(SEC_ACE
));
145 sort_acl(SEC_ACL
*the_acl
)
148 if (!the_acl
) return;
150 qsort(the_acl
->aces
, the_acl
->num_aces
, sizeof(the_acl
->aces
[0]),
151 QSORT_CAST ace_compare
);
153 for (i
=1;i
<the_acl
->num_aces
;) {
154 if (sec_ace_equal(&the_acl
->aces
[i
-1], &the_acl
->aces
[i
])) {
156 for (j
=i
; j
<the_acl
->num_aces
-1; j
++) {
157 the_acl
->aces
[j
] = the_acl
->aces
[j
+1];
166 /* convert a SID to a string, either numeric or username/group */
168 convert_sid_to_string(struct cli_state
*ipc_cli
,
169 struct policy_handle
*pol
,
174 char **domains
= NULL
;
176 enum lsa_SidType
*types
= NULL
;
177 struct rpc_pipe_client
*pipe_hnd
= find_lsa_pipe_hnd(ipc_cli
);
180 sid_to_fstring(str
, sid
);
183 return; /* no lookup desired */
190 /* Ask LSA to convert the sid to a name */
192 ctx
= talloc_stackframe();
194 if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_sids(pipe_hnd
, ctx
,
195 pol
, 1, sid
, &domains
,
197 !domains
|| !domains
[0] || !names
|| !names
[0]) {
204 slprintf(str
, sizeof(fstring
) - 1, "%s%s%s",
205 domains
[0], lp_winbind_separator(),
211 /* convert a string to a SID, either numeric or username/group */
213 convert_string_to_sid(struct cli_state
*ipc_cli
,
214 struct policy_handle
*pol
,
219 enum lsa_SidType
*types
= NULL
;
220 DOM_SID
*sids
= NULL
;
222 TALLOC_CTX
*ctx
= NULL
;
223 struct rpc_pipe_client
*pipe_hnd
= find_lsa_pipe_hnd(ipc_cli
);
230 if (strncmp(str
, "S-", 2) == 0) {
231 return string_to_sid(sid
, str
);
238 ctx
= talloc_stackframe();
239 if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_names(pipe_hnd
, ctx
,
247 sid_copy(sid
, &sids
[0]);
255 /* parse an ACE in the same format as print_ace() */
257 parse_ace(struct cli_state
*ipc_cli
,
258 struct policy_handle
*pol
,
271 const struct perm_value
*v
;
276 TALLOC_CTX
*frame
= talloc_stackframe();
278 /* These values discovered by inspection */
279 static const struct perm_value special_values
[] = {
289 static const struct perm_value standard_values
[] = {
290 { "READ", 0x001200a9 },
291 { "CHANGE", 0x001301bf },
292 { "FULL", 0x001f01ff },
298 p
= strchr_m(str
,':');
305 /* Try to parse numeric form */
307 if (sscanf(p
, "%i/%i/%i", &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(tok
, "ALLOWED", strlen("ALLOWED")) == 0) {
326 atype
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
327 } else if (StrnCaseCmp(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
, "%i", &aflags
))) {
342 if (!next_token_talloc(frame
, &cp
, &tok
, "/")) {
347 if (strncmp(tok
, "0x", 2) == 0) {
348 if (sscanf(tok
, "%i", &amask
) != 1) {
355 for (v
= standard_values
; v
->perm
; v
++) {
356 if (strcmp(tok
, v
->perm
) == 0) {
367 for (v
= special_values
; v
->perm
; v
++) {
368 if (v
->perm
[0] == *p
) {
388 init_sec_ace(ace
, &sid
, atype
, mask
, aflags
);
393 /* add an ACE to a list of ACEs in a SEC_ACL */
395 add_ace(SEC_ACL
**the_acl
,
403 (*the_acl
) = make_sec_acl(ctx
, 3, 1, ace
);
407 if ((aces
= SMB_CALLOC_ARRAY(SEC_ACE
,
408 1+(*the_acl
)->num_aces
)) == NULL
) {
411 memcpy(aces
, (*the_acl
)->aces
, (*the_acl
)->num_aces
* sizeof(SEC_ACE
));
412 memcpy(aces
+(*the_acl
)->num_aces
, ace
, sizeof(SEC_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 */
423 sec_desc_parse(TALLOC_CTX
*ctx
,
424 struct cli_state
*ipc_cli
,
425 struct policy_handle
*pol
,
431 SEC_DESC
*ret
= NULL
;
433 DOM_SID
*group_sid
=NULL
;
434 DOM_SID
*owner_sid
=NULL
;
438 while (next_token_talloc(ctx
, &p
, &tok
, "\t,\r\n")) {
440 if (StrnCaseCmp(tok
,"REVISION:", 9) == 0) {
441 revision
= strtol(tok
+9, NULL
, 16);
445 if (StrnCaseCmp(tok
,"OWNER:", 6) == 0) {
447 DEBUG(5,("OWNER specified more than once!\n"));
450 owner_sid
= SMB_CALLOC_ARRAY(DOM_SID
, 1);
452 !convert_string_to_sid(ipc_cli
, pol
,
455 DEBUG(5, ("Failed to parse owner sid\n"));
461 if (StrnCaseCmp(tok
,"OWNER+:", 7) == 0) {
463 DEBUG(5,("OWNER specified more than once!\n"));
466 owner_sid
= SMB_CALLOC_ARRAY(DOM_SID
, 1);
468 !convert_string_to_sid(ipc_cli
, pol
,
471 DEBUG(5, ("Failed to parse owner sid\n"));
477 if (StrnCaseCmp(tok
,"GROUP:", 6) == 0) {
479 DEBUG(5,("GROUP specified more than once!\n"));
482 group_sid
= SMB_CALLOC_ARRAY(DOM_SID
, 1);
484 !convert_string_to_sid(ipc_cli
, pol
,
487 DEBUG(5, ("Failed to parse group sid\n"));
493 if (StrnCaseCmp(tok
,"GROUP+:", 7) == 0) {
495 DEBUG(5,("GROUP specified more than once!\n"));
498 group_sid
= SMB_CALLOC_ARRAY(DOM_SID
, 1);
500 !convert_string_to_sid(ipc_cli
, pol
,
503 DEBUG(5, ("Failed to parse group sid\n"));
509 if (StrnCaseCmp(tok
,"ACL:", 4) == 0) {
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(tok
,"ACL+:", 5) == 0) {
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
);
550 /* Obtain the current dos attributes */
551 static DOS_ATTR_DESC
*
552 dos_attr_query(SMBCCTX
*context
,
554 const char *filename
,
557 struct timespec create_time_ts
;
558 struct timespec write_time_ts
;
559 struct timespec access_time_ts
;
560 struct timespec change_time_ts
;
566 ret
= TALLOC_P(ctx
, DOS_ATTR_DESC
);
572 /* Obtain the DOS attributes */
573 if (!SMBC_getatr(context
, srv
, CONST_DISCARD(char *, filename
),
580 errno
= SMBC_errno(context
, srv
->cli
);
581 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(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(tok
, "SIZE:", 5) == 0) {
656 dad
->size
= (SMB_OFF_T
)atof(tok
+5);
660 n
= strlen(attr_strings
.access_time_attr
);
661 if (StrnCaseCmp(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(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(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(tok
, attr_strings
.create_time_attr
,
682 dad
->create_time
= (time_t)strtol(tok
+n
+1,
688 if (StrnCaseCmp(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
,
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);
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(name
, "system.*", 8) == 0);
806 all_nt
= (StrnCaseCmp(name
, "system.nt_sec_desc.*", 20) == 0);
807 all_nt_acls
= (StrnCaseCmp(name
, "system.nt_sec_desc.acl.*", 24) == 0);
808 all_dos
= (StrnCaseCmp(name
, "system.dos_attr.*", 17) == 0);
809 some_nt
= (StrnCaseCmp(name
, "system.nt_sec_desc.", 19) == 0);
810 some_dos
= (StrnCaseCmp(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
) {
816 /* Exclusions are delimited by '!' */
819 pExclude
= (p
== NULL
? NULL
: p
+ 1)) {
821 /* Find end of this exclusion name */
822 if ((p
= strchr(pExclude
, '!')) != NULL
)
827 /* Which exclusion name is this? */
828 if (StrCaseCmp(pExclude
,
829 "nt_sec_desc.revision") == 0) {
830 exclude_nt_revision
= True
;
832 else if (StrCaseCmp(pExclude
,
833 "nt_sec_desc.owner") == 0) {
834 exclude_nt_owner
= True
;
836 else if (StrCaseCmp(pExclude
,
837 "nt_sec_desc.group") == 0) {
838 exclude_nt_group
= True
;
840 else if (StrCaseCmp(pExclude
,
841 "nt_sec_desc.acl") == 0) {
842 exclude_nt_acl
= True
;
844 else if (StrCaseCmp(pExclude
,
845 "dos_attr.mode") == 0) {
846 exclude_dos_mode
= True
;
848 else if (StrCaseCmp(pExclude
,
849 "dos_attr.size") == 0) {
850 exclude_dos_size
= True
;
852 else if (excl_attr_strings
.create_time_attr
!= NULL
&&
854 excl_attr_strings
.change_time_attr
) == 0) {
855 exclude_dos_create_time
= True
;
857 else if (StrCaseCmp(pExclude
,
858 excl_attr_strings
.access_time_attr
) == 0) {
859 exclude_dos_access_time
= True
;
861 else if (StrCaseCmp(pExclude
,
862 excl_attr_strings
.write_time_attr
) == 0) {
863 exclude_dos_write_time
= True
;
865 else if (StrCaseCmp(pExclude
,
866 excl_attr_strings
.change_time_attr
) == 0) {
867 exclude_dos_change_time
= True
;
869 else if (StrCaseCmp(pExclude
, "dos_attr.inode") == 0) {
870 exclude_dos_inode
= True
;
873 DEBUG(5, ("cacl_get received unknown exclusion: %s\n",
884 * If we are (possibly) talking to an NT or new system and some NT
885 * attributes have been requested...
887 if (ipc_cli
&& (all
|| some_nt
|| all_nt_acls
)) {
888 char *targetpath
= NULL
;
889 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 if (!cli_resolve_path(ctx
, "", context
->internal
->auth_info
,
896 &targetcli
, &targetpath
)) {
897 DEBUG(5, ("cacl_get Could not resolve %s\n",
903 /* ... then obtain any NT attributes which were requested */
904 fnum
= cli_nt_create(targetcli
, targetpath
, CREATE_ACCESS_READ
);
907 DEBUG(5, ("cacl_get failed to open %s: %s\n",
908 targetpath
, cli_errstr(targetcli
)));
913 sd
= cli_query_secdesc(targetcli
, fnum
, ctx
);
917 ("cacl_get Failed to query old descriptor\n"));
922 cli_close(targetcli
, fnum
);
924 if (! exclude_nt_revision
) {
926 if (determine_size
) {
927 p
= talloc_asprintf(ctx
,
936 n
= snprintf(buf
, bufsize
,
940 } else if (StrCaseCmp(name
, "revision") == 0) {
941 if (determine_size
) {
942 p
= talloc_asprintf(ctx
, "%d",
950 n
= snprintf(buf
, bufsize
, "%d",
955 if (!determine_size
&& n
> bufsize
) {
965 if (! exclude_nt_owner
) {
966 /* Get owner and group sid */
968 convert_sid_to_string(ipc_cli
, pol
,
977 if (determine_size
) {
978 p
= talloc_asprintf(ctx
, ",OWNER:%s",
985 } else if (sidstr
[0] != '\0') {
986 n
= snprintf(buf
, bufsize
,
987 ",OWNER:%s", sidstr
);
989 } else if (StrnCaseCmp(name
, "owner", 5) == 0) {
990 if (determine_size
) {
991 p
= talloc_asprintf(ctx
, "%s", sidstr
);
998 n
= snprintf(buf
, bufsize
, "%s",
1003 if (!determine_size
&& n
> bufsize
) {
1013 if (! exclude_nt_group
) {
1014 if (sd
->group_sid
) {
1015 convert_sid_to_string(ipc_cli
, pol
,
1019 fstrcpy(sidstr
, "");
1022 if (all
|| all_nt
) {
1023 if (determine_size
) {
1024 p
= talloc_asprintf(ctx
, ",GROUP:%s",
1031 } else if (sidstr
[0] != '\0') {
1032 n
= snprintf(buf
, bufsize
,
1033 ",GROUP:%s", sidstr
);
1035 } else if (StrnCaseCmp(name
, "group", 5) == 0) {
1036 if (determine_size
) {
1037 p
= talloc_asprintf(ctx
, "%s", sidstr
);
1044 n
= snprintf(buf
, bufsize
,
1049 if (!determine_size
&& n
> bufsize
) {
1059 if (! exclude_nt_acl
) {
1060 /* Add aces to value buffer */
1061 for (i
= 0; sd
->dacl
&& i
< sd
->dacl
->num_aces
; i
++) {
1063 SEC_ACE
*ace
= &sd
->dacl
->aces
[i
];
1064 convert_sid_to_string(ipc_cli
, pol
,
1068 if (all
|| all_nt
) {
1069 if (determine_size
) {
1070 p
= talloc_asprintf(
1086 ",ACL:%s:%d/%d/0x%08x",
1092 } else if ((StrnCaseCmp(name
, "acl", 3) == 0 &&
1093 StrCaseCmp(name
+3, sidstr
) == 0) ||
1094 (StrnCaseCmp(name
, "acl+", 4) == 0 &&
1095 StrCaseCmp(name
+4, sidstr
) == 0)) {
1096 if (determine_size
) {
1097 p
= talloc_asprintf(
1109 n
= snprintf(buf
, bufsize
,
1115 } else if (all_nt_acls
) {
1116 if (determine_size
) {
1117 p
= talloc_asprintf(
1119 "%s%s:%d/%d/0x%08x",
1131 n
= snprintf(buf
, bufsize
,
1132 "%s%s:%d/%d/0x%08x",
1140 if (!determine_size
&& n
> bufsize
) {
1151 /* Restore name pointer to its original value */
1155 if (all
|| some_dos
) {
1156 /* Point to the portion after "system.dos_attr." */
1157 name
+= 16; /* if (all) this will be invalid but unused */
1159 /* Obtain the DOS attributes */
1160 if (!SMBC_getatr(context
, srv
, filename
, &mode
, &size
,
1167 errno
= SMBC_errno(context
, srv
->cli
);
1172 create_time
= convert_timespec_to_time_t(create_time_ts
);
1173 access_time
= convert_timespec_to_time_t(access_time_ts
);
1174 write_time
= convert_timespec_to_time_t(write_time_ts
);
1175 change_time
= convert_timespec_to_time_t(change_time_ts
);
1177 if (! exclude_dos_mode
) {
1178 if (all
|| all_dos
) {
1179 if (determine_size
) {
1180 p
= talloc_asprintf(ctx
,
1193 n
= snprintf(buf
, bufsize
,
1201 } else if (StrCaseCmp(name
, "mode") == 0) {
1202 if (determine_size
) {
1203 p
= talloc_asprintf(ctx
, "0x%x", mode
);
1210 n
= snprintf(buf
, bufsize
,
1215 if (!determine_size
&& n
> bufsize
) {
1225 if (! exclude_dos_size
) {
1226 if (all
|| all_dos
) {
1227 if (determine_size
) {
1228 p
= talloc_asprintf(
1238 n
= snprintf(buf
, bufsize
,
1242 } else if (StrCaseCmp(name
, "size") == 0) {
1243 if (determine_size
) {
1244 p
= talloc_asprintf(
1254 n
= snprintf(buf
, bufsize
,
1260 if (!determine_size
&& n
> bufsize
) {
1270 if (! exclude_dos_create_time
&&
1271 attr_strings
.create_time_attr
!= NULL
) {
1272 if (all
|| all_dos
) {
1273 if (determine_size
) {
1274 p
= talloc_asprintf(ctx
,
1276 attr_strings
.create_time_attr
,
1277 (unsigned long) create_time
);
1284 n
= snprintf(buf
, bufsize
,
1286 attr_strings
.create_time_attr
,
1287 (unsigned long) create_time
);
1289 } else if (StrCaseCmp(name
, attr_strings
.create_time_attr
) == 0) {
1290 if (determine_size
) {
1291 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) create_time
);
1298 n
= snprintf(buf
, bufsize
,
1299 "%lu", (unsigned long) create_time
);
1303 if (!determine_size
&& n
> bufsize
) {
1313 if (! exclude_dos_access_time
) {
1314 if (all
|| all_dos
) {
1315 if (determine_size
) {
1316 p
= talloc_asprintf(ctx
,
1318 attr_strings
.access_time_attr
,
1319 (unsigned long) access_time
);
1326 n
= snprintf(buf
, bufsize
,
1328 attr_strings
.access_time_attr
,
1329 (unsigned long) access_time
);
1331 } else if (StrCaseCmp(name
, attr_strings
.access_time_attr
) == 0) {
1332 if (determine_size
) {
1333 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) access_time
);
1340 n
= snprintf(buf
, bufsize
,
1341 "%lu", (unsigned long) access_time
);
1345 if (!determine_size
&& n
> bufsize
) {
1355 if (! exclude_dos_write_time
) {
1356 if (all
|| all_dos
) {
1357 if (determine_size
) {
1358 p
= talloc_asprintf(ctx
,
1360 attr_strings
.write_time_attr
,
1361 (unsigned long) write_time
);
1368 n
= snprintf(buf
, bufsize
,
1370 attr_strings
.write_time_attr
,
1371 (unsigned long) write_time
);
1373 } else if (StrCaseCmp(name
, attr_strings
.write_time_attr
) == 0) {
1374 if (determine_size
) {
1375 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) write_time
);
1382 n
= snprintf(buf
, bufsize
,
1383 "%lu", (unsigned long) write_time
);
1387 if (!determine_size
&& n
> bufsize
) {
1397 if (! exclude_dos_change_time
) {
1398 if (all
|| all_dos
) {
1399 if (determine_size
) {
1400 p
= talloc_asprintf(ctx
,
1402 attr_strings
.change_time_attr
,
1403 (unsigned long) change_time
);
1410 n
= snprintf(buf
, bufsize
,
1412 attr_strings
.change_time_attr
,
1413 (unsigned long) change_time
);
1415 } else if (StrCaseCmp(name
, attr_strings
.change_time_attr
) == 0) {
1416 if (determine_size
) {
1417 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) change_time
);
1424 n
= snprintf(buf
, bufsize
,
1425 "%lu", (unsigned long) change_time
);
1429 if (!determine_size
&& n
> bufsize
) {
1439 if (! exclude_dos_inode
) {
1440 if (all
|| all_dos
) {
1441 if (determine_size
) {
1442 p
= talloc_asprintf(
1452 n
= snprintf(buf
, bufsize
,
1456 } else if (StrCaseCmp(name
, "inode") == 0) {
1457 if (determine_size
) {
1458 p
= talloc_asprintf(
1468 n
= snprintf(buf
, bufsize
,
1474 if (!determine_size
&& n
> bufsize
) {
1484 /* Restore name pointer to its original value */
1496 /*****************************************************
1497 set the ACLs on a file given an ascii description
1498 *******************************************************/
1500 cacl_set(SMBCCTX
*context
,
1502 struct cli_state
*cli
,
1503 struct cli_state
*ipc_cli
,
1504 struct policy_handle
*pol
,
1505 const char *filename
,
1512 SEC_DESC
*sd
= NULL
, *old
;
1513 SEC_ACL
*dacl
= NULL
;
1514 DOM_SID
*owner_sid
= NULL
;
1515 DOM_SID
*group_sid
= NULL
;
1520 bool numeric
= True
;
1521 char *targetpath
= NULL
;
1522 struct cli_state
*targetcli
= NULL
;
1524 /* the_acl will be null for REMOVE_ALL operations */
1526 numeric
= ((p
= strchr(the_acl
, ':')) != NULL
&&
1530 /* if this is to set the entire ACL... */
1531 if (*the_acl
== '*') {
1532 /* ... then increment past the first colon */
1536 sd
= sec_desc_parse(ctx
, ipc_cli
, pol
, numeric
, the_acl
);
1544 /* SMBC_XATTR_MODE_REMOVE_ALL is the only caller
1545 that doesn't deref sd */
1547 if (!sd
&& (mode
!= SMBC_XATTR_MODE_REMOVE_ALL
)) {
1552 if (!cli_resolve_path(ctx
, "", context
->internal
->auth_info
,
1554 &targetcli
, &targetpath
)) {
1555 DEBUG(5,("cacl_set: Could not resolve %s\n", filename
));
1560 /* The desired access below is the only one I could find that works
1561 with NT4, W2KP and Samba */
1563 fnum
= cli_nt_create(targetcli
, targetpath
, CREATE_ACCESS_READ
);
1566 DEBUG(5, ("cacl_set failed to open %s: %s\n",
1567 targetpath
, cli_errstr(targetcli
)));
1572 old
= cli_query_secdesc(targetcli
, fnum
, ctx
);
1575 DEBUG(5, ("cacl_set Failed to query old descriptor\n"));
1580 cli_close(targetcli
, fnum
);
1583 case SMBC_XATTR_MODE_REMOVE_ALL
:
1584 old
->dacl
->num_aces
= 0;
1588 case SMBC_XATTR_MODE_REMOVE
:
1589 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1592 for (j
=0;old
->dacl
&& j
<old
->dacl
->num_aces
;j
++) {
1593 if (sec_ace_equal(&sd
->dacl
->aces
[i
],
1594 &old
->dacl
->aces
[j
])) {
1596 for (k
=j
; k
<old
->dacl
->num_aces
-1;k
++) {
1597 old
->dacl
->aces
[k
] =
1598 old
->dacl
->aces
[k
+1];
1600 old
->dacl
->num_aces
--;
1615 case SMBC_XATTR_MODE_ADD
:
1616 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1619 for (j
=0;old
->dacl
&& j
<old
->dacl
->num_aces
;j
++) {
1620 if (sid_equal(&sd
->dacl
->aces
[i
].trustee
,
1621 &old
->dacl
->aces
[j
].trustee
)) {
1622 if (!(flags
& SMBC_XATTR_FLAG_CREATE
)) {
1627 old
->dacl
->aces
[j
] = sd
->dacl
->aces
[i
];
1633 if (!found
&& (flags
& SMBC_XATTR_FLAG_REPLACE
)) {
1639 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1640 add_ace(&old
->dacl
, &sd
->dacl
->aces
[i
], ctx
);
1646 case SMBC_XATTR_MODE_SET
:
1648 owner_sid
= old
->owner_sid
;
1649 group_sid
= old
->group_sid
;
1653 case SMBC_XATTR_MODE_CHOWN
:
1654 owner_sid
= sd
->owner_sid
;
1657 case SMBC_XATTR_MODE_CHGRP
:
1658 group_sid
= sd
->group_sid
;
1662 /* Denied ACE entries must come before allowed ones */
1663 sort_acl(old
->dacl
);
1665 /* Create new security descriptor and set it */
1666 sd
= make_sec_desc(ctx
, old
->revision
, SEC_DESC_SELF_RELATIVE
,
1667 owner_sid
, group_sid
, NULL
, dacl
, &sd_size
);
1669 fnum
= cli_nt_create(targetcli
, targetpath
,
1670 WRITE_DAC_ACCESS
| WRITE_OWNER_ACCESS
);
1673 DEBUG(5, ("cacl_set failed to open %s: %s\n",
1674 targetpath
, cli_errstr(targetcli
)));
1679 if (!cli_set_secdesc(targetcli
, fnum
, sd
)) {
1680 DEBUG(5, ("ERROR: secdesc set failed: %s\n",
1681 cli_errstr(targetcli
)));
1688 cli_close(targetcli
, fnum
);
1699 SMBC_setxattr_ctx(SMBCCTX
*context
,
1708 SMBCSRV
*srv
= NULL
;
1709 SMBCSRV
*ipc_srv
= NULL
;
1710 char *server
= NULL
;
1713 char *password
= NULL
;
1714 char *workgroup
= NULL
;
1716 DOS_ATTR_DESC
*dad
= NULL
;
1718 const char * create_time_attr
;
1719 const char * access_time_attr
;
1720 const char * write_time_attr
;
1721 const char * change_time_attr
;
1723 TALLOC_CTX
*frame
= talloc_stackframe();
1725 if (!context
|| !context
->internal
->initialized
) {
1727 errno
= EINVAL
; /* Best I can think of ... */
1738 DEBUG(4, ("smbc_setxattr(%s, %s, %.*s)\n",
1739 fname
, name
, (int) size
, (const char*)value
));
1741 if (SMBC_parse_path(frame
,
1756 if (!user
|| user
[0] == (char)0) {
1757 user
= talloc_strdup(frame
, smbc_getUser(context
));
1765 srv
= SMBC_server(frame
, context
, True
,
1766 server
, share
, &workgroup
, &user
, &password
);
1769 return -1; /* errno set by SMBC_server */
1772 if (! srv
->no_nt_session
) {
1773 ipc_srv
= SMBC_attr_server(frame
, context
, server
, share
,
1774 &workgroup
, &user
, &password
);
1776 srv
->no_nt_session
= True
;
1783 * Are they asking to set the entire set of known attributes?
1785 if (StrCaseCmp(name
, "system.*") == 0 ||
1786 StrCaseCmp(name
, "system.*+") == 0) {
1789 talloc_asprintf(talloc_tos(), "%s:%s",
1790 name
+7, (const char *) value
);
1799 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1800 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1803 ? SMBC_XATTR_MODE_SET
1804 : SMBC_XATTR_MODE_ADD
),
1810 /* get a DOS Attribute Descriptor with current attributes */
1811 dad
= dos_attr_query(context
, talloc_tos(), path
, srv
);
1813 /* Overwrite old with new, using what was provided */
1814 dos_attr_parse(context
, dad
, srv
, namevalue
);
1816 /* Set the new DOS attributes */
1817 if (! SMBC_setatr(context
, srv
, path
,
1824 /* cause failure if NT failed too */
1829 /* we only fail if both NT and DOS sets failed */
1830 if (ret
< 0 && ! dad
) {
1831 ret
= -1; /* in case dad was null */
1842 * Are they asking to set an access control element or to set
1843 * the entire access control list?
1845 if (StrCaseCmp(name
, "system.nt_sec_desc.*") == 0 ||
1846 StrCaseCmp(name
, "system.nt_sec_desc.*+") == 0 ||
1847 StrCaseCmp(name
, "system.nt_sec_desc.revision") == 0 ||
1848 StrnCaseCmp(name
, "system.nt_sec_desc.acl", 22) == 0 ||
1849 StrnCaseCmp(name
, "system.nt_sec_desc.acl+", 23) == 0) {
1853 talloc_asprintf(talloc_tos(), "%s:%s",
1854 name
+19, (const char *) value
);
1857 ret
= -1; /* errno set by SMBC_server() */
1859 else if (! namevalue
) {
1863 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1864 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1867 ? SMBC_XATTR_MODE_SET
1868 : SMBC_XATTR_MODE_ADD
),
1876 * Are they asking to set the owner?
1878 if (StrCaseCmp(name
, "system.nt_sec_desc.owner") == 0 ||
1879 StrCaseCmp(name
, "system.nt_sec_desc.owner+") == 0) {
1883 talloc_asprintf(talloc_tos(), "%s:%s",
1884 name
+19, (const char *) value
);
1887 ret
= -1; /* errno set by SMBC_server() */
1889 else if (! namevalue
) {
1893 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1894 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1895 namevalue
, SMBC_XATTR_MODE_CHOWN
, 0);
1902 * Are they asking to set the group?
1904 if (StrCaseCmp(name
, "system.nt_sec_desc.group") == 0 ||
1905 StrCaseCmp(name
, "system.nt_sec_desc.group+") == 0) {
1909 talloc_asprintf(talloc_tos(), "%s:%s",
1910 name
+19, (const char *) value
);
1913 /* errno set by SMBC_server() */
1916 else if (! namevalue
) {
1920 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1921 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1922 namevalue
, SMBC_XATTR_MODE_CHGRP
, 0);
1928 /* Determine whether to use old-style or new-style attribute names */
1929 if (context
->internal
->full_time_names
) {
1930 /* new-style names */
1931 attr_strings
.create_time_attr
= "system.dos_attr.CREATE_TIME";
1932 attr_strings
.access_time_attr
= "system.dos_attr.ACCESS_TIME";
1933 attr_strings
.write_time_attr
= "system.dos_attr.WRITE_TIME";
1934 attr_strings
.change_time_attr
= "system.dos_attr.CHANGE_TIME";
1936 /* old-style names */
1937 attr_strings
.create_time_attr
= NULL
;
1938 attr_strings
.access_time_attr
= "system.dos_attr.A_TIME";
1939 attr_strings
.write_time_attr
= "system.dos_attr.M_TIME";
1940 attr_strings
.change_time_attr
= "system.dos_attr.C_TIME";
1944 * Are they asking to set a DOS attribute?
1946 if (StrCaseCmp(name
, "system.dos_attr.*") == 0 ||
1947 StrCaseCmp(name
, "system.dos_attr.mode") == 0 ||
1948 (attr_strings
.create_time_attr
!= NULL
&&
1949 StrCaseCmp(name
, attr_strings
.create_time_attr
) == 0) ||
1950 StrCaseCmp(name
, attr_strings
.access_time_attr
) == 0 ||
1951 StrCaseCmp(name
, attr_strings
.write_time_attr
) == 0 ||
1952 StrCaseCmp(name
, attr_strings
.change_time_attr
) == 0) {
1954 /* get a DOS Attribute Descriptor with current attributes */
1955 dad
= dos_attr_query(context
, talloc_tos(), path
, srv
);
1958 talloc_asprintf(talloc_tos(), "%s:%s",
1959 name
+16, (const char *) value
);
1964 /* Overwrite old with provided new params */
1965 dos_attr_parse(context
, dad
, srv
, namevalue
);
1967 /* Set the new DOS attributes */
1968 ret2
= SMBC_setatr(context
, srv
, path
,
1975 /* ret2 has True (success) / False (failure) */
1990 /* Unsupported attribute name */
1997 SMBC_getxattr_ctx(SMBCCTX
*context
,
2004 SMBCSRV
*srv
= NULL
;
2005 SMBCSRV
*ipc_srv
= NULL
;
2006 char *server
= NULL
;
2009 char *password
= NULL
;
2010 char *workgroup
= NULL
;
2013 const char * create_time_attr
;
2014 const char * access_time_attr
;
2015 const char * write_time_attr
;
2016 const char * change_time_attr
;
2018 TALLOC_CTX
*frame
= talloc_stackframe();
2020 if (!context
|| !context
->internal
->initialized
) {
2022 errno
= EINVAL
; /* Best I can think of ... */
2033 DEBUG(4, ("smbc_getxattr(%s, %s)\n", fname
, name
));
2035 if (SMBC_parse_path(frame
,
2050 if (!user
|| user
[0] == (char)0) {
2051 user
= talloc_strdup(frame
, smbc_getUser(context
));
2059 srv
= SMBC_server(frame
, context
, True
,
2060 server
, share
, &workgroup
, &user
, &password
);
2063 return -1; /* errno set by SMBC_server */
2066 if (! srv
->no_nt_session
) {
2067 ipc_srv
= SMBC_attr_server(frame
, context
, server
, share
,
2068 &workgroup
, &user
, &password
);
2070 srv
->no_nt_session
= True
;
2076 /* Determine whether to use old-style or new-style attribute names */
2077 if (context
->internal
->full_time_names
) {
2078 /* new-style names */
2079 attr_strings
.create_time_attr
= "system.dos_attr.CREATE_TIME";
2080 attr_strings
.access_time_attr
= "system.dos_attr.ACCESS_TIME";
2081 attr_strings
.write_time_attr
= "system.dos_attr.WRITE_TIME";
2082 attr_strings
.change_time_attr
= "system.dos_attr.CHANGE_TIME";
2084 /* old-style names */
2085 attr_strings
.create_time_attr
= NULL
;
2086 attr_strings
.access_time_attr
= "system.dos_attr.A_TIME";
2087 attr_strings
.write_time_attr
= "system.dos_attr.M_TIME";
2088 attr_strings
.change_time_attr
= "system.dos_attr.C_TIME";
2091 /* Are they requesting a supported attribute? */
2092 if (StrCaseCmp(name
, "system.*") == 0 ||
2093 StrnCaseCmp(name
, "system.*!", 9) == 0 ||
2094 StrCaseCmp(name
, "system.*+") == 0 ||
2095 StrnCaseCmp(name
, "system.*+!", 10) == 0 ||
2096 StrCaseCmp(name
, "system.nt_sec_desc.*") == 0 ||
2097 StrnCaseCmp(name
, "system.nt_sec_desc.*!", 21) == 0 ||
2098 StrCaseCmp(name
, "system.nt_sec_desc.*+") == 0 ||
2099 StrnCaseCmp(name
, "system.nt_sec_desc.*+!", 22) == 0 ||
2100 StrCaseCmp(name
, "system.nt_sec_desc.revision") == 0 ||
2101 StrCaseCmp(name
, "system.nt_sec_desc.owner") == 0 ||
2102 StrCaseCmp(name
, "system.nt_sec_desc.owner+") == 0 ||
2103 StrCaseCmp(name
, "system.nt_sec_desc.group") == 0 ||
2104 StrCaseCmp(name
, "system.nt_sec_desc.group+") == 0 ||
2105 StrnCaseCmp(name
, "system.nt_sec_desc.acl", 22) == 0 ||
2106 StrnCaseCmp(name
, "system.nt_sec_desc.acl+", 23) == 0 ||
2107 StrCaseCmp(name
, "system.dos_attr.*") == 0 ||
2108 StrnCaseCmp(name
, "system.dos_attr.*!", 18) == 0 ||
2109 StrCaseCmp(name
, "system.dos_attr.mode") == 0 ||
2110 StrCaseCmp(name
, "system.dos_attr.size") == 0 ||
2111 (attr_strings
.create_time_attr
!= NULL
&&
2112 StrCaseCmp(name
, attr_strings
.create_time_attr
) == 0) ||
2113 StrCaseCmp(name
, attr_strings
.access_time_attr
) == 0 ||
2114 StrCaseCmp(name
, attr_strings
.write_time_attr
) == 0 ||
2115 StrCaseCmp(name
, attr_strings
.change_time_attr
) == 0 ||
2116 StrCaseCmp(name
, "system.dos_attr.inode") == 0) {
2119 char *filename
= (char *) name
;
2120 ret
= cacl_get(context
, talloc_tos(), srv
,
2121 ipc_srv
== NULL
? NULL
: ipc_srv
->cli
,
2122 &ipc_srv
->pol
, path
,
2124 CONST_DISCARD(char *, value
),
2126 if (ret
< 0 && errno
== 0) {
2127 errno
= SMBC_errno(context
, srv
->cli
);
2133 /* Unsupported attribute name */
2141 SMBC_removexattr_ctx(SMBCCTX
*context
,
2146 SMBCSRV
*srv
= NULL
;
2147 SMBCSRV
*ipc_srv
= NULL
;
2148 char *server
= NULL
;
2151 char *password
= NULL
;
2152 char *workgroup
= NULL
;
2154 TALLOC_CTX
*frame
= talloc_stackframe();
2156 if (!context
|| !context
->internal
->initialized
) {
2158 errno
= EINVAL
; /* Best I can think of ... */
2169 DEBUG(4, ("smbc_removexattr(%s, %s)\n", fname
, name
));
2171 if (SMBC_parse_path(frame
,
2186 if (!user
|| user
[0] == (char)0) {
2187 user
= talloc_strdup(frame
, smbc_getUser(context
));
2195 srv
= SMBC_server(frame
, context
, True
,
2196 server
, share
, &workgroup
, &user
, &password
);
2199 return -1; /* errno set by SMBC_server */
2202 if (! srv
->no_nt_session
) {
2203 ipc_srv
= SMBC_attr_server(frame
, context
, server
, share
,
2204 &workgroup
, &user
, &password
);
2206 srv
->no_nt_session
= True
;
2214 return -1; /* errno set by SMBC_attr_server */
2217 /* Are they asking to set the entire ACL? */
2218 if (StrCaseCmp(name
, "system.nt_sec_desc.*") == 0 ||
2219 StrCaseCmp(name
, "system.nt_sec_desc.*+") == 0) {
2222 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
2223 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
2224 NULL
, SMBC_XATTR_MODE_REMOVE_ALL
, 0);
2230 * Are they asking to remove one or more spceific security descriptor
2233 if (StrCaseCmp(name
, "system.nt_sec_desc.revision") == 0 ||
2234 StrCaseCmp(name
, "system.nt_sec_desc.owner") == 0 ||
2235 StrCaseCmp(name
, "system.nt_sec_desc.owner+") == 0 ||
2236 StrCaseCmp(name
, "system.nt_sec_desc.group") == 0 ||
2237 StrCaseCmp(name
, "system.nt_sec_desc.group+") == 0 ||
2238 StrnCaseCmp(name
, "system.nt_sec_desc.acl", 22) == 0 ||
2239 StrnCaseCmp(name
, "system.nt_sec_desc.acl+", 23) == 0) {
2242 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
2243 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
2244 CONST_DISCARD(char *, name
) + 19,
2245 SMBC_XATTR_MODE_REMOVE
, 0);
2250 /* Unsupported attribute name */
2257 SMBC_listxattr_ctx(SMBCCTX
*context
,
2263 * This isn't quite what listxattr() is supposed to do. This returns
2264 * the complete set of attribute names, always, rather than only those
2265 * attribute names which actually exist for a file. Hmmm...
2268 const char supported_old
[] =
2271 "system.nt_sec_desc.revision\0"
2272 "system.nt_sec_desc.owner\0"
2273 "system.nt_sec_desc.owner+\0"
2274 "system.nt_sec_desc.group\0"
2275 "system.nt_sec_desc.group+\0"
2276 "system.nt_sec_desc.acl.*\0"
2277 "system.nt_sec_desc.acl\0"
2278 "system.nt_sec_desc.acl+\0"
2279 "system.nt_sec_desc.*\0"
2280 "system.nt_sec_desc.*+\0"
2281 "system.dos_attr.*\0"
2282 "system.dos_attr.mode\0"
2283 "system.dos_attr.c_time\0"
2284 "system.dos_attr.a_time\0"
2285 "system.dos_attr.m_time\0"
2287 const char supported_new
[] =
2290 "system.nt_sec_desc.revision\0"
2291 "system.nt_sec_desc.owner\0"
2292 "system.nt_sec_desc.owner+\0"
2293 "system.nt_sec_desc.group\0"
2294 "system.nt_sec_desc.group+\0"
2295 "system.nt_sec_desc.acl.*\0"
2296 "system.nt_sec_desc.acl\0"
2297 "system.nt_sec_desc.acl+\0"
2298 "system.nt_sec_desc.*\0"
2299 "system.nt_sec_desc.*+\0"
2300 "system.dos_attr.*\0"
2301 "system.dos_attr.mode\0"
2302 "system.dos_attr.create_time\0"
2303 "system.dos_attr.access_time\0"
2304 "system.dos_attr.write_time\0"
2305 "system.dos_attr.change_time\0"
2307 const char * supported
;
2309 if (context
->internal
->full_time_names
) {
2310 supported
= supported_new
;
2311 retsize
= sizeof(supported_new
);
2313 supported
= supported_old
;
2314 retsize
= sizeof(supported_old
);
2321 if (retsize
> size
) {
2326 /* this can't be strcpy() because there are embedded null characters */
2327 memcpy(list
, supported
, retsize
);