diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2010-09-10 08:53:41 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2010-09-10 08:54:11 (GMT) |
commit | 759c3c2a2a62648b0fc4b2970a1fdb3a52c488a7 (patch) | |
tree | fe6e7ff284d8def1dac6516d6d35b4ecde52363e /src/network/kernel | |
parent | ecac806359a092e2e09adb027e5a45d2cd993a9f (diff) | |
download | Qt-759c3c2a2a62648b0fc4b2970a1fdb3a52c488a7.zip Qt-759c3c2a2a62648b0fc4b2970a1fdb3a52c488a7.tar.gz Qt-759c3c2a2a62648b0fc4b2970a1fdb3a52c488a7.tar.bz2 |
NTLM code: Save domain in different variable
Reviewed-by: Markus Goetz
Diffstat (limited to 'src/network/kernel')
-rw-r--r-- | src/network/kernel/qauthenticator.cpp | 39 | ||||
-rw-r--r-- | src/network/kernel/qauthenticator_p.h | 1 |
2 files changed, 31 insertions, 9 deletions
diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp index 18cc14e..f97d833 100644 --- a/src/network/kernel/qauthenticator.cpp +++ b/src/network/kernel/qauthenticator.cpp @@ -210,19 +210,38 @@ void QAuthenticator::setUser(const QString &user) switch(d->method) { case QAuthenticatorPrivate::DigestMd5: - case QAuthenticatorPrivate::Ntlm: - if((separatorPosn = user.indexOf(QLatin1String("\\"))) != -1) - { + if((separatorPosn = user.indexOf(QLatin1String("\\"))) != -1) { //domain name is present + d->userDomain.clear(); d->realm = user.left(separatorPosn); d->user = user.mid(separatorPosn + 1); } else if((separatorPosn = user.indexOf(QLatin1String("@"))) != -1) { //domain name is present + d->userDomain.clear(); d->realm = user.mid(separatorPosn + 1); d->user = user.left(separatorPosn); } else { d->user = user; d->realm.clear(); + d->userDomain.clear(); + } + break; + + case QAuthenticatorPrivate::Ntlm: + if((separatorPosn = user.indexOf(QLatin1String("\\"))) != -1) { + //domain name is present + d->realm.clear(); + d->userDomain = user.left(separatorPosn); + d->user = user.mid(separatorPosn + 1); + } else if((separatorPosn = user.indexOf(QLatin1String("@"))) != -1) { + //domain name is present + d->realm.clear(); + d->userDomain = user.left(separatorPosn); + d->user = user.left(separatorPosn); + } else { + d->user = user; + d->realm.clear(); + d->userDomain.clear(); } break; // For other auth mechanisms, domain name will be part of username @@ -1178,7 +1197,7 @@ static QByteArray qCreatev2Hash(const QAuthenticatorPrivate *ctx, // Assuming the user and domain is always unicode in challenge QByteArray message = qStringAsUcs2Le(ctx->user.toUpper()) + - qStringAsUcs2Le(ctx->realm); + qStringAsUcs2Le(phase3->domainStr); phase3->v2Hash = qEncodeHmacMd5(hashKey, message); } @@ -1364,9 +1383,6 @@ static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray& phas bool unicode = ch.flags & NTLMSSP_NEGOTIATE_UNICODE; - if(ctx->realm.isEmpty()) - ctx->realm = ch.targetNameStr; - pb.flags = NTLMSSP_NEGOTIATE_NTLM; if (unicode) pb.flags |= NTLMSSP_NEGOTIATE_UNICODE; @@ -1377,8 +1393,13 @@ static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray& phas int offset = QNtlmPhase3BlockBase::Size; Q_ASSERT(QNtlmPhase3BlockBase::Size == sizeof(QNtlmPhase3BlockBase)); - offset = qEncodeNtlmString(pb.domain, offset, ctx->realm, unicode); - pb.domainStr = ctx->realm; + if(ctx->userDomain.isEmpty()) { + offset = qEncodeNtlmString(pb.domain, offset, ch.targetNameStr, unicode); + pb.domainStr = ch.targetNameStr; + } else { + offset = qEncodeNtlmString(pb.domain, offset, ctx->userDomain, unicode); + pb.domainStr = ctx->userDomain; + } offset = qEncodeNtlmString(pb.user, offset, ctx->user, unicode); pb.userStr = ctx->user; diff --git a/src/network/kernel/qauthenticator_p.h b/src/network/kernel/qauthenticator_p.h index 1096601..4e09360 100644 --- a/src/network/kernel/qauthenticator_p.h +++ b/src/network/kernel/qauthenticator_p.h @@ -91,6 +91,7 @@ public: // ntlm specific QString workstation; + QString userDomain; QByteArray calculateResponse(const QByteArray &method, const QByteArray &path); |