Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 17 | #include "users.hpp" |
| 18 | |
Nan Zhou | 49c8136 | 2022-10-25 00:07:08 +0000 | [diff] [blame] | 19 | #include <boost/process/child.hpp> |
| 20 | #include <boost/process/io.hpp> |
| 21 | #include <phosphor-logging/elog-errors.hpp> |
| 22 | #include <phosphor-logging/elog.hpp> |
Jiaqing Zhao | 11ec666 | 2022-07-05 20:55:34 +0800 | [diff] [blame] | 23 | #include <phosphor-logging/lg2.hpp> |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 24 | #include <sdbusplus/bus.hpp> |
| 25 | #include <sdbusplus/server/object.hpp> |
Nan Zhou | 49c8136 | 2022-10-25 00:07:08 +0000 | [diff] [blame] | 26 | #include <xyz/openbmc_project/Common/error.hpp> |
Richard Marian Thomaiyar | 9164fd9 | 2018-06-13 16:51:00 +0530 | [diff] [blame] | 27 | #include <xyz/openbmc_project/User/AccountPolicy/server.hpp> |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 28 | #include <xyz/openbmc_project/User/Manager/server.hpp> |
| 29 | |
Nan Zhou | e47c09d | 2022-10-25 00:06:41 +0000 | [diff] [blame] | 30 | #include <span> |
| 31 | #include <string> |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 32 | #include <unordered_map> |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 33 | #include <variant> |
Nan Zhou | e47c09d | 2022-10-25 00:06:41 +0000 | [diff] [blame] | 34 | #include <vector> |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 35 | |
| 36 | namespace phosphor |
| 37 | { |
| 38 | namespace user |
| 39 | { |
| 40 | |
Nan Zhou | 49c8136 | 2022-10-25 00:07:08 +0000 | [diff] [blame] | 41 | inline constexpr size_t ipmiMaxUsers = 15; |
| 42 | inline constexpr size_t maxSystemUsers = 30; |
Nan Zhou | 4bc6981 | 2022-10-25 00:07:13 +0000 | [diff] [blame] | 43 | inline constexpr uint8_t minPasswdLength = 8; |
Nan Zhou | da401fe | 2022-10-25 00:07:18 +0000 | [diff] [blame] | 44 | inline constexpr size_t maxSystemGroupNameLength = 32; |
| 45 | inline constexpr size_t maxSystemGroupCount = 64; |
Nan Zhou | 49c8136 | 2022-10-25 00:07:08 +0000 | [diff] [blame] | 46 | |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 47 | using UserMgrIface = sdbusplus::xyz::openbmc_project::User::server::Manager; |
| 48 | using UserSSHLists = |
| 49 | std::pair<std::vector<std::string>, std::vector<std::string>>; |
Richard Marian Thomaiyar | 9164fd9 | 2018-06-13 16:51:00 +0530 | [diff] [blame] | 50 | using AccountPolicyIface = |
| 51 | sdbusplus::xyz::openbmc_project::User::server::AccountPolicy; |
| 52 | |
Patrick Williams | b3ef4e1 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 53 | using Ifaces = sdbusplus::server::object_t<UserMgrIface, AccountPolicyIface>; |
Ratan Gupta | 1af1223 | 2018-11-03 00:35:38 +0530 | [diff] [blame] | 54 | |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 55 | using Privilege = std::string; |
| 56 | using GroupList = std::vector<std::string>; |
| 57 | using UserEnabled = bool; |
| 58 | using PropertyName = std::string; |
Ravi Teja | 5fe724a | 2019-05-07 05:14:42 -0500 | [diff] [blame] | 59 | using ServiceEnabled = bool; |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 60 | |
| 61 | using UserInfo = std::variant<Privilege, GroupList, UserEnabled>; |
| 62 | using UserInfoMap = std::map<PropertyName, UserInfo>; |
| 63 | |
| 64 | using DbusUserObjPath = sdbusplus::message::object_path; |
| 65 | |
Patrick Williams | fdf0937 | 2020-05-13 18:01:45 -0500 | [diff] [blame] | 66 | using DbusUserPropVariant = std::variant<Privilege, ServiceEnabled>; |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 67 | |
Alexander Filippov | 7562658 | 2022-02-09 18:42:37 +0300 | [diff] [blame] | 68 | using DbusUserObjProperties = std::map<PropertyName, DbusUserPropVariant>; |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 69 | |
| 70 | using Interface = std::string; |
| 71 | |
| 72 | using DbusUserObjValue = std::map<Interface, DbusUserObjProperties>; |
| 73 | |
| 74 | using DbusUserObj = std::map<DbusUserObjPath, DbusUserObjValue>; |
| 75 | |
Nan Zhou | e47c09d | 2022-10-25 00:06:41 +0000 | [diff] [blame] | 76 | std::string getCSVFromVector(std::span<const std::string> vec); |
| 77 | |
Nan Zhou | 332fb9d | 2022-10-25 00:07:03 +0000 | [diff] [blame] | 78 | bool removeStringFromCSV(std::string& csvStr, const std::string& delStr); |
| 79 | |
Nan Zhou | 8a11d99 | 2022-10-25 00:07:06 +0000 | [diff] [blame] | 80 | template <typename... ArgTypes> |
Nan Zhou | 49c8136 | 2022-10-25 00:07:08 +0000 | [diff] [blame] | 81 | std::vector<std::string> executeCmd(const char* path, ArgTypes&&... tArgs) |
| 82 | { |
| 83 | std::vector<std::string> stdOutput; |
| 84 | boost::process::ipstream stdOutStream; |
| 85 | boost::process::child execProg(path, const_cast<char*>(tArgs)..., |
| 86 | boost::process::std_out > stdOutStream); |
| 87 | std::string stdOutLine; |
| 88 | |
| 89 | while (stdOutStream && std::getline(stdOutStream, stdOutLine) && |
| 90 | !stdOutLine.empty()) |
| 91 | { |
| 92 | stdOutput.emplace_back(stdOutLine); |
| 93 | } |
| 94 | |
| 95 | execProg.wait(); |
| 96 | |
| 97 | int retCode = execProg.exit_code(); |
| 98 | if (retCode) |
| 99 | { |
Jiaqing Zhao | 11ec666 | 2022-07-05 20:55:34 +0800 | [diff] [blame] | 100 | lg2::error("Command {PATH} execution failed, return code {RETCODE}", |
| 101 | "PATH", path, "RETCODE", retCode); |
Nan Zhou | 49c8136 | 2022-10-25 00:07:08 +0000 | [diff] [blame] | 102 | phosphor::logging::elog< |
| 103 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure>(); |
| 104 | } |
| 105 | |
| 106 | return stdOutput; |
| 107 | } |
Nan Zhou | 8a11d99 | 2022-10-25 00:07:06 +0000 | [diff] [blame] | 108 | |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 109 | /** @class UserMgr |
| 110 | * @brief Responsible for managing user accounts over the D-Bus interface. |
| 111 | */ |
Ratan Gupta | 1af1223 | 2018-11-03 00:35:38 +0530 | [diff] [blame] | 112 | class UserMgr : public Ifaces |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 113 | { |
| 114 | public: |
| 115 | UserMgr() = delete; |
| 116 | ~UserMgr() = default; |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 117 | UserMgr(const UserMgr&) = delete; |
| 118 | UserMgr& operator=(const UserMgr&) = delete; |
| 119 | UserMgr(UserMgr&&) = delete; |
| 120 | UserMgr& operator=(UserMgr&&) = delete; |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 121 | |
| 122 | /** @brief Constructs UserMgr object. |
| 123 | * |
| 124 | * @param[in] bus - sdbusplus handler |
| 125 | * @param[in] path - D-Bus path |
| 126 | */ |
Patrick Williams | b3ef4e1 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 127 | UserMgr(sdbusplus::bus_t& bus, const char* path); |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 128 | |
| 129 | /** @brief create user method. |
| 130 | * This method creates a new user as requested |
| 131 | * |
| 132 | * @param[in] userName - Name of the user which has to be created |
| 133 | * @param[in] groupNames - Group names list, to which user has to be added. |
| 134 | * @param[in] priv - Privilege of the user. |
| 135 | * @param[in] enabled - State of the user enabled / disabled. |
| 136 | */ |
| 137 | void createUser(std::string userName, std::vector<std::string> groupNames, |
| 138 | std::string priv, bool enabled) override; |
| 139 | |
| 140 | /** @brief rename user method. |
| 141 | * This method renames the user as requested |
| 142 | * |
| 143 | * @param[in] userName - current name of the user |
| 144 | * @param[in] newUserName - new user name to which it has to be renamed. |
| 145 | */ |
| 146 | void renameUser(std::string userName, std::string newUserName) override; |
| 147 | |
| 148 | /** @brief delete user method. |
| 149 | * This method deletes the user as requested |
| 150 | * |
| 151 | * @param[in] userName - Name of the user which has to be deleted |
| 152 | */ |
| 153 | void deleteUser(std::string userName); |
| 154 | |
| 155 | /** @brief Update user groups & privilege. |
| 156 | * This method updates user groups & privilege |
| 157 | * |
| 158 | * @param[in] userName - user name, for which update is requested |
| 159 | * @param[in] groupName - Group to be updated.. |
| 160 | * @param[in] priv - Privilege to be updated. |
| 161 | */ |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 162 | void updateGroupsAndPriv(const std::string& userName, |
Nan Zhou | fef6303 | 2022-10-25 00:07:12 +0000 | [diff] [blame] | 163 | std::vector<std::string> groups, |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 164 | const std::string& priv); |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 165 | |
| 166 | /** @brief Update user enabled state. |
| 167 | * This method enables / disables user |
| 168 | * |
| 169 | * @param[in] userName - user name, for which update is requested |
| 170 | * @param[in] enabled - enable / disable the user |
| 171 | */ |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 172 | void userEnable(const std::string& userName, bool enabled); |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 173 | |
Richard Marian Thomaiyar | 9164fd9 | 2018-06-13 16:51:00 +0530 | [diff] [blame] | 174 | /** @brief update minimum password length requirement |
| 175 | * |
| 176 | * @param[in] val - minimum password length |
| 177 | * @return - minimum password length |
| 178 | */ |
| 179 | uint8_t minPasswordLength(uint8_t val) override; |
| 180 | |
| 181 | /** @brief update old password history count |
| 182 | * |
| 183 | * @param[in] val - number of times old passwords has to be avoided |
| 184 | * @return - number of times old password has to be avoided |
| 185 | */ |
| 186 | uint8_t rememberOldPasswordTimes(uint8_t val) override; |
| 187 | |
| 188 | /** @brief update maximum number of failed login attempt before locked |
| 189 | * out. |
| 190 | * |
| 191 | * @param[in] val - number of allowed attempt |
| 192 | * @return - number of allowed attempt |
| 193 | */ |
| 194 | uint16_t maxLoginAttemptBeforeLockout(uint16_t val) override; |
| 195 | |
| 196 | /** @brief update timeout to unlock the account |
| 197 | * |
| 198 | * @param[in] val - value in seconds |
| 199 | * @return - value in seconds |
| 200 | */ |
| 201 | uint32_t accountUnlockTimeout(uint32_t val) override; |
| 202 | |
Jason M. Bills | 2d042d1 | 2023-03-28 15:32:45 -0700 | [diff] [blame] | 203 | /** @brief parses the faillock output for locked user status |
| 204 | * |
| 205 | * @param[in] - output from faillock for the user |
| 206 | * @return - true / false indicating user locked / un-locked |
| 207 | **/ |
| 208 | bool |
| 209 | parseFaillockForLockout(const std::vector<std::string>& faillockOutput); |
| 210 | |
Richard Marian Thomaiyar | c704519 | 2018-06-13 16:51:00 +0530 | [diff] [blame] | 211 | /** @brief lists user locked state for failed attempt |
| 212 | * |
| 213 | * @param[in] - user name |
| 214 | * @return - true / false indicating user locked / un-locked |
| 215 | **/ |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 216 | virtual bool userLockedForFailedAttempt(const std::string& userName); |
Richard Marian Thomaiyar | c704519 | 2018-06-13 16:51:00 +0530 | [diff] [blame] | 217 | |
| 218 | /** @brief lists user locked state for failed attempt |
| 219 | * |
| 220 | * @param[in]: user name |
| 221 | * @param[in]: value - false -unlock user account, true - no action taken |
| 222 | **/ |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 223 | bool userLockedForFailedAttempt(const std::string& userName, |
| 224 | const bool& value); |
Richard Marian Thomaiyar | c704519 | 2018-06-13 16:51:00 +0530 | [diff] [blame] | 225 | |
Joseph Reynolds | 3ab6cc2 | 2020-03-03 14:09:03 -0600 | [diff] [blame] | 226 | /** @brief shows if the user's password is expired |
| 227 | * |
| 228 | * @param[in]: user name |
| 229 | * @return - true / false indicating user password expired |
| 230 | **/ |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 231 | virtual bool userPasswordExpired(const std::string& userName); |
Joseph Reynolds | 3ab6cc2 | 2020-03-03 14:09:03 -0600 | [diff] [blame] | 232 | |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 233 | /** @brief returns user info |
| 234 | * Checks if user is local user, then returns map of properties of user. |
| 235 | * like user privilege, list of user groups, user enabled state and user |
| 236 | * locked state. If its not local user, then it checks if its a ldap user, |
| 237 | * then it gets the privilege mapping of the LDAP group. |
| 238 | * |
| 239 | * @param[in] - user name |
| 240 | * @return - map of user properties |
| 241 | **/ |
| 242 | UserInfoMap getUserInfo(std::string userName) override; |
| 243 | |
Nan Zhou | 49c8136 | 2022-10-25 00:07:08 +0000 | [diff] [blame] | 244 | /** @brief get IPMI user count |
| 245 | * method to get IPMI user count |
| 246 | * |
| 247 | * @return - returns user count |
| 248 | */ |
| 249 | virtual size_t getIpmiUsersCount(void); |
| 250 | |
Nan Zhou | da401fe | 2022-10-25 00:07:18 +0000 | [diff] [blame] | 251 | void createGroup(std::string groupName) override; |
| 252 | |
| 253 | void deleteGroup(std::string groupName) override; |
| 254 | |
| 255 | static std::vector<std::string> readAllGroupsOnSystem(); |
| 256 | |
Nan Zhou | e48085d | 2022-10-25 00:07:04 +0000 | [diff] [blame] | 257 | protected: |
| 258 | /** @brief get pam argument value |
| 259 | * method to get argument value from pam configuration |
| 260 | * |
| 261 | * @param[in] moduleName - name of the module from where arg has to be read |
| 262 | * @param[in] argName - argument name |
| 263 | * @param[out] argValue - argument value |
| 264 | * |
| 265 | * @return 0 - success state of the function |
| 266 | */ |
| 267 | int getPamModuleArgValue(const std::string& moduleName, |
| 268 | const std::string& argName, std::string& argValue); |
| 269 | |
Jason M. Bills | 2d042d1 | 2023-03-28 15:32:45 -0700 | [diff] [blame] | 270 | /** @brief get pam argument value |
| 271 | * method to get argument value from pam configuration |
| 272 | * |
| 273 | * @param[in] confFile - path of the module config file from where arg has |
| 274 | * to be read |
| 275 | * @param[in] argName - argument name |
| 276 | * @param[out] argValue - argument value |
| 277 | * |
| 278 | * @return 0 - success state of the function |
| 279 | */ |
| 280 | int getPamModuleConfValue(const std::string& confFile, |
| 281 | const std::string& argName, |
| 282 | std::string& argValue); |
| 283 | |
Nan Zhou | e48085d | 2022-10-25 00:07:04 +0000 | [diff] [blame] | 284 | /** @brief set pam argument value |
| 285 | * method to set argument value in pam configuration |
| 286 | * |
| 287 | * @param[in] moduleName - name of the module in which argument value has |
| 288 | * to be set |
| 289 | * @param[in] argName - argument name |
| 290 | * @param[out] argValue - argument value |
| 291 | * |
| 292 | * @return 0 - success state of the function |
| 293 | */ |
| 294 | int setPamModuleArgValue(const std::string& moduleName, |
| 295 | const std::string& argName, |
| 296 | const std::string& argValue); |
| 297 | |
Jason M. Bills | 2d042d1 | 2023-03-28 15:32:45 -0700 | [diff] [blame] | 298 | /** @brief set pam argument value |
| 299 | * method to set argument value in pam configuration |
| 300 | * |
| 301 | * @param[in] confFile - path of the module config file in which argument |
| 302 | * value has to be set |
| 303 | * @param[in] argName - argument name |
| 304 | * @param[out] argValue - argument value |
| 305 | * |
| 306 | * @return 0 - success state of the function |
| 307 | */ |
| 308 | int setPamModuleConfValue(const std::string& confFile, |
| 309 | const std::string& argName, |
| 310 | const std::string& argValue); |
| 311 | |
Nan Zhou | 8a11d99 | 2022-10-25 00:07:06 +0000 | [diff] [blame] | 312 | /** @brief check for user presence |
| 313 | * method to check for user existence |
| 314 | * |
| 315 | * @param[in] userName - name of the user |
| 316 | * @return -true if user exists and false if not. |
| 317 | */ |
| 318 | bool isUserExist(const std::string& userName); |
| 319 | |
Nan Zhou | 49c8136 | 2022-10-25 00:07:08 +0000 | [diff] [blame] | 320 | size_t getNonIpmiUsersCount(); |
| 321 | |
Nan Zhou | 8a11d99 | 2022-10-25 00:07:06 +0000 | [diff] [blame] | 322 | /** @brief check user exists |
| 323 | * method to check whether user exist, and throw if not. |
| 324 | * |
| 325 | * @param[in] userName - name of the user |
| 326 | */ |
| 327 | void throwForUserDoesNotExist(const std::string& userName); |
| 328 | |
| 329 | /** @brief check user does not exist |
| 330 | * method to check whether does not exist, and throw if exists. |
| 331 | * |
| 332 | * @param[in] userName - name of the user |
| 333 | */ |
| 334 | void throwForUserExists(const std::string& userName); |
| 335 | |
Nan Zhou | 40e4497 | 2022-10-25 00:07:07 +0000 | [diff] [blame] | 336 | /** @brief check user name constraints |
| 337 | * method to check user name constraints and throw if failed. |
| 338 | * |
| 339 | * @param[in] userName - name of the user |
| 340 | * @param[in] groupNames - user groups |
| 341 | */ |
| 342 | void |
| 343 | throwForUserNameConstraints(const std::string& userName, |
| 344 | const std::vector<std::string>& groupNames); |
| 345 | |
Nan Zhou | 49c8136 | 2022-10-25 00:07:08 +0000 | [diff] [blame] | 346 | /** @brief check group user count |
| 347 | * method to check max group user count, and throw if limit reached |
| 348 | * |
| 349 | * @param[in] groupNames - group name |
| 350 | */ |
| 351 | void throwForMaxGrpUserCount(const std::vector<std::string>& groupNames); |
| 352 | |
| 353 | virtual void executeUserAdd(const char* userName, const char* groups, |
| 354 | bool sshRequested, bool enabled); |
| 355 | |
| 356 | virtual void executeUserDelete(const char* userName); |
| 357 | |
Jayanth Othayoth | ac921a5 | 2023-07-21 03:48:55 -0500 | [diff] [blame] | 358 | /** @brief clear user's failure records |
| 359 | * method to clear user fail records and throw if failed. |
| 360 | * |
| 361 | * @param[in] userName - name of the user |
| 362 | */ |
| 363 | virtual void executeUserClearFailRecords(const char* userName); |
| 364 | |
Nan Zhou | f25443e | 2022-10-25 00:07:11 +0000 | [diff] [blame] | 365 | virtual void executeUserRename(const char* userName, |
| 366 | const char* newUserName); |
| 367 | |
Nan Zhou | fef6303 | 2022-10-25 00:07:12 +0000 | [diff] [blame] | 368 | virtual void executeUserModify(const char* userName, const char* newGroups, |
| 369 | bool sshRequested); |
| 370 | |
Nan Zhou | 6b6f2d8 | 2022-10-25 00:07:17 +0000 | [diff] [blame] | 371 | virtual void executeUserModifyUserEnable(const char* userName, |
| 372 | bool enabled); |
| 373 | |
Nan Zhou | da401fe | 2022-10-25 00:07:18 +0000 | [diff] [blame] | 374 | virtual void executeGroupCreation(const char* groupName); |
Nan Zhou | 86040c2 | 2022-11-17 02:08:24 +0000 | [diff] [blame] | 375 | |
Nan Zhou | da401fe | 2022-10-25 00:07:18 +0000 | [diff] [blame] | 376 | virtual void executeGroupDeletion(const char* groupName); |
Nan Zhou | 86040c2 | 2022-11-17 02:08:24 +0000 | [diff] [blame] | 377 | |
Nan Zhou | a295303 | 2022-11-11 21:50:32 +0000 | [diff] [blame] | 378 | virtual std::vector<std::string> getFailedAttempt(const char* userName); |
| 379 | |
Nan Zhou | 589aeb4 | 2022-10-25 00:07:09 +0000 | [diff] [blame] | 380 | /** @brief check for valid privielge |
| 381 | * method to check valid privilege, and throw if invalid |
| 382 | * |
| 383 | * @param[in] priv - privilege of the user |
| 384 | */ |
| 385 | void throwForInvalidPrivilege(const std::string& priv); |
| 386 | |
Nan Zhou | ecf8876 | 2022-10-25 00:07:10 +0000 | [diff] [blame] | 387 | /** @brief check for valid groups |
| 388 | * method to check valid groups, and throw if invalid |
| 389 | * |
| 390 | * @param[in] groupNames - user groups |
| 391 | */ |
| 392 | void throwForInvalidGroups(const std::vector<std::string>& groupName); |
| 393 | |
Nan Zhou | 4bc6981 | 2022-10-25 00:07:13 +0000 | [diff] [blame] | 394 | void initializeAccountPolicy(); |
| 395 | |
Nan Zhou | da401fe | 2022-10-25 00:07:18 +0000 | [diff] [blame] | 396 | /** @brief checks if the group creation meets all constraints |
| 397 | * @param groupName - group to check |
| 398 | */ |
| 399 | void checkCreateGroupConstraints(const std::string& groupName); |
| 400 | |
| 401 | /** @brief checks if the group deletion meets all constraints |
| 402 | * @param groupName - group to check |
| 403 | */ |
| 404 | void checkDeleteGroupConstraints(const std::string& groupName); |
| 405 | |
| 406 | /** @brief checks if the group name is legal and whether it's allowed to |
| 407 | * change. The daemon doesn't allow arbitrary group to be created |
| 408 | * @param groupName - group to check |
| 409 | */ |
| 410 | void checkAndThrowForDisallowedGroupCreation(const std::string& groupName); |
| 411 | |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 412 | private: |
| 413 | /** @brief sdbusplus handler */ |
Patrick Williams | b3ef4e1 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 414 | sdbusplus::bus_t& bus; |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 415 | |
| 416 | /** @brief object path */ |
| 417 | const std::string path; |
| 418 | |
| 419 | /** @brief privilege manager container */ |
Nan Zhou | da401fe | 2022-10-25 00:07:18 +0000 | [diff] [blame] | 420 | const std::vector<std::string> privMgr = {"priv-admin", "priv-operator", |
| 421 | "priv-user"}; |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 422 | |
| 423 | /** @brief groups manager container */ |
Nan Zhou | da401fe | 2022-10-25 00:07:18 +0000 | [diff] [blame] | 424 | std::vector<std::string> groupsMgr; |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 425 | |
| 426 | /** @brief map container to hold users object */ |
| 427 | using UserName = std::string; |
| 428 | std::unordered_map<UserName, std::unique_ptr<phosphor::user::Users>> |
| 429 | usersList; |
| 430 | |
| 431 | /** @brief get users in group |
| 432 | * method to get group user list |
| 433 | * |
| 434 | * @param[in] groupName - group name |
| 435 | * |
| 436 | * @return userList - list of users in the group. |
| 437 | */ |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 438 | std::vector<std::string> getUsersInGroup(const std::string& groupName); |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 439 | |
| 440 | /** @brief get user & SSH users list |
| 441 | * method to get the users and ssh users list. |
| 442 | * |
| 443 | *@return - vector of User & SSH user lists |
| 444 | */ |
| 445 | UserSSHLists getUserAndSshGrpList(void); |
| 446 | |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 447 | /** @brief get user enabled state |
| 448 | * method to get user enabled state. |
| 449 | * |
| 450 | * @param[in] userName - name of the user |
| 451 | * @return - user enabled status (true/false) |
| 452 | */ |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 453 | bool isUserEnabled(const std::string& userName); |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 454 | |
| 455 | /** @brief initialize the user manager objects |
| 456 | * method to initialize the user manager objects accordingly |
| 457 | * |
| 458 | */ |
| 459 | void initUserObjects(void); |
| 460 | |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 461 | /** @brief get service name |
| 462 | * method to get dbus service name |
| 463 | * |
| 464 | * @param[in] path - object path |
| 465 | * @param[in] intf - interface |
| 466 | * @return - service name |
| 467 | */ |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 468 | std::string getServiceName(std::string&& path, std::string&& intf); |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 469 | |
Alexander Filippov | 7562658 | 2022-02-09 18:42:37 +0300 | [diff] [blame] | 470 | /** @brief get primary group ID of specified user |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 471 | * |
Alexander Filippov | 7562658 | 2022-02-09 18:42:37 +0300 | [diff] [blame] | 472 | * @param[in] - userName |
| 473 | * @return - primary group ID |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 474 | */ |
Alexander Filippov | 7562658 | 2022-02-09 18:42:37 +0300 | [diff] [blame] | 475 | virtual gid_t getPrimaryGroup(const std::string& userName) const; |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 476 | |
Alexander Filippov | 7562658 | 2022-02-09 18:42:37 +0300 | [diff] [blame] | 477 | /** @brief check whether if the user is a member of the group |
| 478 | * |
| 479 | * @param[in] - userName |
| 480 | * @param[in] - ID of the user's primary group |
| 481 | * @param[in] - groupName |
| 482 | * @return - true if the user is a member of the group |
| 483 | */ |
| 484 | virtual bool isGroupMember(const std::string& userName, gid_t primaryGid, |
| 485 | const std::string& groupName) const; |
| 486 | |
| 487 | protected: |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 488 | /** @brief get privilege mapper object |
| 489 | * method to get dbus privilege mapper object |
| 490 | * |
| 491 | * @return - map of user object |
| 492 | */ |
raviteja-b | 8cc4405 | 2019-02-27 23:29:36 -0600 | [diff] [blame] | 493 | virtual DbusUserObj getPrivilegeMapperObject(void); |
| 494 | |
| 495 | friend class TestUserMgr; |
Nan Zhou | e48085d | 2022-10-25 00:07:04 +0000 | [diff] [blame] | 496 | |
Jason M. Bills | 2d042d1 | 2023-03-28 15:32:45 -0700 | [diff] [blame] | 497 | std::string faillockConfigFile; |
Jason M. Bills | 3b280ec | 2023-08-15 16:15:48 -0700 | [diff] [blame^] | 498 | std::string pwHistoryConfigFile; |
Jason M. Bills | 2d042d1 | 2023-03-28 15:32:45 -0700 | [diff] [blame] | 499 | std::string pwQualityConfigFile; |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 500 | }; |
| 501 | |
| 502 | } // namespace user |
| 503 | } // namespace phosphor |