chiark / gitweb /
copy: adjust directory times after writing to the directory
[elogind.git] / src / basic / user-util.h
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
22 #include <stdbool.h>
23 #include <sys/types.h>
24 #include <unistd.h>
25
26 bool uid_is_valid(uid_t uid);
27
28 static inline bool gid_is_valid(gid_t gid) {
29         return uid_is_valid((uid_t) gid);
30 }
31
32 int parse_uid(const char *s, uid_t* ret_uid);
33
34 static inline int parse_gid(const char *s, gid_t *ret_gid) {
35         return parse_uid(s, (uid_t*) ret_gid);
36 }
37
38 #if 0 /// UNNEEDED by elogind
39 char* getlogname_malloc(void);
40 char* getusername_malloc(void);
41 #endif // 0
42
43 int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
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 #if 0 /// UNNEEDED by elogind
50 int in_gid(gid_t gid);
51 int in_group(const char *name);
52
53 int get_home_dir(char **ret);
54 int get_shell(char **_ret);
55 #endif // 0
56
57 int reset_uid_gid(void);
58
59 #if 0 /// UNNEEDED by elogind
60 int take_etc_passwd_lock(const char *root);
61 #endif // 0
62
63 #define UID_INVALID ((uid_t) -1)
64 #define GID_INVALID ((gid_t) -1)
65
66 /* The following macros add 1 when converting things, since UID 0 is a
67  * valid UID, while the pointer NULL is special */
68 #define PTR_TO_UID(p) ((uid_t) (((uintptr_t) (p))-1))
69 #define UID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1))
70
71 #define PTR_TO_GID(p) ((gid_t) (((uintptr_t) (p))-1))
72 #define GID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1))
73
74 static inline bool userns_supported(void) {
75         return access("/proc/self/uid_map", F_OK) >= 0;
76 }