summaryrefslogtreecommitdiff
path: root/redfish-core
diff options
context:
space:
mode:
authorEd Tanous <ed@tanous.net>2024-04-04 00:32:38 +0300
committerEd Tanous <ed@tanous.net>2024-04-17 20:44:22 +0300
commit757178a551c2dcc24730dccb6ed1cd11005b3b8f (patch)
tree8d5366604eafb9d0e7faf8d499ba823bbfed236a /redfish-core
parent6b0f66bdaa12ef09bf628f2610ea48ac14888b6f (diff)
downloadbmcweb-757178a551c2dcc24730dccb6ed1cd11005b3b8f.tar.xz
Refactor tftp parser
This function in the next patch will be used for more than just TFTP, so rename it to match intent, and refactor to use non-TFTP specific types. Tested: Rename only. Need help on TFTP setups if we need it. Change-Id: Ifc7485aa60ec53407c38b3d1bec530bdacf50075 Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'redfish-core')
-rw-r--r--redfish-core/lib/update_service.hpp95
1 files changed, 63 insertions, 32 deletions
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index a735567c8e..df4043f369 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -19,6 +19,7 @@
#include "app.hpp"
#include "dbus_utility.hpp"
+#include "generated/enums/update_service.hpp"
#include "multipart_parser.hpp"
#include "ossl_random.hpp"
#include "query.hpp"
@@ -441,16 +442,10 @@ inline void monitorForSoftwareAvailable(
std::bind_front(afterUpdateErrorMatcher, asyncResp, url));
}
-struct TftpUrl
-{
- std::string fwFile;
- std::string tftpServer;
-};
-
-inline std::optional<TftpUrl>
- parseTftpUrl(std::string imageURI,
- std::optional<std::string> transferProtocol,
- crow::Response& res)
+inline std::optional<boost::urls::url>
+ parseSimpleUpdateUrl(std::string imageURI,
+ std::optional<std::string> transferProtocol,
+ crow::Response& res)
{
if (imageURI.find("://") == std::string::npos)
{
@@ -467,7 +462,11 @@ inline std::optional<TftpUrl>
return std::nullopt;
}
// OpenBMC currently only supports TFTP
- if (*transferProtocol != "TFTP")
+ if (*transferProtocol == "TFTP")
+ {
+ imageURI = "tftp://" + imageURI;
+ }
+ else
{
messages::actionParameterNotSupported(res, "TransferProtocol",
*transferProtocol);
@@ -475,7 +474,6 @@ inline std::optional<TftpUrl>
*transferProtocol);
return std::nullopt;
}
- imageURI = "tftp://" + imageURI;
}
boost::system::result<boost::urls::url> url =
@@ -489,32 +487,52 @@ inline std::optional<TftpUrl>
}
url->normalize();
- if (url->scheme() != "tftp")
+ if (url->scheme() == "tftp")
+ {
+ if (url->encoded_path().size() < 2)
+ {
+ messages::actionParameterNotSupported(res, "ImageURI",
+ url->buffer());
+ return std::nullopt;
+ }
+ }
+ else
{
messages::actionParameterNotSupported(res, "ImageURI", imageURI);
return std::nullopt;
}
- std::string path(url->encoded_path());
- if (path.size() < 2)
+
+ if (url->encoded_path().empty())
{
- messages::actionParameterNotSupported(res, "ImageURI", imageURI);
+ messages::actionParameterValueTypeError(res, imageURI, "ImageURI",
+ "UpdateService.SimpleUpdate");
return std::nullopt;
}
- path.erase(0, 1);
- std::string host(url->encoded_host_and_port());
- return TftpUrl{path, host};
+
+ return *url;
}
inline void doTftpUpdate(const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const TftpUrl& tftpUrl)
+ const boost::urls::url_view_base& url)
{
#ifndef BMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE
messages::actionParameterNotSupported(asyncResp->res, "ImageURI",
- tftpUrl.tftpServer);
+ url.buffer());
return;
#endif
- BMCWEB_LOG_DEBUG("Server: {} File: {}", tftpUrl.tftpServer, tftpUrl.fwFile);
+
+ std::string path(url.encoded_path());
+ if (path.size() < 2)
+ {
+ messages::actionParameterNotSupported(asyncResp->res, "ImageURI",
+ url.buffer());
+ return;
+ }
+ // TFTP expects a path without a /
+ path.erase(0, 1);
+ std::string host(url.encoded_host_and_port());
+ BMCWEB_LOG_DEBUG("Server: {} File: {}", host, path);
// Setup callback for when new software detected
// Give TFTP 10 minutes to complete
@@ -545,7 +563,7 @@ inline void doTftpUpdate(const crow::Request& req,
},
"xyz.openbmc_project.Software.Download",
"/xyz/openbmc_project/software", "xyz.openbmc_project.Common.TFTP",
- "DownloadViaTFTP", tftpUrl.fwFile, tftpUrl.tftpServer);
+ "DownloadViaTFTP", path, host);
}
inline void handleUpdateServiceSimpleUpdateAction(
@@ -575,15 +593,22 @@ inline void handleUpdateServiceSimpleUpdateAction(
return;
}
- std::optional<TftpUrl> ret = parseTftpUrl(imageURI, transferProtocol,
- asyncResp->res);
- if (!ret)
+ std::optional<boost::urls::url> url =
+ parseSimpleUpdateUrl(imageURI, transferProtocol, asyncResp->res);
+ if (!url)
{
return;
}
-
- BMCWEB_LOG_DEBUG("Server: {} File: {}", ret->tftpServer, ret->fwFile);
- doTftpUpdate(req, asyncResp, *ret);
+ if (url->scheme() == "tftp")
+ {
+ doTftpUpdate(req, asyncResp, *url);
+ }
+ else
+ {
+ messages::actionParameterNotSupported(asyncResp->res, "ImageURI",
+ url->buffer());
+ return;
+ }
BMCWEB_LOG_DEBUG("Exit UpdateService.SimpleUpdate doPost");
}
@@ -805,15 +830,21 @@ inline void
asyncResp->res.jsonValue["MaxImageSizeBytes"] = bmcwebHttpReqBodyLimitMb *
1024 * 1024;
-#ifdef BMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE
// Update Actions object.
nlohmann::json& updateSvcSimpleUpdate =
asyncResp->res.jsonValue["Actions"]["#UpdateService.SimpleUpdate"];
updateSvcSimpleUpdate["target"] =
"/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate";
- updateSvcSimpleUpdate["TransferProtocol@Redfish.AllowableValues"] = {
- "TFTP"};
+
+ nlohmann::json::array_t allowed;
+
+#ifdef BMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE
+ allowed.emplace_back(update_service::TransferProtocolType::TFTP);
#endif
+
+ updateSvcSimpleUpdate["TransferProtocol@Redfish.AllowableValues"] =
+ std::move(allowed);
+
// Get the current ApplyTime value
sdbusplus::asio::getProperty<std::string>(
*crow::connections::systemBus, "xyz.openbmc_project.Settings",