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 |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 17 | #include <sdbusplus/bus.hpp> |
| 18 | #include <sdbusplus/server/object.hpp> |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 19 | #include <xyz/openbmc_project/Object/Delete/server.hpp> |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 20 | #include <xyz/openbmc_project/User/Attributes/server.hpp> |
Abhilash Raju | a1a754c | 2024-07-25 05:43:40 -0500 | [diff] [blame^] | 21 | #include <xyz/openbmc_project/User/MultiFactorAuthConfiguration/server.hpp> |
| 22 | #include <xyz/openbmc_project/User/TOTPAuthenticator/server.hpp> |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 23 | namespace phosphor |
| 24 | { |
| 25 | namespace user |
| 26 | { |
| 27 | |
| 28 | namespace Base = sdbusplus::xyz::openbmc_project; |
Ratan Gupta | 1af1223 | 2018-11-03 00:35:38 +0530 | [diff] [blame] | 29 | using UsersIface = Base::User::server::Attributes; |
Abhilash Raju | a1a754c | 2024-07-25 05:43:40 -0500 | [diff] [blame^] | 30 | |
| 31 | using TOTPAuthenticatorIface = Base::User::server::TOTPAuthenticator; |
Ratan Gupta | 1af1223 | 2018-11-03 00:35:38 +0530 | [diff] [blame] | 32 | using DeleteIface = Base::Object::server::Delete; |
Abhilash Raju | a1a754c | 2024-07-25 05:43:40 -0500 | [diff] [blame^] | 33 | using Interfaces = sdbusplus::server::object_t<UsersIface, DeleteIface, |
| 34 | TOTPAuthenticatorIface>; |
| 35 | using MultiFactorAuthType = sdbusplus::common::xyz::openbmc_project::user:: |
| 36 | MultiFactorAuthConfiguration::Type; |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 37 | // Place where all user objects has to be created |
| 38 | constexpr auto usersObjPath = "/xyz/openbmc_project/user"; |
| 39 | |
| 40 | class UserMgr; // Forward declaration for UserMgr. |
| 41 | |
| 42 | /** @class Users |
| 43 | * @brief Lists User objects and it's properties |
| 44 | */ |
Ratan Gupta | 1af1223 | 2018-11-03 00:35:38 +0530 | [diff] [blame] | 45 | class Users : public Interfaces |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 46 | { |
| 47 | public: |
| 48 | Users() = delete; |
| 49 | ~Users() = default; |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 50 | Users(const Users&) = delete; |
| 51 | Users& operator=(const Users&) = delete; |
| 52 | Users(Users&&) = delete; |
| 53 | Users& operator=(Users&&) = delete; |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 54 | |
| 55 | /** @brief Constructs UserMgr object. |
| 56 | * |
| 57 | * @param[in] bus - sdbusplus handler |
| 58 | * @param[in] path - D-Bus path |
| 59 | * @param[in] groups - users group list |
| 60 | * @param[in] priv - users privilege |
| 61 | * @param[in] enabled - user enabled state |
| 62 | * @param[in] parent - user manager - parent object |
| 63 | */ |
Patrick Williams | b3ef4e1 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 64 | Users(sdbusplus::bus_t& bus, const char* path, |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 65 | std::vector<std::string> groups, std::string priv, bool enabled, |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 66 | UserMgr& parent); |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 67 | |
| 68 | /** @brief delete user method. |
| 69 | * This method deletes the user as requested |
| 70 | * |
| 71 | */ |
| 72 | void delete_(void) override; |
| 73 | |
| 74 | /** @brief update user privilege |
| 75 | * |
| 76 | * @param[in] value - User privilege |
| 77 | */ |
| 78 | std::string userPrivilege(std::string value) override; |
| 79 | |
Nan Zhou | fef6303 | 2022-10-25 00:07:12 +0000 | [diff] [blame] | 80 | void setUserPrivilege(const std::string& value); |
| 81 | |
| 82 | void setUserGroups(const std::vector<std::string>& groups); |
| 83 | |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 84 | /** @brief lists user privilege |
| 85 | * |
| 86 | */ |
| 87 | std::string userPrivilege(void) const override; |
| 88 | |
| 89 | /** @brief update user groups |
| 90 | * |
| 91 | * @param[in] value - User groups |
| 92 | */ |
Patrick Williams | 88a82db | 2025-02-01 08:22:37 -0500 | [diff] [blame] | 93 | std::vector<std::string> userGroups( |
| 94 | std::vector<std::string> value) override; |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 95 | |
| 96 | /** @brief list user groups |
| 97 | * |
| 98 | */ |
| 99 | std::vector<std::string> userGroups(void) const override; |
| 100 | |
| 101 | /** @brief lists user enabled state |
| 102 | * |
| 103 | */ |
| 104 | bool userEnabled(void) const override; |
| 105 | |
Nan Zhou | 6b6f2d8 | 2022-10-25 00:07:17 +0000 | [diff] [blame] | 106 | void setUserEnabled(bool value); |
| 107 | |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 108 | /** @brief update user enabled state |
| 109 | * |
| 110 | * @param[in] value - bool value |
| 111 | */ |
| 112 | bool userEnabled(bool value) override; |
| 113 | |
Richard Marian Thomaiyar | c704519 | 2018-06-13 16:51:00 +0530 | [diff] [blame] | 114 | /** @brief lists user locked state for failed attempt |
| 115 | * |
| 116 | **/ |
| 117 | bool userLockedForFailedAttempt(void) const override; |
| 118 | |
| 119 | /** @brief unlock user locked state for failed attempt |
| 120 | * |
| 121 | * @param[in]: value - false - unlock user account, true - no action taken |
| 122 | **/ |
| 123 | bool userLockedForFailedAttempt(bool value) override; |
| 124 | |
Joseph Reynolds | 3ab6cc2 | 2020-03-03 14:09:03 -0600 | [diff] [blame] | 125 | /** @brief indicates if the user's password is expired |
| 126 | * |
| 127 | **/ |
Nan Zhou | f3fb77c | 2022-08-29 17:51:59 +0000 | [diff] [blame] | 128 | bool userPasswordExpired(void) const override; |
Joseph Reynolds | 3ab6cc2 | 2020-03-03 14:09:03 -0600 | [diff] [blame] | 129 | |
Abhilash Raju | a1a754c | 2024-07-25 05:43:40 -0500 | [diff] [blame^] | 130 | std::string getUserName() const |
| 131 | { |
| 132 | return userName; |
| 133 | } |
| 134 | bool secretKeyIsValid() const override; |
| 135 | std::string createSecretKey() override; |
| 136 | bool verifyOTP(std::string otp) override; |
| 137 | bool secretKeyGenerationRequired() const override; |
| 138 | void clearSecretKey() override; |
| 139 | MultiFactorAuthType bypassedProtocol(MultiFactorAuthType value, |
| 140 | bool skipSignal) override; |
| 141 | void enableMultiFactorAuth(MultiFactorAuthType type, bool value); |
| 142 | |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 143 | private: |
Abhilash Raju | a1a754c | 2024-07-25 05:43:40 -0500 | [diff] [blame^] | 144 | bool checkMfaStatus() const; |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 145 | std::string userName; |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 146 | UserMgr& manager; |
Richard Marian Thomaiyar | 9f630d9 | 2018-05-24 10:49:10 +0530 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | } // namespace user |
| 150 | } // namespace phosphor |