Apply diff for patch
This commit is contained in:
parent
a86304783f
commit
e311d78c7c
6 changed files with 49 additions and 19 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <libhbsdcontrol.h>
|
#include <libhbsdcontrol.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "include/feature.h"
|
#include "include/feature.h"
|
||||||
static VALUE __rb_eError(void);
|
static VALUE __rb_eError(void);
|
||||||
static VALUE __set(VALUE, VALUE, VALUE);
|
static VALUE __set(VALUE, VALUE, VALUE);
|
||||||
|
@ -12,15 +13,9 @@ feature_set(VALUE self, VALUE rb_path, VALUE rb_state)
|
||||||
{
|
{
|
||||||
Check_Type(rb_path, T_STRING);
|
Check_Type(rb_path, T_STRING);
|
||||||
Check_Type(rb_state, T_FIXNUM);
|
Check_Type(rb_state, T_FIXNUM);
|
||||||
if (getuid() != 0) {
|
|
||||||
rb_raise(__rb_eError(), "This operation requires root privileges.");
|
|
||||||
} else if (rb_funcall(rb_cFile, rb_intern("exist?"), 1, rb_path) == Qfalse) {
|
|
||||||
rb_raise(__rb_eError(), "The given path does not exist.");
|
|
||||||
} else {
|
|
||||||
VALUE rb_feature = rb_funcall(self, rb_intern("name"), 0);
|
VALUE rb_feature = rb_funcall(self, rb_intern("name"), 0);
|
||||||
Check_Type(rb_feature, T_STRING);
|
Check_Type(rb_feature, T_STRING);
|
||||||
return (__set(rb_path, rb_feature, rb_state));
|
return (__set(rb_path, rb_feature, rb_state));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,7 +30,7 @@ __set(VALUE rb_path, VALUE rb_feature, VALUE rb_state)
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
return (Qtrue);
|
return (Qtrue);
|
||||||
} else {
|
} else {
|
||||||
rb_raise(__rb_eError(), "hbsdcontrol_set_feature_state failed");
|
rb_syserr_fail(errno, "hbsdcontrol_set_feature_state");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ module BSD::Control
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# The path to a file.
|
# The path to a file.
|
||||||
#
|
#
|
||||||
# @raise [BSD::Control::Error]
|
# @raise [SystemCallError]
|
||||||
# When the operation fails.
|
# Might raise a number of Errno exceptions.
|
||||||
#
|
#
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
# Returns true on success.
|
# Returns true on success.
|
||||||
|
@ -31,8 +31,8 @@ module BSD::Control
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# The path to a file.
|
# The path to a file.
|
||||||
#
|
#
|
||||||
# @raise [BSD::Control::Error]
|
# @raise [SystemCallError]
|
||||||
# When the operation fails.
|
# Might raise a number of Errno exceptions.
|
||||||
#
|
#
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
# Returns true on success.
|
# Returns true on success.
|
||||||
|
|
19
test/superuser/disable_feature_test.rb
Normal file
19
test/superuser/disable_feature_test.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
require_relative "../setup"
|
||||||
|
module BSD::Control
|
||||||
|
class DisableFeatureTest < Test::Unit::TestCase
|
||||||
|
require 'fileutils'
|
||||||
|
include FileUtils
|
||||||
|
|
||||||
|
def test_disable_mprotect_nonexistent_file
|
||||||
|
assert_raises Errno::ENOENT do
|
||||||
|
BSD::Control.feature(:mprotect).disable!(file)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def file
|
||||||
|
File.join(__dir__, "file")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -22,7 +22,7 @@ module BSD::Control
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_enable_mprotect_nonexistent_file
|
def test_enable_mprotect_nonexistent_file
|
||||||
assert_raises(BSD::Control::Error) do
|
assert_raises(Errno::ENOENT) do
|
||||||
BSD::Control.feature(:mprotect).enable!(file)
|
BSD::Control.feature(:mprotect).enable!(file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
19
test/unprivileged/disable_feature_test.rb
Normal file
19
test/unprivileged/disable_feature_test.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
require_relative "../setup"
|
||||||
|
module BSD::Control
|
||||||
|
class DisableFeatureTest < Test::Unit::TestCase
|
||||||
|
require 'fileutils'
|
||||||
|
include FileUtils
|
||||||
|
|
||||||
|
def test_disable_mprotect_nonexistent_file
|
||||||
|
assert_raises(Errno::ENOENT) do
|
||||||
|
BSD::Control.feature(:mprotect).disable!(file)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def file
|
||||||
|
File.join(__dir__, "file")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -6,10 +6,7 @@ module BSD::Control
|
||||||
|
|
||||||
def test_enable_feature_lacks_privileges
|
def test_enable_feature_lacks_privileges
|
||||||
touch(file)
|
touch(file)
|
||||||
assert_raises(
|
assert_raises(Errno::EPERM) do
|
||||||
BSD::Control::Error,
|
|
||||||
"This operation requires root privileges."
|
|
||||||
) do
|
|
||||||
BSD::Control.feature(:mprotect).enable!(file)
|
BSD::Control.feature(:mprotect).enable!(file)
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
|
|
Loading…
Reference in a new issue