QAuthenticator(Negotiate): Try provided credential

Windows only so far, need a similar patch for *nix, or an alternate
approach when there is no server set up.

Pick-to: 5.15
Task-number: QTBUG-85123
Change-Id: Iff7a6b1540a2f1984153a237eea07c7bb1970064
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
bb10
Mårten Nordheim 2020-09-04 19:57:19 +02:00
parent b41a7afb00
commit 219ed70957
1 changed files with 17 additions and 4 deletions

View File

@ -1532,12 +1532,25 @@ static QByteArray qSspiStartup(QAuthenticatorPrivate *ctx, QAuthenticatorPrivate
ctx->sspiWindowsHandles.reset(new QSSPIWindowsHandles);
memset(&ctx->sspiWindowsHandles->credHandle, 0, sizeof(CredHandle));
SEC_WINNT_AUTH_IDENTITY auth;
auth.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
bool useAuth = false;
if (method == QAuthenticatorPrivate::Negotiate && !ctx->user.isEmpty()) {
auth.Domain = const_cast<ushort *>(ctx->userDomain.utf16());
auth.DomainLength = ctx->userDomain.size();
auth.User = const_cast<ushort *>(ctx->user.utf16());
auth.UserLength = ctx->user.size();
auth.Password = const_cast<ushort *>(ctx->password.utf16());
auth.PasswordLength = ctx->password.size();
useAuth = true;
}
// Acquire our credentials handle
SECURITY_STATUS secStatus = pSecurityFunctionTable->AcquireCredentialsHandle(
nullptr,
(SEC_WCHAR*)(method == QAuthenticatorPrivate::Negotiate ? L"Negotiate" : L"NTLM"),
SECPKG_CRED_OUTBOUND, nullptr, nullptr, nullptr, nullptr,
&ctx->sspiWindowsHandles->credHandle, &expiry
nullptr,
(SEC_WCHAR *)(method == QAuthenticatorPrivate::Negotiate ? L"Negotiate" : L"NTLM"),
SECPKG_CRED_OUTBOUND, nullptr, useAuth ? &auth : nullptr, nullptr, nullptr,
&ctx->sspiWindowsHandles->credHandle, &expiry
);
if (secStatus != SEC_E_OK) {
ctx->sspiWindowsHandles.reset(nullptr);