From 3cc2221cc382fcf9efc341e551c4eb1f742b5200 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Fri, 12 Jul 2024 05:18:07 -0300 Subject: [PATCH] Add cap_all --- lib/bsd/capsicum/ffi.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/bsd/capsicum/ffi.rb b/lib/bsd/capsicum/ffi.rb index 9bd0d26..6ff90fe 100644 --- a/lib/bsd/capsicum/ffi.rb +++ b/lib/bsd/capsicum/ffi.rb @@ -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] + # Returns all known capabilities + def cap_all + @cap_all ||= Constants.constants.select { _1.to_s.start_with?("CAP_") } + end end private_constant :FFI end