11 uid_t unpriv_uid
= 5000;
12 gid_t unpriv_gid
= 5000;
15 test(int (*fn
)(), int expected
, char *msg
, char *msg2
)
23 printf("%s (%s): ", msg
, msg2
);
25 if (retval
== expected
) {
28 printf("FAILED (was: %d, expected: %d)\n", retval
, expected
);
34 test_as_root(int (*fn
)(), int expected
, char *msg
)
37 fprintf(stderr
, "must be run as root\n");
41 test(fn
, expected
, msg
, "as root");
45 test_as_jailed_root(int (*fn
)(), int expected
, char *msg
)
48 fprintf(stderr
, "must be run as root\n");
55 fprintf(stderr
, "fork failed\n");
68 fprintf(stderr
, "jail failed\n");
71 test(fn
, expected
, msg
, "as jailed root");
75 waitpid(child
, NULL
, 0);
80 test_as_unpriv(int (*fn
)(), int expected
, char *msg
)
83 fprintf(stderr
, "must be run as root\n");
90 fprintf(stderr
, "fork failed\n");
98 if (getuid() != unpriv_uid
|| getgid() != unpriv_gid
) {
99 fprintf(stderr
, "setuid/gid failed\n");
102 test(fn
, expected
, msg
, "as unpriv");
106 waitpid(child
, NULL
, 0);
111 test_as_jailed_unpriv(int (*fn
)(), int expected
, char *msg
)
114 fprintf(stderr
, "must be run as root\n");
121 fprintf(stderr
, "fork failed\n");
134 fprintf(stderr
, "jail failed\n");
141 if (getuid() != unpriv_uid
|| getgid() != unpriv_gid
) {
142 fprintf(stderr
, "setuid/gid failed\n");
145 test(fn
, expected
, msg
, "as jailed unpriv");
149 waitpid(child
, NULL
, 0);