-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathaccessfs.go
68 lines (59 loc) · 1.12 KB
/
accessfs.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
package landlock
import (
"fmt"
"strings"
)
var flagNames = []string{
"Execute",
"WriteFile",
"ReadFile",
"ReadDir",
"RemoveDir",
"RemoveFile",
"MakeChar",
"MakeDir",
"MakeReg",
"MakeSock",
"MakeFifo",
"MakeBlock",
"MakeSym",
}
// AccessFSSet is a set of Landlockable file system access operations.
type AccessFSSet uint64
var supportedAccessFS = AccessFSSet((1 << 13) - 1)
func (a AccessFSSet) String() string {
if a.isEmpty() {
return "∅"
}
var b strings.Builder
b.WriteByte('{')
for i := 0; i < 64; i++ {
if a&(1<<i) == 0 {
continue
}
if b.Len() > 1 {
b.WriteByte(',')
}
if i < len(flagNames) {
b.WriteString(flagNames[i])
} else {
b.WriteString(fmt.Sprintf("1<<%v", i))
}
}
b.WriteByte('}')
return b.String()
}
func (a AccessFSSet) isSubset(b AccessFSSet) bool {
return a&b == a
}
func (a AccessFSSet) intersect(b AccessFSSet) AccessFSSet {
return a & b
}
func (a AccessFSSet) isEmpty() bool {
return a == 0
}
// valid returns true iff the given AccessFSSet is supported by this
// version of go-landlock.
func (a AccessFSSet) valid() bool {
return a.isSubset(supportedAccessFS)
}