2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2015-10-25 22:32:30 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2010 Lennart Poettering
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2016-08-19 05:19:10 +02:00
|
|
|
#include <stdint.h>
|
2015-11-18 22:46:33 +01:00
|
|
|
#include <sys/types.h>
|
2016-04-22 14:10:09 +02:00
|
|
|
#include <unistd.h>
|
2015-10-25 22:32:30 +01:00
|
|
|
|
|
|
|
bool uid_is_valid(uid_t uid);
|
|
|
|
|
|
|
|
static inline bool gid_is_valid(gid_t gid) {
|
|
|
|
return uid_is_valid((uid_t) gid);
|
|
|
|
}
|
|
|
|
|
|
|
|
int parse_uid(const char *s, uid_t* ret_uid);
|
|
|
|
|
|
|
|
static inline int parse_gid(const char *s, gid_t *ret_gid) {
|
|
|
|
return parse_uid(s, (uid_t*) ret_gid);
|
|
|
|
}
|
|
|
|
|
|
|
|
char* getlogname_malloc(void);
|
|
|
|
char* getusername_malloc(void);
|
|
|
|
|
|
|
|
int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
|
2016-08-25 10:24:10 +02:00
|
|
|
int get_user_creds_clean(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
|
2015-10-25 22:32:30 +01:00
|
|
|
int get_group_creds(const char **groupname, gid_t *gid);
|
|
|
|
|
|
|
|
char* uid_to_name(uid_t uid);
|
|
|
|
char* gid_to_name(gid_t gid);
|
|
|
|
|
|
|
|
int in_gid(gid_t gid);
|
|
|
|
int in_group(const char *name);
|
|
|
|
|
|
|
|
int get_home_dir(char **ret);
|
|
|
|
int get_shell(char **_ret);
|
|
|
|
|
|
|
|
int reset_uid_gid(void);
|
2015-10-26 19:08:09 +01:00
|
|
|
|
|
|
|
int take_etc_passwd_lock(const char *root);
|
2015-10-27 00:42:07 +01:00
|
|
|
|
|
|
|
#define UID_INVALID ((uid_t) -1)
|
|
|
|
#define GID_INVALID ((gid_t) -1)
|
|
|
|
|
2017-12-04 17:06:56 +01:00
|
|
|
#define UID_NOBODY ((uid_t) 65534U)
|
|
|
|
#define GID_NOBODY ((gid_t) 65534U)
|
|
|
|
|
2016-08-19 05:19:10 +02:00
|
|
|
static inline bool uid_is_dynamic(uid_t uid) {
|
|
|
|
return DYNAMIC_UID_MIN <= uid && uid <= DYNAMIC_UID_MAX;
|
|
|
|
}
|
|
|
|
|
2017-12-02 13:07:18 +01:00
|
|
|
static inline bool gid_is_dynamic(gid_t gid) {
|
|
|
|
return uid_is_dynamic((uid_t) gid);
|
|
|
|
}
|
|
|
|
|
2017-12-02 12:59:21 +01:00
|
|
|
static inline bool uid_is_system(uid_t uid) {
|
|
|
|
return uid <= SYSTEM_UID_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool gid_is_system(gid_t gid) {
|
|
|
|
return gid <= SYSTEM_GID_MAX;
|
|
|
|
}
|
|
|
|
|
2016-08-19 05:19:10 +02:00
|
|
|
/* The following macros add 1 when converting things, since UID 0 is a valid UID, while the pointer
|
|
|
|
* NULL is special */
|
2015-10-27 00:42:07 +01:00
|
|
|
#define PTR_TO_UID(p) ((uid_t) (((uintptr_t) (p))-1))
|
|
|
|
#define UID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1))
|
|
|
|
|
|
|
|
#define PTR_TO_GID(p) ((gid_t) (((uintptr_t) (p))-1))
|
|
|
|
#define GID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1))
|
2016-04-22 14:10:09 +02:00
|
|
|
|
|
|
|
static inline bool userns_supported(void) {
|
|
|
|
return access("/proc/self/uid_map", F_OK) >= 0;
|
|
|
|
}
|
2016-07-14 12:23:39 +02:00
|
|
|
|
|
|
|
bool valid_user_group_name(const char *u);
|
|
|
|
bool valid_user_group_name_or_id(const char *u);
|
|
|
|
bool valid_gecos(const char *d);
|
|
|
|
bool valid_home(const char *p);
|
2016-09-28 18:37:39 +02:00
|
|
|
|
|
|
|
int maybe_setgroups(size_t size, const gid_t *list);
|
2018-01-10 18:26:03 +01:00
|
|
|
|
|
|
|
bool synthesize_nobody(void);
|