2 * Store Windows ACLs in xattrs.
4 * Copyright (C) Volker Lendecke, 2008
5 * Copyright (C) Jeremy Allison, 2008
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 /* NOTE: This is an experimental module, not yet finished. JRA. */
24 #include "librpc/gen_ndr/xattr.h"
25 #include "librpc/gen_ndr/ndr_xattr.h"
26 #include "../lib/crypto/crypto.h"
29 #define DBGC_CLASS DBGC_VFS
31 /* Pull in the common functions. */
32 #include "modules/vfs_acl_common.c"
34 /*******************************************************************
35 Pull a security descriptor into a DATA_BLOB from a xattr.
36 *******************************************************************/
38 static NTSTATUS
get_acl_blob(TALLOC_CTX
*ctx
,
39 vfs_handle_struct
*handle
,
54 tmp
= TALLOC_REALLOC_ARRAY(ctx
, val
, uint8_t, size
);
57 return NT_STATUS_NO_MEMORY
;
62 if (fsp
&& fsp
->fh
->fd
!= -1) {
63 sizeret
= SMB_VFS_FGETXATTR(fsp
, XATTR_NTACL_NAME
, val
, size
);
65 sizeret
= SMB_VFS_GETXATTR(handle
->conn
, name
,
66 XATTR_NTACL_NAME
, val
, size
);
73 /* Max ACL size is 65536 bytes. */
76 if ((errno
== ERANGE
) && (size
!= 65536)) {
77 /* Too small, try again. */
82 /* Real error - exit here. */
84 return map_nt_error_from_unix(errno
);
88 pblob
->length
= sizeret
;
92 /*******************************************************************
93 Store a DATA_BLOB into an xattr given an fsp pointer.
94 *******************************************************************/
96 static NTSTATUS
store_acl_blob_fsp(vfs_handle_struct
*handle
,
103 DEBUG(10,("store_acl_blob_fsp: storing blob length %u on file %s\n",
104 (unsigned int)pblob
->length
, fsp_str_dbg(fsp
)));
107 if (fsp
->fh
->fd
!= -1) {
108 ret
= SMB_VFS_FSETXATTR(fsp
, XATTR_NTACL_NAME
,
109 pblob
->data
, pblob
->length
, 0);
111 ret
= SMB_VFS_SETXATTR(fsp
->conn
, fsp
->fsp_name
->base_name
,
113 pblob
->data
, pblob
->length
, 0);
121 DEBUG(5, ("store_acl_blob_fsp: setting attr failed for file %s"
125 return map_nt_error_from_unix(errno
);
130 /*********************************************************************
131 Remove a Windows ACL - we're setting the underlying POSIX ACL.
132 *********************************************************************/
134 static int sys_acl_set_file_xattr(vfs_handle_struct
*handle
,
139 int ret
= SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
,
148 SMB_VFS_REMOVEXATTR(handle
->conn
, name
, XATTR_NTACL_NAME
);
154 /*********************************************************************
155 Remove a Windows ACL - we're setting the underlying POSIX ACL.
156 *********************************************************************/
158 static int sys_acl_set_fd_xattr(vfs_handle_struct
*handle
,
162 int ret
= SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
,
170 SMB_VFS_FREMOVEXATTR(fsp
, XATTR_NTACL_NAME
);
176 static int connect_acl_xattr(struct vfs_handle_struct
*handle
,
180 int ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
186 /* Ensure we have "inherit acls = yes" if we're
187 * using this module. */
188 DEBUG(2,("connect_acl_xattr: setting 'inherit acls = true' "
189 "and 'dos filemode = true' for service %s\n",
192 lp_do_parameter(SNUM(handle
->conn
), "inherit acls", "true");
193 lp_do_parameter(SNUM(handle
->conn
), "dos filemode", "true");
198 static struct vfs_fn_pointers vfs_acl_xattr_fns
= {
199 .connect_fn
= connect_acl_xattr
,
200 .opendir
= opendir_acl_common
,
201 .mkdir
= mkdir_acl_common
,
202 .rmdir
= rmdir_acl_common
,
203 .open
= open_acl_common
,
204 .create_file
= create_file_acl_common
,
205 .unlink
= unlink_acl_common
,
206 .fget_nt_acl
= fget_nt_acl_common
,
207 .get_nt_acl
= get_nt_acl_common
,
208 .fset_nt_acl
= fset_nt_acl_common
,
209 .sys_acl_set_file
= sys_acl_set_file_xattr
,
210 .sys_acl_set_fd
= sys_acl_set_fd_xattr
213 NTSTATUS
vfs_acl_xattr_init(void)
215 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "acl_xattr",