yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> |
| 3 | * |
| 4 | * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. |
| 5 | */ |
| 6 | |
| 7 | #include <unistd.h> |
| 8 | #include <stdio.h> |
| 9 | #include <errno.h> |
| 10 | #include <pwd.h> |
| 11 | #include <sys/types.h> |
| 12 | #include <sys/syscall.h> |
| 13 | |
| 14 | #if !defined __UCLIBC_LINUX_SPECIFIC__ |
| 15 | #undef __NR_setresuid |
| 16 | #undef __NR_setresuid32 |
| 17 | #endif |
| 18 | |
| 19 | int seteuid(uid_t uid) |
| 20 | { |
| 21 | int result; |
| 22 | |
| 23 | if (uid == (uid_t) ~0) |
| 24 | { |
| 25 | __set_errno (EINVAL); |
| 26 | return -1; |
| 27 | } |
| 28 | |
| 29 | #if (defined __NR_setresuid || defined __NR_setresuid32) && defined __USE_GNU |
| 30 | result = setresuid(-1, uid, -1); |
| 31 | if (result == -1 && errno == ENOSYS) |
| 32 | /* Will also set the saved user ID if euid != uid, |
| 33 | * making it impossible to switch back...*/ |
| 34 | #endif |
| 35 | result = setreuid(-1, uid); |
| 36 | |
| 37 | return result; |
| 38 | } |
| 39 | libc_hidden_def(seteuid) |