FdoSecrets: do not share entry <-> item property by multiple unlock prompts

Fixes #7753
This commit is contained in:
Aetf 2022-04-03 23:46:18 -04:00 committed by Jonathan White
parent a98bf1eac3
commit 6b0eeb9722
2 changed files with 14 additions and 12 deletions

View File

@ -297,15 +297,15 @@ namespace FdoSecrets
continue; continue;
} }
auto entry = item->backend(); auto entry = item->backend();
if (client->itemKnown(entry->uuid())) { auto uuid = entry->uuid();
if (!client->itemAuthorized(entry->uuid())) { if (client->itemKnown(uuid)) {
if (!client->itemAuthorized(uuid)) {
m_numRejected += 1; m_numRejected += 1;
} }
// Already saw this entry
continue; continue;
} }
// attach a temporary property, so later we can get the item m_entryToItems[uuid] = item.data();
// back from the dialog's result
entry->setProperty(FdoSecretsBackend, QVariant::fromValue(item.data()));
entries << entry; entries << entry;
} }
} }
@ -331,15 +331,17 @@ namespace FdoSecrets
} }
for (auto it = decisions.constBegin(); it != decisions.constEnd(); ++it) { for (auto it = decisions.constBegin(); it != decisions.constEnd(); ++it) {
auto entry = it.key(); auto entry = it.key();
auto uuid = entry->uuid();
// get back the corresponding item // get back the corresponding item
auto item = entry->property(FdoSecretsBackend).value<Item*>(); auto item = m_entryToItems.value(uuid);
entry->setProperty(FdoSecretsBackend, {}); if (!item) {
Q_ASSERT(item); continue;
}
// set auth // set auth
client->setItemAuthorized(entry->uuid(), it.value()); client->setItemAuthorized(uuid, it.value());
if (client->itemAuthorized(entry->uuid())) { if (client->itemAuthorized(uuid)) {
m_unlocked += item->objectPath(); m_unlocked += item->objectPath();
} else { } else {
m_numRejected += 1; m_numRejected += 1;

View File

@ -172,10 +172,10 @@ namespace FdoSecrets
void itemUnlockFinished(const QHash<Entry*, AuthDecision>& results, AuthDecision forFutureEntries); void itemUnlockFinished(const QHash<Entry*, AuthDecision>& results, AuthDecision forFutureEntries);
void unlockItems(); void unlockItems();
static constexpr auto FdoSecretsBackend = "FdoSecretsBackend";
QList<QPointer<Collection>> m_collections; QList<QPointer<Collection>> m_collections;
QHash<Collection*, QList<QPointer<Item>>> m_items; QHash<Collection*, QList<QPointer<Item>>> m_items;
QHash<QUuid, Item*> m_entryToItems;
QList<QDBusObjectPath> m_unlocked; QList<QDBusObjectPath> m_unlocked;
int m_numRejected = 0; int m_numRejected = 0;