1*699cd480SApple OSS Distributions #include <errno.h>
2*699cd480SApple OSS Distributions #include <stdbool.h>
3*699cd480SApple OSS Distributions #include <stdio.h>
4*699cd480SApple OSS Distributions #include <stdlib.h>
5*699cd480SApple OSS Distributions #include <string.h>
6*699cd480SApple OSS Distributions #include <unistd.h>
7*699cd480SApple OSS Distributions
8*699cd480SApple OSS Distributions #include <sys/kern_debug.h>
9*699cd480SApple OSS Distributions
10*699cd480SApple OSS Distributions int
main(int argc,char * argv[])11*699cd480SApple OSS Distributions main(int argc, char *argv[])
12*699cd480SApple OSS Distributions {
13*699cd480SApple OSS Distributions int opt;
14*699cd480SApple OSS Distributions
15*699cd480SApple OSS Distributions syscall_rejection_selector_t masks[16] = { 0 };
16*699cd480SApple OSS Distributions
17*699cd480SApple OSS Distributions int pos = 0;
18*699cd480SApple OSS Distributions unsigned char selector = 0;
19*699cd480SApple OSS Distributions bool next_is_allow = false;
20*699cd480SApple OSS Distributions
21*699cd480SApple OSS Distributions uint64_t flags = SYSCALL_REJECTION_FLAGS_DEFAULT;
22*699cd480SApple OSS Distributions
23*699cd480SApple OSS Distributions while ((opt = getopt(argc, argv, "ads:i:OF")) != -1) {
24*699cd480SApple OSS Distributions switch (opt) {
25*699cd480SApple OSS Distributions case 'a':
26*699cd480SApple OSS Distributions next_is_allow = true;
27*699cd480SApple OSS Distributions break;
28*699cd480SApple OSS Distributions case 'd':
29*699cd480SApple OSS Distributions next_is_allow = false;
30*699cd480SApple OSS Distributions break;
31*699cd480SApple OSS Distributions case 's':
32*699cd480SApple OSS Distributions selector = (syscall_rejection_selector_t)atoi(optarg);
33*699cd480SApple OSS Distributions break;
34*699cd480SApple OSS Distributions case 'i':
35*699cd480SApple OSS Distributions pos = atoi(optarg);
36*699cd480SApple OSS Distributions if (next_is_allow) {
37*699cd480SApple OSS Distributions // printf("%i: ALLOW %u\n", pos, (unsigned int)selector);
38*699cd480SApple OSS Distributions masks[pos] = SYSCALL_REJECTION_ALLOW(selector);
39*699cd480SApple OSS Distributions } else {
40*699cd480SApple OSS Distributions // printf("%i: DENY %u\n", pos, (unsigned int)selector);
41*699cd480SApple OSS Distributions masks[pos] = SYSCALL_REJECTION_DENY(selector);
42*699cd480SApple OSS Distributions }
43*699cd480SApple OSS Distributions break;
44*699cd480SApple OSS Distributions case 'O':
45*699cd480SApple OSS Distributions flags |= SYSCALL_REJECTION_FLAGS_ONCE;
46*699cd480SApple OSS Distributions break;
47*699cd480SApple OSS Distributions case 'F':
48*699cd480SApple OSS Distributions flags |= SYSCALL_REJECTION_FLAGS_FORCE_FATAL;
49*699cd480SApple OSS Distributions break;
50*699cd480SApple OSS Distributions default:
51*699cd480SApple OSS Distributions fprintf(stderr, "unknown option '%c'\n", opt);
52*699cd480SApple OSS Distributions exit(2);
53*699cd480SApple OSS Distributions }
54*699cd480SApple OSS Distributions }
55*699cd480SApple OSS Distributions
56*699cd480SApple OSS Distributions debug_syscall_reject_config(masks, sizeof(masks) / sizeof(masks[0]), flags);
57*699cd480SApple OSS Distributions
58*699cd480SApple OSS Distributions int __unused ret = chdir("/tmp");
59*699cd480SApple OSS Distributions
60*699cd480SApple OSS Distributions syscall_rejection_selector_t all_allow_masks[16] = { 0 };
61*699cd480SApple OSS Distributions all_allow_masks[0] = SYSCALL_REJECTION_ALLOW(SYSCALL_REJECTION_ALL);
62*699cd480SApple OSS Distributions
63*699cd480SApple OSS Distributions debug_syscall_reject_config(all_allow_masks, sizeof(all_allow_masks) / sizeof(all_allow_masks[0]), SYSCALL_REJECTION_FLAGS_DEFAULT);
64*699cd480SApple OSS Distributions
65*699cd480SApple OSS Distributions return 0;
66*699cd480SApple OSS Distributions }
67