Fix bug #8807 - dcerpc_lsa_lookup_sids_noalloc() crashes when groups has more than...
[Samba/gebeck_regimport.git] / source3 / modules / vfs_acl_common.c
blobca303d376e5ac8a736d77118612053279a5611cb
1 /*
2 * Store Windows ACLs in data store - common functions.
3 * #included into modules/vfs_acl_xattr.c and modules/vfs_acl_tdb.c
5 * Copyright (C) Volker Lendecke, 2008
6 * Copyright (C) Jeremy Allison, 2009
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/>.
22 #include "smbd/smbd.h"
23 #include "system/filesys.h"
24 #include "../libcli/security/security.h"
25 #include "../librpc/gen_ndr/ndr_security.h"
26 #include "../lib/util/bitmap.h"
28 static NTSTATUS create_acl_blob(const struct security_descriptor *psd,
29 DATA_BLOB *pblob,
30 uint16_t hash_type,
31 uint8_t hash[XATTR_SD_HASH_SIZE]);
33 static NTSTATUS get_acl_blob(TALLOC_CTX *ctx,
34 vfs_handle_struct *handle,
35 files_struct *fsp,
36 const char *name,
37 DATA_BLOB *pblob);
39 static NTSTATUS store_acl_blob_fsp(vfs_handle_struct *handle,
40 files_struct *fsp,
41 DATA_BLOB *pblob);
43 #define HASH_SECURITY_INFO (SECINFO_OWNER | \
44 SECINFO_GROUP | \
45 SECINFO_DACL | \
46 SECINFO_SACL)
48 /*******************************************************************
49 Hash a security descriptor.
50 *******************************************************************/
52 static NTSTATUS hash_sd_sha256(struct security_descriptor *psd,
53 uint8_t *hash)
55 DATA_BLOB blob;
56 SHA256_CTX tctx;
57 NTSTATUS status;
59 memset(hash, '\0', XATTR_SD_HASH_SIZE);
60 status = create_acl_blob(psd, &blob, XATTR_SD_HASH_TYPE_SHA256, hash);
61 if (!NT_STATUS_IS_OK(status)) {
62 return status;
65 samba_SHA256_Init(&tctx);
66 samba_SHA256_Update(&tctx, blob.data, blob.length);
67 samba_SHA256_Final(hash, &tctx);
69 return NT_STATUS_OK;
72 /*******************************************************************
73 Parse out a struct security_descriptor from a DATA_BLOB.
74 *******************************************************************/
76 static NTSTATUS parse_acl_blob(const DATA_BLOB *pblob,
77 struct security_descriptor **ppdesc,
78 uint16_t *p_hash_type,
79 uint8_t hash[XATTR_SD_HASH_SIZE])
81 TALLOC_CTX *ctx = talloc_tos();
82 struct xattr_NTACL xacl;
83 enum ndr_err_code ndr_err;
84 size_t sd_size;
86 ndr_err = ndr_pull_struct_blob(pblob, ctx, &xacl,
87 (ndr_pull_flags_fn_t)ndr_pull_xattr_NTACL);
89 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
90 DEBUG(5, ("parse_acl_blob: ndr_pull_xattr_NTACL failed: %s\n",
91 ndr_errstr(ndr_err)));
92 return ndr_map_error2ntstatus(ndr_err);
95 switch (xacl.version) {
96 case 1:
97 *ppdesc = make_sec_desc(ctx, SD_REVISION,
98 xacl.info.sd->type | SEC_DESC_SELF_RELATIVE,
99 xacl.info.sd->owner_sid,
100 xacl.info.sd->group_sid,
101 xacl.info.sd->sacl,
102 xacl.info.sd->dacl,
103 &sd_size);
104 /* No hash - null out. */
105 *p_hash_type = XATTR_SD_HASH_TYPE_NONE;
106 memset(hash, '\0', XATTR_SD_HASH_SIZE);
107 break;
108 case 2:
109 *ppdesc = make_sec_desc(ctx, SD_REVISION,
110 xacl.info.sd_hs2->sd->type | SEC_DESC_SELF_RELATIVE,
111 xacl.info.sd_hs2->sd->owner_sid,
112 xacl.info.sd_hs2->sd->group_sid,
113 xacl.info.sd_hs2->sd->sacl,
114 xacl.info.sd_hs2->sd->dacl,
115 &sd_size);
116 /* No hash - null out. */
117 *p_hash_type = XATTR_SD_HASH_TYPE_NONE;
118 memset(hash, '\0', XATTR_SD_HASH_SIZE);
119 break;
120 case 3:
121 *ppdesc = make_sec_desc(ctx, SD_REVISION,
122 xacl.info.sd_hs3->sd->type | SEC_DESC_SELF_RELATIVE,
123 xacl.info.sd_hs3->sd->owner_sid,
124 xacl.info.sd_hs3->sd->group_sid,
125 xacl.info.sd_hs3->sd->sacl,
126 xacl.info.sd_hs3->sd->dacl,
127 &sd_size);
128 *p_hash_type = xacl.info.sd_hs3->hash_type;
129 /* Current version 3. */
130 memcpy(hash, xacl.info.sd_hs3->hash, XATTR_SD_HASH_SIZE);
131 break;
132 default:
133 return NT_STATUS_REVISION_MISMATCH;
136 TALLOC_FREE(xacl.info.sd);
138 return (*ppdesc != NULL) ? NT_STATUS_OK : NT_STATUS_NO_MEMORY;
141 /*******************************************************************
142 Create a DATA_BLOB from a security descriptor.
143 *******************************************************************/
145 static NTSTATUS create_acl_blob(const struct security_descriptor *psd,
146 DATA_BLOB *pblob,
147 uint16_t hash_type,
148 uint8_t hash[XATTR_SD_HASH_SIZE])
150 struct xattr_NTACL xacl;
151 struct security_descriptor_hash_v3 sd_hs3;
152 enum ndr_err_code ndr_err;
153 TALLOC_CTX *ctx = talloc_tos();
155 ZERO_STRUCT(xacl);
156 ZERO_STRUCT(sd_hs3);
158 xacl.version = 3;
159 xacl.info.sd_hs3 = &sd_hs3;
160 xacl.info.sd_hs3->sd = discard_const_p(struct security_descriptor, psd);
161 xacl.info.sd_hs3->hash_type = hash_type;
162 memcpy(&xacl.info.sd_hs3->hash[0], hash, XATTR_SD_HASH_SIZE);
164 ndr_err = ndr_push_struct_blob(
165 pblob, ctx, &xacl,
166 (ndr_push_flags_fn_t)ndr_push_xattr_NTACL);
168 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
169 DEBUG(5, ("create_acl_blob: ndr_push_xattr_NTACL failed: %s\n",
170 ndr_errstr(ndr_err)));
171 return ndr_map_error2ntstatus(ndr_err);
174 return NT_STATUS_OK;
177 /*******************************************************************
178 Add in 3 inheritable components for a non-inheritable directory ACL.
179 CREATOR_OWNER/CREATOR_GROUP/WORLD.
180 *******************************************************************/
182 static void add_directory_inheritable_components(vfs_handle_struct *handle,
183 const char *name,
184 SMB_STRUCT_STAT *psbuf,
185 struct security_descriptor *psd)
187 struct connection_struct *conn = handle->conn;
188 int num_aces = (psd->dacl ? psd->dacl->num_aces : 0);
189 struct smb_filename smb_fname;
190 enum security_ace_type acltype;
191 uint32_t access_mask;
192 mode_t dir_mode;
193 mode_t file_mode;
194 mode_t mode;
195 struct security_ace *new_ace_list = talloc_zero_array(talloc_tos(),
196 struct security_ace,
197 num_aces + 3);
199 if (new_ace_list == NULL) {
200 return;
203 /* Fake a quick smb_filename. */
204 ZERO_STRUCT(smb_fname);
205 smb_fname.st = *psbuf;
206 smb_fname.base_name = discard_const_p(char, name);
208 dir_mode = unix_mode(conn,
209 FILE_ATTRIBUTE_DIRECTORY, &smb_fname, NULL);
210 file_mode = unix_mode(conn,
211 FILE_ATTRIBUTE_ARCHIVE, &smb_fname, NULL);
213 mode = dir_mode | file_mode;
215 DEBUG(10, ("add_directory_inheritable_components: directory %s, "
216 "mode = 0%o\n",
217 name,
218 (unsigned int)mode ));
220 if (num_aces) {
221 memcpy(new_ace_list, psd->dacl->aces,
222 num_aces * sizeof(struct security_ace));
224 access_mask = map_canon_ace_perms(SNUM(conn), &acltype,
225 mode & 0700, false);
227 init_sec_ace(&new_ace_list[num_aces],
228 &global_sid_Creator_Owner,
229 acltype,
230 access_mask,
231 SEC_ACE_FLAG_CONTAINER_INHERIT|
232 SEC_ACE_FLAG_OBJECT_INHERIT|
233 SEC_ACE_FLAG_INHERIT_ONLY);
234 access_mask = map_canon_ace_perms(SNUM(conn), &acltype,
235 (mode << 3) & 0700, false);
236 init_sec_ace(&new_ace_list[num_aces+1],
237 &global_sid_Creator_Group,
238 acltype,
239 access_mask,
240 SEC_ACE_FLAG_CONTAINER_INHERIT|
241 SEC_ACE_FLAG_OBJECT_INHERIT|
242 SEC_ACE_FLAG_INHERIT_ONLY);
243 access_mask = map_canon_ace_perms(SNUM(conn), &acltype,
244 (mode << 6) & 0700, false);
245 init_sec_ace(&new_ace_list[num_aces+2],
246 &global_sid_World,
247 acltype,
248 access_mask,
249 SEC_ACE_FLAG_CONTAINER_INHERIT|
250 SEC_ACE_FLAG_OBJECT_INHERIT|
251 SEC_ACE_FLAG_INHERIT_ONLY);
252 psd->dacl->aces = new_ace_list;
253 psd->dacl->num_aces += 3;
256 /*******************************************************************
257 Pull a DATA_BLOB from an xattr given a pathname.
258 If the hash doesn't match, or doesn't exist - return the underlying
259 filesystem sd.
260 *******************************************************************/
262 static NTSTATUS get_nt_acl_internal(vfs_handle_struct *handle,
263 files_struct *fsp,
264 const char *name,
265 uint32_t security_info,
266 struct security_descriptor **ppdesc)
268 DATA_BLOB blob = data_blob_null;
269 NTSTATUS status;
270 uint16_t hash_type = XATTR_SD_HASH_TYPE_NONE;
271 uint8_t hash[XATTR_SD_HASH_SIZE];
272 uint8_t hash_tmp[XATTR_SD_HASH_SIZE];
273 struct security_descriptor *psd = NULL;
274 struct security_descriptor *pdesc_next = NULL;
275 bool ignore_file_system_acl = lp_parm_bool(SNUM(handle->conn),
276 ACL_MODULE_NAME,
277 "ignore system acls",
278 false);
280 if (fsp && name == NULL) {
281 name = fsp->fsp_name->base_name;
284 DEBUG(10, ("get_nt_acl_internal: name=%s\n", name));
286 /* Get the full underlying sd for the hash
287 or to return as backup. */
288 if (fsp) {
289 status = SMB_VFS_NEXT_FGET_NT_ACL(handle,
290 fsp,
291 HASH_SECURITY_INFO,
292 &pdesc_next);
293 } else {
294 status = SMB_VFS_NEXT_GET_NT_ACL(handle,
295 name,
296 HASH_SECURITY_INFO,
297 &pdesc_next);
300 if (!NT_STATUS_IS_OK(status)) {
301 DEBUG(10, ("get_nt_acl_internal: get_next_acl for file %s "
302 "returned %s\n",
303 name,
304 nt_errstr(status)));
305 return status;
308 status = get_acl_blob(talloc_tos(), handle, fsp, name, &blob);
309 if (!NT_STATUS_IS_OK(status)) {
310 DEBUG(10, ("get_nt_acl_internal: get_acl_blob returned %s\n",
311 nt_errstr(status)));
312 psd = pdesc_next;
313 goto out;
316 status = parse_acl_blob(&blob, &psd,
317 &hash_type, &hash[0]);
318 if (!NT_STATUS_IS_OK(status)) {
319 DEBUG(10, ("parse_acl_blob returned %s\n",
320 nt_errstr(status)));
321 psd = pdesc_next;
322 goto out;
325 /* Ensure the hash type is one we know. */
326 switch (hash_type) {
327 case XATTR_SD_HASH_TYPE_NONE:
328 /* No hash, just return blob sd. */
329 goto out;
330 case XATTR_SD_HASH_TYPE_SHA256:
331 break;
332 default:
333 DEBUG(10, ("get_nt_acl_internal: ACL blob revision "
334 "mismatch (%u) for file %s\n",
335 (unsigned int)hash_type,
336 name));
337 TALLOC_FREE(psd);
338 psd = pdesc_next;
339 goto out;
342 if (ignore_file_system_acl) {
343 goto out;
346 status = hash_sd_sha256(pdesc_next, hash_tmp);
347 if (!NT_STATUS_IS_OK(status)) {
348 TALLOC_FREE(psd);
349 psd = pdesc_next;
350 goto out;
353 if (memcmp(&hash[0], &hash_tmp[0], XATTR_SD_HASH_SIZE) == 0) {
354 /* Hash matches, return blob sd. */
355 DEBUG(10, ("get_nt_acl_internal: blob hash "
356 "matches for file %s\n",
357 name ));
358 goto out;
361 /* Hash doesn't match, return underlying sd. */
362 TALLOC_FREE(psd);
363 psd = pdesc_next;
365 out:
367 if (psd != pdesc_next) {
368 /* We're returning the blob, throw
369 * away the filesystem SD. */
370 TALLOC_FREE(pdesc_next);
371 } else {
372 SMB_STRUCT_STAT sbuf;
373 SMB_STRUCT_STAT *psbuf = &sbuf;
374 bool is_directory = false;
376 * We're returning the underlying ACL from the
377 * filesystem. If it's a directory, and has no
378 * inheritable ACE entries we have to fake them.
380 if (fsp) {
381 status = vfs_stat_fsp(fsp);
382 if (!NT_STATUS_IS_OK(status)) {
383 return status;
385 psbuf = &fsp->fsp_name->st;
386 } else {
387 int ret = vfs_stat_smb_fname(handle->conn,
388 name,
389 &sbuf);
390 if (ret == -1) {
391 return map_nt_error_from_unix(errno);
394 is_directory = S_ISDIR(psbuf->st_ex_mode);
396 if (ignore_file_system_acl) {
397 TALLOC_FREE(pdesc_next);
398 status = make_default_filesystem_acl(talloc_tos(),
399 name,
400 psbuf,
401 &psd);
402 if (!NT_STATUS_IS_OK(status)) {
403 return status;
405 } else {
406 if (is_directory &&
407 !sd_has_inheritable_components(psd,
408 true)) {
409 add_directory_inheritable_components(handle,
410 name,
411 psbuf,
412 psd);
414 /* The underlying POSIX module always sets
415 the ~SEC_DESC_DACL_PROTECTED bit, as ACLs
416 can't be inherited in this way under POSIX.
417 Remove it for Windows-style ACLs. */
418 psd->type &= ~SEC_DESC_DACL_PROTECTED;
422 if (!(security_info & SECINFO_OWNER)) {
423 psd->owner_sid = NULL;
425 if (!(security_info & SECINFO_GROUP)) {
426 psd->group_sid = NULL;
428 if (!(security_info & SECINFO_DACL)) {
429 psd->type &= ~SEC_DESC_DACL_PRESENT;
430 psd->dacl = NULL;
432 if (!(security_info & SECINFO_SACL)) {
433 psd->type &= ~SEC_DESC_SACL_PRESENT;
434 psd->sacl = NULL;
437 TALLOC_FREE(blob.data);
438 *ppdesc = psd;
440 if (DEBUGLEVEL >= 10) {
441 DEBUG(10,("get_nt_acl_internal: returning acl for %s is:\n",
442 name ));
443 NDR_PRINT_DEBUG(security_descriptor, psd);
446 return NT_STATUS_OK;
449 /*********************************************************************
450 Fetch a security descriptor given an fsp.
451 *********************************************************************/
453 static NTSTATUS fget_nt_acl_common(vfs_handle_struct *handle, files_struct *fsp,
454 uint32_t security_info, struct security_descriptor **ppdesc)
456 return get_nt_acl_internal(handle, fsp,
457 NULL, security_info, ppdesc);
460 /*********************************************************************
461 Fetch a security descriptor given a pathname.
462 *********************************************************************/
464 static NTSTATUS get_nt_acl_common(vfs_handle_struct *handle,
465 const char *name, uint32_t security_info, struct security_descriptor **ppdesc)
467 return get_nt_acl_internal(handle, NULL,
468 name, security_info, ppdesc);
471 /*********************************************************************
472 Store a security descriptor given an fsp.
473 *********************************************************************/
475 static NTSTATUS fset_nt_acl_common(vfs_handle_struct *handle, files_struct *fsp,
476 uint32_t security_info_sent, const struct security_descriptor *orig_psd)
478 NTSTATUS status;
479 DATA_BLOB blob;
480 struct security_descriptor *pdesc_next = NULL;
481 struct security_descriptor *psd = NULL;
482 uint8_t hash[XATTR_SD_HASH_SIZE];
483 bool chown_needed = false;
485 if (DEBUGLEVEL >= 10) {
486 DEBUG(10,("fset_nt_acl_xattr: incoming sd for file %s\n",
487 fsp_str_dbg(fsp)));
488 NDR_PRINT_DEBUG(security_descriptor,
489 discard_const_p(struct security_descriptor, orig_psd));
492 status = get_nt_acl_internal(handle, fsp,
493 NULL,
494 SECINFO_OWNER|SECINFO_GROUP|SECINFO_DACL|SECINFO_SACL,
495 &psd);
497 if (!NT_STATUS_IS_OK(status)) {
498 return status;
501 psd->revision = orig_psd->revision;
502 /* All our SD's are self relative. */
503 psd->type = orig_psd->type | SEC_DESC_SELF_RELATIVE;
505 if ((security_info_sent & SECINFO_OWNER) && (orig_psd->owner_sid != NULL)) {
506 if (!dom_sid_equal(orig_psd->owner_sid, psd->owner_sid)) {
507 /* We're changing the owner. */
508 chown_needed = true;
510 psd->owner_sid = orig_psd->owner_sid;
512 if ((security_info_sent & SECINFO_GROUP) && (orig_psd->group_sid != NULL)) {
513 if (!dom_sid_equal(orig_psd->group_sid, psd->group_sid)) {
514 /* We're changing the group. */
515 chown_needed = true;
517 psd->group_sid = orig_psd->group_sid;
519 if (security_info_sent & SECINFO_DACL) {
520 psd->dacl = orig_psd->dacl;
521 psd->type |= SEC_DESC_DACL_PRESENT;
523 if (security_info_sent & SECINFO_SACL) {
524 psd->sacl = orig_psd->sacl;
525 psd->type |= SEC_DESC_SACL_PRESENT;
528 status = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
529 if (!NT_STATUS_IS_OK(status)) {
530 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
531 return status;
533 /* We got access denied here. If we're already root,
534 or we didn't need to do a chown, or the fsp isn't
535 open with WRITE_OWNER access, just return. */
536 if (get_current_uid(handle->conn) == 0 ||
537 chown_needed == false ||
538 !(fsp->access_mask & SEC_STD_WRITE_OWNER)) {
539 return NT_STATUS_ACCESS_DENIED;
542 DEBUG(10,("fset_nt_acl_common: overriding chown on file %s "
543 "for sid %s\n",
544 fsp_str_dbg(fsp),
545 sid_string_tos(psd->owner_sid)
548 /* Ok, we failed to chown and we have
549 SEC_STD_WRITE_OWNER access - override. */
550 become_root();
551 status = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp,
552 security_info_sent, psd);
553 unbecome_root();
554 if (!NT_STATUS_IS_OK(status)) {
555 return status;
559 /* Get the full underlying sd, then hash. */
560 status = SMB_VFS_NEXT_FGET_NT_ACL(handle,
561 fsp,
562 HASH_SECURITY_INFO,
563 &pdesc_next);
565 if (!NT_STATUS_IS_OK(status)) {
566 return status;
569 status = hash_sd_sha256(pdesc_next, hash);
570 if (!NT_STATUS_IS_OK(status)) {
571 return status;
574 if (DEBUGLEVEL >= 10) {
575 DEBUG(10,("fset_nt_acl_xattr: storing xattr sd for file %s\n",
576 fsp_str_dbg(fsp)));
577 NDR_PRINT_DEBUG(security_descriptor,
578 discard_const_p(struct security_descriptor, psd));
580 create_acl_blob(psd, &blob, XATTR_SD_HASH_TYPE_SHA256, hash);
581 store_acl_blob_fsp(handle, fsp, &blob);
583 return NT_STATUS_OK;
586 static int acl_common_remove_object(vfs_handle_struct *handle,
587 const char *path,
588 bool is_directory)
590 connection_struct *conn = handle->conn;
591 struct file_id id;
592 files_struct *fsp = NULL;
593 int ret = 0;
594 char *parent_dir = NULL;
595 const char *final_component = NULL;
596 struct smb_filename local_fname;
597 int saved_errno = 0;
598 char *saved_dir = NULL;
600 saved_dir = vfs_GetWd(talloc_tos(),conn);
601 if (!saved_dir) {
602 saved_errno = errno;
603 goto out;
606 if (!parent_dirname(talloc_tos(), path,
607 &parent_dir, &final_component)) {
608 saved_errno = ENOMEM;
609 goto out;
612 DEBUG(10,("acl_common_remove_object: removing %s %s/%s\n",
613 is_directory ? "directory" : "file",
614 parent_dir, final_component ));
616 /* cd into the parent dir to pin it. */
617 ret = vfs_ChDir(conn, parent_dir);
618 if (ret == -1) {
619 saved_errno = errno;
620 goto out;
623 ZERO_STRUCT(local_fname);
624 local_fname.base_name = discard_const_p(char, final_component);
626 /* Must use lstat here. */
627 ret = SMB_VFS_LSTAT(conn, &local_fname);
628 if (ret == -1) {
629 saved_errno = errno;
630 goto out;
633 /* Ensure we have this file open with DELETE access. */
634 id = vfs_file_id_from_sbuf(conn, &local_fname.st);
635 for (fsp = file_find_di_first(conn->sconn, id); fsp;
636 fsp = file_find_di_next(fsp)) {
637 if (fsp->access_mask & DELETE_ACCESS &&
638 fsp->delete_on_close) {
639 /* We did open this for delete,
640 * allow the delete as root.
642 break;
646 if (!fsp) {
647 DEBUG(10,("acl_common_remove_object: %s %s/%s "
648 "not an open file\n",
649 is_directory ? "directory" : "file",
650 parent_dir, final_component ));
651 saved_errno = EACCES;
652 goto out;
655 become_root();
656 if (is_directory) {
657 ret = SMB_VFS_NEXT_RMDIR(handle, final_component);
658 } else {
659 ret = SMB_VFS_NEXT_UNLINK(handle, &local_fname);
661 unbecome_root();
663 if (ret == -1) {
664 saved_errno = errno;
667 out:
669 TALLOC_FREE(parent_dir);
671 if (saved_dir) {
672 vfs_ChDir(conn, saved_dir);
674 if (saved_errno) {
675 errno = saved_errno;
677 return ret;
680 static int rmdir_acl_common(struct vfs_handle_struct *handle,
681 const char *path)
683 int ret;
685 /* Try the normal rmdir first. */
686 ret = SMB_VFS_NEXT_RMDIR(handle, path);
687 if (ret == 0) {
688 return 0;
690 if (errno == EACCES || errno == EPERM) {
691 /* Failed due to access denied,
692 see if we need to root override. */
693 return acl_common_remove_object(handle,
694 path,
695 true);
698 DEBUG(10,("rmdir_acl_common: unlink of %s failed %s\n",
699 path,
700 strerror(errno) ));
701 return -1;
704 static int unlink_acl_common(struct vfs_handle_struct *handle,
705 const struct smb_filename *smb_fname)
707 int ret;
709 /* Try the normal unlink first. */
710 ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
711 if (ret == 0) {
712 return 0;
714 if (errno == EACCES || errno == EPERM) {
715 /* Failed due to access denied,
716 see if we need to root override. */
718 /* Don't do anything fancy for streams. */
719 if (smb_fname->stream_name) {
720 return -1;
722 return acl_common_remove_object(handle,
723 smb_fname->base_name,
724 false);
727 DEBUG(10,("unlink_acl_common: unlink of %s failed %s\n",
728 smb_fname->base_name,
729 strerror(errno) ));
730 return -1;
733 static int chmod_acl_module_common(struct vfs_handle_struct *handle,
734 const char *path, mode_t mode)
736 if (lp_posix_pathnames()) {
737 /* Only allow this on POSIX pathnames. */
738 return SMB_VFS_NEXT_CHMOD(handle, path, mode);
740 return 0;
743 static int fchmod_acl_module_common(struct vfs_handle_struct *handle,
744 struct files_struct *fsp, mode_t mode)
746 if (fsp->posix_open) {
747 /* Only allow this on POSIX opens. */
748 return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
750 return 0;
753 static int chmod_acl_acl_module_common(struct vfs_handle_struct *handle,
754 const char *name, mode_t mode)
756 if (lp_posix_pathnames()) {
757 /* Only allow this on POSIX pathnames. */
758 return SMB_VFS_NEXT_CHMOD_ACL(handle, name, mode);
760 return 0;
763 static int fchmod_acl_acl_module_common(struct vfs_handle_struct *handle,
764 struct files_struct *fsp, mode_t mode)
766 if (fsp->posix_open) {
767 /* Only allow this on POSIX opens. */
768 return SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
770 return 0;