Blob


1 #include "gmid.h"
3 #if defined(__FreeBSD__)
5 #include <sys/capsicum.h>
6 #include <err.h>
8 void
9 sandbox()
10 {
11 struct vhost *h;
12 int has_cgi = 0;
14 for (h = hosts; h->domain != NULL; ++h)
15 if (h->cgi != NULL)
16 has_cgi = 1;
18 if (has_cgi) {
19 LOGW(NULL, "disabling sandbox because CGI scripts are enabled");
20 return;
21 }
23 if (cap_enter() == -1)
24 err(1, "cap_enter");
25 }
27 #elif defined(__linux__)
29 void
30 sandbox()
31 {
32 /* TODO: seccomp */
33 }
35 #elif defined(__OpenBSD__)
37 #include <err.h>
38 #include <unistd.h>
40 void
41 sandbox()
42 {
43 struct vhost *h;
44 int has_cgi = 0;
46 for (h = hosts; h->domain != NULL; ++h) {
47 if (unveil(h->dir, "rx") == -1)
48 err(1, "unveil %s for domain %s", h->dir, h->domain);
50 if (h->cgi != NULL)
51 has_cgi = 1;
52 }
54 if (pledge("stdio rpath inet proc exec", NULL) == -1)
55 err(1, "pledge");
57 /* drop proc and exec if cgi isn't enabled */
58 if (!has_cgi)
59 if (pledge("stdio rpath inet", NULL) == -1)
60 err(1, "pledge");
61 }
63 #else
65 void
66 sandbox()
67 {
68 LOGN(NULL, "%s", "no sandbox method known for this OS");
69 }
71 #endif