lib/puppet/provider/nameservice/directoryservice.rb in puppet-2.7.13 vs lib/puppet/provider/nameservice/directoryservice.rb in puppet-2.7.14

- old
+ new

@@ -321,13 +321,19 @@ users_plist = Plist::parse_xml(plutil( '-convert', 'xml1', '-o', '/dev/stdout', \ "#{@@users_plist_dir}/#{resource_name}.plist")) # users_plist['ShadowHashData'][0].string is actually a binary plist # that's nested INSIDE the user's plist (which itself is a binary - # plist). - password_hash_plist = users_plist['ShadowHashData'][0].string - converted_hash_plist = convert_binary_to_xml(password_hash_plist) + # plist). If we encounter a user plist that DOESN'T have a + # ShadowHashData field, create one. + if users_plist['ShadowHashData'] + password_hash_plist = users_plist['ShadowHashData'][0].string + converted_hash_plist = convert_binary_to_xml(password_hash_plist) + else + users_plist['ShadowHashData'] = [StringIO.new] + converted_hash_plist = {'SALTED-SHA512' => StringIO.new} + end # converted_hash_plist['SALTED-SHA512'].string expects a Base64 encoded # string. The password_hash provided as a resource attribute is a # hex value. We need to convert the provided hex value to a Base64 # encoded string to nest it in the converted hash plist. @@ -346,10 +352,10 @@ end def self.get_password(guid, username) # Use Puppet::Util::Package.versioncmp() to catch the scenario where a # version '10.10' would be < '10.7' with simple string comparison. This - # if-statement only executes if the current version is less-than 10.7 + # if-statement only executes if the current version is less-than 10.7 if (Puppet::Util::Package.versioncmp(get_macosx_version_major, '10.7') == -1) password_hash = nil password_hash_file = "#{@@password_hash_dir}/#{guid}" if File.exists?(password_hash_file) and File.file?(password_hash_file) fail("Could not read password hash file at #{password_hash_file}") if not File.readable?(password_hash_file)