Lewanczyk, Dawid | 88d16c9 | 2018-02-02 14:51:09 +0100 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
Lewanczyk, Dawid | 88d16c9 | 2018-02-02 14:51:09 +0100 | [diff] [blame] | 17 | #include "node.hpp" |
| 18 | |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 19 | #include <dbus_utility.hpp> |
Ed Tanous | 65b0dc3 | 2018-09-19 16:04:03 -0700 | [diff] [blame] | 20 | #include <error_messages.hpp> |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 21 | #include <openbmc_dbus_rest.hpp> |
Ed Tanous | a840879 | 2018-09-05 16:08:38 -0700 | [diff] [blame] | 22 | #include <utils/json_utils.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 23 | |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 24 | #include <variant> |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 25 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 26 | namespace redfish |
| 27 | { |
Lewanczyk, Dawid | 88d16c9 | 2018-02-02 14:51:09 +0100 | [diff] [blame] | 28 | |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 29 | constexpr const char* ldapConfigObject = |
| 30 | "/xyz/openbmc_project/user/ldap/openldap"; |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 31 | constexpr const char* ADConfigObject = |
| 32 | "/xyz/openbmc_project/user/ldap/active_directory"; |
| 33 | |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 34 | constexpr const char* ldapRootObject = "/xyz/openbmc_project/user/ldap"; |
| 35 | constexpr const char* ldapDbusService = "xyz.openbmc_project.Ldap.Config"; |
| 36 | constexpr const char* ldapConfigInterface = |
| 37 | "xyz.openbmc_project.User.Ldap.Config"; |
| 38 | constexpr const char* ldapCreateInterface = |
| 39 | "xyz.openbmc_project.User.Ldap.Create"; |
| 40 | constexpr const char* ldapEnableInterface = "xyz.openbmc_project.Object.Enable"; |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 41 | constexpr const char* ldapPrivMapperInterface = |
| 42 | "xyz.openbmc_project.User.PrivilegeMapper"; |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 43 | constexpr const char* dbusObjManagerIntf = "org.freedesktop.DBus.ObjectManager"; |
| 44 | constexpr const char* propertyInterface = "org.freedesktop.DBus.Properties"; |
| 45 | constexpr const char* mapperBusName = "xyz.openbmc_project.ObjectMapper"; |
| 46 | constexpr const char* mapperObjectPath = "/xyz/openbmc_project/object_mapper"; |
| 47 | constexpr const char* mapperIntf = "xyz.openbmc_project.ObjectMapper"; |
| 48 | |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 49 | struct LDAPRoleMapData |
| 50 | { |
| 51 | std::string groupName; |
| 52 | std::string privilege; |
| 53 | }; |
| 54 | |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 55 | struct LDAPConfigData |
| 56 | { |
| 57 | std::string uri{}; |
| 58 | std::string bindDN{}; |
| 59 | std::string baseDN{}; |
| 60 | std::string searchScope{}; |
| 61 | std::string serverType{}; |
| 62 | bool serviceEnabled = false; |
| 63 | std::string userNameAttribute{}; |
| 64 | std::string groupAttribute{}; |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 65 | std::vector<std::pair<std::string, LDAPRoleMapData>> groupRoleList; |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 66 | }; |
| 67 | |
Patrick Williams | 19bd78d | 2020-05-13 17:38:24 -0500 | [diff] [blame] | 68 | using DbusVariantType = std::variant<bool, int32_t, std::string>; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 69 | |
| 70 | using DbusInterfaceType = boost::container::flat_map< |
| 71 | std::string, boost::container::flat_map<std::string, DbusVariantType>>; |
| 72 | |
| 73 | using ManagedObjectType = |
| 74 | std::vector<std::pair<sdbusplus::message::object_path, DbusInterfaceType>>; |
| 75 | |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 76 | using GetObjectType = |
| 77 | std::vector<std::pair<std::string, std::vector<std::string>>>; |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 78 | |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 79 | inline std::string getRoleIdFromPrivilege(std::string_view role) |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 80 | { |
| 81 | if (role == "priv-admin") |
| 82 | { |
| 83 | return "Administrator"; |
| 84 | } |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 85 | else if (role == "priv-user") |
| 86 | { |
AppaRao Puli | c80fee5 | 2019-10-16 14:49:36 +0530 | [diff] [blame] | 87 | return "ReadOnly"; |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 88 | } |
| 89 | else if (role == "priv-operator") |
| 90 | { |
| 91 | return "Operator"; |
| 92 | } |
jayaprakash Mutyala | e9e6d24 | 2019-07-29 11:59:08 +0000 | [diff] [blame] | 93 | else if ((role == "") || (role == "priv-noaccess")) |
| 94 | { |
| 95 | return "NoAccess"; |
| 96 | } |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 97 | return ""; |
| 98 | } |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 99 | inline std::string getPrivilegeFromRoleId(std::string_view role) |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 100 | { |
| 101 | if (role == "Administrator") |
| 102 | { |
| 103 | return "priv-admin"; |
| 104 | } |
AppaRao Puli | c80fee5 | 2019-10-16 14:49:36 +0530 | [diff] [blame] | 105 | else if (role == "ReadOnly") |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 106 | { |
| 107 | return "priv-user"; |
| 108 | } |
| 109 | else if (role == "Operator") |
| 110 | { |
| 111 | return "priv-operator"; |
| 112 | } |
jayaprakash Mutyala | 9620060 | 2020-04-08 11:09:10 +0000 | [diff] [blame] | 113 | else if ((role == "NoAccess") || (role == "")) |
jayaprakash Mutyala | e9e6d24 | 2019-07-29 11:59:08 +0000 | [diff] [blame] | 114 | { |
| 115 | return "priv-noaccess"; |
| 116 | } |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 117 | return ""; |
| 118 | } |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 119 | |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 120 | void userErrorMessageHandler(const sd_bus_error* e, |
| 121 | std::shared_ptr<AsyncResp> asyncResp, |
| 122 | const std::string& newUser, |
| 123 | const std::string& username) |
| 124 | { |
| 125 | const char* errorMessage = e->name; |
| 126 | if (e == nullptr) |
| 127 | { |
| 128 | messages::internalError(asyncResp->res); |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | if (strcmp(errorMessage, |
| 133 | "xyz.openbmc_project.User.Common.Error.UserNameExists") == 0) |
| 134 | { |
| 135 | messages::resourceAlreadyExists(asyncResp->res, |
Gunnar Mills | 8114bd4 | 2020-06-11 20:55:21 -0500 | [diff] [blame] | 136 | "#ManagerAccount.v1_4_0.ManagerAccount", |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 137 | "UserName", newUser); |
| 138 | } |
| 139 | else if (strcmp(errorMessage, "xyz.openbmc_project.User.Common.Error." |
| 140 | "UserNameDoesNotExist") == 0) |
| 141 | { |
| 142 | messages::resourceNotFound( |
Gunnar Mills | 8114bd4 | 2020-06-11 20:55:21 -0500 | [diff] [blame] | 143 | asyncResp->res, "#ManagerAccount.v1_4_0.ManagerAccount", username); |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 144 | } |
| 145 | else if (strcmp(errorMessage, |
| 146 | "xyz.openbmc_project.Common.Error.InvalidArgument") == 0) |
| 147 | { |
| 148 | messages::propertyValueFormatError(asyncResp->res, newUser, "UserName"); |
| 149 | } |
| 150 | else if (strcmp(errorMessage, |
| 151 | "xyz.openbmc_project.User.Common.Error.NoResource") == 0) |
| 152 | { |
| 153 | messages::createLimitReachedForResource(asyncResp->res); |
| 154 | } |
| 155 | else if (strcmp(errorMessage, "xyz.openbmc_project.User.Common.Error." |
| 156 | "UserNameGroupFail") == 0) |
| 157 | { |
| 158 | messages::propertyValueFormatError(asyncResp->res, newUser, "UserName"); |
| 159 | } |
| 160 | else |
| 161 | { |
| 162 | messages::internalError(asyncResp->res); |
| 163 | } |
| 164 | |
| 165 | return; |
| 166 | } |
| 167 | |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 168 | void parseLDAPConfigData(nlohmann::json& json_response, |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 169 | const LDAPConfigData& confData, |
| 170 | const std::string& ldapType) |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 171 | { |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 172 | std::string service = |
| 173 | (ldapType == "LDAP") ? "LDAPService" : "ActiveDirectoryService"; |
Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 174 | nlohmann::json ldap = { |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 175 | {"ServiceEnabled", confData.serviceEnabled}, |
| 176 | {"ServiceAddresses", nlohmann::json::array({confData.uri})}, |
| 177 | {"Authentication", |
| 178 | {{"AuthenticationType", "UsernameAndPassword"}, |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 179 | {"Username", confData.bindDN}, |
| 180 | {"Password", nullptr}}}, |
| 181 | {"LDAPService", |
| 182 | {{"SearchSettings", |
| 183 | {{"BaseDistinguishedNames", |
| 184 | nlohmann::json::array({confData.baseDN})}, |
| 185 | {"UsernameAttribute", confData.userNameAttribute}, |
| 186 | {"GroupsAttribute", confData.groupAttribute}}}}}, |
| 187 | }; |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 188 | |
Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 189 | json_response[ldapType].update(std::move(ldap)); |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 190 | |
| 191 | nlohmann::json& roleMapArray = json_response[ldapType]["RemoteRoleMapping"]; |
| 192 | roleMapArray = nlohmann::json::array(); |
| 193 | for (auto& obj : confData.groupRoleList) |
| 194 | { |
| 195 | BMCWEB_LOG_DEBUG << "Pushing the data groupName=" |
| 196 | << obj.second.groupName << "\n"; |
| 197 | roleMapArray.push_back( |
| 198 | {nlohmann::json::array({"RemoteGroup", obj.second.groupName}), |
| 199 | nlohmann::json::array( |
| 200 | {"LocalRole", getRoleIdFromPrivilege(obj.second.privilege)})}); |
| 201 | } |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /** |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 205 | * @brief validates given JSON input and then calls appropriate method to |
| 206 | * create, to delete or to set Rolemapping object based on the given input. |
| 207 | * |
| 208 | */ |
| 209 | static void handleRoleMapPatch( |
| 210 | const std::shared_ptr<AsyncResp>& asyncResp, |
| 211 | const std::vector<std::pair<std::string, LDAPRoleMapData>>& roleMapObjData, |
| 212 | const std::string& serverType, std::vector<nlohmann::json>& input) |
| 213 | { |
| 214 | for (size_t index = 0; index < input.size(); index++) |
| 215 | { |
| 216 | nlohmann::json& thisJson = input[index]; |
| 217 | |
| 218 | if (thisJson.is_null()) |
| 219 | { |
| 220 | // delete the existing object |
| 221 | if (index < roleMapObjData.size()) |
| 222 | { |
| 223 | crow::connections::systemBus->async_method_call( |
| 224 | [asyncResp, roleMapObjData, serverType, |
| 225 | index](const boost::system::error_code ec) { |
| 226 | if (ec) |
| 227 | { |
| 228 | BMCWEB_LOG_ERROR << "DBUS response error: " << ec; |
| 229 | messages::internalError(asyncResp->res); |
| 230 | return; |
| 231 | } |
| 232 | asyncResp->res |
| 233 | .jsonValue[serverType]["RemoteRoleMapping"][index] = |
| 234 | nullptr; |
| 235 | }, |
| 236 | ldapDbusService, roleMapObjData[index].first, |
| 237 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 238 | } |
| 239 | else |
| 240 | { |
| 241 | BMCWEB_LOG_ERROR << "Can't delete the object"; |
| 242 | messages::propertyValueTypeError( |
| 243 | asyncResp->res, thisJson.dump(), |
| 244 | "RemoteRoleMapping/" + std::to_string(index)); |
| 245 | return; |
| 246 | } |
| 247 | } |
| 248 | else if (thisJson.empty()) |
| 249 | { |
| 250 | // Don't do anything for the empty objects,parse next json |
| 251 | // eg {"RemoteRoleMapping",[{}]} |
| 252 | } |
| 253 | else |
| 254 | { |
| 255 | // update/create the object |
| 256 | std::optional<std::string> remoteGroup; |
| 257 | std::optional<std::string> localRole; |
| 258 | |
| 259 | if (!json_util::readJson(thisJson, asyncResp->res, "RemoteGroup", |
| 260 | remoteGroup, "LocalRole", localRole)) |
| 261 | { |
| 262 | continue; |
| 263 | } |
| 264 | |
| 265 | // Update existing RoleMapping Object |
| 266 | if (index < roleMapObjData.size()) |
| 267 | { |
| 268 | BMCWEB_LOG_DEBUG << "Update Role Map Object"; |
| 269 | // If "RemoteGroup" info is provided |
| 270 | if (remoteGroup) |
| 271 | { |
| 272 | crow::connections::systemBus->async_method_call( |
| 273 | [asyncResp, roleMapObjData, serverType, index, |
| 274 | remoteGroup](const boost::system::error_code ec) { |
| 275 | if (ec) |
| 276 | { |
| 277 | BMCWEB_LOG_ERROR << "DBUS response error: " |
| 278 | << ec; |
| 279 | messages::internalError(asyncResp->res); |
| 280 | return; |
| 281 | } |
| 282 | asyncResp->res |
| 283 | .jsonValue[serverType]["RemoteRoleMapping"] |
| 284 | [index]["RemoteGroup"] = *remoteGroup; |
| 285 | }, |
| 286 | ldapDbusService, roleMapObjData[index].first, |
| 287 | propertyInterface, "Set", |
| 288 | "xyz.openbmc_project.User.PrivilegeMapperEntry", |
| 289 | "GroupName", |
| 290 | std::variant<std::string>(std::move(*remoteGroup))); |
| 291 | } |
| 292 | |
| 293 | // If "LocalRole" info is provided |
| 294 | if (localRole) |
| 295 | { |
| 296 | crow::connections::systemBus->async_method_call( |
| 297 | [asyncResp, roleMapObjData, serverType, index, |
| 298 | localRole](const boost::system::error_code ec) { |
| 299 | if (ec) |
| 300 | { |
| 301 | BMCWEB_LOG_ERROR << "DBUS response error: " |
| 302 | << ec; |
| 303 | messages::internalError(asyncResp->res); |
| 304 | return; |
| 305 | } |
| 306 | asyncResp->res |
| 307 | .jsonValue[serverType]["RemoteRoleMapping"] |
| 308 | [index]["LocalRole"] = *localRole; |
| 309 | }, |
| 310 | ldapDbusService, roleMapObjData[index].first, |
| 311 | propertyInterface, "Set", |
| 312 | "xyz.openbmc_project.User.PrivilegeMapperEntry", |
| 313 | "Privilege", |
| 314 | std::variant<std::string>( |
| 315 | getPrivilegeFromRoleId(std::move(*localRole)))); |
| 316 | } |
| 317 | } |
| 318 | // Create a new RoleMapping Object. |
| 319 | else |
| 320 | { |
| 321 | BMCWEB_LOG_DEBUG |
| 322 | << "setRoleMappingProperties: Creating new Object"; |
| 323 | std::string pathString = |
| 324 | "RemoteRoleMapping/" + std::to_string(index); |
| 325 | |
| 326 | if (!localRole) |
| 327 | { |
| 328 | messages::propertyMissing(asyncResp->res, |
| 329 | pathString + "/LocalRole"); |
| 330 | continue; |
| 331 | } |
| 332 | if (!remoteGroup) |
| 333 | { |
| 334 | messages::propertyMissing(asyncResp->res, |
| 335 | pathString + "/RemoteGroup"); |
| 336 | continue; |
| 337 | } |
| 338 | |
| 339 | std::string dbusObjectPath; |
| 340 | if (serverType == "ActiveDirectory") |
| 341 | { |
| 342 | dbusObjectPath = ADConfigObject; |
| 343 | } |
| 344 | else if (serverType == "LDAP") |
| 345 | { |
| 346 | dbusObjectPath = ldapConfigObject; |
| 347 | } |
| 348 | |
| 349 | BMCWEB_LOG_DEBUG << "Remote Group=" << *remoteGroup |
| 350 | << ",LocalRole=" << *localRole; |
| 351 | |
| 352 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 353 | [asyncResp, serverType, localRole, |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 354 | remoteGroup](const boost::system::error_code ec) { |
| 355 | if (ec) |
| 356 | { |
| 357 | BMCWEB_LOG_ERROR << "DBUS response error: " << ec; |
| 358 | messages::internalError(asyncResp->res); |
| 359 | return; |
| 360 | } |
| 361 | nlohmann::json& remoteRoleJson = |
| 362 | asyncResp->res |
| 363 | .jsonValue[serverType]["RemoteRoleMapping"]; |
| 364 | remoteRoleJson.push_back( |
| 365 | {{"LocalRole", *localRole}, |
| 366 | {"RemoteGroup", *remoteGroup}}); |
| 367 | }, |
| 368 | ldapDbusService, dbusObjectPath, ldapPrivMapperInterface, |
| 369 | "Create", std::move(*remoteGroup), |
| 370 | getPrivilegeFromRoleId(std::move(*localRole))); |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | /** |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 377 | * Function that retrieves all properties for LDAP config object |
| 378 | * into JSON |
| 379 | */ |
| 380 | template <typename CallbackFunc> |
| 381 | inline void getLDAPConfigData(const std::string& ldapType, |
| 382 | CallbackFunc&& callback) |
| 383 | { |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 384 | |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 385 | const std::array<const char*, 2> interfaces = {ldapEnableInterface, |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 386 | ldapConfigInterface}; |
| 387 | |
| 388 | crow::connections::systemBus->async_method_call( |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 389 | [callback, ldapType](const boost::system::error_code ec, |
| 390 | const GetObjectType& resp) { |
| 391 | LDAPConfigData confData{}; |
| 392 | if (ec || resp.empty()) |
| 393 | { |
| 394 | BMCWEB_LOG_ERROR << "DBUS response error during getting of " |
| 395 | "service name: " |
| 396 | << ec; |
| 397 | callback(false, confData, ldapType); |
| 398 | return; |
| 399 | } |
| 400 | std::string service = resp.begin()->first; |
| 401 | crow::connections::systemBus->async_method_call( |
| 402 | [callback, ldapType](const boost::system::error_code error_code, |
| 403 | const ManagedObjectType& ldapObjects) { |
| 404 | LDAPConfigData confData{}; |
| 405 | if (error_code) |
| 406 | { |
| 407 | callback(false, confData, ldapType); |
| 408 | BMCWEB_LOG_ERROR << "D-Bus responses error: " |
| 409 | << error_code; |
| 410 | return; |
| 411 | } |
| 412 | |
| 413 | std::string ldapDbusType; |
| 414 | std::string searchString; |
| 415 | |
| 416 | if (ldapType == "LDAP") |
| 417 | { |
| 418 | ldapDbusType = "xyz.openbmc_project.User.Ldap.Config." |
| 419 | "Type.OpenLdap"; |
| 420 | searchString = "openldap"; |
| 421 | } |
| 422 | else if (ldapType == "ActiveDirectory") |
| 423 | { |
| 424 | ldapDbusType = |
| 425 | "xyz.openbmc_project.User.Ldap.Config.Type." |
| 426 | "ActiveDirectory"; |
| 427 | searchString = "active_directory"; |
| 428 | } |
| 429 | else |
| 430 | { |
| 431 | BMCWEB_LOG_ERROR |
| 432 | << "Can't get the DbusType for the given type=" |
| 433 | << ldapType; |
| 434 | callback(false, confData, ldapType); |
| 435 | return; |
| 436 | } |
| 437 | |
| 438 | std::string ldapEnableInterfaceStr = ldapEnableInterface; |
| 439 | std::string ldapConfigInterfaceStr = ldapConfigInterface; |
| 440 | |
| 441 | for (const auto& object : ldapObjects) |
| 442 | { |
| 443 | // let's find the object whose ldap type is equal to the |
| 444 | // given type |
| 445 | if (object.first.str.find(searchString) == |
| 446 | std::string::npos) |
| 447 | { |
| 448 | continue; |
| 449 | } |
| 450 | |
| 451 | for (const auto& interface : object.second) |
| 452 | { |
| 453 | if (interface.first == ldapEnableInterfaceStr) |
| 454 | { |
| 455 | // rest of the properties are string. |
| 456 | for (const auto& property : interface.second) |
| 457 | { |
| 458 | if (property.first == "Enabled") |
| 459 | { |
| 460 | const bool* value = |
| 461 | std::get_if<bool>(&property.second); |
| 462 | if (value == nullptr) |
| 463 | { |
| 464 | continue; |
| 465 | } |
| 466 | confData.serviceEnabled = *value; |
| 467 | break; |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | else if (interface.first == ldapConfigInterfaceStr) |
| 472 | { |
| 473 | |
| 474 | for (const auto& property : interface.second) |
| 475 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 476 | const std::string* strValue = |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 477 | std::get_if<std::string>( |
| 478 | &property.second); |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 479 | if (strValue == nullptr) |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 480 | { |
| 481 | continue; |
| 482 | } |
| 483 | if (property.first == "LDAPServerURI") |
| 484 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 485 | confData.uri = *strValue; |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 486 | } |
| 487 | else if (property.first == "LDAPBindDN") |
| 488 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 489 | confData.bindDN = *strValue; |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 490 | } |
| 491 | else if (property.first == "LDAPBaseDN") |
| 492 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 493 | confData.baseDN = *strValue; |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 494 | } |
| 495 | else if (property.first == |
| 496 | "LDAPSearchScope") |
| 497 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 498 | confData.searchScope = *strValue; |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 499 | } |
| 500 | else if (property.first == |
| 501 | "GroupNameAttribute") |
| 502 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 503 | confData.groupAttribute = *strValue; |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 504 | } |
| 505 | else if (property.first == |
| 506 | "UserNameAttribute") |
| 507 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 508 | confData.userNameAttribute = *strValue; |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 509 | } |
| 510 | else if (property.first == "LDAPType") |
| 511 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 512 | confData.serverType = *strValue; |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | } |
| 516 | else if (interface.first == |
| 517 | "xyz.openbmc_project.User." |
| 518 | "PrivilegeMapperEntry") |
| 519 | { |
| 520 | LDAPRoleMapData roleMapData{}; |
| 521 | for (const auto& property : interface.second) |
| 522 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 523 | const std::string* strValue = |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 524 | std::get_if<std::string>( |
| 525 | &property.second); |
| 526 | |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 527 | if (strValue == nullptr) |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 528 | { |
| 529 | continue; |
| 530 | } |
| 531 | |
| 532 | if (property.first == "GroupName") |
| 533 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 534 | roleMapData.groupName = *strValue; |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 535 | } |
| 536 | else if (property.first == "Privilege") |
| 537 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 538 | roleMapData.privilege = *strValue; |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | |
Ed Tanous | 0f0353b | 2019-10-24 11:37:51 -0700 | [diff] [blame] | 542 | confData.groupRoleList.emplace_back( |
| 543 | object.first.str, roleMapData); |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 544 | } |
| 545 | } |
| 546 | } |
| 547 | callback(true, confData, ldapType); |
| 548 | }, |
| 549 | service, ldapRootObject, dbusObjManagerIntf, |
| 550 | "GetManagedObjects"); |
| 551 | }, |
| 552 | mapperBusName, mapperObjectPath, mapperIntf, "GetObject", |
| 553 | ldapConfigObject, interfaces); |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 554 | } |
| 555 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 556 | class AccountService : public Node |
| 557 | { |
| 558 | public: |
Zbigniew Kurzynski | 7815863 | 2019-11-05 12:57:37 +0100 | [diff] [blame] | 559 | AccountService(CrowApp& app) : |
| 560 | Node(app, "/redfish/v1/AccountService/"), app(app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 561 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 562 | entityPrivileges = { |
Gunnar Mills | 3c5a376 | 2020-01-29 15:21:30 -0600 | [diff] [blame] | 563 | {boost::beast::http::verb::get, {{"Login"}}}, |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 564 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 565 | {boost::beast::http::verb::patch, {{"ConfigureUsers"}}}, |
| 566 | {boost::beast::http::verb::put, {{"ConfigureUsers"}}}, |
| 567 | {boost::beast::http::verb::delete_, {{"ConfigureUsers"}}}, |
| 568 | {boost::beast::http::verb::post, {{"ConfigureUsers"}}}}; |
| 569 | } |
Lewanczyk, Dawid | 88d16c9 | 2018-02-02 14:51:09 +0100 | [diff] [blame] | 570 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 571 | private: |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 572 | /** |
| 573 | * @brief parses the authentication section under the LDAP |
| 574 | * @param input JSON data |
| 575 | * @param asyncResp pointer to the JSON response |
| 576 | * @param userName userName to be filled from the given JSON. |
| 577 | * @param password password to be filled from the given JSON. |
| 578 | */ |
| 579 | void |
| 580 | parseLDAPAuthenticationJson(nlohmann::json input, |
| 581 | const std::shared_ptr<AsyncResp>& asyncResp, |
| 582 | std::optional<std::string>& username, |
| 583 | std::optional<std::string>& password) |
| 584 | { |
| 585 | std::optional<std::string> authType; |
| 586 | |
| 587 | if (!json_util::readJson(input, asyncResp->res, "AuthenticationType", |
| 588 | authType, "Username", username, "Password", |
| 589 | password)) |
| 590 | { |
| 591 | return; |
| 592 | } |
| 593 | if (!authType) |
| 594 | { |
| 595 | return; |
| 596 | } |
| 597 | if (*authType != "UsernameAndPassword") |
| 598 | { |
| 599 | messages::propertyValueNotInList(asyncResp->res, *authType, |
| 600 | "AuthenticationType"); |
| 601 | return; |
| 602 | } |
| 603 | } |
| 604 | /** |
| 605 | * @brief parses the LDAPService section under the LDAP |
| 606 | * @param input JSON data |
| 607 | * @param asyncResp pointer to the JSON response |
| 608 | * @param baseDNList baseDN to be filled from the given JSON. |
| 609 | * @param userNameAttribute userName to be filled from the given JSON. |
| 610 | * @param groupaAttribute password to be filled from the given JSON. |
| 611 | */ |
| 612 | |
| 613 | void parseLDAPServiceJson( |
| 614 | nlohmann::json input, const std::shared_ptr<AsyncResp>& asyncResp, |
| 615 | std::optional<std::vector<std::string>>& baseDNList, |
| 616 | std::optional<std::string>& userNameAttribute, |
| 617 | std::optional<std::string>& groupsAttribute) |
| 618 | { |
| 619 | std::optional<nlohmann::json> searchSettings; |
| 620 | |
| 621 | if (!json_util::readJson(input, asyncResp->res, "SearchSettings", |
| 622 | searchSettings)) |
| 623 | { |
| 624 | return; |
| 625 | } |
| 626 | if (!searchSettings) |
| 627 | { |
| 628 | return; |
| 629 | } |
| 630 | if (!json_util::readJson(*searchSettings, asyncResp->res, |
| 631 | "BaseDistinguishedNames", baseDNList, |
| 632 | "UsernameAttribute", userNameAttribute, |
| 633 | "GroupsAttribute", groupsAttribute)) |
| 634 | { |
| 635 | return; |
| 636 | } |
| 637 | } |
| 638 | /** |
| 639 | * @brief updates the LDAP server address and updates the |
| 640 | json response with the new value. |
| 641 | * @param serviceAddressList address to be updated. |
| 642 | * @param asyncResp pointer to the JSON response |
| 643 | * @param ldapServerElementName Type of LDAP |
| 644 | server(openLDAP/ActiveDirectory) |
| 645 | */ |
| 646 | |
| 647 | void handleServiceAddressPatch( |
| 648 | const std::vector<std::string>& serviceAddressList, |
| 649 | const std::shared_ptr<AsyncResp>& asyncResp, |
| 650 | const std::string& ldapServerElementName, |
| 651 | const std::string& ldapConfigObject) |
| 652 | { |
| 653 | crow::connections::systemBus->async_method_call( |
| 654 | [asyncResp, ldapServerElementName, |
| 655 | serviceAddressList](const boost::system::error_code ec) { |
| 656 | if (ec) |
| 657 | { |
| 658 | BMCWEB_LOG_DEBUG |
Gunnar Mills | c61704a | 2020-07-08 13:47:06 -0500 | [diff] [blame^] | 659 | << "Error Occurred in updating the service address"; |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 660 | messages::internalError(asyncResp->res); |
| 661 | return; |
| 662 | } |
| 663 | std::vector<std::string> modifiedserviceAddressList = { |
| 664 | serviceAddressList.front()}; |
| 665 | asyncResp->res |
| 666 | .jsonValue[ldapServerElementName]["ServiceAddresses"] = |
| 667 | modifiedserviceAddressList; |
| 668 | if ((serviceAddressList).size() > 1) |
| 669 | { |
| 670 | messages::propertyValueModified(asyncResp->res, |
| 671 | "ServiceAddresses", |
| 672 | serviceAddressList.front()); |
| 673 | } |
| 674 | BMCWEB_LOG_DEBUG << "Updated the service address"; |
| 675 | }, |
| 676 | ldapDbusService, ldapConfigObject, propertyInterface, "Set", |
| 677 | ldapConfigInterface, "LDAPServerURI", |
| 678 | std::variant<std::string>(serviceAddressList.front())); |
| 679 | } |
| 680 | /** |
| 681 | * @brief updates the LDAP Bind DN and updates the |
| 682 | json response with the new value. |
| 683 | * @param username name of the user which needs to be updated. |
| 684 | * @param asyncResp pointer to the JSON response |
| 685 | * @param ldapServerElementName Type of LDAP |
| 686 | server(openLDAP/ActiveDirectory) |
| 687 | */ |
| 688 | |
| 689 | void handleUserNamePatch(const std::string& username, |
| 690 | const std::shared_ptr<AsyncResp>& asyncResp, |
| 691 | const std::string& ldapServerElementName, |
| 692 | const std::string& ldapConfigObject) |
| 693 | { |
| 694 | crow::connections::systemBus->async_method_call( |
| 695 | [asyncResp, username, |
| 696 | ldapServerElementName](const boost::system::error_code ec) { |
| 697 | if (ec) |
| 698 | { |
| 699 | BMCWEB_LOG_DEBUG |
Gunnar Mills | c61704a | 2020-07-08 13:47:06 -0500 | [diff] [blame^] | 700 | << "Error occurred in updating the username"; |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 701 | messages::internalError(asyncResp->res); |
| 702 | return; |
| 703 | } |
| 704 | asyncResp->res.jsonValue[ldapServerElementName] |
| 705 | ["Authentication"]["Username"] = |
| 706 | username; |
| 707 | BMCWEB_LOG_DEBUG << "Updated the username"; |
| 708 | }, |
| 709 | ldapDbusService, ldapConfigObject, propertyInterface, "Set", |
| 710 | ldapConfigInterface, "LDAPBindDN", |
| 711 | std::variant<std::string>(username)); |
| 712 | } |
| 713 | |
| 714 | /** |
| 715 | * @brief updates the LDAP password |
| 716 | * @param password : ldap password which needs to be updated. |
| 717 | * @param asyncResp pointer to the JSON response |
| 718 | * @param ldapServerElementName Type of LDAP |
| 719 | * server(openLDAP/ActiveDirectory) |
| 720 | */ |
| 721 | |
| 722 | void handlePasswordPatch(const std::string& password, |
| 723 | const std::shared_ptr<AsyncResp>& asyncResp, |
| 724 | const std::string& ldapServerElementName, |
| 725 | const std::string& ldapConfigObject) |
| 726 | { |
| 727 | crow::connections::systemBus->async_method_call( |
| 728 | [asyncResp, password, |
| 729 | ldapServerElementName](const boost::system::error_code ec) { |
| 730 | if (ec) |
| 731 | { |
| 732 | BMCWEB_LOG_DEBUG |
Gunnar Mills | c61704a | 2020-07-08 13:47:06 -0500 | [diff] [blame^] | 733 | << "Error occurred in updating the password"; |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 734 | messages::internalError(asyncResp->res); |
| 735 | return; |
| 736 | } |
| 737 | asyncResp->res.jsonValue[ldapServerElementName] |
| 738 | ["Authentication"]["Password"] = ""; |
| 739 | BMCWEB_LOG_DEBUG << "Updated the password"; |
| 740 | }, |
| 741 | ldapDbusService, ldapConfigObject, propertyInterface, "Set", |
| 742 | ldapConfigInterface, "LDAPBindDNPassword", |
| 743 | std::variant<std::string>(password)); |
| 744 | } |
| 745 | |
| 746 | /** |
| 747 | * @brief updates the LDAP BaseDN and updates the |
| 748 | json response with the new value. |
| 749 | * @param baseDNList baseDN list which needs to be updated. |
| 750 | * @param asyncResp pointer to the JSON response |
| 751 | * @param ldapServerElementName Type of LDAP |
| 752 | server(openLDAP/ActiveDirectory) |
| 753 | */ |
| 754 | |
| 755 | void handleBaseDNPatch(const std::vector<std::string>& baseDNList, |
| 756 | const std::shared_ptr<AsyncResp>& asyncResp, |
| 757 | const std::string& ldapServerElementName, |
| 758 | const std::string& ldapConfigObject) |
| 759 | { |
| 760 | crow::connections::systemBus->async_method_call( |
| 761 | [asyncResp, baseDNList, |
| 762 | ldapServerElementName](const boost::system::error_code ec) { |
| 763 | if (ec) |
| 764 | { |
Gunnar Mills | c61704a | 2020-07-08 13:47:06 -0500 | [diff] [blame^] | 765 | BMCWEB_LOG_DEBUG |
| 766 | << "Error Occurred in Updating the base DN"; |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 767 | messages::internalError(asyncResp->res); |
| 768 | return; |
| 769 | } |
| 770 | auto& serverTypeJson = |
| 771 | asyncResp->res.jsonValue[ldapServerElementName]; |
| 772 | auto& searchSettingsJson = |
| 773 | serverTypeJson["LDAPService"]["SearchSettings"]; |
| 774 | std::vector<std::string> modifiedBaseDNList = { |
| 775 | baseDNList.front()}; |
| 776 | searchSettingsJson["BaseDistinguishedNames"] = |
| 777 | modifiedBaseDNList; |
| 778 | if (baseDNList.size() > 1) |
| 779 | { |
| 780 | messages::propertyValueModified(asyncResp->res, |
| 781 | "BaseDistinguishedNames", |
| 782 | baseDNList.front()); |
| 783 | } |
| 784 | BMCWEB_LOG_DEBUG << "Updated the base DN"; |
| 785 | }, |
| 786 | ldapDbusService, ldapConfigObject, propertyInterface, "Set", |
| 787 | ldapConfigInterface, "LDAPBaseDN", |
| 788 | std::variant<std::string>(baseDNList.front())); |
| 789 | } |
| 790 | /** |
| 791 | * @brief updates the LDAP user name attribute and updates the |
| 792 | json response with the new value. |
| 793 | * @param userNameAttribute attribute to be updated. |
| 794 | * @param asyncResp pointer to the JSON response |
| 795 | * @param ldapServerElementName Type of LDAP |
| 796 | server(openLDAP/ActiveDirectory) |
| 797 | */ |
| 798 | |
| 799 | void handleUserNameAttrPatch(const std::string& userNameAttribute, |
| 800 | const std::shared_ptr<AsyncResp>& asyncResp, |
| 801 | const std::string& ldapServerElementName, |
| 802 | const std::string& ldapConfigObject) |
| 803 | { |
| 804 | crow::connections::systemBus->async_method_call( |
| 805 | [asyncResp, userNameAttribute, |
| 806 | ldapServerElementName](const boost::system::error_code ec) { |
| 807 | if (ec) |
| 808 | { |
Gunnar Mills | c61704a | 2020-07-08 13:47:06 -0500 | [diff] [blame^] | 809 | BMCWEB_LOG_DEBUG << "Error Occurred in Updating the " |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 810 | "username attribute"; |
| 811 | messages::internalError(asyncResp->res); |
| 812 | return; |
| 813 | } |
| 814 | auto& serverTypeJson = |
| 815 | asyncResp->res.jsonValue[ldapServerElementName]; |
| 816 | auto& searchSettingsJson = |
| 817 | serverTypeJson["LDAPService"]["SearchSettings"]; |
| 818 | searchSettingsJson["UsernameAttribute"] = userNameAttribute; |
| 819 | BMCWEB_LOG_DEBUG << "Updated the user name attr."; |
| 820 | }, |
| 821 | ldapDbusService, ldapConfigObject, propertyInterface, "Set", |
| 822 | ldapConfigInterface, "UserNameAttribute", |
| 823 | std::variant<std::string>(userNameAttribute)); |
| 824 | } |
| 825 | /** |
| 826 | * @brief updates the LDAP group attribute and updates the |
| 827 | json response with the new value. |
| 828 | * @param groupsAttribute attribute to be updated. |
| 829 | * @param asyncResp pointer to the JSON response |
| 830 | * @param ldapServerElementName Type of LDAP |
| 831 | server(openLDAP/ActiveDirectory) |
| 832 | */ |
| 833 | |
| 834 | void handleGroupNameAttrPatch(const std::string& groupsAttribute, |
| 835 | const std::shared_ptr<AsyncResp>& asyncResp, |
| 836 | const std::string& ldapServerElementName, |
| 837 | const std::string& ldapConfigObject) |
| 838 | { |
| 839 | crow::connections::systemBus->async_method_call( |
| 840 | [asyncResp, groupsAttribute, |
| 841 | ldapServerElementName](const boost::system::error_code ec) { |
| 842 | if (ec) |
| 843 | { |
Gunnar Mills | c61704a | 2020-07-08 13:47:06 -0500 | [diff] [blame^] | 844 | BMCWEB_LOG_DEBUG << "Error Occurred in Updating the " |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 845 | "groupname attribute"; |
| 846 | messages::internalError(asyncResp->res); |
| 847 | return; |
| 848 | } |
| 849 | auto& serverTypeJson = |
| 850 | asyncResp->res.jsonValue[ldapServerElementName]; |
| 851 | auto& searchSettingsJson = |
| 852 | serverTypeJson["LDAPService"]["SearchSettings"]; |
| 853 | searchSettingsJson["GroupsAttribute"] = groupsAttribute; |
| 854 | BMCWEB_LOG_DEBUG << "Updated the groupname attr"; |
| 855 | }, |
| 856 | ldapDbusService, ldapConfigObject, propertyInterface, "Set", |
| 857 | ldapConfigInterface, "GroupNameAttribute", |
| 858 | std::variant<std::string>(groupsAttribute)); |
| 859 | } |
| 860 | /** |
| 861 | * @brief updates the LDAP service enable and updates the |
| 862 | json response with the new value. |
| 863 | * @param input JSON data. |
| 864 | * @param asyncResp pointer to the JSON response |
| 865 | * @param ldapServerElementName Type of LDAP |
| 866 | server(openLDAP/ActiveDirectory) |
| 867 | */ |
| 868 | |
| 869 | void handleServiceEnablePatch(bool serviceEnabled, |
| 870 | const std::shared_ptr<AsyncResp>& asyncResp, |
| 871 | const std::string& ldapServerElementName, |
| 872 | const std::string& ldapConfigObject) |
| 873 | { |
| 874 | crow::connections::systemBus->async_method_call( |
| 875 | [asyncResp, serviceEnabled, |
| 876 | ldapServerElementName](const boost::system::error_code ec) { |
| 877 | if (ec) |
| 878 | { |
| 879 | BMCWEB_LOG_DEBUG |
Gunnar Mills | c61704a | 2020-07-08 13:47:06 -0500 | [diff] [blame^] | 880 | << "Error Occurred in Updating the service enable"; |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 881 | messages::internalError(asyncResp->res); |
| 882 | return; |
| 883 | } |
| 884 | asyncResp->res |
| 885 | .jsonValue[ldapServerElementName]["ServiceEnabled"] = |
| 886 | serviceEnabled; |
| 887 | BMCWEB_LOG_DEBUG << "Updated Service enable = " |
| 888 | << serviceEnabled; |
| 889 | }, |
| 890 | ldapDbusService, ldapConfigObject, propertyInterface, "Set", |
| 891 | ldapEnableInterface, "Enabled", std::variant<bool>(serviceEnabled)); |
| 892 | } |
| 893 | |
Zbigniew Kurzynski | 7815863 | 2019-11-05 12:57:37 +0100 | [diff] [blame] | 894 | void handleAuthMethodsPatch(nlohmann::json& input, |
| 895 | const std::shared_ptr<AsyncResp>& asyncResp) |
| 896 | { |
| 897 | std::optional<bool> basicAuth; |
| 898 | std::optional<bool> cookie; |
| 899 | std::optional<bool> sessionToken; |
| 900 | std::optional<bool> xToken; |
Zbigniew Kurzynski | 501f1e5 | 2019-10-02 11:22:11 +0200 | [diff] [blame] | 901 | std::optional<bool> tls; |
Zbigniew Kurzynski | 7815863 | 2019-11-05 12:57:37 +0100 | [diff] [blame] | 902 | |
| 903 | if (!json_util::readJson(input, asyncResp->res, "BasicAuth", basicAuth, |
| 904 | "Cookie", cookie, "SessionToken", sessionToken, |
Zbigniew Kurzynski | 501f1e5 | 2019-10-02 11:22:11 +0200 | [diff] [blame] | 905 | "XToken", xToken, "TLS", tls)) |
Zbigniew Kurzynski | 7815863 | 2019-11-05 12:57:37 +0100 | [diff] [blame] | 906 | { |
| 907 | BMCWEB_LOG_ERROR << "Cannot read values from AuthMethod tag"; |
| 908 | return; |
| 909 | } |
| 910 | |
| 911 | // Make a copy of methods configuration |
| 912 | crow::persistent_data::AuthConfigMethods authMethodsConfig = |
| 913 | crow::persistent_data::SessionStore::getInstance() |
| 914 | .getAuthMethodsConfig(); |
| 915 | |
| 916 | if (basicAuth) |
| 917 | { |
| 918 | authMethodsConfig.basic = *basicAuth; |
| 919 | } |
| 920 | |
| 921 | if (cookie) |
| 922 | { |
| 923 | authMethodsConfig.cookie = *cookie; |
| 924 | } |
| 925 | |
| 926 | if (sessionToken) |
| 927 | { |
| 928 | authMethodsConfig.sessionToken = *sessionToken; |
| 929 | } |
| 930 | |
| 931 | if (xToken) |
| 932 | { |
| 933 | authMethodsConfig.xtoken = *xToken; |
| 934 | } |
| 935 | |
Zbigniew Kurzynski | 501f1e5 | 2019-10-02 11:22:11 +0200 | [diff] [blame] | 936 | if (tls) |
| 937 | { |
| 938 | authMethodsConfig.tls = *tls; |
| 939 | } |
| 940 | |
Zbigniew Kurzynski | 7815863 | 2019-11-05 12:57:37 +0100 | [diff] [blame] | 941 | if (!authMethodsConfig.basic && !authMethodsConfig.cookie && |
Zbigniew Kurzynski | 501f1e5 | 2019-10-02 11:22:11 +0200 | [diff] [blame] | 942 | !authMethodsConfig.sessionToken && !authMethodsConfig.xtoken && |
| 943 | !authMethodsConfig.tls) |
Zbigniew Kurzynski | 7815863 | 2019-11-05 12:57:37 +0100 | [diff] [blame] | 944 | { |
| 945 | // Do not allow user to disable everything |
| 946 | messages::actionNotSupported(asyncResp->res, |
| 947 | "of disabling all available methods"); |
| 948 | return; |
| 949 | } |
| 950 | |
| 951 | crow::persistent_data::SessionStore::getInstance() |
| 952 | .updateAuthMethodsConfig(authMethodsConfig); |
| 953 | // Save configuration immediately |
| 954 | app.template getMiddleware<crow::persistent_data::Middleware>() |
| 955 | .writeData(); |
| 956 | |
| 957 | messages::success(asyncResp->res); |
| 958 | } |
| 959 | |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 960 | /** |
| 961 | * @brief Get the required values from the given JSON, validates the |
| 962 | * value and create the LDAP config object. |
| 963 | * @param input JSON data |
| 964 | * @param asyncResp pointer to the JSON response |
| 965 | * @param serverType Type of LDAP server(openLDAP/ActiveDirectory) |
| 966 | */ |
| 967 | |
| 968 | void handleLDAPPatch(nlohmann::json& input, |
| 969 | const std::shared_ptr<AsyncResp>& asyncResp, |
| 970 | const crow::Request& req, |
| 971 | const std::vector<std::string>& params, |
| 972 | const std::string& serverType) |
| 973 | { |
Ratan Gupta | eb2bbe5 | 2019-04-22 14:27:01 +0530 | [diff] [blame] | 974 | std::string dbusObjectPath; |
| 975 | if (serverType == "ActiveDirectory") |
| 976 | { |
| 977 | dbusObjectPath = ADConfigObject; |
| 978 | } |
| 979 | else if (serverType == "LDAP") |
| 980 | { |
| 981 | dbusObjectPath = ldapConfigObject; |
| 982 | } |
| 983 | |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 984 | std::optional<nlohmann::json> authentication; |
| 985 | std::optional<nlohmann::json> ldapService; |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 986 | std::optional<std::vector<std::string>> serviceAddressList; |
| 987 | std::optional<bool> serviceEnabled; |
| 988 | std::optional<std::vector<std::string>> baseDNList; |
| 989 | std::optional<std::string> userNameAttribute; |
| 990 | std::optional<std::string> groupsAttribute; |
| 991 | std::optional<std::string> userName; |
| 992 | std::optional<std::string> password; |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 993 | std::optional<std::vector<nlohmann::json>> remoteRoleMapData; |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 994 | |
| 995 | if (!json_util::readJson(input, asyncResp->res, "Authentication", |
| 996 | authentication, "LDAPService", ldapService, |
| 997 | "ServiceAddresses", serviceAddressList, |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 998 | "ServiceEnabled", serviceEnabled, |
| 999 | "RemoteRoleMapping", remoteRoleMapData)) |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1000 | { |
| 1001 | return; |
| 1002 | } |
| 1003 | |
| 1004 | if (authentication) |
| 1005 | { |
| 1006 | parseLDAPAuthenticationJson(*authentication, asyncResp, userName, |
| 1007 | password); |
| 1008 | } |
| 1009 | if (ldapService) |
| 1010 | { |
| 1011 | parseLDAPServiceJson(*ldapService, asyncResp, baseDNList, |
| 1012 | userNameAttribute, groupsAttribute); |
| 1013 | } |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1014 | if (serviceAddressList) |
| 1015 | { |
| 1016 | if ((*serviceAddressList).size() == 0) |
| 1017 | { |
| 1018 | messages::propertyValueNotInList(asyncResp->res, "[]", |
| 1019 | "ServiceAddress"); |
| 1020 | return; |
| 1021 | } |
| 1022 | } |
| 1023 | if (baseDNList) |
| 1024 | { |
| 1025 | if ((*baseDNList).size() == 0) |
| 1026 | { |
| 1027 | messages::propertyValueNotInList(asyncResp->res, "[]", |
| 1028 | "BaseDistinguishedNames"); |
| 1029 | return; |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | // nothing to update, then return |
| 1034 | if (!userName && !password && !serviceAddressList && !baseDNList && |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 1035 | !userNameAttribute && !groupsAttribute && !serviceEnabled && |
| 1036 | !remoteRoleMapData) |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1037 | { |
| 1038 | return; |
| 1039 | } |
| 1040 | |
| 1041 | // Get the existing resource first then keep modifying |
| 1042 | // whenever any property gets updated. |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1043 | getLDAPConfigData(serverType, [this, asyncResp, userName, password, |
| 1044 | baseDNList, userNameAttribute, |
Gunnar Mills | ba9dd4a | 2020-02-20 10:40:18 -0600 | [diff] [blame] | 1045 | groupsAttribute, serviceAddressList, |
| 1046 | serviceEnabled, dbusObjectPath, |
| 1047 | remoteRoleMapData]( |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1048 | bool success, LDAPConfigData confData, |
| 1049 | const std::string& serverType) { |
| 1050 | if (!success) |
| 1051 | { |
| 1052 | messages::internalError(asyncResp->res); |
| 1053 | return; |
| 1054 | } |
| 1055 | parseLDAPConfigData(asyncResp->res.jsonValue, confData, serverType); |
| 1056 | if (confData.serviceEnabled) |
| 1057 | { |
| 1058 | // Disable the service first and update the rest of |
| 1059 | // the properties. |
| 1060 | handleServiceEnablePatch(false, asyncResp, serverType, |
Ratan Gupta | eb2bbe5 | 2019-04-22 14:27:01 +0530 | [diff] [blame] | 1061 | dbusObjectPath); |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1062 | } |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1063 | |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1064 | if (serviceAddressList) |
| 1065 | { |
| 1066 | handleServiceAddressPatch(*serviceAddressList, asyncResp, |
Ratan Gupta | eb2bbe5 | 2019-04-22 14:27:01 +0530 | [diff] [blame] | 1067 | serverType, dbusObjectPath); |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1068 | } |
| 1069 | if (userName) |
| 1070 | { |
| 1071 | handleUserNamePatch(*userName, asyncResp, serverType, |
Ratan Gupta | eb2bbe5 | 2019-04-22 14:27:01 +0530 | [diff] [blame] | 1072 | dbusObjectPath); |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1073 | } |
| 1074 | if (password) |
| 1075 | { |
| 1076 | handlePasswordPatch(*password, asyncResp, serverType, |
Ratan Gupta | eb2bbe5 | 2019-04-22 14:27:01 +0530 | [diff] [blame] | 1077 | dbusObjectPath); |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1078 | } |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1079 | |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1080 | if (baseDNList) |
| 1081 | { |
| 1082 | handleBaseDNPatch(*baseDNList, asyncResp, serverType, |
Ratan Gupta | eb2bbe5 | 2019-04-22 14:27:01 +0530 | [diff] [blame] | 1083 | dbusObjectPath); |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1084 | } |
| 1085 | if (userNameAttribute) |
| 1086 | { |
| 1087 | handleUserNameAttrPatch(*userNameAttribute, asyncResp, |
Ratan Gupta | eb2bbe5 | 2019-04-22 14:27:01 +0530 | [diff] [blame] | 1088 | serverType, dbusObjectPath); |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1089 | } |
| 1090 | if (groupsAttribute) |
| 1091 | { |
| 1092 | handleGroupNameAttrPatch(*groupsAttribute, asyncResp, |
Ratan Gupta | eb2bbe5 | 2019-04-22 14:27:01 +0530 | [diff] [blame] | 1093 | serverType, dbusObjectPath); |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1094 | } |
| 1095 | if (serviceEnabled) |
| 1096 | { |
| 1097 | // if user has given the value as true then enable |
| 1098 | // the service. if user has given false then no-op |
| 1099 | // as service is already stopped. |
| 1100 | if (*serviceEnabled) |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1101 | { |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1102 | handleServiceEnablePatch(*serviceEnabled, asyncResp, |
Ratan Gupta | eb2bbe5 | 2019-04-22 14:27:01 +0530 | [diff] [blame] | 1103 | serverType, dbusObjectPath); |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1104 | } |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1105 | } |
| 1106 | else |
| 1107 | { |
| 1108 | // if user has not given the service enabled value |
| 1109 | // then revert it to the same state as it was |
| 1110 | // before. |
| 1111 | handleServiceEnablePatch(confData.serviceEnabled, asyncResp, |
Ratan Gupta | eb2bbe5 | 2019-04-22 14:27:01 +0530 | [diff] [blame] | 1112 | serverType, dbusObjectPath); |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1113 | } |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 1114 | |
| 1115 | if (remoteRoleMapData) |
| 1116 | { |
| 1117 | std::vector<nlohmann::json> remoteRoleMap = |
| 1118 | std::move(*remoteRoleMapData); |
| 1119 | |
| 1120 | handleRoleMapPatch(asyncResp, confData.groupRoleList, |
| 1121 | serverType, remoteRoleMap); |
| 1122 | } |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1123 | }); |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1124 | } |
Ed Tanous | d4b5443 | 2019-07-17 22:51:55 +0000 | [diff] [blame] | 1125 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1126 | void doGet(crow::Response& res, const crow::Request& req, |
| 1127 | const std::vector<std::string>& params) override |
| 1128 | { |
Zbigniew Kurzynski | 7815863 | 2019-11-05 12:57:37 +0100 | [diff] [blame] | 1129 | const crow::persistent_data::AuthConfigMethods& authMethodsConfig = |
| 1130 | crow::persistent_data::SessionStore::getInstance() |
| 1131 | .getAuthMethodsConfig(); |
| 1132 | |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1133 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 1134 | res.jsonValue = { |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1135 | {"@odata.id", "/redfish/v1/AccountService"}, |
| 1136 | {"@odata.type", "#AccountService." |
Gunnar Mills | ba9dd4a | 2020-02-20 10:40:18 -0600 | [diff] [blame] | 1137 | "v1_5_0.AccountService"}, |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1138 | {"Id", "AccountService"}, |
| 1139 | {"Name", "Account Service"}, |
| 1140 | {"Description", "Account Service"}, |
| 1141 | {"ServiceEnabled", true}, |
AppaRao Puli | 343ff2e | 2019-03-24 00:42:13 +0530 | [diff] [blame] | 1142 | {"MaxPasswordLength", 20}, |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1143 | {"Accounts", |
| 1144 | {{"@odata.id", "/redfish/v1/AccountService/Accounts"}}}, |
Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 1145 | {"Roles", {{"@odata.id", "/redfish/v1/AccountService/Roles"}}}, |
Zbigniew Kurzynski | 7815863 | 2019-11-05 12:57:37 +0100 | [diff] [blame] | 1146 | {"Oem", |
| 1147 | {{"OpenBMC", |
| 1148 | {{"@odata.type", "#OemAccountService.v1_0_0.AccountService"}, |
| 1149 | {"AuthMethods", |
| 1150 | { |
| 1151 | {"BasicAuth", authMethodsConfig.basic}, |
| 1152 | {"SessionToken", authMethodsConfig.sessionToken}, |
| 1153 | {"XToken", authMethodsConfig.xtoken}, |
| 1154 | {"Cookie", authMethodsConfig.cookie}, |
Zbigniew Kurzynski | 501f1e5 | 2019-10-02 11:22:11 +0200 | [diff] [blame] | 1155 | {"TLS", authMethodsConfig.tls}, |
Zbigniew Kurzynski | 7815863 | 2019-11-05 12:57:37 +0100 | [diff] [blame] | 1156 | }}}}}}, |
Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 1157 | {"LDAP", |
| 1158 | {{"Certificates", |
| 1159 | {{"@odata.id", |
| 1160 | "/redfish/v1/AccountService/LDAP/Certificates"}}}}}}; |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1161 | crow::connections::systemBus->async_method_call( |
| 1162 | [asyncResp]( |
| 1163 | const boost::system::error_code ec, |
| 1164 | const std::vector<std::pair< |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 1165 | std::string, std::variant<uint32_t, uint16_t, uint8_t>>>& |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1166 | propertiesList) { |
| 1167 | if (ec) |
| 1168 | { |
| 1169 | messages::internalError(asyncResp->res); |
| 1170 | return; |
| 1171 | } |
| 1172 | BMCWEB_LOG_DEBUG << "Got " << propertiesList.size() |
| 1173 | << "properties for AccountService"; |
| 1174 | for (const std::pair<std::string, |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 1175 | std::variant<uint32_t, uint16_t, uint8_t>>& |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1176 | property : propertiesList) |
| 1177 | { |
| 1178 | if (property.first == "MinPasswordLength") |
| 1179 | { |
| 1180 | const uint8_t* value = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 1181 | std::get_if<uint8_t>(&property.second); |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1182 | if (value != nullptr) |
| 1183 | { |
| 1184 | asyncResp->res.jsonValue["MinPasswordLength"] = |
| 1185 | *value; |
| 1186 | } |
| 1187 | } |
| 1188 | if (property.first == "AccountUnlockTimeout") |
| 1189 | { |
| 1190 | const uint32_t* value = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 1191 | std::get_if<uint32_t>(&property.second); |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1192 | if (value != nullptr) |
| 1193 | { |
| 1194 | asyncResp->res.jsonValue["AccountLockoutDuration"] = |
| 1195 | *value; |
| 1196 | } |
| 1197 | } |
| 1198 | if (property.first == "MaxLoginAttemptBeforeLockout") |
| 1199 | { |
| 1200 | const uint16_t* value = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 1201 | std::get_if<uint16_t>(&property.second); |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1202 | if (value != nullptr) |
| 1203 | { |
| 1204 | asyncResp->res |
| 1205 | .jsonValue["AccountLockoutThreshold"] = *value; |
| 1206 | } |
| 1207 | } |
| 1208 | } |
| 1209 | }, |
| 1210 | "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", |
| 1211 | "org.freedesktop.DBus.Properties", "GetAll", |
| 1212 | "xyz.openbmc_project.User.AccountPolicy"); |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 1213 | |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 1214 | auto callback = [asyncResp](bool success, LDAPConfigData& confData, |
| 1215 | const std::string& ldapType) { |
| 1216 | parseLDAPConfigData(asyncResp->res.jsonValue, confData, ldapType); |
| 1217 | }; |
| 1218 | |
| 1219 | getLDAPConfigData("LDAP", callback); |
| 1220 | getLDAPConfigData("ActiveDirectory", callback); |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1221 | } |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 1222 | |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1223 | void doPatch(crow::Response& res, const crow::Request& req, |
| 1224 | const std::vector<std::string>& params) override |
| 1225 | { |
| 1226 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 1227 | |
| 1228 | std::optional<uint32_t> unlockTimeout; |
| 1229 | std::optional<uint16_t> lockoutThreshold; |
Ratan Gupta | 19fb6e7 | 2019-03-04 13:30:50 +0530 | [diff] [blame] | 1230 | std::optional<uint16_t> minPasswordLength; |
| 1231 | std::optional<uint16_t> maxPasswordLength; |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1232 | std::optional<nlohmann::json> ldapObject; |
Ratan Gupta | eb2bbe5 | 2019-04-22 14:27:01 +0530 | [diff] [blame] | 1233 | std::optional<nlohmann::json> activeDirectoryObject; |
Zbigniew Kurzynski | 7815863 | 2019-11-05 12:57:37 +0100 | [diff] [blame] | 1234 | std::optional<nlohmann::json> oemObject; |
Ratan Gupta | 19fb6e7 | 2019-03-04 13:30:50 +0530 | [diff] [blame] | 1235 | |
Zbigniew Kurzynski | 7815863 | 2019-11-05 12:57:37 +0100 | [diff] [blame] | 1236 | if (!json_util::readJson( |
| 1237 | req, res, "AccountLockoutDuration", unlockTimeout, |
| 1238 | "AccountLockoutThreshold", lockoutThreshold, |
| 1239 | "MaxPasswordLength", maxPasswordLength, "MinPasswordLength", |
| 1240 | minPasswordLength, "LDAP", ldapObject, "ActiveDirectory", |
| 1241 | activeDirectoryObject, "Oem", oemObject)) |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1242 | { |
| 1243 | return; |
| 1244 | } |
Ratan Gupta | 19fb6e7 | 2019-03-04 13:30:50 +0530 | [diff] [blame] | 1245 | |
| 1246 | if (minPasswordLength) |
| 1247 | { |
| 1248 | messages::propertyNotWritable(asyncResp->res, "MinPasswordLength"); |
| 1249 | } |
| 1250 | |
| 1251 | if (maxPasswordLength) |
| 1252 | { |
| 1253 | messages::propertyNotWritable(asyncResp->res, "MaxPasswordLength"); |
| 1254 | } |
| 1255 | |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1256 | if (ldapObject) |
| 1257 | { |
| 1258 | handleLDAPPatch(*ldapObject, asyncResp, req, params, "LDAP"); |
| 1259 | } |
| 1260 | |
Zbigniew Kurzynski | 7815863 | 2019-11-05 12:57:37 +0100 | [diff] [blame] | 1261 | if (std::optional<nlohmann::json> oemOpenBMCObject; |
| 1262 | oemObject && |
| 1263 | json_util::readJson(*oemObject, res, "OpenBMC", oemOpenBMCObject)) |
| 1264 | { |
| 1265 | if (std::optional<nlohmann::json> authMethodsObject; |
| 1266 | oemOpenBMCObject && |
| 1267 | json_util::readJson(*oemOpenBMCObject, res, "AuthMethods", |
| 1268 | authMethodsObject)) |
| 1269 | { |
| 1270 | if (authMethodsObject) |
| 1271 | { |
| 1272 | handleAuthMethodsPatch(*authMethodsObject, asyncResp); |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | |
Ratan Gupta | eb2bbe5 | 2019-04-22 14:27:01 +0530 | [diff] [blame] | 1277 | if (activeDirectoryObject) |
| 1278 | { |
| 1279 | handleLDAPPatch(*activeDirectoryObject, asyncResp, req, params, |
| 1280 | "ActiveDirectory"); |
| 1281 | } |
| 1282 | |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1283 | if (unlockTimeout) |
| 1284 | { |
| 1285 | crow::connections::systemBus->async_method_call( |
| 1286 | [asyncResp](const boost::system::error_code ec) { |
| 1287 | if (ec) |
| 1288 | { |
| 1289 | messages::internalError(asyncResp->res); |
| 1290 | return; |
| 1291 | } |
Ratan Gupta | add6133 | 2019-02-13 20:49:16 +0530 | [diff] [blame] | 1292 | messages::success(asyncResp->res); |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1293 | }, |
| 1294 | "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", |
| 1295 | "org.freedesktop.DBus.Properties", "Set", |
| 1296 | "xyz.openbmc_project.User.AccountPolicy", |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 1297 | "AccountUnlockTimeout", std::variant<uint32_t>(*unlockTimeout)); |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1298 | } |
| 1299 | if (lockoutThreshold) |
| 1300 | { |
| 1301 | crow::connections::systemBus->async_method_call( |
| 1302 | [asyncResp](const boost::system::error_code ec) { |
| 1303 | if (ec) |
| 1304 | { |
| 1305 | messages::internalError(asyncResp->res); |
| 1306 | return; |
| 1307 | } |
Ratan Gupta | add6133 | 2019-02-13 20:49:16 +0530 | [diff] [blame] | 1308 | messages::success(asyncResp->res); |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1309 | }, |
| 1310 | "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", |
| 1311 | "org.freedesktop.DBus.Properties", "Set", |
| 1312 | "xyz.openbmc_project.User.AccountPolicy", |
| 1313 | "MaxLoginAttemptBeforeLockout", |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 1314 | std::variant<uint16_t>(*lockoutThreshold)); |
AppaRao Puli | 3d958bb | 2018-12-25 12:45:54 +0530 | [diff] [blame] | 1315 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1316 | } |
Zbigniew Kurzynski | 7815863 | 2019-11-05 12:57:37 +0100 | [diff] [blame] | 1317 | |
| 1318 | CrowApp& app; |
Lewanczyk, Dawid | 88d16c9 | 2018-02-02 14:51:09 +0100 | [diff] [blame] | 1319 | }; |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 1320 | |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1321 | class AccountsCollection : public Node |
| 1322 | { |
| 1323 | public: |
| 1324 | AccountsCollection(CrowApp& app) : |
| 1325 | Node(app, "/redfish/v1/AccountService/Accounts/") |
| 1326 | { |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1327 | entityPrivileges = { |
Gunnar Mills | f365910 | 2020-01-29 16:23:28 -0600 | [diff] [blame] | 1328 | // According to the PrivilegeRegistry, GET should actually be |
| 1329 | // "Login". A "Login" only privilege would return an empty "Members" |
| 1330 | // list. Not going to worry about this since none of the defined |
| 1331 | // roles are just "Login". E.g. Readonly is {"Login", |
| 1332 | // "ConfigureSelf"}. In the rare event anyone defines a role that |
| 1333 | // has Login but not ConfigureSelf, implement this. |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1334 | {boost::beast::http::verb::get, |
Gunnar Mills | f365910 | 2020-01-29 16:23:28 -0600 | [diff] [blame] | 1335 | {{"ConfigureUsers"}, {"ConfigureSelf"}}}, |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1336 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 1337 | {boost::beast::http::verb::patch, {{"ConfigureUsers"}}}, |
| 1338 | {boost::beast::http::verb::put, {{"ConfigureUsers"}}}, |
| 1339 | {boost::beast::http::verb::delete_, {{"ConfigureUsers"}}}, |
| 1340 | {boost::beast::http::verb::post, {{"ConfigureUsers"}}}}; |
| 1341 | } |
| 1342 | |
| 1343 | private: |
| 1344 | void doGet(crow::Response& res, const crow::Request& req, |
| 1345 | const std::vector<std::string>& params) override |
| 1346 | { |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1347 | auto asyncResp = std::make_shared<AsyncResp>(res); |
Gunnar Mills | 9440096 | 2020-02-14 11:56:41 -0600 | [diff] [blame] | 1348 | res.jsonValue = {{"@odata.id", "/redfish/v1/AccountService/Accounts"}, |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1349 | {"@odata.type", "#ManagerAccountCollection." |
| 1350 | "ManagerAccountCollection"}, |
| 1351 | {"Name", "Accounts Collection"}, |
| 1352 | {"Description", "BMC User Accounts"}}; |
| 1353 | |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1354 | crow::connections::systemBus->async_method_call( |
Gunnar Mills | f365910 | 2020-01-29 16:23:28 -0600 | [diff] [blame] | 1355 | [asyncResp, &req, this](const boost::system::error_code ec, |
| 1356 | const ManagedObjectType& users) { |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1357 | if (ec) |
| 1358 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1359 | messages::internalError(asyncResp->res); |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1360 | return; |
| 1361 | } |
| 1362 | |
| 1363 | nlohmann::json& memberArray = |
| 1364 | asyncResp->res.jsonValue["Members"]; |
| 1365 | memberArray = nlohmann::json::array(); |
| 1366 | |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1367 | for (auto& user : users) |
| 1368 | { |
| 1369 | const std::string& path = |
| 1370 | static_cast<const std::string&>(user.first); |
| 1371 | std::size_t lastIndex = path.rfind("/"); |
| 1372 | if (lastIndex == std::string::npos) |
| 1373 | { |
| 1374 | lastIndex = 0; |
| 1375 | } |
| 1376 | else |
| 1377 | { |
| 1378 | lastIndex += 1; |
| 1379 | } |
Gunnar Mills | f365910 | 2020-01-29 16:23:28 -0600 | [diff] [blame] | 1380 | |
| 1381 | // As clarified by Redfish here: |
| 1382 | // https://redfishforum.com/thread/281/manageraccountcollection-change-allows-account-enumeration |
| 1383 | // Users without ConfigureUsers, only see their own account. |
| 1384 | // Users with ConfigureUsers, see all accounts. |
| 1385 | if (req.session->username == path.substr(lastIndex) || |
| 1386 | isAllowedWithoutConfigureSelf(req)) |
| 1387 | { |
| 1388 | memberArray.push_back( |
| 1389 | {{"@odata.id", |
| 1390 | "/redfish/v1/AccountService/Accounts/" + |
| 1391 | path.substr(lastIndex)}}); |
| 1392 | } |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1393 | } |
Gunnar Mills | f365910 | 2020-01-29 16:23:28 -0600 | [diff] [blame] | 1394 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 1395 | memberArray.size(); |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1396 | }, |
| 1397 | "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", |
| 1398 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
| 1399 | } |
Ed Tanous | 04ae99e | 2018-09-20 15:54:36 -0700 | [diff] [blame] | 1400 | void doPost(crow::Response& res, const crow::Request& req, |
| 1401 | const std::vector<std::string>& params) override |
| 1402 | { |
| 1403 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 1404 | |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1405 | std::string username; |
| 1406 | std::string password; |
Ed Tanous | a24526d | 2018-12-10 15:17:59 -0800 | [diff] [blame] | 1407 | std::optional<std::string> roleId("User"); |
| 1408 | std::optional<bool> enabled = true; |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1409 | if (!json_util::readJson(req, res, "UserName", username, "Password", |
| 1410 | password, "RoleId", roleId, "Enabled", |
| 1411 | enabled)) |
Ed Tanous | 04ae99e | 2018-09-20 15:54:36 -0700 | [diff] [blame] | 1412 | { |
| 1413 | return; |
| 1414 | } |
| 1415 | |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 1416 | std::string priv = getPrivilegeFromRoleId(*roleId); |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1417 | if (priv.empty()) |
Ed Tanous | 04ae99e | 2018-09-20 15:54:36 -0700 | [diff] [blame] | 1418 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1419 | messages::propertyValueNotInList(asyncResp->res, *roleId, "RoleId"); |
Ed Tanous | 04ae99e | 2018-09-20 15:54:36 -0700 | [diff] [blame] | 1420 | return; |
| 1421 | } |
jayaprakash Mutyala | 9620060 | 2020-04-08 11:09:10 +0000 | [diff] [blame] | 1422 | // TODO: Following override will be reverted once support in |
| 1423 | // phosphor-user-manager is added. In order to avoid dependency issues, |
| 1424 | // this is added in bmcweb, which will removed, once |
| 1425 | // phosphor-user-manager supports priv-noaccess. |
| 1426 | if (priv == "priv-noaccess") |
| 1427 | { |
| 1428 | roleId = ""; |
| 1429 | } |
| 1430 | else |
| 1431 | { |
| 1432 | roleId = priv; |
| 1433 | } |
Ed Tanous | 04ae99e | 2018-09-20 15:54:36 -0700 | [diff] [blame] | 1434 | |
Ayushi Smriti | 599c71d | 2019-08-23 17:43:18 +0000 | [diff] [blame] | 1435 | // Reading AllGroups property |
Ed Tanous | 04ae99e | 2018-09-20 15:54:36 -0700 | [diff] [blame] | 1436 | crow::connections::systemBus->async_method_call( |
Ayushi Smriti | 599c71d | 2019-08-23 17:43:18 +0000 | [diff] [blame] | 1437 | [asyncResp, username, password{std::move(password)}, roleId, |
| 1438 | enabled](const boost::system::error_code ec, |
| 1439 | const std::variant<std::vector<std::string>>& allGroups) { |
Ed Tanous | 04ae99e | 2018-09-20 15:54:36 -0700 | [diff] [blame] | 1440 | if (ec) |
| 1441 | { |
Ayushi Smriti | 599c71d | 2019-08-23 17:43:18 +0000 | [diff] [blame] | 1442 | BMCWEB_LOG_DEBUG << "ERROR with async_method_call"; |
| 1443 | messages::internalError(asyncResp->res); |
Ed Tanous | 04ae99e | 2018-09-20 15:54:36 -0700 | [diff] [blame] | 1444 | return; |
| 1445 | } |
| 1446 | |
Ayushi Smriti | 599c71d | 2019-08-23 17:43:18 +0000 | [diff] [blame] | 1447 | const std::vector<std::string>* allGroupsList = |
| 1448 | std::get_if<std::vector<std::string>>(&allGroups); |
| 1449 | |
| 1450 | if (allGroupsList == nullptr || allGroupsList->empty()) |
Ed Tanous | 04ae99e | 2018-09-20 15:54:36 -0700 | [diff] [blame] | 1451 | { |
Ayushi Smriti | 599c71d | 2019-08-23 17:43:18 +0000 | [diff] [blame] | 1452 | messages::internalError(asyncResp->res); |
Ed Tanous | 04ae99e | 2018-09-20 15:54:36 -0700 | [diff] [blame] | 1453 | return; |
| 1454 | } |
| 1455 | |
Ayushi Smriti | 599c71d | 2019-08-23 17:43:18 +0000 | [diff] [blame] | 1456 | crow::connections::systemBus->async_method_call( |
| 1457 | [asyncResp, username, password{std::move(password)}]( |
anil kumar appana | 0d4197e | 2019-06-13 15:06:23 +0000 | [diff] [blame] | 1458 | const boost::system::error_code ec, |
| 1459 | sdbusplus::message::message& m) { |
Ayushi Smriti | 599c71d | 2019-08-23 17:43:18 +0000 | [diff] [blame] | 1460 | if (ec) |
| 1461 | { |
anil kumar appana | 0d4197e | 2019-06-13 15:06:23 +0000 | [diff] [blame] | 1462 | userErrorMessageHandler(m.get_error(), asyncResp, |
| 1463 | username, ""); |
Ayushi Smriti | 599c71d | 2019-08-23 17:43:18 +0000 | [diff] [blame] | 1464 | return; |
| 1465 | } |
| 1466 | |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 1467 | if (pamUpdatePassword(username, password) != |
| 1468 | PAM_SUCCESS) |
Ayushi Smriti | 599c71d | 2019-08-23 17:43:18 +0000 | [diff] [blame] | 1469 | { |
| 1470 | // At this point we have a user that's been created, |
| 1471 | // but the password set failed.Something is wrong, |
| 1472 | // so delete the user that we've already created |
| 1473 | crow::connections::systemBus->async_method_call( |
anil kumar appana | 0d4197e | 2019-06-13 15:06:23 +0000 | [diff] [blame] | 1474 | [asyncResp, |
| 1475 | password](const boost::system::error_code ec) { |
Ayushi Smriti | 599c71d | 2019-08-23 17:43:18 +0000 | [diff] [blame] | 1476 | if (ec) |
| 1477 | { |
| 1478 | messages::internalError(asyncResp->res); |
| 1479 | return; |
| 1480 | } |
| 1481 | |
anil kumar appana | 0d4197e | 2019-06-13 15:06:23 +0000 | [diff] [blame] | 1482 | // If password is invalid |
| 1483 | messages::propertyValueFormatError( |
| 1484 | asyncResp->res, password, "Password"); |
Ayushi Smriti | 599c71d | 2019-08-23 17:43:18 +0000 | [diff] [blame] | 1485 | }, |
| 1486 | "xyz.openbmc_project.User.Manager", |
| 1487 | "/xyz/openbmc_project/user/" + username, |
| 1488 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 1489 | |
| 1490 | BMCWEB_LOG_ERROR << "pamUpdatePassword Failed"; |
| 1491 | return; |
| 1492 | } |
| 1493 | |
| 1494 | messages::created(asyncResp->res); |
| 1495 | asyncResp->res.addHeader( |
| 1496 | "Location", |
| 1497 | "/redfish/v1/AccountService/Accounts/" + username); |
| 1498 | }, |
| 1499 | "xyz.openbmc_project.User.Manager", |
| 1500 | "/xyz/openbmc_project/user", |
| 1501 | "xyz.openbmc_project.User.Manager", "CreateUser", username, |
| 1502 | *allGroupsList, *roleId, *enabled); |
Ed Tanous | 04ae99e | 2018-09-20 15:54:36 -0700 | [diff] [blame] | 1503 | }, |
| 1504 | "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", |
Ayushi Smriti | 599c71d | 2019-08-23 17:43:18 +0000 | [diff] [blame] | 1505 | "org.freedesktop.DBus.Properties", "Get", |
| 1506 | "xyz.openbmc_project.User.Manager", "AllGroups"); |
Ed Tanous | 04ae99e | 2018-09-20 15:54:36 -0700 | [diff] [blame] | 1507 | } |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1508 | }; |
| 1509 | |
| 1510 | class ManagerAccount : public Node |
| 1511 | { |
| 1512 | public: |
| 1513 | ManagerAccount(CrowApp& app) : |
| 1514 | Node(app, "/redfish/v1/AccountService/Accounts/<str>/", std::string()) |
| 1515 | { |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1516 | entityPrivileges = { |
| 1517 | {boost::beast::http::verb::get, |
| 1518 | {{"ConfigureUsers"}, {"ConfigureManager"}, {"ConfigureSelf"}}}, |
| 1519 | {boost::beast::http::verb::head, {{"Login"}}}, |
Joseph Reynolds | 900f949 | 2019-11-25 15:37:29 -0600 | [diff] [blame] | 1520 | {boost::beast::http::verb::patch, |
| 1521 | {{"ConfigureUsers"}, {"ConfigureSelf"}}}, |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1522 | {boost::beast::http::verb::put, {{"ConfigureUsers"}}}, |
| 1523 | {boost::beast::http::verb::delete_, {{"ConfigureUsers"}}}, |
| 1524 | {boost::beast::http::verb::post, {{"ConfigureUsers"}}}}; |
| 1525 | } |
| 1526 | |
| 1527 | private: |
| 1528 | void doGet(crow::Response& res, const crow::Request& req, |
| 1529 | const std::vector<std::string>& params) override |
| 1530 | { |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1531 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 1532 | |
| 1533 | if (params.size() != 1) |
| 1534 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1535 | messages::internalError(asyncResp->res); |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1536 | return; |
| 1537 | } |
| 1538 | |
Joseph Reynolds | 900f949 | 2019-11-25 15:37:29 -0600 | [diff] [blame] | 1539 | // Perform a proper ConfigureSelf authority check. If the |
| 1540 | // user is operating on an account not their own, then their |
| 1541 | // ConfigureSelf privilege does not apply. In this case, |
| 1542 | // perform the authority check again without the user's |
| 1543 | // ConfigureSelf privilege. |
| 1544 | if (req.session->username != params[0]) |
| 1545 | { |
| 1546 | if (!isAllowedWithoutConfigureSelf(req)) |
| 1547 | { |
| 1548 | BMCWEB_LOG_DEBUG << "GET Account denied access"; |
| 1549 | messages::insufficientPrivilege(asyncResp->res); |
| 1550 | return; |
| 1551 | } |
| 1552 | } |
| 1553 | |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1554 | crow::connections::systemBus->async_method_call( |
| 1555 | [asyncResp, accountName{std::string(params[0])}]( |
| 1556 | const boost::system::error_code ec, |
| 1557 | const ManagedObjectType& users) { |
| 1558 | if (ec) |
| 1559 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1560 | messages::internalError(asyncResp->res); |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1561 | return; |
| 1562 | } |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1563 | auto userIt = users.begin(); |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1564 | |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1565 | for (; userIt != users.end(); userIt++) |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1566 | { |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1567 | if (boost::ends_with(userIt->first.str, "/" + accountName)) |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1568 | { |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1569 | break; |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1570 | } |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1571 | } |
| 1572 | if (userIt == users.end()) |
| 1573 | { |
| 1574 | messages::resourceNotFound(asyncResp->res, "ManagerAccount", |
| 1575 | accountName); |
| 1576 | return; |
| 1577 | } |
Ayushi Smriti | 4e68c45 | 2019-09-04 14:37:55 +0530 | [diff] [blame] | 1578 | |
| 1579 | asyncResp->res.jsonValue = { |
Gunnar Mills | 8114bd4 | 2020-06-11 20:55:21 -0500 | [diff] [blame] | 1580 | {"@odata.type", "#ManagerAccount.v1_4_0.ManagerAccount"}, |
Ayushi Smriti | 4e68c45 | 2019-09-04 14:37:55 +0530 | [diff] [blame] | 1581 | {"Name", "User Account"}, |
| 1582 | {"Description", "User Account"}, |
Gunnar Mills | 8114bd4 | 2020-06-11 20:55:21 -0500 | [diff] [blame] | 1583 | {"Password", nullptr}, |
| 1584 | {"AccountTypes", {"Redfish"}}}; |
Ayushi Smriti | 4e68c45 | 2019-09-04 14:37:55 +0530 | [diff] [blame] | 1585 | |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1586 | for (const auto& interface : userIt->second) |
| 1587 | { |
| 1588 | if (interface.first == |
| 1589 | "xyz.openbmc_project.User.Attributes") |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1590 | { |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1591 | for (const auto& property : interface.second) |
Ed Tanous | 65b0dc3 | 2018-09-19 16:04:03 -0700 | [diff] [blame] | 1592 | { |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1593 | if (property.first == "UserEnabled") |
Ed Tanous | 65b0dc3 | 2018-09-19 16:04:03 -0700 | [diff] [blame] | 1594 | { |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1595 | const bool* userEnabled = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 1596 | std::get_if<bool>(&property.second); |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1597 | if (userEnabled == nullptr) |
Ed Tanous | 65b0dc3 | 2018-09-19 16:04:03 -0700 | [diff] [blame] | 1598 | { |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1599 | BMCWEB_LOG_ERROR |
| 1600 | << "UserEnabled wasn't a bool"; |
| 1601 | messages::internalError(asyncResp->res); |
| 1602 | return; |
Ed Tanous | 65b0dc3 | 2018-09-19 16:04:03 -0700 | [diff] [blame] | 1603 | } |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1604 | asyncResp->res.jsonValue["Enabled"] = |
| 1605 | *userEnabled; |
| 1606 | } |
| 1607 | else if (property.first == |
| 1608 | "UserLockedForFailedAttempt") |
| 1609 | { |
| 1610 | const bool* userLocked = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 1611 | std::get_if<bool>(&property.second); |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1612 | if (userLocked == nullptr) |
| 1613 | { |
| 1614 | BMCWEB_LOG_ERROR << "UserLockedForF" |
| 1615 | "ailedAttempt " |
| 1616 | "wasn't a bool"; |
| 1617 | messages::internalError(asyncResp->res); |
| 1618 | return; |
| 1619 | } |
| 1620 | asyncResp->res.jsonValue["Locked"] = |
| 1621 | *userLocked; |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1622 | asyncResp->res.jsonValue |
| 1623 | ["Locked@Redfish.AllowableValues"] = { |
Joseph Reynolds | 3bf4e63 | 2020-02-06 14:44:32 -0600 | [diff] [blame] | 1624 | "false"}; // can only unlock accounts |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1625 | } |
| 1626 | else if (property.first == "UserPrivilege") |
| 1627 | { |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 1628 | const std::string* userPrivPtr = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 1629 | std::get_if<std::string>(&property.second); |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 1630 | if (userPrivPtr == nullptr) |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1631 | { |
| 1632 | BMCWEB_LOG_ERROR |
| 1633 | << "UserPrivilege wasn't a " |
| 1634 | "string"; |
| 1635 | messages::internalError(asyncResp->res); |
| 1636 | return; |
| 1637 | } |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 1638 | std::string role = |
| 1639 | getRoleIdFromPrivilege(*userPrivPtr); |
| 1640 | if (role.empty()) |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1641 | { |
| 1642 | BMCWEB_LOG_ERROR << "Invalid user role"; |
| 1643 | messages::internalError(asyncResp->res); |
| 1644 | return; |
| 1645 | } |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 1646 | asyncResp->res.jsonValue["RoleId"] = role; |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1647 | |
| 1648 | asyncResp->res.jsonValue["Links"]["Role"] = { |
| 1649 | {"@odata.id", "/redfish/v1/AccountService/" |
| 1650 | "Roles/" + |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 1651 | role}}; |
Ed Tanous | 65b0dc3 | 2018-09-19 16:04:03 -0700 | [diff] [blame] | 1652 | } |
Joseph Reynolds | 3bf4e63 | 2020-02-06 14:44:32 -0600 | [diff] [blame] | 1653 | else if (property.first == "UserPasswordExpired") |
| 1654 | { |
| 1655 | const bool* userPasswordExpired = |
| 1656 | std::get_if<bool>(&property.second); |
| 1657 | if (userPasswordExpired == nullptr) |
| 1658 | { |
| 1659 | BMCWEB_LOG_ERROR << "UserPassword" |
| 1660 | "Expired " |
| 1661 | "wasn't a bool"; |
| 1662 | messages::internalError(asyncResp->res); |
| 1663 | return; |
| 1664 | } |
| 1665 | asyncResp->res |
| 1666 | .jsonValue["PasswordChangeRequired"] = |
| 1667 | *userPasswordExpired; |
| 1668 | } |
Ed Tanous | 65b0dc3 | 2018-09-19 16:04:03 -0700 | [diff] [blame] | 1669 | } |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1670 | } |
| 1671 | } |
| 1672 | |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1673 | asyncResp->res.jsonValue["@odata.id"] = |
| 1674 | "/redfish/v1/AccountService/Accounts/" + accountName; |
| 1675 | asyncResp->res.jsonValue["Id"] = accountName; |
| 1676 | asyncResp->res.jsonValue["UserName"] = accountName; |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1677 | }, |
| 1678 | "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", |
| 1679 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
| 1680 | } |
Ed Tanous | a840879 | 2018-09-05 16:08:38 -0700 | [diff] [blame] | 1681 | |
| 1682 | void doPatch(crow::Response& res, const crow::Request& req, |
| 1683 | const std::vector<std::string>& params) override |
| 1684 | { |
| 1685 | auto asyncResp = std::make_shared<AsyncResp>(res); |
Ed Tanous | a840879 | 2018-09-05 16:08:38 -0700 | [diff] [blame] | 1686 | if (params.size() != 1) |
| 1687 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1688 | messages::internalError(asyncResp->res); |
Ed Tanous | a840879 | 2018-09-05 16:08:38 -0700 | [diff] [blame] | 1689 | return; |
| 1690 | } |
| 1691 | |
Ed Tanous | a24526d | 2018-12-10 15:17:59 -0800 | [diff] [blame] | 1692 | std::optional<std::string> newUserName; |
| 1693 | std::optional<std::string> password; |
| 1694 | std::optional<bool> enabled; |
| 1695 | std::optional<std::string> roleId; |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1696 | std::optional<bool> locked; |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1697 | if (!json_util::readJson(req, res, "UserName", newUserName, "Password", |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1698 | password, "RoleId", roleId, "Enabled", enabled, |
| 1699 | "Locked", locked)) |
Ed Tanous | a840879 | 2018-09-05 16:08:38 -0700 | [diff] [blame] | 1700 | { |
| 1701 | return; |
| 1702 | } |
| 1703 | |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1704 | const std::string& username = params[0]; |
Ed Tanous | a840879 | 2018-09-05 16:08:38 -0700 | [diff] [blame] | 1705 | |
Joseph Reynolds | 900f949 | 2019-11-25 15:37:29 -0600 | [diff] [blame] | 1706 | // Perform a proper ConfigureSelf authority check. If the |
| 1707 | // session is being used to PATCH a property other than |
| 1708 | // Password, then the ConfigureSelf privilege does not apply. |
| 1709 | // If the user is operating on an account not their own, then |
| 1710 | // their ConfigureSelf privilege does not apply. In either |
| 1711 | // case, perform the authority check again without the user's |
| 1712 | // ConfigureSelf privilege. |
| 1713 | if ((username != req.session->username) || |
| 1714 | (newUserName || enabled || roleId || locked)) |
| 1715 | { |
| 1716 | if (!isAllowedWithoutConfigureSelf(req)) |
| 1717 | { |
| 1718 | BMCWEB_LOG_WARNING << "PATCH Password denied access"; |
| 1719 | asyncResp->res.clear(); |
| 1720 | messages::insufficientPrivilege(asyncResp->res); |
| 1721 | return; |
| 1722 | } |
| 1723 | } |
| 1724 | |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 1725 | // if user name is not provided in the patch method or if it |
| 1726 | // matches the user name in the URI, then we are treating it as updating |
| 1727 | // user properties other then username. If username provided doesn't |
| 1728 | // match the URI, then we are treating this as user rename request. |
| 1729 | if (!newUserName || (newUserName.value() == username)) |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1730 | { |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1731 | updateUserProperties(asyncResp, username, password, enabled, roleId, |
| 1732 | locked); |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1733 | return; |
| 1734 | } |
| 1735 | else |
| 1736 | { |
| 1737 | crow::connections::systemBus->async_method_call( |
| 1738 | [this, asyncResp, username, password(std::move(password)), |
| 1739 | roleId(std::move(roleId)), enabled(std::move(enabled)), |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 1740 | newUser{std::string(*newUserName)}, |
| 1741 | locked(std::move(locked))](const boost::system::error_code ec, |
| 1742 | sdbusplus::message::message& m) { |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1743 | if (ec) |
Ed Tanous | a840879 | 2018-09-05 16:08:38 -0700 | [diff] [blame] | 1744 | { |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 1745 | userErrorMessageHandler(m.get_error(), asyncResp, |
| 1746 | newUser, username); |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1747 | return; |
| 1748 | } |
| 1749 | |
| 1750 | updateUserProperties(asyncResp, newUser, password, enabled, |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1751 | roleId, locked); |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1752 | }, |
| 1753 | "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", |
| 1754 | "xyz.openbmc_project.User.Manager", "RenameUser", username, |
| 1755 | *newUserName); |
| 1756 | } |
| 1757 | } |
| 1758 | |
| 1759 | void updateUserProperties(std::shared_ptr<AsyncResp> asyncResp, |
| 1760 | const std::string& username, |
Ed Tanous | a24526d | 2018-12-10 15:17:59 -0800 | [diff] [blame] | 1761 | std::optional<std::string> password, |
| 1762 | std::optional<bool> enabled, |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1763 | std::optional<std::string> roleId, |
| 1764 | std::optional<bool> locked) |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1765 | { |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1766 | std::string dbusObjectPath = "/xyz/openbmc_project/user/" + username; |
| 1767 | dbus::utility::escapePathForDbus(dbusObjectPath); |
| 1768 | |
Ratan Gupta | 22c3371 | 2019-05-03 21:50:28 +0530 | [diff] [blame] | 1769 | dbus::utility::checkDbusPathExists( |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1770 | dbusObjectPath, |
| 1771 | [dbusObjectPath(std::move(dbusObjectPath)), username, |
| 1772 | password(std::move(password)), roleId(std::move(roleId)), |
| 1773 | enabled(std::move(enabled)), locked(std::move(locked)), |
| 1774 | asyncResp{std::move(asyncResp)}](int rc) { |
| 1775 | if (!rc) |
| 1776 | { |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 1777 | messages::resourceNotFound( |
Gunnar Mills | 8114bd4 | 2020-06-11 20:55:21 -0500 | [diff] [blame] | 1778 | asyncResp->res, "#ManagerAccount.v1_4_0.ManagerAccount", |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 1779 | username); |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1780 | return; |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1781 | } |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 1782 | |
| 1783 | if (password) |
| 1784 | { |
| 1785 | int retval = pamUpdatePassword(username, *password); |
| 1786 | |
| 1787 | if (retval == PAM_USER_UNKNOWN) |
| 1788 | { |
| 1789 | messages::resourceNotFound( |
| 1790 | asyncResp->res, |
Gunnar Mills | 8114bd4 | 2020-06-11 20:55:21 -0500 | [diff] [blame] | 1791 | "#ManagerAccount.v1_4_0.ManagerAccount", username); |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 1792 | } |
| 1793 | else if (retval == PAM_AUTHTOK_ERR) |
| 1794 | { |
| 1795 | // If password is invalid |
| 1796 | messages::propertyValueFormatError( |
| 1797 | asyncResp->res, *password, "Password"); |
| 1798 | BMCWEB_LOG_ERROR << "pamUpdatePassword Failed"; |
| 1799 | } |
| 1800 | else if (retval != PAM_SUCCESS) |
| 1801 | { |
| 1802 | messages::internalError(asyncResp->res); |
| 1803 | return; |
| 1804 | } |
| 1805 | } |
| 1806 | |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1807 | if (enabled) |
| 1808 | { |
| 1809 | crow::connections::systemBus->async_method_call( |
| 1810 | [asyncResp](const boost::system::error_code ec) { |
| 1811 | if (ec) |
| 1812 | { |
| 1813 | BMCWEB_LOG_ERROR << "D-Bus responses error: " |
| 1814 | << ec; |
| 1815 | messages::internalError(asyncResp->res); |
| 1816 | return; |
| 1817 | } |
| 1818 | messages::success(asyncResp->res); |
| 1819 | return; |
| 1820 | }, |
| 1821 | "xyz.openbmc_project.User.Manager", |
| 1822 | dbusObjectPath.c_str(), |
| 1823 | "org.freedesktop.DBus.Properties", "Set", |
| 1824 | "xyz.openbmc_project.User.Attributes", "UserEnabled", |
| 1825 | std::variant<bool>{*enabled}); |
| 1826 | } |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1827 | |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1828 | if (roleId) |
| 1829 | { |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 1830 | std::string priv = getPrivilegeFromRoleId(*roleId); |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1831 | if (priv.empty()) |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1832 | { |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1833 | messages::propertyValueNotInList(asyncResp->res, |
| 1834 | *roleId, "RoleId"); |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1835 | return; |
| 1836 | } |
jayaprakash Mutyala | 9620060 | 2020-04-08 11:09:10 +0000 | [diff] [blame] | 1837 | if (priv == "priv-noaccess") |
| 1838 | { |
| 1839 | priv = ""; |
| 1840 | } |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1841 | |
| 1842 | crow::connections::systemBus->async_method_call( |
| 1843 | [asyncResp](const boost::system::error_code ec) { |
| 1844 | if (ec) |
| 1845 | { |
| 1846 | BMCWEB_LOG_ERROR << "D-Bus responses error: " |
| 1847 | << ec; |
| 1848 | messages::internalError(asyncResp->res); |
| 1849 | return; |
| 1850 | } |
| 1851 | messages::success(asyncResp->res); |
| 1852 | }, |
| 1853 | "xyz.openbmc_project.User.Manager", |
| 1854 | dbusObjectPath.c_str(), |
| 1855 | "org.freedesktop.DBus.Properties", "Set", |
| 1856 | "xyz.openbmc_project.User.Attributes", "UserPrivilege", |
| 1857 | std::variant<std::string>{priv}); |
| 1858 | } |
| 1859 | |
| 1860 | if (locked) |
| 1861 | { |
| 1862 | // admin can unlock the account which is locked by |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 1863 | // successive authentication failures but admin should |
| 1864 | // not be allowed to lock an account. |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1865 | if (*locked) |
| 1866 | { |
| 1867 | messages::propertyValueNotInList(asyncResp->res, "true", |
| 1868 | "Locked"); |
| 1869 | return; |
| 1870 | } |
| 1871 | |
| 1872 | crow::connections::systemBus->async_method_call( |
| 1873 | [asyncResp](const boost::system::error_code ec) { |
| 1874 | if (ec) |
| 1875 | { |
| 1876 | BMCWEB_LOG_ERROR << "D-Bus responses error: " |
| 1877 | << ec; |
| 1878 | messages::internalError(asyncResp->res); |
| 1879 | return; |
| 1880 | } |
| 1881 | messages::success(asyncResp->res); |
| 1882 | return; |
| 1883 | }, |
| 1884 | "xyz.openbmc_project.User.Manager", |
| 1885 | dbusObjectPath.c_str(), |
| 1886 | "org.freedesktop.DBus.Properties", "Set", |
| 1887 | "xyz.openbmc_project.User.Attributes", |
| 1888 | "UserLockedForFailedAttempt", |
Patrick Williams | 19bd78d | 2020-05-13 17:38:24 -0500 | [diff] [blame] | 1889 | std::variant<bool>{*locked}); |
Ratan Gupta | 24c8542 | 2019-01-30 19:41:24 +0530 | [diff] [blame] | 1890 | } |
| 1891 | }); |
Ed Tanous | a840879 | 2018-09-05 16:08:38 -0700 | [diff] [blame] | 1892 | } |
Ed Tanous | 06e086d | 2018-09-19 17:19:52 -0700 | [diff] [blame] | 1893 | |
| 1894 | void doDelete(crow::Response& res, const crow::Request& req, |
| 1895 | const std::vector<std::string>& params) override |
| 1896 | { |
| 1897 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 1898 | |
| 1899 | if (params.size() != 1) |
| 1900 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1901 | messages::internalError(asyncResp->res); |
Ed Tanous | 06e086d | 2018-09-19 17:19:52 -0700 | [diff] [blame] | 1902 | return; |
| 1903 | } |
| 1904 | |
| 1905 | const std::string userPath = "/xyz/openbmc_project/user/" + params[0]; |
| 1906 | |
| 1907 | crow::connections::systemBus->async_method_call( |
| 1908 | [asyncResp, username{std::move(params[0])}]( |
| 1909 | const boost::system::error_code ec) { |
| 1910 | if (ec) |
| 1911 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1912 | messages::resourceNotFound( |
Gunnar Mills | 8114bd4 | 2020-06-11 20:55:21 -0500 | [diff] [blame] | 1913 | asyncResp->res, "#ManagerAccount.v1_4_0.ManagerAccount", |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1914 | username); |
Ed Tanous | 06e086d | 2018-09-19 17:19:52 -0700 | [diff] [blame] | 1915 | return; |
| 1916 | } |
| 1917 | |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1918 | messages::accountRemoved(asyncResp->res); |
Ed Tanous | 06e086d | 2018-09-19 17:19:52 -0700 | [diff] [blame] | 1919 | }, |
| 1920 | "xyz.openbmc_project.User.Manager", userPath, |
| 1921 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 1922 | } |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 1923 | }; |
Lewanczyk, Dawid | 88d16c9 | 2018-02-02 14:51:09 +0100 | [diff] [blame] | 1924 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1925 | } // namespace redfish |