Adds MLSEnabled function.#192
Adds MLSEnabled function.#192thaJeztah merged 1 commit intoopencontainers:mainfrom badochov:is_selinux_mls_enabled
Conversation
|
LGTM |
thaJeztah
left a comment
There was a problem hiding this comment.
Thanks! left comments inline
go-selinux/selinux_linux.go
Outdated
|
|
||
| // isMLSEnabled checks if MLS is enabled. | ||
| func isMLSEnabled() bool { | ||
| enabledB, err := os.ReadFile(selinuxMLSEnabledPath()) |
There was a problem hiding this comment.
I see it's done in other places as well, but I think the selinuxMLSEnabledPath() may be a bit "too much abstraction", especially as we only use it in a single place; perhaps just inline it;
enabledB, err := os.ReadFile(filepath.Join(getSelinuxMountPoint(), "mls"))
go-selinux/selinux_linux.go
Outdated
| return false | ||
| } | ||
|
|
||
| return !bytes.Equal(enabledB, []byte{'1'}) |
There was a problem hiding this comment.
Should this be the reverse? (i.e., it return true if the file contains 1 ?
There was a problem hiding this comment.
There was a problem hiding this comment.
Ooooh!
/*
* Function: is_selinux_mls_enabled()
* Return: 1 on success
* 0 on failure
*/
Hm.. right; perhaps would be good to add a comment there to describe it (perhaps also with that link) to explain this is really correct 😅.
There was a problem hiding this comment.
I don't think we need the reverse it, in the linked code I see:
if (!strcmp(buf, "1"))
enabled = 1;
Doesn't that mean the function returns 1 when buf is "1"?
There was a problem hiding this comment.
i was going through this line and documentation of strcmo multiple times I have no idea how I convoced myself to be wrong so many times
There was a problem hiding this comment.
OH MY! 🤦 for some reason I completely didn't spot that as well. Thanks @giuseppe !!! (it adds to my dislike of "too many booleans")
go-selinux/selinux.go
Outdated
| // IsMLSEnabled checks if MLS is enabled. | ||
| func IsMLSEnabled() bool { |
There was a problem hiding this comment.
It's more conventional in Go to omit Is prefixes (as the bool return already describes it's a boolean result). (Same for Get (and Set), but that's already in the code, so we can't reverse that 😂).
Perhaps (same for the non-exported variants);
// MLSEnabled checks if MLS is enabled.
func MLSEnabled() bool {Which will be called as selinux.MLSEnabled(), e.g.
if selinux.MLSEnabled() {
// do magic stuff!
}There was a problem hiding this comment.
Thank for information :D. I didn't change name of the helper as i could figure out any other name that would be sane and unexported.
| func isMLSEnabled() bool { | ||
| } |
There was a problem hiding this comment.
This needs a return;
func isMLSEnabled() bool {
return false
}|
@badochov you may have missed my last comment;
While updating, could you also update the commit message (change |
|
Oh, never mind, I see you also didn't address the other comment yet 😅 (let me know when it's updated 👍 ) |
|
@thaJeztah I've updated the PR. |
Closes #176. Signed-off-by: Hubert Badocha <[email protected]>
As in https://github.com/SELinuxProject/selinux/blob/master/libselinux/src/enabled.c#L29
Closes #176.