diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2006-03-06 10:45:58 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2006-03-06 10:45:58 +0000 |
commit | bc2cb0af87ca7084b9523e760d68aad4217276f8 (patch) | |
tree | 61c35eb64e2d68f77ce6b3ce477f0c18eea079fd /sbin | |
parent | 5803ed8cfde384a9de032eaa23f79772700350bd (diff) |
convert permanent privilege revocation to use setresuid/setresgid;
ok henning@
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/ccdconfig/ccdconfig.c | 11 | ||||
-rw-r--r-- | sbin/dhclient/dhclient.c | 12 | ||||
-rw-r--r-- | sbin/pflogd/privsep.c | 14 | ||||
-rw-r--r-- | sbin/ping/ping.c | 10 | ||||
-rw-r--r-- | sbin/ping6/ping6.c | 8 |
5 files changed, 29 insertions, 26 deletions
diff --git a/sbin/ccdconfig/ccdconfig.c b/sbin/ccdconfig/ccdconfig.c index b10a125150b..2413f5952b0 100644 --- a/sbin/ccdconfig/ccdconfig.c +++ b/sbin/ccdconfig/ccdconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ccdconfig.c,v 1.26 2005/11/12 20:15:13 deraadt Exp $ */ +/* $OpenBSD: ccdconfig.c,v 1.27 2006/03/06 10:45:56 djm Exp $ */ /* $NetBSD: ccdconfig.c,v 1.6 1996/05/16 07:11:18 thorpej Exp $ */ /*- @@ -115,6 +115,7 @@ int main(int argc, char *argv[]) { int ch, options = 0, action = CCD_CONFIG; + gid_t gid; while ((ch = getopt(argc, argv, "cCf:gM:N:uUv")) != -1) { switch (ch) { @@ -172,10 +173,10 @@ main(int argc, char *argv[]) * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. */ - if (core != NULL || kernel != NULL || action != CCD_DUMP) { - setegid(getgid()); - setgid(getgid()); - } + gid = getgid(); + if (core != NULL || kernel != NULL || action != CCD_DUMP) + if (setresgid(gid, gid, gid) == -1) + err(1, "setresgid"); switch (action) { case CCD_CONFIG: diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 06c71dd2f4d..36a7fa5dc5f 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.81 2005/10/26 15:42:04 henning Exp $ */ +/* $OpenBSD: dhclient.c,v 1.82 2006/03/06 10:45:56 djm Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -363,10 +363,12 @@ main(int argc, char *argv[]) if (chdir("/") == -1) error("chdir(\"/\")"); - if (setgroups(1, &pw->pw_gid) || - setegid(pw->pw_gid) || setgid(pw->pw_gid) || - seteuid(pw->pw_uid) || setuid(pw->pw_uid)) - error("can't drop privileges: %m"); + if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) == -1) + error("setresgid"); + if (setgroups(1, &pw->pw_gid) == -1) + error("setgroups"); + if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1) + error("setresuid"); endpwent(); diff --git a/sbin/pflogd/privsep.c b/sbin/pflogd/privsep.c index 66734ee2857..f1272eb4b33 100644 --- a/sbin/pflogd/privsep.c +++ b/sbin/pflogd/privsep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.c,v 1.14 2006/01/15 16:38:04 canacar Exp $ */ +/* $OpenBSD: privsep.c,v 1.15 2006/03/06 10:45:56 djm Exp $ */ /* * Copyright (c) 2003 Can Erkin Acar @@ -98,16 +98,12 @@ priv_init(void) err(1, "unable to chdir"); gidset[0] = pw->pw_gid; + if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) == -1) + err(1, "setresgid() failed"); if (setgroups(1, gidset) == -1) err(1, "setgroups() failed"); - if (setegid(pw->pw_gid) == -1) - err(1, "setegid() failed"); - if (setgid(pw->pw_gid) == -1) - err(1, "setgid() failed"); - if (seteuid(pw->pw_uid) == -1) - err(1, "seteuid() failed"); - if (setuid(pw->pw_uid) == -1) - err(1, "setuid() failed"); + if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1) + err(1, "setresuid() failed"); close(socks[0]); priv_fd = socks[1]; return 0; diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index 49fd36b8ba1..a235fcb605b 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping.c,v 1.73 2006/01/09 22:42:35 deraadt Exp $ */ +/* $OpenBSD: ping.c,v 1.74 2006/03/06 10:45:56 djm Exp $ */ /* $NetBSD: ping.c,v 1.20 1995/08/11 22:37:58 cgd Exp $ */ /* @@ -43,7 +43,7 @@ static const char copyright[] = #if 0 static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93"; #else -static const char rcsid[] = "$OpenBSD: ping.c,v 1.73 2006/01/09 22:42:35 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: ping.c,v 1.74 2006/03/06 10:45:56 djm Exp $"; #endif #endif /* not lint */ @@ -198,13 +198,15 @@ main(int argc, char *argv[]) const char *errstr; fd_set *fdmaskp; size_t fdmasks; + uid_t uid; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0) err(1, "socket"); /* revoke privs */ - seteuid(getuid()); - setuid(getuid()); + uid = getuid(); + if (setresuid(uid, uid, uid) == -1) + err(1, "setresuid"); preload = 0; datap = &outpack[8 + sizeof(struct tvi)]; diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index 75e2030ade0..a7215ade766 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping6.c,v 1.61 2005/12/12 18:45:40 jaredy Exp $ */ +/* $OpenBSD: ping6.c,v 1.62 2006/03/06 10:45:57 djm Exp $ */ /* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */ /* @@ -316,6 +316,7 @@ main(int argc, char *argv[]) #ifdef IPV6_USE_MIN_MTU int mflag = 0; #endif + uid_t uid; /* just to be sure */ memset(&smsghdr, 0, sizeof(smsghdr)); @@ -682,8 +683,9 @@ main(int argc, char *argv[]) } /* revoke root privilege */ - seteuid(getuid()); - setuid(getuid()); + uid = getuid(); + if (setresuid(uid, uid, uid) == -1) + err(1, "setresuid"); if ((options & F_FLOOD) && (options & F_INTERVAL)) errx(1, "-f and -i incompatible options"); |