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 /*******************************************************************
32 Pull a security descriptor into a DATA_BLOB from a xattr.
33 *******************************************************************/
35 NTSTATUS get_acl_blob(TALLOC_CTX *ctx,
36 vfs_handle_struct *handle,
51 tmp = TALLOC_REALLOC_ARRAY(ctx, val, uint8_t, size);
54 return NT_STATUS_NO_MEMORY;
59 if (fsp && fsp->fh->fd != -1) {
60 sizeret = SMB_VFS_FGETXATTR(fsp, XATTR_NTACL_NAME, val, size);
62 sizeret = SMB_VFS_GETXATTR(handle->conn, name,
63 XATTR_NTACL_NAME, val, size);
70 /* Max ACL size is 65536 bytes. */
73 if ((errno == ERANGE) && (size != 65536)) {
74 /* Too small, try again. */
79 /* Real error - exit here. */
81 return map_nt_error_from_unix(errno);
85 pblob->length = sizeret;
89 /*******************************************************************
90 Store a DATA_BLOB into an xattr given an fsp pointer.
91 *******************************************************************/
93 NTSTATUS store_acl_blob_fsp(vfs_handle_struct *handle,
100 DEBUG(10,("store_acl_blob_fsp: storing blob length %u on file %s\n",
101 (unsigned int)pblob->length, fsp_str_dbg(fsp)));
104 if (fsp->fh->fd != -1) {
105 ret = SMB_VFS_FSETXATTR(fsp, XATTR_NTACL_NAME,
106 pblob->data, pblob->length, 0);
108 ret = SMB_VFS_SETXATTR(fsp->conn, fsp->fsp_name->base_name,
110 pblob->data, pblob->length, 0);
118 DEBUG(5, ("store_acl_blob_fsp: setting attr failed for file %s"
122 return map_nt_error_from_unix(errno);
127 /*******************************************************************
128 Store a DATA_BLOB into an xattr given a pathname.
129 *******************************************************************/
131 NTSTATUS store_acl_blob_pathname(vfs_handle_struct *handle,
135 connection_struct *conn = handle->conn;
139 DEBUG(10,("store_acl_blob_pathname: storing blob "
140 "length %u on file %s\n",
141 (unsigned int)pblob->length, fname));
144 ret = SMB_VFS_SETXATTR(conn, fname,
146 pblob->data, pblob->length, 0);
153 DEBUG(5, ("store_acl_blob_pathname: setting attr failed "
154 "for file %s with error %s\n",
157 return map_nt_error_from_unix(errno);
162 /*********************************************************************
163 Remove a Windows ACL - we're setting the underlying POSIX ACL.
164 *********************************************************************/
166 static int sys_acl_set_file_xattr(vfs_handle_struct *handle,
171 int ret = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle,
180 SMB_VFS_REMOVEXATTR(handle->conn, name, XATTR_NTACL_NAME);
186 /*********************************************************************
187 Remove a Windows ACL - we're setting the underlying POSIX ACL.
188 *********************************************************************/
190 static int sys_acl_set_fd_xattr(vfs_handle_struct *handle,
194 int ret = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle,
202 SMB_VFS_FREMOVEXATTR(fsp, XATTR_NTACL_NAME);
209 static struct vfs_fn_pointers vfs_acl_xattr_fns = {
210 .mkdir = mkdir_acl_common,
211 .open = open_acl_common,
212 .fget_nt_acl = fget_nt_acl_common,
213 .get_nt_acl = get_nt_acl_common,
214 .fset_nt_acl = fset_nt_acl_common,
215 .sys_acl_set_file = sys_acl_set_file_xattr,
216 .sys_acl_set_fd = sys_acl_set_fd_xattr
219 NTSTATUS vfs_acl_xattr_init(void)
221 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "acl_xattr",