From 44ecacea6b45d7ae5d5eb70fe01d7ade4b90c525 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Sun, 2 Nov 2003 10:03:23 +0000 Subject: Both setegid and seteuid were implemented suboptimally, such that we were unable to switch back to the original saved group/user ID. -Erik --- libc/sysdeps/linux/common/seteuid.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'libc/sysdeps/linux/common/seteuid.c') diff --git a/libc/sysdeps/linux/common/seteuid.c b/libc/sysdeps/linux/common/seteuid.c index fbf60909d..e970e0711 100644 --- a/libc/sysdeps/linux/common/seteuid.c +++ b/libc/sysdeps/linux/common/seteuid.c @@ -1,9 +1,28 @@ +#define _GNU_SOURCE #include #include #include +#include #include +#include int seteuid(uid_t uid) { - return setreuid(-1, uid); + int result; + + if (uid == (uid_t) ~0) + { + __set_errno (EINVAL); + return -1; + } + +#ifdef __NR_setresuid + result = setresuid(-1, uid, -1); + if (result == -1 && errno == ENOSYS) + /* Will also set the saved user ID if euid != uid, + * making it impossible to switch back...*/ +#endif + result = setreuid(-1, uid); + + return result; } -- cgit v1.2.3