OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // windows.h must be first otherwise Win8 SDK breaks. | 5 // windows.h must be first otherwise Win8 SDK breaks. |
6 #include <windows.h> | 6 #include <windows.h> |
7 #include <LM.h> | 7 #include <LM.h> |
8 #include <wincred.h> | 8 #include <wincred.h> |
9 | 9 |
10 // SECURITY_WIN32 must be defined in order to get | 10 // SECURITY_WIN32 must be defined in order to get |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 HANDLE handle = INVALID_HANDLE_VALUE; | 122 HANDLE handle = INVALID_HANDLE_VALUE; |
123 | 123 |
124 // Attempt to login using blank password. | 124 // Attempt to login using blank password. |
125 DWORD logon_result = LogonUser(username, | 125 DWORD logon_result = LogonUser(username, |
126 L".", | 126 L".", |
127 L"", | 127 L"", |
128 LOGON32_LOGON_NETWORK, | 128 LOGON32_LOGON_NETWORK, |
129 LOGON32_PROVIDER_DEFAULT, | 129 LOGON32_PROVIDER_DEFAULT, |
130 &handle); | 130 &handle); |
131 | 131 |
132 auto last_error = GetLastError(); | |
brucedawson
2015/09/12 00:33:55
CloseHandle could affect LastError. Unlikely, but
| |
132 // Win XP and later return ERROR_ACCOUNT_RESTRICTION for blank password. | 133 // Win XP and later return ERROR_ACCOUNT_RESTRICTION for blank password. |
133 if (logon_result) | 134 if (logon_result) |
134 CloseHandle(handle); | 135 CloseHandle(handle); |
135 | 136 |
136 // In the case the password is blank, then LogonUser returns a failure, | 137 // In the case the password is blank, then LogonUser returns a failure, |
137 // handle is INVALID_HANDLE_VALUE, and GetLastError() is | 138 // handle is INVALID_HANDLE_VALUE, and GetLastError() is |
138 // ERROR_ACCOUNT_RESTRICTION. | 139 // ERROR_ACCOUNT_RESTRICTION. |
139 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms681385 | 140 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms681385 |
140 blank_password = (logon_result || | 141 blank_password = (logon_result || |
141 GetLastError() == ERROR_ACCOUNT_RESTRICTION); | 142 last_error == ERROR_ACCOUNT_RESTRICTION); |
142 } | 143 } |
143 | 144 |
144 // Account for clock skew between pulling the password age and | 145 // Account for clock skew between pulling the password age and |
145 // writing to the preferences by adding a small skew factor here. | 146 // writing to the preferences by adding a small skew factor here. |
146 last_changed += base::Time::kMicrosecondsPerSecond; | 147 last_changed += base::Time::kMicrosecondsPerSecond; |
147 | 148 |
148 // Update the preferences with new values. | 149 // Update the preferences with new values. |
149 prefs->pref_last_changed_ = last_changed; | 150 prefs->pref_last_changed_ = last_changed; |
150 prefs->blank_password_ = blank_password; | 151 prefs->blank_password_ = blank_password; |
151 return blank_password; | 152 return blank_password; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 } | 315 } |
315 } | 316 } |
316 SecureZeroMemory(password, sizeof(password)); | 317 SecureZeroMemory(password, sizeof(password)); |
317 } | 318 } |
318 } while (credErr == NO_ERROR && | 319 } while (credErr == NO_ERROR && |
319 (retval == false && tries < kMaxPasswordRetries)); | 320 (retval == false && tries < kMaxPasswordRetries)); |
320 return retval; | 321 return retval; |
321 } | 322 } |
322 | 323 |
323 } // namespace password_manager_util_win | 324 } // namespace password_manager_util_win |
OLD | NEW |