]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Move smb_set_file_unix_hlink() to smb1_trans2.c
authorVolker Lendecke <vl@samba.org>
Thu, 29 Dec 2022 09:47:12 +0000 (10:47 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 4 Jan 2023 08:54:32 +0000 (08:54 +0000)
Most of this is direct cut&paste without reformatting.

Don't pass SMB_SET_FILE_UNIX_HLINK through smbd_do_setfilepathinfo(),
directly handle it in call_trans2setpathinfo() where we know we have a
path.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/smb1_trans2.c
source3/smbd/smb2_trans2.c

index 03eb0f18c37ad563aec5cb31e0992ad051ae2db6..8301ffbfba029962430a1262faf84d5a49405900 100644 (file)
@@ -3120,6 +3120,82 @@ static NTSTATUS smb_set_file_unix_link(connection_struct *conn,
        return NT_STATUS_OK;
 }
 
+/****************************************************************************
+ Deal with SMB_SET_FILE_UNIX_HLINK (create a UNIX hard link).
+****************************************************************************/
+
+static NTSTATUS smb_set_file_unix_hlink(connection_struct *conn,
+                                       struct smb_request *req,
+                                       const char *pdata, int total_data,
+                                       struct smb_filename *smb_fname_new)
+{
+       char *oldname = NULL;
+       struct files_struct *src_dirfsp = NULL;
+       struct smb_filename *smb_fname_old = NULL;
+       uint32_t ucf_flags = ucf_flags_from_smb_request(req);
+       NTTIME old_twrp = 0;
+       TALLOC_CTX *ctx = talloc_tos();
+       NTSTATUS status = NT_STATUS_OK;
+
+       if (!CAN_WRITE(conn)) {
+               return NT_STATUS_DOS(ERRSRV, ERRaccess);
+       }
+
+       /* Set a hard link. */
+       if (total_data == 0) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       if (req->posix_pathnames) {
+               srvstr_get_path_posix(ctx,
+                       pdata,
+                       req->flags2,
+                       &oldname,
+                       pdata,
+                       total_data,
+                       STR_TERMINATE,
+                       &status);
+       } else {
+               srvstr_get_path(ctx,
+                       pdata,
+                       req->flags2,
+                       &oldname,
+                       pdata,
+                       total_data,
+                       STR_TERMINATE,
+                       &status);
+       }
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       DEBUG(10,("smb_set_file_unix_hlink: SMB_SET_FILE_UNIX_LINK doing hard link %s -> %s\n",
+               smb_fname_str_dbg(smb_fname_new), oldname));
+
+       if (ucf_flags & UCF_GMT_PATHNAME) {
+               extract_snapshot_token(oldname, &old_twrp);
+       }
+       status = filename_convert_dirfsp(ctx,
+                                        conn,
+                                        oldname,
+                                        ucf_flags,
+                                        old_twrp,
+                                        &src_dirfsp,
+                                        &smb_fname_old);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       return hardlink_internals(ctx,
+                                 conn,
+                                 req,
+                                 false,
+                                 src_dirfsp,
+                                 smb_fname_old,
+                                 NULL, /* new_dirfsp */
+                                 smb_fname_new);
+}
+
 static void call_trans2setpathinfo(
        connection_struct *conn,
        struct smb_request *req,
@@ -3243,6 +3319,11 @@ static void call_trans2setpathinfo(
                status = smb_set_file_unix_link(
                        conn, req, *ppdata, total_data, smb_fname);
                break;
+
+       case SMB_SET_FILE_UNIX_HLINK:
+               status = smb_set_file_unix_hlink(
+                       conn, req, *ppdata, total_data, smb_fname);
+               break;
        }
 
        if (info_level_handled) {
index e6647a06d39636da408b32287902096e8846d459..d4a7125460520a1d4591489bb9c89f1b4ce9471e 100644 (file)
@@ -4946,78 +4946,6 @@ static NTSTATUS smb_file_mode_information(connection_struct *conn,
        return NT_STATUS_OK;
 }
 
-/****************************************************************************
- Deal with SMB_SET_FILE_UNIX_HLINK (create a UNIX hard link).
-****************************************************************************/
-
-static NTSTATUS smb_set_file_unix_hlink(connection_struct *conn,
-                                       struct smb_request *req,
-                                       const char *pdata, int total_data,
-                                       struct smb_filename *smb_fname_new)
-{
-       char *oldname = NULL;
-       struct files_struct *src_dirfsp = NULL;
-       struct smb_filename *smb_fname_old = NULL;
-       uint32_t ucf_flags = ucf_flags_from_smb_request(req);
-       NTTIME old_twrp = 0;
-       TALLOC_CTX *ctx = talloc_tos();
-       NTSTATUS status = NT_STATUS_OK;
-
-       /* Set a hard link. */
-       if (total_data == 0) {
-               return NT_STATUS_INVALID_PARAMETER;
-       }
-
-       if (req->posix_pathnames) {
-               srvstr_get_path_posix(ctx,
-                       pdata,
-                       req->flags2,
-                       &oldname,
-                       pdata,
-                       total_data,
-                       STR_TERMINATE,
-                       &status);
-       } else {
-               srvstr_get_path(ctx,
-                       pdata,
-                       req->flags2,
-                       &oldname,
-                       pdata,
-                       total_data,
-                       STR_TERMINATE,
-                       &status);
-       }
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
-       DEBUG(10,("smb_set_file_unix_hlink: SMB_SET_FILE_UNIX_LINK doing hard link %s -> %s\n",
-               smb_fname_str_dbg(smb_fname_new), oldname));
-
-       if (ucf_flags & UCF_GMT_PATHNAME) {
-               extract_snapshot_token(oldname, &old_twrp);
-       }
-       status = filename_convert_dirfsp(ctx,
-                                        conn,
-                                        oldname,
-                                        ucf_flags,
-                                        old_twrp,
-                                        &src_dirfsp,
-                                        &smb_fname_old);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
-       return hardlink_internals(ctx,
-                                 conn,
-                                 req,
-                                 false,
-                                 src_dirfsp,
-                                 smb_fname_old,
-                                 NULL, /* new_dirfsp */
-                                 smb_fname_new);
-}
-
 /****************************************************************************
  Deal with SMB2_FILE_RENAME_INFORMATION_INTERNAL
 ****************************************************************************/
@@ -6290,18 +6218,6 @@ static NTSTATUS smbd_do_posix_setfilepathinfo(struct connection_struct *conn,
                        break;
                }
 
-               case SMB_SET_FILE_UNIX_HLINK:
-               {
-                       if (smb_fname == NULL) {
-                               /* We must have a pathname for this. */
-                               return NT_STATUS_INVALID_LEVEL;
-                       }
-                       status = smb_set_file_unix_hlink(conn, req,
-                                                        pdata, total_data,
-                                                        smb_fname);
-                       break;
-               }
-
 #if defined(HAVE_POSIX_ACLS)
                case SMB_SET_POSIX_ACL:
                {