Remove ambiguous privileges constructor
There are a number of endpoints that assume that a given routes
privileges are governed by a single set of privileges, instead of
multiple sets ORed together. To handle this, there were two overloads
of the privileges() method, one that took a vector of Privileges, and
one that took an initializer_list of const char*. Unfortunately, this
leads some code in AccountService to pick the wrong overload when it's
called like this
.privileges( {{"ConfigureUsers"}, {"ConfigureManager"},
{"ConfigureSelf"}})
This is supposed to be "User must have ConfigureUsers, or
ConfigureManager, or ConfigureSelf". Currently, because it selects the
wrong overload, it computes to "User must have ConfigureUsers AND
ConfigureManager AND ConfigureSelf.
The double braces are supposed to cause this to form a vector of
Privileges, but it appears that the initializer list gets consumed, and
the single invocation of initializer list is called. Interestingly,
trying to put in a privileges overload of
intializer_list<initializer_list<const char*>> causes the compilation to
fail with an ambiguous call error, which is what I would've expected to
see previously in this case, but alas, I'm only a novice when it comes
to how the C++ standard works in these edge cases. This is likely due
in part to the fact that they were templates of an unused template param
(seemingly copied from the previous method) and SFINAE rules around
templates.
This commit functionally removes one of the privileges overloads, and
adds a second set of braces to every privileges call that previously had
a single set of braces. Previous code will not compile now, which is
IMO a good thing.
This likely popped up in the Node class removal, because the Node class
explicitly constructs a vector of Privilege objects, ensuing it can hit
the right overload
Tested:
Ran Redfish service validator
Tested the specific use case outlined on discord with:
Creating a new user with operator privilege:
```
redfishtool -S Always -u root -p 0penBmc -vvvvvvvvv -r 192.168.7.2
AccountService adduser foo mysuperPass1 Operator
```
Then attempting to list accounts:
```
curl -vvvv --insecure --user foo:mysuperPass1
https://192.168.7.2/redfish/v1/AccountService/Accounts/foo
```
Which succeeded and returned the account in question.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I83e62b70e97f56dc57d43b9081f333a02fe85495
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index 02a4fad..33747dd 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -388,7 +388,7 @@
{
BMCWEB_ROUTE(
app, "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate/")
- .privileges({"ConfigureComponents"})
+ .privileges({{"ConfigureComponents"}})
.methods(
boost::beast::http::verb::
post)([](const crow::Request& req,
@@ -507,7 +507,7 @@
inline void requestRoutesUpdateService(App& app)
{
BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/")
- .privileges({"Login"})
+ .privileges({{"Login"}})
.methods(
boost::beast::http::verb::
get)([](const crow::Request&,
@@ -579,7 +579,7 @@
"xyz.openbmc_project.Software.ApplyTime", "RequestedApplyTime");
});
BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/")
- .privileges({"ConfigureComponents"})
+ .privileges({{"ConfigureComponents"}})
.methods(boost::beast::http::verb::patch)(
[](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
@@ -661,7 +661,7 @@
}
});
BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/")
- .privileges({"ConfigureComponents"})
+ .privileges({{"ConfigureComponents"}})
.methods(boost::beast::http::verb::post)(
[](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
@@ -687,7 +687,7 @@
inline void requestRoutesSoftwareInventoryCollection(App& app)
{
BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/FirmwareInventory/")
- .privileges({"Login"})
+ .privileges({{"Login"}})
.methods(boost::beast::http::verb::get)(
[](const crow::Request&,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
@@ -776,7 +776,7 @@
inline void requestRoutesSoftwareInventory(App& app)
{
BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/FirmwareInventory/<str>/")
- .privileges({"Login"})
+ .privileges({{"Login"}})
.methods(
boost::beast::http::verb::get)([](const crow::Request&,
const std::shared_ptr<