Add cap_all

This commit is contained in:
0x1eef 2024-07-12 05:18:07 -03:00
parent 0e0b52320f
commit 3cc2221cc3

View file

@ -4,11 +4,11 @@ module BSD::Capsicum
module FFI
require "fiddle"
require "fiddle/import"
include Fiddle::Types
include Constants
extend Fiddle::Importer
dlload Dir["/lib/libc.*"].first
include Fiddle::Types
include Constants
extern "int cap_getmode(u_int*)"
extern "int cap_enter(void)"
extern "int cap_rights_limit(int, const cap_rights_t*)"
@ -53,11 +53,19 @@ module BSD::Capsicum
self["__cap_rights_init"].call(
CAP_RIGHTS_VERSION,
rights,
*capabilities.flat_map {
[ULONG_LONG, (Symbol === _1) ? Constants.const_get(_1) : _1]
*capabilities.flat_map { |cap|
[ULONG_LONG, cap_all.include?(cap) ? Constants.const_get(cap) : cap]
}
)
end
##
# @api private
# @return [Array<Symbol>]
# Returns all known capabilities
def cap_all
@cap_all ||= Constants.constants.select { _1.to_s.start_with?("CAP_") }
end
end
private_constant :FFI
end