Ruby bindings for libhbsdcontrol(3)
Find a file
2024-04-09 19:15: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/bsdcontrol.rb Raise SystemCallError instead of RuntimeError 2024-03-30 03:48:26 -03:00
lib v0.1.1 2024-04-09 16:44:18 -03:00
test Map HBSDCTRL_STATE_(ENABLED|DISABLED) into Ruby 2024-03-20 21:58:18 -03:00
.clang-format Reimplement on top of libhbsdcontrol v2 2024-03-20 16:26:58 -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
bsdcontrol.rb.gemspec Loosen rake-compiler dependency 2024-03-20 21:45:28 -03:00
Gemfile First commit 2024-02-29 22:29:43 -03:00
Gemfile.lock Loosen rake-compiler dependency 2024-03-20 21:45:28 -03:00
LICENSE Add LICENSE 2024-02-29 22:35:05 -03:00
Rakefile.rb Add task desc for 'clang:format' 2024-03-20 21:40:28 -03:00
README.md Fix README 2024-04-09 19:15:15 -03:00

About

bsdcontrol.rb provides Ruby bindings for libhbsdcontrol from the hardenedbsd project.

Examples

Features

The first example obtains a list of hardenedbsd features that can be enabled, disabled or restored to the system default:

#!/usr/bin/env ruby
# Required privileges: unprivileged user or superuser.
require "bsdcontrol"
BSD::Control
  .available_features
  .each do
  print "The ", _1.name, " feature is available", "\n"
end

Enable

The following example enables the mprotect feature for the emacs binary. When a feature is enabled for a given file, that setting takes precendence over the system default. The system default can be restored with BSD::Control::Feature#sysdef!:

#!/usr/bin/env ruby
# Required privileges: superuser.
require "bsdcontrol"
BSD::Control
  .feature(:mprotect)
  .enable!("/usr/local/bin/emacs-29.2")

Status

There are five recognized statuses: unknown, enabled, disabled, sysdef, and invalid. The sysdef status indicates that a feature is configured to use the system default, and it is the most common status:

#!/usr/bin/env ruby
# Required privileges: superuser.
require "bsdcontrol"
BSD::Control
  .feature(:mprotect)
  .status("/bin/ls") # => :sysdef

Documentation

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

Install

Rubygems.org

bsdcontrol.rb can be installed via rubygems.org.

gem install bsdcontrol.rb

Sources

License

BSD Zero Clause.
See LICENSE.