summaryrefslogtreecommitdiff
path: root/http/routing.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-02-27 08:42:46 +0300
committerEd Tanous <ed@tanous.net>2022-03-22 20:53:16 +0300
commitb9d36b4791d77a47e1f3c5c4564fcdf7cc68c115 (patch)
tree22a37e506310ded94a45aed79799929f94bac330 /http/routing.hpp
parenta2dd60a69046cdda90077463f614140aeb91edc4 (diff)
downloadbmcweb-b9d36b4791d77a47e1f3c5c4564fcdf7cc68c115.tar.xz
Consitently use dbus::utility types
This saves about 4k on the binary size Tested: Redfish service validator passes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I9546227a19c691b1aecb80e80307889548c0293f
Diffstat (limited to 'http/routing.hpp')
-rw-r--r--http/routing.hpp76
1 files changed, 37 insertions, 39 deletions
diff --git a/http/routing.hpp b/http/routing.hpp
index 5b819c582c..0fa2497905 100644
--- a/http/routing.hpp
+++ b/http/routing.hpp
@@ -1275,8 +1275,7 @@ class Router
crow::connections::systemBus->async_method_call(
[&req, asyncResp, &rules, ruleIndex,
found](const boost::system::error_code ec,
- const std::map<std::string, dbus::utility::DbusVariantType>&
- userInfo) {
+ const dbus::utility::DBusPropertiesMap& userInfoMap) {
if (ec)
{
BMCWEB_LOG_ERROR << "GetUserInfo failed...";
@@ -1284,30 +1283,42 @@ class Router
boost::beast::http::status::internal_server_error);
return;
}
-
- const std::string* userRolePtr = nullptr;
- auto userInfoIter = userInfo.find("UserPrivilege");
- if (userInfoIter != userInfo.end())
- {
- userRolePtr =
- std::get_if<std::string>(&userInfoIter->second);
- }
-
std::string userRole{};
- if (userRolePtr != nullptr)
- {
- userRole = *userRolePtr;
- BMCWEB_LOG_DEBUG << "userName = " << req.session->username
- << " userRole = " << *userRolePtr;
- }
+ const bool* remoteUser = nullptr;
+ std::optional<bool> passwordExpired;
- const bool* remoteUserPtr = nullptr;
- auto remoteUserIter = userInfo.find("RemoteUser");
- if (remoteUserIter != userInfo.end())
+ for (const auto& userInfo : userInfoMap)
{
- remoteUserPtr = std::get_if<bool>(&remoteUserIter->second);
+ if (userInfo.first == "UserPrivilege")
+ {
+ const std::string* userRolePtr =
+ std::get_if<std::string>(&userInfo.second);
+ if (userRolePtr == nullptr)
+ {
+ continue;
+ }
+ userRole = *userRolePtr;
+ BMCWEB_LOG_DEBUG
+ << "userName = " << req.session->username
+ << " userRole = " << *userRolePtr;
+ }
+ else if (userInfo.first == "RemoteUser")
+ {
+ remoteUser = std::get_if<bool>(&userInfo.second);
+ }
+ else if (userInfo.first == "UserPasswordExpired")
+ {
+ const bool* passwordExpiredPtr =
+ std::get_if<bool>(&userInfo.second);
+ if (passwordExpiredPtr == nullptr)
+ {
+ continue;
+ }
+ passwordExpired = *passwordExpiredPtr;
+ }
}
- if (remoteUserPtr == nullptr)
+
+ if (remoteUser == nullptr)
{
BMCWEB_LOG_ERROR
<< "RemoteUser property missing or wrong type";
@@ -1315,24 +1326,10 @@ class Router
boost::beast::http::status::internal_server_error);
return;
}
- bool remoteUser = *remoteUserPtr;
- bool passwordExpired = false; // default for remote user
- if (!remoteUser)
+ if (passwordExpired == std::nullopt)
{
- const bool* passwordExpiredPtr = nullptr;
- auto passwordExpiredIter =
- userInfo.find("UserPasswordExpired");
- if (passwordExpiredIter != userInfo.end())
- {
- passwordExpiredPtr =
- std::get_if<bool>(&passwordExpiredIter->second);
- }
- if (passwordExpiredPtr != nullptr)
- {
- passwordExpired = *passwordExpiredPtr;
- }
- else
+ if (!*remoteUser)
{
BMCWEB_LOG_ERROR
<< "UserPasswordExpired property is expected for"
@@ -1341,6 +1338,7 @@ class Router
boost::beast::http::status::internal_server_error);
return;
}
+ passwordExpired = false;
}
// Get the userprivileges from the role
@@ -1350,7 +1348,7 @@ class Router
// Set isConfigureSelfOnly based on D-Bus results. This
// ignores the results from both pamAuthenticateUser and the
// value from any previous use of this session.
- req.session->isConfigureSelfOnly = passwordExpired;
+ req.session->isConfigureSelfOnly = *passwordExpired;
// Modifyprivileges if isConfigureSelfOnly.
if (req.session->isConfigureSelfOnly)