-
Notifications
You must be signed in to change notification settings - Fork 12
/
users.cpp
183 lines (161 loc) · 4.44 KB
/
users.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
// Copyright (c) 2018 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#include "config.h"
#include "users.hpp"
#include "user_mgr.hpp"
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/User/Common/error.hpp>
#include <filesystem>
namespace phosphor
{
namespace user
{
using namespace phosphor::logging;
using InsufficientPermission =
sdbusplus::xyz::openbmc_project::Common::Error::InsufficientPermission;
using InternalFailure =
sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
using InvalidArgument =
sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
using NoResource =
sdbusplus::xyz::openbmc_project::User::Common::Error::NoResource;
using Argument = xyz::openbmc_project::Common::InvalidArgument;
/** @brief Constructs UserMgr object.
*
* @param[in] bus - sdbusplus handler
* @param[in] path - D-Bus path
* @param[in] groups - users group list
* @param[in] priv - user privilege
* @param[in] enabled - user enabled state
* @param[in] parent - user manager - parent object
*/
Users::Users(sdbusplus::bus::bus& bus, const char* path,
std::vector<std::string> groups, std::string priv, bool enabled,
UserMgr& parent) :
Interfaces(bus, path, Interfaces::action::defer_emit),
userName(std::filesystem::path(path).filename()), manager(parent)
{
UsersIface::userPrivilege(priv, true);
UsersIface::userGroups(groups, true);
UsersIface::userEnabled(enabled, true);
this->emit_object_added();
}
/** @brief delete user method.
* This method deletes the user as requested
*
*/
void Users::delete_(void)
{
manager.deleteUser(userName);
}
/** @brief update user privilege
*
* @param[in] value - User privilege
*/
std::string Users::userPrivilege(std::string value)
{
if (value == UsersIface::userPrivilege())
{
return value;
}
manager.updateGroupsAndPriv(userName, UsersIface::userGroups(), value);
return UsersIface::userPrivilege(value);
}
/** @brief list user privilege
*
*/
std::string Users::userPrivilege(void) const
{
return UsersIface::userPrivilege();
}
/** @brief update user groups
*
* @param[in] value - User groups
*/
std::vector<std::string> Users::userGroups(std::vector<std::string> value)
{
if (value == UsersIface::userGroups())
{
return value;
}
std::sort(value.begin(), value.end());
manager.updateGroupsAndPriv(userName, value, UsersIface::userPrivilege());
return UsersIface::userGroups(value);
}
/** @brief list user groups
*
*/
std::vector<std::string> Users::userGroups(void) const
{
return UsersIface::userGroups();
}
/** @brief lists user enabled state
*
*/
bool Users::userEnabled(void) const
{
return UsersIface::userEnabled();
}
/** @brief update user enabled state
*
* @param[in] value - bool value
*/
bool Users::userEnabled(bool value)
{
if (value == UsersIface::userEnabled())
{
return value;
}
manager.userEnable(userName, value);
return UsersIface::userEnabled(value);
}
/** @brief lists user locked state for failed attempt
*
**/
bool Users::userLockedForFailedAttempt(void) const
{
return manager.userLockedForFailedAttempt(userName);
}
/** @brief unlock user locked state for failed attempt
*
* @param[in]: value - false - unlock user account, true - no action taken
**/
bool Users::userLockedForFailedAttempt(bool value)
{
if (value != false)
{
return userLockedForFailedAttempt();
}
else
{
return manager.userLockedForFailedAttempt(userName, value);
}
}
/** @brief indicates if the user's password is expired
*
**/
bool Users::userPasswordExpired(void) const
{
return manager.userPasswordExpired(userName);
}
} // namespace user
} // namespace phosphor