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 17 18 #include "app.hpp" 19 #include "dbus_utility.hpp" 20 #include "error_messages.hpp" 21 #include "generated/enums/account_service.hpp" 22 #include "openbmc_dbus_rest.hpp" 23 #include "persistent_data.hpp" 24 #include "query.hpp" 25 #include "registries/privilege_registry.hpp" 26 #include "utils/dbus_utils.hpp" 27 #include "utils/json_utils.hpp" 28 29 #include <sdbusplus/asio/property.hpp> 30 #include <sdbusplus/unpack_properties.hpp> 31 32 #include <array> 33 #include <optional> 34 #include <ranges> 35 #include <string> 36 #include <string_view> 37 #include <vector> 38 39 namespace redfish 40 { 41 42 constexpr const char* ldapConfigObjectName = 43 "/xyz/openbmc_project/user/ldap/openldap"; 44 constexpr const char* adConfigObject = 45 "/xyz/openbmc_project/user/ldap/active_directory"; 46 47 constexpr const char* rootUserDbusPath = "/xyz/openbmc_project/user/"; 48 constexpr const char* ldapRootObject = "/xyz/openbmc_project/user/ldap"; 49 constexpr const char* ldapDbusService = "xyz.openbmc_project.Ldap.Config"; 50 constexpr const char* ldapConfigInterface = 51 "xyz.openbmc_project.User.Ldap.Config"; 52 constexpr const char* ldapCreateInterface = 53 "xyz.openbmc_project.User.Ldap.Create"; 54 constexpr const char* ldapEnableInterface = "xyz.openbmc_project.Object.Enable"; 55 constexpr const char* ldapPrivMapperInterface = 56 "xyz.openbmc_project.User.PrivilegeMapper"; 57 58 struct LDAPRoleMapData 59 { 60 std::string groupName; 61 std::string privilege; 62 }; 63 64 struct LDAPConfigData 65 { 66 std::string uri; 67 std::string bindDN; 68 std::string baseDN; 69 std::string searchScope; 70 std::string serverType; 71 bool serviceEnabled = false; 72 std::string userNameAttribute; 73 std::string groupAttribute; 74 std::vector<std::pair<std::string, LDAPRoleMapData>> groupRoleList; 75 }; 76 77 inline std::string getRoleIdFromPrivilege(std::string_view role) 78 { 79 if (role == "priv-admin") 80 { 81 return "Administrator"; 82 } 83 if (role == "priv-user") 84 { 85 return "ReadOnly"; 86 } 87 if (role == "priv-operator") 88 { 89 return "Operator"; 90 } 91 return ""; 92 } 93 inline std::string getPrivilegeFromRoleId(std::string_view role) 94 { 95 if (role == "Administrator") 96 { 97 return "priv-admin"; 98 } 99 if (role == "ReadOnly") 100 { 101 return "priv-user"; 102 } 103 if (role == "Operator") 104 { 105 return "priv-operator"; 106 } 107 return ""; 108 } 109 110 /** 111 * @brief Maps user group names retrieved from D-Bus object to 112 * Account Types. 113 * 114 * @param[in] userGroups List of User groups 115 * @param[out] res AccountTypes populated 116 * 117 * @return true in case of success, false if UserGroups contains 118 * invalid group name(s). 119 */ 120 inline bool translateUserGroup(const std::vector<std::string>& userGroups, 121 crow::Response& res) 122 { 123 std::vector<std::string> accountTypes; 124 for (const auto& userGroup : userGroups) 125 { 126 if (userGroup == "redfish") 127 { 128 accountTypes.emplace_back("Redfish"); 129 accountTypes.emplace_back("WebUI"); 130 } 131 else if (userGroup == "ipmi") 132 { 133 accountTypes.emplace_back("IPMI"); 134 } 135 else if (userGroup == "ssh") 136 { 137 accountTypes.emplace_back("ManagerConsole"); 138 } 139 else if (userGroup == "hostconsole") 140 { 141 // The hostconsole group controls who can access the host console 142 // port via ssh and websocket. 143 accountTypes.emplace_back("HostConsole"); 144 } 145 else if (userGroup == "web") 146 { 147 // 'web' is one of the valid groups in the UserGroups property of 148 // the user account in the D-Bus object. This group is currently not 149 // doing anything, and is considered to be equivalent to 'redfish'. 150 // 'redfish' user group is mapped to 'Redfish'and 'WebUI' 151 // AccountTypes, so do nothing here... 152 } 153 else 154 { 155 // Invalid user group name. Caller throws an exception. 156 return false; 157 } 158 } 159 160 res.jsonValue["AccountTypes"] = std::move(accountTypes); 161 return true; 162 } 163 164 /** 165 * @brief Builds User Groups from the Account Types 166 * 167 * @param[in] asyncResp Async Response 168 * @param[in] accountTypes List of Account Types 169 * @param[out] userGroups List of User Groups mapped from Account Types 170 * 171 * @return true if Account Types mapped to User Groups, false otherwise. 172 */ 173 inline bool 174 getUserGroupFromAccountType(crow::Response& res, 175 const std::vector<std::string>& accountTypes, 176 std::vector<std::string>& userGroups) 177 { 178 // Need both Redfish and WebUI Account Types to map to 'redfish' User Group 179 bool redfishType = false; 180 bool webUIType = false; 181 182 for (const auto& accountType : accountTypes) 183 { 184 if (accountType == "Redfish") 185 { 186 redfishType = true; 187 } 188 else if (accountType == "WebUI") 189 { 190 webUIType = true; 191 } 192 else if (accountType == "IPMI") 193 { 194 userGroups.emplace_back("ipmi"); 195 } 196 else if (accountType == "HostConsole") 197 { 198 userGroups.emplace_back("hostconsole"); 199 } 200 else if (accountType == "ManagerConsole") 201 { 202 userGroups.emplace_back("ssh"); 203 } 204 else 205 { 206 // Invalid Account Type 207 messages::propertyValueNotInList(res, "AccountTypes", accountType); 208 return false; 209 } 210 } 211 212 // Both Redfish and WebUI Account Types are needed to PATCH 213 if (redfishType ^ webUIType) 214 { 215 BMCWEB_LOG_ERROR( 216 "Missing Redfish or WebUI Account Type to set redfish User Group"); 217 messages::strictAccountTypes(res, "AccountTypes"); 218 return false; 219 } 220 221 if (redfishType && webUIType) 222 { 223 userGroups.emplace_back("redfish"); 224 } 225 226 return true; 227 } 228 229 /** 230 * @brief Sets UserGroups property of the user based on the Account Types 231 * 232 * @param[in] accountTypes List of User Account Types 233 * @param[in] asyncResp Async Response 234 * @param[in] dbusObjectPath D-Bus Object Path 235 * @param[in] userSelf true if User is updating OWN Account Types 236 */ 237 inline void 238 patchAccountTypes(const std::vector<std::string>& accountTypes, 239 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 240 const std::string& dbusObjectPath, bool userSelf) 241 { 242 // Check if User is disabling own Redfish Account Type 243 if (userSelf && 244 (accountTypes.cend() == 245 std::find(accountTypes.cbegin(), accountTypes.cend(), "Redfish"))) 246 { 247 BMCWEB_LOG_ERROR( 248 "User disabling OWN Redfish Account Type is not allowed"); 249 messages::strictAccountTypes(asyncResp->res, "AccountTypes"); 250 return; 251 } 252 253 std::vector<std::string> updatedUserGroups; 254 if (!getUserGroupFromAccountType(asyncResp->res, accountTypes, 255 updatedUserGroups)) 256 { 257 // Problem in mapping Account Types to User Groups, Error already 258 // logged. 259 return; 260 } 261 setDbusProperty(asyncResp, "xyz.openbmc_project.User.Manager", 262 dbusObjectPath, "xyz.openbmc_project.User.Attributes", 263 "UserGroups", "AccountTypes", updatedUserGroups); 264 } 265 266 inline void userErrorMessageHandler( 267 const sd_bus_error* e, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 268 const std::string& newUser, const std::string& username) 269 { 270 if (e == nullptr) 271 { 272 messages::internalError(asyncResp->res); 273 return; 274 } 275 276 const char* errorMessage = e->name; 277 if (strcmp(errorMessage, 278 "xyz.openbmc_project.User.Common.Error.UserNameExists") == 0) 279 { 280 messages::resourceAlreadyExists(asyncResp->res, "ManagerAccount", 281 "UserName", newUser); 282 } 283 else if (strcmp(errorMessage, "xyz.openbmc_project.User.Common.Error." 284 "UserNameDoesNotExist") == 0) 285 { 286 messages::resourceNotFound(asyncResp->res, "ManagerAccount", username); 287 } 288 else if ((strcmp(errorMessage, 289 "xyz.openbmc_project.Common.Error.InvalidArgument") == 290 0) || 291 (strcmp( 292 errorMessage, 293 "xyz.openbmc_project.User.Common.Error.UserNameGroupFail") == 294 0)) 295 { 296 messages::propertyValueFormatError(asyncResp->res, newUser, "UserName"); 297 } 298 else if (strcmp(errorMessage, 299 "xyz.openbmc_project.User.Common.Error.NoResource") == 0) 300 { 301 messages::createLimitReachedForResource(asyncResp->res); 302 } 303 else 304 { 305 BMCWEB_LOG_ERROR("DBUS response error {}", errorMessage); 306 messages::internalError(asyncResp->res); 307 } 308 } 309 310 inline void parseLDAPConfigData(nlohmann::json& jsonResponse, 311 const LDAPConfigData& confData, 312 const std::string& ldapType) 313 { 314 nlohmann::json::object_t ldap; 315 ldap["ServiceEnabled"] = confData.serviceEnabled; 316 nlohmann::json::array_t serviceAddresses; 317 serviceAddresses.emplace_back(confData.uri); 318 ldap["ServiceAddresses"] = std::move(serviceAddresses); 319 320 nlohmann::json::object_t authentication; 321 authentication["AuthenticationType"] = 322 account_service::AuthenticationTypes::UsernameAndPassword; 323 authentication["Username"] = confData.bindDN; 324 authentication["Password"] = nullptr; 325 ldap["Authentication"] = std::move(authentication); 326 327 nlohmann::json::object_t ldapService; 328 nlohmann::json::object_t searchSettings; 329 nlohmann::json::array_t baseDistinguishedNames; 330 baseDistinguishedNames.emplace_back(confData.baseDN); 331 332 searchSettings["BaseDistinguishedNames"] = 333 std::move(baseDistinguishedNames); 334 searchSettings["UsernameAttribute"] = confData.userNameAttribute; 335 searchSettings["GroupsAttribute"] = confData.groupAttribute; 336 ldapService["SearchSettings"] = std::move(searchSettings); 337 ldap["LDAPService"] = std::move(ldapService); 338 339 nlohmann::json::array_t roleMapArray; 340 for (const auto& obj : confData.groupRoleList) 341 { 342 BMCWEB_LOG_DEBUG("Pushing the data groupName={}", obj.second.groupName); 343 344 nlohmann::json::object_t remoteGroup; 345 remoteGroup["RemoteGroup"] = obj.second.groupName; 346 remoteGroup["LocalRole"] = getRoleIdFromPrivilege(obj.second.privilege); 347 roleMapArray.emplace_back(std::move(remoteGroup)); 348 } 349 350 ldap["RemoteRoleMapping"] = std::move(roleMapArray); 351 352 jsonResponse[ldapType].update(ldap); 353 } 354 355 /** 356 * @brief validates given JSON input and then calls appropriate method to 357 * create, to delete or to set Rolemapping object based on the given input. 358 * 359 */ 360 inline void handleRoleMapPatch( 361 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 362 const std::vector<std::pair<std::string, LDAPRoleMapData>>& roleMapObjData, 363 const std::string& serverType, 364 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input) 365 { 366 for (size_t index = 0; index < input.size(); index++) 367 { 368 std::variant<nlohmann::json::object_t, std::nullptr_t>& thisJson = 369 input[index]; 370 nlohmann::json::object_t* obj = 371 std::get_if<nlohmann::json::object_t>(&thisJson); 372 if (obj == nullptr) 373 { 374 // delete the existing object 375 if (index < roleMapObjData.size()) 376 { 377 crow::connections::systemBus->async_method_call( 378 [asyncResp, roleMapObjData, serverType, 379 index](const boost::system::error_code& ec) { 380 if (ec) 381 { 382 BMCWEB_LOG_ERROR("DBUS response error: {}", ec); 383 messages::internalError(asyncResp->res); 384 return; 385 } 386 asyncResp->res.jsonValue[serverType]["RemoteRoleMapping"] 387 [index] = nullptr; 388 }, 389 ldapDbusService, roleMapObjData[index].first, 390 "xyz.openbmc_project.Object.Delete", "Delete"); 391 } 392 else 393 { 394 BMCWEB_LOG_ERROR("Can't delete the object"); 395 messages::propertyValueTypeError(asyncResp->res, "null", 396 "RemoteRoleMapping/" + 397 std::to_string(index)); 398 return; 399 } 400 } 401 else if (obj->empty()) 402 { 403 // Don't do anything for the empty objects,parse next json 404 // eg {"RemoteRoleMapping",[{}]} 405 } 406 else 407 { 408 // update/create the object 409 std::optional<std::string> remoteGroup; 410 std::optional<std::string> localRole; 411 412 if (!json_util::readJsonObject(*obj, asyncResp->res, "RemoteGroup", 413 remoteGroup, "LocalRole", localRole)) 414 { 415 continue; 416 } 417 418 // Update existing RoleMapping Object 419 if (index < roleMapObjData.size()) 420 { 421 BMCWEB_LOG_DEBUG("Update Role Map Object"); 422 // If "RemoteGroup" info is provided 423 if (remoteGroup) 424 { 425 setDbusProperty( 426 asyncResp, ldapDbusService, roleMapObjData[index].first, 427 "xyz.openbmc_project.User.PrivilegeMapperEntry", 428 "GroupName", 429 std::format("RemoteRoleMapping/{}/RemoteGroup", index), 430 *remoteGroup); 431 } 432 433 // If "LocalRole" info is provided 434 if (localRole) 435 { 436 setDbusProperty( 437 asyncResp, ldapDbusService, roleMapObjData[index].first, 438 "xyz.openbmc_project.User.PrivilegeMapperEntry", 439 "Privilege", 440 std::format("RemoteRoleMapping/{}/LocalRole", index), 441 *localRole); 442 } 443 } 444 // Create a new RoleMapping Object. 445 else 446 { 447 BMCWEB_LOG_DEBUG( 448 "setRoleMappingProperties: Creating new Object"); 449 std::string pathString = "RemoteRoleMapping/" + 450 std::to_string(index); 451 452 if (!localRole) 453 { 454 messages::propertyMissing(asyncResp->res, 455 pathString + "/LocalRole"); 456 continue; 457 } 458 if (!remoteGroup) 459 { 460 messages::propertyMissing(asyncResp->res, 461 pathString + "/RemoteGroup"); 462 continue; 463 } 464 465 std::string dbusObjectPath; 466 if (serverType == "ActiveDirectory") 467 { 468 dbusObjectPath = adConfigObject; 469 } 470 else if (serverType == "LDAP") 471 { 472 dbusObjectPath = ldapConfigObjectName; 473 } 474 475 BMCWEB_LOG_DEBUG("Remote Group={},LocalRole={}", *remoteGroup, 476 *localRole); 477 478 crow::connections::systemBus->async_method_call( 479 [asyncResp, serverType, localRole, 480 remoteGroup](const boost::system::error_code& ec) { 481 if (ec) 482 { 483 BMCWEB_LOG_ERROR("DBUS response error: {}", ec); 484 messages::internalError(asyncResp->res); 485 return; 486 } 487 nlohmann::json& remoteRoleJson = 488 asyncResp->res 489 .jsonValue[serverType]["RemoteRoleMapping"]; 490 nlohmann::json::object_t roleMapEntry; 491 roleMapEntry["LocalRole"] = *localRole; 492 roleMapEntry["RemoteGroup"] = *remoteGroup; 493 remoteRoleJson.emplace_back(std::move(roleMapEntry)); 494 }, 495 ldapDbusService, dbusObjectPath, ldapPrivMapperInterface, 496 "Create", *remoteGroup, 497 getPrivilegeFromRoleId(std::move(*localRole))); 498 } 499 } 500 } 501 } 502 503 /** 504 * Function that retrieves all properties for LDAP config object 505 * into JSON 506 */ 507 template <typename CallbackFunc> 508 inline void getLDAPConfigData(const std::string& ldapType, 509 CallbackFunc&& callback) 510 { 511 constexpr std::array<std::string_view, 2> interfaces = { 512 ldapEnableInterface, ldapConfigInterface}; 513 514 dbus::utility::getDbusObject( 515 ldapConfigObjectName, interfaces, 516 [callback = std::forward<CallbackFunc>(callback), 517 ldapType](const boost::system::error_code& ec, 518 const dbus::utility::MapperGetObject& resp) mutable { 519 if (ec || resp.empty()) 520 { 521 BMCWEB_LOG_WARNING( 522 "DBUS response error during getting of service name: {}", ec); 523 LDAPConfigData empty{}; 524 callback(false, empty, ldapType); 525 return; 526 } 527 std::string service = resp.begin()->first; 528 sdbusplus::message::object_path path(ldapRootObject); 529 dbus::utility::getManagedObjects( 530 service, path, 531 [callback, ldapType]( 532 const boost::system::error_code& ec2, 533 const dbus::utility::ManagedObjectType& ldapObjects) mutable { 534 LDAPConfigData confData{}; 535 if (ec2) 536 { 537 callback(false, confData, ldapType); 538 BMCWEB_LOG_WARNING("D-Bus responses error: {}", ec2); 539 return; 540 } 541 542 std::string ldapDbusType; 543 std::string searchString; 544 545 if (ldapType == "LDAP") 546 { 547 ldapDbusType = 548 "xyz.openbmc_project.User.Ldap.Config.Type.OpenLdap"; 549 searchString = "openldap"; 550 } 551 else if (ldapType == "ActiveDirectory") 552 { 553 ldapDbusType = 554 "xyz.openbmc_project.User.Ldap.Config.Type.ActiveDirectory"; 555 searchString = "active_directory"; 556 } 557 else 558 { 559 BMCWEB_LOG_ERROR("Can't get the DbusType for the given type={}", 560 ldapType); 561 callback(false, confData, ldapType); 562 return; 563 } 564 565 std::string ldapEnableInterfaceStr = ldapEnableInterface; 566 std::string ldapConfigInterfaceStr = ldapConfigInterface; 567 568 for (const auto& object : ldapObjects) 569 { 570 // let's find the object whose ldap type is equal to the 571 // given type 572 if (object.first.str.find(searchString) == std::string::npos) 573 { 574 continue; 575 } 576 577 for (const auto& interface : object.second) 578 { 579 if (interface.first == ldapEnableInterfaceStr) 580 { 581 // rest of the properties are string. 582 for (const auto& property : interface.second) 583 { 584 if (property.first == "Enabled") 585 { 586 const bool* value = 587 std::get_if<bool>(&property.second); 588 if (value == nullptr) 589 { 590 continue; 591 } 592 confData.serviceEnabled = *value; 593 break; 594 } 595 } 596 } 597 else if (interface.first == ldapConfigInterfaceStr) 598 { 599 for (const auto& property : interface.second) 600 { 601 const std::string* strValue = 602 std::get_if<std::string>(&property.second); 603 if (strValue == nullptr) 604 { 605 continue; 606 } 607 if (property.first == "LDAPServerURI") 608 { 609 confData.uri = *strValue; 610 } 611 else if (property.first == "LDAPBindDN") 612 { 613 confData.bindDN = *strValue; 614 } 615 else if (property.first == "LDAPBaseDN") 616 { 617 confData.baseDN = *strValue; 618 } 619 else if (property.first == "LDAPSearchScope") 620 { 621 confData.searchScope = *strValue; 622 } 623 else if (property.first == "GroupNameAttribute") 624 { 625 confData.groupAttribute = *strValue; 626 } 627 else if (property.first == "UserNameAttribute") 628 { 629 confData.userNameAttribute = *strValue; 630 } 631 else if (property.first == "LDAPType") 632 { 633 confData.serverType = *strValue; 634 } 635 } 636 } 637 else if (interface.first == 638 "xyz.openbmc_project.User.PrivilegeMapperEntry") 639 { 640 LDAPRoleMapData roleMapData{}; 641 for (const auto& property : interface.second) 642 { 643 const std::string* strValue = 644 std::get_if<std::string>(&property.second); 645 646 if (strValue == nullptr) 647 { 648 continue; 649 } 650 651 if (property.first == "GroupName") 652 { 653 roleMapData.groupName = *strValue; 654 } 655 else if (property.first == "Privilege") 656 { 657 roleMapData.privilege = *strValue; 658 } 659 } 660 661 confData.groupRoleList.emplace_back(object.first.str, 662 roleMapData); 663 } 664 } 665 } 666 callback(true, confData, ldapType); 667 }); 668 }); 669 } 670 671 /** 672 * @brief updates the LDAP server address and updates the 673 json response with the new value. 674 * @param serviceAddressList address to be updated. 675 * @param asyncResp pointer to the JSON response 676 * @param ldapServerElementName Type of LDAP 677 server(openLDAP/ActiveDirectory) 678 */ 679 680 inline void handleServiceAddressPatch( 681 const std::vector<std::string>& serviceAddressList, 682 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 683 const std::string& ldapServerElementName, 684 const std::string& ldapConfigObject) 685 { 686 setDbusProperty(asyncResp, ldapDbusService, ldapConfigObject, 687 ldapConfigInterface, "LDAPServerURI", 688 ldapServerElementName + "/ServiceAddress", 689 serviceAddressList.front()); 690 } 691 /** 692 * @brief updates the LDAP Bind DN and updates the 693 json response with the new value. 694 * @param username name of the user which needs to be updated. 695 * @param asyncResp pointer to the JSON response 696 * @param ldapServerElementName Type of LDAP 697 server(openLDAP/ActiveDirectory) 698 */ 699 700 inline void 701 handleUserNamePatch(const std::string& username, 702 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 703 const std::string& ldapServerElementName, 704 const std::string& ldapConfigObject) 705 { 706 setDbusProperty(asyncResp, ldapDbusService, ldapConfigObject, 707 ldapConfigInterface, "LDAPBindDN", 708 ldapServerElementName + "/Authentication/Username", 709 username); 710 } 711 712 /** 713 * @brief updates the LDAP password 714 * @param password : ldap password which needs to be updated. 715 * @param asyncResp pointer to the JSON response 716 * @param ldapServerElementName Type of LDAP 717 * server(openLDAP/ActiveDirectory) 718 */ 719 720 inline void 721 handlePasswordPatch(const std::string& password, 722 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 723 const std::string& ldapServerElementName, 724 const std::string& ldapConfigObject) 725 { 726 setDbusProperty(asyncResp, ldapDbusService, ldapConfigObject, 727 ldapConfigInterface, "LDAPBindDNPassword", 728 ldapServerElementName + "/Authentication/Password", 729 password); 730 } 731 732 /** 733 * @brief updates the LDAP BaseDN and updates the 734 json response with the new value. 735 * @param baseDNList baseDN list which needs to be updated. 736 * @param asyncResp pointer to the JSON response 737 * @param ldapServerElementName Type of LDAP 738 server(openLDAP/ActiveDirectory) 739 */ 740 741 inline void 742 handleBaseDNPatch(const std::vector<std::string>& baseDNList, 743 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 744 const std::string& ldapServerElementName, 745 const std::string& ldapConfigObject) 746 { 747 setDbusProperty(asyncResp, ldapDbusService, ldapConfigObject, 748 ldapConfigInterface, "LDAPBaseDN", 749 ldapServerElementName + 750 "/LDAPService/SearchSettings/BaseDistinguishedNames", 751 baseDNList.front()); 752 } 753 /** 754 * @brief updates the LDAP user name attribute and updates the 755 json response with the new value. 756 * @param userNameAttribute attribute to be updated. 757 * @param asyncResp pointer to the JSON response 758 * @param ldapServerElementName Type of LDAP 759 server(openLDAP/ActiveDirectory) 760 */ 761 762 inline void 763 handleUserNameAttrPatch(const std::string& userNameAttribute, 764 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 765 const std::string& ldapServerElementName, 766 const std::string& ldapConfigObject) 767 { 768 setDbusProperty(asyncResp, ldapDbusService, ldapConfigObject, 769 ldapConfigInterface, "UserNameAttribute", 770 ldapServerElementName + 771 "LDAPService/SearchSettings/UsernameAttribute", 772 userNameAttribute); 773 } 774 /** 775 * @brief updates the LDAP group attribute and updates the 776 json response with the new value. 777 * @param groupsAttribute attribute to be updated. 778 * @param asyncResp pointer to the JSON response 779 * @param ldapServerElementName Type of LDAP 780 server(openLDAP/ActiveDirectory) 781 */ 782 783 inline void handleGroupNameAttrPatch( 784 const std::string& groupsAttribute, 785 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 786 const std::string& ldapServerElementName, 787 const std::string& ldapConfigObject) 788 { 789 setDbusProperty(asyncResp, ldapDbusService, ldapConfigObject, 790 ldapConfigInterface, "GroupNameAttribute", 791 ldapServerElementName + 792 "/LDAPService/SearchSettings/GroupsAttribute", 793 groupsAttribute); 794 } 795 /** 796 * @brief updates the LDAP service enable and updates the 797 json response with the new value. 798 * @param input JSON data. 799 * @param asyncResp pointer to the JSON response 800 * @param ldapServerElementName Type of LDAP 801 server(openLDAP/ActiveDirectory) 802 */ 803 804 inline void handleServiceEnablePatch( 805 bool serviceEnabled, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 806 const std::string& ldapServerElementName, 807 const std::string& ldapConfigObject) 808 { 809 setDbusProperty(asyncResp, ldapDbusService, ldapConfigObject, 810 ldapEnableInterface, "Enabled", 811 ldapServerElementName + "/ServiceEnabled", serviceEnabled); 812 } 813 814 struct AuthMethods 815 { 816 std::optional<bool> basicAuth; 817 std::optional<bool> cookie; 818 std::optional<bool> sessionToken; 819 std::optional<bool> xToken; 820 std::optional<bool> tls; 821 }; 822 823 inline void 824 handleAuthMethodsPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 825 const AuthMethods& auth) 826 { 827 persistent_data::AuthConfigMethods& authMethodsConfig = 828 persistent_data::SessionStore::getInstance().getAuthMethodsConfig(); 829 830 if (auth.basicAuth) 831 { 832 #ifndef BMCWEB_ENABLE_BASIC_AUTHENTICATION 833 messages::actionNotSupported( 834 asyncResp->res, 835 "Setting BasicAuth when basic-auth feature is disabled"); 836 return; 837 #endif 838 authMethodsConfig.basic = *auth.basicAuth; 839 } 840 841 if (auth.cookie) 842 { 843 #ifndef BMCWEB_ENABLE_COOKIE_AUTHENTICATION 844 messages::actionNotSupported( 845 asyncResp->res, 846 "Setting Cookie when cookie-auth feature is disabled"); 847 return; 848 #endif 849 authMethodsConfig.cookie = *auth.cookie; 850 } 851 852 if (auth.sessionToken) 853 { 854 #ifndef BMCWEB_ENABLE_SESSION_AUTHENTICATION 855 messages::actionNotSupported( 856 asyncResp->res, 857 "Setting SessionToken when session-auth feature is disabled"); 858 return; 859 #endif 860 authMethodsConfig.sessionToken = *auth.sessionToken; 861 } 862 863 if (auth.xToken) 864 { 865 #ifndef BMCWEB_ENABLE_XTOKEN_AUTHENTICATION 866 messages::actionNotSupported( 867 asyncResp->res, 868 "Setting XToken when xtoken-auth feature is disabled"); 869 return; 870 #endif 871 authMethodsConfig.xtoken = *auth.xToken; 872 } 873 874 if (auth.tls) 875 { 876 #ifndef BMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION 877 messages::actionNotSupported( 878 asyncResp->res, 879 "Setting TLS when mutual-tls-auth feature is disabled"); 880 return; 881 #endif 882 authMethodsConfig.tls = *auth.tls; 883 } 884 885 if (!authMethodsConfig.basic && !authMethodsConfig.cookie && 886 !authMethodsConfig.sessionToken && !authMethodsConfig.xtoken && 887 !authMethodsConfig.tls) 888 { 889 // Do not allow user to disable everything 890 messages::actionNotSupported(asyncResp->res, 891 "of disabling all available methods"); 892 return; 893 } 894 895 persistent_data::SessionStore::getInstance().updateAuthMethodsConfig( 896 authMethodsConfig); 897 // Save configuration immediately 898 persistent_data::getConfig().writeData(); 899 900 messages::success(asyncResp->res); 901 } 902 903 /** 904 * @brief Get the required values from the given JSON, validates the 905 * value and create the LDAP config object. 906 * @param input JSON data 907 * @param asyncResp pointer to the JSON response 908 * @param serverType Type of LDAP server(openLDAP/ActiveDirectory) 909 */ 910 911 struct LdapPatchParams 912 { 913 std::optional<std::string> authType; 914 std::optional<std::vector<std::string>> serviceAddressList; 915 std::optional<bool> serviceEnabled; 916 std::optional<std::vector<std::string>> baseDNList; 917 std::optional<std::string> userNameAttribute; 918 std::optional<std::string> groupsAttribute; 919 std::optional<std::string> userName; 920 std::optional<std::string> password; 921 std::optional< 922 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>> 923 remoteRoleMapData; 924 }; 925 926 inline void handleLDAPPatch(LdapPatchParams&& input, 927 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 928 const std::string& serverType) 929 { 930 std::string dbusObjectPath; 931 if (serverType == "ActiveDirectory") 932 { 933 dbusObjectPath = adConfigObject; 934 } 935 else if (serverType == "LDAP") 936 { 937 dbusObjectPath = ldapConfigObjectName; 938 } 939 else 940 { 941 BMCWEB_LOG_ERROR("serverType wasn't AD or LDAP but was {}????", 942 serverType); 943 return; 944 } 945 946 if (input.authType && *input.authType != "UsernameAndPassword") 947 { 948 messages::propertyValueNotInList(asyncResp->res, *input.authType, 949 "AuthenticationType"); 950 return; 951 } 952 953 if (input.serviceAddressList) 954 { 955 if (input.serviceAddressList->empty()) 956 { 957 messages::propertyValueNotInList( 958 asyncResp->res, *input.serviceAddressList, "ServiceAddress"); 959 return; 960 } 961 } 962 if (input.baseDNList) 963 { 964 if (input.baseDNList->empty()) 965 { 966 messages::propertyValueNotInList(asyncResp->res, *input.baseDNList, 967 "BaseDistinguishedNames"); 968 return; 969 } 970 } 971 972 // nothing to update, then return 973 if (!input.userName && !input.password && !input.serviceAddressList && 974 !input.baseDNList && !input.userNameAttribute && 975 !input.groupsAttribute && !input.serviceEnabled && 976 !input.remoteRoleMapData) 977 { 978 return; 979 } 980 981 // Get the existing resource first then keep modifying 982 // whenever any property gets updated. 983 getLDAPConfigData(serverType, 984 [asyncResp, input = std::move(input), 985 dbusObjectPath = std::move(dbusObjectPath)]( 986 bool success, const LDAPConfigData& confData, 987 const std::string& serverT) mutable { 988 if (!success) 989 { 990 messages::internalError(asyncResp->res); 991 return; 992 } 993 parseLDAPConfigData(asyncResp->res.jsonValue, confData, serverT); 994 if (confData.serviceEnabled) 995 { 996 // Disable the service first and update the rest of 997 // the properties. 998 handleServiceEnablePatch(false, asyncResp, serverT, dbusObjectPath); 999 } 1000 1001 if (input.serviceAddressList) 1002 { 1003 handleServiceAddressPatch(*input.serviceAddressList, asyncResp, 1004 serverT, dbusObjectPath); 1005 } 1006 if (input.userName) 1007 { 1008 handleUserNamePatch(*input.userName, asyncResp, serverT, 1009 dbusObjectPath); 1010 } 1011 if (input.password) 1012 { 1013 handlePasswordPatch(*input.password, asyncResp, serverT, 1014 dbusObjectPath); 1015 } 1016 1017 if (input.baseDNList) 1018 { 1019 handleBaseDNPatch(*input.baseDNList, asyncResp, serverT, 1020 dbusObjectPath); 1021 } 1022 if (input.userNameAttribute) 1023 { 1024 handleUserNameAttrPatch(*input.userNameAttribute, asyncResp, 1025 serverT, dbusObjectPath); 1026 } 1027 if (input.groupsAttribute) 1028 { 1029 handleGroupNameAttrPatch(*input.groupsAttribute, asyncResp, serverT, 1030 dbusObjectPath); 1031 } 1032 if (input.serviceEnabled) 1033 { 1034 // if user has given the value as true then enable 1035 // the service. if user has given false then no-op 1036 // as service is already stopped. 1037 if (*input.serviceEnabled) 1038 { 1039 handleServiceEnablePatch(*input.serviceEnabled, asyncResp, 1040 serverT, dbusObjectPath); 1041 } 1042 } 1043 else 1044 { 1045 // if user has not given the service enabled value 1046 // then revert it to the same state as it was 1047 // before. 1048 handleServiceEnablePatch(confData.serviceEnabled, asyncResp, 1049 serverT, dbusObjectPath); 1050 } 1051 1052 if (input.remoteRoleMapData) 1053 { 1054 handleRoleMapPatch(asyncResp, confData.groupRoleList, serverT, 1055 *input.remoteRoleMapData); 1056 } 1057 }); 1058 } 1059 1060 inline void updateUserProperties( 1061 std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& username, 1062 const std::optional<std::string>& password, 1063 const std::optional<bool>& enabled, 1064 const std::optional<std::string>& roleId, const std::optional<bool>& locked, 1065 std::optional<std::vector<std::string>> accountTypes, bool userSelf) 1066 { 1067 sdbusplus::message::object_path tempObjPath(rootUserDbusPath); 1068 tempObjPath /= username; 1069 std::string dbusObjectPath(tempObjPath); 1070 1071 dbus::utility::checkDbusPathExists( 1072 dbusObjectPath, [dbusObjectPath, username, password, roleId, enabled, 1073 locked, accountTypes(std::move(accountTypes)), 1074 userSelf, asyncResp{std::move(asyncResp)}](int rc) { 1075 if (rc <= 0) 1076 { 1077 messages::resourceNotFound(asyncResp->res, "ManagerAccount", 1078 username); 1079 return; 1080 } 1081 1082 if (password) 1083 { 1084 int retval = pamUpdatePassword(username, *password); 1085 1086 if (retval == PAM_USER_UNKNOWN) 1087 { 1088 messages::resourceNotFound(asyncResp->res, "ManagerAccount", 1089 username); 1090 } 1091 else if (retval == PAM_AUTHTOK_ERR) 1092 { 1093 // If password is invalid 1094 messages::propertyValueFormatError(asyncResp->res, nullptr, 1095 "Password"); 1096 BMCWEB_LOG_ERROR("pamUpdatePassword Failed"); 1097 } 1098 else if (retval != PAM_SUCCESS) 1099 { 1100 messages::internalError(asyncResp->res); 1101 return; 1102 } 1103 else 1104 { 1105 messages::success(asyncResp->res); 1106 } 1107 } 1108 1109 if (enabled) 1110 { 1111 setDbusProperty(asyncResp, "xyz.openbmc_project.User.Manager", 1112 dbusObjectPath, 1113 "xyz.openbmc_project.User.Attributes", 1114 "UserEnabled", "Enabled", *enabled); 1115 } 1116 1117 if (roleId) 1118 { 1119 std::string priv = getPrivilegeFromRoleId(*roleId); 1120 if (priv.empty()) 1121 { 1122 messages::propertyValueNotInList(asyncResp->res, true, 1123 "Locked"); 1124 return; 1125 } 1126 setDbusProperty(asyncResp, "xyz.openbmc_project.User.Manager", 1127 dbusObjectPath, 1128 "xyz.openbmc_project.User.Attributes", 1129 "UserPrivilege", "RoleId", priv); 1130 } 1131 1132 if (locked) 1133 { 1134 // admin can unlock the account which is locked by 1135 // successive authentication failures but admin should 1136 // not be allowed to lock an account. 1137 if (*locked) 1138 { 1139 messages::propertyValueNotInList(asyncResp->res, "true", 1140 "Locked"); 1141 return; 1142 } 1143 setDbusProperty(asyncResp, "xyz.openbmc_project.User.Manager", 1144 dbusObjectPath, 1145 "xyz.openbmc_project.User.Attributes", 1146 "UserLockedForFailedAttempt", "Locked", *locked); 1147 } 1148 1149 if (accountTypes) 1150 { 1151 patchAccountTypes(*accountTypes, asyncResp, dbusObjectPath, 1152 userSelf); 1153 } 1154 }); 1155 } 1156 1157 inline void handleAccountServiceHead( 1158 App& app, const crow::Request& req, 1159 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1160 { 1161 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1162 { 1163 return; 1164 } 1165 asyncResp->res.addHeader( 1166 boost::beast::http::field::link, 1167 "</redfish/v1/JsonSchemas/AccountService/AccountService.json>; rel=describedby"); 1168 } 1169 1170 inline void 1171 handleAccountServiceGet(App& app, const crow::Request& req, 1172 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1173 { 1174 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1175 { 1176 return; 1177 } 1178 1179 if (req.session == nullptr) 1180 { 1181 messages::internalError(asyncResp->res); 1182 return; 1183 } 1184 1185 const persistent_data::AuthConfigMethods& authMethodsConfig = 1186 persistent_data::SessionStore::getInstance().getAuthMethodsConfig(); 1187 1188 asyncResp->res.addHeader( 1189 boost::beast::http::field::link, 1190 "</redfish/v1/JsonSchemas/AccountService/AccountService.json>; rel=describedby"); 1191 1192 nlohmann::json& json = asyncResp->res.jsonValue; 1193 json["@odata.id"] = "/redfish/v1/AccountService"; 1194 json["@odata.type"] = "#AccountService." 1195 "v1_10_0.AccountService"; 1196 json["Id"] = "AccountService"; 1197 json["Name"] = "Account Service"; 1198 json["Description"] = "Account Service"; 1199 json["ServiceEnabled"] = true; 1200 json["MaxPasswordLength"] = 20; 1201 json["Accounts"]["@odata.id"] = "/redfish/v1/AccountService/Accounts"; 1202 json["Roles"]["@odata.id"] = "/redfish/v1/AccountService/Roles"; 1203 json["Oem"]["OpenBMC"]["@odata.type"] = 1204 "#OpenBMCAccountService.v1_0_0.AccountService"; 1205 json["Oem"]["OpenBMC"]["@odata.id"] = 1206 "/redfish/v1/AccountService#/Oem/OpenBMC"; 1207 json["Oem"]["OpenBMC"]["AuthMethods"]["BasicAuth"] = 1208 authMethodsConfig.basic; 1209 json["Oem"]["OpenBMC"]["AuthMethods"]["SessionToken"] = 1210 authMethodsConfig.sessionToken; 1211 json["Oem"]["OpenBMC"]["AuthMethods"]["XToken"] = authMethodsConfig.xtoken; 1212 json["Oem"]["OpenBMC"]["AuthMethods"]["Cookie"] = authMethodsConfig.cookie; 1213 json["Oem"]["OpenBMC"]["AuthMethods"]["TLS"] = authMethodsConfig.tls; 1214 1215 // /redfish/v1/AccountService/LDAP/Certificates is something only 1216 // ConfigureManager can access then only display when the user has 1217 // permissions ConfigureManager 1218 Privileges effectiveUserPrivileges = 1219 redfish::getUserPrivileges(*req.session); 1220 1221 if (isOperationAllowedWithPrivileges({{"ConfigureManager"}}, 1222 effectiveUserPrivileges)) 1223 { 1224 asyncResp->res.jsonValue["LDAP"]["Certificates"]["@odata.id"] = 1225 "/redfish/v1/AccountService/LDAP/Certificates"; 1226 } 1227 sdbusplus::asio::getAllProperties( 1228 *crow::connections::systemBus, "xyz.openbmc_project.User.Manager", 1229 "/xyz/openbmc_project/user", "xyz.openbmc_project.User.AccountPolicy", 1230 [asyncResp](const boost::system::error_code& ec, 1231 const dbus::utility::DBusPropertiesMap& propertiesList) { 1232 if (ec) 1233 { 1234 messages::internalError(asyncResp->res); 1235 return; 1236 } 1237 1238 BMCWEB_LOG_DEBUG("Got {}properties for AccountService", 1239 propertiesList.size()); 1240 1241 const uint8_t* minPasswordLength = nullptr; 1242 const uint32_t* accountUnlockTimeout = nullptr; 1243 const uint16_t* maxLoginAttemptBeforeLockout = nullptr; 1244 1245 const bool success = sdbusplus::unpackPropertiesNoThrow( 1246 dbus_utils::UnpackErrorPrinter(), propertiesList, 1247 "MinPasswordLength", minPasswordLength, "AccountUnlockTimeout", 1248 accountUnlockTimeout, "MaxLoginAttemptBeforeLockout", 1249 maxLoginAttemptBeforeLockout); 1250 1251 if (!success) 1252 { 1253 messages::internalError(asyncResp->res); 1254 return; 1255 } 1256 1257 if (minPasswordLength != nullptr) 1258 { 1259 asyncResp->res.jsonValue["MinPasswordLength"] = *minPasswordLength; 1260 } 1261 1262 if (accountUnlockTimeout != nullptr) 1263 { 1264 asyncResp->res.jsonValue["AccountLockoutDuration"] = 1265 *accountUnlockTimeout; 1266 } 1267 1268 if (maxLoginAttemptBeforeLockout != nullptr) 1269 { 1270 asyncResp->res.jsonValue["AccountLockoutThreshold"] = 1271 *maxLoginAttemptBeforeLockout; 1272 } 1273 }); 1274 1275 auto callback = [asyncResp](bool success, const LDAPConfigData& confData, 1276 const std::string& ldapType) { 1277 if (!success) 1278 { 1279 return; 1280 } 1281 parseLDAPConfigData(asyncResp->res.jsonValue, confData, ldapType); 1282 }; 1283 1284 getLDAPConfigData("LDAP", callback); 1285 getLDAPConfigData("ActiveDirectory", callback); 1286 } 1287 1288 inline void handleAccountServicePatch( 1289 App& app, const crow::Request& req, 1290 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1291 { 1292 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1293 { 1294 return; 1295 } 1296 std::optional<uint32_t> unlockTimeout; 1297 std::optional<uint16_t> lockoutThreshold; 1298 std::optional<uint8_t> minPasswordLength; 1299 std::optional<uint16_t> maxPasswordLength; 1300 LdapPatchParams ldapObject; 1301 LdapPatchParams activeDirectoryObject; 1302 AuthMethods auth; 1303 // clang-format off 1304 if (!json_util::readJsonPatch( 1305 req, asyncResp->res, 1306 "AccountLockoutDuration", unlockTimeout, 1307 "AccountLockoutThreshold", lockoutThreshold, 1308 "ActiveDirectory/Authentication/AuthenticationType", activeDirectoryObject.authType, 1309 "ActiveDirectory/Authentication/Password", activeDirectoryObject.password, 1310 "ActiveDirectory/Authentication/Username", activeDirectoryObject.userName, 1311 "ActiveDirectory/LDAPService/SearchSettings/BaseDistinguishedNames", activeDirectoryObject.baseDNList, 1312 "ActiveDirectory/LDAPService/SearchSettings/GroupsAttribute", activeDirectoryObject.groupsAttribute, 1313 "ActiveDirectory/LDAPService/SearchSettings/UsernameAttribute", activeDirectoryObject.userNameAttribute, 1314 "ActiveDirectory/RemoteRoleMapping", activeDirectoryObject.remoteRoleMapData, 1315 "ActiveDirectory/ServiceAddresses", activeDirectoryObject.serviceAddressList, 1316 "ActiveDirectory/ServiceEnabled", activeDirectoryObject.serviceEnabled, 1317 "LDAP/Authentication/AuthenticationType", ldapObject.authType, 1318 "LDAP/Authentication/Password", ldapObject.password, 1319 "LDAP/Authentication/Username", ldapObject.userName, 1320 "LDAP/LDAPService/SearchSettings/BaseDistinguishedNames", ldapObject.baseDNList, 1321 "LDAP/LDAPService/SearchSettings/GroupsAttribute", ldapObject.groupsAttribute, 1322 "LDAP/LDAPService/SearchSettings/UsernameAttribute", ldapObject.userNameAttribute, 1323 "LDAP/RemoteRoleMapping", ldapObject.remoteRoleMapData, 1324 "LDAP/ServiceAddresses", ldapObject.serviceAddressList, 1325 "LDAP/ServiceEnabled", ldapObject.serviceEnabled, 1326 "MaxPasswordLength", maxPasswordLength, 1327 "MinPasswordLength", minPasswordLength, 1328 "Oem/OpenBMC/AuthMethods/BasicAuth", auth.basicAuth, 1329 "Oem/OpenBMC/AuthMethods/Cookie", auth.cookie, 1330 "Oem/OpenBMC/AuthMethods/SessionToken", auth.sessionToken, 1331 "Oem/OpenBMC/AuthMethods/TLS", auth.tls, 1332 "Oem/OpenBMC/AuthMethods/XToken", auth.xToken)) 1333 { 1334 return; 1335 } 1336 // clang-format on 1337 1338 if (minPasswordLength) 1339 { 1340 setDbusProperty( 1341 asyncResp, "xyz.openbmc_project.User.Manager", 1342 sdbusplus::message::object_path("/xyz/openbmc_project/user"), 1343 "xyz.openbmc_project.User.AccountPolicy", "MinPasswordLength", 1344 "MinPasswordLength", *minPasswordLength); 1345 } 1346 1347 if (maxPasswordLength) 1348 { 1349 messages::propertyNotWritable(asyncResp->res, "MaxPasswordLength"); 1350 } 1351 1352 handleLDAPPatch(std::move(activeDirectoryObject), asyncResp, 1353 "ActiveDirectory"); 1354 handleLDAPPatch(std::move(ldapObject), asyncResp, "LDAP"); 1355 1356 handleAuthMethodsPatch(asyncResp, auth); 1357 1358 if (unlockTimeout) 1359 { 1360 setDbusProperty( 1361 asyncResp, "xyz.openbmc_project.User.Manager", 1362 sdbusplus::message::object_path("/xyz/openbmc_project/user"), 1363 "xyz.openbmc_project.User.AccountPolicy", "AccountUnlockTimeout", 1364 "AccountLockoutDuration", *unlockTimeout); 1365 } 1366 if (lockoutThreshold) 1367 { 1368 setDbusProperty( 1369 asyncResp, "xyz.openbmc_project.User.Manager", 1370 sdbusplus::message::object_path("/xyz/openbmc_project/user"), 1371 "xyz.openbmc_project.User.AccountPolicy", 1372 "MaxLoginAttemptBeforeLockout", "AccountLockoutThreshold", 1373 *lockoutThreshold); 1374 } 1375 } 1376 1377 inline void handleAccountCollectionHead( 1378 App& app, const crow::Request& req, 1379 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1380 { 1381 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1382 { 1383 return; 1384 } 1385 asyncResp->res.addHeader( 1386 boost::beast::http::field::link, 1387 "</redfish/v1/JsonSchemas/ManagerAccountCollection.json>; rel=describedby"); 1388 } 1389 1390 inline void handleAccountCollectionGet( 1391 App& app, const crow::Request& req, 1392 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1393 { 1394 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1395 { 1396 return; 1397 } 1398 1399 if (req.session == nullptr) 1400 { 1401 messages::internalError(asyncResp->res); 1402 return; 1403 } 1404 1405 asyncResp->res.addHeader( 1406 boost::beast::http::field::link, 1407 "</redfish/v1/JsonSchemas/ManagerAccountCollection.json>; rel=describedby"); 1408 1409 asyncResp->res.jsonValue["@odata.id"] = 1410 "/redfish/v1/AccountService/Accounts"; 1411 asyncResp->res.jsonValue["@odata.type"] = "#ManagerAccountCollection." 1412 "ManagerAccountCollection"; 1413 asyncResp->res.jsonValue["Name"] = "Accounts Collection"; 1414 asyncResp->res.jsonValue["Description"] = "BMC User Accounts"; 1415 1416 Privileges effectiveUserPrivileges = 1417 redfish::getUserPrivileges(*req.session); 1418 1419 std::string thisUser; 1420 if (req.session) 1421 { 1422 thisUser = req.session->username; 1423 } 1424 sdbusplus::message::object_path path("/xyz/openbmc_project/user"); 1425 dbus::utility::getManagedObjects( 1426 "xyz.openbmc_project.User.Manager", path, 1427 [asyncResp, thisUser, effectiveUserPrivileges]( 1428 const boost::system::error_code& ec, 1429 const dbus::utility::ManagedObjectType& users) { 1430 if (ec) 1431 { 1432 messages::internalError(asyncResp->res); 1433 return; 1434 } 1435 1436 bool userCanSeeAllAccounts = 1437 effectiveUserPrivileges.isSupersetOf({"ConfigureUsers"}); 1438 1439 bool userCanSeeSelf = 1440 effectiveUserPrivileges.isSupersetOf({"ConfigureSelf"}); 1441 1442 nlohmann::json& memberArray = asyncResp->res.jsonValue["Members"]; 1443 memberArray = nlohmann::json::array(); 1444 1445 for (const auto& userpath : users) 1446 { 1447 std::string user = userpath.first.filename(); 1448 if (user.empty()) 1449 { 1450 messages::internalError(asyncResp->res); 1451 BMCWEB_LOG_ERROR("Invalid firmware ID"); 1452 1453 return; 1454 } 1455 1456 // As clarified by Redfish here: 1457 // https://redfishforum.com/thread/281/manageraccountcollection-change-allows-account-enumeration 1458 // Users without ConfigureUsers, only see their own 1459 // account. Users with ConfigureUsers, see all 1460 // accounts. 1461 if (userCanSeeAllAccounts || (thisUser == user && userCanSeeSelf)) 1462 { 1463 nlohmann::json::object_t member; 1464 member["@odata.id"] = boost::urls::format( 1465 "/redfish/v1/AccountService/Accounts/{}", user); 1466 memberArray.emplace_back(std::move(member)); 1467 } 1468 } 1469 asyncResp->res.jsonValue["Members@odata.count"] = memberArray.size(); 1470 }); 1471 } 1472 1473 inline void processAfterCreateUser( 1474 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1475 const std::string& username, const std::string& password, 1476 const boost::system::error_code& ec, sdbusplus::message_t& m) 1477 { 1478 if (ec) 1479 { 1480 userErrorMessageHandler(m.get_error(), asyncResp, username, ""); 1481 return; 1482 } 1483 1484 if (pamUpdatePassword(username, password) != PAM_SUCCESS) 1485 { 1486 // At this point we have a user that's been 1487 // created, but the password set 1488 // failed.Something is wrong, so delete the user 1489 // that we've already created 1490 sdbusplus::message::object_path tempObjPath(rootUserDbusPath); 1491 tempObjPath /= username; 1492 const std::string userPath(tempObjPath); 1493 1494 crow::connections::systemBus->async_method_call( 1495 [asyncResp, password](const boost::system::error_code& ec3) { 1496 if (ec3) 1497 { 1498 messages::internalError(asyncResp->res); 1499 return; 1500 } 1501 1502 // If password is invalid 1503 messages::propertyValueFormatError(asyncResp->res, nullptr, 1504 "Password"); 1505 }, 1506 "xyz.openbmc_project.User.Manager", userPath, 1507 "xyz.openbmc_project.Object.Delete", "Delete"); 1508 1509 BMCWEB_LOG_ERROR("pamUpdatePassword Failed"); 1510 return; 1511 } 1512 1513 messages::created(asyncResp->res); 1514 asyncResp->res.addHeader("Location", 1515 "/redfish/v1/AccountService/Accounts/" + username); 1516 } 1517 1518 inline void processAfterGetAllGroups( 1519 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1520 const std::string& username, const std::string& password, 1521 const std::string& roleId, bool enabled, 1522 std::optional<std::vector<std::string>> accountTypes, 1523 const std::vector<std::string>& allGroupsList) 1524 { 1525 std::vector<std::string> userGroups; 1526 std::vector<std::string> accountTypeUserGroups; 1527 1528 // If user specified account types then convert them to unix user groups 1529 if (accountTypes) 1530 { 1531 if (!getUserGroupFromAccountType(asyncResp->res, *accountTypes, 1532 accountTypeUserGroups)) 1533 { 1534 // Problem in mapping Account Types to User Groups, Error already 1535 // logged. 1536 return; 1537 } 1538 } 1539 1540 for (const auto& grp : allGroupsList) 1541 { 1542 // If user specified the account type then only accept groups which are 1543 // in the account types group list. 1544 if (!accountTypeUserGroups.empty()) 1545 { 1546 bool found = false; 1547 for (const auto& grp1 : accountTypeUserGroups) 1548 { 1549 if (grp == grp1) 1550 { 1551 found = true; 1552 break; 1553 } 1554 } 1555 if (!found) 1556 { 1557 continue; 1558 } 1559 } 1560 1561 // Console access is provided to the user who is a member of 1562 // hostconsole group and has a administrator role. So, set 1563 // hostconsole group only for the administrator. 1564 if ((grp == "hostconsole") && (roleId != "priv-admin")) 1565 { 1566 if (!accountTypeUserGroups.empty()) 1567 { 1568 BMCWEB_LOG_ERROR( 1569 "Only administrator can get HostConsole access"); 1570 asyncResp->res.result(boost::beast::http::status::bad_request); 1571 return; 1572 } 1573 continue; 1574 } 1575 userGroups.emplace_back(grp); 1576 } 1577 1578 // Make sure user specified groups are valid. This is internal error because 1579 // it some inconsistencies between user manager and bmcweb. 1580 if (!accountTypeUserGroups.empty() && 1581 accountTypeUserGroups.size() != userGroups.size()) 1582 { 1583 messages::internalError(asyncResp->res); 1584 return; 1585 } 1586 crow::connections::systemBus->async_method_call( 1587 [asyncResp, username, password](const boost::system::error_code& ec2, 1588 sdbusplus::message_t& m) { 1589 processAfterCreateUser(asyncResp, username, password, ec2, m); 1590 }, 1591 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", 1592 "xyz.openbmc_project.User.Manager", "CreateUser", username, userGroups, 1593 roleId, enabled); 1594 } 1595 1596 inline void handleAccountCollectionPost( 1597 App& app, const crow::Request& req, 1598 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1599 { 1600 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1601 { 1602 return; 1603 } 1604 std::string username; 1605 std::string password; 1606 std::optional<std::string> roleIdJson; 1607 std::optional<bool> enabledJson; 1608 std::optional<std::vector<std::string>> accountTypes; 1609 if (!json_util::readJsonPatch(req, asyncResp->res, "UserName", username, 1610 "Password", password, "RoleId", roleIdJson, 1611 "Enabled", enabledJson, "AccountTypes", 1612 accountTypes)) 1613 { 1614 return; 1615 } 1616 1617 std::string roleId = roleIdJson.value_or("User"); 1618 std::string priv = getPrivilegeFromRoleId(roleId); 1619 if (priv.empty()) 1620 { 1621 messages::propertyValueNotInList(asyncResp->res, roleId, "RoleId"); 1622 return; 1623 } 1624 roleId = priv; 1625 1626 bool enabled = enabledJson.value_or(true); 1627 1628 // Reading AllGroups property 1629 sdbusplus::asio::getProperty<std::vector<std::string>>( 1630 *crow::connections::systemBus, "xyz.openbmc_project.User.Manager", 1631 "/xyz/openbmc_project/user", "xyz.openbmc_project.User.Manager", 1632 "AllGroups", 1633 [asyncResp, username, password{std::move(password)}, roleId, enabled, 1634 accountTypes](const boost::system::error_code& ec, 1635 const std::vector<std::string>& allGroupsList) { 1636 if (ec) 1637 { 1638 BMCWEB_LOG_DEBUG("ERROR with async_method_call"); 1639 messages::internalError(asyncResp->res); 1640 return; 1641 } 1642 1643 if (allGroupsList.empty()) 1644 { 1645 messages::internalError(asyncResp->res); 1646 return; 1647 } 1648 1649 processAfterGetAllGroups(asyncResp, username, password, roleId, enabled, 1650 accountTypes, allGroupsList); 1651 }); 1652 } 1653 1654 inline void 1655 handleAccountHead(App& app, const crow::Request& req, 1656 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1657 const std::string& /*accountName*/) 1658 { 1659 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1660 { 1661 return; 1662 } 1663 asyncResp->res.addHeader( 1664 boost::beast::http::field::link, 1665 "</redfish/v1/JsonSchemas/ManagerAccount/ManagerAccount.json>; rel=describedby"); 1666 } 1667 1668 inline void 1669 handleAccountGet(App& app, const crow::Request& req, 1670 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1671 const std::string& accountName) 1672 { 1673 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1674 { 1675 return; 1676 } 1677 asyncResp->res.addHeader( 1678 boost::beast::http::field::link, 1679 "</redfish/v1/JsonSchemas/ManagerAccount/ManagerAccount.json>; rel=describedby"); 1680 1681 #ifdef BMCWEB_INSECURE_DISABLE_AUTHENTICATION 1682 // If authentication is disabled, there are no user accounts 1683 messages::resourceNotFound(asyncResp->res, "ManagerAccount", accountName); 1684 return; 1685 #endif // BMCWEB_INSECURE_DISABLE_AUTHENTICATION 1686 1687 if (req.session == nullptr) 1688 { 1689 messages::internalError(asyncResp->res); 1690 return; 1691 } 1692 if (req.session->username != accountName) 1693 { 1694 // At this point we've determined that the user is trying to 1695 // modify a user that isn't them. We need to verify that they 1696 // have permissions to modify other users, so re-run the auth 1697 // check with the same permissions, minus ConfigureSelf. 1698 Privileges effectiveUserPrivileges = 1699 redfish::getUserPrivileges(*req.session); 1700 Privileges requiredPermissionsToChangeNonSelf = {"ConfigureUsers", 1701 "ConfigureManager"}; 1702 if (!effectiveUserPrivileges.isSupersetOf( 1703 requiredPermissionsToChangeNonSelf)) 1704 { 1705 BMCWEB_LOG_DEBUG("GET Account denied access"); 1706 messages::insufficientPrivilege(asyncResp->res); 1707 return; 1708 } 1709 } 1710 1711 sdbusplus::message::object_path path("/xyz/openbmc_project/user"); 1712 dbus::utility::getManagedObjects( 1713 "xyz.openbmc_project.User.Manager", path, 1714 [asyncResp, 1715 accountName](const boost::system::error_code& ec, 1716 const dbus::utility::ManagedObjectType& users) { 1717 if (ec) 1718 { 1719 messages::internalError(asyncResp->res); 1720 return; 1721 } 1722 const auto userIt = std::ranges::find_if( 1723 users, 1724 [accountName]( 1725 const std::pair<sdbusplus::message::object_path, 1726 dbus::utility::DBusInterfacesMap>& user) { 1727 return accountName == user.first.filename(); 1728 }); 1729 1730 if (userIt == users.end()) 1731 { 1732 messages::resourceNotFound(asyncResp->res, "ManagerAccount", 1733 accountName); 1734 return; 1735 } 1736 1737 asyncResp->res.jsonValue["@odata.type"] = 1738 "#ManagerAccount.v1_7_0.ManagerAccount"; 1739 asyncResp->res.jsonValue["Name"] = "User Account"; 1740 asyncResp->res.jsonValue["Description"] = "User Account"; 1741 asyncResp->res.jsonValue["Password"] = nullptr; 1742 asyncResp->res.jsonValue["StrictAccountTypes"] = true; 1743 1744 for (const auto& interface : userIt->second) 1745 { 1746 if (interface.first == "xyz.openbmc_project.User.Attributes") 1747 { 1748 for (const auto& property : interface.second) 1749 { 1750 if (property.first == "UserEnabled") 1751 { 1752 const bool* userEnabled = 1753 std::get_if<bool>(&property.second); 1754 if (userEnabled == nullptr) 1755 { 1756 BMCWEB_LOG_ERROR("UserEnabled wasn't a bool"); 1757 messages::internalError(asyncResp->res); 1758 return; 1759 } 1760 asyncResp->res.jsonValue["Enabled"] = *userEnabled; 1761 } 1762 else if (property.first == "UserLockedForFailedAttempt") 1763 { 1764 const bool* userLocked = 1765 std::get_if<bool>(&property.second); 1766 if (userLocked == nullptr) 1767 { 1768 BMCWEB_LOG_ERROR("UserLockedForF" 1769 "ailedAttempt " 1770 "wasn't a bool"); 1771 messages::internalError(asyncResp->res); 1772 return; 1773 } 1774 asyncResp->res.jsonValue["Locked"] = *userLocked; 1775 asyncResp->res 1776 .jsonValue["Locked@Redfish.AllowableValues"] = { 1777 "false"}; // can only unlock accounts 1778 } 1779 else if (property.first == "UserPrivilege") 1780 { 1781 const std::string* userPrivPtr = 1782 std::get_if<std::string>(&property.second); 1783 if (userPrivPtr == nullptr) 1784 { 1785 BMCWEB_LOG_ERROR("UserPrivilege wasn't a " 1786 "string"); 1787 messages::internalError(asyncResp->res); 1788 return; 1789 } 1790 std::string role = getRoleIdFromPrivilege(*userPrivPtr); 1791 if (role.empty()) 1792 { 1793 BMCWEB_LOG_ERROR("Invalid user role"); 1794 messages::internalError(asyncResp->res); 1795 return; 1796 } 1797 asyncResp->res.jsonValue["RoleId"] = role; 1798 1799 nlohmann::json& roleEntry = 1800 asyncResp->res.jsonValue["Links"]["Role"]; 1801 roleEntry["@odata.id"] = boost::urls::format( 1802 "/redfish/v1/AccountService/Roles/{}", role); 1803 } 1804 else if (property.first == "UserPasswordExpired") 1805 { 1806 const bool* userPasswordExpired = 1807 std::get_if<bool>(&property.second); 1808 if (userPasswordExpired == nullptr) 1809 { 1810 BMCWEB_LOG_ERROR( 1811 "UserPasswordExpired wasn't a bool"); 1812 messages::internalError(asyncResp->res); 1813 return; 1814 } 1815 asyncResp->res.jsonValue["PasswordChangeRequired"] = 1816 *userPasswordExpired; 1817 } 1818 else if (property.first == "UserGroups") 1819 { 1820 const std::vector<std::string>* userGroups = 1821 std::get_if<std::vector<std::string>>( 1822 &property.second); 1823 if (userGroups == nullptr) 1824 { 1825 BMCWEB_LOG_ERROR( 1826 "userGroups wasn't a string vector"); 1827 messages::internalError(asyncResp->res); 1828 return; 1829 } 1830 if (!translateUserGroup(*userGroups, asyncResp->res)) 1831 { 1832 BMCWEB_LOG_ERROR("userGroups mapping failed"); 1833 messages::internalError(asyncResp->res); 1834 return; 1835 } 1836 } 1837 } 1838 } 1839 } 1840 1841 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 1842 "/redfish/v1/AccountService/Accounts/{}", accountName); 1843 asyncResp->res.jsonValue["Id"] = accountName; 1844 asyncResp->res.jsonValue["UserName"] = accountName; 1845 }); 1846 } 1847 1848 inline void 1849 handleAccountDelete(App& app, const crow::Request& req, 1850 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1851 const std::string& username) 1852 { 1853 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1854 { 1855 return; 1856 } 1857 1858 #ifdef BMCWEB_INSECURE_DISABLE_AUTHENTICATION 1859 // If authentication is disabled, there are no user accounts 1860 messages::resourceNotFound(asyncResp->res, "ManagerAccount", username); 1861 return; 1862 1863 #endif // BMCWEB_INSECURE_DISABLE_AUTHENTICATION 1864 sdbusplus::message::object_path tempObjPath(rootUserDbusPath); 1865 tempObjPath /= username; 1866 const std::string userPath(tempObjPath); 1867 1868 crow::connections::systemBus->async_method_call( 1869 [asyncResp, username](const boost::system::error_code& ec) { 1870 if (ec) 1871 { 1872 messages::resourceNotFound(asyncResp->res, "ManagerAccount", 1873 username); 1874 return; 1875 } 1876 1877 messages::accountRemoved(asyncResp->res); 1878 }, 1879 "xyz.openbmc_project.User.Manager", userPath, 1880 "xyz.openbmc_project.Object.Delete", "Delete"); 1881 } 1882 1883 inline void 1884 handleAccountPatch(App& app, const crow::Request& req, 1885 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1886 const std::string& username) 1887 { 1888 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1889 { 1890 return; 1891 } 1892 #ifdef BMCWEB_INSECURE_DISABLE_AUTHENTICATION 1893 // If authentication is disabled, there are no user accounts 1894 messages::resourceNotFound(asyncResp->res, "ManagerAccount", username); 1895 return; 1896 1897 #endif // BMCWEB_INSECURE_DISABLE_AUTHENTICATION 1898 std::optional<std::string> newUserName; 1899 std::optional<std::string> password; 1900 std::optional<bool> enabled; 1901 std::optional<std::string> roleId; 1902 std::optional<bool> locked; 1903 std::optional<std::vector<std::string>> accountTypes; 1904 1905 if (req.session == nullptr) 1906 { 1907 messages::internalError(asyncResp->res); 1908 return; 1909 } 1910 1911 bool userSelf = (username == req.session->username); 1912 1913 Privileges effectiveUserPrivileges = 1914 redfish::getUserPrivileges(*req.session); 1915 Privileges configureUsers = {"ConfigureUsers"}; 1916 bool userHasConfigureUsers = 1917 effectiveUserPrivileges.isSupersetOf(configureUsers); 1918 if (userHasConfigureUsers) 1919 { 1920 // Users with ConfigureUsers can modify for all users 1921 if (!json_util::readJsonPatch( 1922 req, asyncResp->res, "UserName", newUserName, "Password", 1923 password, "RoleId", roleId, "Enabled", enabled, "Locked", 1924 locked, "AccountTypes", accountTypes)) 1925 { 1926 return; 1927 } 1928 } 1929 else 1930 { 1931 // ConfigureSelf accounts can only modify their own account 1932 if (!userSelf) 1933 { 1934 messages::insufficientPrivilege(asyncResp->res); 1935 return; 1936 } 1937 1938 // ConfigureSelf accounts can only modify their password 1939 if (!json_util::readJsonPatch(req, asyncResp->res, "Password", 1940 password)) 1941 { 1942 return; 1943 } 1944 } 1945 1946 // if user name is not provided in the patch method or if it 1947 // matches the user name in the URI, then we are treating it as 1948 // updating user properties other then username. If username 1949 // provided doesn't match the URI, then we are treating this as 1950 // user rename request. 1951 if (!newUserName || (newUserName.value() == username)) 1952 { 1953 updateUserProperties(asyncResp, username, password, enabled, roleId, 1954 locked, accountTypes, userSelf); 1955 return; 1956 } 1957 crow::connections::systemBus->async_method_call( 1958 [asyncResp, username, password(std::move(password)), 1959 roleId(std::move(roleId)), enabled, newUser{std::string(*newUserName)}, 1960 locked, userSelf, accountTypes(std::move(accountTypes))]( 1961 const boost::system::error_code& ec, sdbusplus::message_t& m) { 1962 if (ec) 1963 { 1964 userErrorMessageHandler(m.get_error(), asyncResp, newUser, 1965 username); 1966 return; 1967 } 1968 1969 updateUserProperties(asyncResp, newUser, password, enabled, roleId, 1970 locked, accountTypes, userSelf); 1971 }, 1972 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", 1973 "xyz.openbmc_project.User.Manager", "RenameUser", username, 1974 *newUserName); 1975 } 1976 1977 inline void requestAccountServiceRoutes(App& app) 1978 { 1979 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/") 1980 .privileges(redfish::privileges::headAccountService) 1981 .methods(boost::beast::http::verb::head)( 1982 std::bind_front(handleAccountServiceHead, std::ref(app))); 1983 1984 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/") 1985 .privileges(redfish::privileges::getAccountService) 1986 .methods(boost::beast::http::verb::get)( 1987 std::bind_front(handleAccountServiceGet, std::ref(app))); 1988 1989 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/") 1990 .privileges(redfish::privileges::patchAccountService) 1991 .methods(boost::beast::http::verb::patch)( 1992 std::bind_front(handleAccountServicePatch, std::ref(app))); 1993 1994 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/") 1995 .privileges(redfish::privileges::headManagerAccountCollection) 1996 .methods(boost::beast::http::verb::head)( 1997 std::bind_front(handleAccountCollectionHead, std::ref(app))); 1998 1999 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/") 2000 .privileges(redfish::privileges::getManagerAccountCollection) 2001 .methods(boost::beast::http::verb::get)( 2002 std::bind_front(handleAccountCollectionGet, std::ref(app))); 2003 2004 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/") 2005 .privileges(redfish::privileges::postManagerAccountCollection) 2006 .methods(boost::beast::http::verb::post)( 2007 std::bind_front(handleAccountCollectionPost, std::ref(app))); 2008 2009 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/") 2010 .privileges(redfish::privileges::headManagerAccount) 2011 .methods(boost::beast::http::verb::head)( 2012 std::bind_front(handleAccountHead, std::ref(app))); 2013 2014 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/") 2015 .privileges(redfish::privileges::getManagerAccount) 2016 .methods(boost::beast::http::verb::get)( 2017 std::bind_front(handleAccountGet, std::ref(app))); 2018 2019 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/") 2020 // TODO this privilege should be using the generated endpoints, but 2021 // because of the special handling of ConfigureSelf, it's not able to 2022 // yet 2023 .privileges({{"ConfigureUsers"}, {"ConfigureSelf"}}) 2024 .methods(boost::beast::http::verb::patch)( 2025 std::bind_front(handleAccountPatch, std::ref(app))); 2026 2027 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/") 2028 .privileges(redfish::privileges::deleteManagerAccount) 2029 .methods(boost::beast::http::verb::delete_)( 2030 std::bind_front(handleAccountDelete, std::ref(app))); 2031 } 2032 2033 } // namespace redfish 2034