From: Volker Lendecke Date: Fri, 26 Sep 2025 08:25:42 +0000 (+0200) Subject: smbd: Simplify smb2_parse_file_rename_information() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5312ba310838e8ed3125a081e0afc0758ccd7879;p=thirdparty%2Fsamba.git smbd: Simplify smb2_parse_file_rename_information() The caller in smb2_file_rename_information() does not need the dst_dirfsp, factor out the filename_convert_dirfsp() code. Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 41baa76c866..f764b30b643 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -1137,18 +1137,15 @@ NTSTATUS smb_set_fsquota(connection_struct *conn, files_struct *fsp, const DATA_BLOB *qdata); -NTSTATUS smb2_parse_file_rename_information( - TALLOC_CTX *ctx, - struct connection_struct *conn, - struct smb_request *req, - const char *pdata, - int total_data, - files_struct *fsp, - struct smb_filename *smb_fname_src, - char **_newname, - bool *overwrite, - struct files_struct **_dst_dirfsp, - struct smb_filename **_smb_fname_dst); +NTSTATUS smb2_parse_file_rename_information(TALLOC_CTX *ctx, + struct connection_struct *conn, + struct smb_request *req, + const char *pdata, + int total_data, + files_struct *fsp, + struct smb_filename *smb_fname_src, + char **_newname, + bool *overwrite); /* The following definitions come from smbd/uid.c */ diff --git a/source3/smbd/smb2_setinfo.c b/source3/smbd/smb2_setinfo.c index ffa6b4a6a9e..f66ad34baa9 100644 --- a/source3/smbd/smb2_setinfo.c +++ b/source3/smbd/smb2_setinfo.c @@ -392,6 +392,79 @@ static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx, return tevent_req_post(req, ev); } +static NTSTATUS smb2_parse_file_rename_information_dst( + TALLOC_CTX *mem_ctx, + struct connection_struct *conn, + struct smb_request *req, + const char *pdata, + int total_data, + files_struct *fsp, + struct smb_filename *smb_fname_src, + char **_newname, + bool *_overwrite, + struct files_struct **_dst_dirfsp, + struct smb_filename **_smb_fname_dst) +{ + char *newname = NULL; + bool overwrite = false; + struct files_struct *dst_dirfsp = NULL; + struct smb_filename *smb_fname_dst = NULL; + uint32_t ucf_flags = ucf_flags_from_smb_request(req); + NTSTATUS status; + + status = smb2_parse_file_rename_information(mem_ctx, + conn, + req, + pdata, + total_data, + fsp, + smb_fname_src, + &newname, + &overwrite); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + /* SMB2 rename paths are never DFS. */ + req->flags2 &= ~FLAGS2_DFS_PATHNAMES; + ucf_flags &= ~UCF_DFS_PATHNAME; + + if (newname[0] == ':') { + /* Create an smb_fname to call rename_internals_fsp() with. */ + smb_fname_dst = synthetic_smb_fname( + mem_ctx, + fsp->base_fsp->fsp_name->base_name, + newname, + NULL, + fsp->base_fsp->fsp_name->twrp, + fsp->base_fsp->fsp_name->flags); + if (smb_fname_dst == NULL) { + TALLOC_FREE(newname); + return NT_STATUS_NO_MEMORY; + } + goto done; + } + + status = filename_convert_dirfsp(mem_ctx, + conn, + newname, + ucf_flags, + 0, /* Never a TWRP. */ + &dst_dirfsp, + &smb_fname_dst); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + +done: + *_newname = newname; + *_overwrite = overwrite; + *_dst_dirfsp = dst_dirfsp; + *_smb_fname_dst = smb_fname_dst; + return NT_STATUS_OK; +} + + static void smbd_smb2_setinfo_lease_break_fsp_check(struct tevent_req *req); static void smbd_smb2_setinfo_lease_break_fsp_done(struct tevent_req *subreq); static void smbd_smb2_setinfo_rename_dst_check(struct tevent_req *req); @@ -594,17 +667,18 @@ static void smbd_smb2_setinfo_rename_dst_check(struct tevent_req *req) return; } - status = smb2_parse_file_rename_information(state, - fsp->conn, - state->smb2req->smb1req, - (char *)state->data.data, - state->data.length, - fsp, - fsp->fsp_name, - &newname, - &overwrite, - &dst_dirfsp, - &smb_fname_dst); + status = smb2_parse_file_rename_information_dst( + state, + fsp->conn, + state->smb2req->smb1req, + (char *)state->data.data, + state->data.length, + fsp, + fsp->fsp_name, + &newname, + &overwrite, + &dst_dirfsp, + &smb_fname_dst); if (tevent_req_nterror(req, status)) { return; } @@ -805,17 +879,18 @@ static void smbd_smb2_setinfo_rename_dst_parent_check(struct tevent_req *req) if (is_named_stream(fsp->fsp_name)) { return; } - status = smb2_parse_file_rename_information(state, - fsp->conn, - state->smb2req->smb1req, - (char *)state->data.data, - state->data.length, - fsp, - fsp->fsp_name, - &newname, - &overwrite, - &dst_parent_dirfsp, - &smb_fname_dst); + status = smb2_parse_file_rename_information_dst( + state, + fsp->conn, + state->smb2req->smb1req, + (char *)state->data.data, + state->data.length, + fsp, + fsp->fsp_name, + &newname, + &overwrite, + &dst_parent_dirfsp, + &smb_fname_dst); if (tevent_req_nterror(req, status)) { return; } diff --git a/source3/smbd/smb2_trans2.c b/source3/smbd/smb2_trans2.c index ffdafa10470..e2e7f3af9df 100644 --- a/source3/smbd/smb2_trans2.c +++ b/source3/smbd/smb2_trans2.c @@ -4237,23 +4237,17 @@ static NTSTATUS smb_file_mode_information(connection_struct *conn, Deal with SMB2_FILE_RENAME_INFORMATION_INTERNAL ****************************************************************************/ -NTSTATUS smb2_parse_file_rename_information( - TALLOC_CTX *ctx, - struct connection_struct *conn, - struct smb_request *req, - const char *pdata, - int total_data, - files_struct *fsp, - struct smb_filename *smb_fname_src, - char **_newname, - bool *_overwrite, - struct files_struct **_dst_dirfsp, - struct smb_filename **_smb_fname_dst) +NTSTATUS smb2_parse_file_rename_information(TALLOC_CTX *ctx, + struct connection_struct *conn, + struct smb_request *req, + const char *pdata, + int total_data, + files_struct *fsp, + struct smb_filename *smb_fname_src, + char **_newname, + bool *_overwrite) { char *newname = NULL; - struct files_struct *dst_dirfsp = NULL; - struct smb_filename *smb_fname_dst = NULL; - uint32_t ucf_flags = ucf_flags_from_smb_request(req); bool overwrite = false; uint32_t len; NTSTATUS status; @@ -4285,10 +4279,6 @@ NTSTATUS smb2_parse_file_rename_information( return NT_STATUS_INVALID_PARAMETER; } - /* SMB2 rename paths are never DFS. */ - req->flags2 &= ~FLAGS2_DFS_PATHNAMES; - ucf_flags &= ~UCF_DFS_PATHNAME; - status = check_path_syntax(newname, fsp->fsp_name->flags & SMB_FILENAME_POSIX_PATH); if (!NT_STATUS_IS_OK(status)) { @@ -4298,37 +4288,8 @@ NTSTATUS smb2_parse_file_rename_information( DBG_DEBUG("got name |%s|\n", newname); - if (newname[0] == ':') { - /* Create an smb_fname to call rename_internals_fsp() with. */ - smb_fname_dst = synthetic_smb_fname(talloc_tos(), - fsp->base_fsp->fsp_name->base_name, - newname, - NULL, - fsp->base_fsp->fsp_name->twrp, - fsp->base_fsp->fsp_name->flags); - if (smb_fname_dst == NULL) { - TALLOC_FREE(newname); - return NT_STATUS_NO_MEMORY; - } - goto done; - } - - status = filename_convert_dirfsp(ctx, - conn, - newname, - ucf_flags, - 0, /* Never a TWRP. */ - &dst_dirfsp, - &smb_fname_dst); - if (!NT_STATUS_IS_OK(status)) { - return status; - } - -done: *_newname = newname; *_overwrite = overwrite; - *_dst_dirfsp = dst_dirfsp; - *_smb_fname_dst = smb_fname_dst; return NT_STATUS_OK; } @@ -4344,8 +4305,6 @@ static NTSTATUS smb2_file_rename_information(connection_struct *conn, bool overwrite; struct smb_filename *smb_fname_src_parent = NULL; struct smb_filename *smb_fname_src_rel = NULL; - struct files_struct *dst_dirfsp = NULL; - struct smb_filename *smb_fname_dst = NULL; NTSTATUS status = NT_STATUS_OK; TALLOC_CTX *ctx = talloc_tos(); @@ -4357,9 +4316,7 @@ static NTSTATUS smb2_file_rename_information(connection_struct *conn, fsp, smb_fname_src, &newname, - &overwrite, - &dst_dirfsp, - &smb_fname_dst); + &overwrite); if (!NT_STATUS_IS_OK(status)) { return status; } @@ -4367,7 +4324,7 @@ static NTSTATUS smb2_file_rename_information(connection_struct *conn, DBG_DEBUG("SMB_FILE_RENAME_INFORMATION (%s) %s -> %s\n", fsp_fnum_dbg(fsp), fsp_str_dbg(fsp), - smb_fname_str_dbg(smb_fname_dst)); + newname); status = parent_pathref(talloc_tos(), conn->cwd_fsp, @@ -4390,7 +4347,6 @@ static NTSTATUS smb2_file_rename_information(connection_struct *conn, TALLOC_FREE(smb_fname_src_rel); TALLOC_FREE(smb_fname_src_parent); - TALLOC_FREE(smb_fname_dst); return status; }