diff options
author | 1998-11-15 19:52:11 +0000 | |
---|---|---|
committer | 1998-11-15 19:52:11 +0000 | |
commit | 8cafe4e090baace0eca001061c98c995acfc7306 (patch) | |
tree | ee14b7d01ae167841b879822f2ab7343ae46e34e | |
parent | ftok requires minor crank (diff) | |
download | wireguard-openbsd-8cafe4e090baace0eca001061c98c995acfc7306.tar.xz wireguard-openbsd-8cafe4e090baace0eca001061c98c995acfc7306.zip |
improve behaviour; ww@styx.org
-rw-r--r-- | lib/libc/compat-43/__setregid.c | 18 | ||||
-rw-r--r-- | lib/libc/compat-43/__setreuid.c | 18 |
2 files changed, 31 insertions, 5 deletions
diff --git a/lib/libc/compat-43/__setregid.c b/lib/libc/compat-43/__setregid.c index c8f4d058708..e1133b2178a 100644 --- a/lib/libc/compat-43/__setregid.c +++ b/lib/libc/compat-43/__setregid.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: __setregid.c,v 1.3 1996/09/15 09:30:44 tholo Exp $"; +static char *rcsid = "$OpenBSD: __setregid.c,v 1.4 1998/11/15 19:52:11 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -44,18 +44,32 @@ __setregid(rgid, egid) gid_t rgid, egid; { static gid_t svgid = (gid_t) -1; + uid_t ruid, euid; if (svgid == (gid_t) -1) svgid = getegid(); + + ruid = getuid(); + euid = geteuid(); + /* * we assume that the intent of setting rgid is to be able to get * back rgid priviledge. So we make sure that we will be able to * do so, but do not actually set the rgid. */ - if (rgid != (gid_t) -1 && rgid != getgid() && rgid != svgid) { + if (rgid != (gid_t) -1 && rgid != getgid() && rgid != svgid && + ruid != 0 && euid != 0) { errno = EPERM; return (-1); } + + /* + * If we are root and want to change our real group id, do so. + * Since this clobbers our egid, so we must do this before + * we setegid(). + */ + if ((ruid == 0 || euid == 0) && rgid != -1) + setgid(rgid); if (egid != (gid_t) -1 && setegid(egid) < 0) return (-1); return (0); diff --git a/lib/libc/compat-43/__setreuid.c b/lib/libc/compat-43/__setreuid.c index cf8ac987ac1..0fdc97aa814 100644 --- a/lib/libc/compat-43/__setreuid.c +++ b/lib/libc/compat-43/__setreuid.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: __setreuid.c,v 1.3 1996/09/15 09:30:45 tholo Exp $"; +static char *rcsid = "$OpenBSD: __setreuid.c,v 1.4 1998/11/15 19:52:11 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -44,18 +44,30 @@ __setreuid(ruid, euid) uid_t ruid, euid; { static uid_t svuid = (uid_t) -1; - + uid_t sruid; + if (svuid == (uid_t) -1) svuid = geteuid(); + + sruid = getuid(); /* * we assume that the intent of setting ruid is to be able to get * back ruid priviledge. So we make sure that we will be able to * do so, but do not actually set the ruid. */ - if (ruid != (uid_t) -1 && ruid != getuid() && ruid != svuid) { + if (ruid != (uid_t) -1 && ruid != sruid && ruid != svuid && + svuid != 0 && sruid != 0) { errno = EPERM; return (-1); } + + /* + * If we are root and want to change our real uid, do so. + * Since this clobbers our euid, we must do this before + * we seteuid() + */ + if ((svuid == 0 || sruid == 0) && ruid != -1) + setuid(ruid); if (euid != (uid_t) -1 && seteuid(euid) < 0) return (-1); return (0); |