Skip to content

Commit

Permalink
Prevent SSH Agent from using entries in the recycle bin
Browse files Browse the repository at this point in the history
* Fixes #10516
* Also cleanup Group::isRecycled() code a little
  • Loading branch information
droidmonkey committed Apr 20, 2024
1 parent e657cbf commit 6f11422
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/core/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions src/sshagent/SSHAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/sshagent/SSHAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class SSHAgent : public QObject
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;
Expand Down

0 comments on commit 6f11422

Please sign in to comment.