From fe8b4617ddc1663d57ab5b0ffdeedb413e19a506 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 7 Aug 2024 13:14:23 +0200 Subject: [PATCH] s3:vfs_default: implement VFS_RENAME_HOW_NO_REPLACE in vfswrap_renameat() We can use renameat2() without ifdef as libreplace always provides it. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15693 Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- source3/modules/vfs_default.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index ec46596ac62..5922aba3e8a 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -1291,22 +1291,28 @@ static int vfswrap_renameat(vfs_handle_struct *handle, const struct vfs_rename_how *how) { int result = -1; + int flags = 0; START_PROFILE(syscall_renameat); SMB_ASSERT(!is_named_stream(smb_fname_src)); SMB_ASSERT(!is_named_stream(smb_fname_dst)); - if (how->flags != 0) { + if (how->flags & ~VFS_RENAME_HOW_NO_REPLACE) { END_PROFILE(syscall_renameat); errno = EINVAL; return -1; } - result = renameat(fsp_get_pathref_fd(srcfsp), - smb_fname_src->base_name, - fsp_get_pathref_fd(dstfsp), - smb_fname_dst->base_name); + if (how->flags & VFS_RENAME_HOW_NO_REPLACE) { + flags |= RENAME_NOREPLACE; + } + + result = renameat2(fsp_get_pathref_fd(srcfsp), + smb_fname_src->base_name, + fsp_get_pathref_fd(dstfsp), + smb_fname_dst->base_name, + flags); END_PROFILE(syscall_renameat); return result;