From: Samuel Cabrero Date: Wed, 8 Oct 2025 11:18:44 +0000 (+0200) Subject: smbd: Refactor reopen_from_fsp(), factor out name based reopen X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc0a6a3a69b1ac09e4b8981b1bde851e3d55d5ed;p=thirdparty%2Fsamba.git smbd: Refactor reopen_from_fsp(), factor out name based reopen BUG: https://bugzilla.samba.org/show_bug.cgi?id=15805 Signed-off-by: Samuel Cabrero Reviewed-by: Ralph Boehme --- diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 5294d0c9c9d..9751aba0c52 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -845,6 +845,33 @@ static NTSTATUS fd_open_atomic(struct files_struct *dirfsp, return status; } +/* + * Close the existing pathref fd and set the fsp flag + * is_pathref to false so we get a "normal" fd this time. + */ +static NTSTATUS reopen_from_fsp_namebased(struct files_struct *dirfsp, + struct smb_filename *smb_fname, + struct files_struct *fsp, + const struct vfs_open_how *how, + bool *p_file_created) +{ + NTSTATUS status; + + status = fd_close(fsp); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + fsp->fsp_flags.is_pathref = false; + + status = fd_open_atomic(dirfsp, + smb_fname, + fsp, + how, + p_file_created); + return status; +} + NTSTATUS reopen_from_fsp(struct files_struct *dirfsp, struct smb_filename *smb_fname, struct files_struct *fsp, @@ -894,7 +921,12 @@ NTSTATUS reopen_from_fsp(struct files_struct *dirfsp, * point we get ENOENT. We * have to retry pathbased. */ - goto namebased_open; + return reopen_from_fsp_namebased(dirfsp, + smb_fname, + fsp, + how, + p_file_created); + } /* restore ENOENT if changed in the meantime */ errno = ENOENT; @@ -914,22 +946,11 @@ NTSTATUS reopen_from_fsp(struct files_struct *dirfsp, return NT_STATUS_OK; } -#if defined(HAVE_FSTATFS) && defined(HAVE_LINUX_MAGIC_H) -namebased_open: -#endif - /* - * Close the existing pathref fd and set the fsp flag - * is_pathref to false so we get a "normal" fd this time. - */ - status = fd_close(fsp); - if (!NT_STATUS_IS_OK(status)) { - return status; - } - - fsp->fsp_flags.is_pathref = false; - - status = fd_open_atomic(dirfsp, smb_fname, fsp, how, p_file_created); - return status; + return reopen_from_fsp_namebased(dirfsp, + smb_fname, + fsp, + how, + p_file_created); } /****************************************************************************