From 06bfac2125da5e4d37a596d1213912f0c698e69e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 28 Mar 2022 18:39:55 -0700 Subject: [PATCH] s3: smbd: Preserve the fsp->fsp_name->st buf across a MSG_SMB_FILE_RENAME message. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG: https://bugzilla.samba.org/show_bug.cgi?id=15038 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme Autobuild-User(master): Ralph Böhme Autobuild-Date(master): Wed Mar 30 15:07:09 UTC 2022 on sn-devel-184 --- source3/smbd/open.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 9e792a23132..00d8f414c3a 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -4887,16 +4887,36 @@ void msg_file_was_renamed(struct messaging_context *msg_ctx, } if (strcmp(fsp->conn->connectpath, msg->servicepath) == 0) { + SMB_STRUCT_STAT fsp_orig_sbuf; NTSTATUS status; DBG_DEBUG("renaming file %s from %s -> %s\n", fsp_fnum_dbg(fsp), fsp_str_dbg(fsp), smb_fname_str_dbg(smb_fname)); + + /* + * The incoming smb_fname here has an + * invalid stat struct from synthetic_smb_fname() + * above. + * Preserve the existing stat from the + * open fsp after fsp_set_smb_fname() + * overwrites with the invalid stat. + * + * (We could just copy this into + * smb_fname->st, but keep this code + * identical to the fix in rename_open_files() + * for clarity. + * + * We will do an fstat before returning + * any of this metadata to the client anyway. + */ + fsp_orig_sbuf = fsp->fsp_name->st; status = fsp_set_smb_fname(fsp, smb_fname); if (!NT_STATUS_IS_OK(status)) { DBG_DEBUG("fsp_set_smb_fname failed: %s\n", nt_errstr(status)); } + fsp->fsp_name->st = fsp_orig_sbuf; } else { /* TODO. JRA. */ /*