Ruby bindings for libhbsdcontrol(3)
Find a file
2024-03-08 02:17:15 -03:00
.bundle First commit 2024-02-29 22:29:43 -03:00
bin Add more testcases 2024-03-07 22:57:24 -03:00
ext/hbsdctl.rb FFI.reset -> FFI.sysdef! 2024-03-08 01:19:05 -03:00
lib Update API docs 2024-03-08 02:17:15 -03:00
test Control#feature! -> Control#feature 2024-03-08 01:23:16 -03:00
.gitignore First commit 2024-02-29 22:29:43 -03:00
.projectile First commit 2024-02-29 22:29:43 -03:00
.styleguide.cfg Add .styleguide.cfg 2024-03-07 01:34:34 -03:00
Gemfile First commit 2024-02-29 22:29:43 -03:00
Gemfile.lock Add testcases 2024-03-07 20:30:36 -03:00
hbsdctl.rb.gemspec gemspec: update 2024-03-07 22:57:24 -03:00
LICENSE Add LICENSE 2024-02-29 22:35:05 -03:00
Rakefile.rb Add testcases 2024-03-07 20:30:36 -03:00
README.md README: update 2024-03-08 02:12:12 -03:00

About

hbsdctl.rb is a C extension that binds libhbsdcontrol from the hardenedbsd project to Ruby. Through this library, you can query what features are available and if root: enable, disable or query the status of a feature for a given file.

Examples

Features

As a regular user account, you can obtain a list of available features. But to enable, disable or query the status of a feature for a given file a superuser account is required:

#!/usr/bin/env ruby
# As a regular user account
require "hbsdctl"
BSD::Control
  .available_features
  .each do
  print "The ", _1.name, " feature is available", "\n"
end

Enable

As a superuser account, you can enable or disable a feature for a given file. The example enables the mprotect feature for the emacs binary:

#!/usr/bin/env ruby
# As a superuser account
require "hbsdctl"
BSD::Control
  .feature(:mprotect)
  .enable!("/usr/local/bin/emacs-29.2")

Status

As a superuser account, you can query whether or not a feature is enabled or disabled for a given file. There are four statuses that can be returned: conflict, sysdef, enabled, and disabled. The first status (conflict) is rare and indicates that a feature is both enabled and disabled. The other three are more common. The sysdef status indicates that a feature takes its settings from the system default (sysctl):

#!/usr/bin/env ruby
# As a superuser account
require "hbsdctl"
BSD::Control
  .feature(:mprotect)
  .status("/bin/ls") # => :sysdef

Documentation

A complete API reference is available at 0x1eef.github.io/x/hbsdctl.rb.

Install

Git

hbsdctl.rb is distributed as a RubyGem through its git repositories.
git.hardenedbsd.org, GitHub, and GitLab are available as sources.

Rubygems.org

hbsdctl.rb can also be installed via rubygems.org.

gem install hbsdctl.rb

License

BSD Zero Clause.
See LICENSE.