blob: a5ff131b65d6b11c2830f6cd46c3aa7b9faef6ed [file] [log] [blame]
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +05301/*
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 Thomaiyar9f630d92018-05-24 10:49:10 +053017#include <sdbusplus/bus.hpp>
18#include <sdbusplus/server/object.hpp>
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053019#include <xyz/openbmc_project/Object/Delete/server.hpp>
Patrick Williams9638afb2021-02-22 17:16:24 -060020#include <xyz/openbmc_project/User/Attributes/server.hpp>
Abhilash Rajua1a754c2024-07-25 05:43:40 -050021#include <xyz/openbmc_project/User/MultiFactorAuthConfiguration/server.hpp>
22#include <xyz/openbmc_project/User/TOTPAuthenticator/server.hpp>
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053023namespace phosphor
24{
25namespace user
26{
27
28namespace Base = sdbusplus::xyz::openbmc_project;
Ratan Gupta1af12232018-11-03 00:35:38 +053029using UsersIface = Base::User::server::Attributes;
Abhilash Rajua1a754c2024-07-25 05:43:40 -050030
31using TOTPAuthenticatorIface = Base::User::server::TOTPAuthenticator;
Ratan Gupta1af12232018-11-03 00:35:38 +053032using DeleteIface = Base::Object::server::Delete;
Abhilash Rajua1a754c2024-07-25 05:43:40 -050033using Interfaces = sdbusplus::server::object_t<UsersIface, DeleteIface,
34 TOTPAuthenticatorIface>;
35using MultiFactorAuthType = sdbusplus::common::xyz::openbmc_project::user::
36 MultiFactorAuthConfiguration::Type;
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053037// Place where all user objects has to be created
38constexpr auto usersObjPath = "/xyz/openbmc_project/user";
39
40class UserMgr; // Forward declaration for UserMgr.
41
42/** @class Users
43 * @brief Lists User objects and it's properties
44 */
Ratan Gupta1af12232018-11-03 00:35:38 +053045class Users : public Interfaces
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053046{
47 public:
48 Users() = delete;
49 ~Users() = default;
Patrick Williams9638afb2021-02-22 17:16:24 -060050 Users(const Users&) = delete;
51 Users& operator=(const Users&) = delete;
52 Users(Users&&) = delete;
53 Users& operator=(Users&&) = delete;
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053054
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 Williamsb3ef4e12022-07-22 19:26:55 -050064 Users(sdbusplus::bus_t& bus, const char* path,
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053065 std::vector<std::string> groups, std::string priv, bool enabled,
Patrick Williams9638afb2021-02-22 17:16:24 -060066 UserMgr& parent);
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053067
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 Zhoufef63032022-10-25 00:07:12 +000080 void setUserPrivilege(const std::string& value);
81
82 void setUserGroups(const std::vector<std::string>& groups);
83
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053084 /** @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 Williams88a82db2025-02-01 08:22:37 -050093 std::vector<std::string> userGroups(
94 std::vector<std::string> value) override;
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053095
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 Zhou6b6f2d82022-10-25 00:07:17 +0000106 void setUserEnabled(bool value);
107
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +0530108 /** @brief update user enabled state
109 *
110 * @param[in] value - bool value
111 */
112 bool userEnabled(bool value) override;
113
Richard Marian Thomaiyarc7045192018-06-13 16:51:00 +0530114 /** @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 Reynolds3ab6cc22020-03-03 14:09:03 -0600125 /** @brief indicates if the user's password is expired
126 *
127 **/
Nan Zhouf3fb77c2022-08-29 17:51:59 +0000128 bool userPasswordExpired(void) const override;
Joseph Reynolds3ab6cc22020-03-03 14:09:03 -0600129
Abhilash Rajua1a754c2024-07-25 05:43:40 -0500130 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 Thomaiyar9f630d92018-05-24 10:49:10 +0530143 private:
Abhilash Rajua1a754c2024-07-25 05:43:40 -0500144 bool checkMfaStatus() const;
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +0530145 std::string userName;
Patrick Williams9638afb2021-02-22 17:16:24 -0600146 UserMgr& manager;
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +0530147};
148
149} // namespace user
150} // namespace phosphor