/src/systemd/src/basic/uid-classification.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
2 | | #pragma once |
3 | | |
4 | | #include "forward.h" |
5 | | |
6 | | /* The container base should have the last 16 bit set to zero */ |
7 | | assert_cc((CONTAINER_UID_BASE_MIN & 0xFFFFU) == 0); |
8 | | assert_cc((CONTAINER_UID_BASE_MAX & 0xFFFFU) == 0); |
9 | | |
10 | | /* Given we assign 64K UIDs to containers, the last container UID is 0xFFFF larger than the base */ |
11 | | #define CONTAINER_UID_MIN (CONTAINER_UID_BASE_MIN) |
12 | | #define CONTAINER_UID_MAX (CONTAINER_UID_BASE_MAX + 0xFFFFU) |
13 | | |
14 | | assert_cc((FOREIGN_UID_BASE & 0xFFFFU) == 0); |
15 | | #define FOREIGN_UID_MIN (FOREIGN_UID_BASE) |
16 | | #define FOREIGN_UID_MAX (FOREIGN_UID_BASE + 0xFFFFU) |
17 | | |
18 | | bool uid_is_system(uid_t uid); |
19 | | bool gid_is_system(gid_t gid); |
20 | | |
21 | 0 | static inline bool uid_is_greeter(uid_t uid) { |
22 | 0 | return GREETER_UID_MIN <= uid && uid <= GREETER_UID_MAX; |
23 | 0 | } |
24 | | |
25 | 0 | static inline bool uid_is_dynamic(uid_t uid) { |
26 | 0 | return DYNAMIC_UID_MIN <= uid && uid <= DYNAMIC_UID_MAX; |
27 | 0 | } |
28 | | |
29 | 0 | static inline bool gid_is_dynamic(gid_t gid) { |
30 | 0 | return uid_is_dynamic((uid_t) gid); |
31 | 0 | } |
32 | | |
33 | 0 | static inline bool uid_is_container(uid_t uid) { |
34 | 0 | return CONTAINER_UID_MIN <= uid && uid <= CONTAINER_UID_MAX; |
35 | 0 | } |
36 | | |
37 | 0 | static inline bool gid_is_container(gid_t gid) { |
38 | 0 | return uid_is_container((uid_t) gid); |
39 | 0 | } |
40 | | |
41 | 0 | static inline bool uid_is_foreign(uid_t uid) { |
42 | 0 | return FOREIGN_UID_MIN <= uid && uid <= FOREIGN_UID_MAX; |
43 | 0 | } |
44 | | |
45 | 0 | static inline bool gid_is_foreign(gid_t gid) { |
46 | 0 | return uid_is_foreign((uid_t) gid); |
47 | 0 | } |
48 | | |
49 | | typedef struct UGIDAllocationRange { |
50 | | uid_t system_alloc_uid_min; |
51 | | uid_t system_uid_max; |
52 | | gid_t system_alloc_gid_min; |
53 | | gid_t system_gid_max; |
54 | | } UGIDAllocationRange; |
55 | | |
56 | | int read_login_defs(UGIDAllocationRange *ret_defs, const char *path, const char *root); |
57 | | const UGIDAllocationRange *acquire_ugid_allocation_range(void); |
58 | | |
59 | | bool uid_for_system_journal(uid_t uid); |