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
) {
41 if (ndr_syntax_id_equal(&pipe_hnd
->abstract_syntax
,
42 &ndr_table_lsarpc
.syntax_id
)) {
50 * Sort ACEs according to the documentation at
51 * http://support.microsoft.com/kb/269175, at least as far as it defines the
56 ace_compare(SEC_ACE
*ace1
,
62 /* If the ACEs are equal, we have nothing more to do. */
63 if (sec_ace_equal(ace1
, ace2
)) {
67 /* Inherited follow non-inherited */
68 b1
= ((ace1
->flags
& SEC_ACE_FLAG_INHERITED_ACE
) != 0);
69 b2
= ((ace2
->flags
& SEC_ACE_FLAG_INHERITED_ACE
) != 0);
75 * What shall we do with AUDITs and ALARMs? It's undefined. We'll
76 * sort them after DENY and ALLOW.
78 b1
= (ace1
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED
&&
79 ace1
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
&&
80 ace1
->type
!= SEC_ACE_TYPE_ACCESS_DENIED
&&
81 ace1
->type
!= SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
82 b2
= (ace2
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED
&&
83 ace2
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
&&
84 ace2
->type
!= SEC_ACE_TYPE_ACCESS_DENIED
&&
85 ace2
->type
!= SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
90 /* Allowed ACEs follow denied ACEs */
91 b1
= (ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED
||
92 ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
);
93 b2
= (ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED
||
94 ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
);
100 * ACEs applying to an entity's object follow those applying to the
103 b1
= (ace1
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
||
104 ace1
->type
== SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
105 b2
= (ace2
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
||
106 ace2
->type
== SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
);
108 return (b1
? 1 : -1);
112 * If we get this far, the ACEs are similar as far as the
113 * characteristics we typically care about (those defined by the
114 * referenced MS document). We'll now sort by characteristics that
115 * just seems reasonable.
118 if (ace1
->type
!= ace2
->type
) {
119 return ace2
->type
- ace1
->type
;
122 if (sid_compare(&ace1
->trustee
, &ace2
->trustee
)) {
123 return sid_compare(&ace1
->trustee
, &ace2
->trustee
);
126 if (ace1
->flags
!= ace2
->flags
) {
127 return ace1
->flags
- ace2
->flags
;
130 if (ace1
->access_mask
!= ace2
->access_mask
) {
131 return ace1
->access_mask
- ace2
->access_mask
;
134 if (ace1
->size
!= ace2
->size
) {
135 return ace1
->size
- ace2
->size
;
138 return memcmp(ace1
, ace2
, sizeof(SEC_ACE
));
143 sort_acl(SEC_ACL
*the_acl
)
146 if (!the_acl
) return;
148 TYPESAFE_QSORT(the_acl
->aces
, the_acl
->num_aces
, ace_compare
);
150 for (i
=1;i
<the_acl
->num_aces
;) {
151 if (sec_ace_equal(&the_acl
->aces
[i
-1], &the_acl
->aces
[i
])) {
153 for (j
=i
; j
<the_acl
->num_aces
-1; j
++) {
154 the_acl
->aces
[j
] = the_acl
->aces
[j
+1];
163 /* convert a SID to a string, either numeric or username/group */
165 convert_sid_to_string(struct cli_state
*ipc_cli
,
166 struct policy_handle
*pol
,
171 char **domains
= NULL
;
173 enum lsa_SidType
*types
= NULL
;
174 struct rpc_pipe_client
*pipe_hnd
= find_lsa_pipe_hnd(ipc_cli
);
177 sid_to_fstring(str
, sid
);
180 return; /* no lookup desired */
187 /* Ask LSA to convert the sid to a name */
189 ctx
= talloc_stackframe();
191 if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_sids(pipe_hnd
, ctx
,
192 pol
, 1, sid
, &domains
,
194 !domains
|| !domains
[0] || !names
|| !names
[0]) {
201 slprintf(str
, sizeof(fstring
) - 1, "%s%s%s",
202 domains
[0], lp_winbind_separator(),
208 /* convert a string to a SID, either numeric or username/group */
210 convert_string_to_sid(struct cli_state
*ipc_cli
,
211 struct policy_handle
*pol
,
216 enum lsa_SidType
*types
= NULL
;
217 DOM_SID
*sids
= NULL
;
219 TALLOC_CTX
*ctx
= NULL
;
220 struct rpc_pipe_client
*pipe_hnd
= find_lsa_pipe_hnd(ipc_cli
);
227 if (strncmp(str
, "S-", 2) == 0) {
228 return string_to_sid(sid
, str
);
235 ctx
= talloc_stackframe();
236 if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_names(pipe_hnd
, ctx
,
244 sid_copy(sid
, &sids
[0]);
251 /* parse an ACE in the same format as print_ace() */
253 parse_ace(struct cli_state
*ipc_cli
,
254 struct policy_handle
*pol
,
267 const struct perm_value
*v
;
272 TALLOC_CTX
*frame
= talloc_stackframe();
274 /* These values discovered by inspection */
275 static const struct perm_value special_values
[] = {
285 static const struct perm_value standard_values
[] = {
286 { "READ", 0x001200a9 },
287 { "CHANGE", 0x001301bf },
288 { "FULL", 0x001f01ff },
293 p
= strchr_m(str
,':');
300 /* Try to parse numeric form */
302 if (sscanf(p
, "%i/%i/%i", &atype
, &aflags
, &amask
) == 3 &&
303 convert_string_to_sid(ipc_cli
, pol
, numeric
, &sid
, str
)) {
307 /* Try to parse text form */
309 if (!convert_string_to_sid(ipc_cli
, pol
, numeric
, &sid
, str
)) {
315 if (!next_token_talloc(frame
, &cp
, &tok
, "/")) {
320 if (StrnCaseCmp(tok
, "ALLOWED", strlen("ALLOWED")) == 0) {
321 atype
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
322 } else if (StrnCaseCmp(tok
, "DENIED", strlen("DENIED")) == 0) {
323 atype
= SEC_ACE_TYPE_ACCESS_DENIED
;
329 /* Only numeric form accepted for flags at present */
331 if (!(next_token_talloc(frame
, &cp
, &tok
, "/") &&
332 sscanf(tok
, "%i", &aflags
))) {
337 if (!next_token_talloc(frame
, &cp
, &tok
, "/")) {
342 if (strncmp(tok
, "0x", 2) == 0) {
343 if (sscanf(tok
, "%i", &amask
) != 1) {
350 for (v
= standard_values
; v
->perm
; v
++) {
351 if (strcmp(tok
, v
->perm
) == 0) {
362 for (v
= special_values
; v
->perm
; v
++) {
363 if (v
->perm
[0] == *p
) {
383 init_sec_ace(ace
, &sid
, atype
, mask
, aflags
);
388 /* add an ACE to a list of ACEs in a SEC_ACL */
390 add_ace(SEC_ACL
**the_acl
,
398 (*the_acl
) = make_sec_acl(ctx
, 3, 1, ace
);
402 if ((aces
= SMB_CALLOC_ARRAY(SEC_ACE
,
403 1+(*the_acl
)->num_aces
)) == NULL
) {
406 memcpy(aces
, (*the_acl
)->aces
, (*the_acl
)->num_aces
* sizeof(SEC_ACE
));
407 memcpy(aces
+(*the_acl
)->num_aces
, ace
, sizeof(SEC_ACE
));
408 newacl
= make_sec_acl(ctx
, (*the_acl
)->revision
,
409 1+(*the_acl
)->num_aces
, aces
);
416 /* parse a ascii version of a security descriptor */
418 sec_desc_parse(TALLOC_CTX
*ctx
,
419 struct cli_state
*ipc_cli
,
420 struct policy_handle
*pol
,
426 SEC_DESC
*ret
= NULL
;
428 DOM_SID
*group_sid
=NULL
;
429 DOM_SID
*owner_sid
=NULL
;
433 while (next_token_talloc(ctx
, &p
, &tok
, "\t,\r\n")) {
435 if (StrnCaseCmp(tok
,"REVISION:", 9) == 0) {
436 revision
= strtol(tok
+9, NULL
, 16);
440 if (StrnCaseCmp(tok
,"OWNER:", 6) == 0) {
442 DEBUG(5,("OWNER specified more than once!\n"));
445 owner_sid
= SMB_CALLOC_ARRAY(DOM_SID
, 1);
447 !convert_string_to_sid(ipc_cli
, pol
,
450 DEBUG(5, ("Failed to parse owner sid\n"));
456 if (StrnCaseCmp(tok
,"OWNER+:", 7) == 0) {
458 DEBUG(5,("OWNER specified more than once!\n"));
461 owner_sid
= SMB_CALLOC_ARRAY(DOM_SID
, 1);
463 !convert_string_to_sid(ipc_cli
, pol
,
466 DEBUG(5, ("Failed to parse owner sid\n"));
472 if (StrnCaseCmp(tok
,"GROUP:", 6) == 0) {
474 DEBUG(5,("GROUP specified more than once!\n"));
477 group_sid
= SMB_CALLOC_ARRAY(DOM_SID
, 1);
479 !convert_string_to_sid(ipc_cli
, pol
,
482 DEBUG(5, ("Failed to parse group sid\n"));
488 if (StrnCaseCmp(tok
,"GROUP+:", 7) == 0) {
490 DEBUG(5,("GROUP specified more than once!\n"));
493 group_sid
= SMB_CALLOC_ARRAY(DOM_SID
, 1);
495 !convert_string_to_sid(ipc_cli
, pol
,
498 DEBUG(5, ("Failed to parse group sid\n"));
504 if (StrnCaseCmp(tok
,"ACL:", 4) == 0) {
506 if (!parse_ace(ipc_cli
, pol
, &ace
, numeric
, tok
+4)) {
507 DEBUG(5, ("Failed to parse ACL %s\n", tok
));
510 if(!add_ace(&dacl
, &ace
, ctx
)) {
511 DEBUG(5, ("Failed to add ACL %s\n", tok
));
517 if (StrnCaseCmp(tok
,"ACL+:", 5) == 0) {
519 if (!parse_ace(ipc_cli
, pol
, &ace
, False
, tok
+5)) {
520 DEBUG(5, ("Failed to parse ACL %s\n", tok
));
523 if(!add_ace(&dacl
, &ace
, ctx
)) {
524 DEBUG(5, ("Failed to add ACL %s\n", tok
));
530 DEBUG(5, ("Failed to parse security descriptor\n"));
534 ret
= make_sec_desc(ctx
, revision
, SEC_DESC_SELF_RELATIVE
,
535 owner_sid
, group_sid
, NULL
, dacl
, &sd_size
);
538 SAFE_FREE(group_sid
);
539 SAFE_FREE(owner_sid
);
544 /* Obtain the current dos attributes */
545 static DOS_ATTR_DESC
*
546 dos_attr_query(SMBCCTX
*context
,
548 const char *filename
,
551 struct timespec create_time_ts
;
552 struct timespec write_time_ts
;
553 struct timespec access_time_ts
;
554 struct timespec change_time_ts
;
560 ret
= TALLOC_P(ctx
, DOS_ATTR_DESC
);
566 /* Obtain the DOS attributes */
567 if (!SMBC_getatr(context
, srv
, CONST_DISCARD(char *, filename
),
574 errno
= SMBC_errno(context
, srv
->cli
);
575 DEBUG(5, ("dos_attr_query Failed to query old attributes\n"));
581 ret
->create_time
= convert_timespec_to_time_t(create_time_ts
);
582 ret
->access_time
= convert_timespec_to_time_t(access_time_ts
);
583 ret
->write_time
= convert_timespec_to_time_t(write_time_ts
);
584 ret
->change_time
= convert_timespec_to_time_t(change_time_ts
);
591 /* parse a ascii version of a security descriptor */
593 dos_attr_parse(SMBCCTX
*context
,
601 TALLOC_CTX
*frame
= NULL
;
603 const char * create_time_attr
;
604 const char * access_time_attr
;
605 const char * write_time_attr
;
606 const char * change_time_attr
;
609 /* Determine whether to use old-style or new-style attribute names */
610 if (context
->internal
->full_time_names
) {
611 /* new-style names */
612 attr_strings
.create_time_attr
= "CREATE_TIME";
613 attr_strings
.access_time_attr
= "ACCESS_TIME";
614 attr_strings
.write_time_attr
= "WRITE_TIME";
615 attr_strings
.change_time_attr
= "CHANGE_TIME";
617 /* old-style names */
618 attr_strings
.create_time_attr
= NULL
;
619 attr_strings
.access_time_attr
= "A_TIME";
620 attr_strings
.write_time_attr
= "M_TIME";
621 attr_strings
.change_time_attr
= "C_TIME";
624 /* if this is to set the entire ACL... */
626 /* ... then increment past the first colon if there is one */
627 if ((p
= strchr(str
, ':')) != NULL
) {
634 frame
= talloc_stackframe();
635 while (next_token_talloc(frame
, &p
, &tok
, "\t,\r\n")) {
636 if (StrnCaseCmp(tok
, "MODE:", 5) == 0) {
637 long request
= strtol(tok
+5, NULL
, 16);
639 dad
->mode
= (request
|
640 (IS_DOS_DIR(dad
->mode
)
641 ? FILE_ATTRIBUTE_DIRECTORY
642 : FILE_ATTRIBUTE_NORMAL
));
649 if (StrnCaseCmp(tok
, "SIZE:", 5) == 0) {
650 dad
->size
= (SMB_OFF_T
)atof(tok
+5);
654 n
= strlen(attr_strings
.access_time_attr
);
655 if (StrnCaseCmp(tok
, attr_strings
.access_time_attr
, n
) == 0) {
656 dad
->access_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
660 n
= strlen(attr_strings
.change_time_attr
);
661 if (StrnCaseCmp(tok
, attr_strings
.change_time_attr
, n
) == 0) {
662 dad
->change_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
666 n
= strlen(attr_strings
.write_time_attr
);
667 if (StrnCaseCmp(tok
, attr_strings
.write_time_attr
, n
) == 0) {
668 dad
->write_time
= (time_t)strtol(tok
+n
+1, NULL
, 10);
672 if (attr_strings
.create_time_attr
!= NULL
) {
673 n
= strlen(attr_strings
.create_time_attr
);
674 if (StrnCaseCmp(tok
, attr_strings
.create_time_attr
,
676 dad
->create_time
= (time_t)strtol(tok
+n
+1,
682 if (StrnCaseCmp(tok
, "INODE:", 6) == 0) {
683 dad
->inode
= (SMB_INO_T
)atof(tok
+6);
690 /*****************************************************
691 Retrieve the acls for a file.
692 *******************************************************/
695 cacl_get(SMBCCTX
*context
,
698 struct cli_state
*ipc_cli
,
699 struct policy_handle
*pol
,
714 bool exclude_nt_revision
= False
;
715 bool exclude_nt_owner
= False
;
716 bool exclude_nt_group
= False
;
717 bool exclude_nt_acl
= False
;
718 bool exclude_dos_mode
= False
;
719 bool exclude_dos_size
= False
;
720 bool exclude_dos_create_time
= False
;
721 bool exclude_dos_access_time
= False
;
722 bool exclude_dos_write_time
= False
;
723 bool exclude_dos_change_time
= False
;
724 bool exclude_dos_inode
= False
;
726 bool determine_size
= (bufsize
== 0);
730 fstring name_sandbox
;
734 struct timespec create_time_ts
;
735 struct timespec write_time_ts
;
736 struct timespec access_time_ts
;
737 struct timespec change_time_ts
;
738 time_t create_time
= (time_t)0;
739 time_t write_time
= (time_t)0;
740 time_t access_time
= (time_t)0;
741 time_t change_time
= (time_t)0;
745 struct cli_state
*cli
= srv
->cli
;
747 const char * create_time_attr
;
748 const char * access_time_attr
;
749 const char * write_time_attr
;
750 const char * change_time_attr
;
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 /* Determine whether to use old-style or new-style attribute names */
760 if (context
->internal
->full_time_names
) {
761 /* new-style names */
762 attr_strings
.create_time_attr
= "CREATE_TIME";
763 attr_strings
.access_time_attr
= "ACCESS_TIME";
764 attr_strings
.write_time_attr
= "WRITE_TIME";
765 attr_strings
.change_time_attr
= "CHANGE_TIME";
767 excl_attr_strings
.create_time_attr
= "CREATE_TIME";
768 excl_attr_strings
.access_time_attr
= "ACCESS_TIME";
769 excl_attr_strings
.write_time_attr
= "WRITE_TIME";
770 excl_attr_strings
.change_time_attr
= "CHANGE_TIME";
772 /* old-style names */
773 attr_strings
.create_time_attr
= NULL
;
774 attr_strings
.access_time_attr
= "A_TIME";
775 attr_strings
.write_time_attr
= "M_TIME";
776 attr_strings
.change_time_attr
= "C_TIME";
778 excl_attr_strings
.create_time_attr
= NULL
;
779 excl_attr_strings
.access_time_attr
= "dos_attr.A_TIME";
780 excl_attr_strings
.write_time_attr
= "dos_attr.M_TIME";
781 excl_attr_strings
.change_time_attr
= "dos_attr.C_TIME";
784 /* Copy name so we can strip off exclusions (if any are specified) */
785 strncpy(name_sandbox
, attr_name
, sizeof(name_sandbox
) - 1);
787 /* Ensure name is null terminated */
788 name_sandbox
[sizeof(name_sandbox
) - 1] = '\0';
790 /* Play in the sandbox */
793 /* If there are any exclusions, point to them and mask them from name */
794 if ((pExclude
= strchr(name
, '!')) != NULL
)
799 all
= (StrnCaseCmp(name
, "system.*", 8) == 0);
800 all_nt
= (StrnCaseCmp(name
, "system.nt_sec_desc.*", 20) == 0);
801 all_nt_acls
= (StrnCaseCmp(name
, "system.nt_sec_desc.acl.*", 24) == 0);
802 all_dos
= (StrnCaseCmp(name
, "system.dos_attr.*", 17) == 0);
803 some_nt
= (StrnCaseCmp(name
, "system.nt_sec_desc.", 19) == 0);
804 some_dos
= (StrnCaseCmp(name
, "system.dos_attr.", 16) == 0);
805 numeric
= (* (name
+ strlen(name
) - 1) != '+');
807 /* Look for exclusions from "all" requests */
808 if (all
|| all_nt
|| all_dos
) {
809 /* Exclusions are delimited by '!' */
812 pExclude
= (p
== NULL
? NULL
: p
+ 1)) {
814 /* Find end of this exclusion name */
815 if ((p
= strchr(pExclude
, '!')) != NULL
)
820 /* Which exclusion name is this? */
821 if (StrCaseCmp(pExclude
,
822 "nt_sec_desc.revision") == 0) {
823 exclude_nt_revision
= True
;
825 else if (StrCaseCmp(pExclude
,
826 "nt_sec_desc.owner") == 0) {
827 exclude_nt_owner
= True
;
829 else if (StrCaseCmp(pExclude
,
830 "nt_sec_desc.group") == 0) {
831 exclude_nt_group
= True
;
833 else if (StrCaseCmp(pExclude
,
834 "nt_sec_desc.acl") == 0) {
835 exclude_nt_acl
= True
;
837 else if (StrCaseCmp(pExclude
,
838 "dos_attr.mode") == 0) {
839 exclude_dos_mode
= True
;
841 else if (StrCaseCmp(pExclude
,
842 "dos_attr.size") == 0) {
843 exclude_dos_size
= True
;
845 else if (excl_attr_strings
.create_time_attr
!= NULL
&&
847 excl_attr_strings
.change_time_attr
) == 0) {
848 exclude_dos_create_time
= True
;
850 else if (StrCaseCmp(pExclude
,
851 excl_attr_strings
.access_time_attr
) == 0) {
852 exclude_dos_access_time
= True
;
854 else if (StrCaseCmp(pExclude
,
855 excl_attr_strings
.write_time_attr
) == 0) {
856 exclude_dos_write_time
= True
;
858 else if (StrCaseCmp(pExclude
,
859 excl_attr_strings
.change_time_attr
) == 0) {
860 exclude_dos_change_time
= True
;
862 else if (StrCaseCmp(pExclude
, "dos_attr.inode") == 0) {
863 exclude_dos_inode
= True
;
866 DEBUG(5, ("cacl_get received unknown exclusion: %s\n",
877 * If we are (possibly) talking to an NT or new system and some NT
878 * attributes have been requested...
880 if (ipc_cli
&& (all
|| some_nt
|| all_nt_acls
)) {
881 char *targetpath
= NULL
;
882 struct cli_state
*targetcli
= NULL
;
884 /* Point to the portion after "system.nt_sec_desc." */
885 name
+= 19; /* if (all) this will be invalid but unused */
887 if (!cli_resolve_path(ctx
, "", context
->internal
->auth_info
,
889 &targetcli
, &targetpath
)) {
890 DEBUG(5, ("cacl_get Could not resolve %s\n",
896 /* ... then obtain any NT attributes which were requested */
897 if (!NT_STATUS_IS_OK(cli_ntcreate(targetcli
, targetpath
, 0, CREATE_ACCESS_READ
, 0,
898 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum
))) {
899 DEBUG(5, ("cacl_get failed to open %s: %s\n",
900 targetpath
, cli_errstr(targetcli
)));
905 sd
= cli_query_secdesc(targetcli
, fnum
, ctx
);
909 ("cacl_get Failed to query old descriptor\n"));
914 cli_close(targetcli
, fnum
);
916 if (! exclude_nt_revision
) {
918 if (determine_size
) {
919 p
= talloc_asprintf(ctx
,
928 n
= snprintf(buf
, bufsize
,
932 } else if (StrCaseCmp(name
, "revision") == 0) {
933 if (determine_size
) {
934 p
= talloc_asprintf(ctx
, "%d",
942 n
= snprintf(buf
, bufsize
, "%d",
947 if (!determine_size
&& n
> bufsize
) {
957 if (! exclude_nt_owner
) {
958 /* Get owner and group sid */
960 convert_sid_to_string(ipc_cli
, pol
,
969 if (determine_size
) {
970 p
= talloc_asprintf(ctx
, ",OWNER:%s",
977 } else if (sidstr
[0] != '\0') {
978 n
= snprintf(buf
, bufsize
,
979 ",OWNER:%s", sidstr
);
981 } else if (StrnCaseCmp(name
, "owner", 5) == 0) {
982 if (determine_size
) {
983 p
= talloc_asprintf(ctx
, "%s", sidstr
);
990 n
= snprintf(buf
, bufsize
, "%s",
995 if (!determine_size
&& n
> bufsize
) {
1005 if (! exclude_nt_group
) {
1006 if (sd
->group_sid
) {
1007 convert_sid_to_string(ipc_cli
, pol
,
1011 fstrcpy(sidstr
, "");
1014 if (all
|| all_nt
) {
1015 if (determine_size
) {
1016 p
= talloc_asprintf(ctx
, ",GROUP:%s",
1023 } else if (sidstr
[0] != '\0') {
1024 n
= snprintf(buf
, bufsize
,
1025 ",GROUP:%s", sidstr
);
1027 } else if (StrnCaseCmp(name
, "group", 5) == 0) {
1028 if (determine_size
) {
1029 p
= talloc_asprintf(ctx
, "%s", sidstr
);
1036 n
= snprintf(buf
, bufsize
,
1041 if (!determine_size
&& n
> bufsize
) {
1051 if (! exclude_nt_acl
) {
1052 /* Add aces to value buffer */
1053 for (i
= 0; sd
->dacl
&& i
< sd
->dacl
->num_aces
; i
++) {
1055 SEC_ACE
*ace
= &sd
->dacl
->aces
[i
];
1056 convert_sid_to_string(ipc_cli
, pol
,
1060 if (all
|| all_nt
) {
1061 if (determine_size
) {
1062 p
= talloc_asprintf(
1078 ",ACL:%s:%d/%d/0x%08x",
1084 } else if ((StrnCaseCmp(name
, "acl", 3) == 0 &&
1085 StrCaseCmp(name
+3, sidstr
) == 0) ||
1086 (StrnCaseCmp(name
, "acl+", 4) == 0 &&
1087 StrCaseCmp(name
+4, sidstr
) == 0)) {
1088 if (determine_size
) {
1089 p
= talloc_asprintf(
1101 n
= snprintf(buf
, bufsize
,
1107 } else if (all_nt_acls
) {
1108 if (determine_size
) {
1109 p
= talloc_asprintf(
1111 "%s%s:%d/%d/0x%08x",
1123 n
= snprintf(buf
, bufsize
,
1124 "%s%s:%d/%d/0x%08x",
1132 if (!determine_size
&& n
> bufsize
) {
1143 /* Restore name pointer to its original value */
1147 if (all
|| some_dos
) {
1148 /* Point to the portion after "system.dos_attr." */
1149 name
+= 16; /* if (all) this will be invalid but unused */
1151 /* Obtain the DOS attributes */
1152 if (!SMBC_getatr(context
, srv
, filename
, &mode
, &size
,
1159 errno
= SMBC_errno(context
, srv
->cli
);
1163 create_time
= convert_timespec_to_time_t(create_time_ts
);
1164 access_time
= convert_timespec_to_time_t(access_time_ts
);
1165 write_time
= convert_timespec_to_time_t(write_time_ts
);
1166 change_time
= convert_timespec_to_time_t(change_time_ts
);
1168 if (! exclude_dos_mode
) {
1169 if (all
|| all_dos
) {
1170 if (determine_size
) {
1171 p
= talloc_asprintf(ctx
,
1184 n
= snprintf(buf
, bufsize
,
1192 } else if (StrCaseCmp(name
, "mode") == 0) {
1193 if (determine_size
) {
1194 p
= talloc_asprintf(ctx
, "0x%x", mode
);
1201 n
= snprintf(buf
, bufsize
,
1206 if (!determine_size
&& n
> bufsize
) {
1216 if (! exclude_dos_size
) {
1217 if (all
|| all_dos
) {
1218 if (determine_size
) {
1219 p
= talloc_asprintf(
1229 n
= snprintf(buf
, bufsize
,
1233 } else if (StrCaseCmp(name
, "size") == 0) {
1234 if (determine_size
) {
1235 p
= talloc_asprintf(
1245 n
= snprintf(buf
, bufsize
,
1251 if (!determine_size
&& n
> bufsize
) {
1261 if (! exclude_dos_create_time
&&
1262 attr_strings
.create_time_attr
!= NULL
) {
1263 if (all
|| all_dos
) {
1264 if (determine_size
) {
1265 p
= talloc_asprintf(ctx
,
1267 attr_strings
.create_time_attr
,
1268 (unsigned long) create_time
);
1275 n
= snprintf(buf
, bufsize
,
1277 attr_strings
.create_time_attr
,
1278 (unsigned long) create_time
);
1280 } else if (StrCaseCmp(name
, attr_strings
.create_time_attr
) == 0) {
1281 if (determine_size
) {
1282 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) create_time
);
1289 n
= snprintf(buf
, bufsize
,
1290 "%lu", (unsigned long) create_time
);
1294 if (!determine_size
&& n
> bufsize
) {
1304 if (! exclude_dos_access_time
) {
1305 if (all
|| all_dos
) {
1306 if (determine_size
) {
1307 p
= talloc_asprintf(ctx
,
1309 attr_strings
.access_time_attr
,
1310 (unsigned long) access_time
);
1317 n
= snprintf(buf
, bufsize
,
1319 attr_strings
.access_time_attr
,
1320 (unsigned long) access_time
);
1322 } else if (StrCaseCmp(name
, attr_strings
.access_time_attr
) == 0) {
1323 if (determine_size
) {
1324 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) access_time
);
1331 n
= snprintf(buf
, bufsize
,
1332 "%lu", (unsigned long) access_time
);
1336 if (!determine_size
&& n
> bufsize
) {
1346 if (! exclude_dos_write_time
) {
1347 if (all
|| all_dos
) {
1348 if (determine_size
) {
1349 p
= talloc_asprintf(ctx
,
1351 attr_strings
.write_time_attr
,
1352 (unsigned long) write_time
);
1359 n
= snprintf(buf
, bufsize
,
1361 attr_strings
.write_time_attr
,
1362 (unsigned long) write_time
);
1364 } else if (StrCaseCmp(name
, attr_strings
.write_time_attr
) == 0) {
1365 if (determine_size
) {
1366 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) write_time
);
1373 n
= snprintf(buf
, bufsize
,
1374 "%lu", (unsigned long) write_time
);
1378 if (!determine_size
&& n
> bufsize
) {
1388 if (! exclude_dos_change_time
) {
1389 if (all
|| all_dos
) {
1390 if (determine_size
) {
1391 p
= talloc_asprintf(ctx
,
1393 attr_strings
.change_time_attr
,
1394 (unsigned long) change_time
);
1401 n
= snprintf(buf
, bufsize
,
1403 attr_strings
.change_time_attr
,
1404 (unsigned long) change_time
);
1406 } else if (StrCaseCmp(name
, attr_strings
.change_time_attr
) == 0) {
1407 if (determine_size
) {
1408 p
= talloc_asprintf(ctx
, "%lu", (unsigned long) change_time
);
1415 n
= snprintf(buf
, bufsize
,
1416 "%lu", (unsigned long) change_time
);
1420 if (!determine_size
&& n
> bufsize
) {
1430 if (! exclude_dos_inode
) {
1431 if (all
|| all_dos
) {
1432 if (determine_size
) {
1433 p
= talloc_asprintf(
1443 n
= snprintf(buf
, bufsize
,
1447 } else if (StrCaseCmp(name
, "inode") == 0) {
1448 if (determine_size
) {
1449 p
= talloc_asprintf(
1459 n
= snprintf(buf
, bufsize
,
1465 if (!determine_size
&& n
> bufsize
) {
1475 /* Restore name pointer to its original value */
1487 /*****************************************************
1488 set the ACLs on a file given an ascii description
1489 *******************************************************/
1491 cacl_set(SMBCCTX
*context
,
1493 struct cli_state
*cli
,
1494 struct cli_state
*ipc_cli
,
1495 struct policy_handle
*pol
,
1496 const char *filename
,
1501 uint16_t fnum
= (uint16_t)-1;
1503 SEC_DESC
*sd
= NULL
, *old
;
1504 SEC_ACL
*dacl
= NULL
;
1505 DOM_SID
*owner_sid
= NULL
;
1506 DOM_SID
*group_sid
= NULL
;
1511 bool numeric
= True
;
1512 char *targetpath
= NULL
;
1513 struct cli_state
*targetcli
= NULL
;
1515 /* the_acl will be null for REMOVE_ALL operations */
1517 numeric
= ((p
= strchr(the_acl
, ':')) != NULL
&&
1521 /* if this is to set the entire ACL... */
1522 if (*the_acl
== '*') {
1523 /* ... then increment past the first colon */
1527 sd
= sec_desc_parse(ctx
, ipc_cli
, pol
, numeric
, the_acl
);
1534 /* SMBC_XATTR_MODE_REMOVE_ALL is the only caller
1535 that doesn't deref sd */
1537 if (!sd
&& (mode
!= SMBC_XATTR_MODE_REMOVE_ALL
)) {
1542 if (!cli_resolve_path(ctx
, "", context
->internal
->auth_info
,
1544 &targetcli
, &targetpath
)) {
1545 DEBUG(5,("cacl_set: Could not resolve %s\n", filename
));
1550 /* The desired access below is the only one I could find that works
1551 with NT4, W2KP and Samba */
1553 if (!NT_STATUS_IS_OK(cli_ntcreate(targetcli
, targetpath
, 0, CREATE_ACCESS_READ
, 0,
1554 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum
))) {
1555 DEBUG(5, ("cacl_set failed to open %s: %s\n",
1556 targetpath
, cli_errstr(targetcli
)));
1561 old
= cli_query_secdesc(targetcli
, fnum
, ctx
);
1564 DEBUG(5, ("cacl_set Failed to query old descriptor\n"));
1569 cli_close(targetcli
, fnum
);
1572 case SMBC_XATTR_MODE_REMOVE_ALL
:
1573 old
->dacl
->num_aces
= 0;
1577 case SMBC_XATTR_MODE_REMOVE
:
1578 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1581 for (j
=0;old
->dacl
&& j
<old
->dacl
->num_aces
;j
++) {
1582 if (sec_ace_equal(&sd
->dacl
->aces
[i
],
1583 &old
->dacl
->aces
[j
])) {
1585 for (k
=j
; k
<old
->dacl
->num_aces
-1;k
++) {
1586 old
->dacl
->aces
[k
] =
1587 old
->dacl
->aces
[k
+1];
1589 old
->dacl
->num_aces
--;
1604 case SMBC_XATTR_MODE_ADD
:
1605 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1608 for (j
=0;old
->dacl
&& j
<old
->dacl
->num_aces
;j
++) {
1609 if (sid_equal(&sd
->dacl
->aces
[i
].trustee
,
1610 &old
->dacl
->aces
[j
].trustee
)) {
1611 if (!(flags
& SMBC_XATTR_FLAG_CREATE
)) {
1616 old
->dacl
->aces
[j
] = sd
->dacl
->aces
[i
];
1622 if (!found
&& (flags
& SMBC_XATTR_FLAG_REPLACE
)) {
1628 for (i
=0;sd
->dacl
&& i
<sd
->dacl
->num_aces
;i
++) {
1629 add_ace(&old
->dacl
, &sd
->dacl
->aces
[i
], ctx
);
1635 case SMBC_XATTR_MODE_SET
:
1637 owner_sid
= old
->owner_sid
;
1638 group_sid
= old
->group_sid
;
1642 case SMBC_XATTR_MODE_CHOWN
:
1643 owner_sid
= sd
->owner_sid
;
1646 case SMBC_XATTR_MODE_CHGRP
:
1647 group_sid
= sd
->group_sid
;
1651 /* Denied ACE entries must come before allowed ones */
1652 sort_acl(old
->dacl
);
1654 /* Create new security descriptor and set it */
1655 sd
= make_sec_desc(ctx
, old
->revision
, SEC_DESC_SELF_RELATIVE
,
1656 owner_sid
, group_sid
, NULL
, dacl
, &sd_size
);
1658 if (!NT_STATUS_IS_OK(cli_ntcreate(targetcli
, targetpath
, 0,
1659 WRITE_DAC_ACCESS
| WRITE_OWNER_ACCESS
, 0,
1660 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum
))) {
1661 DEBUG(5, ("cacl_set failed to open %s: %s\n",
1662 targetpath
, cli_errstr(targetcli
)));
1667 if (!cli_set_secdesc(targetcli
, fnum
, sd
)) {
1668 DEBUG(5, ("ERROR: secdesc set failed: %s\n",
1669 cli_errstr(targetcli
)));
1676 cli_close(targetcli
, fnum
);
1687 SMBC_setxattr_ctx(SMBCCTX
*context
,
1696 SMBCSRV
*srv
= NULL
;
1697 SMBCSRV
*ipc_srv
= NULL
;
1698 char *server
= NULL
;
1701 char *password
= NULL
;
1702 char *workgroup
= NULL
;
1704 DOS_ATTR_DESC
*dad
= NULL
;
1706 const char * create_time_attr
;
1707 const char * access_time_attr
;
1708 const char * write_time_attr
;
1709 const char * change_time_attr
;
1711 TALLOC_CTX
*frame
= talloc_stackframe();
1713 if (!context
|| !context
->internal
->initialized
) {
1714 errno
= EINVAL
; /* Best I can think of ... */
1725 DEBUG(4, ("smbc_setxattr(%s, %s, %.*s)\n",
1726 fname
, name
, (int) size
, (const char*)value
));
1728 if (SMBC_parse_path(frame
,
1743 if (!user
|| user
[0] == (char)0) {
1744 user
= talloc_strdup(frame
, smbc_getUser(context
));
1752 srv
= SMBC_server(frame
, context
, True
,
1753 server
, share
, &workgroup
, &user
, &password
);
1756 return -1; /* errno set by SMBC_server */
1759 if (! srv
->no_nt_session
) {
1760 ipc_srv
= SMBC_attr_server(frame
, context
, server
, share
,
1761 &workgroup
, &user
, &password
);
1763 srv
->no_nt_session
= True
;
1770 * Are they asking to set the entire set of known attributes?
1772 if (StrCaseCmp(name
, "system.*") == 0 ||
1773 StrCaseCmp(name
, "system.*+") == 0) {
1776 talloc_asprintf(talloc_tos(), "%s:%s",
1777 name
+7, (const char *) value
);
1786 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1787 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1790 ? SMBC_XATTR_MODE_SET
1791 : SMBC_XATTR_MODE_ADD
),
1797 /* get a DOS Attribute Descriptor with current attributes */
1798 dad
= dos_attr_query(context
, talloc_tos(), path
, srv
);
1800 /* Overwrite old with new, using what was provided */
1801 dos_attr_parse(context
, dad
, srv
, namevalue
);
1803 /* Set the new DOS attributes */
1804 if (! SMBC_setatr(context
, srv
, path
,
1811 /* cause failure if NT failed too */
1816 /* we only fail if both NT and DOS sets failed */
1817 if (ret
< 0 && ! dad
) {
1818 ret
= -1; /* in case dad was null */
1829 * Are they asking to set an access control element or to set
1830 * the entire access control list?
1832 if (StrCaseCmp(name
, "system.nt_sec_desc.*") == 0 ||
1833 StrCaseCmp(name
, "system.nt_sec_desc.*+") == 0 ||
1834 StrCaseCmp(name
, "system.nt_sec_desc.revision") == 0 ||
1835 StrnCaseCmp(name
, "system.nt_sec_desc.acl", 22) == 0 ||
1836 StrnCaseCmp(name
, "system.nt_sec_desc.acl+", 23) == 0) {
1840 talloc_asprintf(talloc_tos(), "%s:%s",
1841 name
+19, (const char *) value
);
1844 ret
= -1; /* errno set by SMBC_server() */
1846 else if (! namevalue
) {
1850 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1851 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1854 ? SMBC_XATTR_MODE_SET
1855 : SMBC_XATTR_MODE_ADD
),
1863 * Are they asking to set the owner?
1865 if (StrCaseCmp(name
, "system.nt_sec_desc.owner") == 0 ||
1866 StrCaseCmp(name
, "system.nt_sec_desc.owner+") == 0) {
1870 talloc_asprintf(talloc_tos(), "%s:%s",
1871 name
+19, (const char *) value
);
1874 ret
= -1; /* errno set by SMBC_server() */
1876 else if (! namevalue
) {
1880 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1881 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1882 namevalue
, SMBC_XATTR_MODE_CHOWN
, 0);
1889 * Are they asking to set the group?
1891 if (StrCaseCmp(name
, "system.nt_sec_desc.group") == 0 ||
1892 StrCaseCmp(name
, "system.nt_sec_desc.group+") == 0) {
1896 talloc_asprintf(talloc_tos(), "%s:%s",
1897 name
+19, (const char *) value
);
1900 /* errno set by SMBC_server() */
1903 else if (! namevalue
) {
1907 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
1908 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
1909 namevalue
, SMBC_XATTR_MODE_CHGRP
, 0);
1915 /* Determine whether to use old-style or new-style attribute names */
1916 if (context
->internal
->full_time_names
) {
1917 /* new-style names */
1918 attr_strings
.create_time_attr
= "system.dos_attr.CREATE_TIME";
1919 attr_strings
.access_time_attr
= "system.dos_attr.ACCESS_TIME";
1920 attr_strings
.write_time_attr
= "system.dos_attr.WRITE_TIME";
1921 attr_strings
.change_time_attr
= "system.dos_attr.CHANGE_TIME";
1923 /* old-style names */
1924 attr_strings
.create_time_attr
= NULL
;
1925 attr_strings
.access_time_attr
= "system.dos_attr.A_TIME";
1926 attr_strings
.write_time_attr
= "system.dos_attr.M_TIME";
1927 attr_strings
.change_time_attr
= "system.dos_attr.C_TIME";
1931 * Are they asking to set a DOS attribute?
1933 if (StrCaseCmp(name
, "system.dos_attr.*") == 0 ||
1934 StrCaseCmp(name
, "system.dos_attr.mode") == 0 ||
1935 (attr_strings
.create_time_attr
!= NULL
&&
1936 StrCaseCmp(name
, attr_strings
.create_time_attr
) == 0) ||
1937 StrCaseCmp(name
, attr_strings
.access_time_attr
) == 0 ||
1938 StrCaseCmp(name
, attr_strings
.write_time_attr
) == 0 ||
1939 StrCaseCmp(name
, attr_strings
.change_time_attr
) == 0) {
1941 /* get a DOS Attribute Descriptor with current attributes */
1942 dad
= dos_attr_query(context
, talloc_tos(), path
, srv
);
1945 talloc_asprintf(talloc_tos(), "%s:%s",
1946 name
+16, (const char *) value
);
1951 /* Overwrite old with provided new params */
1952 dos_attr_parse(context
, dad
, srv
, namevalue
);
1954 /* Set the new DOS attributes */
1955 ret2
= SMBC_setatr(context
, srv
, path
,
1962 /* ret2 has True (success) / False (failure) */
1977 /* Unsupported attribute name */
1984 SMBC_getxattr_ctx(SMBCCTX
*context
,
1991 SMBCSRV
*srv
= NULL
;
1992 SMBCSRV
*ipc_srv
= NULL
;
1993 char *server
= NULL
;
1996 char *password
= NULL
;
1997 char *workgroup
= NULL
;
2000 const char * create_time_attr
;
2001 const char * access_time_attr
;
2002 const char * write_time_attr
;
2003 const char * change_time_attr
;
2005 TALLOC_CTX
*frame
= talloc_stackframe();
2007 if (!context
|| !context
->internal
->initialized
) {
2008 errno
= EINVAL
; /* Best I can think of ... */
2019 DEBUG(4, ("smbc_getxattr(%s, %s)\n", fname
, name
));
2021 if (SMBC_parse_path(frame
,
2036 if (!user
|| user
[0] == (char)0) {
2037 user
= talloc_strdup(frame
, smbc_getUser(context
));
2045 srv
= SMBC_server(frame
, context
, True
,
2046 server
, share
, &workgroup
, &user
, &password
);
2049 return -1; /* errno set by SMBC_server */
2052 if (! srv
->no_nt_session
) {
2053 ipc_srv
= SMBC_attr_server(frame
, context
, server
, share
,
2054 &workgroup
, &user
, &password
);
2056 srv
->no_nt_session
= True
;
2062 /* Determine whether to use old-style or new-style attribute names */
2063 if (context
->internal
->full_time_names
) {
2064 /* new-style names */
2065 attr_strings
.create_time_attr
= "system.dos_attr.CREATE_TIME";
2066 attr_strings
.access_time_attr
= "system.dos_attr.ACCESS_TIME";
2067 attr_strings
.write_time_attr
= "system.dos_attr.WRITE_TIME";
2068 attr_strings
.change_time_attr
= "system.dos_attr.CHANGE_TIME";
2070 /* old-style names */
2071 attr_strings
.create_time_attr
= NULL
;
2072 attr_strings
.access_time_attr
= "system.dos_attr.A_TIME";
2073 attr_strings
.write_time_attr
= "system.dos_attr.M_TIME";
2074 attr_strings
.change_time_attr
= "system.dos_attr.C_TIME";
2077 /* Are they requesting a supported attribute? */
2078 if (StrCaseCmp(name
, "system.*") == 0 ||
2079 StrnCaseCmp(name
, "system.*!", 9) == 0 ||
2080 StrCaseCmp(name
, "system.*+") == 0 ||
2081 StrnCaseCmp(name
, "system.*+!", 10) == 0 ||
2082 StrCaseCmp(name
, "system.nt_sec_desc.*") == 0 ||
2083 StrnCaseCmp(name
, "system.nt_sec_desc.*!", 21) == 0 ||
2084 StrCaseCmp(name
, "system.nt_sec_desc.*+") == 0 ||
2085 StrnCaseCmp(name
, "system.nt_sec_desc.*+!", 22) == 0 ||
2086 StrCaseCmp(name
, "system.nt_sec_desc.revision") == 0 ||
2087 StrCaseCmp(name
, "system.nt_sec_desc.owner") == 0 ||
2088 StrCaseCmp(name
, "system.nt_sec_desc.owner+") == 0 ||
2089 StrCaseCmp(name
, "system.nt_sec_desc.group") == 0 ||
2090 StrCaseCmp(name
, "system.nt_sec_desc.group+") == 0 ||
2091 StrnCaseCmp(name
, "system.nt_sec_desc.acl", 22) == 0 ||
2092 StrnCaseCmp(name
, "system.nt_sec_desc.acl+", 23) == 0 ||
2093 StrCaseCmp(name
, "system.dos_attr.*") == 0 ||
2094 StrnCaseCmp(name
, "system.dos_attr.*!", 18) == 0 ||
2095 StrCaseCmp(name
, "system.dos_attr.mode") == 0 ||
2096 StrCaseCmp(name
, "system.dos_attr.size") == 0 ||
2097 (attr_strings
.create_time_attr
!= NULL
&&
2098 StrCaseCmp(name
, attr_strings
.create_time_attr
) == 0) ||
2099 StrCaseCmp(name
, attr_strings
.access_time_attr
) == 0 ||
2100 StrCaseCmp(name
, attr_strings
.write_time_attr
) == 0 ||
2101 StrCaseCmp(name
, attr_strings
.change_time_attr
) == 0 ||
2102 StrCaseCmp(name
, "system.dos_attr.inode") == 0) {
2105 char *filename
= (char *) name
;
2106 ret
= cacl_get(context
, talloc_tos(), srv
,
2107 ipc_srv
== NULL
? NULL
: ipc_srv
->cli
,
2108 &ipc_srv
->pol
, path
,
2110 CONST_DISCARD(char *, value
),
2112 if (ret
< 0 && errno
== 0) {
2113 errno
= SMBC_errno(context
, srv
->cli
);
2119 /* Unsupported attribute name */
2127 SMBC_removexattr_ctx(SMBCCTX
*context
,
2132 SMBCSRV
*srv
= NULL
;
2133 SMBCSRV
*ipc_srv
= NULL
;
2134 char *server
= NULL
;
2137 char *password
= NULL
;
2138 char *workgroup
= NULL
;
2140 TALLOC_CTX
*frame
= talloc_stackframe();
2142 if (!context
|| !context
->internal
->initialized
) {
2143 errno
= EINVAL
; /* Best I can think of ... */
2154 DEBUG(4, ("smbc_removexattr(%s, %s)\n", fname
, name
));
2156 if (SMBC_parse_path(frame
,
2171 if (!user
|| user
[0] == (char)0) {
2172 user
= talloc_strdup(frame
, smbc_getUser(context
));
2180 srv
= SMBC_server(frame
, context
, True
,
2181 server
, share
, &workgroup
, &user
, &password
);
2184 return -1; /* errno set by SMBC_server */
2187 if (! srv
->no_nt_session
) {
2188 ipc_srv
= SMBC_attr_server(frame
, context
, server
, share
,
2189 &workgroup
, &user
, &password
);
2191 srv
->no_nt_session
= True
;
2199 return -1; /* errno set by SMBC_attr_server */
2202 /* Are they asking to set the entire ACL? */
2203 if (StrCaseCmp(name
, "system.nt_sec_desc.*") == 0 ||
2204 StrCaseCmp(name
, "system.nt_sec_desc.*+") == 0) {
2207 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
2208 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
2209 NULL
, SMBC_XATTR_MODE_REMOVE_ALL
, 0);
2215 * Are they asking to remove one or more spceific security descriptor
2218 if (StrCaseCmp(name
, "system.nt_sec_desc.revision") == 0 ||
2219 StrCaseCmp(name
, "system.nt_sec_desc.owner") == 0 ||
2220 StrCaseCmp(name
, "system.nt_sec_desc.owner+") == 0 ||
2221 StrCaseCmp(name
, "system.nt_sec_desc.group") == 0 ||
2222 StrCaseCmp(name
, "system.nt_sec_desc.group+") == 0 ||
2223 StrnCaseCmp(name
, "system.nt_sec_desc.acl", 22) == 0 ||
2224 StrnCaseCmp(name
, "system.nt_sec_desc.acl+", 23) == 0) {
2227 ret
= cacl_set(context
, talloc_tos(), srv
->cli
,
2228 ipc_srv
->cli
, &ipc_srv
->pol
, path
,
2229 CONST_DISCARD(char *, name
) + 19,
2230 SMBC_XATTR_MODE_REMOVE
, 0);
2235 /* Unsupported attribute name */
2242 SMBC_listxattr_ctx(SMBCCTX
*context
,
2248 * This isn't quite what listxattr() is supposed to do. This returns
2249 * the complete set of attribute names, always, rather than only those
2250 * attribute names which actually exist for a file. Hmmm...
2253 const char supported_old
[] =
2256 "system.nt_sec_desc.revision\0"
2257 "system.nt_sec_desc.owner\0"
2258 "system.nt_sec_desc.owner+\0"
2259 "system.nt_sec_desc.group\0"
2260 "system.nt_sec_desc.group+\0"
2261 "system.nt_sec_desc.acl.*\0"
2262 "system.nt_sec_desc.acl\0"
2263 "system.nt_sec_desc.acl+\0"
2264 "system.nt_sec_desc.*\0"
2265 "system.nt_sec_desc.*+\0"
2266 "system.dos_attr.*\0"
2267 "system.dos_attr.mode\0"
2268 "system.dos_attr.c_time\0"
2269 "system.dos_attr.a_time\0"
2270 "system.dos_attr.m_time\0"
2272 const char supported_new
[] =
2275 "system.nt_sec_desc.revision\0"
2276 "system.nt_sec_desc.owner\0"
2277 "system.nt_sec_desc.owner+\0"
2278 "system.nt_sec_desc.group\0"
2279 "system.nt_sec_desc.group+\0"
2280 "system.nt_sec_desc.acl.*\0"
2281 "system.nt_sec_desc.acl\0"
2282 "system.nt_sec_desc.acl+\0"
2283 "system.nt_sec_desc.*\0"
2284 "system.nt_sec_desc.*+\0"
2285 "system.dos_attr.*\0"
2286 "system.dos_attr.mode\0"
2287 "system.dos_attr.create_time\0"
2288 "system.dos_attr.access_time\0"
2289 "system.dos_attr.write_time\0"
2290 "system.dos_attr.change_time\0"
2292 const char * supported
;
2294 if (context
->internal
->full_time_names
) {
2295 supported
= supported_new
;
2296 retsize
= sizeof(supported_new
);
2298 supported
= supported_old
;
2299 retsize
= sizeof(supported_old
);
2306 if (retsize
> size
) {
2311 /* this can't be strcpy() because there are embedded null characters */
2312 memcpy(list
, supported
, retsize
);