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