win_user - use proper error code when failing to validate creds (#60181)

This commit is contained in:
Jordan Borean 2019-08-07 18:28:44 +10:00 committed by GitHub
parent 92187ae53e
commit 45d0e5994a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- win_user - Get proper error code when failing to validate the user's credentials

View file

@ -73,14 +73,19 @@ namespace Ansible
$env:TMP = $original_tmp
$handle = [IntPtr]::Zero
$logon_res = [Ansible.WinUserPInvoke]::LogonUser($Username, $null, $Password,
$LOGON32_LOGON_NETWORK, $LOGON32_PROVIDER_DEFAULT, [Ref]$handle)
$logon_res = [Ansible.WinUserPInvoke]::LogonUser(
$Username,
$null,
$Password,
$LOGON32_LOGON_NETWORK,
$LOGON32_PROVIDER_DEFAULT,
[Ref]$handle
); $err_code = [System.Runtime.InteropServices.Marshal]::GetLastWin32Error()
if ($logon_res) {
$valid_credentials = $true
[Ansible.WinUserPInvoke]::CloseHandle($handle) > $null
} else {
$err_code = [System.Runtime.InteropServices.Marshal]::GetLastWin32Error()
# following errors indicate the creds are correct but the user was
# unable to log on for other reasons, which we don't care about
$success_codes = @(