yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * setresuid() for uClibc |
| 4 | * |
| 5 | * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> |
| 6 | * |
| 7 | * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. |
| 8 | */ |
| 9 | |
| 10 | #include <sys/syscall.h> |
| 11 | #if defined __USE_GNU && defined __UCLIBC_LINUX_SPECIFIC__ |
| 12 | #include <unistd.h> |
| 13 | |
| 14 | #if defined(__NR_setresuid32) |
| 15 | # undef __NR_setresuid |
| 16 | # define __NR_setresuid __NR_setresuid32 |
| 17 | |
| 18 | _syscall3(int, setresuid, uid_t, ruid, uid_t, euid, uid_t, suid) |
| 19 | libc_hidden_def(setresuid) |
| 20 | |
| 21 | #elif defined(__NR_setresuid) |
| 22 | |
| 23 | # define __NR___syscall_setresuid __NR_setresuid |
| 24 | static __inline__ _syscall3(int, __syscall_setresuid, |
| 25 | __kernel_uid_t, rgid, __kernel_uid_t, egid, __kernel_uid_t, sgid) |
| 26 | |
| 27 | int setresuid(uid_t ruid, uid_t euid, uid_t suid) |
| 28 | { |
| 29 | if (((ruid + 1) > (uid_t) ((__kernel_uid_t) - 1U)) |
| 30 | || ((euid + 1) > (uid_t) ((__kernel_uid_t) - 1U)) |
| 31 | || ((suid + 1) > (uid_t) ((__kernel_uid_t) - 1U))) { |
| 32 | __set_errno(EINVAL); |
| 33 | return -1; |
| 34 | } |
| 35 | return (__syscall_setresuid(ruid, euid, suid)); |
| 36 | } |
| 37 | libc_hidden_def(setresuid) |
| 38 | |
| 39 | #endif |
| 40 | |
| 41 | #endif |