chiark / gitweb /
util: introduce reset_uid_gid() for resetting all uids and gids to 0
authorLennart Poettering <lennart@poettering.net>
Wed, 20 May 2015 12:41:39 +0000 (14:41 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 08:57:23 +0000 (09:57 +0100)
src/shared/util.c
src/shared/util.h

index 5efb9591a60f671ff2b2e1b67948ae05a464202d..62c1739c9326933456ee09619ad35bd1947ed777 100644 (file)
@@ -4666,16 +4666,7 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int root_fd) {
                         return -errno;
         }
 
-        if (setresgid(0, 0, 0) < 0)
-                return -errno;
-
-        if (setgroups(0, NULL) < 0)
-                return -errno;
-
-        if (setresuid(0, 0, 0) < 0)
-                return -errno;
-
-        return 0;
+        return reset_uid_gid();
 }
 
 int getpeercred(int fd, struct ucred *ucred) {
@@ -6162,3 +6153,17 @@ 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;
+}
index 4cea627580fd86586acdb5bee5f966e3dde32b0a..014e61c2e6f5807cb783a565b63a0a8f66edd056 100644 (file)
@@ -906,3 +906,5 @@ char *shell_maybe_quote(const char *s);
 int parse_mode(const char *s, mode_t *ret);
 
 int mount_move_root(const char *path);
+
+int reset_uid_gid(void);