X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Futil.c;h=62c1739c9326933456ee09619ad35bd1947ed777;hp=5efb9591a60f671ff2b2e1b67948ae05a464202d;hb=5cb583ac1cc6c9225e341f0cf8d02d42eff7d684;hpb=8eb444001b790b0c16369ceb1420afde4c1e5b24 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; +}