Module: Keyutils::Lib

Extended by:
FFI::Library
Includes:
Errno
Defined in:
lib/keyutils/lib.rb

Defined Under Namespace

Modules: KeySerialConverter, NonnegativeOrErrorLongConverter

Constant Summary collapse

KEY_SPEC =

special process keyring shortcut IDs

{
  THREAD_KEYRING: -1, # key ID for thread-specific keyring
  PROCESS_KEYRING: -2, # key ID for process-specific keyring
  SESSION_KEYRING: -3, # key ID for session-specific keyring
  USER_KEYRING: -4, # key ID for UID-specific keyring
  USER_SESSION_KEYRING: -5, # key ID for UID-session keyring
  GROUP_KEYRING: -6, # key ID for GID-specific keyring
  REQKEY_AUTH_KEY: -7 # key ID for assumed request_key auth key
}
KEY_REQKEY_DEFL =

request-key default keyrings

{
  NO_CHANGE: -1,
  DEFAULT: 0,
  THREAD_KEYRING: 1,
  PROCESS_KEYRING: 2,
  SESSION_KEYRING: 3,
  USER_KEYRING: 4,
  USER_SESSION_KEYRING: 5,
  GROUP_KEYRING: 6
}
KEYCTL =

keyctl commands

{
  GET_KEYRING_ID: 0, # ask for a keyring's ID
  JOIN_SESSION_KEYRING: 1, # join or start named session keyring
  UPDATE: 2, # update a key
  REVOKE: 3, # revoke a key
  CHOWN: 4, # set ownership of a key
  SETPERM: 5, # set perms on a key
  DESCRIBE: 6, # describe a key
  CLEAR: 7, # clear contents of a keyring
  LINK: 8, # link a key into a keyring
  UNLINK: 9, # unlink a key from a keyring
  SEARCH: 10, # search for a key in a keyring
  READ: 11, # read a key or keyring's contents
  INSTANTIATE: 12, # instantiate a partially constructed key
  NEGATE: 13, # negate a partially constructed key
  SET_REQKEY_KEYRING: 14, # set default request-key keyring
  SET_TIMEOUT: 15, # set timeout on a key
  ASSUME_AUTHORITY: 16, # assume authority to instantiate key
  GET_SECURITY: 17, # get key security label
  SESSION_TO_PARENT: 18, # set my session keyring on my parent process
  REJECT: 19, # reject a partially constructed key
  INSTANTIATE_IOV: 20, # instantiate a partially constructed key
  INVALIDATE: 21, # invalidate a key
  GET_PERSISTENT: 22 # get a user's persistent keyring
}
@@lib =
(ffi_lib %w(keyutils keyutils.so.1)).first

Class Method Summary collapse

Class Method Details

.attach_function(fname, *a, errors: {}, **kwargs) ⇒ Object

Attach a C function that can raise error (eg. through return type converter), allowing to provide errorclass => description map



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/keyutils/lib.rb', line 85

def self.attach_function fname, *a, errors: {}, **kwargs
  function = FFI::Library.instance_method(:attach_function).bind(self).call fname, *a, **kwargs
  singleton_class.send :define_method, fname, ->(*a) do
    begin
      function.call *a
    rescue Exception => e
      msg = errors[e.class] || e.message
      call = caller_locations(2, 1).first
      call_desc = "#{call.absolute_path}:#{call.lineno}:in `#{fname}'"
      raise e, msg, [call_desc] + caller(2)
    end
  end
end

.attach_text_string(name) ⇒ Object



8
9
10
11
# File 'lib/keyutils/lib.rb', line 8

def self.attach_text_string name
  val = @@lib.find_variable(name.to_s).get_string 0
  singleton_class.send :define_method, name, ->() { val }
end