diff options
author | Suryakanth Sekar <suryakanth.sekar@linux.intel.com> | 2019-01-16 10:37:57 +0530 |
---|---|---|
committer | Vernon Mauery <vernon.mauery@linux.intel.com> | 2019-03-26 16:38:59 +0000 |
commit | 90b00c71067df78597db92bb60dbacf654a6f80a (patch) | |
tree | 518214e15a188a194a795dc40e2cae72fceba845 /user_channel/usercommands.cpp | |
parent | 17898f625b04d4fee6c2fd0626c47c93f2c2e7bd (diff) | |
download | phosphor-host-ipmid-90b00c71067df78597db92bb60dbacf654a6f80a.tar.gz phosphor-host-ipmid-90b00c71067df78597db92bb60dbacf654a6f80a.zip |
Adding Set Password API support in Userlayer
Moved the pam function from libusercommand to libuserlayer
Added the setPassword API in user layer.
There are modules which requires to use set password functionality
(other ipmi providers-OEM),so it's better to keep the set-password
abstracted in user-layer instead of user-commands.
LIBS macro hold libpam and libmapper.
we want to separate the libpam from lib usercommand.
so,replaced LIBS with libmapper alone.
Tested:Able to set the password in ipmi using userlayer.
ex: ipmitool user set password <userid> <password>
user password should set properly.
Change-Id: I32d55ff5c042613c89805c6b9393d18cbf880461
Signed-off-by: Suryakanth Sekar <suryakanth.sekar@linux.intel.com>
Diffstat (limited to 'user_channel/usercommands.cpp')
-rw-r--r-- | user_channel/usercommands.cpp | 80 |
1 files changed, 2 insertions, 78 deletions
diff --git a/user_channel/usercommands.cpp b/user_channel/usercommands.cpp index 90aadb1..d0ea29f 100644 --- a/user_channel/usercommands.cpp +++ b/user_channel/usercommands.cpp @@ -31,8 +31,6 @@ namespace ipmi using namespace phosphor::logging; -static constexpr uint8_t maxIpmi20PasswordSize = 20; -static constexpr uint8_t maxIpmi15PasswordSize = 16; static constexpr uint8_t disableUser = 0x00; static constexpr uint8_t enableUser = 0x01; static constexpr uint8_t setPassword = 0x02; @@ -352,65 +350,6 @@ ipmi_ret_t ipmiGetUserName(ipmi_netfn_t netfn, ipmi_cmd_t cmd, return IPMI_CC_OK; } -int pamFunctionConversation(int numMsg, const struct pam_message** msg, - struct pam_response** resp, void* appdataPtr) -{ - if (appdataPtr == nullptr) - { - return PAM_AUTH_ERR; - } - size_t passSize = std::strlen(reinterpret_cast<char*>(appdataPtr)) + 1; - char* pass = reinterpret_cast<char*>(malloc(passSize)); - std::strncpy(pass, reinterpret_cast<char*>(appdataPtr), passSize); - - *resp = reinterpret_cast<pam_response*>( - calloc(numMsg, sizeof(struct pam_response))); - - for (int i = 0; i < numMsg; ++i) - { - if (msg[i]->msg_style != PAM_PROMPT_ECHO_OFF) - { - continue; - } - resp[i]->resp = pass; - } - return PAM_SUCCESS; -} - -bool pamUpdatePasswd(const char* username, const char* password) -{ - const struct pam_conv localConversation = {pamFunctionConversation, - const_cast<char*>(password)}; - pam_handle_t* localAuthHandle = NULL; // this gets set by pam_start - - if (pam_start("passwd", username, &localConversation, &localAuthHandle) != - PAM_SUCCESS) - { - return false; - } - int retval = pam_chauthtok(localAuthHandle, PAM_SILENT); - - if (retval != PAM_SUCCESS) - { - if (retval == PAM_AUTHTOK_ERR) - { - log<level::DEBUG>("Authentication Failure"); - } - else - { - log<level::DEBUG>("pam_chauthtok returned failure", - entry("ERROR=%d", retval)); - } - pam_end(localAuthHandle, retval); - return false; - } - if (pam_end(localAuthHandle, PAM_SUCCESS) != PAM_SUCCESS) - { - return false; - } - return true; -} - /** @brief implementes the set user password command * @param[in] netfn - specifies netfn. * @param[in] cmd - specifies cmd number. @@ -462,23 +401,8 @@ ipmi_ret_t ipmiSetUserPassword(ipmi_netfn_t netfn, ipmi_cmd_t cmd, } if (req->operation == setPassword) { - std::string passwd; - passwd.assign(reinterpret_cast<const char*>(req->userPassword), 0, - maxIpmi20PasswordSize); - if (!std::regex_match(passwd.c_str(), - std::regex("[a-zA-z_0-9][a-zA-Z_0-9,?:`!\"]*"))) - { - log<level::ERR>("Invalid password fields", - entry("USER-ID:%d", (uint8_t)req->userId)); - return IPMI_CC_INVALID_FIELD_REQUEST; - } - if (!pamUpdatePasswd(userName.c_str(), passwd.c_str())) - { - log<level::ERR>("Failed to update password", - entry("USER-ID:%d", (uint8_t)req->userId)); - return IPMI_CC_INVALID_FIELD_REQUEST; - } - return IPMI_CC_OK; + return ipmiUserSetUserPassword( + req->userId, reinterpret_cast<const char*>(req->userPassword)); } else if (req->operation == enableUser || req->operation == disableUser) { |