From: Ralph Boehme Date: Mon, 23 Nov 2020 05:00:40 +0000 (+0100) Subject: smbd: add move_smb_fname_fsp_link() X-Git-Tag: samba-4.14.0rc1~368 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=994f88909dfb7bde4381d547d37f4422ed3d77e2;p=thirdparty%2Fsamba.git smbd: add move_smb_fname_fsp_link() Function to move fsps from one smb_fname to another. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/files.c b/source3/smbd/files.c index e69a910e1f8..350a2bf85e0 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -560,6 +560,35 @@ void smb_fname_fsp_unlink(struct smb_filename *smb_fname) destroy_fsp_smb_fname_link(&smb_fname->fsp_link); } +/* + * Move any existing embedded fsp refs from the src name to the + * destination. It's safe to call this on src smb_fname's that have no embedded + * pathref fsp. + */ +NTSTATUS move_smb_fname_fsp_link(struct smb_filename *smb_fname_dst, + struct smb_filename *smb_fname_src) +{ + NTSTATUS status; + + if (smb_fname_src->fsp == NULL) { + return NT_STATUS_OK; + } + + smb_fname_dst->fsp = smb_fname_src->fsp; + talloc_set_destructor(smb_fname_dst, smb_fname_fsp_destructor); + + smb_fname_fsp_unlink(smb_fname_src); + + status = fsp_smb_fname_link(smb_fname_dst->fsp, + &smb_fname_dst->fsp_link, + &smb_fname_dst->fsp); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + return NT_STATUS_OK; +} + /**************************************************************************** Close all open files for a connection. ****************************************************************************/ diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index c79f4814f1e..9f9ceb1f110 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -460,6 +460,9 @@ NTSTATUS openat_pathref_fsp(const struct files_struct *dirfsp, void smb_fname_fsp_unlink(struct smb_filename *smb_fname); +NTSTATUS move_smb_fname_fsp_link(struct smb_filename *smb_fname_dst, + struct smb_filename *smb_fname_src); + /* The following definitions come from smbd/ipc.c */ NTSTATUS nt_status_np_pipe(NTSTATUS status);