diff options
author | bptato <nincsnevem662@gmail.com> | 2024-03-28 01:36:29 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-03-28 01:36:29 +0100 |
commit | b530ccc899a8cc8c63bad29abe1e479eb999b167 (patch) | |
tree | 07062947dfda3ac4356b0ce26de1cbe4e4c87ebd /src/utils/sandbox.nim | |
parent | 52c415762fda7b9369ed4cf88783a6639574e3ea (diff) | |
download | chawan-b530ccc899a8cc8c63bad29abe1e479eb999b167.tar.gz |
Add capsicum support
It's the sandboxing system of FreeBSD. Quite pleasant to work with. (Just trying to figure out the basics with this one before tackling the abomination that is seccomp.) Indeed, the only non-trivial part was getting newSelector to work with Capsicum. Long story short it doesn't, so we use an ugly pointer cast + assignment. But even that is stdlib's "fault", not Capsicum's. This also gets rid of that ugly SocketPath global.
Diffstat (limited to 'src/utils/sandbox.nim')
-rw-r--r-- | src/utils/sandbox.nim | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/utils/sandbox.nim b/src/utils/sandbox.nim new file mode 100644 index 00000000..88fc5c10 --- /dev/null +++ b/src/utils/sandbox.nim @@ -0,0 +1,13 @@ +when defined(freebsd): + import bindings/capsicum + +when defined(freebsd): + proc enterSandbox*() = + # per man:cap_enter(2), it may return ENOSYS if the kernel was compiled + # without CAPABILITY_MODE. So it seems better not to panic in this case. + # (But TODO: when we get enough sandboxing coverage it should print a + # warning or something.) + discard cap_enter() +else: + proc enterSandbox*() = + discard |