xref: /openbmc/phosphor-user-manager/user_mgr.hpp (revision 0e427be810a3233f23186cce599e8bf680ae3f62)
19f630d9eSRichard Marian Thomaiyar /*
29f630d9eSRichard Marian Thomaiyar // Copyright (c) 2018 Intel Corporation
39f630d9eSRichard Marian Thomaiyar //
49f630d9eSRichard Marian Thomaiyar // Licensed under the Apache License, Version 2.0 (the "License");
59f630d9eSRichard Marian Thomaiyar // you may not use this file except in compliance with the License.
69f630d9eSRichard Marian Thomaiyar // You may obtain a copy of the License at
79f630d9eSRichard Marian Thomaiyar //
89f630d9eSRichard Marian Thomaiyar //      http://www.apache.org/licenses/LICENSE-2.0
99f630d9eSRichard Marian Thomaiyar //
109f630d9eSRichard Marian Thomaiyar // Unless required by applicable law or agreed to in writing, software
119f630d9eSRichard Marian Thomaiyar // distributed under the License is distributed on an "AS IS" BASIS,
129f630d9eSRichard Marian Thomaiyar // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139f630d9eSRichard Marian Thomaiyar // See the License for the specific language governing permissions and
149f630d9eSRichard Marian Thomaiyar // limitations under the License.
159f630d9eSRichard Marian Thomaiyar */
169f630d9eSRichard Marian Thomaiyar #pragma once
1793804ebaSAbhilash Raju #include "json_serializer.hpp"
189638afb9SPatrick Williams #include "users.hpp"
199638afb9SPatrick Williams 
2049c81364SNan Zhou #include <boost/process/child.hpp>
2149c81364SNan Zhou #include <boost/process/io.hpp>
2249c81364SNan Zhou #include <phosphor-logging/elog-errors.hpp>
2349c81364SNan Zhou #include <phosphor-logging/elog.hpp>
2411ec666bSJiaqing Zhao #include <phosphor-logging/lg2.hpp>
259f630d9eSRichard Marian Thomaiyar #include <sdbusplus/bus.hpp>
269f630d9eSRichard Marian Thomaiyar #include <sdbusplus/server/object.hpp>
2749c81364SNan Zhou #include <xyz/openbmc_project/Common/error.hpp>
289164fd9bSRichard Marian Thomaiyar #include <xyz/openbmc_project/User/AccountPolicy/server.hpp>
299638afb9SPatrick Williams #include <xyz/openbmc_project/User/Manager/server.hpp>
30a1a754c2SAbhilash Raju #include <xyz/openbmc_project/User/MultiFactorAuthConfiguration/server.hpp>
31a1a754c2SAbhilash Raju #include <xyz/openbmc_project/User/TOTPState/server.hpp>
329638afb9SPatrick Williams 
33e47c09d3SNan Zhou #include <span>
34e47c09d3SNan Zhou #include <string>
359f630d9eSRichard Marian Thomaiyar #include <unordered_map>
36aeaf9413SRatan Gupta #include <variant>
37e47c09d3SNan Zhou #include <vector>
389f630d9eSRichard Marian Thomaiyar 
399f630d9eSRichard Marian Thomaiyar namespace phosphor
409f630d9eSRichard Marian Thomaiyar {
419f630d9eSRichard Marian Thomaiyar namespace user
429f630d9eSRichard Marian Thomaiyar {
439f630d9eSRichard Marian Thomaiyar 
4449c81364SNan Zhou inline constexpr size_t ipmiMaxUsers = 15;
4549c81364SNan Zhou inline constexpr size_t maxSystemUsers = 30;
464bc69810SNan Zhou inline constexpr uint8_t minPasswdLength = 8;
47da401fe5SNan Zhou inline constexpr size_t maxSystemGroupNameLength = 32;
48da401fe5SNan Zhou inline constexpr size_t maxSystemGroupCount = 64;
4949c81364SNan Zhou 
509f630d9eSRichard Marian Thomaiyar using UserMgrIface = sdbusplus::xyz::openbmc_project::User::server::Manager;
519f630d9eSRichard Marian Thomaiyar using UserSSHLists =
529f630d9eSRichard Marian Thomaiyar     std::pair<std::vector<std::string>, std::vector<std::string>>;
539164fd9bSRichard Marian Thomaiyar using AccountPolicyIface =
549164fd9bSRichard Marian Thomaiyar     sdbusplus::xyz::openbmc_project::User::server::AccountPolicy;
559164fd9bSRichard Marian Thomaiyar 
56a1a754c2SAbhilash Raju using MultiFactorAuthConfigurationIface =
57a1a754c2SAbhilash Raju     sdbusplus::xyz::openbmc_project::User::server::MultiFactorAuthConfiguration;
58a1a754c2SAbhilash Raju 
59a1a754c2SAbhilash Raju using TOTPStateIface = sdbusplus::xyz::openbmc_project::User::server::TOTPState;
60a1a754c2SAbhilash Raju 
61a1a754c2SAbhilash Raju using Ifaces = sdbusplus::server::object_t<UserMgrIface, AccountPolicyIface,
62a1a754c2SAbhilash Raju                                            MultiFactorAuthConfigurationIface,
63a1a754c2SAbhilash Raju                                            TOTPStateIface>;
641af12233SRatan Gupta 
65aeaf9413SRatan Gupta using Privilege = std::string;
66aeaf9413SRatan Gupta using GroupList = std::vector<std::string>;
67aeaf9413SRatan Gupta using UserEnabled = bool;
68aeaf9413SRatan Gupta using PropertyName = std::string;
695fe724a7SRavi Teja using ServiceEnabled = bool;
70aeaf9413SRatan Gupta 
71aeaf9413SRatan Gupta using UserInfo = std::variant<Privilege, GroupList, UserEnabled>;
72aeaf9413SRatan Gupta using UserInfoMap = std::map<PropertyName, UserInfo>;
73aeaf9413SRatan Gupta 
74aeaf9413SRatan Gupta using DbusUserObjPath = sdbusplus::message::object_path;
75aeaf9413SRatan Gupta 
76fdf09373SPatrick Williams using DbusUserPropVariant = std::variant<Privilege, ServiceEnabled>;
77aeaf9413SRatan Gupta 
787562658eSAlexander Filippov using DbusUserObjProperties = std::map<PropertyName, DbusUserPropVariant>;
79aeaf9413SRatan Gupta 
80aeaf9413SRatan Gupta using Interface = std::string;
81aeaf9413SRatan Gupta 
82aeaf9413SRatan Gupta using DbusUserObjValue = std::map<Interface, DbusUserObjProperties>;
83aeaf9413SRatan Gupta 
84aeaf9413SRatan Gupta using DbusUserObj = std::map<DbusUserObjPath, DbusUserObjValue>;
85aeaf9413SRatan Gupta 
86a1a754c2SAbhilash Raju using MultiFactorAuthType = sdbusplus::common::xyz::openbmc_project::user::
87a1a754c2SAbhilash Raju     MultiFactorAuthConfiguration::Type;
88e47c09d3SNan Zhou std::string getCSVFromVector(std::span<const std::string> vec);
89e47c09d3SNan Zhou 
90332fb9dcSNan Zhou bool removeStringFromCSV(std::string& csvStr, const std::string& delStr);
91332fb9dcSNan Zhou 
928a11d998SNan Zhou template <typename... ArgTypes>
executeCmd(const char * path,ArgTypes &&...tArgs)9349c81364SNan Zhou std::vector<std::string> executeCmd(const char* path, ArgTypes&&... tArgs)
9449c81364SNan Zhou {
9549c81364SNan Zhou     std::vector<std::string> stdOutput;
9649c81364SNan Zhou     boost::process::ipstream stdOutStream;
9749c81364SNan Zhou     boost::process::child execProg(path, const_cast<char*>(tArgs)...,
9849c81364SNan Zhou                                    boost::process::std_out > stdOutStream);
9949c81364SNan Zhou     std::string stdOutLine;
10049c81364SNan Zhou 
10149c81364SNan Zhou     while (stdOutStream && std::getline(stdOutStream, stdOutLine) &&
10249c81364SNan Zhou            !stdOutLine.empty())
10349c81364SNan Zhou     {
10449c81364SNan Zhou         stdOutput.emplace_back(stdOutLine);
10549c81364SNan Zhou     }
10649c81364SNan Zhou 
10749c81364SNan Zhou     execProg.wait();
10849c81364SNan Zhou 
10949c81364SNan Zhou     int retCode = execProg.exit_code();
11049c81364SNan Zhou     if (retCode)
11149c81364SNan Zhou     {
11211ec666bSJiaqing Zhao         lg2::error("Command {PATH} execution failed, return code {RETCODE}",
11311ec666bSJiaqing Zhao                    "PATH", path, "RETCODE", retCode);
11449c81364SNan Zhou         phosphor::logging::elog<
11549c81364SNan Zhou             sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure>();
11649c81364SNan Zhou     }
11749c81364SNan Zhou 
11849c81364SNan Zhou     return stdOutput;
11949c81364SNan Zhou }
1208a11d998SNan Zhou 
1219f630d9eSRichard Marian Thomaiyar /** @class UserMgr
1229f630d9eSRichard Marian Thomaiyar  *  @brief Responsible for managing user accounts over the D-Bus interface.
1239f630d9eSRichard Marian Thomaiyar  */
1241af12233SRatan Gupta class UserMgr : public Ifaces
1259f630d9eSRichard Marian Thomaiyar {
1269f630d9eSRichard Marian Thomaiyar   public:
1279f630d9eSRichard Marian Thomaiyar     UserMgr() = delete;
1289f630d9eSRichard Marian Thomaiyar     ~UserMgr() = default;
1299f630d9eSRichard Marian Thomaiyar     UserMgr(const UserMgr&) = delete;
1309f630d9eSRichard Marian Thomaiyar     UserMgr& operator=(const UserMgr&) = delete;
1319f630d9eSRichard Marian Thomaiyar     UserMgr(UserMgr&&) = delete;
1329f630d9eSRichard Marian Thomaiyar     UserMgr& operator=(UserMgr&&) = delete;
1339f630d9eSRichard Marian Thomaiyar 
1349f630d9eSRichard Marian Thomaiyar     /** @brief Constructs UserMgr object.
1359f630d9eSRichard Marian Thomaiyar      *
1369f630d9eSRichard Marian Thomaiyar      *  @param[in] bus  - sdbusplus handler
1379f630d9eSRichard Marian Thomaiyar      *  @param[in] path - D-Bus path
1389f630d9eSRichard Marian Thomaiyar      */
139b3ef4e1aSPatrick Williams     UserMgr(sdbusplus::bus_t& bus, const char* path);
1409f630d9eSRichard Marian Thomaiyar 
1419f630d9eSRichard Marian Thomaiyar     /** @brief create user method.
1429f630d9eSRichard Marian Thomaiyar      *  This method creates a new user as requested
1439f630d9eSRichard Marian Thomaiyar      *
1449f630d9eSRichard Marian Thomaiyar      *  @param[in] userName - Name of the user which has to be created
1459f630d9eSRichard Marian Thomaiyar      *  @param[in] groupNames - Group names list, to which user has to be added.
1469f630d9eSRichard Marian Thomaiyar      *  @param[in] priv - Privilege of the user.
1479f630d9eSRichard Marian Thomaiyar      *  @param[in] enabled - State of the user enabled / disabled.
1489f630d9eSRichard Marian Thomaiyar      */
1499f630d9eSRichard Marian Thomaiyar     void createUser(std::string userName, std::vector<std::string> groupNames,
1509f630d9eSRichard Marian Thomaiyar                     std::string priv, bool enabled) override;
1519f630d9eSRichard Marian Thomaiyar 
1529f630d9eSRichard Marian Thomaiyar     /** @brief rename user method.
1539f630d9eSRichard Marian Thomaiyar      *  This method renames the user as requested
1549f630d9eSRichard Marian Thomaiyar      *
1559f630d9eSRichard Marian Thomaiyar      *  @param[in] userName - current name of the user
1569f630d9eSRichard Marian Thomaiyar      *  @param[in] newUserName - new user name to which it has to be renamed.
1579f630d9eSRichard Marian Thomaiyar      */
1589f630d9eSRichard Marian Thomaiyar     void renameUser(std::string userName, std::string newUserName) override;
1599f630d9eSRichard Marian Thomaiyar 
1609f630d9eSRichard Marian Thomaiyar     /** @brief delete user method.
1619f630d9eSRichard Marian Thomaiyar      *  This method deletes the user as requested
1629f630d9eSRichard Marian Thomaiyar      *
1639f630d9eSRichard Marian Thomaiyar      *  @param[in] userName - Name of the user which has to be deleted
1649f630d9eSRichard Marian Thomaiyar      */
1659f630d9eSRichard Marian Thomaiyar     void deleteUser(std::string userName);
1669f630d9eSRichard Marian Thomaiyar 
1679f630d9eSRichard Marian Thomaiyar     /** @brief Update user groups & privilege.
1689f630d9eSRichard Marian Thomaiyar      *  This method updates user groups & privilege
1699f630d9eSRichard Marian Thomaiyar      *
1709f630d9eSRichard Marian Thomaiyar      *  @param[in] userName - user name, for which update is requested
1719f630d9eSRichard Marian Thomaiyar      *  @param[in] groupName - Group to be updated..
1729f630d9eSRichard Marian Thomaiyar      *  @param[in] priv - Privilege to be updated.
1739f630d9eSRichard Marian Thomaiyar      */
1749f630d9eSRichard Marian Thomaiyar     void updateGroupsAndPriv(const std::string& userName,
175fef63038SNan Zhou                              std::vector<std::string> groups,
1769f630d9eSRichard Marian Thomaiyar                              const std::string& priv);
1779f630d9eSRichard Marian Thomaiyar 
1789f630d9eSRichard Marian Thomaiyar     /** @brief Update user enabled state.
1799f630d9eSRichard Marian Thomaiyar      *  This method enables / disables user
1809f630d9eSRichard Marian Thomaiyar      *
1819f630d9eSRichard Marian Thomaiyar      *  @param[in] userName - user name, for which update is requested
1829f630d9eSRichard Marian Thomaiyar      *  @param[in] enabled - enable / disable the user
1839f630d9eSRichard Marian Thomaiyar      */
1849f630d9eSRichard Marian Thomaiyar     void userEnable(const std::string& userName, bool enabled);
1859f630d9eSRichard Marian Thomaiyar 
186e8edab57SDenis Zlobin     /** @brief get user enabled state
187e8edab57SDenis Zlobin      *  method to get user enabled state.
188e8edab57SDenis Zlobin      *
189e8edab57SDenis Zlobin      *  @param[in] userName - name of the user
190e8edab57SDenis Zlobin      *  @return - user enabled status (true/false)
191e8edab57SDenis Zlobin      */
192e8edab57SDenis Zlobin     virtual bool isUserEnabled(const std::string& userName);
193e8edab57SDenis Zlobin 
1949164fd9bSRichard Marian Thomaiyar     /** @brief update minimum password length requirement
1959164fd9bSRichard Marian Thomaiyar      *
1969164fd9bSRichard Marian Thomaiyar      *  @param[in] val - minimum password length
1979164fd9bSRichard Marian Thomaiyar      *  @return - minimum password length
1989164fd9bSRichard Marian Thomaiyar      */
1999164fd9bSRichard Marian Thomaiyar     uint8_t minPasswordLength(uint8_t val) override;
2009164fd9bSRichard Marian Thomaiyar 
2019164fd9bSRichard Marian Thomaiyar     /** @brief update old password history count
2029164fd9bSRichard Marian Thomaiyar      *
2039164fd9bSRichard Marian Thomaiyar      *  @param[in] val - number of times old passwords has to be avoided
2049164fd9bSRichard Marian Thomaiyar      *  @return - number of times old password has to be avoided
2059164fd9bSRichard Marian Thomaiyar      */
2069164fd9bSRichard Marian Thomaiyar     uint8_t rememberOldPasswordTimes(uint8_t val) override;
2079164fd9bSRichard Marian Thomaiyar 
2089164fd9bSRichard Marian Thomaiyar     /** @brief update maximum number of failed login attempt before locked
2099164fd9bSRichard Marian Thomaiyar      *  out.
2109164fd9bSRichard Marian Thomaiyar      *
2119164fd9bSRichard Marian Thomaiyar      *  @param[in] val - number of allowed attempt
2129164fd9bSRichard Marian Thomaiyar      *  @return - number of allowed attempt
2139164fd9bSRichard Marian Thomaiyar      */
2149164fd9bSRichard Marian Thomaiyar     uint16_t maxLoginAttemptBeforeLockout(uint16_t val) override;
2159164fd9bSRichard Marian Thomaiyar 
2169164fd9bSRichard Marian Thomaiyar     /** @brief update timeout to unlock the account
2179164fd9bSRichard Marian Thomaiyar      *
2189164fd9bSRichard Marian Thomaiyar      *  @param[in] val - value in seconds
2199164fd9bSRichard Marian Thomaiyar      *  @return - value in seconds
2209164fd9bSRichard Marian Thomaiyar      */
2219164fd9bSRichard Marian Thomaiyar     uint32_t accountUnlockTimeout(uint32_t val) override;
2229164fd9bSRichard Marian Thomaiyar 
2232d042d14SJason M. Bills     /** @brief parses the faillock output for locked user status
2242d042d14SJason M. Bills      *
2252d042d14SJason M. Bills      * @param[in] - output from faillock for the user
2262d042d14SJason M. Bills      * @return - true / false indicating user locked / un-locked
2272d042d14SJason M. Bills      **/
22888a82dbcSPatrick Williams     bool parseFaillockForLockout(
22988a82dbcSPatrick Williams         const std::vector<std::string>& faillockOutput);
2302d042d14SJason M. Bills 
231c704519eSRichard Marian Thomaiyar     /** @brief lists user locked state for failed attempt
232c704519eSRichard Marian Thomaiyar      *
233c704519eSRichard Marian Thomaiyar      * @param[in] - user name
234c704519eSRichard Marian Thomaiyar      * @return - true / false indicating user locked / un-locked
235c704519eSRichard Marian Thomaiyar      **/
2368cc44050Sraviteja-b     virtual bool userLockedForFailedAttempt(const std::string& userName);
237c704519eSRichard Marian Thomaiyar 
238c704519eSRichard Marian Thomaiyar     /** @brief lists user locked state for failed attempt
239c704519eSRichard Marian Thomaiyar      *
240c704519eSRichard Marian Thomaiyar      * @param[in]: user name
241c704519eSRichard Marian Thomaiyar      * @param[in]: value - false -unlock user account, true - no action taken
242c704519eSRichard Marian Thomaiyar      **/
243c704519eSRichard Marian Thomaiyar     bool userLockedForFailedAttempt(const std::string& userName,
244c704519eSRichard Marian Thomaiyar                                     const bool& value);
245c704519eSRichard Marian Thomaiyar 
2463ab6cc28SJoseph Reynolds     /** @brief shows if the user's password is expired
2473ab6cc28SJoseph Reynolds      *
2483ab6cc28SJoseph Reynolds      * @param[in]: user name
2493ab6cc28SJoseph Reynolds      * @return - true / false indicating user password expired
2503ab6cc28SJoseph Reynolds      **/
2513ab6cc28SJoseph Reynolds     virtual bool userPasswordExpired(const std::string& userName);
2523ab6cc28SJoseph Reynolds 
253aeaf9413SRatan Gupta     /** @brief returns user info
254aeaf9413SRatan Gupta      * Checks if user is local user, then returns map of properties of user.
255aeaf9413SRatan Gupta      * like user privilege, list of user groups, user enabled state and user
256aeaf9413SRatan Gupta      * locked state. If its not local user, then it checks if its a ldap user,
257aeaf9413SRatan Gupta      * then it gets the privilege mapping of the LDAP group.
258aeaf9413SRatan Gupta      *
259aeaf9413SRatan Gupta      * @param[in] - user name
260aeaf9413SRatan Gupta      * @return -  map of user properties
261aeaf9413SRatan Gupta      **/
262aeaf9413SRatan Gupta     UserInfoMap getUserInfo(std::string userName) override;
263aeaf9413SRatan Gupta 
26449c81364SNan Zhou     /** @brief get IPMI user count
26549c81364SNan Zhou      *  method to get IPMI user count
26649c81364SNan Zhou      *
26749c81364SNan Zhou      * @return - returns user count
26849c81364SNan Zhou      */
26949c81364SNan Zhou     virtual size_t getIpmiUsersCount(void);
27049c81364SNan Zhou 
271da401fe5SNan Zhou     void createGroup(std::string groupName) override;
272da401fe5SNan Zhou 
273da401fe5SNan Zhou     void deleteGroup(std::string groupName) override;
enabled() const274*0e427be8SAbhilash Raju 
275*0e427be8SAbhilash Raju     phosphor::user::Users* getUserObject(const std::string& userName)
276*0e427be8SAbhilash Raju     {
277*0e427be8SAbhilash Raju         return usersList[userName].get();
278*0e427be8SAbhilash Raju     }
279*0e427be8SAbhilash Raju 
280a1a754c2SAbhilash Raju     MultiFactorAuthType enabled() const override
281a1a754c2SAbhilash Raju     {
282a1a754c2SAbhilash Raju         return MultiFactorAuthConfigurationIface::enabled();
getSerializer()283a1a754c2SAbhilash Raju     }
284a1a754c2SAbhilash Raju     MultiFactorAuthType enabled(MultiFactorAuthType value,
285a1a754c2SAbhilash Raju                                 bool skipSignal) override;
286a1a754c2SAbhilash Raju     bool secretKeyRequired(std::string userName) override;
287da401fe5SNan Zhou     static std::vector<std::string> readAllGroupsOnSystem();
28893804ebaSAbhilash Raju     void load();
28993804ebaSAbhilash Raju     JsonSerializer& getSerializer()
29093804ebaSAbhilash Raju     {
29193804ebaSAbhilash Raju         return serializer;
29293804ebaSAbhilash Raju     }
293da401fe5SNan Zhou 
294e48085dbSNan Zhou   protected:
295e48085dbSNan Zhou     /** @brief get pam argument value
296e48085dbSNan Zhou      *  method to get argument value from pam configuration
297e48085dbSNan Zhou      *
298e48085dbSNan Zhou      *  @param[in] moduleName - name of the module from where arg has to be read
299e48085dbSNan Zhou      *  @param[in] argName - argument name
300e48085dbSNan Zhou      *  @param[out] argValue - argument value
301e48085dbSNan Zhou      *
302e48085dbSNan Zhou      *  @return 0 - success state of the function
303e48085dbSNan Zhou      */
304e48085dbSNan Zhou     int getPamModuleArgValue(const std::string& moduleName,
305e48085dbSNan Zhou                              const std::string& argName, std::string& argValue);
306e48085dbSNan Zhou 
3072d042d14SJason M. Bills     /** @brief get pam argument value
3082d042d14SJason M. Bills      *  method to get argument value from pam configuration
3092d042d14SJason M. Bills      *
3102d042d14SJason M. Bills      *  @param[in] confFile - path of the module config file from where arg has
3112d042d14SJason M. Bills      * to be read
3122d042d14SJason M. Bills      *  @param[in] argName - argument name
3132d042d14SJason M. Bills      *  @param[out] argValue - argument value
3142d042d14SJason M. Bills      *
3152d042d14SJason M. Bills      *  @return 0 - success state of the function
3162d042d14SJason M. Bills      */
3172d042d14SJason M. Bills     int getPamModuleConfValue(const std::string& confFile,
3182d042d14SJason M. Bills                               const std::string& argName,
3192d042d14SJason M. Bills                               std::string& argValue);
3202d042d14SJason M. Bills 
321e48085dbSNan Zhou     /** @brief set pam argument value
322e48085dbSNan Zhou      *  method to set argument value in pam configuration
323e48085dbSNan Zhou      *
324e48085dbSNan Zhou      *  @param[in] moduleName - name of the module in which argument value has
325e48085dbSNan Zhou      * to be set
326e48085dbSNan Zhou      *  @param[in] argName - argument name
327e48085dbSNan Zhou      *  @param[out] argValue - argument value
328e48085dbSNan Zhou      *
329e48085dbSNan Zhou      *  @return 0 - success state of the function
330e48085dbSNan Zhou      */
331e48085dbSNan Zhou     int setPamModuleArgValue(const std::string& moduleName,
332e48085dbSNan Zhou                              const std::string& argName,
333e48085dbSNan Zhou                              const std::string& argValue);
334e48085dbSNan Zhou 
3352d042d14SJason M. Bills     /** @brief set pam argument value
3362d042d14SJason M. Bills      *  method to set argument value in pam configuration
3372d042d14SJason M. Bills      *
3382d042d14SJason M. Bills      *  @param[in] confFile - path of the module config file in which argument
3392d042d14SJason M. Bills      * value has to be set
3402d042d14SJason M. Bills      *  @param[in] argName - argument name
3412d042d14SJason M. Bills      *  @param[out] argValue - argument value
3422d042d14SJason M. Bills      *
3432d042d14SJason M. Bills      *  @return 0 - success state of the function
3442d042d14SJason M. Bills      */
3452d042d14SJason M. Bills     int setPamModuleConfValue(const std::string& confFile,
3462d042d14SJason M. Bills                               const std::string& argName,
3472d042d14SJason M. Bills                               const std::string& argValue);
3482d042d14SJason M. Bills 
3498a11d998SNan Zhou     /** @brief check for user presence
3508a11d998SNan Zhou      *  method to check for user existence
3518a11d998SNan Zhou      *
3528a11d998SNan Zhou      *  @param[in] userName - name of the user
3538a11d998SNan Zhou      *  @return -true if user exists and false if not.
3548a11d998SNan Zhou      */
3558a11d998SNan Zhou     bool isUserExist(const std::string& userName);
3568a11d998SNan Zhou 
35749c81364SNan Zhou     size_t getNonIpmiUsersCount();
35849c81364SNan Zhou 
3598a11d998SNan Zhou     /** @brief check user exists
3608a11d998SNan Zhou      *  method to check whether user exist, and throw if not.
3618a11d998SNan Zhou      *
3628a11d998SNan Zhou      *  @param[in] userName - name of the user
3638a11d998SNan Zhou      */
3648a11d998SNan Zhou     void throwForUserDoesNotExist(const std::string& userName);
3658a11d998SNan Zhou 
3668a11d998SNan Zhou     /** @brief check user does not exist
3678a11d998SNan Zhou      *  method to check whether does not exist, and throw if exists.
3688a11d998SNan Zhou      *
3698a11d998SNan Zhou      *  @param[in] userName - name of the user
3708a11d998SNan Zhou      */
3718a11d998SNan Zhou     void throwForUserExists(const std::string& userName);
3728a11d998SNan Zhou 
37340e44979SNan Zhou     /** @brief check user name constraints
37440e44979SNan Zhou      *  method to check user name constraints and throw if failed.
37540e44979SNan Zhou      *
37640e44979SNan Zhou      *  @param[in] userName - name of the user
37740e44979SNan Zhou      *  @param[in] groupNames - user groups
37840e44979SNan Zhou      */
37988a82dbcSPatrick Williams     void throwForUserNameConstraints(
38088a82dbcSPatrick Williams         const std::string& userName,
38140e44979SNan Zhou         const std::vector<std::string>& groupNames);
38240e44979SNan Zhou 
38349c81364SNan Zhou     /** @brief check group user count
38449c81364SNan Zhou      *  method to check max group user count, and throw if limit reached
38549c81364SNan Zhou      *
38649c81364SNan Zhou      *  @param[in] groupNames - group name
38749c81364SNan Zhou      */
38849c81364SNan Zhou     void throwForMaxGrpUserCount(const std::vector<std::string>& groupNames);
38949c81364SNan Zhou 
39049c81364SNan Zhou     virtual void executeUserAdd(const char* userName, const char* groups,
39149c81364SNan Zhou                                 bool sshRequested, bool enabled);
39249c81364SNan Zhou 
39349c81364SNan Zhou     virtual void executeUserDelete(const char* userName);
39449c81364SNan Zhou 
395ac921a5eSJayanth Othayoth     /** @brief clear user's failure records
396ac921a5eSJayanth Othayoth      *  method to clear user fail records and throw if failed.
397ac921a5eSJayanth Othayoth      *
398ac921a5eSJayanth Othayoth      *  @param[in] userName - name of the user
399ac921a5eSJayanth Othayoth      */
400ac921a5eSJayanth Othayoth     virtual void executeUserClearFailRecords(const char* userName);
401ac921a5eSJayanth Othayoth 
402f25443e8SNan Zhou     virtual void executeUserRename(const char* userName,
403f25443e8SNan Zhou                                    const char* newUserName);
404f25443e8SNan Zhou 
405fef63038SNan Zhou     virtual void executeUserModify(const char* userName, const char* newGroups,
406fef63038SNan Zhou                                    bool sshRequested);
407fef63038SNan Zhou 
4086b6f2d80SNan Zhou     virtual void executeUserModifyUserEnable(const char* userName,
4096b6f2d80SNan Zhou                                              bool enabled);
4106b6f2d80SNan Zhou 
411da401fe5SNan Zhou     virtual void executeGroupCreation(const char* groupName);
41286040c22SNan Zhou 
413da401fe5SNan Zhou     virtual void executeGroupDeletion(const char* groupName);
41486040c22SNan Zhou 
415a295303bSNan Zhou     virtual std::vector<std::string> getFailedAttempt(const char* userName);
416a295303bSNan Zhou 
417589aeb44SNan Zhou     /** @brief check for valid privielge
418589aeb44SNan Zhou      *  method to check valid privilege, and throw if invalid
419589aeb44SNan Zhou      *
420589aeb44SNan Zhou      *  @param[in] priv - privilege of the user
421589aeb44SNan Zhou      */
422589aeb44SNan Zhou     void throwForInvalidPrivilege(const std::string& priv);
423589aeb44SNan Zhou 
424ecf88768SNan Zhou     /** @brief check for valid groups
425ecf88768SNan Zhou      *  method to check valid groups, and throw if invalid
426ecf88768SNan Zhou      *
427ecf88768SNan Zhou      *  @param[in] groupNames - user groups
428ecf88768SNan Zhou      */
429ecf88768SNan Zhou     void throwForInvalidGroups(const std::vector<std::string>& groupName);
430ecf88768SNan Zhou 
4314bc69810SNan Zhou     void initializeAccountPolicy();
4324bc69810SNan Zhou 
433da401fe5SNan Zhou     /** @brief checks if the group creation meets all constraints
434da401fe5SNan Zhou      * @param groupName - group to check
435da401fe5SNan Zhou      */
436da401fe5SNan Zhou     void checkCreateGroupConstraints(const std::string& groupName);
437da401fe5SNan Zhou 
438da401fe5SNan Zhou     /** @brief checks if the group deletion meets all constraints
439da401fe5SNan Zhou      * @param groupName - group to check
440da401fe5SNan Zhou      */
441da401fe5SNan Zhou     void checkDeleteGroupConstraints(const std::string& groupName);
442da401fe5SNan Zhou 
443da401fe5SNan Zhou     /** @brief checks if the group name is legal and whether it's allowed to
444da401fe5SNan Zhou      * change. The daemon doesn't allow arbitrary group to be created
445da401fe5SNan Zhou      * @param groupName - group to check
446da401fe5SNan Zhou      */
447da401fe5SNan Zhou     void checkAndThrowForDisallowedGroupCreation(const std::string& groupName);
448da401fe5SNan Zhou 
4499f630d9eSRichard Marian Thomaiyar   private:
4509f630d9eSRichard Marian Thomaiyar     /** @brief sdbusplus handler */
451b3ef4e1aSPatrick Williams     sdbusplus::bus_t& bus;
4529f630d9eSRichard Marian Thomaiyar 
4539f630d9eSRichard Marian Thomaiyar     /** @brief object path */
4549f630d9eSRichard Marian Thomaiyar     const std::string path;
4559f630d9eSRichard Marian Thomaiyar 
45693804ebaSAbhilash Raju     /** @brief serializer for mfa */
45793804ebaSAbhilash Raju     JsonSerializer serializer;
4589f630d9eSRichard Marian Thomaiyar     /** @brief privilege manager container */
459da401fe5SNan Zhou     const std::vector<std::string> privMgr = {"priv-admin", "priv-operator",
4605c892d18SAsmitha Karunanithi                                               "priv-user"};
4619f630d9eSRichard Marian Thomaiyar 
4629f630d9eSRichard Marian Thomaiyar     /** @brief groups manager container */
463da401fe5SNan Zhou     std::vector<std::string> groupsMgr;
4649f630d9eSRichard Marian Thomaiyar 
4659f630d9eSRichard Marian Thomaiyar     /** @brief map container to hold users object */
46693804ebaSAbhilash Raju 
46793804ebaSAbhilash Raju     std::unordered_map<std::string, std::unique_ptr<phosphor::user::Users>>
4689f630d9eSRichard Marian Thomaiyar         usersList;
4699f630d9eSRichard Marian Thomaiyar 
4709f630d9eSRichard Marian Thomaiyar     /** @brief get users in group
4719f630d9eSRichard Marian Thomaiyar      *  method to get group user list
4729f630d9eSRichard Marian Thomaiyar      *
4739f630d9eSRichard Marian Thomaiyar      *  @param[in] groupName - group name
4749f630d9eSRichard Marian Thomaiyar      *
4759f630d9eSRichard Marian Thomaiyar      *  @return userList  - list of users in the group.
4769f630d9eSRichard Marian Thomaiyar      */
4779f630d9eSRichard Marian Thomaiyar     std::vector<std::string> getUsersInGroup(const std::string& groupName);
4789f630d9eSRichard Marian Thomaiyar 
4799f630d9eSRichard Marian Thomaiyar     /** @brief get user & SSH users list
4809f630d9eSRichard Marian Thomaiyar      *  method to get the users and ssh users list.
4819f630d9eSRichard Marian Thomaiyar      *
4829f630d9eSRichard Marian Thomaiyar      *@return - vector of User & SSH user lists
4839f630d9eSRichard Marian Thomaiyar      */
4849f630d9eSRichard Marian Thomaiyar     UserSSHLists getUserAndSshGrpList(void);
4859f630d9eSRichard Marian Thomaiyar 
4869f630d9eSRichard Marian Thomaiyar     /** @brief initialize the user manager objects
4879f630d9eSRichard Marian Thomaiyar      *  method to initialize the user manager objects accordingly
4889f630d9eSRichard Marian Thomaiyar      *
4899f630d9eSRichard Marian Thomaiyar      */
4909f630d9eSRichard Marian Thomaiyar     void initUserObjects(void);
4919f630d9eSRichard Marian Thomaiyar 
492aeaf9413SRatan Gupta     /** @brief get service name
493aeaf9413SRatan Gupta      *  method to get dbus service name
494aeaf9413SRatan Gupta      *
495aeaf9413SRatan Gupta      *  @param[in] path - object path
496aeaf9413SRatan Gupta      *  @param[in] intf - interface
497aeaf9413SRatan Gupta      *  @return - service name
498aeaf9413SRatan Gupta      */
499aeaf9413SRatan Gupta     std::string getServiceName(std::string&& path, std::string&& intf);
500aeaf9413SRatan Gupta 
5017562658eSAlexander Filippov     /** @brief get primary group ID of specified user
502aeaf9413SRatan Gupta      *
503aeaf9413SRatan Gupta      * @param[in] - userName
5047562658eSAlexander Filippov      * @return - primary group ID
505aeaf9413SRatan Gupta      */
5067562658eSAlexander Filippov     virtual gid_t getPrimaryGroup(const std::string& userName) const;
507aeaf9413SRatan Gupta 
5087562658eSAlexander Filippov     /** @brief check whether if the user is a member of the group
5097562658eSAlexander Filippov      *
5107562658eSAlexander Filippov      * @param[in] - userName
5117562658eSAlexander Filippov      * @param[in] - ID of the user's primary group
5127562658eSAlexander Filippov      * @param[in] - groupName
5137562658eSAlexander Filippov      * @return - true if the user is a member of the group
5147562658eSAlexander Filippov      */
5157562658eSAlexander Filippov     virtual bool isGroupMember(const std::string& userName, gid_t primaryGid,
5167562658eSAlexander Filippov                                const std::string& groupName) const;
5177562658eSAlexander Filippov 
5187562658eSAlexander Filippov   protected:
519aeaf9413SRatan Gupta     /** @brief get privilege mapper object
520aeaf9413SRatan Gupta      *  method to get dbus privilege mapper object
521aeaf9413SRatan Gupta      *
522aeaf9413SRatan Gupta      *  @return - map of user object
523aeaf9413SRatan Gupta      */
5248cc44050Sraviteja-b     virtual DbusUserObj getPrivilegeMapperObject(void);
5258cc44050Sraviteja-b 
5268cc44050Sraviteja-b     friend class TestUserMgr;
527e48085dbSNan Zhou 
5282d042d14SJason M. Bills     std::string faillockConfigFile;
5293b280ec7SJason M. Bills     std::string pwHistoryConfigFile;
5302d042d14SJason M. Bills     std::string pwQualityConfigFile;
5319f630d9eSRichard Marian Thomaiyar };
5329f630d9eSRichard Marian Thomaiyar 
5339f630d9eSRichard Marian Thomaiyar } // namespace user
5349f630d9eSRichard Marian Thomaiyar } // namespace phosphor
535