aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/lock.hh
blob: ac5ff061b6fd90ffb925fadfd7840662addc9182 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
///@file

#include <memory>

#include <sys/types.h>
#include <vector>

namespace nix {

struct UserLock
{
    virtual ~UserLock() { }

    /**
     * Get the first and last UID.
     */
    std::pair<uid_t, uid_t> getUIDRange()
    {
        auto first = getUID();
        return {first, first + getUIDCount() - 1};
    }

    /**
     * Get the first UID.
     */
    virtual uid_t getUID() = 0;

    virtual uid_t getUIDCount() = 0;

    virtual gid_t getGID() = 0;

    virtual std::vector<gid_t> getSupplementaryGIDs() = 0;
};

/**
 * 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, bool useUserNamespace);

bool useBuildUsers();

}