]> git.proxmox.com Git - systemd.git/blame - src/basic/user-util.h
Imported Upstream version 229
[systemd.git] / src / basic / user-util.h
CommitLineData
db2df898
MP
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
db2df898 22#include <stdbool.h>
4c89c718 23#include <sys/types.h>
db2df898
MP
24
25bool uid_is_valid(uid_t uid);
26
27static inline bool gid_is_valid(gid_t gid) {
28 return uid_is_valid((uid_t) gid);
29}
30
31int parse_uid(const char *s, uid_t* ret_uid);
32
33static inline int parse_gid(const char *s, gid_t *ret_gid) {
34 return parse_uid(s, (uid_t*) ret_gid);
35}
36
37char* getlogname_malloc(void);
38char* getusername_malloc(void);
39
40int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
41int get_group_creds(const char **groupname, gid_t *gid);
42
43char* uid_to_name(uid_t uid);
44char* gid_to_name(gid_t gid);
45
46int in_gid(gid_t gid);
47int in_group(const char *name);
48
49int get_home_dir(char **ret);
50int get_shell(char **_ret);
51
52int reset_uid_gid(void);
53
54int take_etc_passwd_lock(const char *root);
55
56#define UID_INVALID ((uid_t) -1)
57#define GID_INVALID ((gid_t) -1)
58
59/* The following macros add 1 when converting things, since UID 0 is a
60 * valid UID, while the pointer NULL is special */
61#define PTR_TO_UID(p) ((uid_t) (((uintptr_t) (p))-1))
62#define UID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1))
63
64#define PTR_TO_GID(p) ((gid_t) (((uintptr_t) (p))-1))
65#define GID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1))