From 5a9b2518be0572cd530e80de9c2699b9392a4bf1 Mon Sep 17 00:00:00 2001 From: Mike Barnes Date: Sat, 29 Jan 2022 16:14:37 +1100 Subject: [PATCH] Allow dropping privs on platforms without setresuid() --- main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 3b745d5..d958c77 100644 --- a/main.c +++ b/main.c @@ -20,7 +20,7 @@ #include "opts.h" #include "utils.h" -/* lenght of "gemini://" */ +/* length of "gemini://" */ #define GEMINI_PART 9 /* @@ -121,12 +121,21 @@ drop_privileges(const char *user, const char *path) chrooted = 1; echdir("/"); /* drop privileges */ +#if defined (__OpenBSD__) || defined(__FreeBSD__) if (setgroups(1, &pw->pw_gid) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) { errlog("dropping privileges to user %s (uid=%i) failed", user, pw->pw_uid); } +#else + if (setgroups(1, &pw->pw_gid) || + setgid(pw->pw_gid) || + setuid(pw->pw_uid)) { + errlog("dropping privileges to user %s (uid=%i) failed", + user, pw->pw_uid); + } +#endif } #ifdef __OpenBSD__ /*