Class: KerberosAuthenticator::Krb5::Creds
- Inherits:
-
Object
- Object
- KerberosAuthenticator::Krb5::Creds
- Defined in:
- lib/kerberos_authenticator/krb5/creds.rb
Overview
Credentials, or tickets, provided by a KDC for a user.
Constant Summary collapse
- SIZE_OF_KRB5_CREDS =
The size, in bytes, of the krb5_creds structure. This differs between implementations and architectures.
480
Instance Attribute Summary collapse
-
#ptr ⇒ FFI::Pointer
readonly
The pointer to the wrapped krb5_creds struct.
Class Method Summary collapse
-
.initial_creds_for_principal_with_a_password(principal, password, service = nil) ⇒ Creds
Requests initial credentials for principal using password from a KDC.
-
.release(pointer) ⇒ Object
private
Frees the contents of the Creds structure.
Instance Method Summary collapse
-
#initialize(ptr) ⇒ Keytab
constructor
Initialize a new Keytab with a pointer to a krb5_keytab structure.
-
#set_password(newpw, change_password_for = nil) ⇒ TrueClass
Sets a password for a principal using these Creds.
-
#verify(nofail = false, server_principal = nil, keytab = nil) ⇒ TrueClass
Attempts to verify that these Creds were obtained from a KDC with knowledge of a key in keytab.
-
#verify!(server_principal = nil, keytab = nil) ⇒ Object
Calls #verify with nofail as true.
Constructor Details
#initialize(ptr) ⇒ Keytab
Initialize a new Keytab with a pointer to a krb5_keytab structure.
49 50 51 52 53 54 55 56 57 |
# File 'lib/kerberos_authenticator/krb5/creds.rb', line 49 def initialize(ptr) # HACK: AutoPointer won't accept a MemoryPointer, only a Pointer ptr.autorelease = false ptr = FFI::Pointer.new(ptr) ptr = FFI::AutoPointer.new ptr, self.class.method(:release) @ptr = ptr end |
Instance Attribute Details
#ptr ⇒ FFI::Pointer (readonly)
Returns the pointer to the wrapped krb5_creds struct.
|
# File 'lib/kerberos_authenticator/krb5/creds.rb', line 18
|
Class Method Details
.initial_creds_for_principal_with_a_password(principal, password, service = nil) ⇒ Creds
Requests initial credentials for principal using password from a KDC.
37 38 39 40 41 42 43 44 |
# File 'lib/kerberos_authenticator/krb5/creds.rb', line 37 def self.initial_creds_for_principal_with_a_password(principal, password, service = nil) raise TypeError, 'expected Principal' unless principal.is_a? Principal ptr = FFI::MemoryPointer.new :char, SIZE_OF_KRB5_CREDS Krb5.get_init_creds_password(Context.context.ptr, ptr, principal.ptr, password.to_str, nil, nil, 0, service, nil) new(ptr) end |
.release(pointer) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Frees the contents of the Creds structure
114 115 116 |
# File 'lib/kerberos_authenticator/krb5/creds.rb', line 114 def self.release(pointer) Krb5.free_cred_contents(Context.context.ptr, pointer) end |
Instance Method Details
#set_password(newpw, change_password_for = nil) ⇒ TrueClass
Sets a password for a principal using these Creds. The Creds should be for the ‘kadmin/changepw’ service.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/kerberos_authenticator/krb5/creds.rb', line 95 def set_password(newpw, change_password_for = nil) change_password_for_ptr = change_password_for ? change_password_for.ptr : nil result_code = FFI::MemoryPointer.new :int result_code_string = Data.new result_string = Data.new Krb5.set_password(Context.context.ptr, ptr, newpw, change_password_for_ptr, result_code, result_code_string.pointer, result_string.pointer) result_code = result_code.read_uint result_string = result_string.read_string.force_encoding('UTF-8') raise SetPassError.new(result_code, result_string) if result_code > 0 true end |
#verify(nofail = false, server_principal = nil, keytab = nil) ⇒ TrueClass
Attempts to verify that these Creds were obtained from a KDC with knowledge of a key in keytab.
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/kerberos_authenticator/krb5/creds.rb', line 74 def verify(nofail = false, server_principal = nil, keytab = nil) verify_creds_opt = FFI::MemoryPointer.new :int, 2 Krb5.verify_init_creds_opt_init(verify_creds_opt) Krb5.verify_init_creds_opt_set_ap_req_nofail(verify_creds_opt, nofail) server_princ_ptr = server_principal ? server_principal.ptr : nil keytab_ptr = keytab ? keytab.ptr : nil Krb5.verify_init_creds(Context.context.ptr, ptr, server_princ_ptr, keytab_ptr, nil, verify_creds_opt) true end |
#verify!(server_principal = nil, keytab = nil) ⇒ Object
Calls #verify with nofail as true.
61 62 63 |
# File 'lib/kerberos_authenticator/krb5/creds.rb', line 61 def verify!(server_principal = nil, keytab = nil) verify(true, server_principal, keytab) end |