diff options
author | 2016-03-25 16:31:32 +0000 | |
---|---|---|
committer | 2016-03-25 16:31:32 +0000 | |
commit | 747158c79603ab3e63f76e8cebb76390a4c1eed1 (patch) | |
tree | cbbbb5ce440a45985a181ff04342934de937439e | |
parent | regression tests for underlined and bold underscores; (diff) | |
download | wireguard-openbsd-747158c79603ab3e63f76e8cebb76390a4c1eed1.tar.xz wireguard-openbsd-747158c79603ab3e63f76e8cebb76390a4c1eed1.zip |
- Both checks for pw are not needed since it was already done at the start of
the program
- Add error message to syslog if privdrop didn't succeed and then exit
- Remove lint comments
OK beck@ after his suggestion and also looks good to jca@
-rw-r--r-- | libexec/spamd/grey.c | 15 | ||||
-rw-r--r-- | libexec/spamd/spamd.c | 12 |
2 files changed, 11 insertions, 16 deletions
diff --git a/libexec/spamd/grey.c b/libexec/spamd/grey.c index 33fbf650f12..d36288cbdd8 100644 --- a/libexec/spamd/grey.c +++ b/libexec/spamd/grey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grey.c,v 1.62 2015/12/10 16:06:29 beck Exp $ */ +/* $OpenBSD: grey.c,v 1.63 2016/03/25 16:31:32 mestre Exp $ */ /* * Copyright (c) 2004-2006 Bob Beck. All rights reserved. @@ -1000,7 +1000,6 @@ greyscanner(void) PATH_SPAMD_DB); sleep(DB_SCAN_INTERVAL); } - /* NOTREACHED */ } static void @@ -1009,12 +1008,11 @@ drop_privs(void) /* * lose root, continue as non-root user */ - if (pw) { - setgroups(1, &pw->pw_gid); - setegid(pw->pw_gid); - setgid(pw->pw_gid); - seteuid(pw->pw_uid); - setuid(pw->pw_uid); + 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)) { + syslog_r(LOG_ERR, &sdata, "failed to drop privs (%m)"); + exit(1); } } @@ -1107,6 +1105,5 @@ greywatcher(void) setproctitle("(pf <spamd-white> update)"); greyscanner(); - /* NOTREACHED */ exit(1); } diff --git a/libexec/spamd/spamd.c b/libexec/spamd/spamd.c index f26b3c307d8..2f85d346a5e 100644 --- a/libexec/spamd/spamd.c +++ b/libexec/spamd/spamd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spamd.c,v 1.138 2016/03/10 00:07:03 gsoares Exp $ */ +/* $OpenBSD: spamd.c,v 1.139 2016/03/25 16:31:32 mestre Exp $ */ /* * Copyright (c) 2015 Henning Brauer <henning@openbsd.org> @@ -1507,11 +1507,10 @@ main(int argc, char *argv[]) exit(1); } - if (pw) - 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)) - err(1, "failed to drop privs"); + 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)) + err(1, "failed to drop privs"); goto jail; } @@ -1529,7 +1528,6 @@ main(int argc, char *argv[]) } close(trappipe[0]); return (greywatcher()); - /* NOTREACHED */ } jail: |