summary refs log tree commit diff stats
path: root/main_openbsd.go
blob: 7d466ee8132da69204d4a921e3e859a82963c3c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)
}