blob: 063947438af473ed66d9e40ff8c6ddd9599ec759 [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#pragma once
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +053017
Saravanan Palanisamy77381f12019-05-15 22:33:17 +000018#include <bitset>
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000019#include <ipmid/api.hpp>
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +053020#include <string>
21
22namespace ipmi
23{
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053024
25// TODO: Has to be replaced with proper channel number assignment logic
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053026/**
27 * @enum Channel Id
28 */
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053029enum class EChannelID : uint8_t
30{
31 chanLan1 = 0x01
32};
33
34static constexpr uint8_t invalidUserId = 0xFF;
35static constexpr uint8_t reservedUserId = 0x0;
36static constexpr uint8_t ipmiMaxUserName = 16;
37static constexpr uint8_t ipmiMaxUsers = 15;
38static constexpr uint8_t ipmiMaxChannels = 16;
Suryakanth Sekar90b00c72019-01-16 10:37:57 +053039static constexpr uint8_t maxIpmi20PasswordSize = 20;
40static constexpr uint8_t maxIpmi15PasswordSize = 16;
Saravanan Palanisamy77381f12019-05-15 22:33:17 +000041static constexpr uint8_t payloadsPerByte = 8;
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053042
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053043/** @struct PrivAccess
44 *
45 * User privilege related access data as per IPMI specification.(refer spec
46 * sec 22.26)
47 */
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053048struct PrivAccess
49{
50#if BYTE_ORDER == LITTLE_ENDIAN
51 uint8_t privilege : 4;
52 uint8_t ipmiEnabled : 1;
53 uint8_t linkAuthEnabled : 1;
54 uint8_t accessCallback : 1;
55 uint8_t reserved : 1;
56#endif
57#if BYTE_ORDER == BIG_ENDIAN
58 uint8_t reserved : 1;
59 uint8_t accessCallback : 1;
60 uint8_t linkAuthEnabled : 1;
61 uint8_t ipmiEnabled : 1;
62 uint8_t privilege : 4;
63#endif
64} __attribute__((packed));
65
Saravanan Palanisamy77381f12019-05-15 22:33:17 +000066/** @struct UserPayloadAccess
67 *
68 * Structure to denote payload access restrictions applicable for a
69 * given user and channel. (refer spec sec 24.6)
70 */
71struct PayloadAccess
72{
73 std::bitset<payloadsPerByte> stdPayloadEnables1;
74 std::bitset<payloadsPerByte> stdPayloadEnables2Reserved;
75 std::bitset<payloadsPerByte> oemPayloadEnables1;
76 std::bitset<payloadsPerByte> oemPayloadEnables2Reserved;
77};
78
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053079/** @brief initializes user management
80 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000081 * @return ccSuccess for success, others for failure.
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053082 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000083Cc ipmiUserInit();
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053084
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +053085/** @brief The ipmi get user password layer call
86 *
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053087 * @param[in] userName - user name
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +053088 *
89 * @return password or empty string
90 */
91std::string ipmiUserGetPassword(const std::string& userName);
92
AppaRao Pulib29b5ab2018-05-17 10:28:48 +053093/** @brief The IPMI call to clear password entry associated with specified
94 * username
95 *
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053096 * @param[in] userName - user name to be removed
AppaRao Pulib29b5ab2018-05-17 10:28:48 +053097 *
98 * @return 0 on success, non-zero otherwise.
99 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000100Cc ipmiClearUserEntryPassword(const std::string& userName);
Richard Marian Thomaiyar42bed642018-09-21 12:28:57 +0530101
102/** @brief The IPMI call to reuse password entry for the renamed user
103 * to another one
104 *
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530105 * @param[in] userName - user name which has to be renamed
106 * @param[in] newUserName - new user name
Richard Marian Thomaiyar42bed642018-09-21 12:28:57 +0530107 *
108 * @return 0 on success, non-zero otherwise.
109 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000110Cc ipmiRenameUserEntryPassword(const std::string& userName,
111 const std::string& newUserName);
AppaRao Pulib29b5ab2018-05-17 10:28:48 +0530112
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530113/** @brief determines valid userId
114 *
115 * @param[in] userId - user id
116 *
117 * @return true if valid, false otherwise
118 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530119bool ipmiUserIsValidUserId(const uint8_t userId);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530120
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530121/** @brief determines valid privilege level
122 *
123 * @param[in] priv - privilege level
124 *
125 * @return true if valid, false otherwise
126 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530127bool ipmiUserIsValidPrivilege(const uint8_t priv);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530128
129/** @brief get user id corresponding to the user name
130 *
131 * @param[in] userName - user name
132 *
133 * @return userid. Will return 0xff if no user id found
134 */
135uint8_t ipmiUserGetUserId(const std::string& userName);
136
137/** @brief set's user name
138 *
139 * @param[in] userId - user id
140 * @param[in] userName - user name
141 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000142 * @return ccSuccess for success, others for failure.
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530143 */
jayaprakash Mutyalae0af1c42020-03-24 10:11:31 +0000144Cc ipmiUserSetUserName(const uint8_t userId, const char* userName);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530145
jayaprakash Mutyala76363302020-02-14 23:50:38 +0000146/** @brief set's user name
147 *
148 * @param[in] userId - user id
149 * @param[in] userName - user name
150 *
151 * @return ccSuccess for success, others for failure.
152 */
153Cc ipmiUserSetUserName(const uint8_t userId, const std::string& userName);
154
Suryakanth Sekar90b00c72019-01-16 10:37:57 +0530155/** @brief set user password
156 *
157 * @param[in] userId - user id
158 * @param[in] userPassword - New Password
159 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000160 * @return ccSuccess for success, others for failure.
Suryakanth Sekar90b00c72019-01-16 10:37:57 +0530161 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000162Cc ipmiUserSetUserPassword(const uint8_t userId, const char* userPassword);
Suryakanth Sekar90b00c72019-01-16 10:37:57 +0530163
Richard Marian Thomaiyar788362c2019-04-14 15:12:47 +0530164/** @brief set special user password (non-ipmi accounts)
165 *
166 * @param[in] userName - user name
167 * @param[in] userPassword - New Password
168 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000169 * @return ccSuccess for success, others for failure.
Richard Marian Thomaiyar788362c2019-04-14 15:12:47 +0530170 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000171Cc ipmiSetSpecialUserPassword(const std::string& userName,
172 const std::string& userPassword);
Richard Marian Thomaiyar788362c2019-04-14 15:12:47 +0530173
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530174/** @brief get user name
175 *
176 * @param[in] userId - user id
177 * @param[out] userName - user name
178 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000179 * @return ccSuccess for success, others for failure.
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530180 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000181Cc ipmiUserGetUserName(const uint8_t userId, std::string& userName);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530182
183/** @brief provides available fixed, max, and enabled user counts
184 *
185 * @param[out] maxChUsers - max channel users
186 * @param[out] enabledUsers - enabled user count
187 * @param[out] fixedUsers - fixed user count
188 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000189 * @return ccSuccess for success, others for failure.
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530190 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000191Cc ipmiUserGetAllCounts(uint8_t& maxChUsers, uint8_t& enabledUsers,
192 uint8_t& fixedUsers);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530193
Richard Marian Thomaiyar282e79b2018-11-13 19:00:58 +0530194/** @brief function to update user enabled state
195 *
196 * @param[in] userId - user id
197 *..@param[in] state - state of the user to be updated, true - user enabled.
198 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000199 * @return ccSuccess for success, others for failure.
Richard Marian Thomaiyar282e79b2018-11-13 19:00:58 +0530200 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000201Cc ipmiUserUpdateEnabledState(const uint8_t userId, const bool& state);
Richard Marian Thomaiyar282e79b2018-11-13 19:00:58 +0530202
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530203/** @brief determines whether user is enabled
204 *
205 * @param[in] userId - user id
206 *..@param[out] state - state of the user
207 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000208 * @return ccSuccess for success, others for failure.
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530209 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000210Cc ipmiUserCheckEnabled(const uint8_t userId, bool& state);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530211
212/** @brief provides user privilege access data
213 *
214 * @param[in] userId - user id
215 * @param[in] chNum - channel number
216 * @param[out] privAccess - privilege access data
217 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000218 * @return ccSuccess for success, others for failure.
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530219 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000220Cc ipmiUserGetPrivilegeAccess(const uint8_t userId, const uint8_t chNum,
221 PrivAccess& privAccess);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530222
223/** @brief sets user privilege access data
224 *
225 * @param[in] userId - user id
226 * @param[in] chNum - channel number
227 * @param[in] privAccess - privilege access data
228 * @param[in] otherPrivUpdate - flags to indicate other fields update
229 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000230 * @return ccSuccess for success, others for failure.
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530231 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000232Cc ipmiUserSetPrivilegeAccess(const uint8_t userId, const uint8_t chNum,
233 const PrivAccess& privAccess,
234 const bool& otherPrivUpdate);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530235
Ayushi Smriti02650d52019-05-15 11:59:09 +0000236/** @brief check for user pam authentication. This is to determine, whether user
237 * is already locked out for failed login attempt
238 *
239 * @param[in] username - username
240 * @param[in] password - password
241 *
242 * @return status
243 */
244bool ipmiUserPamAuthenticate(std::string_view userName,
245 std::string_view userPassword);
246
Saravanan Palanisamy77381f12019-05-15 22:33:17 +0000247/** @brief sets user payload access data
248 *
249 * @param[in] chNum - channel number
250 * @param[in] operation - ENABLE / DISABLE operation
251 * @param[in] userId - user id
252 * @param[in] payloadAccess - payload access data
253 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000254 * @return ccSuccess for success, others for failure.
Saravanan Palanisamy77381f12019-05-15 22:33:17 +0000255 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000256Cc ipmiUserSetUserPayloadAccess(const uint8_t chNum, const uint8_t operation,
257 const uint8_t userId,
258 const PayloadAccess& payloadAccess);
Saravanan Palanisamy77381f12019-05-15 22:33:17 +0000259
260/** @brief provides user payload access data
261 *
262 * @param[in] chNum - channel number
263 * @param[in] userId - user id
264 * @param[out] payloadAccess - payload access data
265 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000266 * @return ccSuccess for success, others for failure.
Saravanan Palanisamy77381f12019-05-15 22:33:17 +0000267 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000268Cc ipmiUserGetUserPayloadAccess(const uint8_t chNum, const uint8_t userId,
269 PayloadAccess& payloadAccess);
Saravanan Palanisamy77381f12019-05-15 22:33:17 +0000270
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +0530271} // namespace ipmi