2 * Convert ZFS/NFSv4 acls to NT acls and vice versa.
4 * Copyright (C) Jiri Sasek, 2007
5 * based on the foobar.c module which is copyrighted by Volker Lendecke
7 * Many thanks to Axel Apitz for help to fix the special ace's handling
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 #include "nfs4_acls.h"
29 #define DBGC_CLASS DBGC_VFS
31 #define ZFSACL_MODULE_NAME "zfsacl"
34 * read the local file's acls and return it in NT form
35 * using the NFSv4 format conversion
37 static NTSTATUS
zfs_get_nt_acl_common(const char *name
,
46 /* read the number of file aces */
47 if((naces
= acl(name
, ACE_GETACLCNT
, 0, NULL
)) == -1) {
49 DEBUG(9, ("acl(ACE_GETACLCNT, %s): Operation is not "
50 "supported on the filesystem where the file "
53 DEBUG(9, ("acl(ACE_GETACLCNT, %s): %s ", name
,
56 return map_nt_error_from_unix(errno
);
58 /* allocate the field of ZFS aces */
59 mem_ctx
= talloc_tos();
60 acebuf
= (ace_t
*) talloc_size(mem_ctx
, sizeof(ace_t
)*naces
);
62 return NT_STATUS_NO_MEMORY
;
64 /* read the aces into the field */
65 if(acl(name
, ACE_GETACL
, naces
, acebuf
) < 0) {
66 DEBUG(9, ("acl(ACE_GETACL, %s): %s ", name
,
68 return map_nt_error_from_unix(errno
);
70 /* create SMB4ACL data */
71 if((pacl
= smb_create_smb4acl()) == NULL
) {
72 return NT_STATUS_NO_MEMORY
;
74 for(i
=0; i
<naces
; i
++) {
75 SMB_ACE4PROP_T aceprop
;
77 aceprop
.aceType
= (uint32
) acebuf
[i
].a_type
;
78 aceprop
.aceFlags
= (uint32
) acebuf
[i
].a_flags
;
79 aceprop
.aceMask
= (uint32
) acebuf
[i
].a_access_mask
;
80 aceprop
.who
.id
= (uint32
) acebuf
[i
].a_who
;
82 if(aceprop
.aceFlags
& ACE_OWNER
) {
83 aceprop
.flags
= SMB_ACE4_ID_SPECIAL
;
84 aceprop
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
85 } else if(aceprop
.aceFlags
& ACE_GROUP
) {
86 aceprop
.flags
= SMB_ACE4_ID_SPECIAL
;
87 aceprop
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
88 } else if(aceprop
.aceFlags
& ACE_EVERYONE
) {
89 aceprop
.flags
= SMB_ACE4_ID_SPECIAL
;
90 aceprop
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
94 if(smb_add_ace4(pacl
, &aceprop
) == NULL
)
95 return NT_STATUS_NO_MEMORY
;
102 /* call-back function processing the NT acl -> ZFS acl using NFSv4 conv. */
103 static bool zfs_process_smbacl(files_struct
*fsp
, SMB4ACL_T
*smbacl
)
105 int naces
= smb_get_naces(smbacl
), i
;
109 bool have_special_id
= false;
111 /* allocate the field of ZFS aces */
112 mem_ctx
= talloc_tos();
113 acebuf
= (ace_t
*) talloc_size(mem_ctx
, sizeof(ace_t
)*naces
);
118 /* handle all aces */
119 for(smbace
= smb_first_ace4(smbacl
), i
= 0;
121 smbace
= smb_next_ace4(smbace
), i
++) {
122 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
124 acebuf
[i
].a_type
= aceprop
->aceType
;
125 acebuf
[i
].a_flags
= aceprop
->aceFlags
;
126 acebuf
[i
].a_access_mask
= aceprop
->aceMask
;
127 acebuf
[i
].a_who
= aceprop
->who
.id
;
128 if(aceprop
->flags
& SMB_ACE4_ID_SPECIAL
) {
129 switch(aceprop
->who
.special_id
) {
130 case SMB_ACE4_WHO_EVERYONE
:
131 acebuf
[i
].a_flags
|= ACE_EVERYONE
;
133 case SMB_ACE4_WHO_OWNER
:
134 acebuf
[i
].a_flags
|= ACE_OWNER
;
136 case SMB_ACE4_WHO_GROUP
:
137 acebuf
[i
].a_flags
|= ACE_GROUP
;
140 DEBUG(8, ("unsupported special_id %d\n", \
141 aceprop
->who
.special_id
));
142 continue; /* don't add it !!! */
144 have_special_id
= true;
149 && lp_parm_bool(fsp
->conn
->params
->service
, "zfsacl",
150 "denymissingspecial", false)) {
155 SMB_ASSERT(i
== naces
);
158 if(acl(fsp
->fsp_name
->base_name
, ACE_SETACL
, naces
, acebuf
)) {
159 if(errno
== ENOSYS
) {
160 DEBUG(9, ("acl(ACE_SETACL, %s): Operation is not "
161 "supported on the filesystem where the file "
162 "reside", fsp_str_dbg(fsp
)));
164 DEBUG(9, ("acl(ACE_SETACL, %s): %s ", fsp_str_dbg(fsp
),
174 * set the local file's acls obtaining it in NT form
175 * using the NFSv4 format conversion
177 static NTSTATUS
zfs_set_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
,
178 uint32 security_info_sent
,
179 const struct security_descriptor
*psd
)
181 return smb_set_nt_acl_nfs4(fsp
, security_info_sent
, psd
,
185 static NTSTATUS
zfsacl_fget_nt_acl(struct vfs_handle_struct
*handle
,
186 struct files_struct
*fsp
,
187 uint32 security_info
,
188 struct security_descriptor
**ppdesc
)
193 status
= zfs_get_nt_acl_common(fsp
->fsp_name
->base_name
, security_info
,
195 if (!NT_STATUS_IS_OK(status
)) {
199 return smb_fget_nt_acl_nfs4(fsp
, security_info
, ppdesc
, pacl
);
202 static NTSTATUS
zfsacl_get_nt_acl(struct vfs_handle_struct
*handle
,
203 const char *name
, uint32 security_info
,
204 struct security_descriptor
**ppdesc
)
209 status
= zfs_get_nt_acl_common(name
, security_info
, &pacl
);
210 if (!NT_STATUS_IS_OK(status
)) {
214 return smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
, ppdesc
,
218 static NTSTATUS
zfsacl_fset_nt_acl(vfs_handle_struct
*handle
,
220 uint32 security_info_sent
,
221 const struct security_descriptor
*psd
)
223 return zfs_set_nt_acl(handle
, fsp
, security_info_sent
, psd
);
226 /* nils.goroll@hamburg.de 2008-06-16 :
229 - https://bugzilla.samba.org/show_bug.cgi?id=5446
230 - http://bugs.opensolaris.org/view_bug.do?bug_id=6688240
232 Solaris supports NFSv4 and ZFS ACLs through a common system call, acl(2)
233 with ACE_SETACL / ACE_GETACL / ACE_GETACLCNT, which is being wrapped for
234 use by samba in this module.
236 As the acl(2) interface is identical for ZFS and for NFS, this module,
237 vfs_zfsacl, can not only be used for ZFS, but also for sharing NFSv4
240 But while "traditional" POSIX DRAFT ACLs (using acl(2) with SETACL
241 / GETACL / GETACLCNT) fail for ZFS, the Solaris NFS client
242 implemets a compatibility wrapper, which will make calls to
243 traditional ACL calls though vfs_solarisacl succeed. As the
244 compatibility wrapper's implementation is (by design) incomplete,
245 we want to make sure that it is never being called.
247 As long as Samba does not support an exiplicit method for a module
248 to define conflicting vfs methods, we should override all conflicting
251 For this to work, we need to make sure that this module is initialised
252 *after* vfs_solarisacl
254 Function declarations taken from vfs_solarisacl
257 SMB_ACL_T
zfsacl_fail__sys_acl_get_file(vfs_handle_struct
*handle
,
261 return (SMB_ACL_T
)NULL
;
263 SMB_ACL_T
zfsacl_fail__sys_acl_get_fd(vfs_handle_struct
*handle
,
267 return (SMB_ACL_T
)NULL
;
270 int zfsacl_fail__sys_acl_set_file(vfs_handle_struct
*handle
,
278 int zfsacl_fail__sys_acl_set_fd(vfs_handle_struct
*handle
,
280 int fd
, SMB_ACL_T theacl
)
285 int zfsacl_fail__sys_acl_delete_def_file(vfs_handle_struct
*handle
,
291 /* VFS operations structure */
293 static struct vfs_fn_pointers zfsacl_fns
= {
294 .sys_acl_get_file
= zfsacl_fail__sys_acl_get_file
,
295 .sys_acl_get_fd
= zfsacl_fail__sys_acl_get_fd
,
296 .sys_acl_set_file
= zfsacl_fail__sys_acl_set_file
,
297 .sys_acl_set_fd
= zfsacl_fail__sys_acl_set_fd
,
298 .sys_acl_delete_def_file
= zfsacl_fail__sys_acl_delete_def_file
,
299 .fget_nt_acl
= zfsacl_fget_nt_acl
,
300 .get_nt_acl
= zfsacl_get_nt_acl
,
301 .fset_nt_acl
= zfsacl_fset_nt_acl
,
304 NTSTATUS
vfs_zfsacl_init(void);
305 NTSTATUS
vfs_zfsacl_init(void)
307 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "zfsacl",