blob: 28f548bd0387a4a06c623b9e456277ca8874ff40 [file] [log] [blame]
Dmitry V. Levin1da7c952014-12-13 18:24:13 +00001#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4#include <assert.h>
Dmitry V. Levin530bed02014-12-14 13:30:54 +00005#include <stdlib.h>
Dmitry V. Levin1da7c952014-12-13 18:24:13 +00006#include <unistd.h>
7#include <sys/syscall.h>
8
9int
10main(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. Levin68804b32015-03-16 18:10:21 +000017 && defined(__NR_fchown) \
Dmitry V. Levin530bed02014-12-14 13:30:54 +000018 && defined(__NR_getgroups)
Dmitry V. Levin3a15bc82015-03-02 01:13:47 +000019 int uid;
Dmitry V. Levin530bed02014-12-14 13:30:54 +000020 int size;
21 int *list = 0;
Dmitry V. Levin1da7c952014-12-13 18:24:13 +000022
Dmitry V. Levin3a15bc82015-03-02 01:13:47 +000023 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. Levin1da7c952014-12-13 18:24:13 +000033 assert(syscall(__NR_setreuid, -1, -1L) == 0);
Dmitry V. Levin3a15bc82015-03-02 01:13:47 +000034 assert(syscall(__NR_setresuid, uid, -1, -1L) == 0);
Dmitry V. Levin68804b32015-03-16 18:10:21 +000035 assert(syscall(__NR_fchown, 1, -1, -1L) == 0);
Dmitry V. Levin530bed02014-12-14 13:30:54 +000036 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. Levin1da7c952014-12-13 18:24:13 +000039 return 0;
40#else
41 return 77;
42#endif
43}