Fix getting credentials from non-connected database

This commit is contained in:
varjolintu 2019-08-27 21:50:54 +03:00 committed by Jonathan White
parent 23eb13ced6
commit bef1b94d71
2 changed files with 18 additions and 9 deletions

View File

@ -304,7 +304,7 @@
<item> <item>
<widget class="QCheckBox" name="searchInAllDatabases"> <widget class="QCheckBox" name="searchInAllDatabases">
<property name="toolTip"> <property name="toolTip">
<string>Only the selected database has to be connected with a client.</string> <string>All databases connected to the extension will return matching credentials.</string>
</property> </property>
<property name="text"> <property name="text">
<string extracomment="Credentials mean login data requested via browser extension">Searc&amp;h in all opened databases for matching credentials</string> <string extracomment="Credentials mean login data requested via browser extension">Searc&amp;h in all opened databases for matching credentials</string>

View File

@ -605,6 +605,18 @@ BrowserService::searchEntries(const QSharedPointer<Database>& db, const QString&
QList<Entry*> BrowserService::searchEntries(const QString& url, const StringPairList& keyList) QList<Entry*> BrowserService::searchEntries(const QString& url, const StringPairList& keyList)
{ {
// Check if database is connected with KeePassXC-Browser
auto databaseConnected = [&](const QSharedPointer<Database>& db) {
for (const StringPair& keyPair : keyList) {
QString key =
db->metadata()->customData()->value(QLatin1String(ASSOCIATE_KEY_PREFIX) + keyPair.first);
if (!key.isEmpty() && keyPair.second == key) {
return true;
}
}
return false;
};
// Get the list of databases to search // Get the list of databases to search
QList<QSharedPointer<Database>> databases; QList<QSharedPointer<Database>> databases;
if (browserSettings()->searchInAllDatabases()) { if (browserSettings()->searchInAllDatabases()) {
@ -612,20 +624,17 @@ QList<Entry*> BrowserService::searchEntries(const QString& url, const StringPair
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
if (auto* dbWidget = qobject_cast<DatabaseWidget*>(m_dbTabWidget->widget(i))) { if (auto* dbWidget = qobject_cast<DatabaseWidget*>(m_dbTabWidget->widget(i))) {
if (const auto& db = dbWidget->database()) { if (const auto& db = dbWidget->database()) {
// Check if database is connected with KeePassXC-Browser if (databaseConnected(db)) {
for (const StringPair& keyPair : keyList) {
QString key =
db->metadata()->customData()->value(QLatin1String(ASSOCIATE_KEY_PREFIX) + keyPair.first);
if (!key.isEmpty() && keyPair.second == key) {
databases << db; databases << db;
} }
} }
} }
} }
}
} else if (const auto& db = getDatabase()) { } else if (const auto& db = getDatabase()) {
if (databaseConnected(db)) {
databases << db; databases << db;
} }
}
// Search entries matching the hostname // Search entries matching the hostname
QString hostname = QUrl(url).host(); QString hostname = QUrl(url).host();