diff options
author | Andinus <andinus@nand.sh> | 2020-04-08 04:31:21 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-04-08 04:37:48 +0530 |
commit | fa68976a3e7adb8c2c3327c6afc44fef24297337 (patch) | |
tree | be78b3586c60a47845f2c334478628a86fda1d14 /main_openbsd.go | |
parent | a3ede2f5edd006affda8ab386dee3fd44d61c473 (diff) | |
download | grus-fa68976a3e7adb8c2c3327c6afc44fef24297337.tar.gz |
Initial rewrite of grus
Diffstat (limited to 'main_openbsd.go')
-rw-r--r-- | main_openbsd.go | 44 |
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) +} |