1*8ac5aef8SEnji Cooper #include <sys/types.h>
2*8ac5aef8SEnji Cooper #include <fcntl.h>
3*8ac5aef8SEnji Cooper #include <stdio.h>
4*8ac5aef8SEnji Cooper #include <string.h>
5*8ac5aef8SEnji Cooper #include <unistd.h>
6*8ac5aef8SEnji Cooper
main(int argc,char * argv[])7*8ac5aef8SEnji Cooper int main(int argc, char* argv[]) {
8*8ac5aef8SEnji Cooper if (argc == 2 && !strcmp(argv[1], "--pass")) {
9*8ac5aef8SEnji Cooper fprintf(stderr,"[%d] %s immediately returning 0\n", getpid(), argv[0]);
10*8ac5aef8SEnji Cooper return 0;
11*8ac5aef8SEnji Cooper }
12*8ac5aef8SEnji Cooper
13*8ac5aef8SEnji Cooper if (argc == 2 && !strcmp(argv[1], "--fail")) {
14*8ac5aef8SEnji Cooper fprintf(stderr,"[%d] %s immediately returning 1\n", getpid(), argv[0]);
15*8ac5aef8SEnji Cooper return 1;
16*8ac5aef8SEnji Cooper }
17*8ac5aef8SEnji Cooper
18*8ac5aef8SEnji Cooper if (argc == 2 && !strcmp(argv[1], "--checkroot")) {
19*8ac5aef8SEnji Cooper int rc = (geteuid() == 0);
20*8ac5aef8SEnji Cooper fprintf(stderr,"[uid:%d] %s immediately returning (geteuid() == 0) = %d\n", geteuid(), argv[0], rc);
21*8ac5aef8SEnji Cooper return rc;
22*8ac5aef8SEnji Cooper }
23*8ac5aef8SEnji Cooper
24*8ac5aef8SEnji Cooper if (argc == 2 && !strcmp(argv[1], "--capmode")) {
25*8ac5aef8SEnji Cooper /* Expect to already be in capability mode: check we can't open a file */
26*8ac5aef8SEnji Cooper int rc = 0;
27*8ac5aef8SEnji Cooper
28*8ac5aef8SEnji Cooper int fd = open("/etc/passwd", O_RDONLY);
29*8ac5aef8SEnji Cooper if (fd > 0) {
30*8ac5aef8SEnji Cooper fprintf(stderr,"[%d] %s unexpectedly able to open file\n", getpid(), argv[0]);
31*8ac5aef8SEnji Cooper rc = 1;
32*8ac5aef8SEnji Cooper }
33*8ac5aef8SEnji Cooper fprintf(stderr,"[%d] %s --capmode returning %d\n", getpid(), argv[0], rc);
34*8ac5aef8SEnji Cooper return rc;
35*8ac5aef8SEnji Cooper }
36*8ac5aef8SEnji Cooper
37*8ac5aef8SEnji Cooper return -1;
38*8ac5aef8SEnji Cooper }
39