summary refs log tree commit diff stats
path: root/main_openbsd.go
blob: 7bbe99551f4bda782c04c5a4d46219dce278afd5 (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
45
46
47
48
49
50
51
// +build openbsd

package main

import (
	"os"

	"golang.org/x/sys/unix"
	"tildegit.org/andinus/lynx"
)

func main() {
	// We need less permissions on these conditions.
	if len(os.Args) == 1 ||
		os.Args[1] == "version" ||
		os.Args[1] == "env" {
		err := unix.PledgePromises("stdio")
		panicOnErr(err)
	} else {
		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)
}