Feature#set!: Verify the given path exists

This commit is contained in:
0x1eef 2024-03-07 20:25:35 -03:00
parent f95ea4e8f4
commit 6ea77f862f

View file

@ -7,30 +7,30 @@ static VALUE get_rb_eError(void);
* BSD::Control::Feature#set!
**/
VALUE
feature_set(VALUE self, VALUE path, VALUE state)
feature_set(VALUE self, VALUE rb_path, VALUE rb_state)
{
int r;
char *cpath;
VALUE name;
Check_Type(rb_path, T_STRING);
Check_Type(rb_state, T_FIXNUM);
if (getuid() != 0) {
rb_raise(get_rb_eError(), "This operation requires root privileges.");
}
Check_Type(path, T_STRING);
Check_Type(state, T_FIXNUM);
cpath = RSTRING_PTR(path);
name = rb_funcall(self, rb_intern("name"), 0);
Check_Type(name, T_STRING);
} else if (rb_funcall(rb_cFile, rb_intern("exist?"), 1, rb_path) == Qfalse) {
rb_raise(get_rb_eError(), "The given path does not exist.");
} else {
int r;
VALUE rb_name;
rb_name = rb_funcall(self, rb_intern("name"), 0);
Check_Type(rb_name, T_STRING);
r = hbsdcontrol_set_feature_state(
cpath,
RSTRING_PTR(name),
NUM2INT(state)
RSTRING_PTR(rb_path),
RSTRING_PTR(rb_name),
NUM2INT(rb_state)
);
if (r == 0) {
return (Qtrue);
} else {
rb_raise(get_rb_eError(), "hbsdcontrol_set_feature_state failed");
}
}
}