MCPcopy Create free account
hub / github.com/MeisApps/pcbu-desktop / GetAllUsers

Method GetAllUsers

common/src/platform/PlatformHelper.Linux.cpp:13–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include "utils/StringUtils.h"
12
13std::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
32std::string PlatformHelper::GetCurrentUser() {
33 std::optional<uid_t> uid{};

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected