Dmitry V. Levin | 1da7c95 | 2014-12-13 18:24:13 +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 | 1da7c95 | 2014-12-13 18:24:13 +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) \ |
Dmitry V. Levin | 68804b3 | 2015-03-16 18:10:21 +0000 | [diff] [blame] | 17 | && defined(__NR_fchown) \ |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 18 | && defined(__NR_getgroups) |
Dmitry V. Levin | 3a15bc8 | 2015-03-02 01:13:47 +0000 | [diff] [blame] | 19 | int uid; |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 20 | int size; |
| 21 | int *list = 0; |
Dmitry V. Levin | 1da7c95 | 2014-12-13 18:24:13 +0000 | [diff] [blame] | 22 | |
Dmitry V. Levin | 3a15bc8 | 2015-03-02 01:13:47 +0000 | [diff] [blame] | 23 | uid = syscall(__NR_getuid); |
| 24 | assert(syscall(__NR_setuid, uid) == 0); |
| 25 | { |
| 26 | /* |
| 27 | * uids returned by getresuid should be ignored |
| 28 | * to avoid 16bit vs 32bit issues. |
| 29 | */ |
| 30 | int r, e, s; |
| 31 | assert(syscall(__NR_getresuid, &r, &e, &s) == 0); |
| 32 | } |
Dmitry V. Levin | 1da7c95 | 2014-12-13 18:24:13 +0000 | [diff] [blame] | 33 | assert(syscall(__NR_setreuid, -1, -1L) == 0); |
Dmitry V. Levin | 3a15bc8 | 2015-03-02 01:13:47 +0000 | [diff] [blame] | 34 | assert(syscall(__NR_setresuid, uid, -1, -1L) == 0); |
Dmitry V. Levin | 68804b3 | 2015-03-16 18:10:21 +0000 | [diff] [blame] | 35 | assert(syscall(__NR_fchown, 1, -1, -1L) == 0); |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 36 | assert((size = syscall(__NR_getgroups, 0, list)) >= 0); |
| 37 | assert(list = calloc(size + 1, sizeof(*list))); |
| 38 | assert(syscall(__NR_getgroups, size, list) == size); |
Dmitry V. Levin | 1da7c95 | 2014-12-13 18:24:13 +0000 | [diff] [blame] | 39 | return 0; |
| 40 | #else |
| 41 | return 77; |
| 42 | #endif |
| 43 | } |