2 Unix SMB/CIFS implementation.
4 POSIX NTVFS backend - NT ACLs in xattrs
6 Copyright (C) Andrew Tridgell 2006
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "vfs_posix.h"
24 #include "lib/util/unix_privs.h"
25 #include "librpc/gen_ndr/ndr_xattr.h"
28 load the current ACL from extended attributes
30 static NTSTATUS pvfs_acl_load_xattr(struct pvfs_state *pvfs, struct pvfs_filename *name, int fd,
32 struct security_descriptor **sd)
35 struct xattr_NTACL *acl;
37 if (!(pvfs->flags & PVFS_FLAG_XATTR_ENABLE)) {
38 return NT_STATUS_NOT_FOUND;
41 acl = talloc_zero(mem_ctx, struct xattr_NTACL);
42 NT_STATUS_HAVE_NO_MEMORY(acl);
44 status = pvfs_xattr_ndr_load(pvfs, mem_ctx, name->full_name, fd,
47 (ndr_pull_flags_fn_t)ndr_pull_xattr_NTACL);
49 if (!NT_STATUS_IS_OK(status)) {
54 if (acl->version != 1) {
56 return NT_STATUS_INVALID_ACL;
59 *sd = talloc_steal(mem_ctx, acl->info.sd);
65 save the acl for a file into filesystem xattr
67 static NTSTATUS pvfs_acl_save_xattr(struct pvfs_state *pvfs, struct pvfs_filename *name, int fd,
68 struct security_descriptor *sd)
72 struct xattr_NTACL acl;
74 if (!(pvfs->flags & PVFS_FLAG_XATTR_ENABLE)) {
81 /* this xattr is in the "system" namespace, so we need
82 admin privileges to set it */
83 privs = root_privileges();
84 status = pvfs_xattr_ndr_save(pvfs, name->full_name, fd,
87 (ndr_push_flags_fn_t)ndr_push_xattr_NTACL);
94 initialise pvfs acl xattr backend
96 NTSTATUS pvfs_acl_xattr_init(void)
98 struct pvfs_acl_ops ops = {
100 .acl_load = pvfs_acl_load_xattr,
101 .acl_save = pvfs_acl_save_xattr
103 return pvfs_acl_register(&ops);