bsdcontrol.rb/README.md

84 lines
2 KiB
Markdown
Raw Normal View History

2024-03-01 02:29:43 +01:00
## About
2024-03-01 02:28:22 +01:00
2024-03-20 21:28:59 +01:00
bsdcontrol.rb provides Ruby bindings for libhbsdcontrol from the
2024-03-14 20:15:50 +01:00
[hardenedbsd](https://hardenedbsd.org) project. Through
2024-03-08 02:35:34 +01:00
this library, you can query what features are available and if
2024-03-20 21:51:02 +01:00
root: enable or disable a feature for a given file, or restore
the system default for a given file.
2024-03-01 02:28:22 +01:00
2024-03-01 02:29:43 +01:00
## Examples
2024-03-01 02:28:22 +01:00
2024-03-08 05:36:06 +01:00
__Features__
2024-03-01 02:28:22 +01:00
2024-03-14 20:15:50 +01:00
As an unprivileged user or as a superuser, you can obtain a list of
available features:
2024-03-01 02:28:22 +01:00
2024-03-01 02:29:43 +01:00
``` ruby
#!/usr/bin/env ruby
2024-03-14 20:15:50 +01:00
# Required privileges: unprivileged user or superuser.
2024-03-08 05:36:06 +01:00
require "hbsdctl"
2024-03-01 02:29:43 +01:00
BSD::Control
.available_features
.each do
print "The ", _1.name, " feature is available", "\n"
end
2024-03-01 02:28:22 +01:00
```
2024-03-08 05:36:06 +01:00
__Enable__
2024-03-01 02:28:22 +01:00
2024-03-14 20:15:50 +01:00
As a superuser, you can enable or disable a feature for a given file.
2024-03-20 21:51:02 +01:00
The 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 (sysctl):
2024-03-01 02:28:22 +01:00
2024-03-01 02:29:43 +01:00
``` ruby
#!/usr/bin/env ruby
2024-03-14 20:15:50 +01:00
# Required privileges: superuser.
2024-03-08 05:36:06 +01:00
require "hbsdctl"
2024-03-01 02:29:43 +01:00
BSD::Control
2024-03-08 05:23:16 +01:00
.feature(:mprotect)
2024-03-08 02:35:34 +01:00
.enable!("/usr/local/bin/emacs-29.2")
2024-03-01 02:29:43 +01:00
```
2024-03-01 02:28:22 +01:00
2024-03-08 05:36:06 +01:00
__Status__
2024-03-14 20:15:50 +01:00
As a superuser, you can query the status of a feature for a given file.
2024-03-20 21:51:02 +01:00
There are five recognized statuses: `unknown`, `enabled`, `disabled`,
`sysdef`, and `invalid`. The `sysdef` status indicates that a feature takes
its settings from the system default (sysctl), and is the most common status:
2024-03-08 05:36:06 +01:00
``` ruby
#!/usr/bin/env ruby
2024-03-14 20:15:50 +01:00
# Required privileges: superuser.
2024-03-08 05:36:06 +01:00
require "hbsdctl"
BSD::Control
.feature(:mprotect)
.status("/bin/ls") # => :sysdef
```
2024-03-08 02:35:34 +01:00
## Documentation
A complete API reference is available at
2024-03-20 21:28:59 +01:00
[0x1eef.github.io/x/bsdcontrol.rb](https://0x1eef.github.io/x/bsdcontrol.rb).
2024-03-08 02:35:34 +01:00
2024-03-10 14:57:39 +01:00
## Install
2024-03-01 02:35:05 +01:00
**Rubygems.org**
2024-03-20 21:28:59 +01:00
bsdcontrol.rb can be installed via rubygems.org.
2024-03-01 02:35:05 +01:00
2024-03-20 21:28:59 +01:00
gem install bsdcontrol.rb
2024-03-01 02:35:05 +01:00
2024-03-10 15:22:01 +01:00
## Sources
2024-03-20 21:28:59 +01:00
* [GitHub](https://github.com/0x1eef/bsdcontrol.rb)
* [GitLab](https://gitlab.com/0x1eef/bsdcontrol.rb)
* [git.hardenedbsd.org](https://git.hardenedbsd.org/0x1eef/bsdcontrol.rb)
2024-03-10 15:22:01 +01:00
2024-03-01 02:28:22 +01:00
## License
2024-03-01 02:29:43 +01:00
[BSD Zero Clause](https://choosealicense.com/licenses/0bsd/).
<br>
See [LICENSE](./LICENSE).