From: Volker Lendecke Date: Thu, 29 Dec 2022 09:47:12 +0000 (+0100) Subject: smbd: Move smb_set_file_unix_hlink() to smb1_trans2.c X-Git-Tag: talloc-2.4.0~97 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2cef6fcd6d13b68193a04ef64b3d9717a6d1173b;p=thirdparty%2Fsamba.git smbd: Move smb_set_file_unix_hlink() to smb1_trans2.c 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 Reviewed-by: Ralph Boehme --- diff --git a/source3/smbd/smb1_trans2.c b/source3/smbd/smb1_trans2.c index 03eb0f18c37..8301ffbfba0 100644 --- a/source3/smbd/smb1_trans2.c +++ b/source3/smbd/smb1_trans2.c @@ -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) { diff --git a/source3/smbd/smb2_trans2.c b/source3/smbd/smb2_trans2.c index e6647a06d39..d4a71254605 100644 --- a/source3/smbd/smb2_trans2.c +++ b/source3/smbd/smb2_trans2.c @@ -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: {