[Pkg-owncloud-commits] [owncloud-client] 356/498: Proxy auth: Fix cred invalidation on Windows.

Sandro Knauß hefee-guest at moszumanska.debian.org
Tue Aug 11 14:49:06 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 44870fae9f808da7043aa1a545242b55e018613b
Author: Christian Kamm <kamm at incasoftware.de>
Date:   Fri Jul 17 12:46:04 2015 +0200

    Proxy auth: Fix cred invalidation on Windows.
---
 src/gui/proxyauthdialog.cpp  |  1 +
 src/gui/proxyauthdialog.h    |  2 +-
 src/gui/proxyauthhandler.cpp | 33 ++++++++++++++++++++++++++++++---
 src/gui/proxyauthhandler.h   |  7 +++++++
 4 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/src/gui/proxyauthdialog.cpp b/src/gui/proxyauthdialog.cpp
index e3dd922..98a5814 100644
--- a/src/gui/proxyauthdialog.cpp
+++ b/src/gui/proxyauthdialog.cpp
@@ -45,6 +45,7 @@ QString ProxyAuthDialog::password() const
 
 void ProxyAuthDialog::reset()
 {
+    ui->usernameEdit->setFocus();
     ui->usernameEdit->clear();
     ui->passwordEdit->clear();
 }
diff --git a/src/gui/proxyauthdialog.h b/src/gui/proxyauthdialog.h
index 0b24abb..c35f693 100644
--- a/src/gui/proxyauthdialog.h
+++ b/src/gui/proxyauthdialog.h
@@ -40,7 +40,7 @@ public:
     QString username() const;
     QString password() const;
 
-    /// Resets the username and password.
+    /// Resets the dialog for new credential entry.
     void reset();
 
 private:
diff --git a/src/gui/proxyauthhandler.cpp b/src/gui/proxyauthhandler.cpp
index 30a82cc..098e128 100644
--- a/src/gui/proxyauthhandler.cpp
+++ b/src/gui/proxyauthhandler.cpp
@@ -16,6 +16,7 @@
 #include "proxyauthdialog.h"
 #include "theme.h"
 #include "configfile.h"
+#include "account.h"
 
 #include <QApplication>
 
@@ -65,6 +66,7 @@ void ProxyAuthHandler::handleProxyAuthenticationRequired(
         _username.clear();
         _password.clear();
         _blocked = false;
+        _gaveCredentialsTo.clear();
 
         // If the user explicitly configured the proxy in the
         // network settings, don't ask about it.
@@ -78,16 +80,31 @@ void ProxyAuthHandler::handleProxyAuthenticationRequired(
         return;
     }
 
-    qDebug() << Q_FUNC_INFO << key << proxy.type() << authenticator->user();
+    // Find the responsible QNAM if possible.
+    QNetworkAccessManager* sending_qnam = qobject_cast<QNetworkAccessManager*>(sender());
+    if (Account* account = qobject_cast<Account*>(sender())) {
+        sending_qnam = account->networkAccessManager();
+    }
+    if (!sending_qnam) {
+        qDebug() << "Could not get the sending QNAM for" << sender();
+    }
+
+
+    qDebug() << Q_FUNC_INFO << key << proxy.type();
 
     // If we already had a username but auth still failed,
-    // invalidate the old credentials!
+    // invalidate the old credentials! Unfortunately, authenticator->user()
+    // isn't reliable, so we also invalidate credentials if we previously
+    // gave presumably valid credentials to the same QNAM.
     bool invalidated = false;
-    if (!authenticator->user().isEmpty() && !_waitingForDialog && !_waitingForKeychain) {
+    if (!_waitingForDialog && !_waitingForKeychain &&
+            (!authenticator->user().isEmpty()
+             || (sending_qnam && _gaveCredentialsTo.contains(sending_qnam)))) {
         qDebug() << "invalidating old creds" << key;
         _username.clear();
         _password.clear();
         invalidated = true;
+        _gaveCredentialsTo.clear();
     }
 
     if (_username.isEmpty() || _waitingForKeychain) {
@@ -105,6 +122,11 @@ void ProxyAuthHandler::handleProxyAuthenticationRequired(
     qDebug() << "got creds for" << _proxy;
     authenticator->setUser(_username);
     authenticator->setPassword(_password);
+    if (sending_qnam) {
+        _gaveCredentialsTo.insert(sending_qnam);
+        connect(sending_qnam, SIGNAL(destroyed(QObject*)),
+                SLOT(slotSenderDestroyed(QObject*)));
+    }
 }
 
 void ProxyAuthHandler::slotKeychainJobDone()
@@ -112,6 +134,11 @@ void ProxyAuthHandler::slotKeychainJobDone()
     _keychainJobRunning = false;
 }
 
+void ProxyAuthHandler::slotSenderDestroyed(QObject* obj)
+{
+    _gaveCredentialsTo.remove(obj);
+}
+
 bool ProxyAuthHandler::getCredsFromDialog()
 {
     // Open the credentials dialog
diff --git a/src/gui/proxyauthhandler.h b/src/gui/proxyauthhandler.h
index 872ae09..eae20f1 100644
--- a/src/gui/proxyauthhandler.h
+++ b/src/gui/proxyauthhandler.h
@@ -21,6 +21,7 @@
 #include <QPointer>
 #include <QScopedPointer>
 #include <QSettings>
+#include <QSet>
 
 namespace QKeychain {
 class Job;
@@ -56,6 +57,7 @@ public slots:
 
 private slots:
     void slotKeychainJobDone();
+    void slotSenderDestroyed(QObject*);
 
 private:
     ProxyAuthHandler();
@@ -100,6 +102,11 @@ private:
 
     /// For checking the proxy config settings.
     QScopedPointer<ConfigFile> _configFile;
+
+    /// To distinguish between a new QNAM asking for credentials and credentials
+    /// failing for an existing QNAM, we keep track of the senders of the
+    /// proxyAuthRequired signal here.
+    QSet<QObject*> _gaveCredentialsTo;
 };
 
 } // namespace OCC

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list