2020-05-19 21:25:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "types.hh"
|
|
|
|
|
2022-11-03 16:43:40 +00:00
|
|
|
#include <optional>
|
2009-01-12 16:30:32 +00:00
|
|
|
|
2020-05-19 21:25:44 +00:00
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
struct UserLock
|
|
|
|
{
|
|
|
|
virtual ~UserLock() { }
|
|
|
|
|
|
|
|
/* Get the first and last UID. */
|
2022-11-08 15:03:42 +00:00
|
|
|
std::pair<uid_t, uid_t> getUIDRange()
|
2020-05-19 21:25:44 +00:00
|
|
|
{
|
2022-11-08 15:03:42 +00:00
|
|
|
auto first = getUID();
|
|
|
|
return {first, first + getUIDCount() - 1};
|
2020-05-19 21:25:44 +00:00
|
|
|
}
|
|
|
|
|
2022-11-08 15:03:42 +00:00
|
|
|
/* Get the first UID. */
|
|
|
|
virtual uid_t getUID() = 0;
|
|
|
|
|
|
|
|
virtual uid_t getUIDCount() = 0;
|
2020-05-19 21:25:44 +00:00
|
|
|
|
|
|
|
virtual gid_t getGID() = 0;
|
|
|
|
|
|
|
|
virtual std::vector<gid_t> getSupplementaryGIDs() = 0;
|
|
|
|
|
|
|
|
/* Kill any processes currently executing as this user. */
|
|
|
|
virtual void kill() = 0;
|
|
|
|
|
2022-11-08 15:03:42 +00:00
|
|
|
#if __linux__
|
2020-05-19 21:25:44 +00:00
|
|
|
virtual std::optional<Path> getCgroup() { return {}; };
|
2022-11-08 15:03:42 +00:00
|
|
|
#endif
|
2020-05-19 21:25:44 +00:00
|
|
|
};
|
|
|
|
|
2022-11-08 15:03:42 +00:00
|
|
|
/* Acquire a user lock for a UID range of size `nrIds`. Note that this
|
|
|
|
may return nullptr if no user is available. */
|
|
|
|
std::unique_ptr<UserLock> acquireUserLock(uid_t nrIds);
|
2020-05-19 21:25:44 +00:00
|
|
|
|
2020-05-20 09:24:21 +00:00
|
|
|
bool useBuildUsers();
|
|
|
|
|
2020-05-19 21:25:44 +00:00
|
|
|
}
|