class KerberosAuthenticator::Krb5::Context
A Kerberos context, holding all per-thread state.
Attributes
ptr[R]
@!attribute [r] ptr
@return [FFI::Pointer] the pointer to the wrapped krb5_context struct
Public Class Methods
context()
click to toggle source
@return [Context] a fibre-local Context
# File lib/kerberos_authenticator/krb5/context.rb, line 42 def self.context if Krb5.use_secure_context Thread.current[:krb5_secure_context] ||= new(true) else Thread.current[:krb5_context] ||= new end end
new(secure = false)
click to toggle source
@param secure [Boolean] whether to ignore environmental variables when constructing a library context @see web.mit.edu/kerberos/krb5-1.14/doc/appdev/refs/api/krb5_init_secure_context.html krb5_init_secure_context @see web.mit.edu/kerberos/krb5-1.14/doc/appdev/refs/api/krb5_init_context.html krb5_init_context
# File lib/kerberos_authenticator/krb5/context.rb, line 53 def initialize(secure = false) pointer = FFI::MemoryPointer.new :pointer if secure Krb5::LibCallError.raise_if_error { Krb5.init_secure_context(pointer) } else Krb5::LibCallError.raise_if_error { Krb5.init_context(pointer) } end @ptr = FFI::AutoPointer.new pointer.get_pointer(0), self.class.method(:release) self end
release(pointer)
click to toggle source
Frees a Context
@api private @see web.mit.edu/kerberos/krb5-1.14/doc/appdev/refs/api/krb5_free_context.html krb5_free_context
# File lib/kerberos_authenticator/krb5/context.rb, line 85 def self.release(pointer) Krb5.free_context pointer end
Public Instance Methods
default_realm()
click to toggle source
Retrieves the default realm @return [String] @see web.mit.edu/kerberos/krb5-1.14/doc/appdev/refs/api/krb5_get_default_realm.html krb5_get_default_realm
# File lib/kerberos_authenticator/krb5/context.rb, line 70 def default_realm out_ptr = FFI::MemoryPointer.new :pointer Krb5.get_default_realm(ptr, out_ptr) str_ptr = out_ptr.read_pointer copy = String.new(str_ptr.read_string).force_encoding('UTF-8') Krb5.free_string(ptr, str_ptr) copy end