vfs_default: implement pathref opens in vfswrap_openat()
authorRalph Boehme <slow@samba.org>
Fri, 9 Oct 2020 12:24:43 +0000 (14:24 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 16 Dec 2020 09:08:30 +0000 (09:08 +0000)
If the system supports O_PATH we use that, otherwise we fallback to root opens.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/vfs_default.c

index c8325cbe6331be2226bf07c95ed17c817dfdcbe0..074de0960c05417d7bfe5242f3a2598a987dcd27 100644 (file)
@@ -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;