Loading src/runtime.cpp +22 −6 Changes for src/runtime.cpp: 22 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -312,6 +312,20 @@ struct Pid1 { std::string home = "/", name; }; // a classic id from /etc/passwd or /etc/group; a UUID or GUID (FenrirOS // uid_r) or anything else that isn't a plain number can't be a // container's id -- strtoul() would read "3f2a...-..." as uid 3 static bool classicId(const std::string &s, unsigned long &id) { if (s.empty() || s.size() > 10 || s.find_first_not_of("0123456789") != std::string::npos) return false; id = std::strtoul(s.c_str(), nullptr, 10); return id <= 0xfffffffeUL; } unsigned long classicIdOrFail(const std::string &s, const std::string &of) { unsigned long id = 0; if (!classicId(s, id)) fail(tr("%1 has no classic id (%2) in the image", "%1 hat keine klassische ID (%2) im Image", {of, s})); return id; } // "name|uid[:group|gid]" from the container's /etc/passwd and /etc/group Account account(const std::string &spec) { Account a; Loading @@ -326,8 +340,8 @@ struct Pid1 { if (f.size() < 7) continue; if (numeric ? f[2] == u : f[0] == u) { a.name = f[0]; a.uid = (uid_t)std::strtoul(f[2].c_str(), nullptr, 10); a.gid = (gid_t)std::strtoul(f[3].c_str(), nullptr, 10); a.uid = (uid_t)classicIdOrFail(f[2], f[0]); a.gid = (gid_t)classicIdOrFail(f[3], f[0]); a.home = f[5].empty() ? "/" : f[5]; found = true; break; Loading @@ -335,16 +349,16 @@ struct Pid1 { } if (!found) { if (!numeric) fail(tr("no user %1 in the image", "kein Benutzer %1 im Image", {u})); a.uid = (uid_t)std::strtoul(u.c_str(), nullptr, 10); a.uid = (uid_t)classicIdOrFail(u, u); a.gid = a.uid; } if (!g.empty()) { bool gnum = g.find_first_not_of("0123456789") == std::string::npos, gfound = gnum; if (gnum) a.gid = (gid_t)std::strtoul(g.c_str(), nullptr, 10); if (gnum) a.gid = (gid_t)classicIdOrFail(g, g); for (auto &line : split(group, '\n')) { auto f = split(line, ':'); if (!gnum && f.size() >= 3 && f[0] == g) { a.gid = (gid_t)std::strtoul(f[2].c_str(), nullptr, 10); a.gid = (gid_t)classicIdOrFail(f[2], g); gfound = true; } } Loading @@ -356,8 +370,10 @@ struct Pid1 { for (auto &line : split(group, '\n')) { auto f = split(line, ':'); if (f.size() < 4) continue; unsigned long gid; if (!classicId(f[2], gid)) continue; // a UUID or GUID group can't be given for (auto &m : split(f[3], ',')) if (m == a.name) a.groups.push_back((gid_t)std::strtoul(f[2].c_str(), nullptr, 10)); if (m == a.name) a.groups.push_back((gid_t)gid); } return a; } Loading Loading
src/runtime.cpp +22 −6 Changes for src/runtime.cpp: 22 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -312,6 +312,20 @@ struct Pid1 { std::string home = "/", name; }; // a classic id from /etc/passwd or /etc/group; a UUID or GUID (FenrirOS // uid_r) or anything else that isn't a plain number can't be a // container's id -- strtoul() would read "3f2a...-..." as uid 3 static bool classicId(const std::string &s, unsigned long &id) { if (s.empty() || s.size() > 10 || s.find_first_not_of("0123456789") != std::string::npos) return false; id = std::strtoul(s.c_str(), nullptr, 10); return id <= 0xfffffffeUL; } unsigned long classicIdOrFail(const std::string &s, const std::string &of) { unsigned long id = 0; if (!classicId(s, id)) fail(tr("%1 has no classic id (%2) in the image", "%1 hat keine klassische ID (%2) im Image", {of, s})); return id; } // "name|uid[:group|gid]" from the container's /etc/passwd and /etc/group Account account(const std::string &spec) { Account a; Loading @@ -326,8 +340,8 @@ struct Pid1 { if (f.size() < 7) continue; if (numeric ? f[2] == u : f[0] == u) { a.name = f[0]; a.uid = (uid_t)std::strtoul(f[2].c_str(), nullptr, 10); a.gid = (gid_t)std::strtoul(f[3].c_str(), nullptr, 10); a.uid = (uid_t)classicIdOrFail(f[2], f[0]); a.gid = (gid_t)classicIdOrFail(f[3], f[0]); a.home = f[5].empty() ? "/" : f[5]; found = true; break; Loading @@ -335,16 +349,16 @@ struct Pid1 { } if (!found) { if (!numeric) fail(tr("no user %1 in the image", "kein Benutzer %1 im Image", {u})); a.uid = (uid_t)std::strtoul(u.c_str(), nullptr, 10); a.uid = (uid_t)classicIdOrFail(u, u); a.gid = a.uid; } if (!g.empty()) { bool gnum = g.find_first_not_of("0123456789") == std::string::npos, gfound = gnum; if (gnum) a.gid = (gid_t)std::strtoul(g.c_str(), nullptr, 10); if (gnum) a.gid = (gid_t)classicIdOrFail(g, g); for (auto &line : split(group, '\n')) { auto f = split(line, ':'); if (!gnum && f.size() >= 3 && f[0] == g) { a.gid = (gid_t)std::strtoul(f[2].c_str(), nullptr, 10); a.gid = (gid_t)classicIdOrFail(f[2], g); gfound = true; } } Loading @@ -356,8 +370,10 @@ struct Pid1 { for (auto &line : split(group, '\n')) { auto f = split(line, ':'); if (f.size() < 4) continue; unsigned long gid; if (!classicId(f[2], gid)) continue; // a UUID or GUID group can't be given for (auto &m : split(f[3], ',')) if (m == a.name) a.groups.push_back((gid_t)std::strtoul(f[2].c_str(), nullptr, 10)); if (m == a.name) a.groups.push_back((gid_t)gid); } return a; } Loading