2024-06-27 06:01:24 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-06-25 08:25:53 +02:00
|
|
|
module BSD::Capsicum
|
2024-06-25 09:37:54 +02:00
|
|
|
module FFI
|
2024-06-25 08:25:53 +02:00
|
|
|
require "fiddle"
|
2024-07-12 09:41:46 +02:00
|
|
|
require "fiddle/import"
|
|
|
|
extend Fiddle::Importer
|
|
|
|
dlload Dir["/lib/libc.*"].first
|
|
|
|
|
2024-06-25 15:39:04 +02:00
|
|
|
include Fiddle::Types
|
2024-06-25 17:17:23 +02:00
|
|
|
include Constants
|
2024-07-12 09:41:46 +02:00
|
|
|
extern "int cap_getmode(u_int*)"
|
|
|
|
extern "int cap_enter(void)"
|
|
|
|
extern "int cap_rights_limit(int, const cap_rights_t*)"
|
|
|
|
extern "cap_rights_t* __cap_rights_init(int version, cap_rights_t*, ...)"
|
2024-06-25 17:17:23 +02:00
|
|
|
|
2024-06-25 08:25:53 +02:00
|
|
|
module_function
|
|
|
|
|
|
|
|
##
|
|
|
|
# Provides a Ruby interface for cap_enter(2)
|
|
|
|
# @return [Integer]
|
|
|
|
def cap_enter
|
2024-07-12 09:41:46 +02:00
|
|
|
self["cap_enter"].call
|
2024-06-25 08:25:53 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Provides a Ruby interface for cap_getmode(2)
|
|
|
|
# @param [Fiddle::Pointer] uintp
|
|
|
|
# @return [Integer]
|
|
|
|
def cap_getmode(uintp)
|
2024-07-12 09:41:46 +02:00
|
|
|
self["cap_getmode"].call(uintp)
|
2024-06-25 08:25:53 +02:00
|
|
|
end
|
|
|
|
|
2024-06-25 15:39:04 +02:00
|
|
|
##
|
|
|
|
# Provides a Ruby interface for cap_rights_limit(2)
|
|
|
|
# @param [Integer] fd
|
|
|
|
# @param [Fiddle::Pointer] rights
|
|
|
|
# @return [Integer]
|
|
|
|
def cap_rights_limit(fd, rights)
|
2024-07-12 09:41:46 +02:00
|
|
|
self["cap_rights_limit"].call(fd, rights)
|
2024-06-25 15:39:04 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Provides a Ruby interface for cap_rights_init(2)
|
2024-07-12 08:58:34 +02:00
|
|
|
# @see BSD::Capsicum::Constants See Constants for a full list of capabilities
|
2024-07-12 09:19:26 +02:00
|
|
|
# @param [Fiddle::Pointer] rights
|
|
|
|
# A pointer to initialize the `cap_rights_t` structure
|
|
|
|
# @param [Array<Integer>] capabilities
|
|
|
|
# An allowed set of capabilities
|
2024-06-25 15:39:04 +02:00
|
|
|
# @return [Fiddle::Pointer]
|
2024-07-12 08:54:34 +02:00
|
|
|
# Returns a pointer to the structure `cap_rights_t`
|
2024-07-12 09:19:26 +02:00
|
|
|
def cap_rights_init(rights, *capabilities)
|
2024-07-12 09:41:46 +02:00
|
|
|
self["__cap_rights_init"].call(
|
|
|
|
CAP_RIGHTS_VERSION,
|
|
|
|
rights,
|
2024-07-12 09:26:53 +02:00
|
|
|
*capabilities.flat_map {
|
|
|
|
[ULONG_LONG, (Symbol === _1) ? Constants.const_get(_1) : _1]
|
2024-07-12 09:41:46 +02:00
|
|
|
}
|
|
|
|
)
|
2024-06-25 08:25:53 +02:00
|
|
|
end
|
|
|
|
end
|
2024-06-25 20:37:43 +02:00
|
|
|
private_constant :FFI
|
2024-06-25 08:25:53 +02:00
|
|
|
end
|