summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/seteuid.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/sysdeps/linux/common/seteuid.c')
-rw-r--r--libc/sysdeps/linux/common/seteuid.c21
1 files changed, 20 insertions, 1 deletions
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 <unistd.h>
#include <stdio.h>
#include <errno.h>
+#include <pwd.h>
#include <sys/types.h>
+#include <sys/syscall.h>
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;
}