]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
VFS: NULL dirfsp for openat on stream opens
authorVolker Lendecke <vl@samba.org>
Tue, 14 Jun 2022 14:33:57 +0000 (16:33 +0200)
committerRalph Boehme <slow@samba.org>
Mon, 25 Jul 2022 12:04:33 +0000 (12:04 +0000)
The main optimization is to avoid non_widelink_open() for streams
opens based on the fact that all streams opens are relative to
fsp->base_fsp, which is a pathref fsp already.

Neither streams_xattr nor streams_depot referenced dirfsp for the
streams case. Make this more obvious in the callers by passing NULL
and asserting this: non-streams opens and streams opens are just
different things, streams-opens can and do reference a base fsp and
don't need the non_widelink_open logic.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/modules/vfs_fruit.c
source3/modules/vfs_streams_depot.c
source3/modules/vfs_streams_xattr.c
source3/smbd/files.c
source3/smbd/open.c
source3/torture/cmd_vfs.c

index 05ab8fcea69edb1078448e2d3c24b490cda76053..685c15bcaa70f82506c8b1f537671b85834978d1 100644 (file)
@@ -2666,7 +2666,7 @@ static ssize_t fruit_pwrite_meta_stream(vfs_handle_struct *handle,
                }
 
                fd = SMB_VFS_NEXT_OPENAT(handle,
-                                        fsp->conn->cwd_fsp,
+                                        NULL, /* opening a stream */
                                         fsp->fsp_name,
                                         fsp,
                                         fio->flags,
index 107543f6bbce7dc9885ad2c52b467a5996d23463..6722d712bff5af436817894727a2673980b518ba 100644 (file)
@@ -684,6 +684,7 @@ static int streams_depot_openat(struct vfs_handle_struct *handle,
        }
 
        SMB_ASSERT(fsp_is_alternate_stream(fsp));
+       SMB_ASSERT(dirfsp == NULL);
        SMB_ASSERT(VALID_STAT(fsp->base_fsp->fsp_name->st));
 
        create_it = (mode & O_CREAT);
index 3e39770bb378091f4752b2b3e4e562224a650693..dd6892614495694b44116526063997e3d29d1609 100644 (file)
@@ -344,6 +344,7 @@ static int streams_xattr_openat(struct vfs_handle_struct *handle,
        }
 
        SMB_ASSERT(fsp_is_alternate_stream(fsp));
+       SMB_ASSERT(dirfsp == NULL);
 
        status = streams_xattr_get_name(handle, talloc_tos(),
                                        smb_fname->stream_name, &xattr_name);
index c96605555691b92d3b3c5b211831edaab2489031..d6ce87cc5fb6e6756b7c4a6b8e665c8c4aad6f93 100644 (file)
@@ -667,7 +667,7 @@ NTSTATUS open_stream_pathref_fsp(
 
        fd = SMB_VFS_OPENAT(
                conn,
-               dirfsp,
+               NULL,   /* stream open is relative to fsp->base_fsp */
                smb_fname,
                fsp,
                O_RDONLY|O_NONBLOCK|O_NOFOLLOW,
index 8cb349d78b0d3a77020e670b30c97393b49f162b..ce9b43fa072f4c90f208874078ba627a9a7a07d6 100644 (file)
@@ -937,6 +937,35 @@ NTSTATUS fd_openat(const struct files_struct *dirfsp,
                flags |= O_NOFOLLOW;
        }
 
+       if (fsp_is_alternate_stream(fsp)) {
+               int fd;
+
+               SMB_ASSERT(is_named_stream(smb_fname));
+
+               fd = SMB_VFS_OPENAT(
+                       conn,
+                       NULL,   /* stream open is relative to fsp->base_fsp */
+                       smb_fname,
+                       fsp,
+                       flags,
+                       mode);
+               if (fd == -1) {
+                       status = map_nt_error_from_unix(errno);
+               }
+               fsp_set_fd(fsp, fd);
+
+               if (fd != -1) {
+                       status = vfs_stat_fsp(fsp);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               DBG_DEBUG("vfs_stat_fsp failed: %s\n",
+                                         nt_errstr(status));
+                               fd_close(fsp);
+                       }
+               }
+
+               return status;
+       }
+
        /*
         * Only follow symlinks within a share
         * definition.
index b27eca87ab49c816ba8a35626ae41769a0a11933..dab458de69e7d7499751e289a1a8408f1ecdca83 100644 (file)
@@ -418,6 +418,8 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
                        goto fail;
                }
 
+               TALLOC_FREE(fspcwd);
+
                fsp->base_fsp = base_name->fsp;
        }