| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <wincred.h> | 10 #include <wincred.h> |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 need_recheck = false; | 121 need_recheck = false; |
| 122 } | 122 } |
| 123 | 123 |
| 124 if (need_recheck) { | 124 if (need_recheck) { |
| 125 HANDLE handle = INVALID_HANDLE_VALUE; | 125 HANDLE handle = INVALID_HANDLE_VALUE; |
| 126 | 126 |
| 127 // Attempt to login using blank password. | 127 // Attempt to login using blank password. |
| 128 DWORD logon_result = LogonUser(username, | 128 DWORD logon_result = LogonUser(username, |
| 129 L".", | 129 L".", |
| 130 L"", | 130 L"", |
| 131 LOGON32_LOGON_NETWORK, | 131 LOGON32_LOGON_INTERACTIVE, |
| 132 LOGON32_PROVIDER_DEFAULT, | 132 LOGON32_PROVIDER_DEFAULT, |
| 133 &handle); | 133 &handle); |
| 134 | 134 |
| 135 auto last_error = GetLastError(); | 135 auto last_error = GetLastError(); |
| 136 // Win XP and later return ERROR_ACCOUNT_RESTRICTION for blank password. | 136 // Win XP and later return ERROR_ACCOUNT_RESTRICTION for blank password. |
| 137 if (logon_result) | 137 if (logon_result) |
| 138 CloseHandle(handle); | 138 CloseHandle(handle); |
| 139 | 139 |
| 140 // In the case the password is blank, then LogonUser returns a failure, | 140 // In the case the password is blank, then LogonUser returns a failure, |
| 141 // handle is INVALID_HANDLE_VALUE, and GetLastError() is | 141 // handle is INVALID_HANDLE_VALUE, and GetLastError() is |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 password, | 297 password, |
| 298 CREDUI_MAX_PASSWORD_LENGTH+1, | 298 CREDUI_MAX_PASSWORD_LENGTH+1, |
| 299 &save_password, | 299 &save_password, |
| 300 kCredUiDefaultFlags | | 300 kCredUiDefaultFlags | |
| 301 (tries > 1 ? CREDUI_FLAGS_INCORRECT_PASSWORD : 0)); | 301 (tries > 1 ? CREDUI_FLAGS_INCORRECT_PASSWORD : 0)); |
| 302 | 302 |
| 303 if (credErr == NO_ERROR) { | 303 if (credErr == NO_ERROR) { |
| 304 logon_result = LogonUser(username, | 304 logon_result = LogonUser(username, |
| 305 use_principalname ? NULL : L".", | 305 use_principalname ? NULL : L".", |
| 306 password, | 306 password, |
| 307 LOGON32_LOGON_NETWORK, | 307 LOGON32_LOGON_INTERACTIVE, |
| 308 LOGON32_PROVIDER_DEFAULT, | 308 LOGON32_PROVIDER_DEFAULT, |
| 309 &handle); | 309 &handle); |
| 310 if (logon_result) { | 310 if (logon_result) { |
| 311 retval = true; | 311 retval = true; |
| 312 CloseHandle(handle); | 312 CloseHandle(handle); |
| 313 } else { | 313 } else { |
| 314 if (GetLastError() == ERROR_ACCOUNT_RESTRICTION && | 314 if (GetLastError() == ERROR_ACCOUNT_RESTRICTION && |
| 315 wcslen(password) == 0) { | 315 wcslen(password) == 0) { |
| 316 // Password is blank, so permit. | 316 // Password is blank, so permit. |
| 317 retval = true; | 317 retval = true; |
| 318 } else { | 318 } else { |
| 319 DLOG(WARNING) << "Unable to authenticate " << GetLastError(); | 319 DLOG(WARNING) << "Unable to authenticate " << GetLastError(); |
| 320 } | 320 } |
| 321 } | 321 } |
| 322 SecureZeroMemory(password, sizeof(password)); | 322 SecureZeroMemory(password, sizeof(password)); |
| 323 } | 323 } |
| 324 } while (credErr == NO_ERROR && | 324 } while (credErr == NO_ERROR && |
| 325 (retval == false && tries < kMaxPasswordRetries)); | 325 (retval == false && tries < kMaxPasswordRetries)); |
| 326 return retval; | 326 return retval; |
| 327 } | 327 } |
| 328 | 328 |
| 329 } // namespace password_manager_util_win | 329 } // namespace password_manager_util_win |
| OLD | NEW |