]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: VFS: cap: Use real dirfsp for SMB_VFS_RENAMEAT()
authorJeremy Allison <jra@samba.org>
Thu, 17 Jun 2021 00:52:07 +0000 (17:52 -0700)
committerNoel Power <npower@samba.org>
Tue, 22 Jun 2021 13:44:34 +0000 (13:44 +0000)
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
source3/modules/vfs_cap.c

index 27805858530b2d1b39026e35ec81f51c7f69ba21..3bb3d5d9d5e66a7ced08b1123fd3d377b39a2ecb 100644 (file)
@@ -203,22 +203,41 @@ static int cap_renameat(vfs_handle_struct *handle,
        char *capnew = NULL;
        struct smb_filename *smb_fname_src_tmp = NULL;
        struct smb_filename *smb_fname_dst_tmp = NULL;
+       struct smb_filename *full_fname_src = NULL;
+       struct smb_filename *full_fname_dst = NULL;
        int ret = -1;
+       int saved_errno = 0;
+
+       full_fname_src = full_path_from_dirfsp_atname(talloc_tos(),
+                                                 srcfsp,
+                                                 smb_fname_src);
+       if (full_fname_src == NULL) {
+               errno = ENOMEM;
+               goto out;
+       }
+
+       full_fname_dst = full_path_from_dirfsp_atname(talloc_tos(),
+                                                 dstfsp,
+                                                 smb_fname_dst);
+       if (full_fname_dst == NULL) {
+               errno = ENOMEM;
+               goto out;
+       }
 
-       capold = capencode(talloc_tos(), smb_fname_src->base_name);
-       capnew = capencode(talloc_tos(), smb_fname_dst->base_name);
+       capold = capencode(talloc_tos(), full_fname_src->base_name);
+       capnew = capencode(talloc_tos(), full_fname_dst->base_name);
        if (!capold || !capnew) {
                errno = ENOMEM;
                goto out;
        }
 
        /* Setup temporary smb_filename structs. */
-       smb_fname_src_tmp = cp_smb_filename(talloc_tos(), smb_fname_src);
+       smb_fname_src_tmp = cp_smb_filename(talloc_tos(), full_fname_src);
        if (smb_fname_src_tmp == NULL) {
                errno = ENOMEM;
                goto out;
        }
-       smb_fname_dst_tmp = cp_smb_filename(talloc_tos(), smb_fname_dst);
+       smb_fname_dst_tmp = cp_smb_filename(talloc_tos(), full_fname_dst);
        if (smb_fname_dst_tmp == NULL) {
                errno = ENOMEM;
                goto out;
@@ -228,17 +247,28 @@ static int cap_renameat(vfs_handle_struct *handle,
        smb_fname_dst_tmp->base_name = capnew;
 
        ret = SMB_VFS_NEXT_RENAMEAT(handle,
-                               srcfsp,
+                               srcfsp->conn->cwd_fsp,
                                smb_fname_src_tmp,
-                               dstfsp,
+                               dstfsp->conn->cwd_fsp,
                                smb_fname_dst_tmp);
 
  out:
+
+       if (ret != 0) {
+               saved_errno = errno;
+       }
+
+       TALLOC_FREE(full_fname_src);
+       TALLOC_FREE(full_fname_dst);
        TALLOC_FREE(capold);
        TALLOC_FREE(capnew);
        TALLOC_FREE(smb_fname_src_tmp);
        TALLOC_FREE(smb_fname_dst_tmp);
 
+       if (ret != 0) {
+               errno = saved_errno;
+       }
+
        return ret;
 }