Changeset View
Changeset View
Standalone View
Standalone View
contrib/capsicum-test/mini-me.c
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | native \ No newline at end of property |
svn:keywords | null | FreeBSD=%H \ No newline at end of property |
svn:mime-type | null | text/plain \ No newline at end of property |
#include <sys/types.h> | |||||
#include <fcntl.h> | |||||
#include <stdio.h> | |||||
#include <string.h> | |||||
#include <unistd.h> | |||||
int main(int argc, char* argv[]) { | |||||
if (argc == 2 && !strcmp(argv[1], "--pass")) { | |||||
fprintf(stderr,"[%d] %s immediately returning 0\n", getpid(), argv[0]); | |||||
return 0; | |||||
} | |||||
if (argc == 2 && !strcmp(argv[1], "--fail")) { | |||||
fprintf(stderr,"[%d] %s immediately returning 1\n", getpid(), argv[0]); | |||||
return 1; | |||||
} | |||||
if (argc == 2 && !strcmp(argv[1], "--checkroot")) { | |||||
int rc = (geteuid() == 0); | |||||
fprintf(stderr,"[uid:%d] %s immediately returning (geteuid() == 0) = %d\n", geteuid(), argv[0], rc); | |||||
return rc; | |||||
} | |||||
if (argc == 2 && !strcmp(argv[1], "--capmode")) { | |||||
/* Expect to already be in capability mode: check we can't open a file */ | |||||
int rc = 0; | |||||
int fd = open("/etc/passwd", O_RDONLY); | |||||
if (fd > 0) { | |||||
fprintf(stderr,"[%d] %s unexpectedly able to open file\n", getpid(), argv[0]); | |||||
rc = 1; | |||||
} | |||||
fprintf(stderr,"[%d] %s --capmode returning %d\n", getpid(), argv[0], rc); | |||||
return rc; | |||||
} | |||||
return -1; | |||||
} |