class KerberosAuthenticator::Krb5::Principal
A Kerberos principal identifying a user, service or machine.
Attributes
@!attribute [r] ptr
@return [FFI::Pointer] the pointer to the wrapped krb5_principal struct
Public Class Methods
Initialize a new Principal
with a pointer to a pointer to a krb5_principal structure. @param pointer [FFI::Pointer] @return [Principal]
# File lib/kerberos_authenticator/krb5/principal.rb, line 34 def initialize(pointer) @ptr = FFI::AutoPointer.new pointer.get_pointer(0), self.class.method(:release) self end
Convert a string representation of a principal name into a new Principal
. @param name [String] a string representation of a principal name @return [Principal] @see web.mit.edu/kerberos/krb5-1.14/doc/appdev/refs/api/krb5_parse_name.html krb5_parse_name
# File lib/kerberos_authenticator/krb5/principal.rb, line 23 def self.new_with_name(name) raise ArgumentError, 'name cannot be empty' if name.empty? pointer = FFI::MemoryPointer.new :pointer Krb5.parse_name(Context.context.ptr, name, pointer) new(pointer) end
Frees a Principal
@api private @see web.mit.edu/kerberos/krb5-1.14/doc/appdev/refs/api/krb5_free_principal.html krb5_free_principal
# File lib/kerberos_authenticator/krb5/principal.rb, line 74 def self.release(pointer) Krb5.free_principal(Context.context.ptr, pointer) end
Public Instance Methods
A convenience function to allow a Principal
to change a password by authenticating themselves. @raise [Error] if the attempt to change the password fails @return [TrueClass] always returns true if no error was raised
# File lib/kerberos_authenticator/krb5/principal.rb, line 66 def change_password(oldpw, new_pw) changepw_creds = self.initial_creds_with_password(oldpw, 'kadmin/changepw') changepw_creds.set_password(new_pw, self) end
Calls Creds.initial_creds_for_principal_with_a_password
(self, password, service) @param password [String] @param service [String] @return [Creds] @see Creds.initial_creds_for_principal_with_a_password
# File lib/kerberos_authenticator/krb5/principal.rb, line 45 def initial_creds_with_password(password, service = nil) Creds.initial_creds_for_principal_with_a_password(self, password, service) end
@return [String] a string representation of the principal's name @see web.mit.edu/kerberos/krb5-1.14/doc/appdev/refs/api/krb5_unparse_name.html krb5_unparse_name
# File lib/kerberos_authenticator/krb5/principal.rb, line 51 def name out_ptr = FFI::MemoryPointer.new(:pointer, 1) Krb5.unparse_name(Context.context.ptr, ptr, out_ptr) str_ptr = out_ptr.read_pointer copy = String.new(str_ptr.read_string).force_encoding('UTF-8') Krb5.free_unparsed_name(Context.context.ptr, str_ptr) copy end