blob: be5cec6d19d658be68b7c411abf969c22841dd29 [file] [log] [blame]
Dmitry V. Levin80f7db12014-12-13 21:49:01 +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. Levin80f7db12014-12-13 21:49:01 +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) \
17 && defined(__NR_chown) \
Dmitry V. Levin530bed02014-12-14 13:30:54 +000018 && defined(__NR_getgroups) \
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000019 \
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. Levin530bed02014-12-14 13:30:54 +000026 && defined(__NR_getgroups32) \
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000027 \
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. Levin530bed02014-12-14 13:30:54 +000034 && __NR_getgroups != __NR_getgroups32 \
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000035 /**/
Dmitry V. Levin3a15bc82015-03-02 01:13:47 +000036 int uid;
Dmitry V. Levin530bed02014-12-14 13:30:54 +000037 int size;
38 int *list = 0;
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000039
Dmitry V. Levin3a15bc82015-03-02 01:13:47 +000040 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. Levin80f7db12014-12-13 21:49:01 +000050 assert(syscall(__NR_setreuid, -1, 0xffff) == 0);
Dmitry V. Levin3a15bc82015-03-02 01:13:47 +000051 assert(syscall(__NR_setresuid, uid, -1, 0xffff) == 0);
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000052 assert(syscall(__NR_chown, ".", -1, 0xffff) == 0);
Dmitry V. Levin530bed02014-12-14 13:30:54 +000053 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. Levin80f7db12014-12-13 21:49:01 +000056 return 0;
57#else
58 return 77;
59#endif
60}