-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlockdown.go
39 lines (35 loc) · 972 Bytes
/
lockdown.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
package lsm
import (
"errors"
"io/ioutil"
"strings"
)
func parseLockdownScopeFile(path string) (string, error) {
body, err := ioutil.ReadFile(path)
if err != nil {
return "", err
}
//Scope: [none] integrity confidentiality
scopes := strings.Split(strings.TrimSuffix(string(body), "\n"), " ")
for _, scope := range scopes {
if string(scope[0]) == "[" && string(scope[len(scope)-1]) == "]" {
return scope[1 : len(scope)-1], nil
}
}
return "", errors.New("Invalid lockdown format file")
}
// IsLockdownActive checks whether Lockdown LSM is active or not
func (l *LSM) IsLockdownActive() (bool, error) {
scope, err := parseLockdownScopeFile(l.c.LockdownScope)
if err != nil {
return false, err
}
if scope != "none" {
return true, nil
}
return false, nil
}
// LockdownScope gets the current Lockdown scope (none, integrity or confidentiality)
func (l *LSM) LockdownScope() (string, error) {
return parseLockdownScopeFile(l.c.LockdownScope)
}