user-util.h revision d02608170e599b1ffbc7c9a22062bae2579d6e36
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#pragma once
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen/***
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen This file is part of systemd.
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen Copyright 2010 Lennart Poettering
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen systemd is free software; you can redistribute it and/or modify it
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen under the terms of the GNU Lesser General Public License as published by
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen the Free Software Foundation; either version 2.1 of the License, or
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen (at your option) any later version.
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen systemd is distributed in the hope that it will be useful, but
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen Lesser General Public License for more details.
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen You should have received a copy of the GNU Lesser General Public License
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen***/
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#include <sys/types.h>
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#include <stdbool.h>
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poetteringbool uid_is_valid(uid_t uid);
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poetteringstatic inline bool gid_is_valid(gid_t gid) {
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering return uid_is_valid((uid_t) gid);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen}
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenint parse_uid(const char *s, uid_t* ret_uid);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenstatic inline int parse_gid(const char *s, gid_t *ret_gid) {
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering return parse_uid(s, (uid_t*) ret_gid);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen}
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenchar* getlogname_malloc(void);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenchar* getusername_malloc(void);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenint get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenint get_group_creds(const char **groupname, gid_t *gid);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenchar* uid_to_name(uid_t uid);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenchar* gid_to_name(gid_t gid);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenint in_gid(gid_t gid);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenint in_group(const char *name);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenint get_home_dir(char **ret);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenint get_shell(char **_ret);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenint reset_uid_gid(void);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen