Class: MacAdmin::ShadowHash

Inherits:
Object
  • Object
show all
Includes:
Password
Defined in:
lib/macadmin/shadowhash.rb

Overview

ShadowHash (super class)

  • common methods for password sub-classes

Direct Known Subclasses

SaltedSHA1, SaltedSHA512, SaltedSHA512PBKDF2

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from Password

#apropos, #convert_to_blob, #convert_to_hex, #salted_sha1, #salted_sha512, #salted_sha512_pbkdf2, salted_sha512_pbkdf2_from_string

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



14
15
16
# File 'lib/macadmin/shadowhash.rb', line 14

def label
  @label
end

Class Method Details

.create_from_user_record(user) ⇒ Object

Reads the password data from the user record

  • returns an appropriate ShadowHash object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/macadmin/shadowhash.rb', line 20

def create_from_user_record(user)
  if user['ShadowHashData']
    password = read_shadowhashdata(user['ShadowHashData'])
    if password[SaltedSHA512::LABEL]
      return SaltedSHA512.create_from_shadowhashdata(password)
    else
      return SaltedSHA512PBKDF2.create_from_shadowhashdata(password)
    end
  else
    if guid = user['generateduid']
      return SaltedSHA1.create_from_shadowhash_file(guid)
    end
  end
  nil
end

.read_shadowhashdata(data) ⇒ Object

Returns Hash

  • key: label, value: password data



38
39
40
41
# File 'lib/macadmin/shadowhash.rb', line 38

def read_shadowhashdata(data)
  plist = CFPropertyList::List.new(:data => data[0].to_s)
  CFPropertyList.native_types(plist.value)
end