xref: /openbmc/phosphor-host-ipmid/user_channel/user_mgmt.hpp (revision fbc6c9d743d22682f3753841071b8460ad50b5d9)
161024d7dSSnehalatha Venkatesh /*.
25a6b6369SRichard Marian Thomaiyar // Copyright (c) 2018 Intel Corporation
35a6b6369SRichard Marian Thomaiyar //
45a6b6369SRichard Marian Thomaiyar // Licensed under the Apache License, Version 2.0 (the "License");
55a6b6369SRichard Marian Thomaiyar // you may not use this file except in compliance with the License.
65a6b6369SRichard Marian Thomaiyar // You may obtain a copy of the License at
75a6b6369SRichard Marian Thomaiyar //
85a6b6369SRichard Marian Thomaiyar //      http://www.apache.org/licenses/LICENSE-2.0
95a6b6369SRichard Marian Thomaiyar //
105a6b6369SRichard Marian Thomaiyar // Unless required by applicable law or agreed to in writing, software
115a6b6369SRichard Marian Thomaiyar // distributed under the License is distributed on an "AS IS" BASIS,
125a6b6369SRichard Marian Thomaiyar // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135a6b6369SRichard Marian Thomaiyar // See the License for the specific language governing permissions and
145a6b6369SRichard Marian Thomaiyar // limitations under the License.
155a6b6369SRichard Marian Thomaiyar */
165a6b6369SRichard Marian Thomaiyar #pragma once
175a6b6369SRichard Marian Thomaiyar #include "user_layer.hpp"
185a6b6369SRichard Marian Thomaiyar 
195a6b6369SRichard Marian Thomaiyar #include <boost/interprocess/sync/file_lock.hpp>
205a6b6369SRichard Marian Thomaiyar #include <boost/interprocess/sync/named_recursive_mutex.hpp>
219fc5fa18Sjayaprakash Mutyala #include <ipmid/api.hpp>
225a6b6369SRichard Marian Thomaiyar #include <sdbusplus/bus.hpp>
23*fbc6c9d7SPatrick Williams 
24*fbc6c9d7SPatrick Williams #include <cstdint>
25*fbc6c9d7SPatrick Williams #include <ctime>
2616b8693dSVernon Mauery #include <variant>
275a6b6369SRichard Marian Thomaiyar 
285a6b6369SRichard Marian Thomaiyar namespace ipmi
295a6b6369SRichard Marian Thomaiyar {
305a6b6369SRichard Marian Thomaiyar 
315a6b6369SRichard Marian Thomaiyar using DbusUserPropVariant =
3216b8693dSVernon Mauery     std::variant<std::vector<std::string>, std::string, bool>;
335a6b6369SRichard Marian Thomaiyar 
345a6b6369SRichard Marian Thomaiyar using DbusUserObjPath = sdbusplus::message::object_path;
355a6b6369SRichard Marian Thomaiyar 
365a6b6369SRichard Marian Thomaiyar using DbusUserObjProperties =
375a6b6369SRichard Marian Thomaiyar     std::vector<std::pair<std::string, DbusUserPropVariant>>;
385a6b6369SRichard Marian Thomaiyar 
395a6b6369SRichard Marian Thomaiyar using DbusUserObjValue = std::map<std::string, DbusUserObjProperties>;
405a6b6369SRichard Marian Thomaiyar 
416e1ba9efSRichard Marian Thomaiyar /**
426e1ba9efSRichard Marian Thomaiyar  * @enum User update events.
436e1ba9efSRichard Marian Thomaiyar  */
445a6b6369SRichard Marian Thomaiyar enum class UserUpdateEvent
455a6b6369SRichard Marian Thomaiyar {
465a6b6369SRichard Marian Thomaiyar     reservedEvent,
475a6b6369SRichard Marian Thomaiyar     userCreated,
485a6b6369SRichard Marian Thomaiyar     userDeleted,
495a6b6369SRichard Marian Thomaiyar     userRenamed,
505a6b6369SRichard Marian Thomaiyar     userGrpUpdated,
515a6b6369SRichard Marian Thomaiyar     userPrivUpdated,
525a6b6369SRichard Marian Thomaiyar     userStateUpdated
535a6b6369SRichard Marian Thomaiyar };
545a6b6369SRichard Marian Thomaiyar 
556e1ba9efSRichard Marian Thomaiyar /** @struct UserPrivAccess
566e1ba9efSRichard Marian Thomaiyar  *
576e1ba9efSRichard Marian Thomaiyar  *  Structure for user privilege access (refer spec sec 22.22)
586e1ba9efSRichard Marian Thomaiyar  */
595a6b6369SRichard Marian Thomaiyar struct UserPrivAccess
605a6b6369SRichard Marian Thomaiyar {
615a6b6369SRichard Marian Thomaiyar     uint8_t privilege;
625a6b6369SRichard Marian Thomaiyar     bool ipmiEnabled;
635a6b6369SRichard Marian Thomaiyar     bool linkAuthEnabled;
645a6b6369SRichard Marian Thomaiyar     bool accessCallback;
655a6b6369SRichard Marian Thomaiyar };
665a6b6369SRichard Marian Thomaiyar 
676e1ba9efSRichard Marian Thomaiyar /** @struct UserInfo
686e1ba9efSRichard Marian Thomaiyar  *
696e1ba9efSRichard Marian Thomaiyar  *  Structure for user related information
706e1ba9efSRichard Marian Thomaiyar  */
715a6b6369SRichard Marian Thomaiyar struct UserInfo
725a6b6369SRichard Marian Thomaiyar {
735a6b6369SRichard Marian Thomaiyar     uint8_t userName[ipmiMaxUserName];
745a6b6369SRichard Marian Thomaiyar     UserPrivAccess userPrivAccess[ipmiMaxChannels];
755a6b6369SRichard Marian Thomaiyar     bool userEnabled;
765a6b6369SRichard Marian Thomaiyar     bool userInSystem;
775a6b6369SRichard Marian Thomaiyar     bool fixedUserName;
7877381f15SSaravanan Palanisamy     PayloadAccess payloadAccess[ipmiMaxChannels];
795a6b6369SRichard Marian Thomaiyar };
805a6b6369SRichard Marian Thomaiyar 
816e1ba9efSRichard Marian Thomaiyar /** @struct UsersTbl
826e1ba9efSRichard Marian Thomaiyar  *
836e1ba9efSRichard Marian Thomaiyar  *  Structure for array of user related information
846e1ba9efSRichard Marian Thomaiyar  */
855a6b6369SRichard Marian Thomaiyar struct UsersTbl
865a6b6369SRichard Marian Thomaiyar {
875a6b6369SRichard Marian Thomaiyar     //+1 to map with UserId directly. UserId 0 is reserved.
885a6b6369SRichard Marian Thomaiyar     UserInfo user[ipmiMaxUsers + 1];
895a6b6369SRichard Marian Thomaiyar };
905a6b6369SRichard Marian Thomaiyar 
9102650d53SAyushi Smriti /** @brief PAM User Authentication check
9202650d53SAyushi Smriti  *
9302650d53SAyushi Smriti  *  @param[in] username - username in string
9402650d53SAyushi Smriti  *  @param[in] password	- password in string
9502650d53SAyushi Smriti  *
9602650d53SAyushi Smriti  *  @return status
9702650d53SAyushi Smriti  */
9802650d53SAyushi Smriti bool pamUserCheckAuthenticate(std::string_view username,
9902650d53SAyushi Smriti                               std::string_view password);
10002650d53SAyushi Smriti 
1015a6b6369SRichard Marian Thomaiyar class UserAccess;
1025a6b6369SRichard Marian Thomaiyar 
1035a6b6369SRichard Marian Thomaiyar UserAccess& getUserAccessObject();
1045a6b6369SRichard Marian Thomaiyar 
1055a6b6369SRichard Marian Thomaiyar class UserAccess
1065a6b6369SRichard Marian Thomaiyar {
1075a6b6369SRichard Marian Thomaiyar   public:
1085a6b6369SRichard Marian Thomaiyar     UserAccess(const UserAccess&) = delete;
1095a6b6369SRichard Marian Thomaiyar     UserAccess& operator=(const UserAccess&) = delete;
1105a6b6369SRichard Marian Thomaiyar     UserAccess(UserAccess&&) = delete;
1115a6b6369SRichard Marian Thomaiyar     UserAccess& operator=(UserAccess&&) = delete;
1125a6b6369SRichard Marian Thomaiyar 
1135a6b6369SRichard Marian Thomaiyar     ~UserAccess();
1145a6b6369SRichard Marian Thomaiyar     UserAccess();
1155a6b6369SRichard Marian Thomaiyar 
1165a6b6369SRichard Marian Thomaiyar     /** @brief determines valid channel
1175a6b6369SRichard Marian Thomaiyar      *
1185a6b6369SRichard Marian Thomaiyar      *  @param[in] chNum - channel number
1195a6b6369SRichard Marian Thomaiyar      *
1205a6b6369SRichard Marian Thomaiyar      *  @return true if valid, false otherwise
1215a6b6369SRichard Marian Thomaiyar      */
122a45cb34fSRichard Marian Thomaiyar     static bool isValidChannel(const uint8_t chNum);
1235a6b6369SRichard Marian Thomaiyar 
1245a6b6369SRichard Marian Thomaiyar     /** @brief determines valid userId
1255a6b6369SRichard Marian Thomaiyar      *
1265a6b6369SRichard Marian Thomaiyar      *  @param[in] userId - user id
1275a6b6369SRichard Marian Thomaiyar      *
1285a6b6369SRichard Marian Thomaiyar      *  @return true if valid, false otherwise
1295a6b6369SRichard Marian Thomaiyar      */
130a45cb34fSRichard Marian Thomaiyar     static bool isValidUserId(const uint8_t userId);
1315a6b6369SRichard Marian Thomaiyar 
1325a6b6369SRichard Marian Thomaiyar     /** @brief determines valid user privilege
1335a6b6369SRichard Marian Thomaiyar      *
1345a6b6369SRichard Marian Thomaiyar      *  @param[in] priv - Privilege
1355a6b6369SRichard Marian Thomaiyar      *
1365a6b6369SRichard Marian Thomaiyar      *  @return true if valid, false otherwise
1375a6b6369SRichard Marian Thomaiyar      */
138a45cb34fSRichard Marian Thomaiyar     static bool isValidPrivilege(const uint8_t priv);
1395a6b6369SRichard Marian Thomaiyar 
1405a6b6369SRichard Marian Thomaiyar     /** @brief determines sync index to be mapped with common-user-management
1415a6b6369SRichard Marian Thomaiyar      *
1425a6b6369SRichard Marian Thomaiyar      *  @return Index which will be used as sync index
1435a6b6369SRichard Marian Thomaiyar      */
1445a6b6369SRichard Marian Thomaiyar     static uint8_t getUsrMgmtSyncIndex();
1455a6b6369SRichard Marian Thomaiyar 
1465a6b6369SRichard Marian Thomaiyar     /** @brief Converts system privilege to IPMI privilege
1475a6b6369SRichard Marian Thomaiyar      *
1485a6b6369SRichard Marian Thomaiyar      *  @param[in] value - Privilege in string
1495a6b6369SRichard Marian Thomaiyar      *
1505a6b6369SRichard Marian Thomaiyar      *  @return CommandPrivilege - IPMI privilege type
1515a6b6369SRichard Marian Thomaiyar      */
1525a6b6369SRichard Marian Thomaiyar     static CommandPrivilege convertToIPMIPrivilege(const std::string& value);
1535a6b6369SRichard Marian Thomaiyar 
1545a6b6369SRichard Marian Thomaiyar     /** @brief Converts IPMI privilege to system privilege
1555a6b6369SRichard Marian Thomaiyar      *
1565a6b6369SRichard Marian Thomaiyar      *  @param[in] value - IPMI privilege
1575a6b6369SRichard Marian Thomaiyar      *
1585a6b6369SRichard Marian Thomaiyar      *  @return System privilege in string
1595a6b6369SRichard Marian Thomaiyar      */
1605a6b6369SRichard Marian Thomaiyar     static std::string convertToSystemPrivilege(const CommandPrivilege& value);
1615a6b6369SRichard Marian Thomaiyar 
1625a6b6369SRichard Marian Thomaiyar     /** @brief determines whether user name is valid
1635a6b6369SRichard Marian Thomaiyar      *
1645a6b6369SRichard Marian Thomaiyar      *  @param[in] userNameInChar - user name
1655a6b6369SRichard Marian Thomaiyar      *
1665a6b6369SRichard Marian Thomaiyar      *  @return true if valid, false otherwise
1675a6b6369SRichard Marian Thomaiyar      */
16876363302Sjayaprakash Mutyala     bool isValidUserName(const std::string& userName);
1695a6b6369SRichard Marian Thomaiyar 
170489a4ed9SRichard Marian Thomaiyar     /** @brief determines whether ipmi is in available groups list
171489a4ed9SRichard Marian Thomaiyar      *
172489a4ed9SRichard Marian Thomaiyar      * @return true if ipmi group is present, false otherwise
173489a4ed9SRichard Marian Thomaiyar      */
174489a4ed9SRichard Marian Thomaiyar     bool isIpmiInAvailableGroupList();
175489a4ed9SRichard Marian Thomaiyar 
1765a6b6369SRichard Marian Thomaiyar     /** @brief provides user id of the user
1775a6b6369SRichard Marian Thomaiyar      *
1785a6b6369SRichard Marian Thomaiyar      *  @param[in] userName - user name
1795a6b6369SRichard Marian Thomaiyar      *
1805a6b6369SRichard Marian Thomaiyar      *  @return user id of the user, else invalid user id (0xFF), if user not
1815a6b6369SRichard Marian Thomaiyar      * found
1825a6b6369SRichard Marian Thomaiyar      */
1835a6b6369SRichard Marian Thomaiyar     uint8_t getUserId(const std::string& userName);
1845a6b6369SRichard Marian Thomaiyar 
1855a6b6369SRichard Marian Thomaiyar     /** @brief provides user information
1865a6b6369SRichard Marian Thomaiyar      *
1875a6b6369SRichard Marian Thomaiyar      *  @param[in] userId - user id
1885a6b6369SRichard Marian Thomaiyar      *
1895a6b6369SRichard Marian Thomaiyar      *  @return UserInfo for the specified user id
1905a6b6369SRichard Marian Thomaiyar      */
191a45cb34fSRichard Marian Thomaiyar     UserInfo* getUserInfo(const uint8_t userId);
1925a6b6369SRichard Marian Thomaiyar 
1935a6b6369SRichard Marian Thomaiyar     /** @brief sets user information
1945a6b6369SRichard Marian Thomaiyar      *
1955a6b6369SRichard Marian Thomaiyar      *  @param[in] userId - user id
1965a6b6369SRichard Marian Thomaiyar      *  @param[in] userInfo - user information
1975a6b6369SRichard Marian Thomaiyar      *
1985a6b6369SRichard Marian Thomaiyar      */
199a45cb34fSRichard Marian Thomaiyar     void setUserInfo(const uint8_t userId, UserInfo* userInfo);
2005a6b6369SRichard Marian Thomaiyar 
2015a6b6369SRichard Marian Thomaiyar     /** @brief provides user name
2025a6b6369SRichard Marian Thomaiyar      *
2035a6b6369SRichard Marian Thomaiyar      *  @param[in] userId - user id
2045a6b6369SRichard Marian Thomaiyar      *  @param[out] userName - user name
2055a6b6369SRichard Marian Thomaiyar      *
206b541a5a5SNITIN SHARMA      *  @return ccSuccess for success, others for failure.
2075a6b6369SRichard Marian Thomaiyar      */
208b541a5a5SNITIN SHARMA     Cc getUserName(const uint8_t userId, std::string& userName);
2095a6b6369SRichard Marian Thomaiyar 
2105a6b6369SRichard Marian Thomaiyar     /** @brief to set user name
2115a6b6369SRichard Marian Thomaiyar      *
2125a6b6369SRichard Marian Thomaiyar      *  @param[in] userId - user id
213b541a5a5SNITIN SHARMA      *  @param[in] userName - user name
2145a6b6369SRichard Marian Thomaiyar      *
215b541a5a5SNITIN SHARMA      *  @return ccSuccess for success, others for failure.
2165a6b6369SRichard Marian Thomaiyar      */
21776363302Sjayaprakash Mutyala     Cc setUserName(const uint8_t userId, const std::string& userName);
2185a6b6369SRichard Marian Thomaiyar 
219282e79b4SRichard Marian Thomaiyar     /** @brief to set user enabled state
220282e79b4SRichard Marian Thomaiyar      *
221282e79b4SRichard Marian Thomaiyar      *  @param[in] userId - user id
222282e79b4SRichard Marian Thomaiyar      *  @param[in] enabledState - enabled state of the user
223282e79b4SRichard Marian Thomaiyar      *
224b541a5a5SNITIN SHARMA      *  @return ccSuccess for success, others for failure.
225282e79b4SRichard Marian Thomaiyar      */
226b541a5a5SNITIN SHARMA     Cc setUserEnabledState(const uint8_t userId, const bool& enabledState);
227282e79b4SRichard Marian Thomaiyar 
22890b00c71SSuryakanth Sekar     /** @brief to set user password
22990b00c71SSuryakanth Sekar      *
23090b00c71SSuryakanth Sekar      *  @param[in] userId - user id
23190b00c71SSuryakanth Sekar      *  @param[in] userPassword  - new password of the user
23290b00c71SSuryakanth Sekar      *
233b541a5a5SNITIN SHARMA      *  @return ccSuccess for success, others for failure.
23490b00c71SSuryakanth Sekar      */
235b541a5a5SNITIN SHARMA     Cc setUserPassword(const uint8_t userId, const char* userPassword);
23690b00c71SSuryakanth Sekar 
237788362ceSRichard Marian Thomaiyar     /** @brief to set special user password
238788362ceSRichard Marian Thomaiyar      *
239788362ceSRichard Marian Thomaiyar      *  @param[in] userName - user name
240788362ceSRichard Marian Thomaiyar      *  @param[in] userPassword  - new password of the user
241788362ceSRichard Marian Thomaiyar      *
242b541a5a5SNITIN SHARMA      *  @return ccSuccess for success, others for failure.
243788362ceSRichard Marian Thomaiyar      */
244b541a5a5SNITIN SHARMA     Cc setSpecialUserPassword(const std::string& userName,
2451e22a0f1SVernon Mauery                               const SecureString& userPassword);
246788362ceSRichard Marian Thomaiyar 
2475a6b6369SRichard Marian Thomaiyar     /** @brief to set user privilege and access details
2485a6b6369SRichard Marian Thomaiyar      *
2495a6b6369SRichard Marian Thomaiyar      *  @param[in] userId - user id
2505a6b6369SRichard Marian Thomaiyar      *  @param[in] chNum - channel number
2515a6b6369SRichard Marian Thomaiyar      *  @param[in] privAccess - privilege access
2525a6b6369SRichard Marian Thomaiyar      *  @param[in] otherPrivUpdates - other privilege update flag to update ipmi
2535a6b6369SRichard Marian Thomaiyar      * enable, link authentication and access callback
2545a6b6369SRichard Marian Thomaiyar      *
255b541a5a5SNITIN SHARMA      *  @return ccSuccess for success, others for failure.
2565a6b6369SRichard Marian Thomaiyar      */
257b541a5a5SNITIN SHARMA     Cc setUserPrivilegeAccess(const uint8_t userId, const uint8_t chNum,
2585a6b6369SRichard Marian Thomaiyar                               const UserPrivAccess& privAccess,
2595a6b6369SRichard Marian Thomaiyar                               const bool& otherPrivUpdates);
2605a6b6369SRichard Marian Thomaiyar 
26177381f15SSaravanan Palanisamy     /** @brief to get user payload access details from userInfo entry.
26277381f15SSaravanan Palanisamy      *
26377381f15SSaravanan Palanisamy      *  @param[in] userInfo    - userInfo entry in usersTbl.
26477381f15SSaravanan Palanisamy      *  @param[out] stdPayload - stdPayloadEnables1 in a 2D-array.
26577381f15SSaravanan Palanisamy      *  @param[out] oemPayload - oemPayloadEnables1 in a 2D-array.
26677381f15SSaravanan Palanisamy      *
26777381f15SSaravanan Palanisamy      *  @details Update the given 2D-arrays using the payload access details
26877381f15SSaravanan Palanisamy      *  available in the given userInfo entry (from usersTbl).
26977381f15SSaravanan Palanisamy      *  This 2D-array will be mapped to a JSON object (which will be written to
27077381f15SSaravanan Palanisamy      *  a JSON file subsequently).
27177381f15SSaravanan Palanisamy      */
27277381f15SSaravanan Palanisamy     void readPayloadAccessFromUserInfo(
27377381f15SSaravanan Palanisamy         const UserInfo& userInfo,
27477381f15SSaravanan Palanisamy         std::array<std::array<bool, ipmiMaxChannels>, payloadsPerByte>&
27577381f15SSaravanan Palanisamy             stdPayload,
27677381f15SSaravanan Palanisamy         std::array<std::array<bool, ipmiMaxChannels>, payloadsPerByte>&
27777381f15SSaravanan Palanisamy             oemPayload);
27877381f15SSaravanan Palanisamy 
27977381f15SSaravanan Palanisamy     /** @brief to update user payload access details in userInfo entry.
28077381f15SSaravanan Palanisamy      *
28177381f15SSaravanan Palanisamy      *  @param[in] stdPayload - stdPayloadEnables1 in a 2D-array.
28277381f15SSaravanan Palanisamy      *  @param[in] oemPayload - oemPayloadEnables1 in a 2D-array.
28377381f15SSaravanan Palanisamy      *  @param[out] userInfo  - userInfo entry in usersTbl.
28477381f15SSaravanan Palanisamy      *
28577381f15SSaravanan Palanisamy      *  @details Update user payload access details of a given userInfo
28677381f15SSaravanan Palanisamy      *  entry (in usersTbl) with the information provided in given 2D-arrays.
28777381f15SSaravanan Palanisamy      *  This 2D-array was created out of a JSON object (which was created by
28877381f15SSaravanan Palanisamy      *  parsing a JSON file).
28977381f15SSaravanan Palanisamy      */
29077381f15SSaravanan Palanisamy     void updatePayloadAccessInUserInfo(
29177381f15SSaravanan Palanisamy         const std::array<std::array<bool, ipmiMaxChannels>, payloadsPerByte>&
29277381f15SSaravanan Palanisamy             stdPayload,
29377381f15SSaravanan Palanisamy         const std::array<std::array<bool, ipmiMaxChannels>, payloadsPerByte>&
29477381f15SSaravanan Palanisamy             oemPayload,
29577381f15SSaravanan Palanisamy         UserInfo& userInfo);
29677381f15SSaravanan Palanisamy 
29777381f15SSaravanan Palanisamy     /** @brief to set user payload access details
29877381f15SSaravanan Palanisamy      *
29977381f15SSaravanan Palanisamy      *  @param[in] chNum - channel number
30077381f15SSaravanan Palanisamy      *  @param[in] operation - Enable / Disable
30177381f15SSaravanan Palanisamy      *  @param[in] userId - user id
30277381f15SSaravanan Palanisamy      *  @param[in] payloadAccess - payload access
30377381f15SSaravanan Palanisamy      *
304b541a5a5SNITIN SHARMA      *  @return ccSuccess for success, others for failure.
30577381f15SSaravanan Palanisamy      */
306b541a5a5SNITIN SHARMA     Cc setUserPayloadAccess(const uint8_t chNum, const uint8_t operation,
30777381f15SSaravanan Palanisamy                             const uint8_t userId,
30877381f15SSaravanan Palanisamy                             const PayloadAccess& payloadAccess);
30977381f15SSaravanan Palanisamy 
3105a6b6369SRichard Marian Thomaiyar     /** @brief reads user management related data from configuration file
3115a6b6369SRichard Marian Thomaiyar      *
3125a6b6369SRichard Marian Thomaiyar      */
3135a6b6369SRichard Marian Thomaiyar     void readUserData();
3145a6b6369SRichard Marian Thomaiyar 
3155a6b6369SRichard Marian Thomaiyar     /** @brief writes user management related data to configuration file
3165a6b6369SRichard Marian Thomaiyar      *
3175a6b6369SRichard Marian Thomaiyar      */
3185a6b6369SRichard Marian Thomaiyar     void writeUserData();
3195a6b6369SRichard Marian Thomaiyar 
3205a6b6369SRichard Marian Thomaiyar     /** @brief Funtion which checks and reload configuration file data if
3215a6b6369SRichard Marian Thomaiyar      * needed.
3225a6b6369SRichard Marian Thomaiyar      *
3235a6b6369SRichard Marian Thomaiyar      */
3245a6b6369SRichard Marian Thomaiyar     void checkAndReloadUserData();
3255a6b6369SRichard Marian Thomaiyar 
3265a6b6369SRichard Marian Thomaiyar     /** @brief provides user details from D-Bus user property data
3275a6b6369SRichard Marian Thomaiyar      *
3285a6b6369SRichard Marian Thomaiyar      *  @param[in] properties - D-Bus user property
3295a6b6369SRichard Marian Thomaiyar      *  @param[out] usrGrps - user group details
3305a6b6369SRichard Marian Thomaiyar      *  @param[out] usrPriv - user privilege
3315a6b6369SRichard Marian Thomaiyar      *  @param[out] usrEnabled - enabled state of the user.
3325a6b6369SRichard Marian Thomaiyar      *
3335a6b6369SRichard Marian Thomaiyar      *  @return 0 for success, -errno for failure.
3345a6b6369SRichard Marian Thomaiyar      */
3355a6b6369SRichard Marian Thomaiyar     void getUserProperties(const DbusUserObjProperties& properties,
3365a6b6369SRichard Marian Thomaiyar                            std::vector<std::string>& usrGrps,
3375a6b6369SRichard Marian Thomaiyar                            std::string& usrPriv, bool& usrEnabled);
3385a6b6369SRichard Marian Thomaiyar 
3395a6b6369SRichard Marian Thomaiyar     /** @brief provides user details from D-Bus user object data
3405a6b6369SRichard Marian Thomaiyar      *
3415a6b6369SRichard Marian Thomaiyar      *  @param[in] userObjs - D-Bus user object
3425a6b6369SRichard Marian Thomaiyar      *  @param[out] usrGrps - user group details
3435a6b6369SRichard Marian Thomaiyar      *  @param[out] usrPriv - user privilege
3445a6b6369SRichard Marian Thomaiyar      *  @param[out] usrEnabled - enabled state of the user.
3455a6b6369SRichard Marian Thomaiyar      *
3465a6b6369SRichard Marian Thomaiyar      *  @return 0 for success, -errno for failure.
3475a6b6369SRichard Marian Thomaiyar      */
3485a6b6369SRichard Marian Thomaiyar     int getUserObjProperties(const DbusUserObjValue& userObjs,
3495a6b6369SRichard Marian Thomaiyar                              std::vector<std::string>& usrGrps,
3505a6b6369SRichard Marian Thomaiyar                              std::string& usrPriv, bool& usrEnabled);
3515a6b6369SRichard Marian Thomaiyar 
3525a6b6369SRichard Marian Thomaiyar     /** @brief function to add user entry information to the configuration
3535a6b6369SRichard Marian Thomaiyar      *
3545a6b6369SRichard Marian Thomaiyar      *  @param[in] userName - user name
3555a6b6369SRichard Marian Thomaiyar      *  @param[in] priv - privilege of the user
3565a6b6369SRichard Marian Thomaiyar      *  @param[in] enabled - enabled state of the user
3575a6b6369SRichard Marian Thomaiyar      *
3585a6b6369SRichard Marian Thomaiyar      *  @return true for success, false for failure
3595a6b6369SRichard Marian Thomaiyar      */
3605a6b6369SRichard Marian Thomaiyar     bool addUserEntry(const std::string& userName, const std::string& priv,
3615a6b6369SRichard Marian Thomaiyar                       const bool& enabled);
3625a6b6369SRichard Marian Thomaiyar 
3635a6b6369SRichard Marian Thomaiyar     /** @brief function to delete user entry based on user index
3645a6b6369SRichard Marian Thomaiyar      *
3655a6b6369SRichard Marian Thomaiyar      *  @param[in] usrIdx - user index
3665a6b6369SRichard Marian Thomaiyar      *
3675a6b6369SRichard Marian Thomaiyar      */
3685a6b6369SRichard Marian Thomaiyar     void deleteUserIndex(const size_t& usrIdx);
3695a6b6369SRichard Marian Thomaiyar 
3705a6b6369SRichard Marian Thomaiyar     /** @brief function to get users table
3715a6b6369SRichard Marian Thomaiyar      *
3725a6b6369SRichard Marian Thomaiyar      */
3735a6b6369SRichard Marian Thomaiyar     UsersTbl* getUsersTblPtr();
3745a6b6369SRichard Marian Thomaiyar 
3755a6b6369SRichard Marian Thomaiyar     std::unique_ptr<boost::interprocess::named_recursive_mutex> userMutex{
3765a6b6369SRichard Marian Thomaiyar         nullptr};
3775a6b6369SRichard Marian Thomaiyar 
3785a6b6369SRichard Marian Thomaiyar   private:
3795a6b6369SRichard Marian Thomaiyar     UsersTbl usersTbl;
3805a6b6369SRichard Marian Thomaiyar     std::vector<std::string> availablePrivileges;
3815a6b6369SRichard Marian Thomaiyar     std::vector<std::string> availableGroups;
3825d82f474SPatrick Williams     sdbusplus::bus_t bus;
38308d3d06cSJayaprakash Mutyala     std::timespec fileLastUpdatedTime;
3845a6b6369SRichard Marian Thomaiyar     bool signalHndlrObject = false;
3855a6b6369SRichard Marian Thomaiyar     boost::interprocess::file_lock sigHndlrLock;
3865a6b6369SRichard Marian Thomaiyar     boost::interprocess::file_lock mutexCleanupLock;
3875a6b6369SRichard Marian Thomaiyar 
3885a6b6369SRichard Marian Thomaiyar     /** @brief function to get user configuration file timestamp
3895a6b6369SRichard Marian Thomaiyar      *
3905a6b6369SRichard Marian Thomaiyar      *  @return time stamp or -EIO for failure
3915a6b6369SRichard Marian Thomaiyar      */
39208d3d06cSJayaprakash Mutyala     std::timespec getUpdatedFileTime();
3935a6b6369SRichard Marian Thomaiyar 
3945a6b6369SRichard Marian Thomaiyar     /** @brief function to available system privileges and groups
3955a6b6369SRichard Marian Thomaiyar      *
3965a6b6369SRichard Marian Thomaiyar      */
3975a6b6369SRichard Marian Thomaiyar     void getSystemPrivAndGroups();
3985a6b6369SRichard Marian Thomaiyar 
3995a6b6369SRichard Marian Thomaiyar     /** @brief function to init user data from configuration & D-Bus objects
400bbe728c3Sarun-pm      * and to register for signals
4015a6b6369SRichard Marian Thomaiyar      *
4025a6b6369SRichard Marian Thomaiyar      */
403bbe728c3Sarun-pm     void cacheUserDataFile();
4045a6b6369SRichard Marian Thomaiyar };
40561024d7dSSnehalatha Venkatesh 
4065a6b6369SRichard Marian Thomaiyar } // namespace ipmi
407