From 52d37d7ff437017334f912651bd4af909960db10 Mon Sep 17 00:00:00 2001 From: Jérémie Roquet Date: Thu, 16 Oct 2014 16:14:49 +0200 Subject: Take more care with errors from setuid(). This is to ensure the user is aware of errors unsetting the PRIVELEGED option. --- Src/options.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'Src/options.c') diff --git a/Src/options.c b/Src/options.c index 6e4e7b911..3e3e07474 100644 --- a/Src/options.c +++ b/Src/options.c @@ -766,7 +766,17 @@ dosetopt(int optno, int value, int force, char *new_opts) #ifdef HAVE_SETUID setuid(getuid()); setgid(getgid()); -#endif /* HAVE_SETUID */ + if (setuid(getuid())) { + zwarn("failed to change user ID: %e", errno); + return -1; + } else if (setgid(getgid())) { + zwarn("failed to change group ID: %e", errno); + return -1; + } +#else + zwarn("setuid not available"); + return -1; +#endif /* not HAVE_SETUID */ #ifdef JOB_CONTROL } else if (!force && optno == MONITOR && value) { if (new_opts[optno] == value) -- cgit 1.4.1