summary refs log tree commit diff stats
path: root/unveil.go
blob: 924c21e0b445c4169493748d5f0508f3a26cc56a (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
52
53
54
55
package main

import (
	"fmt"
	"os"

	"tildegit.org/andinus/lynx"
)

// blockUnveil func blocks further unveil calls.
func blockUnveil() {
	err := lynx.UnveilBlock()
	if err != nil {
		fmt.Printf("%s :: %s",
			"UnveilBlock() failed",
			err.Error())
		os.Exit(1)
	}

	// We drop unveil from promises after blocking it. We drop
	// rpath too because the config file has been read.
	err = lynx.PledgePromises("stdio rpath exec proc")
	if err != nil {
		fmt.Printf("%s :: %s",
			"blockUnveil failed",
			err.Error())
		os.Exit(1)
	}
}

// initUnveil initializes unveil for inital use.
func initUnveil() {
	err := lynx.Unveil(configFile(), "rc")
	if err != nil {
		fmt.Printf("%s :: %s",
			"Unveil configFile failed",
			err.Error())
		os.Exit(1)
	}

	// os.Exec fails if "/dev/null" is not unveiled & for some
	// reason it calls "/dev/urandom" inititally so we unveil it
	// too because there should be no harm in doing so.
	paths := make(map[string]string)
	paths["/dev/null"] = "r"
	paths["/dev/urandom"] = "r"

	err = lynx.UnveilPaths(paths)
	if err != nil {
		fmt.Printf("%s :: %s",
			"Unveil failed",
			err.Error())
		os.Exit(1)
	}
}