diff options
-rw-r--r-- | src/gui/DatabaseWidget.cpp | 18 | ||||
-rw-r--r-- | src/gui/MainWindow.cpp | 3 | ||||
-rw-r--r-- | src/sshagent/SSHAgent.cpp | 29 | ||||
-rw-r--r-- | src/sshagent/SSHAgent.h | 7 |
4 files changed, 28 insertions, 29 deletions
diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 28d3aedd7..bb0a6ec41 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -214,13 +214,6 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> db, QWidget* parent) m_EntrySearcher = new EntrySearcher(false); m_searchLimitGroup = config()->get(Config::SearchLimitGroup).toBool(); -#ifdef WITH_XC_SSHAGENT - if (sshAgent()->isEnabled()) { - connect(this, SIGNAL(databaseLocked()), sshAgent(), SLOT(databaseLocked())); - connect(this, SIGNAL(databaseUnlocked()), sshAgent(), SLOT(databaseUnlocked())); - } -#endif - #ifdef WITH_XC_KEESHARE // We need to reregister the database to allow exports // from a newly created database @@ -1089,6 +1082,9 @@ void DatabaseWidget::loadDatabase(bool accepted) m_entryBeforeLock = QUuid(); m_saveAttempts = 0; emit databaseUnlocked(); +#ifdef WITH_XC_SSHAGENT + sshAgent()->databaseUnlocked(m_db); +#endif if (config()->get(Config::MinimizeAfterUnlock).toBool()) { getMainWindow()->minimizeOrHide(); } @@ -1176,6 +1172,10 @@ void DatabaseWidget::unlockDatabase(bool accepted) processAutoOpen(); emit databaseUnlocked(); +#ifdef WITH_XC_SSHAGENT + sshAgent()->databaseUnlocked(m_db); +#endif + if (senderDialog && senderDialog->intent() == DatabaseOpenDialog::Intent::AutoType) { QList<QSharedPointer<Database>> dbList; dbList.append(m_db); @@ -1597,6 +1597,10 @@ bool DatabaseWidget::lock() m_entryBeforeLock = currentEntry->uuid(); } +#ifdef WITH_XC_SSHAGENT + sshAgent()->databaseLocked(m_db); +#endif + endSearch(); clearAllWidgets(); switchToOpenDatabase(m_db->filePath()); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 5b3c5c9b6..3def5988e 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -601,6 +601,9 @@ MainWindow::MainWindow() MainWindow::~MainWindow() { +#ifdef WITH_XC_SSHAGENT + sshAgent()->removeAllIdentities(); +#endif } QList<DatabaseWidget*> MainWindow::getOpenDatabases() diff --git a/src/sshagent/SSHAgent.cpp b/src/sshagent/SSHAgent.cpp index c43cc37a6..1e67ae3c8 100644 --- a/src/sshagent/SSHAgent.cpp +++ b/src/sshagent/SSHAgent.cpp @@ -19,6 +19,9 @@ #include "SSHAgent.h" #include "core/Config.h" +#include "core/Database.h" +#include "core/Group.h" +#include "core/Metadata.h" #include "crypto/ssh/BinaryStream.h" #include "crypto/ssh/OpenSSHKey.h" #include "sshagent/KeeAgentSettings.h" @@ -31,11 +34,6 @@ Q_GLOBAL_STATIC(SSHAgent, s_sshAgent); -SSHAgent::~SSHAgent() -{ - removeAllIdentities(); -} - SSHAgent* SSHAgent::instance() { return s_sshAgent; @@ -427,18 +425,15 @@ void SSHAgent::setAutoRemoveOnLock(const OpenSSHKey& key, bool autoRemove) } } -void SSHAgent::databaseLocked() +void SSHAgent::databaseLocked(QSharedPointer<Database> db) { - auto* widget = qobject_cast<DatabaseWidget*>(sender()); - if (!widget) { + if (!db) { return; } - QUuid databaseUuid = widget->database()->uuid(); - auto it = m_addedKeys.begin(); while (it != m_addedKeys.end()) { - if (it.value().first != databaseUuid) { + if (it.value().first != db->uuid()) { ++it; continue; } @@ -452,16 +447,14 @@ void SSHAgent::databaseLocked() } } -void SSHAgent::databaseUnlocked() +void SSHAgent::databaseUnlocked(QSharedPointer<Database> db) { - auto* widget = qobject_cast<DatabaseWidget*>(sender()); - if (!widget) { + if (!db || !isEnabled()) { return; } - for (Entry* e : widget->database()->rootGroup()->entriesRecursive()) { - if (widget->database()->metadata()->recycleBinEnabled() - && e->group() == widget->database()->metadata()->recycleBin()) { + for (Entry* e : db->rootGroup()->entriesRecursive()) { + if (db->metadata()->recycleBinEnabled() && e->group() == db->metadata()->recycleBin()) { continue; } @@ -483,7 +476,7 @@ void SSHAgent::databaseUnlocked() // Add key to agent; ignore errors if we have previously added the key bool known_key = m_addedKeys.contains(key); - if (!addIdentity(key, settings, widget->database()->uuid()) && !known_key) { + if (!addIdentity(key, settings, db->uuid()) && !known_key) { emit error(m_error); } } diff --git a/src/sshagent/SSHAgent.h b/src/sshagent/SSHAgent.h index 7deaf8e7f..d18cd4770 100644 --- a/src/sshagent/SSHAgent.h +++ b/src/sshagent/SSHAgent.h @@ -24,7 +24,6 @@ #include <QtCore> #include "crypto/ssh/OpenSSHKey.h" -#include "gui/DatabaseWidget.h" #include "sshagent/KeeAgentSettings.h" class SSHAgent : public QObject @@ -32,7 +31,7 @@ class SSHAgent : public QObject Q_OBJECT public: - ~SSHAgent() override; + ~SSHAgent() override = default; static SSHAgent* instance(); bool isEnabled() const; @@ -59,8 +58,8 @@ signals: void enabledChanged(bool enabled); public slots: - void databaseLocked(); - void databaseUnlocked(); + void databaseLocked(QSharedPointer<Database> db); + void databaseUnlocked(QSharedPointer<Database> db); private: const quint8 SSH_AGENT_FAILURE = 5; |