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