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.
-
#set_rights!(io, capabilities) ⇒ 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
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bsd/capsicum.rb', line 20 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
40 41 42 43 |
# File 'lib/bsd/capsicum.rb', line 40 def enter! FFI.cap_enter.zero? || raise(SystemCallError.new("cap_enter", Fiddle.last_error)) end |
#set_rights!(io, capabilities) ⇒ Boolean
Limit the capabilities of a file descriptor
62 63 64 65 66 67 68 69 |
# File 'lib/bsd/capsicum.rb', line 62 def set_rights!(io, capabilities) rightsp = Fiddle::Pointer.malloc(Constants::SIZEOF_CAP_RIGHTS_T) FFI.cap_rights_init(rightsp, *capabilities) FFI.cap_rights_limit(io.to_i, rightsp).zero? || raise(SystemCallError.new("cap_rights_limit", Fiddle.last_error)) ensure rightsp.call_free end |