about summary refs log tree commit diff stats
path: root/src/utils
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-05 21:57:36 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-05 21:57:36 +0200
commitdf3838f373a688b0faffec7d8b98198661e7a3d7 (patch)
tree4f1296be4cc3cd182b84f53a9989fd95a3c43b0a /src/utils
parent2c087d701becb78efc0d40ddbb82e11641df6643 (diff)
downloadchawan-df3838f373a688b0faffec7d8b98198661e7a3d7.tar.gz
main: misc improvements
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/sandbox.nim23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/utils/sandbox.nim b/src/utils/sandbox.nim
index a700ea2e..efc03e49 100644
--- a/src/utils/sandbox.nim
+++ b/src/utils/sandbox.nim
@@ -33,7 +33,24 @@
 
 const disableSandbox {.booldefine.} = false
 
-when defined(freebsd) and not disableSandbox:
+type SandboxType* = enum
+  stNone = "no sandbox"
+  stCapsicum = "capsicum"
+  stPledge = "pledge"
+  stLibSeccomp = "libseccomp"
+
+const SandboxMode* = when disableSandbox:
+  stNone
+elif defined(freebsd):
+  stCapsicum
+elif defined(openbsd):
+  stPledge
+elif defined(linux):
+  stLibSeccomp
+else:
+  stNone
+
+when SandboxMode == stCapsicum:
   import bindings/capsicum
 
   proc enterBufferSandbox*(sockPath: string) =
@@ -47,7 +64,7 @@ when defined(freebsd) and not disableSandbox:
     # no difference between buffer; Capsicum is quite straightforward
     # to use in this regard.
     discard cap_enter()
-elif defined(openbsd) and not disableSandbox:
+elif SandboxMode == stPledge:
   import bindings/pledge
 
   proc enterBufferSandbox*(sockPath: string) =
@@ -60,7 +77,7 @@ elif defined(openbsd) and not disableSandbox:
   proc enterNetworkSandbox*() =
     # we don't need much to write out data from sockets to stdout.
     doAssert pledge("stdio", nil) == 0
-elif defined(linux) and not disableSandbox:
+elif SandboxMode == stLibSeccomp:
   import std/posix
   import bindings/libseccomp