From 2c7d1ce088ba9b588652f58616eb2a8d7748ca88 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Sat, 16 Oct 2021 06:15:05 +0200 Subject: passt: Static builds: don't redefine __vsyslog(), skip getpwnam() and initgroups() Signed-off-by: Stefano Brivio --- passt.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'passt.c') diff --git a/passt.c b/passt.c index 3e45095..6878668 100644 --- a/passt.c +++ b/passt.c @@ -212,17 +212,22 @@ static void check_root(void) close(fd); fprintf(stderr, "Don't run this as root. Changing to nobody...\n"); +#ifndef GLIBC_NO_STATIC_NSS pw = getpwnam("nobody"); if (!pw) { perror("getpwnam"); exit(EXIT_FAILURE); } - if (initgroups(pw->pw_name, pw->pw_gid) || - setgid(pw->pw_gid) || setuid(pw->pw_uid)) { - fprintf(stderr, "Can't change to user/group nobody, exiting"); - exit(EXIT_FAILURE); - } + if (!initgroups(pw->pw_name, pw->pw_gid) && + !setgid(pw->pw_gid) && !setuid(pw->pw_uid)) + return; +#else + (void)pw; +#endif + + fprintf(stderr, "Can't change to user/group nobody, exiting"); + exit(EXIT_FAILURE); } /** -- cgit v1.2.3