blob: b241564810749c32103d0ef0b96ef87068a9349a [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
30ipmi_ret_t ipmiUserInit()
31{
32 getUserAccessObject();
33 return IPMI_CC_OK;
34}
35
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +053036std::string ipmiUserGetPassword(const std::string& userName)
37{
38 return passwdMgr.getPasswdByUserName(userName);
39}
40
Richard Marian Thomaiyar42bed642018-09-21 12:28:57 +053041ipmi_ret_t 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 {
45 return IPMI_CC_UNSPECIFIED_ERROR;
46 }
47 return IPMI_CC_OK;
48}
49
50ipmi_ret_t ipmiRenameUserEntryPassword(const std::string& userName,
51 const std::string& newUserName)
52{
53 if (passwdMgr.updateUserEntry(userName, newUserName) != 0)
54 {
55 return IPMI_CC_UNSPECIFIED_ERROR;
56 }
AppaRao Pulib29b5ab2018-05-17 10:28:48 +053057 return IPMI_CC_OK;
58}
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
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053075ipmi_ret_t ipmiUserSetUserName(const uint8_t userId, const char* userName)
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053076{
77 return getUserAccessObject().setUserName(userId, userName);
78}
79
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053080ipmi_ret_t ipmiUserGetUserName(const uint8_t userId, std::string& userName)
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053081{
82 return getUserAccessObject().getUserName(userId, userName);
83}
84
Suryakanth Sekar90b00c72019-01-16 10:37:57 +053085ipmi_ret_t ipmiUserSetUserPassword(const uint8_t userId,
86 const char* userPassword)
87{
88 return getUserAccessObject().setUserPassword(userId, userPassword);
89}
90
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053091ipmi_ret_t ipmiUserGetAllCounts(uint8_t& maxChUsers, uint8_t& enabledUsers,
92 uint8_t& fixedUsers)
93{
94 maxChUsers = ipmiMaxUsers;
95 UsersTbl* userData = getUserAccessObject().getUsersTblPtr();
96 enabledUsers = 0;
97 fixedUsers = 0;
98 // user index 0 is reserved, starts with 1
99 for (size_t count = 1; count <= ipmiMaxUsers; ++count)
100 {
101 if (userData->user[count].userEnabled)
102 {
103 enabledUsers++;
104 }
105 if (userData->user[count].fixedUserName)
106 {
107 fixedUsers++;
108 }
109 }
110 return IPMI_CC_OK;
111}
112
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530113ipmi_ret_t ipmiUserUpdateEnabledState(const uint8_t userId, const bool& state)
Richard Marian Thomaiyar282e79b2018-11-13 19:00:58 +0530114{
115 return getUserAccessObject().setUserEnabledState(userId, state);
116}
117
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530118ipmi_ret_t ipmiUserCheckEnabled(const uint8_t userId, bool& state)
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530119{
120 if (!UserAccess::isValidUserId(userId))
121 {
122 return IPMI_CC_PARM_OUT_OF_RANGE;
123 }
124 UserInfo* userInfo = getUserAccessObject().getUserInfo(userId);
125 state = userInfo->userEnabled;
126 return IPMI_CC_OK;
127}
128
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530129ipmi_ret_t ipmiUserGetPrivilegeAccess(const uint8_t userId, const uint8_t chNum,
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530130 PrivAccess& privAccess)
131{
132
133 if (!UserAccess::isValidChannel(chNum))
134 {
135 return IPMI_CC_INVALID_FIELD_REQUEST;
136 }
137 if (!UserAccess::isValidUserId(userId))
138 {
139 return IPMI_CC_PARM_OUT_OF_RANGE;
140 }
141 UserInfo* userInfo = getUserAccessObject().getUserInfo(userId);
142 privAccess.privilege = userInfo->userPrivAccess[chNum].privilege;
143 privAccess.ipmiEnabled = userInfo->userPrivAccess[chNum].ipmiEnabled;
144 privAccess.linkAuthEnabled =
145 userInfo->userPrivAccess[chNum].linkAuthEnabled;
146 privAccess.accessCallback = userInfo->userPrivAccess[chNum].accessCallback;
147
148 return IPMI_CC_OK;
149}
150
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530151ipmi_ret_t ipmiUserSetPrivilegeAccess(const uint8_t userId, const uint8_t chNum,
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530152 const PrivAccess& privAccess,
153 const bool& otherPrivUpdates)
154{
155 UserPrivAccess userPrivAccess;
156 userPrivAccess.privilege = privAccess.privilege;
157 if (otherPrivUpdates)
158 {
159 userPrivAccess.ipmiEnabled = privAccess.ipmiEnabled;
160 userPrivAccess.linkAuthEnabled = privAccess.linkAuthEnabled;
161 userPrivAccess.accessCallback = privAccess.accessCallback;
162 }
163 return getUserAccessObject().setUserPrivilegeAccess(
164 userId, chNum, userPrivAccess, otherPrivUpdates);
165}
166
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +0530167} // namespace ipmi