summary refs log tree commit diff stats
path: root/main_openbsd.go
diff options
context:
space:
mode:
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)
+}