Map HBSDCTRL_STATE_(ENABLED|DISABLED) into Ruby

And fix `BSD::Control::Feature#disable!`.
This commit is contained in:
0x1eef 2024-03-20 21:58:18 -03:00
parent a4e5b8893f
commit 275d622843
3 changed files with 16 additions and 2 deletions

View file

@ -20,4 +20,6 @@ Init_bsdcontrol(void)
rb_define_method(rb_cFeature, "status", bsdcontrol_feature_status, 1);
rb_define_method(rb_cFeature, "sysdef!", bsdcontrol_feature_sysdef, 1);
rb_define_private_method(rb_cFeature, "set!", bsdcontrol_feature_set, 2);
rb_define_const(rb_cFeature, "ENABLED", INT2NUM(HBSDCTRL_STATE_ENABLED));
rb_define_const(rb_cFeature, "DISABLED", INT2NUM(HBSDCTRL_STATE_DISABLED));
}

View file

@ -22,7 +22,7 @@ module BSD::Control
# @return [Boolean]
# Returns true on success.
def enable!(path)
set!(path, 1)
set!(path, ENABLED)
end
##
@ -37,7 +37,7 @@ module BSD::Control
# @return [Boolean]
# Returns true on success.
def disable!(path)
set!(path, 0)
set!(path, DISABLED)
end
##

View file

@ -4,6 +4,18 @@ module BSD::Control
require 'fileutils'
include FileUtils
def test_disable_pageexec
touch(file)
assert BSD::Control.feature(:pageexec).disable!(file),
"The disable! method should have returned true"
assert_equal(
:disabled,
BSD::Control.feature(:pageexec).status(file)
)
ensure
rm(file)
end
def test_disable_pageexec_nonexistent_file
assert_raises(Errno::ENOENT) do
BSD::Control.feature(:pageexec).disable!(file)