Add BSD::Control::Feature#sysdef!
This commit is contained in:
parent
c064af26a6
commit
427165d1b7
8 changed files with 76 additions and 11 deletions
|
@ -18,5 +18,6 @@ Init_bsdcontrol(void)
|
||||||
bsdcontrol_context_available_features,
|
bsdcontrol_context_available_features,
|
||||||
0);
|
0);
|
||||||
rb_define_method(rb_cFeature, "status", bsdcontrol_feature_status, 1);
|
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_private_method(rb_cFeature, "set!", bsdcontrol_feature_set, 2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,3 +66,31 @@ bsdcontrol_feature_set(VALUE self, VALUE path, VALUE rbstate)
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* BSD::Control::Feature#sysdef!
|
||||||
|
*/
|
||||||
|
VALUE
|
||||||
|
bsdcontrol_feature_sysdef(VALUE self, VALUE path)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
VALUE rbcontext;
|
||||||
|
hbsdctrl_feature_t *feature;
|
||||||
|
hbsdctrl_ctx_t *ctx;
|
||||||
|
rbcontext = rb_funcall(self, rb_intern("context"), 0);
|
||||||
|
fd = bsdcontrol_open(path);
|
||||||
|
ctx = bsdcontrol_unwrap(rbcontext);
|
||||||
|
feature = bsdcontrol_find_feature(ctx, self);
|
||||||
|
errno = 0;
|
||||||
|
if (feature->hf_unapply(ctx, feature, &fd, NULL) == RES_FAIL)
|
||||||
|
{
|
||||||
|
close(fd);
|
||||||
|
errno == 0 ? rb_raise(rb_eSystemCallError, "hf_unapply")
|
||||||
|
: rb_syserr_fail(errno, "hf_unapply");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
close(fd);
|
||||||
|
return Qtrue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
#include <ruby.h>
|
#include <ruby.h>
|
||||||
VALUE bsdcontrol_feature_status(VALUE, VALUE);
|
VALUE bsdcontrol_feature_status(VALUE, VALUE);
|
||||||
VALUE bsdcontrol_feature_set(VALUE,VALUE,VALUE);
|
VALUE bsdcontrol_feature_set(VALUE,VALUE,VALUE);
|
||||||
|
VALUE bsdcontrol_feature_sysdef(VALUE, VALUE);
|
||||||
|
|
|
@ -41,6 +41,7 @@ module BSD::Control
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
# @!method sysdef!(path)
|
||||||
# Restore system defaults for a given file.
|
# Restore system defaults for a given file.
|
||||||
#
|
#
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
|
@ -51,9 +52,6 @@ module BSD::Control
|
||||||
#
|
#
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
# Returns true on success.
|
# Returns true on success.
|
||||||
def sysdef!(path)
|
|
||||||
# FIXME: implement.
|
|
||||||
end
|
|
||||||
|
|
||||||
# @endgroup
|
# @endgroup
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
require "test/unit"
|
require "test/unit"
|
||||||
require "hbsdctl"
|
require "bsdcontrol"
|
||||||
|
|
37
test/superuser/sysdef_feature_test.rb
Normal file
37
test/superuser/sysdef_feature_test.rb
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
require_relative "../setup"
|
||||||
|
module BSD::Control
|
||||||
|
class SysDefFeatureTest < Test::Unit::TestCase
|
||||||
|
require 'fileutils'
|
||||||
|
include FileUtils
|
||||||
|
|
||||||
|
def test_sysdef_pageexec
|
||||||
|
touch(file)
|
||||||
|
assert BSD::Control.feature(:pageexec).enable!(file),
|
||||||
|
"The enable! method should have returned true"
|
||||||
|
assert_equal(
|
||||||
|
BSD::Control.feature(:pageexec).status(file),
|
||||||
|
:enabled
|
||||||
|
)
|
||||||
|
assert BSD::Control.feature(:pageexec).sysdef!(file),
|
||||||
|
"The sysdef! method should have returned true"
|
||||||
|
assert_equal(
|
||||||
|
BSD::Control.feature(:pageexec).status(file),
|
||||||
|
:sysdef
|
||||||
|
)
|
||||||
|
ensure
|
||||||
|
rm(file)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_enable_pageexec_nonexistent_file
|
||||||
|
assert_raises(Errno::ENOENT) do
|
||||||
|
BSD::Control.feature(:pageexec).sysdef!(file)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def file
|
||||||
|
File.join(__dir__, "file")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue