From: Jeremy Allison Date: Tue, 10 Jan 2023 01:33:14 +0000 (-0800) Subject: s3: smbd: Move check_fsp_open() and check_fsp() to smb1_reply.c X-Git-Tag: talloc-2.4.0~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ffa732d8280c2e88daab6c3b97de71a3cdfb3ba;p=thirdparty%2Fsamba.git s3: smbd: Move check_fsp_open() and check_fsp() to smb1_reply.c As these functions can implicitly call reply_nterror(..., NT_STATUS_INVALID_HANDLE) they should never be available to SMB2 code paths. Signed-off-by: Jeremy Allison Reviewed-by: Volker Lendecke Autobuild-User(master): Volker Lendecke Autobuild-Date(master): Wed Jan 11 08:17:04 UTC 2023 on sn-devel-184 --- diff --git a/source3/smbd/smb1_reply.c b/source3/smbd/smb1_reply.c index 1ae07f8602f..de6b4d99f79 100644 --- a/source3/smbd/smb1_reply.c +++ b/source3/smbd/smb1_reply.c @@ -52,6 +52,46 @@ #include "source3/printing/rap_jobid.h" #include "source3/lib/substitute.h" +/**************************************************************************** + Check if we have a correct fsp pointing to a file. Basic check for open fsp. +****************************************************************************/ + +bool check_fsp_open(connection_struct *conn, struct smb_request *req, + files_struct *fsp) +{ + if ((fsp == NULL) || (conn == NULL)) { + reply_nterror(req, NT_STATUS_INVALID_HANDLE); + return false; + } + if ((conn != fsp->conn) || (req->vuid != fsp->vuid)) { + reply_nterror(req, NT_STATUS_INVALID_HANDLE); + return false; + } + return true; +} + +/**************************************************************************** + Check if we have a correct fsp pointing to a file. +****************************************************************************/ + +bool check_fsp(connection_struct *conn, struct smb_request *req, + files_struct *fsp) +{ + if (!check_fsp_open(conn, req, fsp)) { + return false; + } + if (fsp->fsp_flags.is_directory) { + reply_nterror(req, NT_STATUS_INVALID_DEVICE_REQUEST); + return false; + } + if (fsp_get_pathref_fd(fsp) == -1) { + reply_nterror(req, NT_STATUS_ACCESS_DENIED); + return false; + } + fsp->num_smb_operations++; + return true; +} + /**************************************************************************** Reply to a tcon. conn POINTER CAN BE NULL HERE ! diff --git a/source3/smbd/smb2_reply.c b/source3/smbd/smb2_reply.c index 8b2eca20cb1..76e3cf789cd 100644 --- a/source3/smbd/smb2_reply.c +++ b/source3/smbd/smb2_reply.c @@ -524,46 +524,6 @@ size_t srvstr_pull_req_talloc(TALLOC_CTX *ctx, struct smb_request *req, bufrem, flags); } -/**************************************************************************** - Check if we have a correct fsp pointing to a file. Basic check for open fsp. -****************************************************************************/ - -bool check_fsp_open(connection_struct *conn, struct smb_request *req, - files_struct *fsp) -{ - if ((fsp == NULL) || (conn == NULL)) { - reply_nterror(req, NT_STATUS_INVALID_HANDLE); - return False; - } - if ((conn != fsp->conn) || (req->vuid != fsp->vuid)) { - reply_nterror(req, NT_STATUS_INVALID_HANDLE); - return False; - } - return True; -} - -/**************************************************************************** - Check if we have a correct fsp pointing to a file. -****************************************************************************/ - -bool check_fsp(connection_struct *conn, struct smb_request *req, - files_struct *fsp) -{ - if (!check_fsp_open(conn, req, fsp)) { - return False; - } - if (fsp->fsp_flags.is_directory) { - reply_nterror(req, NT_STATUS_INVALID_DEVICE_REQUEST); - return False; - } - if (fsp_get_pathref_fd(fsp) == -1) { - reply_nterror(req, NT_STATUS_ACCESS_DENIED); - return False; - } - fsp->num_smb_operations++; - return True; -} - /**************************************************************************** Check if we have a correct fsp pointing to a quota fake file. Replacement for the CHECK_NTQUOTA_HANDLE_OK macro.