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