secur32: Fix handling of ANSI NTLM credentials
David Woodhouse
dwmw2 at infradead.org
Fri Aug 8 07:21:56 CDT 2014
One of many issues covered in bug 37063... we assume that the
credentials are in Unicode, instead of looking at the Flags field.
diff --git a/dlls/secur32/ntlm.c b/dlls/secur32/ntlm.c
index 0fe64ed..c356cc8 100644
--- a/dlls/secur32/ntlm.c
+++ b/dlls/secur32/ntlm.c
@@ -174,27 +174,77 @@ SECURITY_STATUS SEC_ENTRY ntlm_AcquireCredentialsHandleW(
if(pAuthData != NULL)
{
PSEC_WINNT_AUTH_IDENTITY_W auth_data = pAuthData;
+ LPWSTR domain = NULL, user = NULL, password = NULL;
+ int domain_len = 0, user_len = 0, password_len = 0;
- TRACE("Username is %s\n", debugstr_wn(auth_data->User, auth_data->UserLength));
- TRACE("Domain name is %s\n", debugstr_wn(auth_data->Domain, auth_data->DomainLength));
+ if (auth_data->Flags & SEC_WINNT_AUTH_IDENTITY_ANSI)
+ {
+ if (auth_data->DomainLength)
+ {
+ domain_len = MultiByteToWideChar(CP_ACP, 0, (char *)auth_data->Domain,
+ auth_data->DomainLength, NULL, 0);
+ domain = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * domain_len);
+ MultiByteToWideChar(CP_ACP, 0, (char *)auth_data->Domain, auth_data->DomainLength,
+ domain, domain_len);
+ }
+
+ if (auth_data->UserLength)
+ {
+ user_len = MultiByteToWideChar(CP_ACP, 0, (char *)auth_data->User,
+ auth_data->UserLength, NULL, 0);
+ user = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * user_len);
+ MultiByteToWideChar(CP_ACP, 0, (char *)auth_data->User, auth_data->UserLength,
+ user, user_len);
+ }
+
+ if (auth_data->PasswordLength)
+ {
+ password_len = MultiByteToWideChar(CP_ACP, 0,(char *)auth_data->Password,
+ auth_data->PasswordLength, NULL, 0);
+ password = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * password_len);
+ MultiByteToWideChar(CP_ACP, 0, (char *)auth_data->Password, auth_data->PasswordLength,
+ password, password_len);
+ }
+ }
+ else
+ {
+ domain = auth_data->Domain;
+ domain_len = auth_data->DomainLength;
+
+ user = auth_data->User;
+ user_len = auth_data->UserLength;
+
+ password = auth_data->Password;
+ password_len = auth_data->PasswordLength;
+ }
+
+ TRACE("Username is %s\n", debugstr_wn(user, user_len));
+ TRACE("Domain name is %s\n", debugstr_wn(domain, domain_len));
- ntlm_cred->username_arg = ntlm_GetUsernameArg(auth_data->User, auth_data->UserLength);
- ntlm_cred->domain_arg = ntlm_GetDomainArg(auth_data->Domain, auth_data->DomainLength);
+ ntlm_cred->username_arg = ntlm_GetUsernameArg(user, user_len);
+ ntlm_cred->domain_arg = ntlm_GetDomainArg(domain, domain_len);
- if(auth_data->PasswordLength != 0)
+ if(password_len != 0)
{
ntlm_cred->pwlen = WideCharToMultiByte(CP_UNIXCP,
- WC_NO_BEST_FIT_CHARS, auth_data->Password,
- auth_data->PasswordLength, NULL, 0, NULL,
+ WC_NO_BEST_FIT_CHARS, password,
+ password_len, NULL, 0, NULL,
NULL);
ntlm_cred->password = HeapAlloc(GetProcessHeap(), 0,
ntlm_cred->pwlen);
WideCharToMultiByte(CP_UNIXCP, WC_NO_BEST_FIT_CHARS,
- auth_data->Password, auth_data->PasswordLength,
+ password, password_len,
ntlm_cred->password, ntlm_cred->pwlen, NULL, NULL);
}
+
+ if (auth_data->Flags & SEC_WINNT_AUTH_IDENTITY_ANSI)
+ {
+ HeapFree(GetProcessHeap(), 0, domain);
+ HeapFree(GetProcessHeap(), 0, user);
+ HeapFree(GetProcessHeap(), 0, password);
+ }
}
phCredential->dwUpper = fCredentialUse;
--
David Woodhouse Open Source Technology Centre
David.Woodhouse at intel.com Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5745 bytes
Desc: not available
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20140808/102c6179/attachment.bin>
More information about the wine-patches
mailing list