From a771f1d314bc41b59a279b1859ed28714bed3040 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 20 May 2022 08:06:28 +0200 Subject: [PATCH] smbd: Simplify copy_file() Pass in new_create_disposition directly. We can also remove the if-case (ofun & OPENX_FILE_EXISTS_OPEN) in copy_file, the two callers don't use it. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/modules/vfs_fruit.c | 2 +- source3/printing/nt_printing.c | 3 +-- source3/smbd/proto.h | 2 +- source3/smbd/smb2_reply.c | 25 +------------------------ 4 files changed, 4 insertions(+), 28 deletions(-) diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c index dba09cc462c..05ab8fcea69 100644 --- a/source3/modules/vfs_fruit.c +++ b/source3/modules/vfs_fruit.c @@ -4781,7 +4781,7 @@ static void fruit_offload_write_done(struct tevent_req *subreq) state->handle->conn, src_fname_tmp, dst_fname_tmp, - OPENX_FILE_CREATE_IF_NOT_EXIST); + FILE_CREATE); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("%s: copy %s to %s failed: %s\n", __func__, smb_fname_str_dbg(src_fname_tmp), diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index 85517406852..0929e532436 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -1460,8 +1460,7 @@ static WERROR move_driver_file_to_download_area(TALLOC_CTX *mem_ctx, smb_fname_new->base_name)); status = copy_file(mem_ctx, conn, smb_fname_old, smb_fname_new, - OPENX_FILE_EXISTS_TRUNCATE | - OPENX_FILE_CREATE_IF_NOT_EXIST); + FILE_OVERWRITE_IF); if (!NT_STATUS_IS_OK(status)) { DEBUG(0,("move_driver_file_to_download_area: Unable " diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 28591a17e38..9917562d1de 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -988,7 +988,7 @@ NTSTATUS copy_file(TALLOC_CTX *ctx, connection_struct *conn, struct smb_filename *smb_fname_src, struct smb_filename *smb_fname_dst, - int ofun); + uint32_t new_create_disposition); uint64_t get_lock_offset(const uint8_t *data, int data_offset, bool large_file_format); diff --git a/source3/smbd/smb2_reply.c b/source3/smbd/smb2_reply.c index 6c2876fa80f..673c1e2216b 100644 --- a/source3/smbd/smb2_reply.c +++ b/source3/smbd/smb2_reply.c @@ -1836,13 +1836,12 @@ NTSTATUS copy_file(TALLOC_CTX *ctx, connection_struct *conn, struct smb_filename *smb_fname_src, struct smb_filename *smb_fname_dst, - int ofun) + uint32_t new_create_disposition) { struct smb_filename *smb_fname_dst_tmp = NULL; off_t ret=-1; files_struct *fsp1,*fsp2; uint32_t dosattrs; - uint32_t new_create_disposition; NTSTATUS status; @@ -1861,16 +1860,6 @@ NTSTATUS copy_file(TALLOC_CTX *ctx, goto out; } - if (!map_open_params_to_ntcreate(smb_fname_dst_tmp->base_name, - 0, ofun, - NULL, NULL, - &new_create_disposition, - NULL, - NULL)) { - status = NT_STATUS_INVALID_PARAMETER; - goto out; - } - /* Open the src file for reading. */ status = SMB_VFS_CREATE_FILE( conn, /* conn */ @@ -1935,18 +1924,6 @@ NTSTATUS copy_file(TALLOC_CTX *ctx, goto out; } - if (ofun & OPENX_FILE_EXISTS_OPEN) { - ret = SMB_VFS_LSEEK(fsp2, 0, SEEK_END); - if (ret == -1) { - DEBUG(0, ("error - vfs lseek returned error %s\n", - strerror(errno))); - status = map_nt_error_from_unix(errno); - close_file_free(NULL, &fsp1, ERROR_CLOSE); - close_file_free(NULL, &fsp2, ERROR_CLOSE); - goto out; - } - } - /* Do the actual copy. */ if (smb_fname_src->st.st_ex_size) { ret = vfs_transfer_file(fsp1, fsp2, smb_fname_src->st.st_ex_size); -- 2.11.4.GIT