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 | |
| 30 | ipmi_ret_t ipmiUserInit() |
| 31 | { |
| 32 | getUserAccessObject(); |
| 33 | return IPMI_CC_OK; |
| 34 | } |
| 35 | |
Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 36 | std::string ipmiUserGetPassword(const std::string& userName) |
| 37 | { |
| 38 | return passwdMgr.getPasswdByUserName(userName); |
| 39 | } |
| 40 | |
Richard Marian Thomaiyar | 42bed64 | 2018-09-21 12:28:57 +0530 | [diff] [blame] | 41 | ipmi_ret_t 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 | { |
| 45 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 46 | } |
| 47 | return IPMI_CC_OK; |
| 48 | } |
| 49 | |
| 50 | ipmi_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 Puli | b29b5ab | 2018-05-17 10:28:48 +0530 | [diff] [blame] | 57 | return IPMI_CC_OK; |
| 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 ipmiUserIsValidChannel(const uint8_t chNum) |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 66 | { |
| 67 | return UserAccess::isValidChannel(chNum); |
| 68 | } |
| 69 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 70 | bool ipmiUserIsValidPrivilege(const uint8_t priv) |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 71 | { |
| 72 | return UserAccess::isValidPrivilege(priv); |
| 73 | } |
| 74 | |
| 75 | uint8_t ipmiUserGetUserId(const std::string& userName) |
| 76 | { |
| 77 | return getUserAccessObject().getUserId(userName); |
| 78 | } |
| 79 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 80 | ipmi_ret_t ipmiUserSetUserName(const uint8_t userId, const char* userName) |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 81 | { |
| 82 | return getUserAccessObject().setUserName(userId, userName); |
| 83 | } |
| 84 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 85 | ipmi_ret_t ipmiUserGetUserName(const uint8_t userId, std::string& userName) |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 86 | { |
| 87 | return getUserAccessObject().getUserName(userId, userName); |
| 88 | } |
| 89 | |
| 90 | ipmi_ret_t ipmiUserGetAllCounts(uint8_t& maxChUsers, uint8_t& enabledUsers, |
| 91 | uint8_t& fixedUsers) |
| 92 | { |
| 93 | maxChUsers = ipmiMaxUsers; |
| 94 | UsersTbl* userData = getUserAccessObject().getUsersTblPtr(); |
| 95 | enabledUsers = 0; |
| 96 | fixedUsers = 0; |
| 97 | // user index 0 is reserved, starts with 1 |
| 98 | for (size_t count = 1; count <= ipmiMaxUsers; ++count) |
| 99 | { |
| 100 | if (userData->user[count].userEnabled) |
| 101 | { |
| 102 | enabledUsers++; |
| 103 | } |
| 104 | if (userData->user[count].fixedUserName) |
| 105 | { |
| 106 | fixedUsers++; |
| 107 | } |
| 108 | } |
| 109 | return IPMI_CC_OK; |
| 110 | } |
| 111 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 112 | ipmi_ret_t ipmiUserUpdateEnabledState(const uint8_t userId, const bool& state) |
Richard Marian Thomaiyar | 282e79b | 2018-11-13 19:00:58 +0530 | [diff] [blame] | 113 | { |
| 114 | return getUserAccessObject().setUserEnabledState(userId, state); |
| 115 | } |
| 116 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 117 | ipmi_ret_t ipmiUserCheckEnabled(const uint8_t userId, bool& state) |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 118 | { |
| 119 | if (!UserAccess::isValidUserId(userId)) |
| 120 | { |
| 121 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 122 | } |
| 123 | UserInfo* userInfo = getUserAccessObject().getUserInfo(userId); |
| 124 | state = userInfo->userEnabled; |
| 125 | return IPMI_CC_OK; |
| 126 | } |
| 127 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 128 | ipmi_ret_t ipmiUserGetPrivilegeAccess(const uint8_t userId, const uint8_t chNum, |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 129 | PrivAccess& privAccess) |
| 130 | { |
| 131 | |
| 132 | if (!UserAccess::isValidChannel(chNum)) |
| 133 | { |
| 134 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 135 | } |
| 136 | if (!UserAccess::isValidUserId(userId)) |
| 137 | { |
| 138 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 139 | } |
| 140 | UserInfo* userInfo = getUserAccessObject().getUserInfo(userId); |
| 141 | privAccess.privilege = userInfo->userPrivAccess[chNum].privilege; |
| 142 | privAccess.ipmiEnabled = userInfo->userPrivAccess[chNum].ipmiEnabled; |
| 143 | privAccess.linkAuthEnabled = |
| 144 | userInfo->userPrivAccess[chNum].linkAuthEnabled; |
| 145 | privAccess.accessCallback = userInfo->userPrivAccess[chNum].accessCallback; |
| 146 | |
| 147 | return IPMI_CC_OK; |
| 148 | } |
| 149 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 150 | ipmi_ret_t ipmiUserSetPrivilegeAccess(const uint8_t userId, const uint8_t chNum, |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 151 | const PrivAccess& privAccess, |
| 152 | const bool& otherPrivUpdates) |
| 153 | { |
| 154 | UserPrivAccess userPrivAccess; |
| 155 | userPrivAccess.privilege = privAccess.privilege; |
| 156 | if (otherPrivUpdates) |
| 157 | { |
| 158 | userPrivAccess.ipmiEnabled = privAccess.ipmiEnabled; |
| 159 | userPrivAccess.linkAuthEnabled = privAccess.linkAuthEnabled; |
| 160 | userPrivAccess.accessCallback = privAccess.accessCallback; |
| 161 | } |
| 162 | return getUserAccessObject().setUserPrivilegeAccess( |
| 163 | userId, chNum, userPrivAccess, otherPrivUpdates); |
| 164 | } |
| 165 | |
Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 166 | } // namespace ipmi |