Require root privileges to enable/disable/sysdef a feature
This commit is contained in:
parent
b9eb342c84
commit
50a5d52353
1 changed files with 14 additions and 4 deletions
|
@ -1,5 +1,15 @@
|
|||
#include <ruby.h>
|
||||
#include <libhbsdcontrol.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static VALUE
|
||||
bsd_eError(void)
|
||||
{
|
||||
VALUE rb_mBSD = rb_const_get(rb_cObject, rb_intern("BSD")),
|
||||
rb_mControl = rb_const_get(rb_mBSD, rb_intern("Control")),
|
||||
rb_eError = rb_const_get(rb_mControl, rb_intern("Error"));
|
||||
return rb_eError;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ffi_library_version(VALUE self)
|
||||
|
@ -41,6 +51,9 @@ feature_set(VALUE self, VALUE path, VALUE state)
|
|||
char *cpath;
|
||||
VALUE name;
|
||||
|
||||
if (getuid() != 0) {
|
||||
rb_raise(bsd_eError(), "This operation requires root privileges.");
|
||||
}
|
||||
Check_Type(path, T_STRING);
|
||||
Check_Type(state, T_FIXNUM);
|
||||
cpath = RSTRING_PTR(path);
|
||||
|
@ -54,10 +67,7 @@ feature_set(VALUE self, VALUE path, VALUE state)
|
|||
if (r == 0) {
|
||||
return Qtrue;
|
||||
} else {
|
||||
VALUE rb_mBSD = rb_const_get(rb_cObject, rb_intern("BSD")),
|
||||
rb_mControl = rb_const_get(rb_mBSD, rb_intern("Control")),
|
||||
rb_eError = rb_const_get(rb_mControl, rb_intern("Error"));
|
||||
rb_raise(rb_eError, "hbsdcontrol_set_feature_state failed");
|
||||
rb_raise(bsd_eError(), "hbsdcontrol_set_feature_state failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue