From eb1f945ab52271207124f1907c7b02b198caa039 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 9 Jun 2021 15:57:38 -0700 Subject: [PATCH 1/2] s3: VFS: default: Add proc_fd's fallback for vfswrap_fchown(). https://bugzilla.samba.org/show_bug.cgi?id=14734 Signed-off-by: Jeremy Allison Reviewed-by: Noel Power Autobuild-User(master): Noel Power Autobuild-Date(master): Thu Jun 10 09:16:22 UTC 2021 on sn-devel-184 (cherry picked from commit f44918e6c83c89936156eb24c982a897c9c45f61) --- source3/modules/vfs_default.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 8d592bbad64..9c45bae749f 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -2453,7 +2453,31 @@ static int vfswrap_fchown(vfs_handle_struct *handle, files_struct *fsp, uid_t ui int result; START_PROFILE(syscall_fchown); - result = fchown(fsp_get_io_fd(fsp), uid, gid); + if (!fsp->fsp_flags.is_pathref) { + result = fchown(fsp_get_io_fd(fsp), uid, gid); + END_PROFILE(syscall_fchown); + return result; + } + + if (fsp->fsp_flags.have_proc_fds) { + int fd = fsp_get_pathref_fd(fsp); + const char *p = NULL; + char buf[PATH_MAX]; + + p = sys_proc_fd_path(fd, buf, sizeof(buf)); + if (p != NULL) { + result = chown(p, uid, gid); + } else { + result = -1; + } + END_PROFILE(syscall_fchown); + return result; + } + + /* + * This is no longer a handle based call. + */ + result = chown(fsp->fsp_name->base_name, uid, gid); END_PROFILE(syscall_fchown); return result; #else -- 2.27.0 From 04e19e614c45f2eb3df8fef9b02de3b8164da79e Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Fri, 9 Apr 2021 14:58:34 +0200 Subject: [PATCH 2/2] s3/modules: fchmod: fallback to path based chmod if pathref BUG: https://bugzilla.samba.org/show_bug.cgi?id=14734 Signed-off-by: Noel Power Signed-off-by: Ralph Boehme Back-ported from master commit 6ad10836d6e04d8c95773e9122b63f5a5e040487) --- source3/modules/vfs_default.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 9c45bae749f..b32ab7f5267 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -2436,12 +2436,32 @@ static int vfswrap_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t m int result; START_PROFILE(syscall_fchmod); -#if defined(HAVE_FCHMOD) - result = fchmod(fsp_get_io_fd(fsp), mode); -#else - result = -1; - errno = ENOSYS; -#endif + + if (!fsp->fsp_flags.is_pathref) { + result = fchmod(fsp_get_io_fd(fsp), mode); + END_PROFILE(syscall_fchmod); + return result; + } + + if (fsp->fsp_flags.have_proc_fds) { + int fd = fsp_get_pathref_fd(fsp); + const char *p = NULL; + char buf[PATH_MAX]; + + p = sys_proc_fd_path(fd, buf, sizeof(buf)); + if (p != NULL) { + result = chmod(p, mode); + } else { + result = -1; + } + END_PROFILE(syscall_fchmod); + return result; + } + + /* + * This is no longer a handle based call. + */ + result = chmod(fsp->fsp_name->base_name, mode); END_PROFILE(syscall_fchmod); return result; -- 2.27.0