From a34fc3ff6ce19dc0f9807082b367e5e07b1c8996 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sat, 12 Oct 2024 19:01:20 -0300 Subject: [PATCH] Add examples --- README.md | 9 ++++----- share/bsdcontrol.rb/examples/2_feature_enable.rb | 8 ++++++++ share/bsdcontrol.rb/examples/3_feature_status.rb | 8 ++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 share/bsdcontrol.rb/examples/2_feature_enable.rb create mode 100644 share/bsdcontrol.rb/examples/3_feature_status.rb diff --git a/README.md b/README.md index 9810fc5..8103212 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ bsdcontrol.rb provides Ruby bindings for ## Examples -__Features__ +### Features The first example prints a list of HardenedBSD features that can be enabled, disabled or restored to the system default @@ -22,7 +22,7 @@ BSD::Control end ``` -__Enable__ +### 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 @@ -35,10 +35,10 @@ over the system default. The system default can be restored with require "bsdcontrol" BSD::Control .feature(:mprotect) - .enable!("/usr/local/bin/emacs-29.2") + .enable! File.realpath("/usr/local/bin/emacs") ``` -__Status__ +### Status There are five recognized statuses: `unknown`, `enabled`, `disabled`, `sysdef`, and `invalid`. The `sysdef` status indicates that a feature @@ -77,4 +77,3 @@ bsdcontrol.rb can be installed via rubygems.org: [BSD Zero Clause](https://choosealicense.com/licenses/0bsd/)
See [LICENSE](./LICENSE) - diff --git a/share/bsdcontrol.rb/examples/2_feature_enable.rb b/share/bsdcontrol.rb/examples/2_feature_enable.rb new file mode 100644 index 0000000..14fc7fd --- /dev/null +++ b/share/bsdcontrol.rb/examples/2_feature_enable.rb @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# Required privileges: superuser +require "bsdcontrol" +BSD::Control + .feature(:mprotect) + .enable! File.realpath("/usr/local/bin/emacs") diff --git a/share/bsdcontrol.rb/examples/3_feature_status.rb b/share/bsdcontrol.rb/examples/3_feature_status.rb new file mode 100644 index 0000000..3229f2e --- /dev/null +++ b/share/bsdcontrol.rb/examples/3_feature_status.rb @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# Required privileges: superuser +require "bsdcontrol" +BSD::Control + .feature(:mprotect) + .status("/bin/ls") # => :sysdef