]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Simplify smb2_parse_file_rename_information()
authorVolker Lendecke <vl@samba.org>
Fri, 26 Sep 2025 08:25:42 +0000 (10:25 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 21 Oct 2025 17:33:29 +0000 (17:33 +0000)
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 <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/proto.h
source3/smbd/smb2_setinfo.c
source3/smbd/smb2_trans2.c

index 41baa76c86601b2ec3b5f952b4b30896bb4c44af..f764b30b6439562c3097bca04cb374f345ecd93a 100644 (file)
@@ -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  */
 
index ffa6b4a6a9e350aa3d625b831e967565fa248959..f66ad34baa9315391a49ca05fceee977770f5790 100644 (file)
@@ -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;
        }
index ffdafa104700462c28ed26c908b566d6732cc569..e2e7f3af9df5bfde17913c929405d0d812c6001d 100644 (file)
@@ -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;
 }