smbd: open_stream_pathref_fsp() does not need a dirfsp
authorVolker Lendecke <vl@samba.org>
Mon, 13 Jun 2022 15:31:16 +0000 (17:31 +0200)
committerRalph Boehme <slow@samba.org>
Mon, 25 Jul 2022 12:04:33 +0000 (12:04 +0000)
It opens relative to fsp->base_fsp

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/filename.c
source3/smbd/files.c
source3/smbd/proto.h

index 7042503eee156d0dc1152eecd3ae2453ef36b1f4..e24fd69874449419e6354d85d873199a3eee328d 100644 (file)
@@ -2834,8 +2834,7 @@ NTSTATUS filename_convert_dirfsp(
 
        smb_fname_rel->stream_name = saved_streamname;
 
-       status = open_stream_pathref_fsp(
-               smb_dirname->fsp, &base_fsp, smb_fname_rel);
+       status = open_stream_pathref_fsp(&base_fsp, smb_fname_rel);
 
        if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND) &&
            !conn->case_sensitive) {
@@ -2851,7 +2850,7 @@ NTSTATUS filename_convert_dirfsp(
                        smb_fname_rel->stream_name = found;
                        found = NULL;
                        status = open_stream_pathref_fsp(
-                               smb_dirname->fsp, &base_fsp, smb_fname_rel);
+                               &base_fsp, smb_fname_rel);
                }
        }
 
index 84ac80851f4c1ef266e03d69a3008c63f9628d90..46207bd7c90351af8977b02f59224d857e93fbce 100644 (file)
@@ -603,7 +603,7 @@ NTSTATUS openat_pathref_fsp(const struct files_struct *dirfsp,
                goto fail;
        }
 
-       status = open_stream_pathref_fsp(dirfsp, &base_fname->fsp, smb_fname);
+       status = open_stream_pathref_fsp(&base_fname->fsp, smb_fname);
        if (!NT_STATUS_IS_OK(status)) {
                DBG_DEBUG("open_stream_pathref_fsp failed: %s\n",
                          nt_errstr(status));
@@ -622,20 +622,19 @@ fail:
  * valid non-cwd_fsp dirfsp that we can pass to SMB_VFS_OPENAT()
  */
 NTSTATUS open_stream_pathref_fsp(
-       const struct files_struct *dirfsp,
        struct files_struct **_base_fsp,
        struct smb_filename *smb_fname)
 {
-       connection_struct *conn = dirfsp->conn;
+       struct files_struct *base_fsp = *_base_fsp;
+       connection_struct *conn = base_fsp->conn;
+       struct smb_filename *base_fname = base_fsp->fsp_name;
        struct smb_filename *full_fname = NULL;
        struct files_struct *fsp = NULL;
        int ret, fd;
        NTSTATUS status;
 
        SMB_ASSERT(smb_fname->fsp == NULL);
-       SMB_ASSERT(*_base_fsp != NULL);
        SMB_ASSERT(is_named_stream(smb_fname));
-       SMB_ASSERT(dirfsp != conn->cwd_fsp);
 
        status = fsp_new(conn, conn, &fsp);
        if (!NT_STATUS_IS_OK(status)) {
@@ -648,7 +647,13 @@ NTSTATUS open_stream_pathref_fsp(
 
        fsp->fsp_flags.is_pathref = true;
 
-       full_fname = full_path_from_dirfsp_atname(fsp, dirfsp, smb_fname);
+       full_fname = synthetic_smb_fname(
+               fsp,
+               base_fname->base_name,
+               smb_fname->stream_name,
+               &smb_fname->st,
+               smb_fname->twrp,
+               smb_fname->flags);
        if (full_fname == NULL) {
                status = NT_STATUS_NO_MEMORY;
                goto fail;
@@ -663,8 +668,7 @@ NTSTATUS open_stream_pathref_fsp(
 
        /*
         * non_widelink_open() not required: See the asserts above,
-        * this will only open the stream relative to
-        * dirfsp!=conn->cwd_fsp and fsp->base_fsp!=NULL.
+        * this will only open the stream relative to.
         */
 
        fd = SMB_VFS_OPENAT(
index 64653976e22f67db85459a7dca8a9e6605c63d51..cddfb6eac78448f9e69fc1ac012a39086f93e834 100644 (file)
@@ -458,7 +458,6 @@ NTSTATUS openat_internal_dir_from_pathref(
 NTSTATUS openat_pathref_fsp(const struct files_struct *dirfsp,
                            struct smb_filename *smb_fname);
 NTSTATUS open_stream_pathref_fsp(
-       const struct files_struct *dirfsp,
        struct files_struct **_base_fsp,
        struct smb_filename *smb_fname);