]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Inline dup_file_fsp() into fcb_or_dos_open()
authorVolker Lendecke <vl@samba.org>
Thu, 10 Oct 2024 14:34:50 +0000 (16:34 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 12 Nov 2024 18:07:33 +0000 (18:07 +0000)
Only used once, an not really complex

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

index c75d9168fbcb6ec031aad2c8e033916febbbb159..a5a9a3aa42d8955c7feccb536d7482a2f07337da 100644 (file)
@@ -2412,52 +2412,6 @@ struct files_struct *file_fsp_smb2(struct smbd_smb2_request *smb2req,
        return fsp;
 }
 
-/****************************************************************************
- Duplicate the file handle part for a DOS or FCB open.
-****************************************************************************/
-
-NTSTATUS dup_file_fsp(
-       files_struct *from,
-       uint32_t access_mask,
-       files_struct *to)
-{
-       size_t new_refcount;
-
-       /* this can never happen for print files */
-       SMB_ASSERT(from->print_file == NULL);
-
-       TALLOC_FREE(to->fh);
-
-       to->fh = from->fh;
-       new_refcount = fh_get_refcount(to->fh) + 1;
-       fh_set_refcount(to->fh, new_refcount);
-
-       to->file_id = from->file_id;
-       to->initial_allocation_size = from->initial_allocation_size;
-       to->file_pid = from->file_pid;
-       to->vuid = from->vuid;
-       to->open_time = from->open_time;
-       to->access_mask = access_mask;
-       to->oplock_type = from->oplock_type;
-       to->fsp_flags.can_lock = from->fsp_flags.can_lock;
-       to->fsp_flags.can_read = ((access_mask & FILE_READ_DATA) != 0);
-       to->fsp_flags.can_write =
-               CAN_WRITE(from->conn) &&
-               ((access_mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) != 0);
-       if (from->fsp_name->twrp != 0) {
-               to->fsp_flags.can_write = false;
-       }
-       to->fsp_flags.modified = from->fsp_flags.modified;
-       to->fsp_flags.is_directory = from->fsp_flags.is_directory;
-       to->fsp_flags.aio_write_behind = from->fsp_flags.aio_write_behind;
-       to->fsp_flags.is_fsa = from->fsp_flags.is_fsa;
-       to->fsp_flags.is_pathref = from->fsp_flags.is_pathref;
-       to->fsp_flags.have_proc_fds = from->fsp_flags.have_proc_fds;
-       to->fsp_flags.is_dirfsp = from->fsp_flags.is_dirfsp;
-
-       return fsp_set_smb_fname(to, from->fsp_name);
-}
-
 /**
  * Return a jenkins hash of a pathname on a connection.
  */
index 702756c6e312665cac367d6fc61c368c7d7d5a56..03e33babcbf636e4b3000e0d35484fb7a9e4819f 100644 (file)
@@ -344,10 +344,6 @@ struct files_struct *file_fsp_get(struct smbd_smb2_request *smb2req,
 struct files_struct *file_fsp_smb2(struct smbd_smb2_request *smb2req,
                                   uint64_t persistent_id,
                                   uint64_t volatile_id);
-NTSTATUS dup_file_fsp(
-       files_struct *from,
-       uint32_t access_mask,
-       files_struct *to);
 NTSTATUS file_name_hash(connection_struct *conn,
                        const char *name, uint32_t *p_name_hash);
 NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
index bdd842c504fd3c6b553a668902114dc6f737891a..d5b6c9ba4526c636d7b5d685060d322c565dc8c4 100644 (file)
@@ -41,6 +41,7 @@ struct files_struct *fcb_or_dos_open(
        struct connection_struct *conn = req->conn;
        struct file_id id = vfs_file_id_from_sbuf(conn, &smb_fname->st);
        struct files_struct *fsp = NULL, *new_fsp = NULL;
+       size_t new_refcount;
        NTSTATUS status;
 
        if ((private_flags &
@@ -97,10 +98,35 @@ struct files_struct *fcb_or_dos_open(
                return NULL;
        }
 
-       status = dup_file_fsp(fsp, access_mask, new_fsp);
+       /*
+        * Share the fsp->fh between old and new
+        */
+       TALLOC_FREE(new_fsp->fh);
+       new_fsp->fh = fsp->fh;
+       new_refcount = fh_get_refcount(new_fsp->fh) + 1;
+       fh_set_refcount(new_fsp->fh, new_refcount);
+
+       new_fsp->file_id = fsp->file_id;
+       new_fsp->initial_allocation_size = fsp->initial_allocation_size;
+       new_fsp->file_pid = fsp->file_pid;
+       new_fsp->vuid = fsp->vuid;
+       new_fsp->open_time = fsp->open_time;
+       new_fsp->access_mask = access_mask;
+       new_fsp->oplock_type = fsp->oplock_type;
+       new_fsp->fsp_flags = fsp->fsp_flags;
+       new_fsp->fsp_flags.can_read = ((access_mask & FILE_READ_DATA) != 0);
+       new_fsp->fsp_flags.can_write = CAN_WRITE(fsp->conn) &&
+                                      ((access_mask & (FILE_WRITE_DATA |
+                                                       FILE_APPEND_DATA)) !=
+                                       0);
+       if (fsp->fsp_name->twrp != 0) {
+               new_fsp->fsp_flags.can_write = false;
+       }
+
+       status = fsp_set_smb_fname(new_fsp, fsp->fsp_name);
 
        if (!NT_STATUS_IS_OK(status)) {
-               DBG_DEBUG("dup_file_fsp failed: %s\n", nt_errstr(status));
+               DBG_DEBUG("fsp_set_smb_fname failed: %s\n", nt_errstr(status));
                file_free(req, new_fsp);
                return NULL;
        }