mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
KWalletPasswords, GnomeKeyringPasswords: Implement migration from QupZilla
Implement migration of passwords stored in KWallet or GNOME Keyring from QupZilla to Falkon. The logic is the same as for the profiles: If no "Falkon" folder exists, but a "QupZilla" folder exists, we read all the data from the "QupZilla" folder and write it to the "Falkon" folder. (In GNOME Keyring, those are not actually folders, but application attributes on the entries, but the logic is the same.) In GnomeKeyringPasswordBackend, a storeEntry helper method is introduced to avoid duplicating code. Reviewed By: drosca Differential Revision: https://phabricator.kde.org/D12846
This commit is contained in:
parent
d06a0d60e0
commit
774dbf93de
@ -73,6 +73,31 @@ static GnomeKeyringAttributeList* createAttributes(const PasswordEntry &entry)
|
||||
return attributes;
|
||||
}
|
||||
|
||||
static void storeEntry(PasswordEntry &entry)
|
||||
{
|
||||
guint32 itemId;
|
||||
GnomeKeyringAttributeList* attributes = createAttributes(entry);
|
||||
|
||||
QByteArray pass = entry.password.toUtf8();
|
||||
QByteArray host = entry.host.toUtf8();
|
||||
|
||||
GnomeKeyringResult result = gnome_keyring_item_create_sync(GNOME_KEYRING_DEFAULT,
|
||||
GNOME_KEYRING_ITEM_GENERIC_SECRET,
|
||||
host.constData(),
|
||||
attributes,
|
||||
pass.constData(),
|
||||
TRUE, // Update if exists
|
||||
&itemId);
|
||||
|
||||
gnome_keyring_attribute_list_free(attributes);
|
||||
|
||||
if (result != GNOME_KEYRING_RESULT_OK) {
|
||||
qWarning() << "GnomeKeyringPasswordBackend::addEntry Cannot add entry to keyring!";
|
||||
}
|
||||
|
||||
entry.id = itemId;
|
||||
}
|
||||
|
||||
GnomeKeyringPasswordBackend::GnomeKeyringPasswordBackend()
|
||||
: PasswordBackend()
|
||||
, m_loaded(false)
|
||||
@ -118,27 +143,7 @@ void GnomeKeyringPasswordBackend::addEntry(const PasswordEntry &entry)
|
||||
PasswordEntry stored = entry;
|
||||
stored.updated = QDateTime::currentDateTime().toTime_t();
|
||||
|
||||
guint32 itemId;
|
||||
GnomeKeyringAttributeList* attributes = createAttributes(stored);
|
||||
|
||||
QByteArray pass = stored.password.toUtf8();
|
||||
QByteArray host = stored.host.toUtf8();
|
||||
|
||||
GnomeKeyringResult result = gnome_keyring_item_create_sync(GNOME_KEYRING_DEFAULT,
|
||||
GNOME_KEYRING_ITEM_GENERIC_SECRET,
|
||||
host.constData(),
|
||||
attributes,
|
||||
pass.constData(),
|
||||
TRUE, // Update if exists
|
||||
&itemId);
|
||||
|
||||
gnome_keyring_attribute_list_free(attributes);
|
||||
|
||||
if (result != GNOME_KEYRING_RESULT_OK) {
|
||||
qWarning() << "GnomeKeyringPasswordBackend::addEntry Cannot add entry to keyring!";
|
||||
}
|
||||
|
||||
stored.id = itemId;
|
||||
storeEntry(stored);
|
||||
|
||||
m_allEntries.append(stored);
|
||||
}
|
||||
@ -263,6 +268,22 @@ void GnomeKeyringPasswordBackend::initialize()
|
||||
return;
|
||||
}
|
||||
|
||||
bool migrate = false;
|
||||
if (result == GNOME_KEYRING_RESULT_NO_MATCH) {
|
||||
result = gnome_keyring_find_itemsv_sync(GNOME_KEYRING_ITEM_GENERIC_SECRET, &found,
|
||||
"application", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING, "QupZilla",
|
||||
NULL);
|
||||
|
||||
if (result != GNOME_KEYRING_RESULT_OK && result != GNOME_KEYRING_RESULT_NO_MATCH) {
|
||||
qWarning() << "GnomeKeyringPasswordBackend::initialize Cannot read items from keyring!";
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == GNOME_KEYRING_RESULT_OK) {
|
||||
migrate = true;
|
||||
}
|
||||
}
|
||||
|
||||
GList* tmp = found;
|
||||
|
||||
while (tmp) {
|
||||
@ -273,5 +294,11 @@ void GnomeKeyringPasswordBackend::initialize()
|
||||
|
||||
gnome_keyring_found_list_free(found);
|
||||
|
||||
if (migrate) {
|
||||
for (PasswordEntry &entry : m_allEntries) {
|
||||
storeEntry(entry);
|
||||
}
|
||||
}
|
||||
|
||||
m_loaded = true;
|
||||
}
|
||||
|
@ -164,14 +164,23 @@ void KWalletPasswordBackend::initialize()
|
||||
return;
|
||||
}
|
||||
|
||||
bool migrate = !m_wallet->hasFolder("Falkon") && m_wallet->hasFolder("QupZilla");
|
||||
|
||||
if (!m_wallet->hasFolder("Falkon") && !m_wallet->createFolder("Falkon")) {
|
||||
qWarning() << "KWalletPasswordBackend::initialize Cannot create folder \"Falkon\"!";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_wallet->setFolder("Falkon")) {
|
||||
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"Falkon\"!";
|
||||
return;
|
||||
if (migrate) {
|
||||
if (!m_wallet->setFolder("QupZilla")) {
|
||||
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"QupZilla\"!";
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!m_wallet->setFolder("Falkon")) {
|
||||
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"Falkon\"!";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QMap<QString, QByteArray> entries;
|
||||
@ -188,6 +197,17 @@ void KWalletPasswordBackend::initialize()
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
if (migrate) {
|
||||
if (!m_wallet->setFolder("Falkon")) {
|
||||
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"Falkon\"!";
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (const PasswordEntry &entry, m_allEntries) {
|
||||
m_wallet->writeEntry(entry.id.toString(), encodeEntry(entry));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KWalletPasswordBackend::~KWalletPasswordBackend()
|
||||
|
Loading…
Reference in New Issue
Block a user