diff options
Diffstat (limited to 'user.cpp')
-rw-r--r-- | user.cpp | 37 |
1 files changed, 18 insertions, 19 deletions
@@ -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<char,1024> buffer{}; + std::array<char, 1024> 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<char> tempFileName(shadowFile.begin(), shadowFile.end()); - std::vector<char> fileTemplate = { - '_', '_', 'X', 'X', 'X', 'X', 'X', 'X', '\0' }; - tempFileName.insert( - tempFileName.end(), fileTemplate.begin(), fileTemplate.end()); + std::vector<char> 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<level::ERR>(errMsg.c_str(), - entry("USER=%s",user.c_str()), - entry("ERRNO=%d", errNo)); + log<level::ERR>(errMsg.c_str(), entry("USER=%s", user.c_str()), + entry("ERRNO=%d", errNo)); elog<InternalFailure>(); } } -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<level::ERR>("Error finding crypt algo", - entry("USER=%s",user.c_str())); + entry("USER=%s", user.c_str())); elog<InternalFailure>(); } @@ -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 |