From 3ab6a9a9bf2cadee2930a3a4bf0685c901a7ee5d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 10 Oct 2024 16:34:50 +0200 Subject: [PATCH] smbd: Inline dup_file_fsp() into fcb_or_dos_open() Only used once, an not really complex Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- source3/smbd/files.c | 46 --------------------------------------- source3/smbd/proto.h | 4 ---- source3/smbd/smb1_utils.c | 30 +++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 52 deletions(-) diff --git a/source3/smbd/files.c b/source3/smbd/files.c index c75d9168fbc..a5a9a3aa42d 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -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. */ diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 702756c6e31..03e33babcbf 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -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, diff --git a/source3/smbd/smb1_utils.c b/source3/smbd/smb1_utils.c index bdd842c504f..d5b6c9ba452 100644 --- a/source3/smbd/smb1_utils.c +++ b/source3/smbd/smb1_utils.c @@ -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; } -- 2.47.2