Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 1 | /* |
| 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 Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 20 | #include "user_mgmt.hpp" |
| 21 | |
Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 22 | namespace |
| 23 | { |
| 24 | ipmi::PasswdMgr passwdMgr; |
| 25 | } |
| 26 | |
| 27 | namespace ipmi |
| 28 | { |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 29 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 30 | Cc ipmiUserInit() |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 31 | { |
| 32 | getUserAccessObject(); |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 33 | return ccSuccess; |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 34 | } |
| 35 | |
Vernon Mauery | 1e22a0f | 2021-07-30 13:36:54 -0700 | [diff] [blame] | 36 | SecureString ipmiUserGetPassword(const std::string& userName) |
Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 37 | { |
| 38 | return passwdMgr.getPasswdByUserName(userName); |
| 39 | } |
| 40 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 41 | Cc ipmiClearUserEntryPassword(const std::string& userName) |
AppaRao Puli | b29b5ab | 2018-05-17 10:28:48 +0530 | [diff] [blame] | 42 | { |
Richard Marian Thomaiyar | 42bed64 | 2018-09-21 12:28:57 +0530 | [diff] [blame] | 43 | if (passwdMgr.updateUserEntry(userName, "") != 0) |
| 44 | { |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 45 | return ccUnspecifiedError; |
Richard Marian Thomaiyar | 42bed64 | 2018-09-21 12:28:57 +0530 | [diff] [blame] | 46 | } |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 47 | return ccSuccess; |
Richard Marian Thomaiyar | 42bed64 | 2018-09-21 12:28:57 +0530 | [diff] [blame] | 48 | } |
| 49 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 50 | Cc ipmiRenameUserEntryPassword(const std::string& userName, |
| 51 | const std::string& newUserName) |
Richard Marian Thomaiyar | 42bed64 | 2018-09-21 12:28:57 +0530 | [diff] [blame] | 52 | { |
| 53 | if (passwdMgr.updateUserEntry(userName, newUserName) != 0) |
| 54 | { |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 55 | return ccUnspecifiedError; |
Richard Marian Thomaiyar | 42bed64 | 2018-09-21 12:28:57 +0530 | [diff] [blame] | 56 | } |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 57 | return ccSuccess; |
AppaRao Puli | b29b5ab | 2018-05-17 10:28:48 +0530 | [diff] [blame] | 58 | } |
| 59 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 60 | bool ipmiUserIsValidUserId(const uint8_t userId) |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 61 | { |
| 62 | return UserAccess::isValidUserId(userId); |
| 63 | } |
| 64 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 65 | bool ipmiUserIsValidPrivilege(const uint8_t priv) |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 66 | { |
| 67 | return UserAccess::isValidPrivilege(priv); |
| 68 | } |
| 69 | |
| 70 | uint8_t ipmiUserGetUserId(const std::string& userName) |
| 71 | { |
| 72 | return getUserAccessObject().getUserId(userName); |
| 73 | } |
| 74 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 75 | Cc ipmiUserSetUserName(const uint8_t userId, const char* userName) |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 76 | { |
jayaprakash Mutyala | 7636330 | 2020-02-14 23:50:38 +0000 | [diff] [blame] | 77 | std::string newUser(userName, 0, ipmiMaxUserName); |
| 78 | return getUserAccessObject().setUserName(userId, newUser); |
| 79 | } |
| 80 | |
| 81 | Cc 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 Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 85 | } |
| 86 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 87 | Cc ipmiUserGetUserName(const uint8_t userId, std::string& userName) |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 88 | { |
| 89 | return getUserAccessObject().getUserName(userId, userName); |
| 90 | } |
| 91 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 92 | Cc ipmiUserSetUserPassword(const uint8_t userId, const char* userPassword) |
Suryakanth Sekar | 90b00c7 | 2019-01-16 10:37:57 +0530 | [diff] [blame] | 93 | { |
| 94 | return getUserAccessObject().setUserPassword(userId, userPassword); |
| 95 | } |
| 96 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 97 | Cc ipmiSetSpecialUserPassword(const std::string& userName, |
Vernon Mauery | 1e22a0f | 2021-07-30 13:36:54 -0700 | [diff] [blame] | 98 | const SecureString& userPassword) |
Richard Marian Thomaiyar | 788362c | 2019-04-14 15:12:47 +0530 | [diff] [blame] | 99 | { |
| 100 | return getUserAccessObject().setSpecialUserPassword(userName, userPassword); |
| 101 | } |
| 102 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 103 | Cc ipmiUserGetAllCounts(uint8_t& maxChUsers, uint8_t& enabledUsers, |
| 104 | uint8_t& fixedUsers) |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 105 | { |
| 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 SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 122 | return ccSuccess; |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 123 | } |
| 124 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 125 | Cc ipmiUserUpdateEnabledState(const uint8_t userId, const bool& state) |
Richard Marian Thomaiyar | 282e79b | 2018-11-13 19:00:58 +0530 | [diff] [blame] | 126 | { |
| 127 | return getUserAccessObject().setUserEnabledState(userId, state); |
| 128 | } |
| 129 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 130 | Cc ipmiUserCheckEnabled(const uint8_t userId, bool& state) |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 131 | { |
| 132 | if (!UserAccess::isValidUserId(userId)) |
| 133 | { |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 134 | return ccParmOutOfRange; |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 135 | } |
| 136 | UserInfo* userInfo = getUserAccessObject().getUserInfo(userId); |
| 137 | state = userInfo->userEnabled; |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 138 | return ccSuccess; |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 139 | } |
| 140 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 141 | Cc ipmiUserGetPrivilegeAccess(const uint8_t userId, const uint8_t chNum, |
| 142 | PrivAccess& privAccess) |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 143 | { |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 144 | if (!UserAccess::isValidChannel(chNum)) |
| 145 | { |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 146 | return ccInvalidFieldRequest; |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 147 | } |
| 148 | if (!UserAccess::isValidUserId(userId)) |
| 149 | { |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 150 | return ccParmOutOfRange; |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 151 | } |
| 152 | UserInfo* userInfo = getUserAccessObject().getUserInfo(userId); |
| 153 | privAccess.privilege = userInfo->userPrivAccess[chNum].privilege; |
| 154 | privAccess.ipmiEnabled = userInfo->userPrivAccess[chNum].ipmiEnabled; |
| 155 | privAccess.linkAuthEnabled = |
| 156 | userInfo->userPrivAccess[chNum].linkAuthEnabled; |
| 157 | privAccess.accessCallback = userInfo->userPrivAccess[chNum].accessCallback; |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 158 | return ccSuccess; |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 159 | } |
| 160 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 161 | Cc ipmiUserSetPrivilegeAccess(const uint8_t userId, const uint8_t chNum, |
| 162 | const PrivAccess& privAccess, |
| 163 | const bool& otherPrivUpdates) |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 164 | { |
| 165 | UserPrivAccess userPrivAccess; |
| 166 | userPrivAccess.privilege = privAccess.privilege; |
| 167 | if (otherPrivUpdates) |
| 168 | { |
| 169 | userPrivAccess.ipmiEnabled = privAccess.ipmiEnabled; |
| 170 | userPrivAccess.linkAuthEnabled = privAccess.linkAuthEnabled; |
| 171 | userPrivAccess.accessCallback = privAccess.accessCallback; |
| 172 | } |
| 173 | return getUserAccessObject().setUserPrivilegeAccess( |
| 174 | userId, chNum, userPrivAccess, otherPrivUpdates); |
| 175 | } |
| 176 | |
Ayushi Smriti | 02650d5 | 2019-05-15 11:59:09 +0000 | [diff] [blame] | 177 | bool ipmiUserPamAuthenticate(std::string_view userName, |
| 178 | std::string_view userPassword) |
| 179 | { |
| 180 | return pamUserCheckAuthenticate(userName, userPassword); |
| 181 | } |
| 182 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 183 | Cc ipmiUserSetUserPayloadAccess(const uint8_t chNum, const uint8_t operation, |
| 184 | const uint8_t userId, |
| 185 | const PayloadAccess& payloadAccess) |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 186 | { |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 187 | if (!UserAccess::isValidChannel(chNum)) |
| 188 | { |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 189 | return ccInvalidFieldRequest; |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 190 | } |
| 191 | if (!UserAccess::isValidUserId(userId)) |
| 192 | { |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 193 | return ccParmOutOfRange; |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | return getUserAccessObject().setUserPayloadAccess(chNum, operation, userId, |
| 197 | payloadAccess); |
| 198 | } |
| 199 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 200 | Cc ipmiUserGetUserPayloadAccess(const uint8_t chNum, const uint8_t userId, |
| 201 | PayloadAccess& payloadAccess) |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 202 | { |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 203 | if (!UserAccess::isValidChannel(chNum)) |
| 204 | { |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 205 | return ccInvalidFieldRequest; |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 206 | } |
| 207 | if (!UserAccess::isValidUserId(userId)) |
| 208 | { |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 209 | return ccParmOutOfRange; |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | UserInfo* userInfo = getUserAccessObject().getUserInfo(userId); |
| 213 | |
| 214 | payloadAccess.stdPayloadEnables1 = |
| 215 | userInfo->payloadAccess[chNum].stdPayloadEnables1; |
| 216 | payloadAccess.stdPayloadEnables2Reserved = |
| 217 | userInfo->payloadAccess[chNum].stdPayloadEnables2Reserved; |
| 218 | payloadAccess.oemPayloadEnables1 = |
| 219 | userInfo->payloadAccess[chNum].oemPayloadEnables1; |
| 220 | payloadAccess.oemPayloadEnables2Reserved = |
| 221 | userInfo->payloadAccess[chNum].oemPayloadEnables2Reserved; |
| 222 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 223 | return ccSuccess; |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 226 | } // namespace ipmi |