From 9f630d9eb0ce1c103532a4304ea080066199094e Mon Sep 17 00:00:00 2001 From: Richard Marian Thomaiyar Date: Thu, 24 May 2018 10:49:10 +0530 Subject: Basic support for User manager service Basic support for User Manager service methods are implemented. Change-Id: Id42432ec6dd421b99971268add931dcd70876f7c Signed-off-by: Richard Marian Thomaiyar --- user.cpp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'user.cpp') diff --git a/user.cpp b/user.cpp index 447bfcd..6999a98 100644 --- a/user.cpp +++ b/user.cpp @@ -40,10 +40,10 @@ constexpr auto SHADOW_FILE = "/etc/shadow"; constexpr int SALT_LENGTH = 16; using namespace phosphor::logging; -using InsufficientPermission = sdbusplus::xyz::openbmc_project::Common:: - Error::InsufficientPermission; -using InternalFailure = sdbusplus::xyz::openbmc_project::Common:: - Error::InternalFailure; +using InsufficientPermission = + sdbusplus::xyz::openbmc_project::Common::Error::InsufficientPermission; +using InternalFailure = + sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; // Sets or updates the password void User::setPassword(std::string newPassword) { @@ -68,15 +68,14 @@ void User::setPassword(std::string newPassword) } void User::applyPassword(const std::string& shadowFile, - const std::string& password, - const std::string& salt) + const std::string& password, const std::string& salt) { // Needed by getspnam_r struct spwd shdp; struct spwd* pshdp; // This should be fine even if SHA512 is used. - std::array buffer{}; + std::array buffer{}; // Open the shadow file for reading phosphor::user::File shadow(shadowFile, "r"); @@ -87,10 +86,10 @@ void User::applyPassword(const std::string& shadowFile, // open temp shadow file, by suffixing random name in shadow file name. std::vector tempFileName(shadowFile.begin(), shadowFile.end()); - std::vector fileTemplate = { - '_', '_', 'X', 'X', 'X', 'X', 'X', 'X', '\0' }; - tempFileName.insert( - tempFileName.end(), fileTemplate.begin(), fileTemplate.end()); + std::vector fileTemplate = {'_', '_', 'X', 'X', 'X', + 'X', 'X', 'X', '\0'}; + tempFileName.insert(tempFileName.end(), fileTemplate.begin(), + fileTemplate.end()); int fd = mkstemp(tempFileName.data()); if (fd == -1) @@ -112,7 +111,9 @@ void User::applyPassword(const std::string& shadowFile, // Change the permission of this new temp file // to be same as shadow so that it's secure - struct stat st{}; + struct stat st + { + }; auto r = fstat(fileno((shadow)()), &st); if (r < 0) { @@ -184,15 +185,13 @@ void User::raiseException(int errNo, const std::string& errMsg) } else { - log(errMsg.c_str(), - entry("USER=%s",user.c_str()), - entry("ERRNO=%d", errNo)); + log(errMsg.c_str(), entry("USER=%s", user.c_str()), + entry("ERRNO=%d", errNo)); elog(); } } -std::string User::hashPassword(char* spPwdp, - const std::string& password, +std::string User::hashPassword(char* spPwdp, const std::string& password, const std::string& salt) { // Parse and get crypt algo @@ -200,7 +199,7 @@ std::string User::hashPassword(char* spPwdp, if (cryptAlgo.empty()) { log("Error finding crypt algo", - entry("USER=%s",user.c_str())); + entry("USER=%s", user.c_str())); elog(); } @@ -226,7 +225,7 @@ const std::string User::randomString(int length) // Standard mersenne_twister_engine seeded with rd() std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(0, set.size()-1); + std::uniform_int_distribution<> dis(0, set.size() - 1); for (int count = 0; count < length; count++) { // Use dis to transform the random unsigned int generated by -- cgit v1.2.1