]>
Commit | Line | Data |
---|---|---|
b1d4f8e1 LP |
1 | #pragma once |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2010 Lennart Poettering | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
b1d4f8e1 | 22 | #include <stdbool.h> |
61755fda | 23 | #include <stdint.h> |
71d35b6b | 24 | #include <sys/types.h> |
ccabee0d | 25 | #include <unistd.h> |
b1d4f8e1 LP |
26 | |
27 | bool uid_is_valid(uid_t uid); | |
28 | ||
29 | static inline bool gid_is_valid(gid_t gid) { | |
30 | return uid_is_valid((uid_t) gid); | |
31 | } | |
32 | ||
33 | int parse_uid(const char *s, uid_t* ret_uid); | |
34 | ||
35 | static inline int parse_gid(const char *s, gid_t *ret_gid) { | |
36 | return parse_uid(s, (uid_t*) ret_gid); | |
37 | } | |
38 | ||
b1d4f8e1 LP |
39 | char* getlogname_malloc(void); |
40 | char* getusername_malloc(void); | |
41 | ||
42 | int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell); | |
be39ccf3 | 43 | int get_user_creds_clean(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell); |
b1d4f8e1 LP |
44 | int get_group_creds(const char **groupname, gid_t *gid); |
45 | ||
46 | char* uid_to_name(uid_t uid); | |
47 | char* gid_to_name(gid_t gid); | |
48 | ||
49 | int in_gid(gid_t gid); | |
50 | int in_group(const char *name); | |
51 | ||
52 | int get_home_dir(char **ret); | |
53 | int get_shell(char **_ret); | |
54 | ||
55 | int reset_uid_gid(void); | |
e929bee0 LP |
56 | |
57 | int take_etc_passwd_lock(const char *root); | |
ee104e11 LP |
58 | |
59 | #define UID_INVALID ((uid_t) -1) | |
60 | #define GID_INVALID ((gid_t) -1) | |
61 | ||
61755fda ZJS |
62 | /* Let's pick a UIDs within the 16bit range, so that we are compatible with containers using 16bit |
63 | * user namespacing. At least on Fedora normal users are allocated until UID 60000, hence do not | |
64 | * allocate from below this. Also stay away from the upper end of the range as that is often used | |
65 | * for overflow/nobody users. */ | |
66 | #define DYNAMIC_UID_MIN ((uid_t) UINT32_C(0x0000EF00)) | |
67 | #define DYNAMIC_UID_MAX ((uid_t) UINT32_C(0x0000FFEF)) | |
68 | ||
69 | static inline bool uid_is_dynamic(uid_t uid) { | |
70 | return DYNAMIC_UID_MIN <= uid && uid <= DYNAMIC_UID_MAX; | |
71 | } | |
72 | ||
73 | /* The following macros add 1 when converting things, since UID 0 is a valid UID, while the pointer | |
74 | * NULL is special */ | |
ee104e11 LP |
75 | #define PTR_TO_UID(p) ((uid_t) (((uintptr_t) (p))-1)) |
76 | #define UID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1)) | |
77 | ||
78 | #define PTR_TO_GID(p) ((gid_t) (((uintptr_t) (p))-1)) | |
79 | #define GID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1)) | |
ccabee0d LP |
80 | |
81 | static inline bool userns_supported(void) { | |
82 | return access("/proc/self/uid_map", F_OK) >= 0; | |
83 | } | |
e4631b48 LP |
84 | |
85 | bool valid_user_group_name(const char *u); | |
86 | bool valid_user_group_name_or_id(const char *u); | |
87 | bool valid_gecos(const char *d); | |
88 | bool valid_home(const char *p); | |
36d85478 GS |
89 | |
90 | int maybe_setgroups(size_t size, const gid_t *list); |