From: Ralph Boehme Date: Fri, 9 Oct 2020 12:24:43 +0000 (+0200) Subject: vfs_default: implement pathref opens in vfswrap_openat() X-Git-Tag: samba-4.14.0rc1~389 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cf3c48cb08811e45b6d88a4c27b873485321beb0;p=thirdparty%2Fsamba.git 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 --- 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;