blob: 0f3065e89f74490b0022c887ce93532db5029938 [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>
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053021
22namespace phosphor
23{
24namespace user
25{
26
27namespace Base = sdbusplus::xyz::openbmc_project;
Ratan Gupta1af12232018-11-03 00:35:38 +053028using UsersIface = Base::User::server::Attributes;
29using DeleteIface = Base::Object::server::Delete;
Patrick Williamsb3ef4e12022-07-22 19:26:55 -050030using Interfaces = sdbusplus::server::object_t<UsersIface, DeleteIface>;
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053031// Place where all user objects has to be created
32constexpr auto usersObjPath = "/xyz/openbmc_project/user";
33
34class UserMgr; // Forward declaration for UserMgr.
35
36/** @class Users
37 * @brief Lists User objects and it's properties
38 */
Ratan Gupta1af12232018-11-03 00:35:38 +053039class Users : public Interfaces
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053040{
41 public:
42 Users() = delete;
43 ~Users() = default;
Patrick Williams9638afb2021-02-22 17:16:24 -060044 Users(const Users&) = delete;
45 Users& operator=(const Users&) = delete;
46 Users(Users&&) = delete;
47 Users& operator=(Users&&) = delete;
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053048
49 /** @brief Constructs UserMgr object.
50 *
51 * @param[in] bus - sdbusplus handler
52 * @param[in] path - D-Bus path
53 * @param[in] groups - users group list
54 * @param[in] priv - users privilege
55 * @param[in] enabled - user enabled state
56 * @param[in] parent - user manager - parent object
57 */
Patrick Williamsb3ef4e12022-07-22 19:26:55 -050058 Users(sdbusplus::bus_t& bus, const char* path,
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053059 std::vector<std::string> groups, std::string priv, bool enabled,
Patrick Williams9638afb2021-02-22 17:16:24 -060060 UserMgr& parent);
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053061
62 /** @brief delete user method.
63 * This method deletes the user as requested
64 *
65 */
66 void delete_(void) override;
67
68 /** @brief update user privilege
69 *
70 * @param[in] value - User privilege
71 */
72 std::string userPrivilege(std::string value) override;
73
Nan Zhoufef63032022-10-25 00:07:12 +000074 void setUserPrivilege(const std::string& value);
75
76 void setUserGroups(const std::vector<std::string>& groups);
77
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053078 /** @brief lists user privilege
79 *
80 */
81 std::string userPrivilege(void) const override;
82
83 /** @brief update user groups
84 *
85 * @param[in] value - User groups
86 */
87 std::vector<std::string>
88 userGroups(std::vector<std::string> value) override;
89
90 /** @brief list user groups
91 *
92 */
93 std::vector<std::string> userGroups(void) const override;
94
95 /** @brief lists user enabled state
96 *
97 */
98 bool userEnabled(void) const override;
99
Nan Zhou6b6f2d82022-10-25 00:07:17 +0000100 void setUserEnabled(bool value);
101
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +0530102 /** @brief update user enabled state
103 *
104 * @param[in] value - bool value
105 */
106 bool userEnabled(bool value) override;
107
Richard Marian Thomaiyarc7045192018-06-13 16:51:00 +0530108 /** @brief lists user locked state for failed attempt
109 *
110 **/
111 bool userLockedForFailedAttempt(void) const override;
112
113 /** @brief unlock user locked state for failed attempt
114 *
115 * @param[in]: value - false - unlock user account, true - no action taken
116 **/
117 bool userLockedForFailedAttempt(bool value) override;
118
Joseph Reynolds3ab6cc22020-03-03 14:09:03 -0600119 /** @brief indicates if the user's password is expired
120 *
121 **/
Nan Zhouf3fb77c2022-08-29 17:51:59 +0000122 bool userPasswordExpired(void) const override;
Joseph Reynolds3ab6cc22020-03-03 14:09:03 -0600123
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +0530124 private:
125 std::string userName;
Patrick Williams9638afb2021-02-22 17:16:24 -0600126 UserMgr& manager;
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +0530127};
128
129} // namespace user
130} // namespace phosphor