Module: BSD::Capsicum
- Extended by:
- Capsicum
- Included in:
- Capsicum
- Defined in:
- lib/bsd/capsicum.rb,
lib/bsd/capsicum/ffi.rb,
lib/bsd/capsicum/version.rb,
lib/bsd/capsicum/constants.rb
Defined Under Namespace
Modules: Constants
Constant Summary collapse
- VERSION =
"0.3.0"
Instance Method Summary collapse
-
#in_capability_mode? ⇒ Boolean
(also: #capability_mode?)
Check if we’re in capability mode.
-
#enter! ⇒ Boolean
(also: #enter_capability_mode!)
Enter a process into capability mode.
-
#limit!(io, allow:) ⇒ Boolean
Limit the capabilities of a file descriptor.
Instance Method Details
#in_capability_mode? ⇒ Boolean Also known as: capability_mode?
Check if we’re in capability mode
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bsd/capsicum.rb', line 19 def in_capability_mode? uintp = Fiddle::Pointer.malloc(Fiddle::SIZEOF_UINT) if FFI.cap_getmode(uintp).zero? uintp[0, Fiddle::SIZEOF_UINT].unpack("i") == [1] else raise SystemCallError.new("cap_getmode", Fiddle.last_error) end ensure uintp.call_free end |
#enter! ⇒ Boolean Also known as: enter_capability_mode!
Enter a process into capability mode
38 39 40 41 |
# File 'lib/bsd/capsicum.rb', line 38 def enter! FFI.cap_enter.zero? || raise(SystemCallError.new("cap_enter", Fiddle.last_error)) end |
#limit!(io, allow:) ⇒ Boolean
Limit the capabilities of a file descriptor
61 62 63 64 65 66 67 68 |
# File 'lib/bsd/capsicum.rb', line 61 def limit!(io, allow:) rightsp = Fiddle::Pointer.malloc(Constants::SIZEOF_CAP_RIGHTS_T) FFI.cap_rights_init(rightsp, *allow) FFI.cap_rights_limit(io.to_i, rightsp).zero? || raise(SystemCallError.new("cap_rights_limit", Fiddle.last_error)) ensure rightsp.call_free end |