-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmacos_sip.go
More file actions
44 lines (34 loc) · 994 Bytes
/
macos_sip.go
File metadata and controls
44 lines (34 loc) · 994 Bytes
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
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1
package resources
import (
"io"
"strings"
"go.mondoo.com/mql/v13/providers/os/connection/shared"
)
func (m *mqlMacosSip) status() (string, error) {
conn := m.MqlRuntime.Connection.(shared.Connection)
cmd, err := conn.RunCommand("csrutil status")
if err != nil {
return "", err
}
data, err := io.ReadAll(cmd.Stdout)
if err != nil {
return "", err
}
// csrutil status outputs:
// "System Integrity Protection status: enabled."
// "System Integrity Protection status: disabled."
// May also include individual configuration flags on separate lines
output := strings.TrimSpace(string(data))
// Return the first line which contains the primary status
lines := strings.SplitN(output, "\n", 2)
return strings.TrimSpace(lines[0]), nil
}
func (m *mqlMacosSip) enabled() (bool, error) {
status, err := m.status()
if err != nil {
return false, err
}
return strings.Contains(status, "enabled"), nil
}