blob: 00c3ecf5aef55c749d25053f6e045201b6c4a3bf [file] [log] [blame]
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +02001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
John Edward Broadbent7e860f12021-04-08 15:57:16 -070018#include <app.hpp>
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +020019#include <boost/container/flat_map.hpp>
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +010020#include <boost/process/async_pipe.hpp>
21#include <boost/type_traits/has_dereference.hpp>
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +020022#include <utils/json_utils.hpp>
23// for GetObjectType and ManagedObjectType
Ed Tanoused398212021-06-09 17:05:54 -070024
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +020025#include <account_service.hpp>
Anna Platash9e319cf2020-11-17 10:18:31 +010026#include <boost/url/url_view.hpp>
Ed Tanoused398212021-06-09 17:05:54 -070027#include <registries/privilege_registry.hpp>
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +020028
29namespace redfish
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +020030{
Anna Platash9e319cf2020-11-17 10:18:31 +010031/**
32 * @brief Function extracts transfer protocol name from URI.
33 */
Ed Tanous22db1722021-06-09 10:53:51 -070034inline std::string getTransferProtocolTypeFromUri(const std::string& imageUri)
Anna Platash9e319cf2020-11-17 10:18:31 +010035{
Ed Tanousd32c4fa2021-09-14 13:16:51 -070036 boost::urls::error_code ec;
37 boost::urls::url_view url =
38 boost::urls::parse_uri(boost::string_view(imageUri), ec);
39 if (ec)
Anna Platash9e319cf2020-11-17 10:18:31 +010040 {
Ed Tanousd32c4fa2021-09-14 13:16:51 -070041 return "None";
Anna Platash9e319cf2020-11-17 10:18:31 +010042 }
Ed Tanousd32c4fa2021-09-14 13:16:51 -070043 boost::string_view scheme = url.scheme();
44 if (scheme == "smb")
Anna Platash9e319cf2020-11-17 10:18:31 +010045 {
Ed Tanousd32c4fa2021-09-14 13:16:51 -070046 return "CIFS";
Anna Platash9e319cf2020-11-17 10:18:31 +010047 }
Ed Tanousd32c4fa2021-09-14 13:16:51 -070048 if (scheme == "https")
49 {
50 return "HTTPS";
51 }
52
Anna Platash9e319cf2020-11-17 10:18:31 +010053 return "None";
54}
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +020055
56/**
57 * @brief Read all known properties from VM object interfaces
58 */
Ed Tanous22db1722021-06-09 10:53:51 -070059inline void
Ed Tanous711ac7a2021-12-20 09:34:41 -080060 vmParseInterfaceObject(const dbus::utility::DBusInteracesMap& interface,
zhanghch058d1b46d2021-04-01 11:18:24 +080061 const std::shared_ptr<bmcweb::AsyncResp>& aResp)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +020062{
Ed Tanous711ac7a2021-12-20 09:34:41 -080063 for (const auto& [interface, values] : interface)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +020064 {
Ed Tanous711ac7a2021-12-20 09:34:41 -080065 if (interface == "xyz.openbmc_project.VirtualMedia.MountPoint")
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +020066 {
Ed Tanous711ac7a2021-12-20 09:34:41 -080067 for (const auto& [property, value] : values)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +020068 {
Ed Tanous711ac7a2021-12-20 09:34:41 -080069 if (property == "EndpointId")
70 {
71 const std::string* endpointIdValue =
72 std::get_if<std::string>(&value);
73 if (endpointIdValue == nullptr)
74 {
75 continue;
76 }
77 if (!endpointIdValue->empty())
78 {
79 // Proxy mode
80 aResp->res
81 .jsonValue["Oem"]["OpenBMC"]["WebSocketEndpoint"] =
82 *endpointIdValue;
83 aResp->res.jsonValue["TransferProtocolType"] = "OEM";
84 }
85 }
86 if (property == "ImageURL")
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +020087 {
Anna Platash9e319cf2020-11-17 10:18:31 +010088 const std::string* imageUrlValue =
Ed Tanous711ac7a2021-12-20 09:34:41 -080089 std::get_if<std::string>(&value);
Anna Platash9e319cf2020-11-17 10:18:31 +010090 if (imageUrlValue && !imageUrlValue->empty())
Przemyslaw Czarnowskida4784d2020-11-06 09:58:25 +010091 {
Anna Platash9e319cf2020-11-17 10:18:31 +010092 std::filesystem::path filePath = *imageUrlValue;
93 if (!filePath.has_filename())
94 {
95 // this will handle https share, which not
96 // necessarily has to have filename given.
97 aResp->res.jsonValue["ImageName"] = "";
98 }
99 else
100 {
101 aResp->res.jsonValue["ImageName"] =
102 filePath.filename();
103 }
Przemyslaw Czarnowskida4784d2020-11-06 09:58:25 +0100104
Anna Platash9e319cf2020-11-17 10:18:31 +0100105 aResp->res.jsonValue["Image"] = *imageUrlValue;
Anna Platash9e319cf2020-11-17 10:18:31 +0100106 aResp->res.jsonValue["TransferProtocolType"] =
107 getTransferProtocolTypeFromUri(*imageUrlValue);
108
Ed Tanous711ac7a2021-12-20 09:34:41 -0800109 aResp->res.jsonValue["ConnectedVia"] = "URI";
Anna Platash9e319cf2020-11-17 10:18:31 +0100110 }
111 }
Ed Tanous711ac7a2021-12-20 09:34:41 -0800112 if (property == "WriteProtected")
Anna Platash9e319cf2020-11-17 10:18:31 +0100113 {
Ed Tanous711ac7a2021-12-20 09:34:41 -0800114 const bool* writeProtectedValue = std::get_if<bool>(&value);
Anna Platash9e319cf2020-11-17 10:18:31 +0100115 if (writeProtectedValue)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200116 {
Anna Platash9e319cf2020-11-17 10:18:31 +0100117 aResp->res.jsonValue["WriteProtected"] =
118 *writeProtectedValue;
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200119 }
120 }
121 }
122 }
Ed Tanous711ac7a2021-12-20 09:34:41 -0800123 if (interface == "xyz.openbmc_project.VirtualMedia.Process")
124 {
125 for (const auto& [property, value] : values)
126 {
127 if (property == "Active")
128 {
129 const bool* activeValue = std::get_if<bool>(&value);
130 if (!activeValue)
131 {
132 BMCWEB_LOG_DEBUG << "Value Active not found";
133 return;
134 }
135 aResp->res.jsonValue["Inserted"] = *activeValue;
136
137 if (*activeValue == true)
138 {
139 aResp->res.jsonValue["ConnectedVia"] = "Applet";
140 }
141 }
142 }
143 }
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200144 }
145}
146
147/**
148 * @brief Fill template for Virtual Media Item.
149 */
Ed Tanous22db1722021-06-09 10:53:51 -0700150inline nlohmann::json vmItemTemplate(const std::string& name,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500151 const std::string& resName)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200152{
153 nlohmann::json item;
Ed Tanous22db1722021-06-09 10:53:51 -0700154
155 std::string id = "/redfish/v1/Managers/";
156 id += name;
157 id += "/VirtualMedia/";
158 id += resName;
159 item["@odata.id"] = std::move(id);
160
Przemyslaw Czarnowskid04ba322020-01-21 12:41:56 +0100161 item["@odata.type"] = "#VirtualMedia.v1_3_0.VirtualMedia";
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200162 item["Name"] = "Virtual Removable Media";
163 item["Id"] = resName;
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200164 item["WriteProtected"] = true;
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200165 item["MediaTypes"] = {"CD", "USBStick"};
166 item["TransferMethod"] = "Stream";
Przemyslaw Czarnowskid04ba322020-01-21 12:41:56 +0100167 item["Oem"]["OpenBMC"]["@odata.type"] =
168 "#OemVirtualMedia.v1_0_0.VirtualMedia";
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200169
170 return item;
171}
172
173/**
174 * @brief Fills collection data
175 */
Ed Tanous22db1722021-06-09 10:53:51 -0700176inline void getVmResourceList(std::shared_ptr<bmcweb::AsyncResp> aResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500177 const std::string& service,
178 const std::string& name)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200179{
180 BMCWEB_LOG_DEBUG << "Get available Virtual Media resources.";
181 crow::connections::systemBus->async_method_call(
Ed Tanous711ac7a2021-12-20 09:34:41 -0800182 [name,
183 aResp{std::move(aResp)}](const boost::system::error_code ec,
184 dbus::utility::ManagedObjectType& subtree) {
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200185 if (ec)
186 {
187 BMCWEB_LOG_DEBUG << "DBUS response error";
188 return;
189 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500190 nlohmann::json& members = aResp->res.jsonValue["Members"];
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200191 members = nlohmann::json::array();
192
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500193 for (const auto& object : subtree)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200194 {
195 nlohmann::json item;
Ed Tanous2dfd18e2020-12-18 00:41:31 +0000196 std::string path = object.first.filename();
197 if (path.empty())
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200198 {
199 continue;
200 }
201
Ed Tanous22db1722021-06-09 10:53:51 -0700202 std::string id = "/redfish/v1/Managers/";
203 id += name;
204 id += "/VirtualMedia/";
205 id += path;
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200206
Ed Tanous22db1722021-06-09 10:53:51 -0700207 item["@odata.id"] = std::move(id);
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200208 members.emplace_back(std::move(item));
209 }
210 aResp->res.jsonValue["Members@odata.count"] = members.size();
211 },
212 service, "/xyz/openbmc_project/VirtualMedia",
213 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
214}
215
216/**
217 * @brief Fills data for specific resource
218 */
Ed Tanous22db1722021-06-09 10:53:51 -0700219inline void getVmData(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500220 const std::string& service, const std::string& name,
221 const std::string& resName)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200222{
223 BMCWEB_LOG_DEBUG << "Get Virtual Media resource data.";
224
225 crow::connections::systemBus->async_method_call(
Ed Tanous914e2d52022-01-07 11:38:34 -0800226 [resName, name,
227 aResp](const boost::system::error_code ec,
228 const dbus::utility::ManagedObjectType& subtree) {
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200229 if (ec)
230 {
231 BMCWEB_LOG_DEBUG << "DBUS response error";
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200232
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200233 return;
234 }
235
Ed Tanous914e2d52022-01-07 11:38:34 -0800236 for (const auto& item : subtree)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200237 {
Ed Tanous2dfd18e2020-12-18 00:41:31 +0000238 std::string thispath = item.first.filename();
239 if (thispath.empty())
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200240 {
241 continue;
242 }
243
Ed Tanous2dfd18e2020-12-18 00:41:31 +0000244 if (thispath != resName)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200245 {
246 continue;
247 }
248
Przemyslaw Czarnowski1a6258d2021-04-14 11:02:46 +0200249 // "Legacy"/"Proxy"
250 auto mode = item.first.parent_path();
251 // "VirtualMedia"
252 auto type = mode.parent_path();
253 if (mode.filename().empty() || type.filename().empty())
254 {
255 continue;
256 }
257
258 if (type.filename() != "VirtualMedia")
259 {
260 continue;
261 }
262
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200263 aResp->res.jsonValue = vmItemTemplate(name, resName);
Ed Tanous22db1722021-06-09 10:53:51 -0700264 std::string actionsId = "/redfish/v1/Managers/";
265 actionsId += name;
266 actionsId += "/VirtualMedia/";
267 actionsId += resName;
268 actionsId += "/Actions";
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200269
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200270 // Check if dbus path is Legacy type
Przemyslaw Czarnowski1a6258d2021-04-14 11:02:46 +0200271 if (mode.filename() == "Legacy")
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200272 {
273 aResp->res.jsonValue["Actions"]["#VirtualMedia.InsertMedia"]
274 ["target"] =
Ed Tanous22db1722021-06-09 10:53:51 -0700275 actionsId + "/VirtualMedia.InsertMedia";
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200276 }
277
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200278 vmParseInterfaceObject(item.second, aResp);
279
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200280 aResp->res.jsonValue["Actions"]["#VirtualMedia.EjectMedia"]
281 ["target"] =
Ed Tanous22db1722021-06-09 10:53:51 -0700282 actionsId + "/VirtualMedia.EjectMedia";
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200283
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200284 return;
285 }
286
287 messages::resourceNotFound(
Przemyslaw Czarnowskid04ba322020-01-21 12:41:56 +0100288 aResp->res, "#VirtualMedia.v1_3_0.VirtualMedia", resName);
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200289 },
290 service, "/xyz/openbmc_project/VirtualMedia",
291 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
292}
293
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200294/**
Ed Tanous22db1722021-06-09 10:53:51 -0700295 * @brief Transfer protocols supported for InsertMedia action.
296 *
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200297 */
Ed Tanous22db1722021-06-09 10:53:51 -0700298enum class TransferProtocol
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200299{
Ed Tanous22db1722021-06-09 10:53:51 -0700300 https,
301 smb,
302 invalid
303};
304
305/**
306 * @brief Function extracts transfer protocol type from URI.
307 *
308 */
309inline std::optional<TransferProtocol>
310 getTransferProtocolFromUri(const std::string& imageUri)
311{
Ed Tanousd32c4fa2021-09-14 13:16:51 -0700312 boost::urls::error_code ec;
313 boost::urls::url_view url =
314 boost::urls::parse_uri(boost::string_view(imageUri), ec);
315 if (ec)
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200316 {
Ed Tanousd32c4fa2021-09-14 13:16:51 -0700317 return {};
Agata Olenderc6f4e012020-03-11 15:19:07 +0100318 }
Ed Tanousd32c4fa2021-09-14 13:16:51 -0700319
320 boost::string_view scheme = url.scheme();
321 if (scheme == "smb")
Agata Olenderc6f4e012020-03-11 15:19:07 +0100322 {
Ed Tanousd32c4fa2021-09-14 13:16:51 -0700323 return TransferProtocol::smb;
324 }
325 if (scheme == "https")
326 {
327 return TransferProtocol::https;
328 }
329 if (!scheme.empty())
330 {
331 return TransferProtocol::invalid;
Agata Olenderc6f4e012020-03-11 15:19:07 +0100332 }
333
Ed Tanous22db1722021-06-09 10:53:51 -0700334 return {};
335}
336
337/**
338 * @brief Function convert transfer protocol from string param.
339 *
340 */
341inline std::optional<TransferProtocol> getTransferProtocolFromParam(
342 const std::optional<std::string>& transferProtocolType)
343{
344 if (transferProtocolType == std::nullopt)
Agata Olenderc6f4e012020-03-11 15:19:07 +0100345 {
Ed Tanous22db1722021-06-09 10:53:51 -0700346 return {};
Agata Olenderc6f4e012020-03-11 15:19:07 +0100347 }
348
Ed Tanous22db1722021-06-09 10:53:51 -0700349 if (*transferProtocolType == "CIFS")
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200350 {
Ed Tanous22db1722021-06-09 10:53:51 -0700351 return TransferProtocol::smb;
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200352 }
353
Ed Tanous22db1722021-06-09 10:53:51 -0700354 if (*transferProtocolType == "HTTPS")
355 {
356 return TransferProtocol::https;
357 }
358
359 return TransferProtocol::invalid;
360}
361
362/**
363 * @brief Function extends URI with transfer protocol type.
364 *
365 */
366inline std::string
367 getUriWithTransferProtocol(const std::string& imageUri,
368 const TransferProtocol& transferProtocol)
369{
370 if (transferProtocol == TransferProtocol::smb)
371 {
372 return "smb://" + imageUri;
373 }
374
375 if (transferProtocol == TransferProtocol::https)
376 {
377 return "https://" + imageUri;
378 }
379
380 return imageUri;
381}
382
383/**
384 * @brief Function validate parameters of insert media request.
385 *
386 */
387inline bool
388 validateParams(crow::Response& res, std::string& imageUrl,
389 const std::optional<bool>& inserted,
390 const std::optional<std::string>& transferMethod,
391 const std::optional<std::string>& transferProtocolType)
392{
393 BMCWEB_LOG_DEBUG << "Validation started";
394 // required param imageUrl must not be empty
395 if (imageUrl.empty())
396 {
397 BMCWEB_LOG_ERROR << "Request action parameter Image is empty.";
398
399 messages::propertyValueFormatError(res, "<empty>", "Image");
400
401 return false;
402 }
403
404 // optional param inserted must be true
405 if ((inserted != std::nullopt) && (*inserted != true))
406 {
407 BMCWEB_LOG_ERROR
408 << "Request action optional parameter Inserted must be true.";
409
410 messages::actionParameterNotSupported(res, "Inserted", "InsertMedia");
411
412 return false;
413 }
414
415 // optional param transferMethod must be stream
416 if ((transferMethod != std::nullopt) && (*transferMethod != "Stream"))
417 {
418 BMCWEB_LOG_ERROR << "Request action optional parameter "
419 "TransferMethod must be Stream.";
420
421 messages::actionParameterNotSupported(res, "TransferMethod",
422 "InsertMedia");
423
424 return false;
425 }
426
427 std::optional<TransferProtocol> uriTransferProtocolType =
428 getTransferProtocolFromUri(imageUrl);
429
430 std::optional<TransferProtocol> paramTransferProtocolType =
431 getTransferProtocolFromParam(transferProtocolType);
432
433 // ImageUrl does not contain valid protocol type
434 if (*uriTransferProtocolType == TransferProtocol::invalid)
435 {
436 BMCWEB_LOG_ERROR << "Request action parameter ImageUrl must "
437 "contain specified protocol type from list: "
438 "(smb, https).";
439
440 messages::resourceAtUriInUnknownFormat(res, imageUrl);
441
442 return false;
443 }
444
445 // transferProtocolType should contain value from list
446 if (*paramTransferProtocolType == TransferProtocol::invalid)
447 {
448 BMCWEB_LOG_ERROR << "Request action parameter TransferProtocolType "
449 "must be provided with value from list: "
450 "(CIFS, HTTPS).";
451
452 messages::propertyValueNotInList(res, *transferProtocolType,
453 "TransferProtocolType");
454 return false;
455 }
456
457 // valid transfer protocol not provided either with URI nor param
458 if ((uriTransferProtocolType == std::nullopt) &&
459 (paramTransferProtocolType == std::nullopt))
460 {
461 BMCWEB_LOG_ERROR << "Request action parameter ImageUrl must "
462 "contain specified protocol type or param "
463 "TransferProtocolType must be provided.";
464
465 messages::resourceAtUriInUnknownFormat(res, imageUrl);
466
467 return false;
468 }
469
470 // valid transfer protocol provided both with URI and param
471 if ((paramTransferProtocolType != std::nullopt) &&
472 (uriTransferProtocolType != std::nullopt))
473 {
474 // check if protocol is the same for URI and param
475 if (*paramTransferProtocolType != *uriTransferProtocolType)
476 {
477 BMCWEB_LOG_ERROR << "Request action parameter "
478 "TransferProtocolType must contain the "
479 "same protocol type as protocol type "
480 "provided with param imageUrl.";
481
482 messages::actionParameterValueTypeError(res, *transferProtocolType,
483 "TransferProtocolType",
484 "InsertMedia");
485
486 return false;
487 }
488 }
489
490 // validation passed
491 // add protocol to URI if needed
492 if (uriTransferProtocolType == std::nullopt)
493 {
494 imageUrl =
495 getUriWithTransferProtocol(imageUrl, *paramTransferProtocolType);
496 }
497
498 return true;
499}
500
501template <typename T>
502static void secureCleanup(T& value)
503{
504 auto raw = const_cast<typename T::value_type*>(value.data());
505 explicit_bzero(raw, value.size() * sizeof(*raw));
506}
507
508class Credentials
509{
510 public:
511 Credentials(std::string&& user, std::string&& password) :
512 userBuf(std::move(user)), passBuf(std::move(password))
513 {}
514
515 ~Credentials()
516 {
517 secureCleanup(userBuf);
518 secureCleanup(passBuf);
519 }
520
521 const std::string& user()
522 {
523 return userBuf;
524 }
525
526 const std::string& password()
527 {
528 return passBuf;
529 }
530
531 Credentials() = delete;
532 Credentials(const Credentials&) = delete;
533 Credentials& operator=(const Credentials&) = delete;
Ed Tanousecd6a3a2022-01-07 09:18:40 -0800534 Credentials(Credentials&&) = delete;
535 Credentials& operator=(Credentials&&) = delete;
Ed Tanous22db1722021-06-09 10:53:51 -0700536
537 private:
538 std::string userBuf;
539 std::string passBuf;
540};
541
542class CredentialsProvider
543{
544 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500545 template <typename T>
Ed Tanous22db1722021-06-09 10:53:51 -0700546 struct Deleter
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100547 {
Ed Tanous22db1722021-06-09 10:53:51 -0700548 void operator()(T* buff) const
549 {
550 if (buff)
551 {
552 secureCleanup(*buff);
553 delete buff;
554 }
555 }
556 };
557
558 using Buffer = std::vector<char>;
559 using SecureBuffer = std::unique_ptr<Buffer, Deleter<Buffer>>;
560 // Using explicit definition instead of std::function to avoid implicit
561 // conversions eg. stack copy instead of reference
562 using FormatterFunc = void(const std::string& username,
563 const std::string& password, Buffer& dest);
564
565 CredentialsProvider(std::string&& user, std::string&& password) :
566 credentials(std::move(user), std::move(password))
567 {}
568
569 const std::string& user()
570 {
571 return credentials.user();
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100572 }
573
Ed Tanous22db1722021-06-09 10:53:51 -0700574 const std::string& password()
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100575 {
Ed Tanous22db1722021-06-09 10:53:51 -0700576 return credentials.password();
577 }
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100578
Ed Tanous22db1722021-06-09 10:53:51 -0700579 SecureBuffer pack(FormatterFunc formatter)
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100580 {
Ed Tanous22db1722021-06-09 10:53:51 -0700581 SecureBuffer packed{new Buffer{}};
582 if (formatter)
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100583 {
Ed Tanous22db1722021-06-09 10:53:51 -0700584 formatter(credentials.user(), credentials.password(), *packed);
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100585 }
586
Ed Tanous22db1722021-06-09 10:53:51 -0700587 return packed;
588 }
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100589
Ed Tanous22db1722021-06-09 10:53:51 -0700590 private:
591 Credentials credentials;
592};
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100593
Ed Tanous22db1722021-06-09 10:53:51 -0700594// Wrapper for boost::async_pipe ensuring proper pipe cleanup
595template <typename Buffer>
596class Pipe
597{
598 public:
599 using unix_fd = sdbusplus::message::unix_fd;
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100600
Ed Tanous22db1722021-06-09 10:53:51 -0700601 Pipe(boost::asio::io_context& io, Buffer&& buffer) :
602 impl(io), buffer{std::move(buffer)}
603 {}
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100604
Ed Tanous22db1722021-06-09 10:53:51 -0700605 ~Pipe()
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100606 {
Ed Tanous22db1722021-06-09 10:53:51 -0700607 // Named pipe needs to be explicitly removed
608 impl.close();
609 }
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100610
Ed Tanousecd6a3a2022-01-07 09:18:40 -0800611 Pipe(const Pipe&) = delete;
612 Pipe(Pipe&&) = delete;
613 Pipe& operator=(const Pipe&) = delete;
614 Pipe& operator=(Pipe&&) = delete;
615
Ed Tanous22db1722021-06-09 10:53:51 -0700616 unix_fd fd()
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200617 {
Ed Tanous22db1722021-06-09 10:53:51 -0700618 return unix_fd{impl.native_source()};
619 }
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100620
Ed Tanous22db1722021-06-09 10:53:51 -0700621 template <typename WriteHandler>
622 void asyncWrite(WriteHandler&& handler)
623 {
624 impl.async_write_some(data(), std::forward<WriteHandler>(handler));
625 }
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100626
Ed Tanous22db1722021-06-09 10:53:51 -0700627 private:
628 // Specialization for pointer types
629 template <typename B = Buffer>
630 typename std::enable_if<boost::has_dereference<B>::value,
631 boost::asio::const_buffer>::type
632 data()
633 {
634 return boost::asio::buffer(*buffer);
635 }
636
637 template <typename B = Buffer>
638 typename std::enable_if<!boost::has_dereference<B>::value,
639 boost::asio::const_buffer>::type
640 data()
641 {
642 return boost::asio::buffer(buffer);
643 }
644
645 const std::string name;
646 boost::process::async_pipe impl;
647 Buffer buffer;
648};
649
650/**
651 * @brief Function transceives data with dbus directly.
652 *
653 * All BMC state properties will be retrieved before sending reset request.
654 */
655inline void doMountVmLegacy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
656 const std::string& service, const std::string& name,
657 const std::string& imageUrl, const bool rw,
658 std::string&& userName, std::string&& password)
659{
660 using SecurePipe = Pipe<CredentialsProvider::SecureBuffer>;
661 constexpr const size_t secretLimit = 1024;
662
663 std::shared_ptr<SecurePipe> secretPipe;
Ed Tanous168e20c2021-12-13 14:39:53 -0800664 dbus::utility::DbusVariantType unixFd = -1;
Ed Tanous22db1722021-06-09 10:53:51 -0700665
666 if (!userName.empty() || !password.empty())
667 {
668 // Encapsulate in safe buffer
669 CredentialsProvider credentials(std::move(userName),
670 std::move(password));
671
672 // Payload must contain data + NULL delimiters
673 if (credentials.user().size() + credentials.password().size() + 2 >
674 secretLimit)
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100675 {
Ed Tanous22db1722021-06-09 10:53:51 -0700676 BMCWEB_LOG_ERROR << "Credentials too long to handle";
677 messages::unrecognizedRequestBody(asyncResp->res);
678 return;
679 }
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100680
Ed Tanous22db1722021-06-09 10:53:51 -0700681 // Pack secret
682 auto secret = credentials.pack(
683 [](const auto& user, const auto& pass, auto& buff) {
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100684 std::copy(user.begin(), user.end(), std::back_inserter(buff));
685 buff.push_back('\0');
686 std::copy(pass.begin(), pass.end(), std::back_inserter(buff));
687 buff.push_back('\0');
688 });
689
Ed Tanous22db1722021-06-09 10:53:51 -0700690 // Open pipe
691 secretPipe = std::make_shared<SecurePipe>(
692 crow::connections::systemBus->get_io_context(), std::move(secret));
693 unixFd = secretPipe->fd();
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100694
Ed Tanous22db1722021-06-09 10:53:51 -0700695 // Pass secret over pipe
696 secretPipe->asyncWrite(
697 [asyncResp](const boost::system::error_code& ec, std::size_t) {
698 if (ec)
699 {
700 BMCWEB_LOG_ERROR << "Failed to pass secret: " << ec;
701 messages::internalError(asyncResp->res);
702 }
703 });
704 }
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100705
Ed Tanous22db1722021-06-09 10:53:51 -0700706 crow::connections::systemBus->async_method_call(
707 [asyncResp, secretPipe](const boost::system::error_code ec,
708 bool success) {
709 if (ec)
710 {
711 BMCWEB_LOG_ERROR << "Bad D-Bus request error: " << ec;
712 messages::internalError(asyncResp->res);
713 }
714 else if (!success)
715 {
716 BMCWEB_LOG_ERROR << "Service responded with error";
717 messages::generalError(asyncResp->res);
718 }
719 },
720 service, "/xyz/openbmc_project/VirtualMedia/Legacy/" + name,
721 "xyz.openbmc_project.VirtualMedia.Legacy", "Mount", imageUrl, rw,
722 unixFd);
723}
724
725/**
726 * @brief Function transceives data with dbus directly.
727 *
728 * All BMC state properties will be retrieved before sending reset request.
729 */
730inline void doVmAction(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
731 const std::string& service, const std::string& name,
732 bool legacy)
733{
734
735 // Legacy mount requires parameter with image
736 if (legacy)
737 {
Adrian Ambrożewiczd6da5be2020-01-13 18:31:01 +0100738 crow::connections::systemBus->async_method_call(
Ed Tanous22db1722021-06-09 10:53:51 -0700739 [asyncResp](const boost::system::error_code ec) {
Adrian Ambrożewiczd6da5be2020-01-13 18:31:01 +0100740 if (ec)
741 {
742 BMCWEB_LOG_ERROR << "Bad D-Bus request error: " << ec;
Ed Tanous22db1722021-06-09 10:53:51 -0700743
Adrian Ambrożewiczd6da5be2020-01-13 18:31:01 +0100744 messages::internalError(asyncResp->res);
Ed Tanous22db1722021-06-09 10:53:51 -0700745 return;
Adrian Ambrożewiczd6da5be2020-01-13 18:31:01 +0100746 }
747 },
748 service, "/xyz/openbmc_project/VirtualMedia/Legacy/" + name,
Ed Tanous22db1722021-06-09 10:53:51 -0700749 "xyz.openbmc_project.VirtualMedia.Legacy", "Unmount");
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200750 }
Ed Tanous22db1722021-06-09 10:53:51 -0700751 else // proxy
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200752 {
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200753 crow::connections::systemBus->async_method_call(
Ed Tanous22db1722021-06-09 10:53:51 -0700754 [asyncResp](const boost::system::error_code ec) {
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200755 if (ec)
756 {
Ed Tanous22db1722021-06-09 10:53:51 -0700757 BMCWEB_LOG_ERROR << "Bad D-Bus request error: " << ec;
758
zhanghch058d1b46d2021-04-01 11:18:24 +0800759 messages::internalError(asyncResp->res);
Ed Tanous22db1722021-06-09 10:53:51 -0700760 return;
761 }
762 },
763 service, "/xyz/openbmc_project/VirtualMedia/Proxy/" + name,
764 "xyz.openbmc_project.VirtualMedia.Proxy", "Unmount");
765 }
766}
767
Ed Tanous98be3e32021-09-16 15:05:36 -0700768struct InsertMediaActionParams
769{
770 std::string imageUrl;
771 std::optional<std::string> userName;
772 std::optional<std::string> password;
773 std::optional<std::string> transferMethod;
774 std::optional<std::string> transferProtocolType;
775 std::optional<bool> writeProtected = true;
776 std::optional<bool> inserted;
777};
778
Ed Tanous22db1722021-06-09 10:53:51 -0700779inline void requestNBDVirtualMediaRoutes(App& app)
780{
George Liu0fda0f12021-11-16 10:06:17 +0800781 BMCWEB_ROUTE(
782 app,
783 "/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.InsertMedia")
Ed Tanoused398212021-06-09 17:05:54 -0700784 .privileges(redfish::privileges::postVirtualMedia)
Ed Tanous22db1722021-06-09 10:53:51 -0700785 .methods(boost::beast::http::verb::post)(
786 [](const crow::Request& req,
787 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
788 const std::string& name, const std::string& resName) {
789 if (name != "bmc")
790 {
791 messages::resourceNotFound(asyncResp->res,
792 "VirtualMedia.Insert", resName);
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200793
794 return;
795 }
Ed Tanous98be3e32021-09-16 15:05:36 -0700796 InsertMediaActionParams actionParams;
797
798 // Read obligatory parameters (url of
799 // image)
800 if (!json_util::readJson(
801 req, asyncResp->res, "Image", actionParams.imageUrl,
802 "WriteProtected", actionParams.writeProtected,
803 "UserName", actionParams.userName, "Password",
804 actionParams.password, "Inserted",
805 actionParams.inserted, "TransferMethod",
806 actionParams.transferMethod, "TransferProtocolType",
807 actionParams.transferProtocolType))
808 {
809 BMCWEB_LOG_DEBUG << "Image is not provided";
810 return;
811 }
812
813 bool paramsValid = validateParams(
814 asyncResp->res, actionParams.imageUrl,
815 actionParams.inserted, actionParams.transferMethod,
816 actionParams.transferProtocolType);
817
818 if (paramsValid == false)
819 {
820 return;
821 }
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200822
823 crow::connections::systemBus->async_method_call(
Ed Tanous98be3e32021-09-16 15:05:36 -0700824 [asyncResp, actionParams,
Ed Tanous22db1722021-06-09 10:53:51 -0700825 resName](const boost::system::error_code ec,
Ed Tanous98be3e32021-09-16 15:05:36 -0700826 const GetObjectType& getObjectType) mutable {
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200827 if (ec)
828 {
Ed Tanous22db1722021-06-09 10:53:51 -0700829 BMCWEB_LOG_ERROR
830 << "ObjectMapper::GetObject call failed: "
831 << ec;
832 messages::internalError(asyncResp->res);
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200833
834 return;
835 }
Ed Tanous22db1722021-06-09 10:53:51 -0700836 std::string service = getObjectType.begin()->first;
837 BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200838
Ed Tanous22db1722021-06-09 10:53:51 -0700839 crow::connections::systemBus->async_method_call(
Ed Tanous98be3e32021-09-16 15:05:36 -0700840 [service, resName, actionParams,
Ed Tanous22db1722021-06-09 10:53:51 -0700841 asyncResp](const boost::system::error_code ec,
Ed Tanous711ac7a2021-12-20 09:34:41 -0800842 dbus::utility::ManagedObjectType&
843 subtree) mutable {
Ed Tanous22db1722021-06-09 10:53:51 -0700844 if (ec)
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200845 {
Ed Tanous22db1722021-06-09 10:53:51 -0700846 BMCWEB_LOG_DEBUG << "DBUS response error";
847
848 return;
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200849 }
850
Ed Tanous22db1722021-06-09 10:53:51 -0700851 for (const auto& object : subtree)
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200852 {
Ed Tanous22db1722021-06-09 10:53:51 -0700853 const std::string& path =
854 static_cast<const std::string&>(
855 object.first);
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200856
Ed Tanous22db1722021-06-09 10:53:51 -0700857 std::size_t lastIndex = path.rfind('/');
858 if (lastIndex == std::string::npos)
859 {
860 continue;
861 }
862
863 lastIndex += 1;
864
865 if (path.substr(lastIndex) == resName)
866 {
867 lastIndex = path.rfind("Proxy");
868 if (lastIndex != std::string::npos)
869 {
870 // Not possible in proxy mode
871 BMCWEB_LOG_DEBUG
872 << "InsertMedia not "
873 "allowed in proxy mode";
874 messages::resourceNotFound(
875 asyncResp->res,
876 "VirtualMedia.InsertMedia",
877 resName);
878
879 return;
880 }
881
882 lastIndex = path.rfind("Legacy");
883 if (lastIndex == std::string::npos)
884 {
885 continue;
886 }
887
Ed Tanous22db1722021-06-09 10:53:51 -0700888 // manager is irrelevant for
889 // VirtualMedia dbus calls
Ed Tanous98be3e32021-09-16 15:05:36 -0700890 doMountVmLegacy(
891 asyncResp, service, resName,
892 actionParams.imageUrl,
893 !(*actionParams.writeProtected),
894 std::move(*actionParams.userName),
895 std::move(*actionParams.password));
Ed Tanous22db1722021-06-09 10:53:51 -0700896
897 return;
898 }
899 }
900 BMCWEB_LOG_DEBUG << "Parent item not found";
901 messages::resourceNotFound(
902 asyncResp->res, "VirtualMedia", resName);
903 },
904 service, "/xyz/openbmc_project/VirtualMedia",
905 "org.freedesktop.DBus.ObjectManager",
906 "GetManagedObjects");
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200907 },
Ed Tanous22db1722021-06-09 10:53:51 -0700908 "xyz.openbmc_project.ObjectMapper",
909 "/xyz/openbmc_project/object_mapper",
910 "xyz.openbmc_project.ObjectMapper", "GetObject",
911 "/xyz/openbmc_project/VirtualMedia",
912 std::array<const char*, 0>());
913 });
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200914
George Liu0fda0f12021-11-16 10:06:17 +0800915 BMCWEB_ROUTE(
916 app,
917 "/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.EjectMedia")
Ed Tanoused398212021-06-09 17:05:54 -0700918 .privileges(redfish::privileges::postVirtualMedia)
Ed Tanous22db1722021-06-09 10:53:51 -0700919 .methods(boost::beast::http::verb::post)(
Ed Tanous98be3e32021-09-16 15:05:36 -0700920 [](const crow::Request&,
Ed Tanous22db1722021-06-09 10:53:51 -0700921 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
922 const std::string& name, const std::string& resName) {
923 if (name != "bmc")
924 {
925 messages::resourceNotFound(asyncResp->res,
926 "VirtualMedia.Eject", resName);
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200927
Ed Tanous22db1722021-06-09 10:53:51 -0700928 return;
929 }
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200930
Ed Tanous22db1722021-06-09 10:53:51 -0700931 crow::connections::systemBus->async_method_call(
Ed Tanous98be3e32021-09-16 15:05:36 -0700932 [asyncResp, resName](const boost::system::error_code ec,
933 const GetObjectType& getObjectType) {
Ed Tanous22db1722021-06-09 10:53:51 -0700934 if (ec)
935 {
936 BMCWEB_LOG_ERROR
937 << "ObjectMapper::GetObject call failed: "
938 << ec;
939 messages::internalError(asyncResp->res);
940
941 return;
942 }
943 std::string service = getObjectType.begin()->first;
944 BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
945
946 crow::connections::systemBus->async_method_call(
Ed Tanous98be3e32021-09-16 15:05:36 -0700947 [resName, service, asyncResp{asyncResp}](
Ed Tanous22db1722021-06-09 10:53:51 -0700948 const boost::system::error_code ec,
Ed Tanous711ac7a2021-12-20 09:34:41 -0800949 dbus::utility::ManagedObjectType& subtree) {
Ed Tanous22db1722021-06-09 10:53:51 -0700950 if (ec)
951 {
952 BMCWEB_LOG_DEBUG << "DBUS response error";
953
954 return;
955 }
956
957 for (const auto& object : subtree)
958 {
959 const std::string& path =
960 static_cast<const std::string&>(
961 object.first);
962
963 std::size_t lastIndex = path.rfind('/');
964 if (lastIndex == std::string::npos)
965 {
966 continue;
967 }
968
969 lastIndex += 1;
970
971 if (path.substr(lastIndex) == resName)
972 {
973 lastIndex = path.rfind("Proxy");
974 if (lastIndex != std::string::npos)
975 {
976 // Proxy mode
977 doVmAction(asyncResp, service,
978 resName, false);
979 }
980
981 lastIndex = path.rfind("Legacy");
982 if (lastIndex != std::string::npos)
983 {
984 // Legacy mode
985 doVmAction(asyncResp, service,
986 resName, true);
987 }
988
989 return;
990 }
991 }
992 BMCWEB_LOG_DEBUG << "Parent item not found";
993 messages::resourceNotFound(
994 asyncResp->res, "VirtualMedia", resName);
995 },
996 service, "/xyz/openbmc_project/VirtualMedia",
997 "org.freedesktop.DBus.ObjectManager",
998 "GetManagedObjects");
999 },
1000 "xyz.openbmc_project.ObjectMapper",
1001 "/xyz/openbmc_project/object_mapper",
1002 "xyz.openbmc_project.ObjectMapper", "GetObject",
1003 "/xyz/openbmc_project/VirtualMedia",
1004 std::array<const char*, 0>());
1005 });
1006 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/")
Ed Tanoused398212021-06-09 17:05:54 -07001007 .privileges(redfish::privileges::getVirtualMediaCollection)
Ed Tanous22db1722021-06-09 10:53:51 -07001008 .methods(boost::beast::http::verb::get)(
1009 [](const crow::Request& /* req */,
1010 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1011 const std::string& name) {
1012 if (name != "bmc")
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +02001013 {
Ed Tanous22db1722021-06-09 10:53:51 -07001014 messages::resourceNotFound(asyncResp->res, "VirtualMedia",
1015 name);
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +02001016
1017 return;
1018 }
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +02001019
Ed Tanous22db1722021-06-09 10:53:51 -07001020 asyncResp->res.jsonValue["@odata.type"] =
1021 "#VirtualMediaCollection.VirtualMediaCollection";
1022 asyncResp->res.jsonValue["Name"] = "Virtual Media Services";
1023 asyncResp->res.jsonValue["@odata.id"] =
1024 "/redfish/v1/Managers/" + name + "/VirtualMedia";
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +02001025
Ed Tanous22db1722021-06-09 10:53:51 -07001026 crow::connections::systemBus->async_method_call(
1027 [asyncResp, name](const boost::system::error_code ec,
1028 const GetObjectType& getObjectType) {
1029 if (ec)
1030 {
1031 BMCWEB_LOG_ERROR
1032 << "ObjectMapper::GetObject call failed: "
1033 << ec;
1034 messages::internalError(asyncResp->res);
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +02001035
Ed Tanous22db1722021-06-09 10:53:51 -07001036 return;
1037 }
1038 std::string service = getObjectType.begin()->first;
1039 BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +02001040
Ed Tanous22db1722021-06-09 10:53:51 -07001041 getVmResourceList(asyncResp, service, name);
1042 },
1043 "xyz.openbmc_project.ObjectMapper",
1044 "/xyz/openbmc_project/object_mapper",
1045 "xyz.openbmc_project.ObjectMapper", "GetObject",
1046 "/xyz/openbmc_project/VirtualMedia",
1047 std::array<const char*, 0>());
1048 });
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +02001049
Ed Tanous22db1722021-06-09 10:53:51 -07001050 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001051 .privileges(redfish::privileges::getVirtualMedia)
Ed Tanous22db1722021-06-09 10:53:51 -07001052 .methods(boost::beast::http::verb::get)(
1053 [](const crow::Request& /* req */,
1054 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1055 const std::string& name, const std::string& resName) {
1056 if (name != "bmc")
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +02001057 {
Ed Tanous22db1722021-06-09 10:53:51 -07001058 messages::resourceNotFound(asyncResp->res, "VirtualMedia",
1059 resName);
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +02001060
1061 return;
1062 }
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +02001063
Ed Tanous22db1722021-06-09 10:53:51 -07001064 crow::connections::systemBus->async_method_call(
1065 [asyncResp, name,
1066 resName](const boost::system::error_code ec,
1067 const GetObjectType& getObjectType) {
1068 if (ec)
1069 {
1070 BMCWEB_LOG_ERROR
1071 << "ObjectMapper::GetObject call failed: "
1072 << ec;
1073 messages::internalError(asyncResp->res);
1074
1075 return;
1076 }
1077 std::string service = getObjectType.begin()->first;
1078 BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
1079
1080 getVmData(asyncResp, service, name, resName);
1081 },
1082 "xyz.openbmc_project.ObjectMapper",
1083 "/xyz/openbmc_project/object_mapper",
1084 "xyz.openbmc_project.ObjectMapper", "GetObject",
1085 "/xyz/openbmc_project/VirtualMedia",
1086 std::array<const char*, 0>());
1087 });
1088}
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +02001089
1090} // namespace redfish