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
diff --git a/http/routing.hpp b/http/routing.hpp
index 5b819c5..0fa2497 100644
--- a/http/routing.hpp
+++ b/http/routing.hpp
@@ -1275,8 +1275,7 @@
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 @@
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)
+ const bool* remoteUser = nullptr;
+ std::optional<bool> passwordExpired;
+
+ for (const auto& userInfo : userInfoMap)
{
- userRole = *userRolePtr;
- BMCWEB_LOG_DEBUG << "userName = " << req.session->username
- << " userRole = " << *userRolePtr;
+ 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;
+ }
}
- const bool* remoteUserPtr = nullptr;
- auto remoteUserIter = userInfo.find("RemoteUser");
- if (remoteUserIter != userInfo.end())
- {
- remoteUserPtr = std::get_if<bool>(&remoteUserIter->second);
- }
- if (remoteUserPtr == nullptr)
+ if (remoteUser == nullptr)
{
BMCWEB_LOG_ERROR
<< "RemoteUser property missing or wrong type";
@@ -1315,24 +1326,10 @@
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 @@
boost::beast::http::status::internal_server_error);
return;
}
+ passwordExpired = false;
}
// Get the userprivileges from the role
@@ -1350,7 +1348,7 @@
// 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)