From b9d36b4791d77a47e1f3c5c4564fcdf7cc68c115 Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Sat, 26 Feb 2022 21:42:46 -0800 Subject: Consitently use dbus::utility types This saves about 4k on the binary size Tested: Redfish service validator passes. Signed-off-by: Ed Tanous Change-Id: I9546227a19c691b1aecb80e80307889548c0293f --- http/routing.hpp | 76 +++++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 39 deletions(-) (limited to 'http/routing.hpp') 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& - 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(&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 passwordExpired; - const bool* remoteUserPtr = nullptr; - auto remoteUserIter = userInfo.find("RemoteUser"); - if (remoteUserIter != userInfo.end()) + for (const auto& userInfo : userInfoMap) { - remoteUserPtr = std::get_if(&remoteUserIter->second); + if (userInfo.first == "UserPrivilege") + { + const std::string* userRolePtr = + std::get_if(&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(&userInfo.second); + } + else if (userInfo.first == "UserPasswordExpired") + { + const bool* passwordExpiredPtr = + std::get_if(&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(&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) -- cgit v1.2.3