From cf3c48cb08811e45b6d88a4c27b873485321beb0 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Fri, 9 Oct 2020 14:24:43 +0200 Subject: [PATCH] vfs_default: implement pathref opens in vfswrap_openat() If the system supports O_PATH we use that, otherwise we fallback to root opens. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- source3/modules/vfs_default.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index c8325cbe633..074de0960c0 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -693,6 +693,8 @@ static int vfswrap_openat(vfs_handle_struct *handle, int flags, mode_t mode) { + bool have_opath = false; + bool became_root = false; int result; START_PROFILE(syscall_openat); @@ -703,11 +705,29 @@ static int vfswrap_openat(vfs_handle_struct *handle, goto out; } +#ifdef O_PATH + have_opath = true; + if (fsp->fsp_flags.is_pathref) { + flags |= O_PATH; + } +#endif + + if (fsp->fsp_flags.is_pathref && !have_opath) { + become_root(); + became_root = true; + } + result = openat(fsp_get_pathref_fd(dirfsp), smb_fname->base_name, flags, mode); + if (became_root) { + unbecome_root(); + } + + fsp->fsp_flags.have_proc_fds = fsp->conn->have_proc_fds; + out: END_PROFILE(syscall_openat); return result; -- 2.47.3