2020-05-20 00:25:44 +03:00
|
|
|
#pragma once
|
2023-04-01 06:18:41 +03:00
|
|
|
///@file
|
2020-05-20 00:25:44 +03:00
|
|
|
|
|
|
|
#include "types.hh"
|
|
|
|
|
2022-11-03 18:43:40 +02:00
|
|
|
#include <optional>
|
2009-01-12 18:30:32 +02:00
|
|
|
|
2022-11-08 18:00:29 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2020-05-20 00:25:44 +03:00
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
struct UserLock
|
|
|
|
{
|
|
|
|
virtual ~UserLock() { }
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Get the first and last UID.
|
|
|
|
*/
|
2022-11-08 17:03:42 +02:00
|
|
|
std::pair<uid_t, uid_t> getUIDRange()
|
2020-05-20 00:25:44 +03:00
|
|
|
{
|
2022-11-08 17:03:42 +02:00
|
|
|
auto first = getUID();
|
|
|
|
return {first, first + getUIDCount() - 1};
|
2020-05-20 00:25:44 +03:00
|
|
|
}
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Get the first UID.
|
|
|
|
*/
|
2022-11-08 17:03:42 +02:00
|
|
|
virtual uid_t getUID() = 0;
|
|
|
|
|
|
|
|
virtual uid_t getUIDCount() = 0;
|
2020-05-20 00:25:44 +03:00
|
|
|
|
|
|
|
virtual gid_t getGID() = 0;
|
|
|
|
|
|
|
|
virtual std::vector<gid_t> getSupplementaryGIDs() = 0;
|
|
|
|
};
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Acquire a user lock for a UID range of size `nrIds`. Note that this
|
|
|
|
* may return nullptr if no user is available.
|
|
|
|
*/
|
2023-01-05 14:58:55 +02:00
|
|
|
std::unique_ptr<UserLock> acquireUserLock(uid_t nrIds, bool useUserNamespace);
|
2020-05-20 00:25:44 +03:00
|
|
|
|
2020-05-20 12:24:21 +03:00
|
|
|
bool useBuildUsers();
|
|
|
|
|
2020-05-20 00:25:44 +03:00
|
|
|
}
|