summary refs log blame commit diff stats
path: root/main_openbsd.go
blob: 7bbe99551f4bda782c04c5a4d46219dce278afd5 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12











                                   















                                                                






















                                                                
// +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)
}