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