Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 1 | #ifdef HAVE_CONFIG_H |
| 2 | # include "config.h" |
| 3 | #endif |
| 4 | #include <assert.h> |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 5 | #include <stdlib.h> |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 6 | #include <unistd.h> |
| 7 | #include <sys/syscall.h> |
| 8 | |
| 9 | int |
| 10 | main(void) |
| 11 | { |
| 12 | #if defined(__NR_getuid) \ |
| 13 | && defined(__NR_setuid) \ |
| 14 | && defined(__NR_getresuid) \ |
| 15 | && defined(__NR_setreuid) \ |
| 16 | && defined(__NR_setresuid) \ |
| 17 | && defined(__NR_chown) \ |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 18 | && defined(__NR_getgroups) \ |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 19 | \ |
| 20 | && defined(__NR_getuid32) \ |
| 21 | && defined(__NR_setuid32) \ |
| 22 | && defined(__NR_getresuid32) \ |
| 23 | && defined(__NR_setreuid32) \ |
| 24 | && defined(__NR_setresuid32) \ |
| 25 | && defined(__NR_chown32) \ |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 26 | && defined(__NR_getgroups32) \ |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 27 | \ |
| 28 | && __NR_getuid != __NR_getuid32 \ |
| 29 | && __NR_setuid != __NR_setuid32 \ |
| 30 | && __NR_getresuid != __NR_getresuid32 \ |
| 31 | && __NR_setreuid != __NR_setreuid32 \ |
| 32 | && __NR_setresuid != __NR_setresuid32 \ |
| 33 | && __NR_chown != __NR_chown32 \ |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 34 | && __NR_getgroups != __NR_getgroups32 \ |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 35 | /**/ |
Dmitry V. Levin | 3a15bc8 | 2015-03-02 01:13:47 +0000 | [diff] [blame^] | 36 | int uid; |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 37 | int size; |
| 38 | int *list = 0; |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 39 | |
Dmitry V. Levin | 3a15bc8 | 2015-03-02 01:13:47 +0000 | [diff] [blame^] | 40 | uid = syscall(__NR_getuid); |
| 41 | assert(syscall(__NR_setuid, uid) == 0); |
| 42 | { |
| 43 | /* |
| 44 | * uids returned by getresuid should be ignored |
| 45 | * to avoid 16bit vs 32bit issues. |
| 46 | */ |
| 47 | int r, e, s; |
| 48 | assert(syscall(__NR_getresuid, &r, &e, &s) == 0); |
| 49 | } |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 50 | assert(syscall(__NR_setreuid, -1, 0xffff) == 0); |
Dmitry V. Levin | 3a15bc8 | 2015-03-02 01:13:47 +0000 | [diff] [blame^] | 51 | assert(syscall(__NR_setresuid, uid, -1, 0xffff) == 0); |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 52 | assert(syscall(__NR_chown, ".", -1, 0xffff) == 0); |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 53 | assert((size = syscall(__NR_getgroups, 0, list)) >= 0); |
| 54 | assert(list = calloc(size + 1, sizeof(*list))); |
| 55 | assert(syscall(__NR_getgroups, size, list) == size); |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 56 | return 0; |
| 57 | #else |
| 58 | return 77; |
| 59 | #endif |
| 60 | } |