diff options
Diffstat (limited to 'src/utils/sandbox.nim')
-rw-r--r-- | src/utils/sandbox.nim | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/utils/sandbox.nim b/src/utils/sandbox.nim index 88fc5c10..70e592d6 100644 --- a/src/utils/sandbox.nim +++ b/src/utils/sandbox.nim @@ -1,13 +1,36 @@ when defined(freebsd): import bindings/capsicum -when defined(freebsd): - proc enterSandbox*() = + proc enterBufferSandbox*(sockPath: string) = # 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() + + proc enterNetworkSandbox*() = + # no difference between buffer; Capsicum is quite straightforward + # to use in this regard. + discard cap_enter() +elif defined(openbsd): + import bindings/pledge + + proc enterBufferSandbox*(sockPath: string) = + # take whatever we need to + # * fork + # * create/use UNIX domain sockets in sockPath + # * take FDs from the main process + # cw is the minimum for being able to make sockets + doAssert unveil(cstring(sockPath), "cw") == 0 + # note: ordering is important; pledge now removes the unveil promise. + doAssert pledge("unix stdio sendfd recvfd proc cpath", nil) == 0 + + proc enterNetworkSandbox*() = + # we don't need much to write out data from sockets to stdout. + doAssert pledge("stdio", nil) == 0 else: - proc enterSandbox*() = + proc enterBufferSandbox*(sockPath: string) = + discard + + proc enterNetworkSandbox*() = discard |