From c3874d7dae2d260c5dd532b25b92c5e3fdad346b Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Wed, 6 Mar 2024 20:59:54 -0300 Subject: [PATCH] Re-add Feature#sysdef! --- ext/hbsdctl.rb/hbsdctl.c | 23 +++++++++++++++++++++++ lib/bsd/control/feature.rb | 15 +++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/ext/hbsdctl.rb/hbsdctl.c b/ext/hbsdctl.rb/hbsdctl.c index 3b25621..ffa23be 100644 --- a/ext/hbsdctl.rb/hbsdctl.c +++ b/ext/hbsdctl.rb/hbsdctl.c @@ -44,6 +44,28 @@ ffi_available_features(VALUE self) return features; } +static VALUE +ffi_reset(VALUE self, VALUE rb_feature, VALUE rb_path) +{ + VALUE rb_enable_flag, rb_disable_flag; + char *enable_flag, *disable_flag, *path; + + rb_enable_flag = rb_funcall(rb_feature, rb_intern("enable"), 0); + rb_disable_flag = rb_funcall(rb_feature, rb_intern("disable"), 0); + Check_Type(rb_path, T_STRING); + Check_Type(rb_enable_flag, T_STRING); + Check_Type(rb_disable_flag, T_STRING); + path = RSTRING_PTR(rb_path); + enable_flag = RSTRING_PTR(rb_enable_flag); + disable_flag = RSTRING_PTR(rb_disable_flag); + if(hbsdcontrol_extattr_rm_attr(path, disable_flag) == 0 || + hbsdcontrol_extattr_rm_attr(path, enable_flag) == 0) { + return Qtrue; + } else { + return Qfalse; + } +} + static VALUE feature_set(VALUE self, VALUE path, VALUE state) { @@ -83,5 +105,6 @@ Init_hbsdctl(void) rb_define_const(rb_mControl, "Enable", INT2NUM(1)); rb_define_singleton_method(rb_mFFI, "available_features", ffi_available_features, 0); rb_define_singleton_method(rb_mFFI, "library_version", ffi_library_version, 0); + rb_define_singleton_method(rb_mFFI, "reset!", ffi_reset, 2); rb_define_private_method(rb_cFeature, "set!", feature_set, 2); } diff --git a/lib/bsd/control/feature.rb b/lib/bsd/control/feature.rb index 1324a90..c3ec9e7 100644 --- a/lib/bsd/control/feature.rb +++ b/lib/bsd/control/feature.rb @@ -40,6 +40,21 @@ module BSD::Control set!(path, BSD::Control::Disable) end + ## + # Restore system defaults. + # + # @param [String] path + # The path to a file. + # + # @raise [BSD::Control::Error] + # When the operation fails. + # + # @return [Boolean] + # Returns true on success. + def sysdef!(path) + FFI.reset!(self, path) + end + # @endgroup ##