summaryrefslogtreecommitdiff
path: root/sandbox.c
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox.c')
-rw-r--r--sandbox.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/sandbox.c b/sandbox.c
index cbe0043..875ae4e 100644
--- a/sandbox.c
+++ b/sandbox.c
@@ -8,8 +8,6 @@ void sbox_enter(const char *basedir)
8{ 8{
9 const char *address = xs_dict_get(srv_config, "address"); 9 const char *address = xs_dict_get(srv_config, "address");
10 10
11 int smail = !xs_is_true(xs_dict_get(srv_config, "disable_email_notifications"));
12
13 if (xs_is_true(xs_dict_get(srv_config, "disable_openbsd_security"))) { 11 if (xs_is_true(xs_dict_get(srv_config, "disable_openbsd_security"))) {
14 srv_log(xs_dup("OpenBSD security disabled by admin")); 12 srv_log(xs_dup("OpenBSD security disabled by admin"));
15 return; 13 return;
@@ -24,9 +22,6 @@ void sbox_enter(const char *basedir)
24 unveil("/etc/ssl/cert.pem", "r"); 22 unveil("/etc/ssl/cert.pem", "r");
25 unveil("/usr/share/zoneinfo", "r"); 23 unveil("/usr/share/zoneinfo", "r");
26 24
27 if (smail)
28 unveil("/usr/sbin/sendmail", "x");
29
30 if (*address == '/') 25 if (*address == '/')
31 unveil(address, "rwc"); 26 unveil(address, "rwc");
32 27
@@ -36,9 +31,6 @@ void sbox_enter(const char *basedir)
36 31
37 xs *p = xs_str_new("stdio rpath wpath cpath flock inet proc dns fattr"); 32 xs *p = xs_str_new("stdio rpath wpath cpath flock inet proc dns fattr");
38 33
39 if (smail)
40 p = xs_str_cat(p, " exec");
41
42 if (*address == '/') 34 if (*address == '/')
43 p = xs_str_cat(p, " unix"); 35 p = xs_str_cat(p, " unix");
44 36
@@ -55,7 +47,7 @@ void sbox_enter(const char *basedir)
55#include "landloc.h" 47#include "landloc.h"
56 48
57static 49static
58LL_BEGIN(sbox_enter_linux_, const char* basedir, const char *address, int smail) { 50LL_BEGIN(sbox_enter_linux_, const char* basedir, const char *address, int smtp_port) {
59 51
60 const unsigned long long 52 const unsigned long long
61 rd = LANDLOCK_ACCESS_FS_READ_DIR, 53 rd = LANDLOCK_ACCESS_FS_READ_DIR,
@@ -94,9 +86,6 @@ LL_BEGIN(sbox_enter_linux_, const char* basedir, const char *address, int smail)
94 LL_PATH(sdir, s); 86 LL_PATH(sdir, s);
95 } 87 }
96 88
97 if (smail && mtime("/usr/sbin/sendmail") > 0)
98 LL_PATH("/usr/sbin/sendmail", x);
99
100 if (*address != '/') { 89 if (*address != '/') {
101 unsigned short listen_port = xs_number_get(xs_dict_get(srv_config, "port")); 90 unsigned short listen_port = xs_number_get(xs_dict_get(srv_config, "port"));
102 LL_PORT(listen_port, LANDLOCK_ACCESS_NET_BIND_TCP_COMPAT); 91 LL_PORT(listen_port, LANDLOCK_ACCESS_NET_BIND_TCP_COMPAT);
@@ -104,24 +93,34 @@ LL_BEGIN(sbox_enter_linux_, const char* basedir, const char *address, int smail)
104 93
105 LL_PORT(80, LANDLOCK_ACCESS_NET_CONNECT_TCP_COMPAT); 94 LL_PORT(80, LANDLOCK_ACCESS_NET_CONNECT_TCP_COMPAT);
106 LL_PORT(443, LANDLOCK_ACCESS_NET_CONNECT_TCP_COMPAT); 95 LL_PORT(443, LANDLOCK_ACCESS_NET_CONNECT_TCP_COMPAT);
96 if (smtp_port > 0)
97 LL_PORT((unsigned short)smtp_port, LANDLOCK_ACCESS_NET_CONNECT_TCP_COMPAT);
107 98
108} LL_END 99} LL_END
109 100
110void sbox_enter(const char *basedir) 101void sbox_enter(const char *basedir)
111{ 102{
103 const xs_val *v;
104 const char *errstr;
112 const char *address = xs_dict_get(srv_config, "address"); 105 const char *address = xs_dict_get(srv_config, "address");
113 106 int smtp_port = -1;
114 int smail = !xs_is_true(xs_dict_get(srv_config, "disable_email_notifications"));
115 107
116 if (xs_is_true(xs_dict_get(srv_config, "disable_sandbox"))) { 108 if (xs_is_true(xs_dict_get(srv_config, "disable_sandbox"))) {
117 srv_debug(1, xs_dup("Linux sandbox disabled by admin")); 109 srv_debug(1, xs_dup("Linux sandbox disabled by admin"));
118 return; 110 return;
119 } 111 }
120 112
121 if (sbox_enter_linux_(basedir, address, smail) == 0) 113 if ((v = xs_dict_get(srv_config, "email_notifications")) &&
114 (v = xs_dict_get(v, "url"))) {
115 smtp_port = parse_port((const char *)v, &errstr);
116 if (errstr)
117 srv_debug(0, xs_fmt("Couldn't determine port from '%s': %s", (const char *)v, errstr));
118 }
119
120 if (sbox_enter_linux_(basedir, address, smtp_port) == 0)
122 srv_debug(1, xs_dup("Linux sandbox enabled")); 121 srv_debug(1, xs_dup("Linux sandbox enabled"));
123 else 122 else
124 srv_debug(1, xs_dup("Linux sandbox failed")); 123 srv_debug(0, xs_dup("Linux sandbox failed"));
125} 124}
126 125
127#else /* defined(WITH_LINUX_SANDBOX) */ 126#else /* defined(WITH_LINUX_SANDBOX) */