summary refs log tree commit diff stats
path: root/main_openbsd.go
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-04-08 04:31:21 +0530
committerAndinus <andinus@nand.sh>2020-04-08 04:37:48 +0530
commitfa68976a3e7adb8c2c3327c6afc44fef24297337 (patch)
treebe78b3586c60a47845f2c334478628a86fda1d14 /main_openbsd.go
parenta3ede2f5edd006affda8ab386dee3fd44d61c473 (diff)
downloadgrus-fa68976a3e7adb8c2c3327c6afc44fef24297337.tar.gz
Initial rewrite of grus
Diffstat (limited to 'main_openbsd.go')
-rw-r--r--main_openbsd.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/main_openbsd.go b/main_openbsd.go
new file mode 100644
index 0000000..7d466ee
--- /dev/null
+++ b/main_openbsd.go
@@ -0,0 +1,44 @@
+// +build openbsd
+
+package main
+
+import (
+	"os"
+
+	"golang.org/x/sys/unix"
+	"tildegit.org/andinus/lynx"
+)
+
+func main() {
+	err := unix.PledgePromises("unveil stdio rpath")
+	panicOnErr(err)
+
+	unveil()
+
+	// Drop unveil from promises.
+	err = unix.PledgePromises("stdio rpath")
+	panicOnErr(err)
+
+	grus()
+}
+
+func unveil() {
+	paths := make(map[string]string)
+
+	paths["/usr/share/dict"] = "r"
+	paths["/usr/local/share/dict"] = "r"
+
+	// Unveil user defined dictionaries.
+	if len(os.Args) >= 3 {
+		for _, dict := range os.Args[2:] {
+			paths[dict] = "r"
+		}
+	}
+	// This will not return error if the file doesn't exist.
+	err := lynx.UnveilPaths(paths)
+	panicOnErr(err)
+
+	// Block further unveil calls.
+	err = lynx.UnveilBlock()
+	panicOnErr(err)
+}