188d16c9aSLewanczyk, Dawid /* 288d16c9aSLewanczyk, Dawid // Copyright (c) 2018 Intel Corporation 388d16c9aSLewanczyk, Dawid // 488d16c9aSLewanczyk, Dawid // Licensed under the Apache License, Version 2.0 (the "License"); 588d16c9aSLewanczyk, Dawid // you may not use this file except in compliance with the License. 688d16c9aSLewanczyk, Dawid // You may obtain a copy of the License at 788d16c9aSLewanczyk, Dawid // 888d16c9aSLewanczyk, Dawid // http://www.apache.org/licenses/LICENSE-2.0 988d16c9aSLewanczyk, Dawid // 1088d16c9aSLewanczyk, Dawid // Unless required by applicable law or agreed to in writing, software 1188d16c9aSLewanczyk, Dawid // distributed under the License is distributed on an "AS IS" BASIS, 1288d16c9aSLewanczyk, Dawid // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1388d16c9aSLewanczyk, Dawid // See the License for the specific language governing permissions and 1488d16c9aSLewanczyk, Dawid // limitations under the License. 1588d16c9aSLewanczyk, Dawid */ 1688d16c9aSLewanczyk, Dawid #pragma once 1788d16c9aSLewanczyk, Dawid 187e860f15SJohn Edward Broadbent #include <app.hpp> 1924c8542dSRatan Gupta #include <dbus_utility.hpp> 2065b0dc32SEd Tanous #include <error_messages.hpp> 21b9b2e0b2SEd Tanous #include <openbmc_dbus_rest.hpp> 2252cc112dSEd Tanous #include <persistent_data.hpp> 23ed398213SEd Tanous #include <registries/privilege_registry.hpp> 24a840879dSEd Tanous #include <utils/json_utils.hpp> 251214b7e7SGunnar Mills 26abf2add6SEd Tanous #include <variant> 27b9b2e0b2SEd Tanous 281abe55efSEd Tanous namespace redfish 291abe55efSEd Tanous { 3088d16c9aSLewanczyk, Dawid 3123a21a1cSEd Tanous constexpr const char* ldapConfigObjectName = 326973a582SRatan Gupta "/xyz/openbmc_project/user/ldap/openldap"; 332c70f800SEd Tanous constexpr const char* adConfigObject = 34ab828d7cSRatan Gupta "/xyz/openbmc_project/user/ldap/active_directory"; 35ab828d7cSRatan Gupta 366973a582SRatan Gupta constexpr const char* ldapRootObject = "/xyz/openbmc_project/user/ldap"; 376973a582SRatan Gupta constexpr const char* ldapDbusService = "xyz.openbmc_project.Ldap.Config"; 386973a582SRatan Gupta constexpr const char* ldapConfigInterface = 396973a582SRatan Gupta "xyz.openbmc_project.User.Ldap.Config"; 406973a582SRatan Gupta constexpr const char* ldapCreateInterface = 416973a582SRatan Gupta "xyz.openbmc_project.User.Ldap.Create"; 426973a582SRatan Gupta constexpr const char* ldapEnableInterface = "xyz.openbmc_project.Object.Enable"; 4306785244SRatan Gupta constexpr const char* ldapPrivMapperInterface = 4406785244SRatan Gupta "xyz.openbmc_project.User.PrivilegeMapper"; 456973a582SRatan Gupta constexpr const char* dbusObjManagerIntf = "org.freedesktop.DBus.ObjectManager"; 466973a582SRatan Gupta constexpr const char* propertyInterface = "org.freedesktop.DBus.Properties"; 476973a582SRatan Gupta constexpr const char* mapperBusName = "xyz.openbmc_project.ObjectMapper"; 486973a582SRatan Gupta constexpr const char* mapperObjectPath = "/xyz/openbmc_project/object_mapper"; 496973a582SRatan Gupta constexpr const char* mapperIntf = "xyz.openbmc_project.ObjectMapper"; 506973a582SRatan Gupta 5154fc587aSNagaraju Goruganti struct LDAPRoleMapData 5254fc587aSNagaraju Goruganti { 5354fc587aSNagaraju Goruganti std::string groupName; 5454fc587aSNagaraju Goruganti std::string privilege; 5554fc587aSNagaraju Goruganti }; 5654fc587aSNagaraju Goruganti 576973a582SRatan Gupta struct LDAPConfigData 586973a582SRatan Gupta { 596973a582SRatan Gupta std::string uri{}; 606973a582SRatan Gupta std::string bindDN{}; 616973a582SRatan Gupta std::string baseDN{}; 626973a582SRatan Gupta std::string searchScope{}; 636973a582SRatan Gupta std::string serverType{}; 646973a582SRatan Gupta bool serviceEnabled = false; 656973a582SRatan Gupta std::string userNameAttribute{}; 666973a582SRatan Gupta std::string groupAttribute{}; 6754fc587aSNagaraju Goruganti std::vector<std::pair<std::string, LDAPRoleMapData>> groupRoleList; 686973a582SRatan Gupta }; 696973a582SRatan Gupta 7019bd78d9SPatrick Williams using DbusVariantType = std::variant<bool, int32_t, std::string>; 71107077deSPrzemyslaw Czarnowski 72107077deSPrzemyslaw Czarnowski using DbusInterfaceType = boost::container::flat_map< 73107077deSPrzemyslaw Czarnowski std::string, boost::container::flat_map<std::string, DbusVariantType>>; 74107077deSPrzemyslaw Czarnowski 75107077deSPrzemyslaw Czarnowski using ManagedObjectType = 76107077deSPrzemyslaw Czarnowski std::vector<std::pair<sdbusplus::message::object_path, DbusInterfaceType>>; 77107077deSPrzemyslaw Czarnowski 786973a582SRatan Gupta using GetObjectType = 796973a582SRatan Gupta std::vector<std::pair<std::string, std::vector<std::string>>>; 8084e12cb7SAppaRao Puli 8154fc587aSNagaraju Goruganti inline std::string getRoleIdFromPrivilege(std::string_view role) 8284e12cb7SAppaRao Puli { 8384e12cb7SAppaRao Puli if (role == "priv-admin") 8484e12cb7SAppaRao Puli { 8584e12cb7SAppaRao Puli return "Administrator"; 8684e12cb7SAppaRao Puli } 873174e4dfSEd Tanous if (role == "priv-user") 8884e12cb7SAppaRao Puli { 89c80fee55SAppaRao Puli return "ReadOnly"; 9084e12cb7SAppaRao Puli } 913174e4dfSEd Tanous if (role == "priv-operator") 9284e12cb7SAppaRao Puli { 9384e12cb7SAppaRao Puli return "Operator"; 9484e12cb7SAppaRao Puli } 953174e4dfSEd Tanous if ((role == "") || (role == "priv-noaccess")) 96e9e6d240Sjayaprakash Mutyala { 97e9e6d240Sjayaprakash Mutyala return "NoAccess"; 98e9e6d240Sjayaprakash Mutyala } 9984e12cb7SAppaRao Puli return ""; 10084e12cb7SAppaRao Puli } 10154fc587aSNagaraju Goruganti inline std::string getPrivilegeFromRoleId(std::string_view role) 10284e12cb7SAppaRao Puli { 10384e12cb7SAppaRao Puli if (role == "Administrator") 10484e12cb7SAppaRao Puli { 10584e12cb7SAppaRao Puli return "priv-admin"; 10684e12cb7SAppaRao Puli } 1073174e4dfSEd Tanous if (role == "ReadOnly") 10884e12cb7SAppaRao Puli { 10984e12cb7SAppaRao Puli return "priv-user"; 11084e12cb7SAppaRao Puli } 1113174e4dfSEd Tanous if (role == "Operator") 11284e12cb7SAppaRao Puli { 11384e12cb7SAppaRao Puli return "priv-operator"; 11484e12cb7SAppaRao Puli } 1153174e4dfSEd Tanous if ((role == "NoAccess") || (role == "")) 116e9e6d240Sjayaprakash Mutyala { 117e9e6d240Sjayaprakash Mutyala return "priv-noaccess"; 118e9e6d240Sjayaprakash Mutyala } 11984e12cb7SAppaRao Puli return ""; 12084e12cb7SAppaRao Puli } 121b9b2e0b2SEd Tanous 1228d1b46d7Szhanghch05 inline void userErrorMessageHandler( 1238d1b46d7Szhanghch05 const sd_bus_error* e, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1248d1b46d7Szhanghch05 const std::string& newUser, const std::string& username) 12566b5ca76Sjayaprakash Mutyala { 12666b5ca76Sjayaprakash Mutyala if (e == nullptr) 12766b5ca76Sjayaprakash Mutyala { 12866b5ca76Sjayaprakash Mutyala messages::internalError(asyncResp->res); 12966b5ca76Sjayaprakash Mutyala return; 13066b5ca76Sjayaprakash Mutyala } 13166b5ca76Sjayaprakash Mutyala 132055806b3SManojkiran Eda const char* errorMessage = e->name; 13366b5ca76Sjayaprakash Mutyala if (strcmp(errorMessage, 13466b5ca76Sjayaprakash Mutyala "xyz.openbmc_project.User.Common.Error.UserNameExists") == 0) 13566b5ca76Sjayaprakash Mutyala { 13666b5ca76Sjayaprakash Mutyala messages::resourceAlreadyExists(asyncResp->res, 1378114bd4dSGunnar Mills "#ManagerAccount.v1_4_0.ManagerAccount", 13866b5ca76Sjayaprakash Mutyala "UserName", newUser); 13966b5ca76Sjayaprakash Mutyala } 14066b5ca76Sjayaprakash Mutyala else if (strcmp(errorMessage, "xyz.openbmc_project.User.Common.Error." 14166b5ca76Sjayaprakash Mutyala "UserNameDoesNotExist") == 0) 14266b5ca76Sjayaprakash Mutyala { 14366b5ca76Sjayaprakash Mutyala messages::resourceNotFound( 1448114bd4dSGunnar Mills asyncResp->res, "#ManagerAccount.v1_4_0.ManagerAccount", username); 14566b5ca76Sjayaprakash Mutyala } 146d4d25793SEd Tanous else if ((strcmp(errorMessage, 147d4d25793SEd Tanous "xyz.openbmc_project.Common.Error.InvalidArgument") == 148d4d25793SEd Tanous 0) || 149d4d25793SEd Tanous (strcmp(errorMessage, "xyz.openbmc_project.User.Common.Error." 150d4d25793SEd Tanous "UserNameGroupFail") == 0)) 15166b5ca76Sjayaprakash Mutyala { 15266b5ca76Sjayaprakash Mutyala messages::propertyValueFormatError(asyncResp->res, newUser, "UserName"); 15366b5ca76Sjayaprakash Mutyala } 15466b5ca76Sjayaprakash Mutyala else if (strcmp(errorMessage, 15566b5ca76Sjayaprakash Mutyala "xyz.openbmc_project.User.Common.Error.NoResource") == 0) 15666b5ca76Sjayaprakash Mutyala { 15766b5ca76Sjayaprakash Mutyala messages::createLimitReachedForResource(asyncResp->res); 15866b5ca76Sjayaprakash Mutyala } 15966b5ca76Sjayaprakash Mutyala else 16066b5ca76Sjayaprakash Mutyala { 16166b5ca76Sjayaprakash Mutyala messages::internalError(asyncResp->res); 16266b5ca76Sjayaprakash Mutyala } 16366b5ca76Sjayaprakash Mutyala 16466b5ca76Sjayaprakash Mutyala return; 16566b5ca76Sjayaprakash Mutyala } 16666b5ca76Sjayaprakash Mutyala 16781ce609eSEd Tanous inline void parseLDAPConfigData(nlohmann::json& jsonResponse, 168ab828d7cSRatan Gupta const LDAPConfigData& confData, 169ab828d7cSRatan Gupta const std::string& ldapType) 1706973a582SRatan Gupta { 171ab828d7cSRatan Gupta std::string service = 172ab828d7cSRatan Gupta (ldapType == "LDAP") ? "LDAPService" : "ActiveDirectoryService"; 17337cce918SMarri Devender Rao nlohmann::json ldap = { 1746973a582SRatan Gupta {"ServiceEnabled", confData.serviceEnabled}, 1756973a582SRatan Gupta {"ServiceAddresses", nlohmann::json::array({confData.uri})}, 1766973a582SRatan Gupta {"Authentication", 1776973a582SRatan Gupta {{"AuthenticationType", "UsernameAndPassword"}, 1786973a582SRatan Gupta {"Username", confData.bindDN}, 1796973a582SRatan Gupta {"Password", nullptr}}}, 1806973a582SRatan Gupta {"LDAPService", 1816973a582SRatan Gupta {{"SearchSettings", 1826973a582SRatan Gupta {{"BaseDistinguishedNames", 1836973a582SRatan Gupta nlohmann::json::array({confData.baseDN})}, 1846973a582SRatan Gupta {"UsernameAttribute", confData.userNameAttribute}, 1856973a582SRatan Gupta {"GroupsAttribute", confData.groupAttribute}}}}}, 1866973a582SRatan Gupta }; 18754fc587aSNagaraju Goruganti 18881ce609eSEd Tanous jsonResponse[ldapType].update(ldap); 18954fc587aSNagaraju Goruganti 19081ce609eSEd Tanous nlohmann::json& roleMapArray = jsonResponse[ldapType]["RemoteRoleMapping"]; 19154fc587aSNagaraju Goruganti roleMapArray = nlohmann::json::array(); 19254fc587aSNagaraju Goruganti for (auto& obj : confData.groupRoleList) 19354fc587aSNagaraju Goruganti { 19454fc587aSNagaraju Goruganti BMCWEB_LOG_DEBUG << "Pushing the data groupName=" 19554fc587aSNagaraju Goruganti << obj.second.groupName << "\n"; 19654fc587aSNagaraju Goruganti roleMapArray.push_back( 19754fc587aSNagaraju Goruganti {nlohmann::json::array({"RemoteGroup", obj.second.groupName}), 19854fc587aSNagaraju Goruganti nlohmann::json::array( 19954fc587aSNagaraju Goruganti {"LocalRole", getRoleIdFromPrivilege(obj.second.privilege)})}); 20054fc587aSNagaraju Goruganti } 2016973a582SRatan Gupta } 2026973a582SRatan Gupta 2036973a582SRatan Gupta /** 20406785244SRatan Gupta * @brief validates given JSON input and then calls appropriate method to 20506785244SRatan Gupta * create, to delete or to set Rolemapping object based on the given input. 20606785244SRatan Gupta * 20706785244SRatan Gupta */ 20823a21a1cSEd Tanous inline void handleRoleMapPatch( 2098d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 21006785244SRatan Gupta const std::vector<std::pair<std::string, LDAPRoleMapData>>& roleMapObjData, 211f23b7296SEd Tanous const std::string& serverType, const std::vector<nlohmann::json>& input) 21206785244SRatan Gupta { 21306785244SRatan Gupta for (size_t index = 0; index < input.size(); index++) 21406785244SRatan Gupta { 215f23b7296SEd Tanous const nlohmann::json& thisJson = input[index]; 21606785244SRatan Gupta 21706785244SRatan Gupta if (thisJson.is_null()) 21806785244SRatan Gupta { 21906785244SRatan Gupta // delete the existing object 22006785244SRatan Gupta if (index < roleMapObjData.size()) 22106785244SRatan Gupta { 22206785244SRatan Gupta crow::connections::systemBus->async_method_call( 22306785244SRatan Gupta [asyncResp, roleMapObjData, serverType, 22406785244SRatan Gupta index](const boost::system::error_code ec) { 22506785244SRatan Gupta if (ec) 22606785244SRatan Gupta { 22706785244SRatan Gupta BMCWEB_LOG_ERROR << "DBUS response error: " << ec; 22806785244SRatan Gupta messages::internalError(asyncResp->res); 22906785244SRatan Gupta return; 23006785244SRatan Gupta } 23106785244SRatan Gupta asyncResp->res 23206785244SRatan Gupta .jsonValue[serverType]["RemoteRoleMapping"][index] = 23306785244SRatan Gupta nullptr; 23406785244SRatan Gupta }, 23506785244SRatan Gupta ldapDbusService, roleMapObjData[index].first, 23606785244SRatan Gupta "xyz.openbmc_project.Object.Delete", "Delete"); 23706785244SRatan Gupta } 23806785244SRatan Gupta else 23906785244SRatan Gupta { 24006785244SRatan Gupta BMCWEB_LOG_ERROR << "Can't delete the object"; 24106785244SRatan Gupta messages::propertyValueTypeError( 24271f52d96SEd Tanous asyncResp->res, 24371f52d96SEd Tanous thisJson.dump(2, ' ', true, 24471f52d96SEd Tanous nlohmann::json::error_handler_t::replace), 24506785244SRatan Gupta "RemoteRoleMapping/" + std::to_string(index)); 24606785244SRatan Gupta return; 24706785244SRatan Gupta } 24806785244SRatan Gupta } 24906785244SRatan Gupta else if (thisJson.empty()) 25006785244SRatan Gupta { 25106785244SRatan Gupta // Don't do anything for the empty objects,parse next json 25206785244SRatan Gupta // eg {"RemoteRoleMapping",[{}]} 25306785244SRatan Gupta } 25406785244SRatan Gupta else 25506785244SRatan Gupta { 25606785244SRatan Gupta // update/create the object 25706785244SRatan Gupta std::optional<std::string> remoteGroup; 25806785244SRatan Gupta std::optional<std::string> localRole; 25906785244SRatan Gupta 260f23b7296SEd Tanous // This is a copy, but it's required in this case because of how 261f23b7296SEd Tanous // readJson is structured 262f23b7296SEd Tanous nlohmann::json thisJsonCopy = thisJson; 263f23b7296SEd Tanous if (!json_util::readJson(thisJsonCopy, asyncResp->res, 264f23b7296SEd Tanous "RemoteGroup", remoteGroup, "LocalRole", 265f23b7296SEd Tanous localRole)) 26606785244SRatan Gupta { 26706785244SRatan Gupta continue; 26806785244SRatan Gupta } 26906785244SRatan Gupta 27006785244SRatan Gupta // Update existing RoleMapping Object 27106785244SRatan Gupta if (index < roleMapObjData.size()) 27206785244SRatan Gupta { 27306785244SRatan Gupta BMCWEB_LOG_DEBUG << "Update Role Map Object"; 27406785244SRatan Gupta // If "RemoteGroup" info is provided 27506785244SRatan Gupta if (remoteGroup) 27606785244SRatan Gupta { 27706785244SRatan Gupta crow::connections::systemBus->async_method_call( 27806785244SRatan Gupta [asyncResp, roleMapObjData, serverType, index, 27906785244SRatan Gupta remoteGroup](const boost::system::error_code ec) { 28006785244SRatan Gupta if (ec) 28106785244SRatan Gupta { 28206785244SRatan Gupta BMCWEB_LOG_ERROR << "DBUS response error: " 28306785244SRatan Gupta << ec; 28406785244SRatan Gupta messages::internalError(asyncResp->res); 28506785244SRatan Gupta return; 28606785244SRatan Gupta } 28706785244SRatan Gupta asyncResp->res 28806785244SRatan Gupta .jsonValue[serverType]["RemoteRoleMapping"] 28906785244SRatan Gupta [index]["RemoteGroup"] = *remoteGroup; 29006785244SRatan Gupta }, 29106785244SRatan Gupta ldapDbusService, roleMapObjData[index].first, 29206785244SRatan Gupta propertyInterface, "Set", 29306785244SRatan Gupta "xyz.openbmc_project.User.PrivilegeMapperEntry", 29406785244SRatan Gupta "GroupName", 29506785244SRatan Gupta std::variant<std::string>(std::move(*remoteGroup))); 29606785244SRatan Gupta } 29706785244SRatan Gupta 29806785244SRatan Gupta // If "LocalRole" info is provided 29906785244SRatan Gupta if (localRole) 30006785244SRatan Gupta { 30106785244SRatan Gupta crow::connections::systemBus->async_method_call( 30206785244SRatan Gupta [asyncResp, roleMapObjData, serverType, index, 30306785244SRatan Gupta localRole](const boost::system::error_code ec) { 30406785244SRatan Gupta if (ec) 30506785244SRatan Gupta { 30606785244SRatan Gupta BMCWEB_LOG_ERROR << "DBUS response error: " 30706785244SRatan Gupta << ec; 30806785244SRatan Gupta messages::internalError(asyncResp->res); 30906785244SRatan Gupta return; 31006785244SRatan Gupta } 31106785244SRatan Gupta asyncResp->res 31206785244SRatan Gupta .jsonValue[serverType]["RemoteRoleMapping"] 31306785244SRatan Gupta [index]["LocalRole"] = *localRole; 31406785244SRatan Gupta }, 31506785244SRatan Gupta ldapDbusService, roleMapObjData[index].first, 31606785244SRatan Gupta propertyInterface, "Set", 31706785244SRatan Gupta "xyz.openbmc_project.User.PrivilegeMapperEntry", 31806785244SRatan Gupta "Privilege", 31906785244SRatan Gupta std::variant<std::string>( 32006785244SRatan Gupta getPrivilegeFromRoleId(std::move(*localRole)))); 32106785244SRatan Gupta } 32206785244SRatan Gupta } 32306785244SRatan Gupta // Create a new RoleMapping Object. 32406785244SRatan Gupta else 32506785244SRatan Gupta { 32606785244SRatan Gupta BMCWEB_LOG_DEBUG 32706785244SRatan Gupta << "setRoleMappingProperties: Creating new Object"; 32806785244SRatan Gupta std::string pathString = 32906785244SRatan Gupta "RemoteRoleMapping/" + std::to_string(index); 33006785244SRatan Gupta 33106785244SRatan Gupta if (!localRole) 33206785244SRatan Gupta { 33306785244SRatan Gupta messages::propertyMissing(asyncResp->res, 33406785244SRatan Gupta pathString + "/LocalRole"); 33506785244SRatan Gupta continue; 33606785244SRatan Gupta } 33706785244SRatan Gupta if (!remoteGroup) 33806785244SRatan Gupta { 33906785244SRatan Gupta messages::propertyMissing(asyncResp->res, 34006785244SRatan Gupta pathString + "/RemoteGroup"); 34106785244SRatan Gupta continue; 34206785244SRatan Gupta } 34306785244SRatan Gupta 34406785244SRatan Gupta std::string dbusObjectPath; 34506785244SRatan Gupta if (serverType == "ActiveDirectory") 34606785244SRatan Gupta { 3472c70f800SEd Tanous dbusObjectPath = adConfigObject; 34806785244SRatan Gupta } 34906785244SRatan Gupta else if (serverType == "LDAP") 35006785244SRatan Gupta { 35123a21a1cSEd Tanous dbusObjectPath = ldapConfigObjectName; 35206785244SRatan Gupta } 35306785244SRatan Gupta 35406785244SRatan Gupta BMCWEB_LOG_DEBUG << "Remote Group=" << *remoteGroup 35506785244SRatan Gupta << ",LocalRole=" << *localRole; 35606785244SRatan Gupta 35706785244SRatan Gupta crow::connections::systemBus->async_method_call( 358271584abSEd Tanous [asyncResp, serverType, localRole, 35906785244SRatan Gupta remoteGroup](const boost::system::error_code ec) { 36006785244SRatan Gupta if (ec) 36106785244SRatan Gupta { 36206785244SRatan Gupta BMCWEB_LOG_ERROR << "DBUS response error: " << ec; 36306785244SRatan Gupta messages::internalError(asyncResp->res); 36406785244SRatan Gupta return; 36506785244SRatan Gupta } 36606785244SRatan Gupta nlohmann::json& remoteRoleJson = 36706785244SRatan Gupta asyncResp->res 36806785244SRatan Gupta .jsonValue[serverType]["RemoteRoleMapping"]; 36906785244SRatan Gupta remoteRoleJson.push_back( 37006785244SRatan Gupta {{"LocalRole", *localRole}, 37106785244SRatan Gupta {"RemoteGroup", *remoteGroup}}); 37206785244SRatan Gupta }, 37306785244SRatan Gupta ldapDbusService, dbusObjectPath, ldapPrivMapperInterface, 3743174e4dfSEd Tanous "Create", *remoteGroup, 37506785244SRatan Gupta getPrivilegeFromRoleId(std::move(*localRole))); 37606785244SRatan Gupta } 37706785244SRatan Gupta } 37806785244SRatan Gupta } 37906785244SRatan Gupta } 38006785244SRatan Gupta 38106785244SRatan Gupta /** 3826973a582SRatan Gupta * Function that retrieves all properties for LDAP config object 3836973a582SRatan Gupta * into JSON 3846973a582SRatan Gupta */ 3856973a582SRatan Gupta template <typename CallbackFunc> 3866973a582SRatan Gupta inline void getLDAPConfigData(const std::string& ldapType, 3876973a582SRatan Gupta CallbackFunc&& callback) 3886973a582SRatan Gupta { 38954fc587aSNagaraju Goruganti 39054fc587aSNagaraju Goruganti const std::array<const char*, 2> interfaces = {ldapEnableInterface, 39154fc587aSNagaraju Goruganti ldapConfigInterface}; 39254fc587aSNagaraju Goruganti 39354fc587aSNagaraju Goruganti crow::connections::systemBus->async_method_call( 39454fc587aSNagaraju Goruganti [callback, ldapType](const boost::system::error_code ec, 39554fc587aSNagaraju Goruganti const GetObjectType& resp) { 39654fc587aSNagaraju Goruganti if (ec || resp.empty()) 39754fc587aSNagaraju Goruganti { 39854fc587aSNagaraju Goruganti BMCWEB_LOG_ERROR << "DBUS response error during getting of " 39954fc587aSNagaraju Goruganti "service name: " 40054fc587aSNagaraju Goruganti << ec; 40123a21a1cSEd Tanous LDAPConfigData empty{}; 40223a21a1cSEd Tanous callback(false, empty, ldapType); 40354fc587aSNagaraju Goruganti return; 40454fc587aSNagaraju Goruganti } 40554fc587aSNagaraju Goruganti std::string service = resp.begin()->first; 40654fc587aSNagaraju Goruganti crow::connections::systemBus->async_method_call( 40781ce609eSEd Tanous [callback, ldapType](const boost::system::error_code errorCode, 4086973a582SRatan Gupta const ManagedObjectType& ldapObjects) { 4096973a582SRatan Gupta LDAPConfigData confData{}; 41081ce609eSEd Tanous if (errorCode) 4116973a582SRatan Gupta { 412ab828d7cSRatan Gupta callback(false, confData, ldapType); 41354fc587aSNagaraju Goruganti BMCWEB_LOG_ERROR << "D-Bus responses error: " 41481ce609eSEd Tanous << errorCode; 4156973a582SRatan Gupta return; 4166973a582SRatan Gupta } 417ab828d7cSRatan Gupta 418ab828d7cSRatan Gupta std::string ldapDbusType; 41954fc587aSNagaraju Goruganti std::string searchString; 42054fc587aSNagaraju Goruganti 421ab828d7cSRatan Gupta if (ldapType == "LDAP") 422ab828d7cSRatan Gupta { 42354fc587aSNagaraju Goruganti ldapDbusType = "xyz.openbmc_project.User.Ldap.Config." 42454fc587aSNagaraju Goruganti "Type.OpenLdap"; 42554fc587aSNagaraju Goruganti searchString = "openldap"; 426ab828d7cSRatan Gupta } 427ab828d7cSRatan Gupta else if (ldapType == "ActiveDirectory") 428ab828d7cSRatan Gupta { 42954fc587aSNagaraju Goruganti ldapDbusType = 43054fc587aSNagaraju Goruganti "xyz.openbmc_project.User.Ldap.Config.Type." 431ab828d7cSRatan Gupta "ActiveDirectory"; 43254fc587aSNagaraju Goruganti searchString = "active_directory"; 433ab828d7cSRatan Gupta } 434ab828d7cSRatan Gupta else 435ab828d7cSRatan Gupta { 43654fc587aSNagaraju Goruganti BMCWEB_LOG_ERROR 43754fc587aSNagaraju Goruganti << "Can't get the DbusType for the given type=" 438ab828d7cSRatan Gupta << ldapType; 439ab828d7cSRatan Gupta callback(false, confData, ldapType); 440ab828d7cSRatan Gupta return; 441ab828d7cSRatan Gupta } 442ab828d7cSRatan Gupta 443ab828d7cSRatan Gupta std::string ldapEnableInterfaceStr = ldapEnableInterface; 444ab828d7cSRatan Gupta std::string ldapConfigInterfaceStr = ldapConfigInterface; 445ab828d7cSRatan Gupta 4466973a582SRatan Gupta for (const auto& object : ldapObjects) 4476973a582SRatan Gupta { 44854fc587aSNagaraju Goruganti // let's find the object whose ldap type is equal to the 44954fc587aSNagaraju Goruganti // given type 45054fc587aSNagaraju Goruganti if (object.first.str.find(searchString) == 45154fc587aSNagaraju Goruganti std::string::npos) 4526973a582SRatan Gupta { 453ab828d7cSRatan Gupta continue; 454ab828d7cSRatan Gupta } 455ab828d7cSRatan Gupta 4566973a582SRatan Gupta for (const auto& interface : object.second) 4576973a582SRatan Gupta { 4586973a582SRatan Gupta if (interface.first == ldapEnableInterfaceStr) 4596973a582SRatan Gupta { 4606973a582SRatan Gupta // rest of the properties are string. 4616973a582SRatan Gupta for (const auto& property : interface.second) 4626973a582SRatan Gupta { 4636973a582SRatan Gupta if (property.first == "Enabled") 4646973a582SRatan Gupta { 4656973a582SRatan Gupta const bool* value = 4666973a582SRatan Gupta std::get_if<bool>(&property.second); 4676973a582SRatan Gupta if (value == nullptr) 4686973a582SRatan Gupta { 4696973a582SRatan Gupta continue; 4706973a582SRatan Gupta } 4716973a582SRatan Gupta confData.serviceEnabled = *value; 4726973a582SRatan Gupta break; 4736973a582SRatan Gupta } 4746973a582SRatan Gupta } 4756973a582SRatan Gupta } 4766973a582SRatan Gupta else if (interface.first == ldapConfigInterfaceStr) 4776973a582SRatan Gupta { 4786973a582SRatan Gupta 4796973a582SRatan Gupta for (const auto& property : interface.second) 4806973a582SRatan Gupta { 481271584abSEd Tanous const std::string* strValue = 48254fc587aSNagaraju Goruganti std::get_if<std::string>( 48354fc587aSNagaraju Goruganti &property.second); 484271584abSEd Tanous if (strValue == nullptr) 4856973a582SRatan Gupta { 4866973a582SRatan Gupta continue; 4876973a582SRatan Gupta } 4886973a582SRatan Gupta if (property.first == "LDAPServerURI") 4896973a582SRatan Gupta { 490271584abSEd Tanous confData.uri = *strValue; 4916973a582SRatan Gupta } 4926973a582SRatan Gupta else if (property.first == "LDAPBindDN") 4936973a582SRatan Gupta { 494271584abSEd Tanous confData.bindDN = *strValue; 4956973a582SRatan Gupta } 4966973a582SRatan Gupta else if (property.first == "LDAPBaseDN") 4976973a582SRatan Gupta { 498271584abSEd Tanous confData.baseDN = *strValue; 4996973a582SRatan Gupta } 50054fc587aSNagaraju Goruganti else if (property.first == 50154fc587aSNagaraju Goruganti "LDAPSearchScope") 5026973a582SRatan Gupta { 503271584abSEd Tanous confData.searchScope = *strValue; 5046973a582SRatan Gupta } 50554fc587aSNagaraju Goruganti else if (property.first == 50654fc587aSNagaraju Goruganti "GroupNameAttribute") 5076973a582SRatan Gupta { 508271584abSEd Tanous confData.groupAttribute = *strValue; 5096973a582SRatan Gupta } 51054fc587aSNagaraju Goruganti else if (property.first == 51154fc587aSNagaraju Goruganti "UserNameAttribute") 5126973a582SRatan Gupta { 513271584abSEd Tanous confData.userNameAttribute = *strValue; 5146973a582SRatan Gupta } 51554fc587aSNagaraju Goruganti else if (property.first == "LDAPType") 516ab828d7cSRatan Gupta { 517271584abSEd Tanous confData.serverType = *strValue; 51854fc587aSNagaraju Goruganti } 51954fc587aSNagaraju Goruganti } 52054fc587aSNagaraju Goruganti } 52154fc587aSNagaraju Goruganti else if (interface.first == 52254fc587aSNagaraju Goruganti "xyz.openbmc_project.User." 52354fc587aSNagaraju Goruganti "PrivilegeMapperEntry") 52454fc587aSNagaraju Goruganti { 52554fc587aSNagaraju Goruganti LDAPRoleMapData roleMapData{}; 52654fc587aSNagaraju Goruganti for (const auto& property : interface.second) 52754fc587aSNagaraju Goruganti { 528271584abSEd Tanous const std::string* strValue = 52954fc587aSNagaraju Goruganti std::get_if<std::string>( 53054fc587aSNagaraju Goruganti &property.second); 53154fc587aSNagaraju Goruganti 532271584abSEd Tanous if (strValue == nullptr) 53354fc587aSNagaraju Goruganti { 53454fc587aSNagaraju Goruganti continue; 53554fc587aSNagaraju Goruganti } 53654fc587aSNagaraju Goruganti 53754fc587aSNagaraju Goruganti if (property.first == "GroupName") 53854fc587aSNagaraju Goruganti { 539271584abSEd Tanous roleMapData.groupName = *strValue; 54054fc587aSNagaraju Goruganti } 54154fc587aSNagaraju Goruganti else if (property.first == "Privilege") 54254fc587aSNagaraju Goruganti { 543271584abSEd Tanous roleMapData.privilege = *strValue; 54454fc587aSNagaraju Goruganti } 54554fc587aSNagaraju Goruganti } 54654fc587aSNagaraju Goruganti 5470f0353b6SEd Tanous confData.groupRoleList.emplace_back( 5480f0353b6SEd Tanous object.first.str, roleMapData); 54954fc587aSNagaraju Goruganti } 55054fc587aSNagaraju Goruganti } 55154fc587aSNagaraju Goruganti } 552ab828d7cSRatan Gupta callback(true, confData, ldapType); 55354fc587aSNagaraju Goruganti }, 55454fc587aSNagaraju Goruganti service, ldapRootObject, dbusObjManagerIntf, 5556973a582SRatan Gupta "GetManagedObjects"); 55654fc587aSNagaraju Goruganti }, 55754fc587aSNagaraju Goruganti mapperBusName, mapperObjectPath, mapperIntf, "GetObject", 55823a21a1cSEd Tanous ldapConfigObjectName, interfaces); 5596973a582SRatan Gupta } 5606973a582SRatan Gupta 5618a07d286SRatan Gupta /** 5628a07d286SRatan Gupta * @brief parses the authentication section under the LDAP 5638a07d286SRatan Gupta * @param input JSON data 5648a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 5658a07d286SRatan Gupta * @param userName userName to be filled from the given JSON. 5668a07d286SRatan Gupta * @param password password to be filled from the given JSON. 5678a07d286SRatan Gupta */ 5684f48d5f6SEd Tanous inline void parseLDAPAuthenticationJson( 5696c51eab1SEd Tanous nlohmann::json input, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 5706c51eab1SEd Tanous std::optional<std::string>& username, std::optional<std::string>& password) 5718a07d286SRatan Gupta { 5728a07d286SRatan Gupta std::optional<std::string> authType; 5738a07d286SRatan Gupta 5748a07d286SRatan Gupta if (!json_util::readJson(input, asyncResp->res, "AuthenticationType", 5758a07d286SRatan Gupta authType, "Username", username, "Password", 5768a07d286SRatan Gupta password)) 5778a07d286SRatan Gupta { 5788a07d286SRatan Gupta return; 5798a07d286SRatan Gupta } 5808a07d286SRatan Gupta if (!authType) 5818a07d286SRatan Gupta { 5828a07d286SRatan Gupta return; 5838a07d286SRatan Gupta } 5848a07d286SRatan Gupta if (*authType != "UsernameAndPassword") 5858a07d286SRatan Gupta { 5868a07d286SRatan Gupta messages::propertyValueNotInList(asyncResp->res, *authType, 5878a07d286SRatan Gupta "AuthenticationType"); 5888a07d286SRatan Gupta return; 5898a07d286SRatan Gupta } 5908a07d286SRatan Gupta } 5918a07d286SRatan Gupta /** 5928a07d286SRatan Gupta * @brief parses the LDAPService section under the LDAP 5938a07d286SRatan Gupta * @param input JSON data 5948a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 5958a07d286SRatan Gupta * @param baseDNList baseDN to be filled from the given JSON. 5968a07d286SRatan Gupta * @param userNameAttribute userName to be filled from the given JSON. 5978a07d286SRatan Gupta * @param groupaAttribute password to be filled from the given JSON. 5988a07d286SRatan Gupta */ 5998a07d286SRatan Gupta 6004f48d5f6SEd Tanous inline void 6014f48d5f6SEd Tanous parseLDAPServiceJson(nlohmann::json input, 6028d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6038a07d286SRatan Gupta std::optional<std::vector<std::string>>& baseDNList, 6048a07d286SRatan Gupta std::optional<std::string>& userNameAttribute, 6058a07d286SRatan Gupta std::optional<std::string>& groupsAttribute) 6068a07d286SRatan Gupta { 6078a07d286SRatan Gupta std::optional<nlohmann::json> searchSettings; 6088a07d286SRatan Gupta 6098a07d286SRatan Gupta if (!json_util::readJson(input, asyncResp->res, "SearchSettings", 6108a07d286SRatan Gupta searchSettings)) 6118a07d286SRatan Gupta { 6128a07d286SRatan Gupta return; 6138a07d286SRatan Gupta } 6148a07d286SRatan Gupta if (!searchSettings) 6158a07d286SRatan Gupta { 6168a07d286SRatan Gupta return; 6178a07d286SRatan Gupta } 6188a07d286SRatan Gupta if (!json_util::readJson(*searchSettings, asyncResp->res, 6198a07d286SRatan Gupta "BaseDistinguishedNames", baseDNList, 6208a07d286SRatan Gupta "UsernameAttribute", userNameAttribute, 6218a07d286SRatan Gupta "GroupsAttribute", groupsAttribute)) 6228a07d286SRatan Gupta { 6238a07d286SRatan Gupta return; 6248a07d286SRatan Gupta } 6258a07d286SRatan Gupta } 6268a07d286SRatan Gupta /** 6278a07d286SRatan Gupta * @brief updates the LDAP server address and updates the 6288a07d286SRatan Gupta json response with the new value. 6298a07d286SRatan Gupta * @param serviceAddressList address to be updated. 6308a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 6318a07d286SRatan Gupta * @param ldapServerElementName Type of LDAP 6328a07d286SRatan Gupta server(openLDAP/ActiveDirectory) 6338a07d286SRatan Gupta */ 6348a07d286SRatan Gupta 6354f48d5f6SEd Tanous inline void handleServiceAddressPatch( 6368a07d286SRatan Gupta const std::vector<std::string>& serviceAddressList, 6378d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6388a07d286SRatan Gupta const std::string& ldapServerElementName, 6398a07d286SRatan Gupta const std::string& ldapConfigObject) 6408a07d286SRatan Gupta { 6418a07d286SRatan Gupta crow::connections::systemBus->async_method_call( 6428a07d286SRatan Gupta [asyncResp, ldapServerElementName, 6438a07d286SRatan Gupta serviceAddressList](const boost::system::error_code ec) { 6448a07d286SRatan Gupta if (ec) 6458a07d286SRatan Gupta { 6468a07d286SRatan Gupta BMCWEB_LOG_DEBUG 647c61704abSGunnar Mills << "Error Occurred in updating the service address"; 6488a07d286SRatan Gupta messages::internalError(asyncResp->res); 6498a07d286SRatan Gupta return; 6508a07d286SRatan Gupta } 6518a07d286SRatan Gupta std::vector<std::string> modifiedserviceAddressList = { 6528a07d286SRatan Gupta serviceAddressList.front()}; 6538a07d286SRatan Gupta asyncResp->res 6548a07d286SRatan Gupta .jsonValue[ldapServerElementName]["ServiceAddresses"] = 6558a07d286SRatan Gupta modifiedserviceAddressList; 6568a07d286SRatan Gupta if ((serviceAddressList).size() > 1) 6578a07d286SRatan Gupta { 6588a07d286SRatan Gupta messages::propertyValueModified(asyncResp->res, 6598a07d286SRatan Gupta "ServiceAddresses", 6608a07d286SRatan Gupta serviceAddressList.front()); 6618a07d286SRatan Gupta } 6628a07d286SRatan Gupta BMCWEB_LOG_DEBUG << "Updated the service address"; 6638a07d286SRatan Gupta }, 6648a07d286SRatan Gupta ldapDbusService, ldapConfigObject, propertyInterface, "Set", 6658a07d286SRatan Gupta ldapConfigInterface, "LDAPServerURI", 6668a07d286SRatan Gupta std::variant<std::string>(serviceAddressList.front())); 6678a07d286SRatan Gupta } 6688a07d286SRatan Gupta /** 6698a07d286SRatan Gupta * @brief updates the LDAP Bind DN and updates the 6708a07d286SRatan Gupta json response with the new value. 6718a07d286SRatan Gupta * @param username name of the user which needs to be updated. 6728a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 6738a07d286SRatan Gupta * @param ldapServerElementName Type of LDAP 6748a07d286SRatan Gupta server(openLDAP/ActiveDirectory) 6758a07d286SRatan Gupta */ 6768a07d286SRatan Gupta 6774f48d5f6SEd Tanous inline void 6784f48d5f6SEd Tanous handleUserNamePatch(const std::string& username, 6798d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6808a07d286SRatan Gupta const std::string& ldapServerElementName, 6818a07d286SRatan Gupta const std::string& ldapConfigObject) 6828a07d286SRatan Gupta { 6838a07d286SRatan Gupta crow::connections::systemBus->async_method_call( 6848a07d286SRatan Gupta [asyncResp, username, 6858a07d286SRatan Gupta ldapServerElementName](const boost::system::error_code ec) { 6868a07d286SRatan Gupta if (ec) 6878a07d286SRatan Gupta { 6886c51eab1SEd Tanous BMCWEB_LOG_DEBUG << "Error occurred in updating the username"; 6898a07d286SRatan Gupta messages::internalError(asyncResp->res); 6908a07d286SRatan Gupta return; 6918a07d286SRatan Gupta } 6926c51eab1SEd Tanous asyncResp->res.jsonValue[ldapServerElementName]["Authentication"] 6936c51eab1SEd Tanous ["Username"] = username; 6948a07d286SRatan Gupta BMCWEB_LOG_DEBUG << "Updated the username"; 6958a07d286SRatan Gupta }, 6968a07d286SRatan Gupta ldapDbusService, ldapConfigObject, propertyInterface, "Set", 6976c51eab1SEd Tanous ldapConfigInterface, "LDAPBindDN", std::variant<std::string>(username)); 6988a07d286SRatan Gupta } 6998a07d286SRatan Gupta 7008a07d286SRatan Gupta /** 7018a07d286SRatan Gupta * @brief updates the LDAP password 7028a07d286SRatan Gupta * @param password : ldap password which needs to be updated. 7038a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 7048a07d286SRatan Gupta * @param ldapServerElementName Type of LDAP 7058a07d286SRatan Gupta * server(openLDAP/ActiveDirectory) 7068a07d286SRatan Gupta */ 7078a07d286SRatan Gupta 7084f48d5f6SEd Tanous inline void 7094f48d5f6SEd Tanous handlePasswordPatch(const std::string& password, 7108d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7118a07d286SRatan Gupta const std::string& ldapServerElementName, 7128a07d286SRatan Gupta const std::string& ldapConfigObject) 7138a07d286SRatan Gupta { 7148a07d286SRatan Gupta crow::connections::systemBus->async_method_call( 7158a07d286SRatan Gupta [asyncResp, password, 7168a07d286SRatan Gupta ldapServerElementName](const boost::system::error_code ec) { 7178a07d286SRatan Gupta if (ec) 7188a07d286SRatan Gupta { 7196c51eab1SEd Tanous BMCWEB_LOG_DEBUG << "Error occurred in updating the password"; 7208a07d286SRatan Gupta messages::internalError(asyncResp->res); 7218a07d286SRatan Gupta return; 7228a07d286SRatan Gupta } 7236c51eab1SEd Tanous asyncResp->res.jsonValue[ldapServerElementName]["Authentication"] 7246c51eab1SEd Tanous ["Password"] = ""; 7258a07d286SRatan Gupta BMCWEB_LOG_DEBUG << "Updated the password"; 7268a07d286SRatan Gupta }, 7278a07d286SRatan Gupta ldapDbusService, ldapConfigObject, propertyInterface, "Set", 7288a07d286SRatan Gupta ldapConfigInterface, "LDAPBindDNPassword", 7298a07d286SRatan Gupta std::variant<std::string>(password)); 7308a07d286SRatan Gupta } 7318a07d286SRatan Gupta 7328a07d286SRatan Gupta /** 7338a07d286SRatan Gupta * @brief updates the LDAP BaseDN and updates the 7348a07d286SRatan Gupta json response with the new value. 7358a07d286SRatan Gupta * @param baseDNList baseDN list which needs to be updated. 7368a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 7378a07d286SRatan Gupta * @param ldapServerElementName Type of LDAP 7388a07d286SRatan Gupta server(openLDAP/ActiveDirectory) 7398a07d286SRatan Gupta */ 7408a07d286SRatan Gupta 7414f48d5f6SEd Tanous inline void 7424f48d5f6SEd Tanous handleBaseDNPatch(const std::vector<std::string>& baseDNList, 7438d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7448a07d286SRatan Gupta const std::string& ldapServerElementName, 7458a07d286SRatan Gupta const std::string& ldapConfigObject) 7468a07d286SRatan Gupta { 7478a07d286SRatan Gupta crow::connections::systemBus->async_method_call( 7488a07d286SRatan Gupta [asyncResp, baseDNList, 7498a07d286SRatan Gupta ldapServerElementName](const boost::system::error_code ec) { 7508a07d286SRatan Gupta if (ec) 7518a07d286SRatan Gupta { 7526c51eab1SEd Tanous BMCWEB_LOG_DEBUG << "Error Occurred in Updating the base DN"; 7538a07d286SRatan Gupta messages::internalError(asyncResp->res); 7548a07d286SRatan Gupta return; 7558a07d286SRatan Gupta } 7568a07d286SRatan Gupta auto& serverTypeJson = 7578a07d286SRatan Gupta asyncResp->res.jsonValue[ldapServerElementName]; 7588a07d286SRatan Gupta auto& searchSettingsJson = 7598a07d286SRatan Gupta serverTypeJson["LDAPService"]["SearchSettings"]; 7606c51eab1SEd Tanous std::vector<std::string> modifiedBaseDNList = {baseDNList.front()}; 7616c51eab1SEd Tanous searchSettingsJson["BaseDistinguishedNames"] = modifiedBaseDNList; 7628a07d286SRatan Gupta if (baseDNList.size() > 1) 7638a07d286SRatan Gupta { 7648a07d286SRatan Gupta messages::propertyValueModified(asyncResp->res, 7658a07d286SRatan Gupta "BaseDistinguishedNames", 7668a07d286SRatan Gupta baseDNList.front()); 7678a07d286SRatan Gupta } 7688a07d286SRatan Gupta BMCWEB_LOG_DEBUG << "Updated the base DN"; 7698a07d286SRatan Gupta }, 7708a07d286SRatan Gupta ldapDbusService, ldapConfigObject, propertyInterface, "Set", 7718a07d286SRatan Gupta ldapConfigInterface, "LDAPBaseDN", 7728a07d286SRatan Gupta std::variant<std::string>(baseDNList.front())); 7738a07d286SRatan Gupta } 7748a07d286SRatan Gupta /** 7758a07d286SRatan Gupta * @brief updates the LDAP user name attribute and updates the 7768a07d286SRatan Gupta json response with the new value. 7778a07d286SRatan Gupta * @param userNameAttribute attribute to be updated. 7788a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 7798a07d286SRatan Gupta * @param ldapServerElementName Type of LDAP 7808a07d286SRatan Gupta server(openLDAP/ActiveDirectory) 7818a07d286SRatan Gupta */ 7828a07d286SRatan Gupta 7834f48d5f6SEd Tanous inline void 7844f48d5f6SEd Tanous handleUserNameAttrPatch(const std::string& userNameAttribute, 7858d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7868a07d286SRatan Gupta const std::string& ldapServerElementName, 7878a07d286SRatan Gupta const std::string& ldapConfigObject) 7888a07d286SRatan Gupta { 7898a07d286SRatan Gupta crow::connections::systemBus->async_method_call( 7908a07d286SRatan Gupta [asyncResp, userNameAttribute, 7918a07d286SRatan Gupta ldapServerElementName](const boost::system::error_code ec) { 7928a07d286SRatan Gupta if (ec) 7938a07d286SRatan Gupta { 794c61704abSGunnar Mills BMCWEB_LOG_DEBUG << "Error Occurred in Updating the " 7958a07d286SRatan Gupta "username attribute"; 7968a07d286SRatan Gupta messages::internalError(asyncResp->res); 7978a07d286SRatan Gupta return; 7988a07d286SRatan Gupta } 7998a07d286SRatan Gupta auto& serverTypeJson = 8008a07d286SRatan Gupta asyncResp->res.jsonValue[ldapServerElementName]; 8018a07d286SRatan Gupta auto& searchSettingsJson = 8028a07d286SRatan Gupta serverTypeJson["LDAPService"]["SearchSettings"]; 8038a07d286SRatan Gupta searchSettingsJson["UsernameAttribute"] = userNameAttribute; 8048a07d286SRatan Gupta BMCWEB_LOG_DEBUG << "Updated the user name attr."; 8058a07d286SRatan Gupta }, 8068a07d286SRatan Gupta ldapDbusService, ldapConfigObject, propertyInterface, "Set", 8078a07d286SRatan Gupta ldapConfigInterface, "UserNameAttribute", 8088a07d286SRatan Gupta std::variant<std::string>(userNameAttribute)); 8098a07d286SRatan Gupta } 8108a07d286SRatan Gupta /** 8118a07d286SRatan Gupta * @brief updates the LDAP group attribute and updates the 8128a07d286SRatan Gupta json response with the new value. 8138a07d286SRatan Gupta * @param groupsAttribute attribute to be updated. 8148a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 8158a07d286SRatan Gupta * @param ldapServerElementName Type of LDAP 8168a07d286SRatan Gupta server(openLDAP/ActiveDirectory) 8178a07d286SRatan Gupta */ 8188a07d286SRatan Gupta 8194f48d5f6SEd Tanous inline void handleGroupNameAttrPatch( 8208d1b46d7Szhanghch05 const std::string& groupsAttribute, 8218d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8228a07d286SRatan Gupta const std::string& ldapServerElementName, 8238a07d286SRatan Gupta const std::string& ldapConfigObject) 8248a07d286SRatan Gupta { 8258a07d286SRatan Gupta crow::connections::systemBus->async_method_call( 8268a07d286SRatan Gupta [asyncResp, groupsAttribute, 8278a07d286SRatan Gupta ldapServerElementName](const boost::system::error_code ec) { 8288a07d286SRatan Gupta if (ec) 8298a07d286SRatan Gupta { 830c61704abSGunnar Mills BMCWEB_LOG_DEBUG << "Error Occurred in Updating the " 8318a07d286SRatan Gupta "groupname attribute"; 8328a07d286SRatan Gupta messages::internalError(asyncResp->res); 8338a07d286SRatan Gupta return; 8348a07d286SRatan Gupta } 8358a07d286SRatan Gupta auto& serverTypeJson = 8368a07d286SRatan Gupta asyncResp->res.jsonValue[ldapServerElementName]; 8378a07d286SRatan Gupta auto& searchSettingsJson = 8388a07d286SRatan Gupta serverTypeJson["LDAPService"]["SearchSettings"]; 8398a07d286SRatan Gupta searchSettingsJson["GroupsAttribute"] = groupsAttribute; 8408a07d286SRatan Gupta BMCWEB_LOG_DEBUG << "Updated the groupname attr"; 8418a07d286SRatan Gupta }, 8428a07d286SRatan Gupta ldapDbusService, ldapConfigObject, propertyInterface, "Set", 8438a07d286SRatan Gupta ldapConfigInterface, "GroupNameAttribute", 8448a07d286SRatan Gupta std::variant<std::string>(groupsAttribute)); 8458a07d286SRatan Gupta } 8468a07d286SRatan Gupta /** 8478a07d286SRatan Gupta * @brief updates the LDAP service enable and updates the 8488a07d286SRatan Gupta json response with the new value. 8498a07d286SRatan Gupta * @param input JSON data. 8508a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 8518a07d286SRatan Gupta * @param ldapServerElementName Type of LDAP 8528a07d286SRatan Gupta server(openLDAP/ActiveDirectory) 8538a07d286SRatan Gupta */ 8548a07d286SRatan Gupta 8554f48d5f6SEd Tanous inline void handleServiceEnablePatch( 8566c51eab1SEd Tanous bool serviceEnabled, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8578a07d286SRatan Gupta const std::string& ldapServerElementName, 8588a07d286SRatan Gupta const std::string& ldapConfigObject) 8598a07d286SRatan Gupta { 8608a07d286SRatan Gupta crow::connections::systemBus->async_method_call( 8618a07d286SRatan Gupta [asyncResp, serviceEnabled, 8628a07d286SRatan Gupta ldapServerElementName](const boost::system::error_code ec) { 8638a07d286SRatan Gupta if (ec) 8648a07d286SRatan Gupta { 8658a07d286SRatan Gupta BMCWEB_LOG_DEBUG 866c61704abSGunnar Mills << "Error Occurred in Updating the service enable"; 8678a07d286SRatan Gupta messages::internalError(asyncResp->res); 8688a07d286SRatan Gupta return; 8698a07d286SRatan Gupta } 8706c51eab1SEd Tanous asyncResp->res.jsonValue[ldapServerElementName]["ServiceEnabled"] = 8718a07d286SRatan Gupta serviceEnabled; 8726c51eab1SEd Tanous BMCWEB_LOG_DEBUG << "Updated Service enable = " << serviceEnabled; 8738a07d286SRatan Gupta }, 8748a07d286SRatan Gupta ldapDbusService, ldapConfigObject, propertyInterface, "Set", 8758a07d286SRatan Gupta ldapEnableInterface, "Enabled", std::variant<bool>(serviceEnabled)); 8768a07d286SRatan Gupta } 8778a07d286SRatan Gupta 8784f48d5f6SEd Tanous inline void 8794f48d5f6SEd Tanous handleAuthMethodsPatch(nlohmann::json& input, 8808d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 88178158631SZbigniew Kurzynski { 88278158631SZbigniew Kurzynski std::optional<bool> basicAuth; 88378158631SZbigniew Kurzynski std::optional<bool> cookie; 88478158631SZbigniew Kurzynski std::optional<bool> sessionToken; 88578158631SZbigniew Kurzynski std::optional<bool> xToken; 886501f1e58SZbigniew Kurzynski std::optional<bool> tls; 88778158631SZbigniew Kurzynski 88878158631SZbigniew Kurzynski if (!json_util::readJson(input, asyncResp->res, "BasicAuth", basicAuth, 88978158631SZbigniew Kurzynski "Cookie", cookie, "SessionToken", sessionToken, 890501f1e58SZbigniew Kurzynski "XToken", xToken, "TLS", tls)) 89178158631SZbigniew Kurzynski { 89278158631SZbigniew Kurzynski BMCWEB_LOG_ERROR << "Cannot read values from AuthMethod tag"; 89378158631SZbigniew Kurzynski return; 89478158631SZbigniew Kurzynski } 89578158631SZbigniew Kurzynski 89678158631SZbigniew Kurzynski // Make a copy of methods configuration 89752cc112dSEd Tanous persistent_data::AuthConfigMethods authMethodsConfig = 89852cc112dSEd Tanous persistent_data::SessionStore::getInstance().getAuthMethodsConfig(); 89978158631SZbigniew Kurzynski 90078158631SZbigniew Kurzynski if (basicAuth) 90178158631SZbigniew Kurzynski { 902f16f6263SAlan Kuo #ifndef BMCWEB_ENABLE_BASIC_AUTHENTICATION 903f16f6263SAlan Kuo messages::actionNotSupported( 904f16f6263SAlan Kuo asyncResp->res, "Setting BasicAuth when basic-auth feature " 905f16f6263SAlan Kuo "is disabled"); 906f16f6263SAlan Kuo return; 907f16f6263SAlan Kuo #endif 90878158631SZbigniew Kurzynski authMethodsConfig.basic = *basicAuth; 90978158631SZbigniew Kurzynski } 91078158631SZbigniew Kurzynski 91178158631SZbigniew Kurzynski if (cookie) 91278158631SZbigniew Kurzynski { 913f16f6263SAlan Kuo #ifndef BMCWEB_ENABLE_COOKIE_AUTHENTICATION 9146c51eab1SEd Tanous messages::actionNotSupported(asyncResp->res, 9156c51eab1SEd Tanous "Setting Cookie when cookie-auth feature " 916f16f6263SAlan Kuo "is disabled"); 917f16f6263SAlan Kuo return; 918f16f6263SAlan Kuo #endif 91978158631SZbigniew Kurzynski authMethodsConfig.cookie = *cookie; 92078158631SZbigniew Kurzynski } 92178158631SZbigniew Kurzynski 92278158631SZbigniew Kurzynski if (sessionToken) 92378158631SZbigniew Kurzynski { 924f16f6263SAlan Kuo #ifndef BMCWEB_ENABLE_SESSION_AUTHENTICATION 925f16f6263SAlan Kuo messages::actionNotSupported( 9266c51eab1SEd Tanous asyncResp->res, "Setting SessionToken when session-auth feature " 927f16f6263SAlan Kuo "is disabled"); 928f16f6263SAlan Kuo return; 929f16f6263SAlan Kuo #endif 93078158631SZbigniew Kurzynski authMethodsConfig.sessionToken = *sessionToken; 93178158631SZbigniew Kurzynski } 93278158631SZbigniew Kurzynski 93378158631SZbigniew Kurzynski if (xToken) 93478158631SZbigniew Kurzynski { 935f16f6263SAlan Kuo #ifndef BMCWEB_ENABLE_XTOKEN_AUTHENTICATION 9366c51eab1SEd Tanous messages::actionNotSupported(asyncResp->res, 9376c51eab1SEd Tanous "Setting XToken when xtoken-auth feature " 938f16f6263SAlan Kuo "is disabled"); 939f16f6263SAlan Kuo return; 940f16f6263SAlan Kuo #endif 94178158631SZbigniew Kurzynski authMethodsConfig.xtoken = *xToken; 94278158631SZbigniew Kurzynski } 94378158631SZbigniew Kurzynski 944501f1e58SZbigniew Kurzynski if (tls) 945501f1e58SZbigniew Kurzynski { 946f16f6263SAlan Kuo #ifndef BMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION 9476c51eab1SEd Tanous messages::actionNotSupported(asyncResp->res, 9486c51eab1SEd Tanous "Setting TLS when mutual-tls-auth feature " 949f16f6263SAlan Kuo "is disabled"); 950f16f6263SAlan Kuo return; 951f16f6263SAlan Kuo #endif 952501f1e58SZbigniew Kurzynski authMethodsConfig.tls = *tls; 953501f1e58SZbigniew Kurzynski } 954501f1e58SZbigniew Kurzynski 95578158631SZbigniew Kurzynski if (!authMethodsConfig.basic && !authMethodsConfig.cookie && 956501f1e58SZbigniew Kurzynski !authMethodsConfig.sessionToken && !authMethodsConfig.xtoken && 957501f1e58SZbigniew Kurzynski !authMethodsConfig.tls) 95878158631SZbigniew Kurzynski { 95978158631SZbigniew Kurzynski // Do not allow user to disable everything 96078158631SZbigniew Kurzynski messages::actionNotSupported(asyncResp->res, 96178158631SZbigniew Kurzynski "of disabling all available methods"); 96278158631SZbigniew Kurzynski return; 96378158631SZbigniew Kurzynski } 96478158631SZbigniew Kurzynski 96552cc112dSEd Tanous persistent_data::SessionStore::getInstance().updateAuthMethodsConfig( 96652cc112dSEd Tanous authMethodsConfig); 96778158631SZbigniew Kurzynski // Save configuration immediately 96852cc112dSEd Tanous persistent_data::getConfig().writeData(); 96978158631SZbigniew Kurzynski 97078158631SZbigniew Kurzynski messages::success(asyncResp->res); 97178158631SZbigniew Kurzynski } 97278158631SZbigniew Kurzynski 9738a07d286SRatan Gupta /** 9748a07d286SRatan Gupta * @brief Get the required values from the given JSON, validates the 9758a07d286SRatan Gupta * value and create the LDAP config object. 9768a07d286SRatan Gupta * @param input JSON data 9778a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 9788a07d286SRatan Gupta * @param serverType Type of LDAP server(openLDAP/ActiveDirectory) 9798a07d286SRatan Gupta */ 9808a07d286SRatan Gupta 9816c51eab1SEd Tanous inline void handleLDAPPatch(nlohmann::json& input, 9828d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 9838a07d286SRatan Gupta const std::string& serverType) 9848a07d286SRatan Gupta { 985eb2bbe56SRatan Gupta std::string dbusObjectPath; 986eb2bbe56SRatan Gupta if (serverType == "ActiveDirectory") 987eb2bbe56SRatan Gupta { 9882c70f800SEd Tanous dbusObjectPath = adConfigObject; 989eb2bbe56SRatan Gupta } 990eb2bbe56SRatan Gupta else if (serverType == "LDAP") 991eb2bbe56SRatan Gupta { 99223a21a1cSEd Tanous dbusObjectPath = ldapConfigObjectName; 993eb2bbe56SRatan Gupta } 994cb13a392SEd Tanous else 995cb13a392SEd Tanous { 996cb13a392SEd Tanous return; 997cb13a392SEd Tanous } 998eb2bbe56SRatan Gupta 9998a07d286SRatan Gupta std::optional<nlohmann::json> authentication; 10008a07d286SRatan Gupta std::optional<nlohmann::json> ldapService; 10018a07d286SRatan Gupta std::optional<std::vector<std::string>> serviceAddressList; 10028a07d286SRatan Gupta std::optional<bool> serviceEnabled; 10038a07d286SRatan Gupta std::optional<std::vector<std::string>> baseDNList; 10048a07d286SRatan Gupta std::optional<std::string> userNameAttribute; 10058a07d286SRatan Gupta std::optional<std::string> groupsAttribute; 10068a07d286SRatan Gupta std::optional<std::string> userName; 10078a07d286SRatan Gupta std::optional<std::string> password; 100806785244SRatan Gupta std::optional<std::vector<nlohmann::json>> remoteRoleMapData; 10098a07d286SRatan Gupta 10108a07d286SRatan Gupta if (!json_util::readJson(input, asyncResp->res, "Authentication", 10118a07d286SRatan Gupta authentication, "LDAPService", ldapService, 10128a07d286SRatan Gupta "ServiceAddresses", serviceAddressList, 101306785244SRatan Gupta "ServiceEnabled", serviceEnabled, 101406785244SRatan Gupta "RemoteRoleMapping", remoteRoleMapData)) 10158a07d286SRatan Gupta { 10168a07d286SRatan Gupta return; 10178a07d286SRatan Gupta } 10188a07d286SRatan Gupta 10198a07d286SRatan Gupta if (authentication) 10208a07d286SRatan Gupta { 10218a07d286SRatan Gupta parseLDAPAuthenticationJson(*authentication, asyncResp, userName, 10228a07d286SRatan Gupta password); 10238a07d286SRatan Gupta } 10248a07d286SRatan Gupta if (ldapService) 10258a07d286SRatan Gupta { 10268a07d286SRatan Gupta parseLDAPServiceJson(*ldapService, asyncResp, baseDNList, 10278a07d286SRatan Gupta userNameAttribute, groupsAttribute); 10288a07d286SRatan Gupta } 10298a07d286SRatan Gupta if (serviceAddressList) 10308a07d286SRatan Gupta { 10318a07d286SRatan Gupta if ((*serviceAddressList).size() == 0) 10328a07d286SRatan Gupta { 10338a07d286SRatan Gupta messages::propertyValueNotInList(asyncResp->res, "[]", 10348a07d286SRatan Gupta "ServiceAddress"); 10358a07d286SRatan Gupta return; 10368a07d286SRatan Gupta } 10378a07d286SRatan Gupta } 10388a07d286SRatan Gupta if (baseDNList) 10398a07d286SRatan Gupta { 10408a07d286SRatan Gupta if ((*baseDNList).size() == 0) 10418a07d286SRatan Gupta { 10428a07d286SRatan Gupta messages::propertyValueNotInList(asyncResp->res, "[]", 10438a07d286SRatan Gupta "BaseDistinguishedNames"); 10448a07d286SRatan Gupta return; 10458a07d286SRatan Gupta } 10468a07d286SRatan Gupta } 10478a07d286SRatan Gupta 10488a07d286SRatan Gupta // nothing to update, then return 10498a07d286SRatan Gupta if (!userName && !password && !serviceAddressList && !baseDNList && 105006785244SRatan Gupta !userNameAttribute && !groupsAttribute && !serviceEnabled && 105106785244SRatan Gupta !remoteRoleMapData) 10528a07d286SRatan Gupta { 10538a07d286SRatan Gupta return; 10548a07d286SRatan Gupta } 10558a07d286SRatan Gupta 10568a07d286SRatan Gupta // Get the existing resource first then keep modifying 10578a07d286SRatan Gupta // whenever any property gets updated. 10586c51eab1SEd Tanous getLDAPConfigData(serverType, [asyncResp, userName, password, baseDNList, 10596c51eab1SEd Tanous userNameAttribute, groupsAttribute, 10606c51eab1SEd Tanous serviceAddressList, serviceEnabled, 10616c51eab1SEd Tanous dbusObjectPath, remoteRoleMapData]( 10626c51eab1SEd Tanous bool success, 10636c51eab1SEd Tanous const LDAPConfigData& confData, 106423a21a1cSEd Tanous const std::string& serverT) { 10658a07d286SRatan Gupta if (!success) 10668a07d286SRatan Gupta { 10678a07d286SRatan Gupta messages::internalError(asyncResp->res); 10688a07d286SRatan Gupta return; 10698a07d286SRatan Gupta } 10706c51eab1SEd Tanous parseLDAPConfigData(asyncResp->res.jsonValue, confData, serverT); 10718a07d286SRatan Gupta if (confData.serviceEnabled) 10728a07d286SRatan Gupta { 10738a07d286SRatan Gupta // Disable the service first and update the rest of 10748a07d286SRatan Gupta // the properties. 10756c51eab1SEd Tanous handleServiceEnablePatch(false, asyncResp, serverT, dbusObjectPath); 10768a07d286SRatan Gupta } 10778a07d286SRatan Gupta 10788a07d286SRatan Gupta if (serviceAddressList) 10798a07d286SRatan Gupta { 10806c51eab1SEd Tanous handleServiceAddressPatch(*serviceAddressList, asyncResp, serverT, 10816c51eab1SEd Tanous dbusObjectPath); 10828a07d286SRatan Gupta } 10838a07d286SRatan Gupta if (userName) 10848a07d286SRatan Gupta { 10856c51eab1SEd Tanous handleUserNamePatch(*userName, asyncResp, serverT, dbusObjectPath); 10868a07d286SRatan Gupta } 10878a07d286SRatan Gupta if (password) 10888a07d286SRatan Gupta { 10896c51eab1SEd Tanous handlePasswordPatch(*password, asyncResp, serverT, dbusObjectPath); 10908a07d286SRatan Gupta } 10918a07d286SRatan Gupta 10928a07d286SRatan Gupta if (baseDNList) 10938a07d286SRatan Gupta { 10946c51eab1SEd Tanous handleBaseDNPatch(*baseDNList, asyncResp, serverT, dbusObjectPath); 10958a07d286SRatan Gupta } 10968a07d286SRatan Gupta if (userNameAttribute) 10978a07d286SRatan Gupta { 10986c51eab1SEd Tanous handleUserNameAttrPatch(*userNameAttribute, asyncResp, serverT, 10996c51eab1SEd Tanous dbusObjectPath); 11008a07d286SRatan Gupta } 11018a07d286SRatan Gupta if (groupsAttribute) 11028a07d286SRatan Gupta { 11036c51eab1SEd Tanous handleGroupNameAttrPatch(*groupsAttribute, asyncResp, serverT, 11046c51eab1SEd Tanous dbusObjectPath); 11058a07d286SRatan Gupta } 11068a07d286SRatan Gupta if (serviceEnabled) 11078a07d286SRatan Gupta { 11088a07d286SRatan Gupta // if user has given the value as true then enable 11098a07d286SRatan Gupta // the service. if user has given false then no-op 11108a07d286SRatan Gupta // as service is already stopped. 11118a07d286SRatan Gupta if (*serviceEnabled) 11128a07d286SRatan Gupta { 11136c51eab1SEd Tanous handleServiceEnablePatch(*serviceEnabled, asyncResp, serverT, 11146c51eab1SEd Tanous dbusObjectPath); 11158a07d286SRatan Gupta } 11168a07d286SRatan Gupta } 11178a07d286SRatan Gupta else 11188a07d286SRatan Gupta { 11198a07d286SRatan Gupta // if user has not given the service enabled value 11208a07d286SRatan Gupta // then revert it to the same state as it was 11218a07d286SRatan Gupta // before. 11228a07d286SRatan Gupta handleServiceEnablePatch(confData.serviceEnabled, asyncResp, 112323a21a1cSEd Tanous serverT, dbusObjectPath); 11248a07d286SRatan Gupta } 112506785244SRatan Gupta 112606785244SRatan Gupta if (remoteRoleMapData) 112706785244SRatan Gupta { 11286c51eab1SEd Tanous handleRoleMapPatch(asyncResp, confData.groupRoleList, serverT, 11296c51eab1SEd Tanous *remoteRoleMapData); 113006785244SRatan Gupta } 11318a07d286SRatan Gupta }); 11328a07d286SRatan Gupta } 1133d4b5443fSEd Tanous 11346c51eab1SEd Tanous inline void updateUserProperties(std::shared_ptr<bmcweb::AsyncResp> asyncResp, 11356c51eab1SEd Tanous const std::string& username, 11366c51eab1SEd Tanous std::optional<std::string> password, 11376c51eab1SEd Tanous std::optional<bool> enabled, 11386c51eab1SEd Tanous std::optional<std::string> roleId, 11396c51eab1SEd Tanous std::optional<bool> locked) 11401abe55efSEd Tanous { 11416c51eab1SEd Tanous std::string dbusObjectPath = "/xyz/openbmc_project/user/" + username; 11426c51eab1SEd Tanous dbus::utility::escapePathForDbus(dbusObjectPath); 11436c51eab1SEd Tanous 11446c51eab1SEd Tanous dbus::utility::checkDbusPathExists( 11456c51eab1SEd Tanous dbusObjectPath, 11461106333aSEd Tanous [dbusObjectPath, username, password(std::move(password)), 11471106333aSEd Tanous roleId(std::move(roleId)), enabled, locked, 11481106333aSEd Tanous asyncResp{std::move(asyncResp)}](int rc) { 11496c51eab1SEd Tanous if (!rc) 11506c51eab1SEd Tanous { 11516c51eab1SEd Tanous messages::resourceNotFound( 11526c51eab1SEd Tanous asyncResp->res, "#ManagerAccount.v1_4_0.ManagerAccount", 11536c51eab1SEd Tanous username); 11546c51eab1SEd Tanous return; 11556c51eab1SEd Tanous } 11566c51eab1SEd Tanous 11576c51eab1SEd Tanous if (password) 11586c51eab1SEd Tanous { 11596c51eab1SEd Tanous int retval = pamUpdatePassword(username, *password); 11606c51eab1SEd Tanous 11616c51eab1SEd Tanous if (retval == PAM_USER_UNKNOWN) 11626c51eab1SEd Tanous { 11636c51eab1SEd Tanous messages::resourceNotFound( 11646c51eab1SEd Tanous asyncResp->res, "#ManagerAccount.v1_4_0.ManagerAccount", 11656c51eab1SEd Tanous username); 11666c51eab1SEd Tanous } 11676c51eab1SEd Tanous else if (retval == PAM_AUTHTOK_ERR) 11686c51eab1SEd Tanous { 11696c51eab1SEd Tanous // If password is invalid 11706c51eab1SEd Tanous messages::propertyValueFormatError(asyncResp->res, 11716c51eab1SEd Tanous *password, "Password"); 11726c51eab1SEd Tanous BMCWEB_LOG_ERROR << "pamUpdatePassword Failed"; 11736c51eab1SEd Tanous } 11746c51eab1SEd Tanous else if (retval != PAM_SUCCESS) 11756c51eab1SEd Tanous { 11766c51eab1SEd Tanous messages::internalError(asyncResp->res); 11776c51eab1SEd Tanous return; 11786c51eab1SEd Tanous } 11796c51eab1SEd Tanous } 11806c51eab1SEd Tanous 11816c51eab1SEd Tanous if (enabled) 11826c51eab1SEd Tanous { 11836c51eab1SEd Tanous crow::connections::systemBus->async_method_call( 11846c51eab1SEd Tanous [asyncResp](const boost::system::error_code ec) { 11856c51eab1SEd Tanous if (ec) 11866c51eab1SEd Tanous { 11876c51eab1SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 11886c51eab1SEd Tanous messages::internalError(asyncResp->res); 11896c51eab1SEd Tanous return; 11906c51eab1SEd Tanous } 11916c51eab1SEd Tanous messages::success(asyncResp->res); 11926c51eab1SEd Tanous return; 11936c51eab1SEd Tanous }, 11946c51eab1SEd Tanous "xyz.openbmc_project.User.Manager", dbusObjectPath.c_str(), 11956c51eab1SEd Tanous "org.freedesktop.DBus.Properties", "Set", 11966c51eab1SEd Tanous "xyz.openbmc_project.User.Attributes", "UserEnabled", 11976c51eab1SEd Tanous std::variant<bool>{*enabled}); 11986c51eab1SEd Tanous } 11996c51eab1SEd Tanous 12006c51eab1SEd Tanous if (roleId) 12016c51eab1SEd Tanous { 12026c51eab1SEd Tanous std::string priv = getPrivilegeFromRoleId(*roleId); 12036c51eab1SEd Tanous if (priv.empty()) 12046c51eab1SEd Tanous { 12056c51eab1SEd Tanous messages::propertyValueNotInList(asyncResp->res, *roleId, 12066c51eab1SEd Tanous "RoleId"); 12076c51eab1SEd Tanous return; 12086c51eab1SEd Tanous } 12096c51eab1SEd Tanous if (priv == "priv-noaccess") 12106c51eab1SEd Tanous { 12116c51eab1SEd Tanous priv = ""; 12126c51eab1SEd Tanous } 12136c51eab1SEd Tanous 12146c51eab1SEd Tanous crow::connections::systemBus->async_method_call( 12156c51eab1SEd Tanous [asyncResp](const boost::system::error_code ec) { 12166c51eab1SEd Tanous if (ec) 12176c51eab1SEd Tanous { 12186c51eab1SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 12196c51eab1SEd Tanous messages::internalError(asyncResp->res); 12206c51eab1SEd Tanous return; 12216c51eab1SEd Tanous } 12226c51eab1SEd Tanous messages::success(asyncResp->res); 12236c51eab1SEd Tanous }, 12246c51eab1SEd Tanous "xyz.openbmc_project.User.Manager", dbusObjectPath.c_str(), 12256c51eab1SEd Tanous "org.freedesktop.DBus.Properties", "Set", 12266c51eab1SEd Tanous "xyz.openbmc_project.User.Attributes", "UserPrivilege", 12276c51eab1SEd Tanous std::variant<std::string>{priv}); 12286c51eab1SEd Tanous } 12296c51eab1SEd Tanous 12306c51eab1SEd Tanous if (locked) 12316c51eab1SEd Tanous { 12326c51eab1SEd Tanous // admin can unlock the account which is locked by 12336c51eab1SEd Tanous // successive authentication failures but admin should 12346c51eab1SEd Tanous // not be allowed to lock an account. 12356c51eab1SEd Tanous if (*locked) 12366c51eab1SEd Tanous { 12376c51eab1SEd Tanous messages::propertyValueNotInList(asyncResp->res, "true", 12386c51eab1SEd Tanous "Locked"); 12396c51eab1SEd Tanous return; 12406c51eab1SEd Tanous } 12416c51eab1SEd Tanous 12426c51eab1SEd Tanous crow::connections::systemBus->async_method_call( 12436c51eab1SEd Tanous [asyncResp](const boost::system::error_code ec) { 12446c51eab1SEd Tanous if (ec) 12456c51eab1SEd Tanous { 12466c51eab1SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 12476c51eab1SEd Tanous messages::internalError(asyncResp->res); 12486c51eab1SEd Tanous return; 12496c51eab1SEd Tanous } 12506c51eab1SEd Tanous messages::success(asyncResp->res); 12516c51eab1SEd Tanous return; 12526c51eab1SEd Tanous }, 12536c51eab1SEd Tanous "xyz.openbmc_project.User.Manager", dbusObjectPath.c_str(), 12546c51eab1SEd Tanous "org.freedesktop.DBus.Properties", "Set", 12556c51eab1SEd Tanous "xyz.openbmc_project.User.Attributes", 12566c51eab1SEd Tanous "UserLockedForFailedAttempt", std::variant<bool>{*locked}); 12576c51eab1SEd Tanous } 12586c51eab1SEd Tanous }); 12596c51eab1SEd Tanous } 12606c51eab1SEd Tanous 12616c51eab1SEd Tanous inline void requestAccountServiceRoutes(App& app) 12626c51eab1SEd Tanous { 12636c51eab1SEd Tanous 12646c51eab1SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/AccountService/") 1265ed398213SEd Tanous .privileges(redfish::privileges::getAccountService) 12666c51eab1SEd Tanous .methods( 126772048780SAbhishek Patel boost::beast::http::verb::get)([](const crow::Request& req, 12686c51eab1SEd Tanous const std::shared_ptr< 12696c51eab1SEd Tanous bmcweb::AsyncResp>& asyncResp) 12706c51eab1SEd Tanous -> void { 127152cc112dSEd Tanous const persistent_data::AuthConfigMethods& authMethodsConfig = 12726c51eab1SEd Tanous persistent_data::SessionStore::getInstance() 12736c51eab1SEd Tanous .getAuthMethodsConfig(); 127478158631SZbigniew Kurzynski 12758d1b46d7Szhanghch05 asyncResp->res.jsonValue = { 12763d958bbcSAppaRao Puli {"@odata.id", "/redfish/v1/AccountService"}, 12773d958bbcSAppaRao Puli {"@odata.type", "#AccountService." 1278ba9dd4a8SGunnar Mills "v1_5_0.AccountService"}, 12793d958bbcSAppaRao Puli {"Id", "AccountService"}, 12803d958bbcSAppaRao Puli {"Name", "Account Service"}, 12813d958bbcSAppaRao Puli {"Description", "Account Service"}, 12823d958bbcSAppaRao Puli {"ServiceEnabled", true}, 1283343ff2e1SAppaRao Puli {"MaxPasswordLength", 20}, 12843d958bbcSAppaRao Puli {"Accounts", 12853d958bbcSAppaRao Puli {{"@odata.id", "/redfish/v1/AccountService/Accounts"}}}, 128637cce918SMarri Devender Rao {"Roles", {{"@odata.id", "/redfish/v1/AccountService/Roles"}}}, 128778158631SZbigniew Kurzynski {"Oem", 128878158631SZbigniew Kurzynski {{"OpenBMC", 128978158631SZbigniew Kurzynski {{"@odata.type", "#OemAccountService.v1_0_0.AccountService"}, 1290d8e3c29aSEd Tanous {"@odata.id", "/redfish/v1/AccountService#/Oem/OpenBMC"}, 129178158631SZbigniew Kurzynski {"AuthMethods", 129278158631SZbigniew Kurzynski { 129378158631SZbigniew Kurzynski {"BasicAuth", authMethodsConfig.basic}, 129478158631SZbigniew Kurzynski {"SessionToken", authMethodsConfig.sessionToken}, 129578158631SZbigniew Kurzynski {"XToken", authMethodsConfig.xtoken}, 129678158631SZbigniew Kurzynski {"Cookie", authMethodsConfig.cookie}, 1297501f1e58SZbigniew Kurzynski {"TLS", authMethodsConfig.tls}, 129872048780SAbhishek Patel }}}}}}}; 129972048780SAbhishek Patel // /redfish/v1/AccountService/LDAP/Certificates is something only 130072048780SAbhishek Patel // ConfigureManager can access then only display when the user has 130172048780SAbhishek Patel // permissions ConfigureManager 130272048780SAbhishek Patel Privileges effectiveUserPrivileges = 130372048780SAbhishek Patel redfish::getUserPrivileges(req.userRole); 130472048780SAbhishek Patel 130572048780SAbhishek Patel if (isOperationAllowedWithPrivileges({{"ConfigureManager"}}, 130672048780SAbhishek Patel effectiveUserPrivileges)) 130772048780SAbhishek Patel { 130872048780SAbhishek Patel asyncResp->res.jsonValue["LDAP"] = { 130972048780SAbhishek Patel {"Certificates", 131037cce918SMarri Devender Rao {{"@odata.id", 131172048780SAbhishek Patel "/redfish/v1/AccountService/LDAP/Certificates"}}}}; 131272048780SAbhishek Patel } 13133d958bbcSAppaRao Puli crow::connections::systemBus->async_method_call( 13143d958bbcSAppaRao Puli [asyncResp]( 13153d958bbcSAppaRao Puli const boost::system::error_code ec, 13166c51eab1SEd Tanous const std::vector< 13176c51eab1SEd Tanous std::pair<std::string, 13186c51eab1SEd Tanous std::variant<uint32_t, uint16_t, uint8_t>>>& 13193d958bbcSAppaRao Puli propertiesList) { 13203d958bbcSAppaRao Puli if (ec) 13213d958bbcSAppaRao Puli { 13223d958bbcSAppaRao Puli messages::internalError(asyncResp->res); 13233d958bbcSAppaRao Puli return; 13243d958bbcSAppaRao Puli } 13253d958bbcSAppaRao Puli BMCWEB_LOG_DEBUG << "Got " << propertiesList.size() 13263d958bbcSAppaRao Puli << "properties for AccountService"; 13273d958bbcSAppaRao Puli for (const std::pair<std::string, 13286c51eab1SEd Tanous std::variant<uint32_t, uint16_t, 13296c51eab1SEd Tanous uint8_t>>& property : 13306c51eab1SEd Tanous propertiesList) 13313d958bbcSAppaRao Puli { 13323d958bbcSAppaRao Puli if (property.first == "MinPasswordLength") 13333d958bbcSAppaRao Puli { 13343d958bbcSAppaRao Puli const uint8_t* value = 1335abf2add6SEd Tanous std::get_if<uint8_t>(&property.second); 13363d958bbcSAppaRao Puli if (value != nullptr) 13373d958bbcSAppaRao Puli { 13383d958bbcSAppaRao Puli asyncResp->res.jsonValue["MinPasswordLength"] = 13393d958bbcSAppaRao Puli *value; 13403d958bbcSAppaRao Puli } 13413d958bbcSAppaRao Puli } 13423d958bbcSAppaRao Puli if (property.first == "AccountUnlockTimeout") 13433d958bbcSAppaRao Puli { 13443d958bbcSAppaRao Puli const uint32_t* value = 1345abf2add6SEd Tanous std::get_if<uint32_t>(&property.second); 13463d958bbcSAppaRao Puli if (value != nullptr) 13473d958bbcSAppaRao Puli { 13486c51eab1SEd Tanous asyncResp->res 13496c51eab1SEd Tanous .jsonValue["AccountLockoutDuration"] = 13503d958bbcSAppaRao Puli *value; 13513d958bbcSAppaRao Puli } 13523d958bbcSAppaRao Puli } 13533d958bbcSAppaRao Puli if (property.first == "MaxLoginAttemptBeforeLockout") 13543d958bbcSAppaRao Puli { 13553d958bbcSAppaRao Puli const uint16_t* value = 1356abf2add6SEd Tanous std::get_if<uint16_t>(&property.second); 13573d958bbcSAppaRao Puli if (value != nullptr) 13583d958bbcSAppaRao Puli { 13593d958bbcSAppaRao Puli asyncResp->res 13606c51eab1SEd Tanous .jsonValue["AccountLockoutThreshold"] = 13616c51eab1SEd Tanous *value; 13623d958bbcSAppaRao Puli } 13633d958bbcSAppaRao Puli } 13643d958bbcSAppaRao Puli } 13653d958bbcSAppaRao Puli }, 13663d958bbcSAppaRao Puli "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", 13673d958bbcSAppaRao Puli "org.freedesktop.DBus.Properties", "GetAll", 13683d958bbcSAppaRao Puli "xyz.openbmc_project.User.AccountPolicy"); 13696973a582SRatan Gupta 1370ab828d7cSRatan Gupta auto callback = [asyncResp](bool success, LDAPConfigData& confData, 1371ab828d7cSRatan Gupta const std::string& ldapType) { 1372cb13a392SEd Tanous if (!success) 1373cb13a392SEd Tanous { 1374cb13a392SEd Tanous return; 1375cb13a392SEd Tanous } 13766c51eab1SEd Tanous parseLDAPConfigData(asyncResp->res.jsonValue, confData, 13776c51eab1SEd Tanous ldapType); 1378ab828d7cSRatan Gupta }; 1379ab828d7cSRatan Gupta 1380ab828d7cSRatan Gupta getLDAPConfigData("LDAP", callback); 1381ab828d7cSRatan Gupta getLDAPConfigData("ActiveDirectory", callback); 13826c51eab1SEd Tanous }); 13836973a582SRatan Gupta 1384f5ffd806SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/AccountService/") 1385f5ffd806SEd Tanous .privileges(redfish::privileges::getAccountService) 1386f5ffd806SEd Tanous .methods(boost::beast::http::verb::patch)( 1387f5ffd806SEd Tanous [](const crow::Request& req, 1388f5ffd806SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) -> void { 1389f5ffd806SEd Tanous std::optional<uint32_t> unlockTimeout; 1390f5ffd806SEd Tanous std::optional<uint16_t> lockoutThreshold; 1391f5ffd806SEd Tanous std::optional<uint16_t> minPasswordLength; 1392f5ffd806SEd Tanous std::optional<uint16_t> maxPasswordLength; 1393f5ffd806SEd Tanous std::optional<nlohmann::json> ldapObject; 1394f5ffd806SEd Tanous std::optional<nlohmann::json> activeDirectoryObject; 1395f5ffd806SEd Tanous std::optional<nlohmann::json> oemObject; 1396f5ffd806SEd Tanous 1397f5ffd806SEd Tanous if (!json_util::readJson( 1398f5ffd806SEd Tanous req, asyncResp->res, "AccountLockoutDuration", 1399f5ffd806SEd Tanous unlockTimeout, "AccountLockoutThreshold", 1400f5ffd806SEd Tanous lockoutThreshold, "MaxPasswordLength", 1401f5ffd806SEd Tanous maxPasswordLength, "MinPasswordLength", 1402f5ffd806SEd Tanous minPasswordLength, "LDAP", ldapObject, 1403f5ffd806SEd Tanous "ActiveDirectory", activeDirectoryObject, "Oem", 1404f5ffd806SEd Tanous oemObject)) 1405f5ffd806SEd Tanous { 1406f5ffd806SEd Tanous return; 1407f5ffd806SEd Tanous } 1408f5ffd806SEd Tanous 1409f5ffd806SEd Tanous if (minPasswordLength) 1410f5ffd806SEd Tanous { 1411f5ffd806SEd Tanous messages::propertyNotWritable(asyncResp->res, 1412f5ffd806SEd Tanous "MinPasswordLength"); 1413f5ffd806SEd Tanous } 1414f5ffd806SEd Tanous 1415f5ffd806SEd Tanous if (maxPasswordLength) 1416f5ffd806SEd Tanous { 1417f5ffd806SEd Tanous messages::propertyNotWritable(asyncResp->res, 1418f5ffd806SEd Tanous "MaxPasswordLength"); 1419f5ffd806SEd Tanous } 1420f5ffd806SEd Tanous 1421f5ffd806SEd Tanous if (ldapObject) 1422f5ffd806SEd Tanous { 1423f5ffd806SEd Tanous handleLDAPPatch(*ldapObject, asyncResp, "LDAP"); 1424f5ffd806SEd Tanous } 1425f5ffd806SEd Tanous 1426f5ffd806SEd Tanous if (std::optional<nlohmann::json> oemOpenBMCObject; 1427f5ffd806SEd Tanous oemObject && 1428f5ffd806SEd Tanous json_util::readJson(*oemObject, asyncResp->res, "OpenBMC", 1429f5ffd806SEd Tanous oemOpenBMCObject)) 1430f5ffd806SEd Tanous { 1431f5ffd806SEd Tanous if (std::optional<nlohmann::json> authMethodsObject; 1432f5ffd806SEd Tanous oemOpenBMCObject && 1433f5ffd806SEd Tanous json_util::readJson(*oemOpenBMCObject, asyncResp->res, 1434f5ffd806SEd Tanous "AuthMethods", authMethodsObject)) 1435f5ffd806SEd Tanous { 1436f5ffd806SEd Tanous if (authMethodsObject) 1437f5ffd806SEd Tanous { 1438f5ffd806SEd Tanous handleAuthMethodsPatch(*authMethodsObject, 1439f5ffd806SEd Tanous asyncResp); 1440f5ffd806SEd Tanous } 1441f5ffd806SEd Tanous } 1442f5ffd806SEd Tanous } 1443f5ffd806SEd Tanous 1444f5ffd806SEd Tanous if (activeDirectoryObject) 1445f5ffd806SEd Tanous { 1446f5ffd806SEd Tanous handleLDAPPatch(*activeDirectoryObject, asyncResp, 1447f5ffd806SEd Tanous "ActiveDirectory"); 1448f5ffd806SEd Tanous } 1449f5ffd806SEd Tanous 1450f5ffd806SEd Tanous if (unlockTimeout) 1451f5ffd806SEd Tanous { 1452f5ffd806SEd Tanous crow::connections::systemBus->async_method_call( 1453f5ffd806SEd Tanous [asyncResp](const boost::system::error_code ec) { 1454f5ffd806SEd Tanous if (ec) 1455f5ffd806SEd Tanous { 1456f5ffd806SEd Tanous messages::internalError(asyncResp->res); 1457f5ffd806SEd Tanous return; 1458f5ffd806SEd Tanous } 1459f5ffd806SEd Tanous messages::success(asyncResp->res); 1460f5ffd806SEd Tanous }, 1461f5ffd806SEd Tanous "xyz.openbmc_project.User.Manager", 1462f5ffd806SEd Tanous "/xyz/openbmc_project/user", 1463f5ffd806SEd Tanous "org.freedesktop.DBus.Properties", "Set", 1464f5ffd806SEd Tanous "xyz.openbmc_project.User.AccountPolicy", 1465f5ffd806SEd Tanous "AccountUnlockTimeout", 1466f5ffd806SEd Tanous std::variant<uint32_t>(*unlockTimeout)); 1467f5ffd806SEd Tanous } 1468f5ffd806SEd Tanous if (lockoutThreshold) 1469f5ffd806SEd Tanous { 1470f5ffd806SEd Tanous crow::connections::systemBus->async_method_call( 1471f5ffd806SEd Tanous [asyncResp](const boost::system::error_code ec) { 1472f5ffd806SEd Tanous if (ec) 1473f5ffd806SEd Tanous { 1474f5ffd806SEd Tanous messages::internalError(asyncResp->res); 1475f5ffd806SEd Tanous return; 1476f5ffd806SEd Tanous } 1477f5ffd806SEd Tanous messages::success(asyncResp->res); 1478f5ffd806SEd Tanous }, 1479f5ffd806SEd Tanous "xyz.openbmc_project.User.Manager", 1480f5ffd806SEd Tanous "/xyz/openbmc_project/user", 1481f5ffd806SEd Tanous "org.freedesktop.DBus.Properties", "Set", 1482f5ffd806SEd Tanous "xyz.openbmc_project.User.AccountPolicy", 1483f5ffd806SEd Tanous "MaxLoginAttemptBeforeLockout", 1484f5ffd806SEd Tanous std::variant<uint16_t>(*lockoutThreshold)); 1485f5ffd806SEd Tanous } 1486f5ffd806SEd Tanous }); 1487f5ffd806SEd Tanous 14886c51eab1SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/") 1489ed398213SEd Tanous .privileges(redfish::privileges::getManagerAccountCollection) 14906c51eab1SEd Tanous .methods(boost::beast::http::verb::get)( 14916c51eab1SEd Tanous [](const crow::Request& req, 14926c51eab1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) -> void { 14938d1b46d7Szhanghch05 asyncResp->res.jsonValue = { 14948d1b46d7Szhanghch05 {"@odata.id", "/redfish/v1/AccountService/Accounts"}, 14950f74e643SEd Tanous {"@odata.type", "#ManagerAccountCollection." 14960f74e643SEd Tanous "ManagerAccountCollection"}, 14970f74e643SEd Tanous {"Name", "Accounts Collection"}, 14980f74e643SEd Tanous {"Description", "BMC User Accounts"}}; 14990f74e643SEd Tanous 15006c51eab1SEd Tanous Privileges effectiveUserPrivileges = 15016c51eab1SEd Tanous redfish::getUserPrivileges(req.userRole); 15026c51eab1SEd Tanous 15036c51eab1SEd Tanous std::string thisUser = req.session->username; 15046c51eab1SEd Tanous 1505b9b2e0b2SEd Tanous crow::connections::systemBus->async_method_call( 1506cef1ddfbSEd Tanous [asyncResp, thisUser, effectiveUserPrivileges]( 1507cef1ddfbSEd Tanous const boost::system::error_code ec, 1508b9b2e0b2SEd Tanous const ManagedObjectType& users) { 1509b9b2e0b2SEd Tanous if (ec) 1510b9b2e0b2SEd Tanous { 1511f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1512b9b2e0b2SEd Tanous return; 1513b9b2e0b2SEd Tanous } 1514b9b2e0b2SEd Tanous 1515cef1ddfbSEd Tanous bool userCanSeeAllAccounts = 1516cef1ddfbSEd Tanous effectiveUserPrivileges.isSupersetOf( 15174f48d5f6SEd Tanous {"ConfigureUsers"}); 1518cef1ddfbSEd Tanous 1519cef1ddfbSEd Tanous bool userCanSeeSelf = 1520cef1ddfbSEd Tanous effectiveUserPrivileges.isSupersetOf( 15214f48d5f6SEd Tanous {"ConfigureSelf"}); 1522cef1ddfbSEd Tanous 1523b9b2e0b2SEd Tanous nlohmann::json& memberArray = 1524b9b2e0b2SEd Tanous asyncResp->res.jsonValue["Members"]; 1525b9b2e0b2SEd Tanous memberArray = nlohmann::json::array(); 1526b9b2e0b2SEd Tanous 15272dfd18efSEd Tanous for (auto& userpath : users) 1528b9b2e0b2SEd Tanous { 15292dfd18efSEd Tanous std::string user = userpath.first.filename(); 15302dfd18efSEd Tanous if (user.empty()) 1531b9b2e0b2SEd Tanous { 15322dfd18efSEd Tanous messages::internalError(asyncResp->res); 15332dfd18efSEd Tanous BMCWEB_LOG_ERROR << "Invalid firmware ID"; 15342dfd18efSEd Tanous 15352dfd18efSEd Tanous return; 1536b9b2e0b2SEd Tanous } 1537f365910cSGunnar Mills 1538f365910cSGunnar Mills // As clarified by Redfish here: 1539f365910cSGunnar Mills // https://redfishforum.com/thread/281/manageraccountcollection-change-allows-account-enumeration 15406c51eab1SEd Tanous // Users without ConfigureUsers, only see their own 15416c51eab1SEd Tanous // account. Users with ConfigureUsers, see all 15426c51eab1SEd Tanous // accounts. 1543cef1ddfbSEd Tanous if (userCanSeeAllAccounts || 1544cef1ddfbSEd Tanous (thisUser == user && userCanSeeSelf)) 1545f365910cSGunnar Mills { 1546b9b2e0b2SEd Tanous memberArray.push_back( 1547f365910cSGunnar Mills {{"@odata.id", 15486c51eab1SEd Tanous "/redfish/v1/AccountService/Accounts/" + 15496c51eab1SEd Tanous user}}); 1550b9b2e0b2SEd Tanous } 1551f365910cSGunnar Mills } 1552f365910cSGunnar Mills asyncResp->res.jsonValue["Members@odata.count"] = 1553f365910cSGunnar Mills memberArray.size(); 1554b9b2e0b2SEd Tanous }, 15556c51eab1SEd Tanous "xyz.openbmc_project.User.Manager", 15566c51eab1SEd Tanous "/xyz/openbmc_project/user", 1557b9b2e0b2SEd Tanous "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 15586c51eab1SEd Tanous }); 15596c51eab1SEd Tanous 15606c51eab1SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/") 1561ed398213SEd Tanous .privileges(redfish::privileges::postManagerAccountCollection) 15626c51eab1SEd Tanous .methods(boost::beast::http::verb::post)([](const crow::Request& req, 15636c51eab1SEd Tanous const std::shared_ptr< 15646c51eab1SEd Tanous bmcweb::AsyncResp>& 15656c51eab1SEd Tanous asyncResp) -> void { 15669712f8acSEd Tanous std::string username; 15679712f8acSEd Tanous std::string password; 1568a24526dcSEd Tanous std::optional<std::string> roleId("User"); 1569a24526dcSEd Tanous std::optional<bool> enabled = true; 15708d1b46d7Szhanghch05 if (!json_util::readJson(req, asyncResp->res, "UserName", username, 15718d1b46d7Szhanghch05 "Password", password, "RoleId", roleId, 15728d1b46d7Szhanghch05 "Enabled", enabled)) 157304ae99ecSEd Tanous { 157404ae99ecSEd Tanous return; 157504ae99ecSEd Tanous } 157604ae99ecSEd Tanous 157754fc587aSNagaraju Goruganti std::string priv = getPrivilegeFromRoleId(*roleId); 157884e12cb7SAppaRao Puli if (priv.empty()) 157904ae99ecSEd Tanous { 15806c51eab1SEd Tanous messages::propertyValueNotInList(asyncResp->res, *roleId, 15816c51eab1SEd Tanous "RoleId"); 158204ae99ecSEd Tanous return; 158304ae99ecSEd Tanous } 158496200606Sjayaprakash Mutyala // TODO: Following override will be reverted once support in 15856c51eab1SEd Tanous // phosphor-user-manager is added. In order to avoid dependency 15866c51eab1SEd Tanous // issues, this is added in bmcweb, which will removed, once 158796200606Sjayaprakash Mutyala // phosphor-user-manager supports priv-noaccess. 158896200606Sjayaprakash Mutyala if (priv == "priv-noaccess") 158996200606Sjayaprakash Mutyala { 159096200606Sjayaprakash Mutyala roleId = ""; 159196200606Sjayaprakash Mutyala } 159296200606Sjayaprakash Mutyala else 159396200606Sjayaprakash Mutyala { 15949712f8acSEd Tanous roleId = priv; 159596200606Sjayaprakash Mutyala } 159604ae99ecSEd Tanous 1597599c71d8SAyushi Smriti // Reading AllGroups property 1598599c71d8SAyushi Smriti crow::connections::systemBus->async_method_call( 1599599c71d8SAyushi Smriti [asyncResp, username, password{std::move(password)}, roleId, 16006c51eab1SEd Tanous enabled]( 16016c51eab1SEd Tanous const boost::system::error_code ec, 1602599c71d8SAyushi Smriti const std::variant<std::vector<std::string>>& allGroups) { 1603599c71d8SAyushi Smriti if (ec) 1604599c71d8SAyushi Smriti { 1605599c71d8SAyushi Smriti BMCWEB_LOG_DEBUG << "ERROR with async_method_call"; 1606599c71d8SAyushi Smriti messages::internalError(asyncResp->res); 1607599c71d8SAyushi Smriti return; 1608599c71d8SAyushi Smriti } 1609599c71d8SAyushi Smriti 1610599c71d8SAyushi Smriti const std::vector<std::string>* allGroupsList = 1611599c71d8SAyushi Smriti std::get_if<std::vector<std::string>>(&allGroups); 1612599c71d8SAyushi Smriti 1613599c71d8SAyushi Smriti if (allGroupsList == nullptr || allGroupsList->empty()) 1614599c71d8SAyushi Smriti { 1615599c71d8SAyushi Smriti messages::internalError(asyncResp->res); 1616599c71d8SAyushi Smriti return; 1617599c71d8SAyushi Smriti } 1618599c71d8SAyushi Smriti 161904ae99ecSEd Tanous crow::connections::systemBus->async_method_call( 1620f23b7296SEd Tanous [asyncResp, username, 1621f23b7296SEd Tanous password](const boost::system::error_code ec2, 16220d4197e0Sanil kumar appana sdbusplus::message::message& m) { 162323a21a1cSEd Tanous if (ec2) 162404ae99ecSEd Tanous { 16256c51eab1SEd Tanous userErrorMessageHandler( 16266c51eab1SEd Tanous m.get_error(), asyncResp, username, ""); 162704ae99ecSEd Tanous return; 162804ae99ecSEd Tanous } 162904ae99ecSEd Tanous 163066b5ca76Sjayaprakash Mutyala if (pamUpdatePassword(username, password) != 163166b5ca76Sjayaprakash Mutyala PAM_SUCCESS) 163204ae99ecSEd Tanous { 16336c51eab1SEd Tanous // At this point we have a user that's been 16346c51eab1SEd Tanous // created, but the password set 16356c51eab1SEd Tanous // failed.Something is wrong, so delete the user 16366c51eab1SEd Tanous // that we've already created 163704ae99ecSEd Tanous crow::connections::systemBus->async_method_call( 163823a21a1cSEd Tanous [asyncResp, password]( 163923a21a1cSEd Tanous const boost::system::error_code ec3) { 164023a21a1cSEd Tanous if (ec3) 164104ae99ecSEd Tanous { 16426c51eab1SEd Tanous messages::internalError( 16436c51eab1SEd Tanous asyncResp->res); 164404ae99ecSEd Tanous return; 164504ae99ecSEd Tanous } 164604ae99ecSEd Tanous 16470d4197e0Sanil kumar appana // If password is invalid 16480d4197e0Sanil kumar appana messages::propertyValueFormatError( 16496c51eab1SEd Tanous asyncResp->res, password, 16506c51eab1SEd Tanous "Password"); 165104ae99ecSEd Tanous }, 165204ae99ecSEd Tanous "xyz.openbmc_project.User.Manager", 165304ae99ecSEd Tanous "/xyz/openbmc_project/user/" + username, 16546c51eab1SEd Tanous "xyz.openbmc_project.Object.Delete", 16556c51eab1SEd Tanous "Delete"); 165604ae99ecSEd Tanous 165704ae99ecSEd Tanous BMCWEB_LOG_ERROR << "pamUpdatePassword Failed"; 165804ae99ecSEd Tanous return; 165904ae99ecSEd Tanous } 166004ae99ecSEd Tanous 1661f12894f8SJason M. Bills messages::created(asyncResp->res); 166204ae99ecSEd Tanous asyncResp->res.addHeader( 166304ae99ecSEd Tanous "Location", 16646c51eab1SEd Tanous "/redfish/v1/AccountService/Accounts/" + 16656c51eab1SEd Tanous username); 166604ae99ecSEd Tanous }, 1667599c71d8SAyushi Smriti "xyz.openbmc_project.User.Manager", 1668599c71d8SAyushi Smriti "/xyz/openbmc_project/user", 16696c51eab1SEd Tanous "xyz.openbmc_project.User.Manager", "CreateUser", 16706c51eab1SEd Tanous username, *allGroupsList, *roleId, *enabled); 1671599c71d8SAyushi Smriti }, 1672599c71d8SAyushi Smriti "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", 1673599c71d8SAyushi Smriti "org.freedesktop.DBus.Properties", "Get", 1674599c71d8SAyushi Smriti "xyz.openbmc_project.User.Manager", "AllGroups"); 16756c51eab1SEd Tanous }); 1676b9b2e0b2SEd Tanous 16776c51eab1SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/") 1678ed398213SEd Tanous .privileges(redfish::privileges::getManagerAccount) 16796c51eab1SEd Tanous .methods( 16806c51eab1SEd Tanous boost::beast::http::verb:: 16816c51eab1SEd Tanous get)([](const crow::Request& req, 16826c51eab1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16836c51eab1SEd Tanous const std::string& accountName) -> void { 16846c51eab1SEd Tanous if (req.session->username != accountName) 1685b9b2e0b2SEd Tanous { 16866c51eab1SEd Tanous // At this point we've determined that the user is trying to 16876c51eab1SEd Tanous // modify a user that isn't them. We need to verify that they 16886c51eab1SEd Tanous // have permissions to modify other users, so re-run the auth 16896c51eab1SEd Tanous // check with the same permissions, minus ConfigureSelf. 16906c51eab1SEd Tanous Privileges effectiveUserPrivileges = 16916c51eab1SEd Tanous redfish::getUserPrivileges(req.userRole); 16926c51eab1SEd Tanous Privileges requiredPermissionsToChangeNonSelf = { 16934f48d5f6SEd Tanous "ConfigureUsers", "ConfigureManager"}; 16946c51eab1SEd Tanous if (!effectiveUserPrivileges.isSupersetOf( 16956c51eab1SEd Tanous requiredPermissionsToChangeNonSelf)) 1696900f9497SJoseph Reynolds { 1697900f9497SJoseph Reynolds BMCWEB_LOG_DEBUG << "GET Account denied access"; 1698900f9497SJoseph Reynolds messages::insufficientPrivilege(asyncResp->res); 1699900f9497SJoseph Reynolds return; 1700900f9497SJoseph Reynolds } 1701900f9497SJoseph Reynolds } 1702900f9497SJoseph Reynolds 1703b9b2e0b2SEd Tanous crow::connections::systemBus->async_method_call( 17046c51eab1SEd Tanous [asyncResp, accountName](const boost::system::error_code ec, 1705b9b2e0b2SEd Tanous const ManagedObjectType& users) { 1706b9b2e0b2SEd Tanous if (ec) 1707b9b2e0b2SEd Tanous { 1708f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1709b9b2e0b2SEd Tanous return; 1710b9b2e0b2SEd Tanous } 171184e12cb7SAppaRao Puli auto userIt = users.begin(); 1712b9b2e0b2SEd Tanous 171384e12cb7SAppaRao Puli for (; userIt != users.end(); userIt++) 1714b9b2e0b2SEd Tanous { 17156c51eab1SEd Tanous if (boost::ends_with(userIt->first.str, 17166c51eab1SEd Tanous "/" + accountName)) 1717b9b2e0b2SEd Tanous { 171884e12cb7SAppaRao Puli break; 1719b9b2e0b2SEd Tanous } 1720b9b2e0b2SEd Tanous } 172184e12cb7SAppaRao Puli if (userIt == users.end()) 1722b9b2e0b2SEd Tanous { 17236c51eab1SEd Tanous messages::resourceNotFound( 17246c51eab1SEd Tanous asyncResp->res, "ManagerAccount", accountName); 172584e12cb7SAppaRao Puli return; 172684e12cb7SAppaRao Puli } 17274e68c45bSAyushi Smriti 17284e68c45bSAyushi Smriti asyncResp->res.jsonValue = { 17296c51eab1SEd Tanous {"@odata.type", 17306c51eab1SEd Tanous "#ManagerAccount.v1_4_0.ManagerAccount"}, 17314e68c45bSAyushi Smriti {"Name", "User Account"}, 17324e68c45bSAyushi Smriti {"Description", "User Account"}, 17338114bd4dSGunnar Mills {"Password", nullptr}, 17348114bd4dSGunnar Mills {"AccountTypes", {"Redfish"}}}; 17354e68c45bSAyushi Smriti 173684e12cb7SAppaRao Puli for (const auto& interface : userIt->second) 173765b0dc32SEd Tanous { 173865b0dc32SEd Tanous if (interface.first == 173965b0dc32SEd Tanous "xyz.openbmc_project.User.Attributes") 174065b0dc32SEd Tanous { 174165b0dc32SEd Tanous for (const auto& property : interface.second) 174265b0dc32SEd Tanous { 174365b0dc32SEd Tanous if (property.first == "UserEnabled") 174465b0dc32SEd Tanous { 174565b0dc32SEd Tanous const bool* userEnabled = 1746abf2add6SEd Tanous std::get_if<bool>(&property.second); 174765b0dc32SEd Tanous if (userEnabled == nullptr) 174865b0dc32SEd Tanous { 174965b0dc32SEd Tanous BMCWEB_LOG_ERROR 175065b0dc32SEd Tanous << "UserEnabled wasn't a bool"; 175184e12cb7SAppaRao Puli messages::internalError(asyncResp->res); 175284e12cb7SAppaRao Puli return; 175365b0dc32SEd Tanous } 175465b0dc32SEd Tanous asyncResp->res.jsonValue["Enabled"] = 175565b0dc32SEd Tanous *userEnabled; 175665b0dc32SEd Tanous } 175765b0dc32SEd Tanous else if (property.first == 175865b0dc32SEd Tanous "UserLockedForFailedAttempt") 175965b0dc32SEd Tanous { 176065b0dc32SEd Tanous const bool* userLocked = 1761abf2add6SEd Tanous std::get_if<bool>(&property.second); 176265b0dc32SEd Tanous if (userLocked == nullptr) 176365b0dc32SEd Tanous { 176484e12cb7SAppaRao Puli BMCWEB_LOG_ERROR << "UserLockedForF" 176584e12cb7SAppaRao Puli "ailedAttempt " 176684e12cb7SAppaRao Puli "wasn't a bool"; 176784e12cb7SAppaRao Puli messages::internalError(asyncResp->res); 176884e12cb7SAppaRao Puli return; 176965b0dc32SEd Tanous } 177065b0dc32SEd Tanous asyncResp->res.jsonValue["Locked"] = 177165b0dc32SEd Tanous *userLocked; 177224c8542dSRatan Gupta asyncResp->res.jsonValue 177324c8542dSRatan Gupta ["Locked@Redfish.AllowableValues"] = { 17743bf4e632SJoseph Reynolds "false"}; // can only unlock accounts 177565b0dc32SEd Tanous } 177684e12cb7SAppaRao Puli else if (property.first == "UserPrivilege") 177784e12cb7SAppaRao Puli { 177854fc587aSNagaraju Goruganti const std::string* userPrivPtr = 17796c51eab1SEd Tanous std::get_if<std::string>( 17806c51eab1SEd Tanous &property.second); 178154fc587aSNagaraju Goruganti if (userPrivPtr == nullptr) 178284e12cb7SAppaRao Puli { 178384e12cb7SAppaRao Puli BMCWEB_LOG_ERROR 178484e12cb7SAppaRao Puli << "UserPrivilege wasn't a " 178584e12cb7SAppaRao Puli "string"; 178684e12cb7SAppaRao Puli messages::internalError(asyncResp->res); 178784e12cb7SAppaRao Puli return; 178884e12cb7SAppaRao Puli } 178954fc587aSNagaraju Goruganti std::string role = 179054fc587aSNagaraju Goruganti getRoleIdFromPrivilege(*userPrivPtr); 179154fc587aSNagaraju Goruganti if (role.empty()) 179284e12cb7SAppaRao Puli { 179384e12cb7SAppaRao Puli BMCWEB_LOG_ERROR << "Invalid user role"; 179484e12cb7SAppaRao Puli messages::internalError(asyncResp->res); 179584e12cb7SAppaRao Puli return; 179684e12cb7SAppaRao Puli } 179754fc587aSNagaraju Goruganti asyncResp->res.jsonValue["RoleId"] = role; 179884e12cb7SAppaRao Puli 17996c51eab1SEd Tanous asyncResp->res.jsonValue["Links"]["Role"] = 18006c51eab1SEd Tanous {{"@odata.id", 18016c51eab1SEd Tanous "/redfish/v1/AccountService/" 180284e12cb7SAppaRao Puli "Roles/" + 180354fc587aSNagaraju Goruganti role}}; 180484e12cb7SAppaRao Puli } 18056c51eab1SEd Tanous else if (property.first == 18066c51eab1SEd Tanous "UserPasswordExpired") 18073bf4e632SJoseph Reynolds { 18083bf4e632SJoseph Reynolds const bool* userPasswordExpired = 18093bf4e632SJoseph Reynolds std::get_if<bool>(&property.second); 18103bf4e632SJoseph Reynolds if (userPasswordExpired == nullptr) 18113bf4e632SJoseph Reynolds { 18123bf4e632SJoseph Reynolds BMCWEB_LOG_ERROR << "UserPassword" 18133bf4e632SJoseph Reynolds "Expired " 18143bf4e632SJoseph Reynolds "wasn't a bool"; 18153bf4e632SJoseph Reynolds messages::internalError(asyncResp->res); 18163bf4e632SJoseph Reynolds return; 18173bf4e632SJoseph Reynolds } 18183bf4e632SJoseph Reynolds asyncResp->res 18193bf4e632SJoseph Reynolds .jsonValue["PasswordChangeRequired"] = 18203bf4e632SJoseph Reynolds *userPasswordExpired; 18213bf4e632SJoseph Reynolds } 182265b0dc32SEd Tanous } 182365b0dc32SEd Tanous } 182465b0dc32SEd Tanous } 182565b0dc32SEd Tanous 1826b9b2e0b2SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 182784e12cb7SAppaRao Puli "/redfish/v1/AccountService/Accounts/" + accountName; 1828b9b2e0b2SEd Tanous asyncResp->res.jsonValue["Id"] = accountName; 1829b9b2e0b2SEd Tanous asyncResp->res.jsonValue["UserName"] = accountName; 1830b9b2e0b2SEd Tanous }, 1831b9b2e0b2SEd Tanous "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", 1832b9b2e0b2SEd Tanous "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 18336c51eab1SEd Tanous }); 1834a840879dSEd Tanous 18356c51eab1SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/") 1836ed398213SEd Tanous // TODO this privilege should be using the generated endpoints, but 1837ed398213SEd Tanous // because of the special handling of ConfigureSelf, it's not able to 1838ed398213SEd Tanous // yet 18396c51eab1SEd Tanous .privileges({{"ConfigureUsers"}, {"ConfigureSelf"}}) 18406c51eab1SEd Tanous .methods(boost::beast::http::verb::patch)( 18416c51eab1SEd Tanous [](const crow::Request& req, 18426c51eab1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 18436c51eab1SEd Tanous const std::string& username) -> void { 1844a24526dcSEd Tanous std::optional<std::string> newUserName; 1845a24526dcSEd Tanous std::optional<std::string> password; 1846a24526dcSEd Tanous std::optional<bool> enabled; 1847a24526dcSEd Tanous std::optional<std::string> roleId; 184824c8542dSRatan Gupta std::optional<bool> locked; 1849*e9cc5172SEd Tanous 1850*e9cc5172SEd Tanous Privileges effectiveUserPrivileges = 1851*e9cc5172SEd Tanous redfish::getUserPrivileges(req.userRole); 1852*e9cc5172SEd Tanous Privileges configureUsers = {"ConfigureUsers"}; 1853*e9cc5172SEd Tanous bool userHasConfigureUsers = 1854*e9cc5172SEd Tanous effectiveUserPrivileges.isSupersetOf(configureUsers); 1855*e9cc5172SEd Tanous if (userHasConfigureUsers) 1856*e9cc5172SEd Tanous { 1857*e9cc5172SEd Tanous // Users with ConfigureUsers can modify for all users 18586c51eab1SEd Tanous if (!json_util::readJson(req, asyncResp->res, "UserName", 18596c51eab1SEd Tanous newUserName, "Password", password, 1860*e9cc5172SEd Tanous "RoleId", roleId, "Enabled", 1861*e9cc5172SEd Tanous enabled, "Locked", locked)) 1862a840879dSEd Tanous { 1863a840879dSEd Tanous return; 1864a840879dSEd Tanous } 1865*e9cc5172SEd Tanous } 1866*e9cc5172SEd Tanous else 1867900f9497SJoseph Reynolds { 1868*e9cc5172SEd Tanous // ConfigureSelf accounts can only modify their own account 1869*e9cc5172SEd Tanous if (username != req.session->username) 1870900f9497SJoseph Reynolds { 1871900f9497SJoseph Reynolds messages::insufficientPrivilege(asyncResp->res); 1872900f9497SJoseph Reynolds return; 1873900f9497SJoseph Reynolds } 1874*e9cc5172SEd Tanous // ConfigureSelf accounts can only modify their password 1875*e9cc5172SEd Tanous if (!json_util::readJson(req, asyncResp->res, "Password", 1876*e9cc5172SEd Tanous password)) 1877*e9cc5172SEd Tanous { 1878*e9cc5172SEd Tanous return; 1879*e9cc5172SEd Tanous } 1880900f9497SJoseph Reynolds } 1881900f9497SJoseph Reynolds 188266b5ca76Sjayaprakash Mutyala // if user name is not provided in the patch method or if it 18836c51eab1SEd Tanous // matches the user name in the URI, then we are treating it as 18846c51eab1SEd Tanous // updating user properties other then username. If username 18856c51eab1SEd Tanous // provided doesn't match the URI, then we are treating this as 18866c51eab1SEd Tanous // user rename request. 188766b5ca76Sjayaprakash Mutyala if (!newUserName || (newUserName.value() == username)) 1888a840879dSEd Tanous { 18896c51eab1SEd Tanous updateUserProperties(asyncResp, username, password, enabled, 18906c51eab1SEd Tanous roleId, locked); 189184e12cb7SAppaRao Puli return; 189284e12cb7SAppaRao Puli } 189384e12cb7SAppaRao Puli crow::connections::systemBus->async_method_call( 18946c51eab1SEd Tanous [asyncResp, username, password(std::move(password)), 1895f23b7296SEd Tanous roleId(std::move(roleId)), enabled, 189666b5ca76Sjayaprakash Mutyala newUser{std::string(*newUserName)}, 1897f23b7296SEd Tanous locked](const boost::system::error_code ec, 189866b5ca76Sjayaprakash Mutyala sdbusplus::message::message& m) { 189984e12cb7SAppaRao Puli if (ec) 190084e12cb7SAppaRao Puli { 19016c51eab1SEd Tanous userErrorMessageHandler(m.get_error(), asyncResp, 19026c51eab1SEd Tanous newUser, username); 1903a840879dSEd Tanous return; 1904a840879dSEd Tanous } 1905a840879dSEd Tanous 19066c51eab1SEd Tanous updateUserProperties(asyncResp, newUser, password, 19076c51eab1SEd Tanous enabled, roleId, locked); 190884e12cb7SAppaRao Puli }, 19096c51eab1SEd Tanous "xyz.openbmc_project.User.Manager", 19106c51eab1SEd Tanous "/xyz/openbmc_project/user", 191184e12cb7SAppaRao Puli "xyz.openbmc_project.User.Manager", "RenameUser", username, 191284e12cb7SAppaRao Puli *newUserName); 19136c51eab1SEd Tanous }); 191484e12cb7SAppaRao Puli 19156c51eab1SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/") 1916ed398213SEd Tanous .privileges(redfish::privileges::deleteManagerAccount) 19176c51eab1SEd Tanous .methods(boost::beast::http::verb::delete_)( 19186c51eab1SEd Tanous [](const crow::Request& /*req*/, 19196c51eab1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 19206c51eab1SEd Tanous const std::string& username) -> void { 19216c51eab1SEd Tanous const std::string userPath = 19226c51eab1SEd Tanous "/xyz/openbmc_project/user/" + username; 192324c8542dSRatan Gupta 19246c51eab1SEd Tanous crow::connections::systemBus->async_method_call( 19256c51eab1SEd Tanous [asyncResp, username](const boost::system::error_code ec) { 19266c51eab1SEd Tanous if (ec) 192766b5ca76Sjayaprakash Mutyala { 192866b5ca76Sjayaprakash Mutyala messages::resourceNotFound( 192966b5ca76Sjayaprakash Mutyala asyncResp->res, 19306c51eab1SEd Tanous "#ManagerAccount.v1_4_0.ManagerAccount", 1931f12894f8SJason M. Bills username); 193206e086d9SEd Tanous return; 193306e086d9SEd Tanous } 193406e086d9SEd Tanous 1935f12894f8SJason M. Bills messages::accountRemoved(asyncResp->res); 193606e086d9SEd Tanous }, 193706e086d9SEd Tanous "xyz.openbmc_project.User.Manager", userPath, 193806e086d9SEd Tanous "xyz.openbmc_project.Object.Delete", "Delete"); 19396c51eab1SEd Tanous }); 194006e086d9SEd Tanous } 194188d16c9aSLewanczyk, Dawid 194288d16c9aSLewanczyk, Dawid } // namespace redfish 1943