summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/dbus_privileges.hpp68
1 files changed, 21 insertions, 47 deletions
diff --git a/include/dbus_privileges.hpp b/include/dbus_privileges.hpp
index 16aae5e62a..6602a5c2fa 100644
--- a/include/dbus_privileges.hpp
+++ b/include/dbus_privileges.hpp
@@ -19,75 +19,49 @@ namespace crow
// Populate session with user information.
inline bool
populateUserInfo(Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const dbus::utility::DBusPropertiesMap& userInfoMap)
{
- const std::string* userRolePtr = nullptr;
- const bool* remoteUser = nullptr;
- const bool* passwordExpired = nullptr;
- const std::vector<std::string>* userGroups = nullptr;
+ if (req.session == nullptr)
+ {
+ return false;
+ }
+
+ std::string userRole;
+ bool remoteUser = false;
+ std::optional<bool> passwordExpired;
+ std::optional<std::vector<std::string>> userGroups;
const bool success = sdbusplus::unpackPropertiesNoThrow(
redfish::dbus_utils::UnpackErrorPrinter(), userInfoMap, "UserPrivilege",
- userRolePtr, "RemoteUser", remoteUser, "UserPasswordExpired",
+ userRole, "RemoteUser", remoteUser, "UserPasswordExpired",
passwordExpired, "UserGroups", userGroups);
if (!success)
{
BMCWEB_LOG_ERROR("Failed to unpack user properties.");
- asyncResp->res.result(
- boost::beast::http::status::internal_server_error);
return false;
}
- if (req.session == nullptr)
+ if (!remoteUser && (!passwordExpired || !userGroups))
{
+ BMCWEB_LOG_ERROR(
+ "Missing UserPasswordExpired or UserGroups property for local user");
return false;
}
- if (userRolePtr != nullptr)
- {
- req.session->userRole = *userRolePtr;
- BMCWEB_LOG_DEBUG("userName = {} userRole = {}", req.session->username,
- *userRolePtr);
- }
-
- if (remoteUser == nullptr)
- {
- BMCWEB_LOG_ERROR("RemoteUser property missing or wrong type");
- asyncResp->res.result(
- boost::beast::http::status::internal_server_error);
- return false;
- }
- bool expired = false;
- if (passwordExpired == nullptr)
- {
- if (!*remoteUser)
- {
- BMCWEB_LOG_ERROR("UserPasswordExpired property is expected for"
- " local user but is missing or wrong type");
- asyncResp->res.result(
- boost::beast::http::status::internal_server_error);
- return false;
- }
- }
- else
- {
- expired = *passwordExpired;
- }
+ req.session->userRole = userRole;
+ BMCWEB_LOG_DEBUG("userName = {} userRole = {}", req.session->username,
+ userRole);
// 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 = expired;
+ req.session->isConfigureSelfOnly = passwordExpired.value_or(false);
- if (userGroups != nullptr)
- {
- req.session->userGroups = *userGroups;
- }
- else
+ req.session->userGroups.clear();
+ if (userGroups)
{
- req.session->userGroups.clear();
+ req.session->userGroups.swap(*userGroups);
}
return true;
@@ -147,7 +121,7 @@ void afterGetUserInfo(Request& req,
return;
}
- if (!populateUserInfo(req, asyncResp, userInfoMap))
+ if (!populateUserInfo(req, userInfoMap))
{
BMCWEB_LOG_ERROR("Failed to populate user information");
asyncResp->res.result(