2 Unix SMB/CIFS implementation.
4 POSIX NTVFS backend - ACL support
6 Copyright (C) Andrew Tridgell 2004
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "auth/auth.h"
25 #include "system/filesys.h"
26 #include "vfs_posix.h"
27 #include "librpc/gen_ndr/ndr_xattr.h"
31 setup a default ACL for a file
33 static NTSTATUS pvfs_default_acl(struct pvfs_state *pvfs,
34 struct smbsrv_request *req,
35 struct pvfs_filename *name, int fd,
36 struct xattr_NTACL *acl)
38 struct security_descriptor *sd;
40 struct security_ace ace;
42 const char *sid_names[] = {
43 SID_BUILTIN_ADMINISTRATORS,
48 uint32_t access_masks[4];
51 sd = security_descriptor_initialise(req);
53 return NT_STATUS_NO_MEMORY;
56 status = sidmap_uid_to_sid(pvfs->sidmap, sd, name->st.st_uid, &sd->owner_sid);
57 if (!NT_STATUS_IS_OK(status)) {
60 status = sidmap_gid_to_sid(pvfs->sidmap, sd, name->st.st_gid, &sd->group_sid);
61 if (!NT_STATUS_IS_OK(status)) {
65 sd->type |= SEC_DESC_DACL_PRESENT;
74 access_masks[0] = SEC_RIGHTS_FULL_CTRL | STD_RIGHT_ALL_ACCESS;
79 mode = name->st.st_mode;
83 SA_RIGHT_FILE_READ_DATA |
84 SA_RIGHT_FILE_READ_EA |
85 SA_RIGHT_FILE_READ_ATTRIBUTES |
86 SA_RIGHT_FILE_EXECUTE;
90 SA_RIGHT_FILE_WRITE_DATA |
91 SA_RIGHT_FILE_APPEND_DATA |
92 SA_RIGHT_FILE_WRITE_EA |
93 SA_RIGHT_FILE_DELETE_CHILD |
94 SA_RIGHT_FILE_WRITE_ATTRIBUTES;
99 SA_RIGHT_FILE_READ_DATA |
100 SA_RIGHT_FILE_READ_EA |
101 SA_RIGHT_FILE_READ_ATTRIBUTES |
102 SA_RIGHT_FILE_EXECUTE;
104 if (mode & S_IWGRP) {
106 SA_RIGHT_FILE_WRITE_DATA |
107 SA_RIGHT_FILE_APPEND_DATA |
108 SA_RIGHT_FILE_WRITE_EA |
109 SA_RIGHT_FILE_DELETE_CHILD |
110 SA_RIGHT_FILE_WRITE_ATTRIBUTES;
113 if (mode & S_IROTH) {
115 SA_RIGHT_FILE_READ_DATA |
116 SA_RIGHT_FILE_READ_EA |
117 SA_RIGHT_FILE_READ_ATTRIBUTES |
118 SA_RIGHT_FILE_EXECUTE;
120 if (mode & S_IWOTH) {
122 SA_RIGHT_FILE_WRITE_DATA |
123 SA_RIGHT_FILE_APPEND_DATA |
124 SA_RIGHT_FILE_WRITE_EA |
125 SA_RIGHT_FILE_DELETE_CHILD |
126 SA_RIGHT_FILE_WRITE_ATTRIBUTES;
129 ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
132 for (i=0;i<ARRAY_SIZE(sid_names);i++) {
135 ace.access_mask = access_masks[i];
137 sid = dom_sid_parse_talloc(sd, sid_names[i]);
139 return NT_STATUS_NO_MEMORY;
143 status = security_descriptor_dacl_add(sd, &ace);
144 if (!NT_STATUS_IS_OK(status)) {
157 omit any security_descriptor elements not specified in the given
160 static void normalise_sd_flags(struct security_descriptor *sd, uint32_t secinfo_flags)
162 if (!(secinfo_flags & OWNER_SECURITY_INFORMATION)) {
163 sd->owner_sid = NULL;
165 if (!(secinfo_flags & GROUP_SECURITY_INFORMATION)) {
166 sd->group_sid = NULL;
168 if (!(secinfo_flags & DACL_SECURITY_INFORMATION)) {
171 if (!(secinfo_flags & SACL_SECURITY_INFORMATION)) {
177 answer a setfileinfo for an ACL
179 NTSTATUS pvfs_acl_set(struct pvfs_state *pvfs,
180 struct smbsrv_request *req,
181 struct pvfs_filename *name, int fd,
182 union smb_setfileinfo *info)
184 struct xattr_NTACL *acl;
185 uint32_t secinfo_flags = info->set_secdesc.in.secinfo_flags;
186 struct security_descriptor *new_sd, *sd;
189 acl = talloc_p(req, struct xattr_NTACL);
191 return NT_STATUS_NO_MEMORY;
194 status = pvfs_acl_load(pvfs, name, fd, acl);
195 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
196 status = pvfs_default_acl(pvfs, req, name, fd, acl);
198 if (!NT_STATUS_IS_OK(status)) {
202 switch (acl->version) {
207 return NT_STATUS_INVALID_LEVEL;
210 new_sd = info->set_secdesc.in.sd;
212 /* only set the elements that have been specified */
213 if (secinfo_flags & OWNER_SECURITY_INFORMATION) {
214 sd->owner_sid = new_sd->owner_sid;
216 if (secinfo_flags & GROUP_SECURITY_INFORMATION) {
217 sd->group_sid = new_sd->group_sid;
219 if (secinfo_flags & DACL_SECURITY_INFORMATION) {
220 sd->dacl = new_sd->dacl;
222 if (secinfo_flags & SACL_SECURITY_INFORMATION) {
223 sd->sacl = new_sd->sacl;
226 status = pvfs_acl_save(pvfs, name, fd, acl);
233 answer a fileinfo query for the ACL
235 NTSTATUS pvfs_acl_query(struct pvfs_state *pvfs,
236 struct smbsrv_request *req,
237 struct pvfs_filename *name, int fd,
238 union smb_fileinfo *info)
240 struct xattr_NTACL *acl;
242 struct security_descriptor *sd;
244 acl = talloc_p(req, struct xattr_NTACL);
246 return NT_STATUS_NO_MEMORY;
249 status = pvfs_acl_load(pvfs, name, fd, acl);
250 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
251 status = pvfs_default_acl(pvfs, req, name, fd, acl);
253 if (!NT_STATUS_IS_OK(status)) {
257 switch (acl->version) {
262 return NT_STATUS_INVALID_LEVEL;
265 normalise_sd_flags(sd, info->query_secdesc.in.secinfo_flags);
267 info->query_secdesc.out.sd = sd;