]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util-lib: split out user/group/uid/gid calls into user-util.[ch]
authorLennart Poettering <lennart@poettering.net>
Sun, 25 Oct 2015 21:32:30 +0000 (22:32 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 26 Oct 2015 00:24:38 +0000 (01:24 +0100)
54 files changed:
Makefile.am
src/basic/audit.c
src/basic/cgroup-util.c
src/basic/process-util.c
src/basic/user-util.c [new file with mode: 0644]
src/basic/user-util.h [new file with mode: 0644]
src/basic/util.c
src/basic/util.h
src/bus-proxyd/bus-proxyd.c
src/bus-proxyd/bus-xml-policy.c
src/bus-proxyd/stdio-bridge.c
src/core/bus-policy.c
src/core/execute.c
src/core/main.c
src/core/socket.c
src/core/timer.c
src/core/unit-printf.c
src/core/unit.c
src/journal/coredump-vacuum.c
src/journal/coredump.c
src/journal/coredumpctl.c
src/journal/journalctl.c
src/libsystemd/sd-bus/bus-socket.c
src/libsystemd/sd-bus/busctl.c
src/libsystemd/sd-login/sd-login.c
src/libsystemd/sd-path/sd-path.c
src/login/inhibit.c
src/login/loginctl.c
src/login/logind-action.c
src/login/logind-core.c
src/login/logind-dbus.c
src/login/logind-inhibit.c
src/login/logind-session.c
src/login/logind-user-dbus.c
src/login/logind-utmp.c
src/machine/machined-dbus.c
src/network/networkd-netdev-tuntap.c
src/network/networkd.c
src/nspawn/nspawn-setuid.c
src/nspawn/nspawn.c
src/nss-mymachines/nss-mymachines.c
src/resolve/resolved.c
src/run/run.c
src/shared/acl-util.c
src/shared/install-printf.c
src/shared/uid-range.c
src/shared/utmp-wtmp.c
src/systemctl/systemctl.c
src/sysusers/sysusers.c
src/test/test-ipcrm.c
src/test/test-util.c
src/timesync/timesyncd.c
src/tmpfiles/tmpfiles.c
src/udev/udev-rules.c

index 459d54460cad775588ec8e2051a8a2ec2282a9d7..69a2b732d0970d49d9d7285fc415fe86669d1474 100644 (file)
@@ -787,6 +787,8 @@ libbasic_la_SOURCES = \
        src/basic/string-util.h \
        src/basic/fd-util.c \
        src/basic/fd-util.h \
+       src/basic/user-util.c \
+       src/basic/user-util.h \
        src/basic/extract-word.c \
        src/basic/extract-word.h \
        src/basic/escape.c \
index af43ec809745a4af577389d9908e13c4bf675620..c9b762151a2c038a1af789cd2228e41df85e48f5 100644 (file)
@@ -27,6 +27,7 @@
 #include "fileio.h"
 #include "macro.h"
 #include "process-util.h"
+#include "user-util.h"
 #include "util.h"
 
 int audit_session_from_pid(pid_t pid, uint32_t *id) {
index 958497543afdc154e14d52d16e2e628a148a9d4c..4af991200c8c6a7c0177eb1bebac03a2faea5ccf 100644 (file)
@@ -43,6 +43,7 @@
 #include "special.h"
 #include "string-util.h"
 #include "unit-name.h"
+#include "user-util.h"
 #include "util.h"
 
 int cg_enumerate_processes(const char *controller, const char *path, FILE **_f) {
index 949bd1f64d933afb1342fa932d1289e65cee77d4..65c93792fbfdae101ab2b94f8462467b35562a08 100644 (file)
@@ -35,6 +35,7 @@
 #include "process-util.h"
 #include "signal-util.h"
 #include "string-util.h"
+#include "user-util.h"
 #include "util.h"
 
 int get_process_state(pid_t pid) {
diff --git a/src/basic/user-util.c b/src/basic/user-util.c
new file mode 100644 (file)
index 0000000..637391f
--- /dev/null
@@ -0,0 +1,403 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  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 <pwd.h>
+#include <grp.h>
+
+#include "user-util.h"
+#include "macro.h"
+#include "util.h"
+#include "string-util.h"
+#include "path-util.h"
+
+bool uid_is_valid(uid_t uid) {
+
+        /* Some libc APIs use UID_INVALID as special placeholder */
+        if (uid == (uid_t) 0xFFFFFFFF)
+                return false;
+
+        /* A long time ago UIDs where 16bit, hence explicitly avoid the 16bit -1 too */
+        if (uid == (uid_t) 0xFFFF)
+                return false;
+
+        return true;
+}
+
+int parse_uid(const char *s, uid_t* ret_uid) {
+        unsigned long ul = 0;
+        uid_t uid;
+        int r;
+
+        assert(s);
+
+        r = safe_atolu(s, &ul);
+        if (r < 0)
+                return r;
+
+        uid = (uid_t) ul;
+
+        if ((unsigned long) uid != ul)
+                return -ERANGE;
+
+        if (!uid_is_valid(uid))
+                return -ENXIO; /* we return ENXIO instead of EINVAL
+                                * here, to make it easy to distuingish
+                                * invalid numeric uids invalid
+                                * strings. */
+
+        if (ret_uid)
+                *ret_uid = uid;
+
+        return 0;
+}
+
+char *lookup_uid(uid_t uid) {
+        long bufsize;
+        char *name;
+        _cleanup_free_ char *buf = NULL;
+        struct passwd pwbuf, *pw = NULL;
+
+        /* Shortcut things to avoid NSS lookups */
+        if (uid == 0)
+                return strdup("root");
+
+        bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
+        if (bufsize <= 0)
+                bufsize = 4096;
+
+        buf = malloc(bufsize);
+        if (!buf)
+                return NULL;
+
+        if (getpwuid_r(uid, &pwbuf, buf, bufsize, &pw) == 0 && pw)
+                return strdup(pw->pw_name);
+
+        if (asprintf(&name, UID_FMT, uid) < 0)
+                return NULL;
+
+        return name;
+}
+
+char* getlogname_malloc(void) {
+        uid_t uid;
+        struct stat st;
+
+        if (isatty(STDIN_FILENO) && fstat(STDIN_FILENO, &st) >= 0)
+                uid = st.st_uid;
+        else
+                uid = getuid();
+
+        return lookup_uid(uid);
+}
+
+char *getusername_malloc(void) {
+        const char *e;
+
+        e = getenv("USER");
+        if (e)
+                return strdup(e);
+
+        return lookup_uid(getuid());
+}
+
+int get_user_creds(
+                const char **username,
+                uid_t *uid, gid_t *gid,
+                const char **home,
+                const char **shell) {
+
+        struct passwd *p;
+        uid_t u;
+
+        assert(username);
+        assert(*username);
+
+        /* We enforce some special rules for uid=0: in order to avoid
+         * NSS lookups for root we hardcode its data. */
+
+        if (streq(*username, "root") || streq(*username, "0")) {
+                *username = "root";
+
+                if (uid)
+                        *uid = 0;
+
+                if (gid)
+                        *gid = 0;
+
+                if (home)
+                        *home = "/root";
+
+                if (shell)
+                        *shell = "/bin/sh";
+
+                return 0;
+        }
+
+        if (parse_uid(*username, &u) >= 0) {
+                errno = 0;
+                p = getpwuid(u);
+
+                /* If there are multiple users with the same id, make
+                 * sure to leave $USER to the configured value instead
+                 * of the first occurrence in the database. However if
+                 * the uid was configured by a numeric uid, then let's
+                 * pick the real username from /etc/passwd. */
+                if (p)
+                        *username = p->pw_name;
+        } else {
+                errno = 0;
+                p = getpwnam(*username);
+        }
+
+        if (!p)
+                return errno > 0 ? -errno : -ESRCH;
+
+        if (uid)
+                *uid = p->pw_uid;
+
+        if (gid)
+                *gid = p->pw_gid;
+
+        if (home)
+                *home = p->pw_dir;
+
+        if (shell)
+                *shell = p->pw_shell;
+
+        return 0;
+}
+
+int get_group_creds(const char **groupname, gid_t *gid) {
+        struct group *g;
+        gid_t id;
+
+        assert(groupname);
+
+        /* We enforce some special rules for gid=0: in order to avoid
+         * NSS lookups for root we hardcode its data. */
+
+        if (streq(*groupname, "root") || streq(*groupname, "0")) {
+                *groupname = "root";
+
+                if (gid)
+                        *gid = 0;
+
+                return 0;
+        }
+
+        if (parse_gid(*groupname, &id) >= 0) {
+                errno = 0;
+                g = getgrgid(id);
+
+                if (g)
+                        *groupname = g->gr_name;
+        } else {
+                errno = 0;
+                g = getgrnam(*groupname);
+        }
+
+        if (!g)
+                return errno > 0 ? -errno : -ESRCH;
+
+        if (gid)
+                *gid = g->gr_gid;
+
+        return 0;
+}
+
+char* uid_to_name(uid_t uid) {
+        struct passwd *p;
+        char *r;
+
+        if (uid == 0)
+                return strdup("root");
+
+        p = getpwuid(uid);
+        if (p)
+                return strdup(p->pw_name);
+
+        if (asprintf(&r, UID_FMT, uid) < 0)
+                return NULL;
+
+        return r;
+}
+
+char* gid_to_name(gid_t gid) {
+        struct group *p;
+        char *r;
+
+        if (gid == 0)
+                return strdup("root");
+
+        p = getgrgid(gid);
+        if (p)
+                return strdup(p->gr_name);
+
+        if (asprintf(&r, GID_FMT, gid) < 0)
+                return NULL;
+
+        return r;
+}
+
+int in_gid(gid_t gid) {
+        gid_t *gids;
+        int ngroups_max, r, i;
+
+        if (getgid() == gid)
+                return 1;
+
+        if (getegid() == gid)
+                return 1;
+
+        ngroups_max = sysconf(_SC_NGROUPS_MAX);
+        assert(ngroups_max > 0);
+
+        gids = alloca(sizeof(gid_t) * ngroups_max);
+
+        r = getgroups(ngroups_max, gids);
+        if (r < 0)
+                return -errno;
+
+        for (i = 0; i < r; i++)
+                if (gids[i] == gid)
+                        return 1;
+
+        return 0;
+}
+
+int in_group(const char *name) {
+        int r;
+        gid_t gid;
+
+        r = get_group_creds(&name, &gid);
+        if (r < 0)
+                return r;
+
+        return in_gid(gid);
+}
+
+int get_home_dir(char **_h) {
+        struct passwd *p;
+        const char *e;
+        char *h;
+        uid_t u;
+
+        assert(_h);
+
+        /* Take the user specified one */
+        e = secure_getenv("HOME");
+        if (e && path_is_absolute(e)) {
+                h = strdup(e);
+                if (!h)
+                        return -ENOMEM;
+
+                *_h = h;
+                return 0;
+        }
+
+        /* Hardcode home directory for root to avoid NSS */
+        u = getuid();
+        if (u == 0) {
+                h = strdup("/root");
+                if (!h)
+                        return -ENOMEM;
+
+                *_h = h;
+                return 0;
+        }
+
+        /* Check the database... */
+        errno = 0;
+        p = getpwuid(u);
+        if (!p)
+                return errno > 0 ? -errno : -ESRCH;
+
+        if (!path_is_absolute(p->pw_dir))
+                return -EINVAL;
+
+        h = strdup(p->pw_dir);
+        if (!h)
+                return -ENOMEM;
+
+        *_h = h;
+        return 0;
+}
+
+int get_shell(char **_s) {
+        struct passwd *p;
+        const char *e;
+        char *s;
+        uid_t u;
+
+        assert(_s);
+
+        /* Take the user specified one */
+        e = getenv("SHELL");
+        if (e) {
+                s = strdup(e);
+                if (!s)
+                        return -ENOMEM;
+
+                *_s = s;
+                return 0;
+        }
+
+        /* Hardcode home directory for root to avoid NSS */
+        u = getuid();
+        if (u == 0) {
+                s = strdup("/bin/sh");
+                if (!s)
+                        return -ENOMEM;
+
+                *_s = s;
+                return 0;
+        }
+
+        /* Check the database... */
+        errno = 0;
+        p = getpwuid(u);
+        if (!p)
+                return errno > 0 ? -errno : -ESRCH;
+
+        if (!path_is_absolute(p->pw_shell))
+                return -EINVAL;
+
+        s = strdup(p->pw_shell);
+        if (!s)
+                return -ENOMEM;
+
+        *_s = s;
+        return 0;
+}
+
+int reset_uid_gid(void) {
+
+        if (setgroups(0, NULL) < 0)
+                return -errno;
+
+        if (setresgid(0, 0, 0) < 0)
+                return -errno;
+
+        if (setresuid(0, 0, 0) < 0)
+                return -errno;
+
+        return 0;
+}
diff --git a/src/basic/user-util.h b/src/basic/user-util.h
new file mode 100644 (file)
index 0000000..9263ede
--- /dev/null
@@ -0,0 +1,55 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#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 <sys/types.h>
+#include <stdbool.h>
+
+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* lookup_uid(uid_t uid);
+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);
+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);
index c02dfc5bc961267d2949d3a3df77c3f820471b81..010261b37d2e3449e7094a228c7f04cb76700144 100644 (file)
@@ -98,6 +98,7 @@
 #include "string-util.h"
 #include "strv.h"
 #include "terminal-util.h"
+#include "user-util.h"
 #include "utf8.h"
 #include "util.h"
 #include "virt.h"
@@ -168,47 +169,6 @@ int parse_pid(const char *s, pid_t* ret_pid) {
         return 0;
 }
 
-bool uid_is_valid(uid_t uid) {
-
-        /* Some libc APIs use UID_INVALID as special placeholder */
-        if (uid == (uid_t) 0xFFFFFFFF)
-                return false;
-
-        /* A long time ago UIDs where 16bit, hence explicitly avoid the 16bit -1 too */
-        if (uid == (uid_t) 0xFFFF)
-                return false;
-
-        return true;
-}
-
-int parse_uid(const char *s, uid_t* ret_uid) {
-        unsigned long ul = 0;
-        uid_t uid;
-        int r;
-
-        assert(s);
-
-        r = safe_atolu(s, &ul);
-        if (r < 0)
-                return r;
-
-        uid = (uid_t) ul;
-
-        if ((unsigned long) uid != ul)
-                return -ERANGE;
-
-        if (!uid_is_valid(uid))
-                return -ENXIO; /* we return ENXIO instead of EINVAL
-                                * here, to make it easy to distuingish
-                                * invalid numeric uids invalid
-                                * strings. */
-
-        if (ret_uid)
-                *ret_uid = uid;
-
-        return 0;
-}
-
 int safe_atou(const char *s, unsigned *ret_u) {
         char *x = NULL;
         unsigned long l;
@@ -1437,55 +1397,6 @@ void rename_process(const char name[8]) {
         }
 }
 
-char *lookup_uid(uid_t uid) {
-        long bufsize;
-        char *name;
-        _cleanup_free_ char *buf = NULL;
-        struct passwd pwbuf, *pw = NULL;
-
-        /* Shortcut things to avoid NSS lookups */
-        if (uid == 0)
-                return strdup("root");
-
-        bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
-        if (bufsize <= 0)
-                bufsize = 4096;
-
-        buf = malloc(bufsize);
-        if (!buf)
-                return NULL;
-
-        if (getpwuid_r(uid, &pwbuf, buf, bufsize, &pw) == 0 && pw)
-                return strdup(pw->pw_name);
-
-        if (asprintf(&name, UID_FMT, uid) < 0)
-                return NULL;
-
-        return name;
-}
-
-char* getlogname_malloc(void) {
-        uid_t uid;
-        struct stat st;
-
-        if (isatty(STDIN_FILENO) && fstat(STDIN_FILENO, &st) >= 0)
-                uid = st.st_uid;
-        else
-                uid = getuid();
-
-        return lookup_uid(uid);
-}
-
-char *getusername_malloc(void) {
-        const char *e;
-
-        e = getenv("USER");
-        if (e)
-                return strdup(e);
-
-        return lookup_uid(getuid());
-}
-
 bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) {
         assert(s);
         assert_cc(sizeof(statfs_f_type_t) >= sizeof(s->f_type));
@@ -2074,182 +1985,6 @@ int socket_from_display(const char *display, char **path) {
         return 0;
 }
 
-int get_user_creds(
-                const char **username,
-                uid_t *uid, gid_t *gid,
-                const char **home,
-                const char **shell) {
-
-        struct passwd *p;
-        uid_t u;
-
-        assert(username);
-        assert(*username);
-
-        /* We enforce some special rules for uid=0: in order to avoid
-         * NSS lookups for root we hardcode its data. */
-
-        if (streq(*username, "root") || streq(*username, "0")) {
-                *username = "root";
-
-                if (uid)
-                        *uid = 0;
-
-                if (gid)
-                        *gid = 0;
-
-                if (home)
-                        *home = "/root";
-
-                if (shell)
-                        *shell = "/bin/sh";
-
-                return 0;
-        }
-
-        if (parse_uid(*username, &u) >= 0) {
-                errno = 0;
-                p = getpwuid(u);
-
-                /* If there are multiple users with the same id, make
-                 * sure to leave $USER to the configured value instead
-                 * of the first occurrence in the database. However if
-                 * the uid was configured by a numeric uid, then let's
-                 * pick the real username from /etc/passwd. */
-                if (p)
-                        *username = p->pw_name;
-        } else {
-                errno = 0;
-                p = getpwnam(*username);
-        }
-
-        if (!p)
-                return errno > 0 ? -errno : -ESRCH;
-
-        if (uid)
-                *uid = p->pw_uid;
-
-        if (gid)
-                *gid = p->pw_gid;
-
-        if (home)
-                *home = p->pw_dir;
-
-        if (shell)
-                *shell = p->pw_shell;
-
-        return 0;
-}
-
-char* uid_to_name(uid_t uid) {
-        struct passwd *p;
-        char *r;
-
-        if (uid == 0)
-                return strdup("root");
-
-        p = getpwuid(uid);
-        if (p)
-                return strdup(p->pw_name);
-
-        if (asprintf(&r, UID_FMT, uid) < 0)
-                return NULL;
-
-        return r;
-}
-
-char* gid_to_name(gid_t gid) {
-        struct group *p;
-        char *r;
-
-        if (gid == 0)
-                return strdup("root");
-
-        p = getgrgid(gid);
-        if (p)
-                return strdup(p->gr_name);
-
-        if (asprintf(&r, GID_FMT, gid) < 0)
-                return NULL;
-
-        return r;
-}
-
-int get_group_creds(const char **groupname, gid_t *gid) {
-        struct group *g;
-        gid_t id;
-
-        assert(groupname);
-
-        /* We enforce some special rules for gid=0: in order to avoid
-         * NSS lookups for root we hardcode its data. */
-
-        if (streq(*groupname, "root") || streq(*groupname, "0")) {
-                *groupname = "root";
-
-                if (gid)
-                        *gid = 0;
-
-                return 0;
-        }
-
-        if (parse_gid(*groupname, &id) >= 0) {
-                errno = 0;
-                g = getgrgid(id);
-
-                if (g)
-                        *groupname = g->gr_name;
-        } else {
-                errno = 0;
-                g = getgrnam(*groupname);
-        }
-
-        if (!g)
-                return errno > 0 ? -errno : -ESRCH;
-
-        if (gid)
-                *gid = g->gr_gid;
-
-        return 0;
-}
-
-int in_gid(gid_t gid) {
-        gid_t *gids;
-        int ngroups_max, r, i;
-
-        if (getgid() == gid)
-                return 1;
-
-        if (getegid() == gid)
-                return 1;
-
-        ngroups_max = sysconf(_SC_NGROUPS_MAX);
-        assert(ngroups_max > 0);
-
-        gids = alloca(sizeof(gid_t) * ngroups_max);
-
-        r = getgroups(ngroups_max, gids);
-        if (r < 0)
-                return -errno;
-
-        for (i = 0; i < r; i++)
-                if (gids[i] == gid)
-                        return 1;
-
-        return 0;
-}
-
-int in_group(const char *name) {
-        int r;
-        gid_t gid;
-
-        r = get_group_creds(&name, &gid);
-        if (r < 0)
-                return r;
-
-        return in_gid(gid);
-}
-
 int glob_exists(const char *path) {
         _cleanup_globfree_ glob_t g = {};
         int k;
@@ -2864,100 +2599,6 @@ bool in_initrd(void) {
         return saved;
 }
 
-int get_home_dir(char **_h) {
-        struct passwd *p;
-        const char *e;
-        char *h;
-        uid_t u;
-
-        assert(_h);
-
-        /* Take the user specified one */
-        e = secure_getenv("HOME");
-        if (e && path_is_absolute(e)) {
-                h = strdup(e);
-                if (!h)
-                        return -ENOMEM;
-
-                *_h = h;
-                return 0;
-        }
-
-        /* Hardcode home directory for root to avoid NSS */
-        u = getuid();
-        if (u == 0) {
-                h = strdup("/root");
-                if (!h)
-                        return -ENOMEM;
-
-                *_h = h;
-                return 0;
-        }
-
-        /* Check the database... */
-        errno = 0;
-        p = getpwuid(u);
-        if (!p)
-                return errno > 0 ? -errno : -ESRCH;
-
-        if (!path_is_absolute(p->pw_dir))
-                return -EINVAL;
-
-        h = strdup(p->pw_dir);
-        if (!h)
-                return -ENOMEM;
-
-        *_h = h;
-        return 0;
-}
-
-int get_shell(char **_s) {
-        struct passwd *p;
-        const char *e;
-        char *s;
-        uid_t u;
-
-        assert(_s);
-
-        /* Take the user specified one */
-        e = getenv("SHELL");
-        if (e) {
-                s = strdup(e);
-                if (!s)
-                        return -ENOMEM;
-
-                *_s = s;
-                return 0;
-        }
-
-        /* Hardcode home directory for root to avoid NSS */
-        u = getuid();
-        if (u == 0) {
-                s = strdup("/bin/sh");
-                if (!s)
-                        return -ENOMEM;
-
-                *_s = s;
-                return 0;
-        }
-
-        /* Check the database... */
-        errno = 0;
-        p = getpwuid(u);
-        if (!p)
-                return errno > 0 ? -errno : -ESRCH;
-
-        if (!path_is_absolute(p->pw_shell))
-                return -EINVAL;
-
-        s = strdup(p->pw_shell);
-        if (!s)
-                return -ENOMEM;
-
-        *_s = s;
-        return 0;
-}
-
 bool filename_is_valid(const char *p) {
 
         if (isempty(p))
@@ -4631,20 +4272,6 @@ int mount_move_root(const char *path) {
         return 0;
 }
 
-int reset_uid_gid(void) {
-
-        if (setgroups(0, NULL) < 0)
-                return -errno;
-
-        if (setresgid(0, 0, 0) < 0)
-                return -errno;
-
-        if (setresuid(0, 0, 0) < 0)
-                return -errno;
-
-        return 0;
-}
-
 int getxattr_malloc(const char *path, const char *name, char **value, bool allow_symlink) {
         char *v;
         size_t l;
index 1a56257cce98b2c34fa90808a0d234d44399c2d6..7d6412523c96039d14bcfa61a0f67e3a98ccd684 100644 (file)
@@ -91,14 +91,7 @@ int parse_size(const char *t, uint64_t base, uint64_t *size);
 
 int parse_boolean(const char *v) _pure_;
 int parse_pid(const char *s, pid_t* ret_pid);
-int parse_uid(const char *s, uid_t* ret_uid);
-#define parse_gid(s, ret_gid) parse_uid(s, ret_gid)
 
-bool uid_is_valid(uid_t uid);
-
-static inline bool gid_is_valid(gid_t gid) {
-        return uid_is_valid((uid_t) gid);
-}
 
 int safe_atou(const char *s, unsigned *ret_u);
 int safe_atoi(const char *s, int *ret_i);
@@ -252,10 +245,6 @@ static inline int dir_is_populated(const char *path) {
         return !r;
 }
 
-char* lookup_uid(uid_t uid);
-char* getlogname_malloc(void);
-char* getusername_malloc(void);
-
 int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
 int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid);
 
@@ -304,15 +293,6 @@ int fchmod_umask(int fd, mode_t mode);
 bool display_is_local(const char *display) _pure_;
 int socket_from_display(const char *display, char **path);
 
-int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
-int get_group_creds(const char **groupname, gid_t *gid);
-
-int in_gid(gid_t gid);
-int in_group(const char *name);
-
-char* uid_to_name(uid_t uid);
-char* gid_to_name(gid_t gid);
-
 int glob_exists(const char *path);
 int glob_extend(char ***strv, const char *path);
 
@@ -378,9 +358,6 @@ bool http_etag_is_valid(const char *etag);
 
 bool in_initrd(void);
 
-int get_home_dir(char **ret);
-int get_shell(char **_ret);
-
 static inline void freep(void *p) {
         free(*(void**) p);
 }
@@ -720,8 +697,6 @@ int parse_mode(const char *s, mode_t *ret);
 
 int mount_move_root(const char *path);
 
-int reset_uid_gid(void);
-
 int getxattr_malloc(const char *path, const char *name, char **value, bool allow_symlink);
 int fgetxattr_malloc(int fd, const char *name, char **value);
 
index 1bbf984a2e7c7beec311d893a1c5aa3c129ec240..7e7574568c1dfc38cae1da3f77b236b27fd8da96 100644 (file)
@@ -43,6 +43,7 @@
 #include "proxy.h"
 #include "string-util.h"
 #include "strv.h"
+#include "user-util.h"
 #include "util.h"
 
 static char *arg_address = NULL;
index c5a1e09cf8506b691881c1e0fabd11c26b28cc84..56dcfeab62252cb5b47891adf6d4b292090ef7c0 100644 (file)
 #include "sd-login.h"
 
 #include "bus-internal.h"
+#include "bus-xml-policy.h"
 #include "conf-files.h"
 #include "fileio.h"
 #include "formats-util.h"
 #include "set.h"
 #include "string-util.h"
 #include "strv.h"
+#include "user-util.h"
 #include "xml.h"
-#include "bus-xml-policy.h"
 
 static void policy_item_free(PolicyItem *i) {
         assert(i);
index 168fc9ead03a3b72dcf90cfb7390df4998164fb0..a009ea76c4f1eeb31f246ef030da0da80de6a21b 100644 (file)
@@ -37,6 +37,7 @@
 #include "log.h"
 #include "proxy.h"
 #include "strv.h"
+#include "user-util.h"
 #include "util.h"
 
 static char *arg_address = NULL;
index a6a8fcd4d328966e53805d1d61c6e15ddd7adaba..2490903a8c21f095f57f94f09e864a4167eeb38a 100644 (file)
 
 #include <stdlib.h>
 
-#include "kdbus.h"
-#include "util.h"
 #include "bus-kernel.h"
 #include "bus-policy.h"
+#include "kdbus.h"
+#include "user-util.h"
+#include "util.h"
 
 int bus_kernel_translate_access(BusPolicyAccess access) {
         assert(access >= 0);
index 55da8ba4b72122f837315ab36fd81cc9500143b8..3f2607ff1a2537bc0a01838f615651d4e070205d 100644 (file)
@@ -90,6 +90,7 @@
 #include "strv.h"
 #include "terminal-util.h"
 #include "unit.h"
+#include "user-util.h"
 #include "util.h"
 #include "utmp-wtmp.h"
 
index 68ec730406f5a7ce94ee5788a340974faf1e0387..b0ca6fa10e0c77c4bc1b24b5e6405108afe9e93e 100644 (file)
@@ -76,6 +76,7 @@
 #include "strv.h"
 #include "switch-root.h"
 #include "terminal-util.h"
+#include "user-util.h"
 #include "virt.h"
 #include "watchdog.h"
 
index e2085dac1c6c6488a46c4f9cf8fdd2ac4ab2d02f..7f401025ed5f58c78040f40bf5ea0a30acb1671d 100644 (file)
@@ -54,6 +54,7 @@
 #include "unit-name.h"
 #include "unit-printf.h"
 #include "unit.h"
+#include "user-util.h"
 
 static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
         [SOCKET_DEAD] = UNIT_INACTIVE,
index 4548a4fa526539c61e7fac3e77826072b0e1d715..908d45ac7397b0600c252b8961b358d9ba7b7396 100644 (file)
 #include "dbus-timer.h"
 #include "special.h"
 #include "string-util.h"
+#include "timer.h"
 #include "unit-name.h"
 #include "unit.h"
-#include "timer.h"
+#include "user-util.h"
 
 static const UnitActiveState state_translation_table[_TIMER_STATE_MAX] = {
         [TIMER_DEAD] = UNIT_INACTIVE,
index 5b62f2d65cad3a51e0350985c4e7b79e5238b659..4a5c7efdb0ed3e3fe462ae1c8e6c94b8b88fa6e1 100644 (file)
@@ -26,8 +26,9 @@
 #include "string-util.h"
 #include "strv.h"
 #include "unit-name.h"
-#include "unit.h"
 #include "unit-printf.h"
+#include "unit.h"
+#include "user-util.h"
 
 static int specifier_prefix_and_instance(char specifier, void *data, void *userdata, char **ret) {
         Unit *u = userdata;
index a054cc79b06c9d4fffe76655e3eb83e634918a60..572b1c1b784220023a484cfc09205c63bd63b12f 100644 (file)
@@ -51,8 +51,9 @@
 #include "string-util.h"
 #include "strv.h"
 #include "unit-name.h"
-#include "virt.h"
 #include "unit.h"
+#include "user-util.h"
+#include "virt.h"
 
 const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX] = {
         [UNIT_SERVICE] = &service_vtable,
index 92259fd5ef0641c9ca0374a07ae6807e560492c3..bad6ea424260abca503015ef425dcc0ea4a27cd3 100644 (file)
@@ -27,6 +27,7 @@
 #include "macro.h"
 #include "string-util.h"
 #include "time-util.h"
+#include "user-util.h"
 #include "util.h"
 
 #define DEFAULT_MAX_USE_LOWER (uint64_t) (1ULL*1024ULL*1024ULL)           /* 1 MiB */
index 3b87eb53554e791ffea2e802f7d4b3cff70b7f40..7336db219b982921232f648d4941d6ebefaa6897 100644 (file)
@@ -52,6 +52,7 @@
 #include "stacktrace.h"
 #include "string-util.h"
 #include "strv.h"
+#include "user-util.h"
 #include "util.h"
 
 /* The maximum size up to which we process coredumps */
index a497a4781b37c83337eed0f4858f90466443738e..f891ddffc6b92d55089f2aeedcf4b0346d042f47 100644 (file)
@@ -42,6 +42,7 @@
 #include "string-util.h"
 #include "terminal-util.h"
 #include "util.h"
+#include "user-util.h"
 
 static enum {
         ACTION_NONE,
index dee25841e1845e315649cef9a00ee4d34034f65c..6e452a4d5113291cf9cb38309f8afd7b107176d5 100644 (file)
@@ -62,6 +62,7 @@
 #include "strv.h"
 #include "terminal-util.h"
 #include "unit-name.h"
+#include "user-util.h"
 
 #define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE)
 
index 3273d9b0c2c9f5c39825bd86964010001a747038..42d7f80461ddd452b1cd91e36255c206674ca208 100644 (file)
@@ -36,6 +36,7 @@
 #include "missing.h"
 #include "signal-util.h"
 #include "string-util.h"
+#include "user-util.h"
 #include "utf8.h"
 #include "util.h"
 
index b55e81ce973c3ea45f8c6894cd1db18dcecfe752..d3e846db84b3ed2d919baed502d284258beaf34b 100644 (file)
@@ -37,6 +37,7 @@
 #include "set.h"
 #include "strv.h"
 #include "terminal-util.h"
+#include "user-util.h"
 #include "util.h"
 
 static bool arg_no_pager = false;
index e1f480d0588ec872399eee59f2d30e1dae35f718..6012004a0b0482f61b20813912bda73c26b1d5ff 100644 (file)
@@ -38,6 +38,7 @@
 #include "macro.h"
 #include "string-util.h"
 #include "strv.h"
+#include "user-util.h"
 #include "util.h"
 
 /* Error codes:
index 2467c126aee5e35bbaa10f10aee9118a9c483b3b..8e3eeb15d89f33bc8b61158f1ed4d352f31af5c5 100644 (file)
@@ -25,6 +25,7 @@
 #include "path-util.h"
 #include "string-util.h"
 #include "strv.h"
+#include "user-util.h"
 #include "util.h"
 
 static int from_environment(const char *envname, const char *fallback, const char **ret) {
index 5ff0957aed4b01979ceed4ff0bb9ad52ef807b4f..f79f89af7edf9aa1c3d358a4d75086d8566c3cca 100644 (file)
@@ -34,6 +34,7 @@
 #include "process-util.h"
 #include "signal-util.h"
 #include "strv.h"
+#include "user-util.h"
 #include "util.h"
 
 static const char* arg_what = "idle:sleep:shutdown";
index bfc8716009a0f55eba5df4369a38203ee9984d51..1cd186dec3d13d8003ee0fb8f0ec8ac9afc45ca5 100644 (file)
@@ -42,6 +42,7 @@
 #include "sysfs-show.h"
 #include "terminal-util.h"
 #include "unit-name.h"
+#include "user-util.h"
 #include "util.h"
 #include "verbs.h"
 
index a44e369149f51875be6862c34a81454e4b487823..f06f8edc0714473ade8430ba97b082d95c5172d6 100644 (file)
@@ -30,6 +30,7 @@
 #include "formats-util.h"
 #include "process-util.h"
 #include "terminal-util.h"
+#include "user-util.h"
 
 int manager_handle_action(
                 Manager *m,
index 3b6e982e9f3e10c1f766a9c363fd55d6282db967..c2541e490ba50c86012769f3394ad29ab8bce4a9 100644 (file)
@@ -33,6 +33,7 @@
 #include "strv.h"
 #include "terminal-util.h"
 #include "udev-util.h"
+#include "user-util.h"
 
 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device) {
         Device *d;
index 1677785467291c8bf0c4581a11b0e9e6b70cd9e5..6da1398b7d4caee73cd9f00c4a4301d7d719d3b8 100644 (file)
@@ -46,6 +46,7 @@
 #include "terminal-util.h"
 #include "udev-util.h"
 #include "unit-name.h"
+#include "user-util.h"
 #include "utmp-wtmp.h"
 
 int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret) {
index ec34535f83e30f5358b6608b2c1901b765d6750d..c4b74eb734f4dfcfdbc5bc16f8214e3257c257dd 100644 (file)
@@ -31,6 +31,7 @@
 #include "logind-inhibit.h"
 #include "mkdir.h"
 #include "string-util.h"
+#include "user-util.h"
 #include "util.h"
 
 Inhibitor* inhibitor_new(Manager *m, const char* id) {
index 10f1cfef810ec27ecc0dbbffc01e9e7891aeb23d..714b1cb2997cd34bcf70f05b025e7c1b40d8b8d5 100644 (file)
@@ -43,6 +43,7 @@
 #include "mkdir.h"
 #include "path-util.h"
 #include "terminal-util.h"
+#include "user-util.h"
 #include "util.h"
 
 #define RELEASE_USEC (20*USEC_PER_SEC)
index 20ea2fbdc415882b28461ab7a70db53378b25921..5975b579e96c45ead89b8829074de2d534b85e5d 100644 (file)
 #include <errno.h>
 #include <string.h>
 
-#include "strv.h"
 #include "bus-util.h"
-#include "logind.h"
-#include "logind-user.h"
 #include "formats-util.h"
+#include "logind-user.h"
+#include "logind.h"
+#include "strv.h"
+#include "user-util.h"
 
 static int property_get_display(
                 sd_bus *bus,
index 1e13ff01de75c460aa0e915c0f8b46848d118a0e..80e461f2dc886bd9fd231916eb222b6c9f1bc23d 100644 (file)
 #include <pwd.h>
 
 #include "sd-messages.h"
-#include "strv.h"
-#include "special.h"
-#include "unit-name.h"
+
 #include "audit.h"
-#include "bus-util.h"
-#include "bus-error.h"
 #include "bus-common-errors.h"
-#include "logind.h"
+#include "bus-error.h"
+#include "bus-util.h"
 #include "formats-util.h"
+#include "logind.h"
+#include "special.h"
+#include "strv.h"
+#include "unit-name.h"
+#include "user-util.h"
 #include "utmp-wtmp.h"
 
 _const_ static usec_t when_wall(usec_t n, usec_t elapse) {
index b5ce6cdca2a8a09e68002ebd4ae610ed16c41cbe..3c91fa86442315106f5e24c1a764a68f5c52f1c8 100644 (file)
@@ -41,6 +41,7 @@
 #include "process-util.h"
 #include "strv.h"
 #include "unit-name.h"
+#include "user-util.h"
 
 static int property_get_pool_path(
                 sd_bus *bus,
index 3096c4f72a38b606c4c49c3a36937d7c556df1f5..d04bb9bd9f8344c0b333976201abdbb5429fc0b8 100644 (file)
@@ -23,8 +23,9 @@
 #include <net/if.h>
 #include <linux/if_tun.h>
 
-#include "networkd-netdev-tuntap.h"
 #include "fd-util.h"
+#include "networkd-netdev-tuntap.h"
+#include "user-util.h"
 
 #define TUN_DEV "/dev/net/tun"
 
index e6259043fa2ad524515d1b879411263a6adc5334..1a178477158478a47c4278331565944d53762026 100644 (file)
 ***/
 
 #include "sd-daemon.h"
+
 #include "capability.h"
-#include "signal-util.h"
 #include "networkd.h"
+#include "signal-util.h"
+#include "user-util.h"
 
 int main(int argc, char *argv[]) {
         _cleanup_manager_free_ Manager *m = NULL;
index 2a1dfd83a9bd568ea74cdefd631489fa94811e5c..6b4ca5a3f30f2969e0fa8fa070e44b2ca801054f 100644 (file)
@@ -29,6 +29,7 @@
 #include "process-util.h"
 #include "signal-util.h"
 #include "string-util.h"
+#include "user-util.h"
 #include "util.h"
 
 static int spawn_getent(const char *database, const char *key, pid_t *rpid) {
index f95842d2522ae2fb592a7d34e26fedcc03c1e838..f01a376af8333664de37ca4343ade8f53195666e 100644 (file)
@@ -90,6 +90,7 @@
 #include "strv.h"
 #include "terminal-util.h"
 #include "udev-util.h"
+#include "user-util.h"
 #include "util.h"
 
 typedef enum ContainerStatus {
index d05a32290b97b93d5f78792b7d0db0e03261ea1b..b98bde676b931a1290153141958fcb62b7897911 100644 (file)
@@ -32,6 +32,7 @@
 #include "macro.h"
 #include "nss-util.h"
 #include "string-util.h"
+#include "user-util.h"
 #include "util.h"
 
 NSS_GETHOSTBYNAME_PROTOTYPES(mymachines);
index 32e61af9251dff82b44da75f4aa3eb170f03239c..df4eb6f63e2747a136cc8996c509d3ab949b9075 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "sd-event.h"
 #include "sd-daemon.h"
-#include "mkdir.h"
+#include "sd-event.h"
+
 #include "capability.h"
+#include "mkdir.h"
+#include "resolved-conf.h"
+#include "resolved-manager.h"
 #include "selinux-util.h"
 #include "signal-util.h"
-
-#include "resolved-manager.h"
-#include "resolved-conf.h"
+#include "user-util.h"
 
 int main(int argc, char *argv[]) {
         _cleanup_(manager_freep) Manager *m = NULL;
index e81d0892e341be2200fe9619cda76d91d30b4cf0..3646305961907e54d68fed3fcd271f9ad6cfd0f2 100644 (file)
@@ -39,6 +39,7 @@
 #include "strv.h"
 #include "terminal-util.h"
 #include "unit-name.h"
+#include "user-util.h"
 
 static bool arg_ask_password = true;
 static bool arg_scope = false;
index 47295ae3795b1be9b9ac8604eeb21b99fd40ad38..e8931daee29e3ac43a47ad19cf1d5d335f25cefd 100644 (file)
 #include <errno.h>
 #include <stdbool.h>
 
+#include "acl-util.h"
 #include "string-util.h"
 #include "strv.h"
+#include "user-util.h"
 #include "util.h"
-#include "acl-util.h"
 
 int acl_find_uid(acl_t acl, uid_t uid, acl_entry_t *entry) {
         acl_entry_t i;
index cbe984d2fba3ec4ea1333ca6b7414f285a432823..224874f65cc25af34a05fa47b255af8b7edd8501 100644 (file)
 
 #include <stdlib.h>
 
+#include "formats-util.h"
+#include "install-printf.h"
 #include "specifier.h"
 #include "unit-name.h"
+#include "user-util.h"
 #include "util.h"
-#include "install-printf.h"
-#include "formats-util.h"
 
 static int specifier_prefix_and_instance(char specifier, void *data, void *userdata, char **ret) {
         UnitFileInstallInfo *i = userdata;
index 4794ff45bbbaf0033f9f4fb974945476a47f8fa1..079dd8752cceead399f81c0e8195ea8312a1848f 100644 (file)
@@ -19,8 +19,9 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "util.h"
 #include "uid-range.h"
+#include "user-util.h"
+#include "util.h"
 
 static bool uid_range_intersect(UidRange *range, uid_t start, uid_t nr) {
         assert(range);
index 93e631336058248baff8a89fb8f6cc4011adf04f..1e6ac2f27dd83f11c359c416095158e10ef33e3e 100644 (file)
@@ -33,6 +33,7 @@
 #include "path-util.h"
 #include "string-util.h"
 #include "terminal-util.h"
+#include "user-util.h"
 #include "utmp-wtmp.h"
 
 int utmp_get_runlevel(int *runlevel, int *previous) {
index 49acea1dd22114ec93e778a1d7d0fc155c8cfc0a..fe4213c08558ca69968614c7dc6072763be1ac16 100644 (file)
@@ -73,6 +73,7 @@
 #include "strv.h"
 #include "terminal-util.h"
 #include "unit-name.h"
+#include "user-util.h"
 #include "util.h"
 #include "utmp-wtmp.h"
 #include "verbs.h"
index 547bd1b34438396ec169d6bea088a8eb2a55b08f..177432bf9ff2dfa8dcfa31805c1729121e1ef66d 100644 (file)
@@ -41,6 +41,7 @@
 #include "utf8.h"
 #include "util.h"
 #include "fd-util.h"
+#include "user-util.h"
 
 typedef enum ItemType {
         ADD_USER = 'u',
index 4944bf6ad930e2b6e15790d501a3fed92c93d2c6..5841cb3fb1d25ab4fc11e4213fa622c7bae30d41 100644 (file)
@@ -19,8 +19,9 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "util.h"
 #include "clean-ipc.h"
+#include "user-util.h"
+#include "util.h"
 
 int main(int argc, char *argv[]) {
         uid_t uid;
index 86895733c08381566647e6f67dafaebf1dc1f5da..c1f8a866affd010e83d0bd87424014de4945c15b 100644 (file)
@@ -46,6 +46,7 @@
 #include "strv.h"
 #include "util.h"
 #include "virt.h"
+#include "user-util.h"
 
 static void test_streq_ptr(void) {
         assert_se(streq_ptr(NULL, NULL));
index 7755a6d89f39e25d59f9ecd1399d9484bef70880..7a0ab18ca012908d0b992a4ee98327e00c693281 100644 (file)
@@ -29,6 +29,7 @@
 #include "signal-util.h"
 #include "timesyncd-conf.h"
 #include "timesyncd-manager.h"
+#include "user-util.h"
 
 static int load_clock_timestamp(uid_t uid, gid_t gid) {
         _cleanup_close_ int fd = -1;
index 457d721303629496f66b15e0c5f1e3888160d985..05c4661a2c5488725daee58425e0566d2168c204 100644 (file)
@@ -59,6 +59,7 @@
 #include "specifier.h"
 #include "string-util.h"
 #include "strv.h"
+#include "user-util.h"
 #include "util.h"
 
 /* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
index f99d1a86c9e1dc30b1edf30cdd9269b74822745f..311d5156455e97c0af4cbf5ed2922a50d37f05d5 100644 (file)
@@ -38,6 +38,7 @@
 #include "strv.h"
 #include "sysctl-util.h"
 #include "udev.h"
+#include "user-util.h"
 #include "util.h"
 
 #define PREALLOC_TOKEN          2048