]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: add move_smb_fname_fsp_link()
authorRalph Boehme <slow@samba.org>
Mon, 23 Nov 2020 05:00:40 +0000 (06:00 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 16 Dec 2020 09:08:30 +0000 (09:08 +0000)
Function to move fsps from one smb_fname to another.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/files.c
source3/smbd/proto.h

index e69a910e1f8e1ae68316b6eac8189c4996910083..350a2bf85e0ec148129e844f4ff3162d694dd0d2 100644 (file)
@@ -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.
 ****************************************************************************/
index c79f4814f1e45b22d52ab96f5c42704a182099eb..9f9ceb1f110a3d78da8d6b1788632bb10ca7d25b 100644 (file)
@@ -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);