| 11 | #include "utils/StringUtils.h" |
| 12 | |
| 13 | std::vector<std::string> PlatformHelper::GetAllUsers() { |
| 14 | auto data = Shell::ReadBytes("/etc/passwd"); |
| 15 | auto passwdStr = std::string(data.begin(), data.end()); |
| 16 | std::vector<std::string> result{}; |
| 17 | for(const auto &entry : StringUtils::Split(passwdStr, "\n")) { |
| 18 | auto split = StringUtils::Split(entry, ":"); |
| 19 | if(split.size() < 3) |
| 20 | continue; |
| 21 | char *end{}; |
| 22 | auto uidStr = split[2].c_str(); |
| 23 | auto uid = std::strtol(uidStr, &end, 10); |
| 24 | if(end == uidStr || (uid != 0 && (uid < 1000 || uid > 60000))) |
| 25 | continue; |
| 26 | auto userName = split[0]; |
| 27 | result.push_back(userName); |
| 28 | } |
| 29 | return result; |
| 30 | } |
| 31 | |
| 32 | std::string PlatformHelper::GetCurrentUser() { |
| 33 | std::optional<uid_t> uid{}; |