summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-05-20 14:41:39 +0200
committerSven Eden <yamakuzure@gmx.net>2017-03-14 09:57:23 +0100
commit5cb583ac1cc6c9225e341f0cf8d02d42eff7d684 (patch)
tree390b19999b6631d5e8915cae7f0bc6edc72645da /src/shared/util.c
parent8eb444001b790b0c16369ceb1420afde4c1e5b24 (diff)
util: introduce reset_uid_gid() for resetting all uids and gids to 0
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 5efb9591a..62c1739c9 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -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;
+}