Skip to content

Commit

Permalink
Merge pull request #192 from badochov/is_selinux_mls_enabled
Browse files Browse the repository at this point in the history
Adds MLSEnabled function.
  • Loading branch information
thaJeztah authored Oct 21, 2022
2 parents 9832127 + d592efa commit 41ff4c2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go-selinux/selinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ func ReserveLabel(label string) {
reserveLabel(label)
}

// MLSEnabled checks if MLS is enabled.
func MLSEnabled() bool {
return isMLSEnabled()
}

// EnforceMode returns the current SELinux mode Enforcing, Permissive, Disabled
func EnforceMode() int {
return enforceMode()
Expand Down
9 changes: 9 additions & 0 deletions go-selinux/selinux_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,15 @@ func selinuxEnforcePath() string {
return filepath.Join(getSelinuxMountPoint(), "enforce")
}

// isMLSEnabled checks if MLS is enabled.
func isMLSEnabled() bool {
enabledB, err := os.ReadFile(filepath.Join(getSelinuxMountPoint(), "mls"))
if err != nil {
return false
}
return bytes.Equal(enabledB, []byte{'1'})
}

// enforceMode returns the current SELinux mode Enforcing, Permissive, Disabled
func enforceMode() int {
var enforce int
Expand Down
4 changes: 4 additions & 0 deletions go-selinux/selinux_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func clearLabels() {
func reserveLabel(label string) {
}

func isMLSEnabled() bool {
return false
}

func enforceMode() int {
return Disabled
}
Expand Down

0 comments on commit 41ff4c2

Please sign in to comment.