Lines Matching refs:userName

201 bool UserMgr::isUserExist(const std::string& userName)  in isUserExist()  argument
203 if (userName.empty()) in isUserExist()
209 if (usersList.find(userName) == usersList.end()) in isUserExist()
216 void UserMgr::throwForUserDoesNotExist(const std::string& userName) in throwForUserDoesNotExist() argument
218 if (!isUserExist(userName)) in throwForUserDoesNotExist()
220 lg2::error("User '{USERNAME}' does not exist", "USERNAME", userName); in throwForUserDoesNotExist()
239 void UserMgr::throwForUserExists(const std::string& userName) in throwForUserExists() argument
241 if (isUserExist(userName)) in throwForUserExists()
243 lg2::error("User '{USERNAME}' already exists", "USERNAME", userName); in throwForUserExists()
249 const std::string& userName, const std::vector<std::string>& groupNames) in throwForUserNameConstraints() argument
254 if (userName.length() > ipmiMaxUserNameLen) in throwForUserNameConstraints()
258 "USERNAME", userName, "LENGTH", userName.length(), in throwForUserNameConstraints()
265 if (userName.length() > systemMaxUserNameLen) in throwForUserNameConstraints()
269 "USERNAME", userName, "LENGTH", userName.length(), "LIMIT", in throwForUserNameConstraints()
274 if (!std::regex_match(userName.c_str(), in throwForUserNameConstraints()
277 lg2::error("Invalid username '{USERNAME}'", "USERNAME", userName); in throwForUserNameConstraints()
360 void UserMgr::createUser(std::string userName, in createUser() argument
368 throwForUserExists(userName); in createUser()
369 throwForUserNameConstraints(userName, groupNames); in createUser()
387 executeUserAdd(userName.c_str(), groups.c_str(), sshRequested, enabled); in createUser()
392 userName); in createUser()
398 tempObjPath /= userName; in createUser()
402 userName, std::make_unique<phosphor::user::Users>( in createUser()
405 lg2::info("User '{USERNAME}' created successfully", "USERNAME", userName); in createUser()
409 void UserMgr::deleteUser(std::string userName) in deleteUser() argument
413 throwForUserDoesNotExist(userName); in deleteUser()
417 executeUserClearFailRecords(userName.c_str()); in deleteUser()
419 executeUserDelete(userName.c_str()); in deleteUser()
423 lg2::error("Delete User '{USERNAME}' failed", "USERNAME", userName); in deleteUser()
427 usersList.erase(userName); in deleteUser()
429 lg2::info("User '{USERNAME}' deleted successfully", "USERNAME", userName); in deleteUser()
495 void UserMgr::renameUser(std::string userName, std::string newUserName) in renameUser() argument
499 throwForUserDoesNotExist(userName); in renameUser()
502 usersList[userName].get()->userGroups()); in renameUser()
505 executeUserRename(userName.c_str(), newUserName.c_str()); in renameUser()
510 userName, "NEWUSERNAME", newUserName); in renameUser()
513 const auto& user = usersList[userName]; in renameUser()
523 this->userRenamed(userName, newUserName); in renameUser()
524 usersList.erase(userName); in renameUser()
531 void UserMgr::updateGroupsAndPriv(const std::string& userName, in updateGroupsAndPriv() argument
539 throwForUserDoesNotExist(userName); in updateGroupsAndPriv()
541 usersList[userName].get()->userGroups(); in updateGroupsAndPriv()
550 throwForUserNameConstraints(userName, groupNames); in updateGroupsAndPriv()
569 executeUserModify(userName.c_str(), groups.c_str(), sshRequested); in updateGroupsAndPriv()
575 "USERNAME", userName); in updateGroupsAndPriv()
580 usersList[userName]->setUserGroups(groupNames); in updateGroupsAndPriv()
581 usersList[userName]->setUserPrivilege(priv); in updateGroupsAndPriv()
583 "USERNAME", userName); in updateGroupsAndPriv()
763 void UserMgr::userEnable(const std::string& userName, bool enabled) in userEnable() argument
767 throwForUserDoesNotExist(userName); in userEnable()
770 executeUserModifyUserEnable(userName.c_str(), enabled); in userEnable()
775 "USERNAME", userName); in userEnable()
779 usersList[userName]->setUserEnabled(enabled); in userEnable()
780 lg2::info("User '{USERNAME}' has been {STATUS}", "USERNAME", userName, in userEnable()
855 bool UserMgr::userLockedForFailedAttempt(const std::string& userName) in userLockedForFailedAttempt() argument
867 output = getFailedAttempt(userName.c_str()); in userLockedForFailedAttempt()
878 bool UserMgr::userLockedForFailedAttempt(const std::string& userName, in userLockedForFailedAttempt() argument
885 return userLockedForFailedAttempt(userName); in userLockedForFailedAttempt()
891 executeUserClearFailRecords(userName.c_str()); in userLockedForFailedAttempt()
899 return userLockedForFailedAttempt(userName); in userLockedForFailedAttempt()
902 bool UserMgr::userPasswordExpired(const std::string& userName) in userPasswordExpired() argument
917 getspnam_r(userName.c_str(), &spwd, buffer.data(), buflen, &spwdPtr); in userPasswordExpired()
982 std::string userName(pwp->pw_name); in getUserAndSshGrpList() local
983 userList.emplace_back(userName); in getUserAndSshGrpList()
990 sshUsersList.emplace_back(userName); in getUserAndSshGrpList()
1010 bool UserMgr::isUserEnabled(const std::string& userName) in isUserEnabled() argument
1017 int status = getspnam_r(userName.c_str(), &spwd, buffer.data(), in isUserEnabled()
1125 gid_t UserMgr::getPrimaryGroup(const std::string& userName) const in getPrimaryGroup()
1138 auto status = getpwnam_r(userName.c_str(), &pwd, buffer.data(), in getPrimaryGroup()
1148 lg2::error("User {USERNAME} does not exist", "USERNAME", userName); in getPrimaryGroup()
1152 bool UserMgr::isGroupMember(const std::string& userName, gid_t primaryGid, in isGroupMember() argument
1197 if (userName == grp.gr_mem[i]) in isGroupMember()
1226 UserInfoMap UserMgr::getUserInfo(std::string userName) in getUserInfo() argument
1230 if (isUserExist(userName)) in getUserInfo()
1232 const auto& user = usersList[userName]; in getUserInfo()
1246 auto primaryGid = getPrimaryGroup(userName); in getUserInfo()
1302 isGroupMember(userName, primaryGid, groupName)) in getUserInfo()
1538 void UserMgr::executeUserAdd(const char* userName, const char* groups, in executeUserAdd() argument
1543 executeCmd("/usr/sbin/useradd", userName, "-G", groups, "-m", "-N", "-s", in executeUserAdd()
1548 void UserMgr::executeUserDelete(const char* userName) in executeUserDelete() argument
1550 executeCmd("/usr/sbin/userdel", userName, "-r"); in executeUserDelete()
1553 void UserMgr::executeUserClearFailRecords(const char* userName) in executeUserClearFailRecords() argument
1555 executeCmd("/usr/sbin/faillock", "--user", userName, "--reset"); in executeUserClearFailRecords()
1558 void UserMgr::executeUserRename(const char* userName, const char* newUserName) in executeUserRename() argument
1562 executeCmd("/usr/sbin/usermod", "-l", newUserName, userName, "-d", in executeUserRename()
1566 void UserMgr::executeUserModify(const char* userName, const char* newGroups, in executeUserModify() argument
1569 executeCmd("/usr/sbin/usermod", userName, "-G", newGroups, "-s", in executeUserModify()
1573 void UserMgr::executeUserModifyUserEnable(const char* userName, bool enabled) in executeUserModifyUserEnable() argument
1577 executeCmd("/usr/sbin/usermod", userName, "-e", in executeUserModifyUserEnable()
1581 std::vector<std::string> UserMgr::getFailedAttempt(const char* userName) in getFailedAttempt() argument
1583 return executeCmd("/usr/sbin/faillock", "--user", userName); in getFailedAttempt()
1615 bool UserMgr::secretKeyRequired(std::string userName) in secretKeyRequired() argument
1617 if (usersList.contains(userName)) in secretKeyRequired()
1619 return usersList[userName]->secretKeyGenerationRequired(); in secretKeyRequired()