Prevent SSH Agent from using entries in the recycle bin

* Fixes #10516
* Also cleanup Group::isRecycled() code a little
This commit is contained in:
Jonathan White 2024-03-29 12:41:05 -04:00
parent e657cbf43b
commit 6f11422604
3 changed files with 17 additions and 17 deletions

View File

@ -223,17 +223,17 @@ Entry* Group::lastTopVisibleEntry() const
bool Group::isRecycled() const
{
auto group = this;
if (!group->database() || !group->m_db->metadata()) {
return false;
auto db = group->database();
if (db) {
auto recycleBin = db->metadata()->recycleBin();
do {
if (group == recycleBin) {
return true;
}
group = group->m_parent;
} while (group);
}
do {
if (group == group->m_db->metadata()->recycleBin()) {
return true;
}
group = group->m_parent;
} while (group);
return false;
}

View File

@ -486,7 +486,7 @@ void SSHAgent::setAutoRemoveOnLock(const OpenSSHKey& key, bool autoRemove)
}
}
void SSHAgent::databaseLocked(QSharedPointer<Database> db)
void SSHAgent::databaseLocked(const QSharedPointer<Database>& db)
{
if (!db) {
return;
@ -508,20 +508,20 @@ void SSHAgent::databaseLocked(QSharedPointer<Database> db)
}
}
void SSHAgent::databaseUnlocked(QSharedPointer<Database> db)
void SSHAgent::databaseUnlocked(const QSharedPointer<Database>& db)
{
if (!db || !isEnabled()) {
return;
}
for (Entry* e : db->rootGroup()->entriesRecursive()) {
if (db->metadata()->recycleBinEnabled() && e->group() == db->metadata()->recycleBin()) {
for (auto entry : db->rootGroup()->entriesRecursive()) {
if (entry->isRecycled()) {
continue;
}
KeeAgentSettings settings;
if (!settings.fromEntry(e)) {
if (!settings.fromEntry(entry)) {
continue;
}
@ -531,7 +531,7 @@ void SSHAgent::databaseUnlocked(QSharedPointer<Database> db)
OpenSSHKey key;
if (!settings.toOpenSSHKey(e, key, true)) {
if (!settings.toOpenSSHKey(entry, key, true)) {
continue;
}

View File

@ -63,8 +63,8 @@ signals:
void enabledChanged(bool enabled);
public slots:
void databaseLocked(QSharedPointer<Database> db);
void databaseUnlocked(QSharedPointer<Database> db);
void databaseLocked(const QSharedPointer<Database>& db);
void databaseUnlocked(const QSharedPointer<Database>& db);
private:
const quint8 SSH_AGENT_FAILURE = 5;