blob: df04dc5bf11b2bf882e2076266b035ab92aed8a0 [file] [log] [blame]
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +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
17#include "user_layer.hpp"
18
19#include "passwd_mgr.hpp"
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053020#include "user_mgmt.hpp"
21
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +053022namespace
23{
24ipmi::PasswdMgr passwdMgr;
25}
26
27namespace ipmi
28{
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053029
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000030Cc ipmiUserInit()
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053031{
32 getUserAccessObject();
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000033 return ccSuccess;
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053034}
35
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +053036std::string ipmiUserGetPassword(const std::string& userName)
37{
38 return passwdMgr.getPasswdByUserName(userName);
39}
40
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000041Cc ipmiClearUserEntryPassword(const std::string& userName)
AppaRao Pulib29b5ab2018-05-17 10:28:48 +053042{
Richard Marian Thomaiyar42bed642018-09-21 12:28:57 +053043 if (passwdMgr.updateUserEntry(userName, "") != 0)
44 {
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000045 return ccUnspecifiedError;
Richard Marian Thomaiyar42bed642018-09-21 12:28:57 +053046 }
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000047 return ccSuccess;
Richard Marian Thomaiyar42bed642018-09-21 12:28:57 +053048}
49
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000050Cc ipmiRenameUserEntryPassword(const std::string& userName,
51 const std::string& newUserName)
Richard Marian Thomaiyar42bed642018-09-21 12:28:57 +053052{
53 if (passwdMgr.updateUserEntry(userName, newUserName) != 0)
54 {
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000055 return ccUnspecifiedError;
Richard Marian Thomaiyar42bed642018-09-21 12:28:57 +053056 }
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000057 return ccSuccess;
AppaRao Pulib29b5ab2018-05-17 10:28:48 +053058}
59
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053060bool ipmiUserIsValidUserId(const uint8_t userId)
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053061{
62 return UserAccess::isValidUserId(userId);
63}
64
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053065bool ipmiUserIsValidPrivilege(const uint8_t priv)
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053066{
67 return UserAccess::isValidPrivilege(priv);
68}
69
70uint8_t ipmiUserGetUserId(const std::string& userName)
71{
72 return getUserAccessObject().getUserId(userName);
73}
74
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000075Cc ipmiUserSetUserName(const uint8_t userId, const char* userName)
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053076{
jayaprakash Mutyala76363302020-02-14 23:50:38 +000077 std::string newUser(userName, 0, ipmiMaxUserName);
78 return getUserAccessObject().setUserName(userId, newUser);
79}
80
81Cc ipmiUserSetUserName(const uint8_t userId, const std::string& userName)
82{
83 std::string newUser(userName, 0, ipmiMaxUserName);
84 return getUserAccessObject().setUserName(userId, newUser);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053085}
86
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000087Cc ipmiUserGetUserName(const uint8_t userId, std::string& userName)
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053088{
89 return getUserAccessObject().getUserName(userId, userName);
90}
91
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000092Cc ipmiUserSetUserPassword(const uint8_t userId, const char* userPassword)
Suryakanth Sekar90b00c72019-01-16 10:37:57 +053093{
94 return getUserAccessObject().setUserPassword(userId, userPassword);
95}
96
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000097Cc ipmiSetSpecialUserPassword(const std::string& userName,
98 const std::string& userPassword)
Richard Marian Thomaiyar788362c2019-04-14 15:12:47 +053099{
100 return getUserAccessObject().setSpecialUserPassword(userName, userPassword);
101}
102
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000103Cc ipmiUserGetAllCounts(uint8_t& maxChUsers, uint8_t& enabledUsers,
104 uint8_t& fixedUsers)
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530105{
106 maxChUsers = ipmiMaxUsers;
107 UsersTbl* userData = getUserAccessObject().getUsersTblPtr();
108 enabledUsers = 0;
109 fixedUsers = 0;
110 // user index 0 is reserved, starts with 1
111 for (size_t count = 1; count <= ipmiMaxUsers; ++count)
112 {
113 if (userData->user[count].userEnabled)
114 {
115 enabledUsers++;
116 }
117 if (userData->user[count].fixedUserName)
118 {
119 fixedUsers++;
120 }
121 }
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000122 return ccSuccess;
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530123}
124
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000125Cc ipmiUserUpdateEnabledState(const uint8_t userId, const bool& state)
Richard Marian Thomaiyar282e79b2018-11-13 19:00:58 +0530126{
127 return getUserAccessObject().setUserEnabledState(userId, state);
128}
129
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000130Cc ipmiUserCheckEnabled(const uint8_t userId, bool& state)
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530131{
132 if (!UserAccess::isValidUserId(userId))
133 {
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000134 return ccParmOutOfRange;
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530135 }
136 UserInfo* userInfo = getUserAccessObject().getUserInfo(userId);
137 state = userInfo->userEnabled;
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000138 return ccSuccess;
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530139}
140
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000141Cc ipmiUserGetPrivilegeAccess(const uint8_t userId, const uint8_t chNum,
142 PrivAccess& privAccess)
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530143{
144
145 if (!UserAccess::isValidChannel(chNum))
146 {
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000147 return ccInvalidFieldRequest;
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530148 }
149 if (!UserAccess::isValidUserId(userId))
150 {
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000151 return ccParmOutOfRange;
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530152 }
153 UserInfo* userInfo = getUserAccessObject().getUserInfo(userId);
154 privAccess.privilege = userInfo->userPrivAccess[chNum].privilege;
155 privAccess.ipmiEnabled = userInfo->userPrivAccess[chNum].ipmiEnabled;
156 privAccess.linkAuthEnabled =
157 userInfo->userPrivAccess[chNum].linkAuthEnabled;
158 privAccess.accessCallback = userInfo->userPrivAccess[chNum].accessCallback;
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000159 return ccSuccess;
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530160}
161
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000162Cc ipmiUserSetPrivilegeAccess(const uint8_t userId, const uint8_t chNum,
163 const PrivAccess& privAccess,
164 const bool& otherPrivUpdates)
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530165{
166 UserPrivAccess userPrivAccess;
167 userPrivAccess.privilege = privAccess.privilege;
168 if (otherPrivUpdates)
169 {
170 userPrivAccess.ipmiEnabled = privAccess.ipmiEnabled;
171 userPrivAccess.linkAuthEnabled = privAccess.linkAuthEnabled;
172 userPrivAccess.accessCallback = privAccess.accessCallback;
173 }
174 return getUserAccessObject().setUserPrivilegeAccess(
175 userId, chNum, userPrivAccess, otherPrivUpdates);
176}
177
Ayushi Smriti02650d52019-05-15 11:59:09 +0000178bool ipmiUserPamAuthenticate(std::string_view userName,
179 std::string_view userPassword)
180{
181 return pamUserCheckAuthenticate(userName, userPassword);
182}
183
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000184Cc ipmiUserSetUserPayloadAccess(const uint8_t chNum, const uint8_t operation,
185 const uint8_t userId,
186 const PayloadAccess& payloadAccess)
Saravanan Palanisamy77381f12019-05-15 22:33:17 +0000187{
188
189 if (!UserAccess::isValidChannel(chNum))
190 {
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000191 return ccInvalidFieldRequest;
Saravanan Palanisamy77381f12019-05-15 22:33:17 +0000192 }
193 if (!UserAccess::isValidUserId(userId))
194 {
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000195 return ccParmOutOfRange;
Saravanan Palanisamy77381f12019-05-15 22:33:17 +0000196 }
197
198 return getUserAccessObject().setUserPayloadAccess(chNum, operation, userId,
199 payloadAccess);
200}
201
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000202Cc ipmiUserGetUserPayloadAccess(const uint8_t chNum, const uint8_t userId,
203 PayloadAccess& payloadAccess)
Saravanan Palanisamy77381f12019-05-15 22:33:17 +0000204{
205
206 if (!UserAccess::isValidChannel(chNum))
207 {
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000208 return ccInvalidFieldRequest;
Saravanan Palanisamy77381f12019-05-15 22:33:17 +0000209 }
210 if (!UserAccess::isValidUserId(userId))
211 {
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000212 return ccParmOutOfRange;
Saravanan Palanisamy77381f12019-05-15 22:33:17 +0000213 }
214
215 UserInfo* userInfo = getUserAccessObject().getUserInfo(userId);
216
217 payloadAccess.stdPayloadEnables1 =
218 userInfo->payloadAccess[chNum].stdPayloadEnables1;
219 payloadAccess.stdPayloadEnables2Reserved =
220 userInfo->payloadAccess[chNum].stdPayloadEnables2Reserved;
221 payloadAccess.oemPayloadEnables1 =
222 userInfo->payloadAccess[chNum].oemPayloadEnables1;
223 payloadAccess.oemPayloadEnables2Reserved =
224 userInfo->payloadAccess[chNum].oemPayloadEnables2Reserved;
225
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000226 return ccSuccess;
Saravanan Palanisamy77381f12019-05-15 22:33:17 +0000227}
228
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +0530229} // namespace ipmi