2 * Convert AFS acls to NT acls and vice versa.
4 * Copyright (C) Volker Lendecke, 2003
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DBGC_CLASS DBGC_VFS
29 #include <afs/venus.h>
30 #include <afs/prs_fs.h>
34 extern const DOM_SID global_sid_World
;
35 extern const DOM_SID global_sid_Builtin_Administrators
;
36 extern const DOM_SID global_sid_Builtin_Backup_Operators
;
37 extern const DOM_SID global_sid_Authenticated_Users
;
38 extern const DOM_SID global_sid_NULL
;
40 static char space_replacement
= '%';
42 extern int afs_syscall(int, char *, int, char *, int);
48 enum SID_NAME_USE type
;
57 struct afs_ace
*acelist
;
62 uint16 in_size
, out_size
;
66 static BOOL
init_afs_acl(struct afs_acl
*acl
)
69 acl
->ctx
= talloc_init("afs_acl");
70 if (acl
->ctx
== NULL
) {
71 DEBUG(10, ("Could not init afs_acl"));
77 static void free_afs_acl(struct afs_acl
*acl
)
80 talloc_destroy(acl
->ctx
);
86 static struct afs_ace
*clone_afs_ace(TALLOC_CTX
*mem_ctx
, struct afs_ace
*ace
)
88 struct afs_ace
*result
= TALLOC_P(mem_ctx
, struct afs_ace
);
96 result
->name
= talloc_strdup(mem_ctx
, ace
->name
);
98 if (result
->name
== NULL
) {
106 /* Ok, this is sort-of a hack. We assume here that we have winbind users in
107 * AFS. And yet another copy of parse_domain_user.... */
109 static BOOL
parse_domain_user(const char *domuser
, fstring domain
,
112 char *p
= strchr(domuser
,*lp_winbind_separator());
119 fstrcpy(domain
, domuser
);
120 domain
[PTR_DIFF(p
, domuser
)] = 0;
126 static struct afs_ace
*new_afs_ace(TALLOC_CTX
*mem_ctx
,
128 const char *name
, uint32 rights
)
131 enum SID_NAME_USE type
;
132 struct afs_ace
*result
;
134 if (strcmp(name
, "system:administrators") == 0) {
136 sid_copy(&sid
, &global_sid_Builtin_Administrators
);
137 type
= SID_NAME_ALIAS
;
139 } else if (strcmp(name
, "system:anyuser") == 0) {
141 sid_copy(&sid
, &global_sid_World
);
142 type
= SID_NAME_ALIAS
;
144 } else if (strcmp(name
, "system:authuser") == 0) {
146 sid_copy(&sid
, &global_sid_Authenticated_Users
);
147 type
= SID_NAME_WKN_GRP
;
149 } else if (strcmp(name
, "system:backup") == 0) {
151 sid_copy(&sid
, &global_sid_Builtin_Backup_Operators
);
152 type
= SID_NAME_ALIAS
;
156 fstring user
, domain
;
158 if (!parse_domain_user(name
, domain
, user
)) {
160 fstrcpy(domain
, lp_workgroup());
163 if (!lookup_name(domain
, user
, &sid
, &type
)) {
164 DEBUG(10, ("Could not find AFS user %s\n", name
));
166 sid_copy(&sid
, &global_sid_NULL
);
167 type
= SID_NAME_UNKNOWN
;
172 result
= TALLOC_P(mem_ctx
, struct afs_ace
);
174 if (result
== NULL
) {
175 DEBUG(0, ("Could not talloc AFS ace\n"));
179 result
->name
= talloc_strdup(mem_ctx
, name
);
180 if (result
->name
== NULL
) {
181 DEBUG(0, ("Could not talloc AFS ace name\n"));
188 result
->positive
= positive
;
189 result
->rights
= rights
;
194 static void add_afs_ace(struct afs_acl
*acl
,
196 const char *name
, uint32 rights
)
200 for (ace
= acl
->acelist
; ace
!= NULL
; ace
= ace
->next
) {
201 if ((ace
->positive
== positive
) &&
202 (strequal(ace
->name
, name
))) {
203 ace
->rights
|= rights
;
208 ace
= new_afs_ace(acl
->ctx
, positive
, name
, rights
);
210 ace
->next
= acl
->acelist
;
215 DEBUG(10, ("add_afs_ace: Added %s entry for %s with rights %d\n",
216 ace
->positive
?"positive":"negative",
217 ace
->name
, ace
->rights
));
222 /* AFS ACLs in string form are a long string of fields delimited with \n.
224 * First line: Number of positive entries
225 * Second line: Number of negative entries
226 * Third and following lines: The entries themselves
228 * An ACE is a line of two fields, delimited by \t.
231 * Second field: Rights
234 static BOOL
parse_afs_acl(struct afs_acl
*acl
, const char *acl_str
)
242 strncpy(str
, acl_str
, MAXSIZE
);
244 if (sscanf(p
, "%d", &nplus
) != 1)
247 DEBUG(10, ("Found %d positive entries\n", nplus
));
249 if ((p
= strchr(p
, '\n')) == NULL
)
253 if (sscanf(p
, "%d", &nminus
) != 1)
256 DEBUG(10, ("Found %d negative entries\n", nminus
));
258 if ((p
= strchr(p
, '\n')) == NULL
)
262 for (aces
= nplus
+nminus
; aces
> 0; aces
--)
272 if ((p
= strchr(p
, '\t')) == NULL
)
277 if (sscanf(p
, "%d", &rights
) != 1)
280 if ((p
= strchr(p
, '\n')) == NULL
)
284 fstrcpy(name
, namep
);
286 while ((space
= strchr_m(name
, space_replacement
)) != NULL
)
289 add_afs_ace(acl
, nplus
>0, name
, rights
);
297 static BOOL
unparse_afs_acl(struct afs_acl
*acl
, char *acl_str
)
299 /* TODO: String length checks!!!! */
307 struct afs_ace
*ace
= acl
->acelist
;
309 while (ace
!= NULL
) {
317 fstr_sprintf(line
, "%d\n", positives
);
318 safe_strcat(acl_str
, line
, MAXSIZE
);
320 fstr_sprintf(line
, "%d\n", negatives
);
321 safe_strcat(acl_str
, line
, MAXSIZE
);
325 while (ace
!= NULL
) {
326 fstr_sprintf(line
, "%s\t%d\n", ace
->name
, ace
->rights
);
327 safe_strcat(acl_str
, line
, MAXSIZE
);
333 static uint32
afs_to_nt_file_rights(uint32 rights
)
337 if (rights
& PRSFS_READ
)
338 result
|= FILE_READ_DATA
| FILE_READ_EA
|
339 FILE_EXECUTE
| FILE_READ_ATTRIBUTES
|
340 READ_CONTROL_ACCESS
| SYNCHRONIZE_ACCESS
;
342 if (rights
& PRSFS_WRITE
)
343 result
|= FILE_WRITE_DATA
| FILE_WRITE_ATTRIBUTES
|
344 FILE_WRITE_EA
| FILE_APPEND_DATA
;
346 if (rights
& PRSFS_LOCK
)
347 result
|= WRITE_OWNER_ACCESS
;
349 if (rights
& PRSFS_DELETE
)
350 result
|= DELETE_ACCESS
;
355 static void afs_to_nt_dir_rights(uint32 afs_rights
, uint32
*nt_rights
,
359 *flag
= SEC_ACE_FLAG_OBJECT_INHERIT
|
360 SEC_ACE_FLAG_CONTAINER_INHERIT
;
362 if (afs_rights
& PRSFS_INSERT
)
363 *nt_rights
|= FILE_ADD_FILE
| FILE_ADD_SUBDIRECTORY
;
365 if (afs_rights
& PRSFS_LOOKUP
)
366 *nt_rights
|= FILE_READ_DATA
| FILE_READ_EA
|
367 FILE_EXECUTE
| FILE_READ_ATTRIBUTES
|
368 READ_CONTROL_ACCESS
| SYNCHRONIZE_ACCESS
;
370 if (afs_rights
& PRSFS_WRITE
)
371 *nt_rights
|= FILE_WRITE_ATTRIBUTES
| FILE_WRITE_DATA
|
372 FILE_APPEND_DATA
| FILE_WRITE_EA
;
374 if ((afs_rights
& (PRSFS_INSERT
|PRSFS_LOOKUP
|PRSFS_DELETE
)) ==
375 (PRSFS_INSERT
|PRSFS_LOOKUP
|PRSFS_DELETE
))
376 *nt_rights
|= FILE_WRITE_ATTRIBUTES
| FILE_WRITE_EA
|
377 GENERIC_WRITE_ACCESS
;
379 if (afs_rights
& PRSFS_DELETE
)
380 *nt_rights
|= DELETE_ACCESS
;
382 if (afs_rights
& PRSFS_ADMINISTER
)
383 *nt_rights
|= FILE_DELETE_CHILD
| WRITE_DAC_ACCESS
|
386 if ( (afs_rights
& PRSFS_LOOKUP
) ==
387 (afs_rights
& (PRSFS_LOOKUP
|PRSFS_READ
)) ) {
388 /* Only lookup right */
389 *flag
= SEC_ACE_FLAG_CONTAINER_INHERIT
;
395 #define AFS_FILE_RIGHTS (PRSFS_READ|PRSFS_WRITE|PRSFS_LOCK)
396 #define AFS_DIR_RIGHTS (PRSFS_INSERT|PRSFS_LOOKUP|PRSFS_DELETE|PRSFS_ADMINISTER)
398 static void split_afs_acl(struct afs_acl
*acl
,
399 struct afs_acl
*dir_acl
,
400 struct afs_acl
*file_acl
)
404 init_afs_acl(dir_acl
);
405 init_afs_acl(file_acl
);
407 for (ace
= acl
->acelist
; ace
!= NULL
; ace
= ace
->next
) {
408 if (ace
->rights
& AFS_FILE_RIGHTS
) {
409 add_afs_ace(file_acl
, ace
->positive
, ace
->name
,
410 ace
->rights
& AFS_FILE_RIGHTS
);
413 if (ace
->rights
& AFS_DIR_RIGHTS
) {
414 add_afs_ace(dir_acl
, ace
->positive
, ace
->name
,
415 ace
->rights
& AFS_DIR_RIGHTS
);
421 static BOOL
same_principal(struct afs_ace
*x
, struct afs_ace
*y
)
423 return ( (x
->positive
== y
->positive
) &&
424 (sid_compare(&x
->sid
, &y
->sid
) == 0) );
427 static void merge_afs_acls(struct afs_acl
*dir_acl
,
428 struct afs_acl
*file_acl
,
429 struct afs_acl
*target
)
433 init_afs_acl(target
);
435 for (ace
= dir_acl
->acelist
; ace
!= NULL
; ace
= ace
->next
) {
436 struct afs_ace
*file_ace
;
439 for (file_ace
= file_acl
->acelist
;
441 file_ace
= file_ace
->next
) {
442 if (!same_principal(ace
, file_ace
))
445 add_afs_ace(target
, ace
->positive
, ace
->name
,
446 ace
->rights
| file_ace
->rights
);
451 add_afs_ace(target
, ace
->positive
, ace
->name
,
455 for (ace
= file_acl
->acelist
; ace
!= NULL
; ace
= ace
->next
) {
456 struct afs_ace
*dir_ace
;
457 BOOL already_seen
= False
;
459 for (dir_ace
= dir_acl
->acelist
;
461 dir_ace
= dir_ace
->next
) {
462 if (!same_principal(ace
, dir_ace
))
468 add_afs_ace(target
, ace
->positive
, ace
->name
,
473 #define PERMS_READ 0x001200a9
474 #define PERMS_CHANGE 0x001301bf
475 #define PERMS_FULL 0x001f01ff
477 static struct static_dir_ace_mapping
{
485 { 0, SEC_ACE_FLAG_OBJECT_INHERIT
|SEC_ACE_FLAG_CONTAINER_INHERIT
,
486 PERMS_FULL
, 127 /* rlidwka */ },
489 { 0, SEC_ACE_FLAG_OBJECT_INHERIT
|SEC_ACE_FLAG_CONTAINER_INHERIT
,
490 PERMS_CHANGE
, 63 /* rlidwk */ },
492 /* Read (including list folder content) */
493 { 0, SEC_ACE_FLAG_OBJECT_INHERIT
|SEC_ACE_FLAG_CONTAINER_INHERIT
,
494 PERMS_READ
, 9 /* rl */ },
496 /* Read without list folder content -- same as "l" */
497 { 0, SEC_ACE_FLAG_OBJECT_INHERIT
|SEC_ACE_FLAG_CONTAINER_INHERIT
,
498 0x00120089, 8 /* l */ },
500 /* some stupid workaround for preventing fallbacks */
501 { 0, 0x3, 0x0012019F, 9 /* rl */ },
502 { 0, 0x13, PERMS_FULL
, 127 /* full */ },
504 /* read, delete and execute access plus synchronize */
505 { 0, 0x3, 0x001300A9, 9 /* should be rdl, set to rl */},
506 /* classical read list */
507 { 0, 0x13, 0x001200A9, 9 /* rl */},
508 /* almost full control, no delete */
509 { 0, 0x13, PERMS_CHANGE
, 63 /* rwidlk */},
512 { 0, SEC_ACE_FLAG_CONTAINER_INHERIT
,
513 PERMS_READ
, 8 /* l */ },
515 /* FULL without inheritance -- in all cases here we also get
516 the corresponding INHERIT_ONLY ACE in the same ACL */
517 { 0, 0, PERMS_FULL
, 127 /* rlidwka */ },
519 /* FULL inherit only -- counterpart to previous one */
520 { 0, SEC_ACE_FLAG_OBJECT_INHERIT
|SEC_ACE_FLAG_CONTAINER_INHERIT
|SEC_ACE_FLAG_INHERIT_ONLY
,
521 PERMS_FULL
| GENERIC_RIGHT_WRITE_ACCESS
, 127 /* rlidwka */ },
523 /* CHANGE without inheritance -- in all cases here we also get
524 the corresponding INHERIT_ONLY ACE in the same ACL */
525 { 0, 0, PERMS_CHANGE
, 63 /* rlidwk */ },
527 /* CHANGE inherit only -- counterpart to previous one */
528 { 0, SEC_ACE_FLAG_OBJECT_INHERIT
|SEC_ACE_FLAG_CONTAINER_INHERIT
|SEC_ACE_FLAG_INHERIT_ONLY
,
529 PERMS_CHANGE
| GENERIC_RIGHT_WRITE_ACCESS
, 63 /* rlidwk */ },
531 /* End marker, hopefully there's no afs right 9999 :-) */
535 static uint32
nt_to_afs_dir_rights(const char *filename
, const SEC_ACE
*ace
)
538 uint32 rights
= ace
->info
.mask
;
539 uint8 flags
= ace
->flags
;
541 struct static_dir_ace_mapping
*m
;
543 for (m
= &ace_mappings
[0]; m
->afs_rights
!= 9999; m
++) {
544 if ( (ace
->type
== m
->type
) &&
545 (ace
->flags
== m
->flags
) &&
546 (ace
->info
.mask
== m
->mask
) )
547 return m
->afs_rights
;
550 DEBUG(1, ("AFSACL FALLBACK: 0x%X 0x%X 0x%X %s %X\n",
551 ace
->type
, ace
->flags
, ace
->info
.mask
, filename
, rights
));
553 if (rights
& (GENERIC_ALL_ACCESS
|WRITE_DAC_ACCESS
)) {
554 result
|= PRSFS_READ
| PRSFS_WRITE
| PRSFS_INSERT
|
555 PRSFS_LOOKUP
| PRSFS_DELETE
| PRSFS_LOCK
|
559 if (rights
& (GENERIC_READ_ACCESS
|FILE_READ_DATA
)) {
560 result
|= PRSFS_LOOKUP
;
561 if (flags
& SEC_ACE_FLAG_OBJECT_INHERIT
) {
562 result
|= PRSFS_READ
;
566 if (rights
& (GENERIC_WRITE_ACCESS
|FILE_WRITE_DATA
)) {
567 result
|= PRSFS_INSERT
| PRSFS_DELETE
;
568 if (flags
& SEC_ACE_FLAG_OBJECT_INHERIT
) {
569 result
|= PRSFS_WRITE
| PRSFS_LOCK
;
576 static uint32
nt_to_afs_file_rights(const char *filename
, const SEC_ACE
*ace
)
579 uint32 rights
= ace
->info
.mask
;
581 if (rights
& (GENERIC_READ_ACCESS
|FILE_READ_DATA
)) {
582 result
|= PRSFS_READ
;
585 if (rights
& (GENERIC_WRITE_ACCESS
|FILE_WRITE_DATA
)) {
586 result
|= PRSFS_WRITE
| PRSFS_LOCK
;
592 static size_t afs_to_nt_acl(struct afs_acl
*afs_acl
,
593 struct files_struct
*fsp
,
594 uint32 security_info
,
595 struct security_descriptor_info
**ppdesc
)
597 SEC_ACE
*nt_ace_list
;
598 DOM_SID owner_sid
, group_sid
;
600 SMB_STRUCT_STAT sbuf
;
604 TALLOC_CTX
*mem_ctx
= main_loop_talloc_get();
606 struct afs_ace
*afs_ace
;
608 if (fsp
->is_directory
|| fsp
->fh
->fd
== -1) {
609 /* Get the stat struct for the owner info. */
610 if(SMB_VFS_STAT(fsp
->conn
,fsp
->fsp_name
, &sbuf
) != 0) {
614 if(SMB_VFS_FSTAT(fsp
,fsp
->fh
->fd
,&sbuf
) != 0) {
619 uid_to_sid(&owner_sid
, sbuf
.st_uid
);
620 gid_to_sid(&group_sid
, sbuf
.st_gid
);
622 nt_ace_list
= TALLOC_ARRAY(mem_ctx
, SEC_ACE
, afs_acl
->num_aces
);
624 if (nt_ace_list
== NULL
)
627 afs_ace
= afs_acl
->acelist
;
630 while (afs_ace
!= NULL
) {
632 uint8 flag
= SEC_ACE_FLAG_OBJECT_INHERIT
|
633 SEC_ACE_FLAG_CONTAINER_INHERIT
;
635 if (afs_ace
->type
== SID_NAME_UNKNOWN
) {
636 DEBUG(10, ("Ignoring unknown name %s\n",
638 afs_ace
= afs_ace
->next
;
642 if (fsp
->is_directory
)
643 afs_to_nt_dir_rights(afs_ace
->rights
, &nt_rights
,
646 nt_rights
= afs_to_nt_file_rights(afs_ace
->rights
);
648 init_sec_access(&mask
, nt_rights
);
649 init_sec_ace(&nt_ace_list
[good_aces
++], &(afs_ace
->sid
),
650 SEC_ACE_TYPE_ACCESS_ALLOWED
, mask
, flag
);
651 afs_ace
= afs_ace
->next
;
654 psa
= make_sec_acl(mem_ctx
, NT4_ACL_REVISION
,
655 good_aces
, nt_ace_list
);
660 *ppdesc
= make_sec_desc(mem_ctx
, SEC_DESC_REVISION
,
661 SEC_DESC_SELF_RELATIVE
,
662 (security_info
& OWNER_SECURITY_INFORMATION
)
664 (security_info
& GROUP_SECURITY_INFORMATION
)
666 NULL
, psa
, &sd_size
);
671 static BOOL
mappable_sid(const DOM_SID
*sid
)
675 if (sid_compare(sid
, &global_sid_Builtin_Administrators
) == 0)
678 if (sid_compare(sid
, &global_sid_World
) == 0)
681 if (sid_compare(sid
, &global_sid_Authenticated_Users
) == 0)
684 if (sid_compare(sid
, &global_sid_Builtin_Backup_Operators
) == 0)
687 string_to_sid(&domain_sid
, "S-1-5-21");
689 if (sid_compare_domain(sid
, &domain_sid
) == 0)
695 static BOOL
nt_to_afs_acl(const char *filename
,
696 uint32 security_info_sent
,
697 struct security_descriptor_info
*psd
,
698 uint32 (*nt_to_afs_rights
)(const char *filename
,
700 struct afs_acl
*afs_acl
)
705 /* Currently we *only* look at the dacl */
707 if (((security_info_sent
& DACL_SECURITY_INFORMATION
) == 0) ||
711 if (!init_afs_acl(afs_acl
))
716 for (i
= 0; i
< dacl
->num_aces
; i
++) {
717 SEC_ACE
*ace
= &(dacl
->ace
[i
]);
720 enum SID_NAME_USE name_type
;
723 if (ace
->type
!= SEC_ACE_TYPE_ACCESS_ALLOWED
) {
724 /* First cut: Only positive ACEs */
728 if (!mappable_sid(&ace
->trustee
)) {
729 DEBUG(10, ("Ignoring unmappable SID %s\n",
730 sid_string_static(&ace
->trustee
)));
734 if (sid_compare(&ace
->trustee
,
735 &global_sid_Builtin_Administrators
) == 0) {
737 fstrcpy(name
, "system:administrators");
739 } else if (sid_compare(&ace
->trustee
,
740 &global_sid_World
) == 0) {
742 fstrcpy(name
, "system:anyuser");
744 } else if (sid_compare(&ace
->trustee
,
745 &global_sid_Authenticated_Users
) == 0) {
747 fstrcpy(name
, "system:authuser");
749 } else if (sid_compare(&ace
->trustee
,
750 &global_sid_Builtin_Backup_Operators
)
753 fstrcpy(name
, "system:backup");
757 if (!lookup_sid(&ace
->trustee
,
758 dom_name
, name
, &name_type
)) {
759 DEBUG(1, ("AFSACL: Could not lookup SID %s on file %s\n",
760 sid_string_static(&ace
->trustee
), filename
));
764 if ( (name_type
== SID_NAME_USER
) ||
765 (name_type
== SID_NAME_DOM_GRP
) ||
766 (name_type
== SID_NAME_ALIAS
) ) {
767 fstring only_username
;
768 fstrcpy(only_username
, name
);
769 fstr_sprintf(name
, "%s%s%s",
770 dom_name
, lp_winbind_separator(),
776 while ((p
= strchr_m(name
, ' ')) != NULL
)
777 *p
= space_replacement
;
779 add_afs_ace(afs_acl
, True
, name
,
780 nt_to_afs_rights(filename
, ace
));
786 static BOOL
afs_get_afs_acl(char *filename
, struct afs_acl
*acl
)
794 DEBUG(5, ("afs_get_afs_acl: %s\n", filename
));
797 iob
.out_size
= MAXSIZE
;
798 iob
.in
= iob
.out
= space
;
800 ret
= afs_syscall(AFSCALL_PIOCTL
, filename
, VIOCGETAL
,
804 DEBUG(1, ("got error from PIOCTL: %d\n", ret
));
808 if (!init_afs_acl(acl
))
811 if (!parse_afs_acl(acl
, space
)) {
812 DEBUG(1, ("Could not parse AFS acl\n"));
820 static size_t afs_get_nt_acl(struct files_struct
*fsp
, uint32 security_info
,
821 struct security_descriptor_info
**ppdesc
)
826 DEBUG(5, ("afs_get_nt_acl: %s\n", fsp
->fsp_name
));
828 if (!afs_get_afs_acl(fsp
->fsp_name
, &acl
)) {
832 sd_size
= afs_to_nt_acl(&acl
, fsp
, security_info
, ppdesc
);
839 /* For setting an AFS ACL we have to take care of the ACEs we could
840 * not properly map to SIDs. Merge all of them into the new ACL. */
842 static void merge_unknown_aces(struct afs_acl
*src
, struct afs_acl
*dst
)
846 for (ace
= src
->acelist
; ace
!= NULL
; ace
= ace
->next
)
848 struct afs_ace
*copy
;
850 if (ace
->type
!= SID_NAME_UNKNOWN
) {
851 DEBUG(10, ("Not merging known ACE for %s\n",
856 DEBUG(10, ("Merging unknown ACE for %s\n", ace
->name
));
858 copy
= clone_afs_ace(dst
->ctx
, ace
);
861 DEBUG(0, ("Could not clone ACE for %s\n", ace
->name
));
865 copy
->next
= dst
->acelist
;
871 static BOOL
afs_set_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
,
872 uint32 security_info_sent
,
873 struct security_descriptor_info
*psd
)
875 struct afs_acl old_afs_acl
, new_afs_acl
;
876 struct afs_acl dir_acl
, file_acl
;
877 char acl_string
[2049];
881 const char *fileacls
;
883 fileacls
= lp_parm_const_string(SNUM(handle
->conn
), "afsacl", "fileacls",
886 ZERO_STRUCT(old_afs_acl
);
887 ZERO_STRUCT(new_afs_acl
);
888 ZERO_STRUCT(dir_acl
);
889 ZERO_STRUCT(file_acl
);
891 pstr_sprintf(name
, fsp
->fsp_name
);
893 if (!fsp
->is_directory
) {
894 /* We need to get the name of the directory containing the
895 * file, this is where the AFS acls live */
896 char *p
= strrchr(name
, '/');
904 if (!afs_get_afs_acl(name
, &old_afs_acl
)) {
905 DEBUG(3, ("Could not get old ACL of %s\n", fsp
->fsp_name
));
909 split_afs_acl(&old_afs_acl
, &dir_acl
, &file_acl
);
911 if (fsp
->is_directory
) {
913 if (!strequal(fileacls
, "yes")) {
914 /* Throw away file acls, we depend on the
915 * inheritance ACEs that also give us file
917 free_afs_acl(&file_acl
);
920 free_afs_acl(&dir_acl
);
921 if (!nt_to_afs_acl(fsp
->fsp_name
, security_info_sent
, psd
,
922 nt_to_afs_dir_rights
, &dir_acl
))
925 if (strequal(fileacls
, "no")) {
930 if (strequal(fileacls
, "ignore")) {
935 free_afs_acl(&file_acl
);
936 if (!nt_to_afs_acl(fsp
->fsp_name
, security_info_sent
, psd
,
937 nt_to_afs_file_rights
, &file_acl
))
941 merge_afs_acls(&dir_acl
, &file_acl
, &new_afs_acl
);
943 merge_unknown_aces(&old_afs_acl
, &new_afs_acl
);
945 unparse_afs_acl(&new_afs_acl
, acl_string
);
948 iob
.in_size
= 1+strlen(iob
.in
);
952 DEBUG(10, ("trying to set acl '%s' on file %s\n", iob
.in
, name
));
954 ret
= afs_syscall(AFSCALL_PIOCTL
, name
, VIOCSETAL
, (char *)&iob
, 0);
957 DEBUG(10, ("VIOCSETAL returned %d\n", ret
));
961 free_afs_acl(&dir_acl
);
962 free_afs_acl(&file_acl
);
963 free_afs_acl(&old_afs_acl
);
964 free_afs_acl(&new_afs_acl
);
969 static size_t afsacl_fget_nt_acl(struct vfs_handle_struct
*handle
,
970 struct files_struct
*fsp
,
971 int fd
, uint32 security_info
,
972 struct security_descriptor_info
**ppdesc
)
974 return afs_get_nt_acl(fsp
, security_info
, ppdesc
);
976 static size_t afsacl_get_nt_acl(struct vfs_handle_struct
*handle
,
977 struct files_struct
*fsp
,
978 const char *name
, uint32 security_info
,
979 struct security_descriptor_info
**ppdesc
)
981 return afs_get_nt_acl(fsp
, security_info
, ppdesc
);
984 BOOL
afsacl_fset_nt_acl(vfs_handle_struct
*handle
,
986 int fd
, uint32 security_info_sent
,
989 return afs_set_nt_acl(handle
, fsp
, security_info_sent
, psd
);
992 BOOL
afsacl_set_nt_acl(vfs_handle_struct
*handle
,
994 const char *name
, uint32 security_info_sent
,
997 return afs_set_nt_acl(handle
, fsp
, security_info_sent
, psd
);
1000 static int afsacl_connect(vfs_handle_struct
*handle
,
1001 connection_struct
*conn
,
1002 const char *service
,
1007 spc
= lp_parm_const_string(SNUM(handle
->conn
), "afsacl", "space", "%");
1010 space_replacement
= spc
[0];
1012 return SMB_VFS_NEXT_CONNECT(handle
, conn
, service
, user
);
1015 /* VFS operations structure */
1017 static vfs_op_tuple afsacl_ops
[] = {
1018 {SMB_VFS_OP(afsacl_connect
), SMB_VFS_OP_CONNECT
,
1019 SMB_VFS_LAYER_TRANSPARENT
},
1020 {SMB_VFS_OP(afsacl_fget_nt_acl
), SMB_VFS_OP_FGET_NT_ACL
,
1021 SMB_VFS_LAYER_TRANSPARENT
},
1022 {SMB_VFS_OP(afsacl_get_nt_acl
), SMB_VFS_OP_GET_NT_ACL
,
1023 SMB_VFS_LAYER_TRANSPARENT
},
1024 {SMB_VFS_OP(afsacl_fset_nt_acl
), SMB_VFS_OP_FSET_NT_ACL
,
1025 SMB_VFS_LAYER_TRANSPARENT
},
1026 {SMB_VFS_OP(afsacl_set_nt_acl
), SMB_VFS_OP_SET_NT_ACL
,
1027 SMB_VFS_LAYER_TRANSPARENT
},
1028 {SMB_VFS_OP(NULL
), SMB_VFS_OP_NOOP
, SMB_VFS_LAYER_NOOP
}
1031 NTSTATUS
vfs_afsacl_init(void)
1033 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "afsacl",