diff --git a/src/runtime/kwalletd/CMakeLists.txt b/src/runtime/kwalletd/CMakeLists.txt --- a/src/runtime/kwalletd/CMakeLists.txt +++ b/src/runtime/kwalletd/CMakeLists.txt @@ -35,9 +35,6 @@ remove_definitions(-DQT_NO_CAST_FROM_ASCII) -# migration agent need exceptions enabled -kde_enable_exceptions() - ecm_setup_version(${KF5_VERSION} VARIABLE_PREFIX KWALLETD VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kwalletd_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5WalletConfigVersion.cmake" @@ -50,8 +47,6 @@ kwalletwizard.cpp ktimeout.cpp kwalletsessionstore.cpp - migrationagent.cpp - migrationwizard.cpp ) ecm_qt_declare_logging_category(kwalletd_SRCS HEADER kwalletd_debug.h IDENTIFIER KWALLETD_LOG CATEGORY_NAME kf5.kwallet.kwalletd) @@ -61,8 +56,6 @@ kwalletwizardpageintro.ui kwalletwizardpageoptions.ui kwalletwizardpagepassword.ui - migrationwizard1.ui - migrationwizard2.ui ) if (Gpgmepp_FOUND) @@ -82,9 +75,6 @@ qt5_add_dbus_adaptor( kwalletd_SRCS ${kwallet_xml} kwalletd.h KWalletD ) -# this is needed for the migration agent -qt5_add_dbus_interface(kwalletd_SRCS ${kwallet_xml} kwallet4_interface) - if(WIN32) configure_file(org.kde.kwalletd5.service.win.in ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kwalletd5.service) diff --git a/src/runtime/kwalletd/kwalletd.h b/src/runtime/kwalletd/kwalletd.h --- a/src/runtime/kwalletd/kwalletd.h +++ b/src/runtime/kwalletd/kwalletd.h @@ -188,7 +188,6 @@ #endif private: - friend class MigrationAgent; // Internal - open a wallet int internalOpen(const QString &appid, const QString &wallet, bool isPath, WId w, bool modal, const QString &service); diff --git a/src/runtime/kwalletd/main.cpp b/src/runtime/kwalletd/main.cpp --- a/src/runtime/kwalletd/main.cpp +++ b/src/runtime/kwalletd/main.cpp @@ -33,7 +33,6 @@ #include "backend/kwalletbackend.h" //For the hash size #include "kwalletd.h" #include "kwalletd_version.h" -#include "migrationagent.h" #ifndef Q_OS_WIN #include @@ -191,9 +190,6 @@ KDBusService dbusUniqueInstance(KDBusService::Unique); - KWalletD walletd; - MigrationAgent migrationAgent(&walletd, hash); - // NOTE: the command should be parsed only after KDBusService instantiation QCommandLineParser cmdParser; aboutdata.setupCommandLine(&cmdParser); @@ -218,6 +214,7 @@ #ifndef Q_OS_WIN if (hash) { + KWalletD walletd; QByteArray passHash(hash, PBKDF2_SHA512_KEYSIZE); int wallet = walletd.pamOpen(KWallet::Wallet::LocalWallet(), passHash, 0); if (wallet < 0) { diff --git a/src/runtime/kwalletd/migrationagent.h b/src/runtime/kwalletd/migrationagent.h deleted file mode 100644 --- a/src/runtime/kwalletd/migrationagent.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - This file is part of the KDE Frameworks - - Copyright (c) 2014 Valentin Rusu - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ -#ifndef _MIGRATIONAGENT_H_ -#define _MIGRATIONAGENT_H_ - -#include - -#include - -class KWalletD; - - -class MigrationAgent : public QObject { - Q_OBJECT -public: - MigrationAgent(KWalletD* kd, const char* hash); - - bool isEmptyOldWallet() const; - bool performMigration(WId wid, bool withoutWizard); - -private Q_SLOTS: - void migrateWallets(); - bool isAlreadyMigrated(); - bool connectOldDaemon(); - bool isMigrationWizardOk(); - void setAlreadyMigrated(); -public Q_SLOTS: - void emitProgressMessage(const QString &); - -Q_SIGNALS: - void progressMessage(const QString &); - void migrationFinished(); - -private: - KWalletD *_kf5_daemon; - org::kde::KWallet *_kde4_daemon; - const char *_pam_hash; -}; - -#endif // _MIGRATIONAGENT_H_ diff --git a/src/runtime/kwalletd/migrationagent.cpp b/src/runtime/kwalletd/migrationagent.cpp deleted file mode 100644 --- a/src/runtime/kwalletd/migrationagent.cpp +++ /dev/null @@ -1,265 +0,0 @@ -/* - This file is part of the KDE Frameworks - - Copyright (c) 2014 Valentin Rusu - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#include "migrationagent.h" -#include "kwalletd_debug.h" -#include "migrationwizard.h" -#include "kwalletd.h" - -#include -#include -#include -#include - -#include -#include - -#define SERVICE_KWALLETD4 "org.kde.kwalletd" -#define ENTRY_ALREADY_MIGRATED "alreadyMigrated" -#define ENTRY_SHOW_MIGRATION_WIZARD "showMigrationWizard" - -MigrationAgent::MigrationAgent(KWalletD* kd, const char *hash) : - _kf5_daemon(kd) - , _kde4_daemon(nullptr) - , _pam_hash(hash) -{ - connect(this, &MigrationAgent::migrationFinished, _kf5_daemon, &KWalletD::registerKWalletd4Service); - if (isAlreadyMigrated()) { - qCDebug(KWALLETD_LOG) << "old wallets were already migrated"; - emit migrationFinished(); - } else { - QTimer::singleShot(100, this, SLOT(migrateWallets())); - } -} - -void MigrationAgent::migrateWallets() -{ - // the migration is done in several steps : - // is the setting "alreadyMigrated" present and true ? - // if yes, then stop here - // if not, then is kwalletd present (the daemon from KDE4) ? - // if not, then stop here - // if yes, then start the migration wizard - // if the migration wizard returns without error - // create "alreadyMigrated=true" setting - qCDebug(KWALLETD_LOG) << "Migration agent starting..."; - if (connectOldDaemon()) { - if (!isEmptyOldWallet()) { - if (isMigrationWizardOk()) { - setAlreadyMigrated(); - emit migrationFinished(); - } else { - qCDebug(KWALLETD_LOG) << "Migration wizard returned an error or has been canceled. The migration agent will resume upon next daemon start"; - } - } else { - qCDebug(KWALLETD_LOG) << "Old wallet is empty. No need to migrate."; - setAlreadyMigrated(); - emit migrationFinished(); - } - } else { - qCDebug(KWALLETD_LOG) << "KDE4 kwalletd not present, stopping migration agent"; - emit migrationFinished(); - } - qCDebug(KWALLETD_LOG) << "Migration agent stop."; -} - -bool MigrationAgent::isAlreadyMigrated() -{ - KConfig kwalletrc(QStringLiteral("kwalletrc")); - KConfigGroup cfg(&kwalletrc, "Migration"); - return cfg.readEntry(ENTRY_ALREADY_MIGRATED, false); -} - -void MigrationAgent::setAlreadyMigrated() -{ - KConfig kwalletrc(QStringLiteral("kwalletrc")); - KConfigGroup cfg(&kwalletrc, "Migration"); - cfg.writeEntry(ENTRY_ALREADY_MIGRATED, true); -} - -bool MigrationAgent::connectOldDaemon() -{ - // the old daemon may not have been started, so attempt start it - // NOTE we provide a "fake" org.kde.kwalletd.service file - see the project structure - // however, this thing is a HACK as we cannot tell here, in KF5, user's KDE4 install prefix - // the provided .service file assumes /usr/bin - QDBusConnectionInterface *bus = QDBusConnection::sessionBus().interface(); - if (!bus->isServiceRegistered(QStringLiteral(SERVICE_KWALLETD4))) { - qCDebug(KWALLETD_LOG) << "kwalletd not started. Attempting start..."; - QDBusReply reply = bus->startService(SERVICE_KWALLETD4); - if (!reply.isValid()) { - qCDebug(KWALLETD_LOG) << "Couldn't start kwalletd: " << reply.error(); - return false; - } - if (!bus->isServiceRegistered(QStringLiteral(SERVICE_KWALLETD4))) { - qCDebug(KWALLETD_LOG) << "The kwalletd service is still not registered after start attemtp. Aborting migration"; - return false; - } else { - qCDebug(KWALLETD_LOG) << "The kwalletd service has been registered"; - } - } - - _kde4_daemon = new org::kde::KWallet(QStringLiteral(SERVICE_KWALLETD4), QStringLiteral("/modules/kwalletd"), QDBusConnection::sessionBus()); - return _kde4_daemon->isValid(); -} - -bool MigrationAgent::isMigrationWizardOk() -{ - bool ok = false; - - // The migration wizard would no longer been shown by default. - // see BUG 351056 - // NOTE if user wants to show the migration wizard, then he should add the - // following setting to the kwalletrc: - // [Migration] - // showMigrationWizard=true - KConfig kwalletrc(QStringLiteral("kwalletrc")); - KConfigGroup cfg(&kwalletrc, "Migration"); - bool showMigrationWizard = cfg.readEntry(ENTRY_SHOW_MIGRATION_WIZARD, false); - - if (showMigrationWizard) { - MigrationWizard *wizard = new MigrationWizard(this); - int result = wizard->exec(); - if (QDialog::Accepted == result) { - // the user either migrated the wallets, or choose not to be prompted again - ok = true; - } - } else { - if (performMigration(0, true)) { - ok = true; - } else { - qCDebug(KWALLETD_LOG) << "Migration failed."; - } - } - - return ok; -} - -void MigrationAgent::emitProgressMessage(const QString &msg) -{ - emit progressMessage(msg); -} - -class MigrationException { - public: MigrationException(const QString &msg): _msg(msg) {} - QString _msg; -}; - -template R invokeAndCheck(MigrationAgent *migrationAgent, F f, QString errorMsg) { - QDBusPendingReply reply = f(); - reply.waitForFinished(); - QApplication::processEvents(); // keep UI responsive to show progress messages - if (!reply.isValid()) { - migrationAgent->emitProgressMessage(errorMsg); - throw MigrationException(errorMsg); - } - return reply.value(); -} - -bool MigrationAgent::isEmptyOldWallet() const { - QStringList wallets; - try { - wallets = invokeAndCheck( - const_cast(this), [this] { return _kde4_daemon->wallets(); }, - i18n("Cannot read old wallet list. Aborting.")); - } catch (MigrationException ex) { - return true; - } - - return wallets.length() == 0; -} - -bool MigrationAgent::performMigration(WId wid, bool withoutWizard) -{ - auto appId = i18n("KDE Wallet Migration Agent"); - try { - QStringList wallets = invokeAndCheck( - this, [this] { return _kde4_daemon->wallets(); }, - i18n("Cannot read old wallet list. Aborting.")); - - for (const QString &wallet : qAsConst(wallets)) { - emit progressMessage(i18n("Migrating wallet: %1", wallet)); - emit progressMessage(i18n("* Creating KF5 wallet: %1", wallet)); - - int handle5 = -1; - if (withoutWizard && (_pam_hash != nullptr)) { - // see BUG 351056 for why this hacky code - // If the user has several wallets, all the values will be - // merged into the single LocalWallet - handle5 = _kf5_daemon->pamOpen(KWallet::Wallet::LocalWallet(), _pam_hash, 0); - } else { - handle5 = _kf5_daemon->internalOpen(appId, wallet, false, 0, true, QString()); - } - if (handle5 <0) { - emit progressMessage(i18n("ERROR when attempting new wallet creation. Aborting.")); - return false; - } - - int handle4 = invokeAndCheck( - this, [this, wallet, wid, appId] { return _kde4_daemon->open(wallet, wid, appId); }, - i18n("Cannot open KDE4 wallet named: %1", wallet)); - emit progressMessage(i18n("* Opened KDE4 wallet: %1", wallet)); - - const QStringList folders = invokeAndCheck( - this, [this, handle4, appId] { return _kde4_daemon->folderList(handle4, appId); }, - i18n("Cannot retrieve folder list. Aborting.")); - - for (const QString &folder : folders) { - emit progressMessage(i18n("* Migrating folder %1", folder)); - - const QStringList entries = invokeAndCheck( - this, [this, handle4, folder, appId] { return _kde4_daemon->entryList(handle4, folder, appId); }, - i18n("Cannot retrieve folder %1 entries. Aborting.", folder)); - - for (const QString &key : entries) { - - int entryType = invokeAndCheck( - this, [this, handle4, folder, key, appId] { return _kde4_daemon->entryType(handle4, folder, key, appId); }, - i18n("Cannot retrieve key %1 info. Aborting.", key)); - - // handle the case where the entries are already there - if (_kf5_daemon->hasEntry(handle5, folder, key, appId)) { - emit progressMessage(i18n("* SKIPPING entry %1 in folder %2 as it seems already migrated", key, folder)); - } else { - QByteArray entry = invokeAndCheck( - this, [this, handle4, folder, key, appId] { return _kde4_daemon->readEntry(handle4, folder, key, appId); }, - i18n("Cannot retrieve key %1 data. Aborting.", key)); - if ( _kf5_daemon->writeEntry(handle5, folder, key, entry, entryType, appId) != 0 ) { - auto msg = i18n("Cannot write entry %1 in the new wallet. Aborting.", key); - emit progressMessage(msg); - throw MigrationException(msg); - } - } - } - } - - //_kde4_daemon->close(handle4, false, appId); - //_kf5_daemon->close(handle5, true, appId); - _kf5_daemon->sync(handle5, appId); - emit progressMessage(i18n("DONE migrating wallet\n")); - } - } catch (MigrationException ex) { - return false; - } - return true; -} - diff --git a/src/runtime/kwalletd/migrationwizard.h b/src/runtime/kwalletd/migrationwizard.h deleted file mode 100644 --- a/src/runtime/kwalletd/migrationwizard.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of the KDE Frameworks - * - * Copyright (c) 2014 Valentin Rusu - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ -#ifndef _MIGRATIONWIZARD_H_ -#define _MIGRATIONWIZARD_H_ - -#include - -class MigrationAgent; - -class MigrationWizard : public QWizard { - Q_OBJECT -public: - explicit MigrationWizard(MigrationAgent *agent); - ~MigrationWizard() override; - - MigrationAgent *agent() const { return _agent; } - -public Q_SLOTS: - void page1Updated(); - -private: - MigrationAgent *_agent; -}; - -#endif // _MIGRATIONWIZARD_H_ diff --git a/src/runtime/kwalletd/migrationwizard.cpp b/src/runtime/kwalletd/migrationwizard.cpp deleted file mode 100644 --- a/src/runtime/kwalletd/migrationwizard.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * This file is part of the KDE Frameworks - * - * Copyright (c) 2014 Valentin Rusu - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#include "migrationwizard.h" -#include "ui_migrationwizard1.h" -#include "ui_migrationwizard2.h" -#include "migrationagent.h" - -class MigrationPage1 : public QWizardPage { -public: - MigrationPage1(QWidget *wizard) - : QWizardPage(wizard) - { - _ui.setupUi(this); - connect(_ui._optionNo, SIGNAL(toggled(bool)), wizard, SLOT(page1Updated())); - connect(_ui._optionNotInterested, SIGNAL(toggled(bool)), wizard, SLOT(page1Updated())); - connect(_ui._optionYes, SIGNAL(toggled(bool)), wizard, SLOT(page1Updated())); - connect(_ui._optionNo, &QRadioButton::toggled, this, &QWizardPage::completeChanged); - } - - bool isComplete() const override { - return !_ui._optionNo->isChecked(); - } - - Ui::MigrationPage1 _ui; -}; - -class MigrationPage2 : public QWizardPage { -public: - MigrationPage2(MigrationWizard* wizard) - : QWizardPage(wizard) - , _agent(wizard->agent()) - , _migrationCompleted(false) - { - _ui.setupUi(this); - } - - void initializePage() override { - connect(_agent, SIGNAL(progressMessage(QString)), _ui._report, SLOT(append(QString))); - _migrationCompleted = _agent->performMigration(winId(), false); - emit completeChanged(); - } - - bool isComplete() const override { - return _migrationCompleted; - } - - Ui::MigrationPage2 _ui; - MigrationAgent *_agent; - bool _migrationCompleted; -}; - -MigrationPage1 *page1 = nullptr; -MigrationPage2 *page2 = nullptr; - -MigrationWizard::MigrationWizard(MigrationAgent *agent) - : _agent(agent) -{ - setOption(HaveFinishButtonOnEarlyPages); - page1 = new MigrationPage1(this); - addPage(page1); - - page2 = new MigrationPage2(this); - addPage(page2); -} - -MigrationWizard::~MigrationWizard() -{ - delete page1; - delete page2; -} - -void MigrationWizard::page1Updated() -{ - if (page1->_ui._optionYes->isChecked()) { - page1->setFinalPage(false); - button(NextButton)->setEnabled(true); - } - if (page1->_ui._optionNo->isChecked()) { - page1->setFinalPage(true); - button(NextButton)->setEnabled(false); - } - if (page1->_ui._optionNotInterested->isChecked()) { - page1->setFinalPage(true); - button(NextButton)->setEnabled(false); - } -} - - diff --git a/src/runtime/kwalletd/migrationwizard1.ui b/src/runtime/kwalletd/migrationwizard1.ui deleted file mode 100644 --- a/src/runtime/kwalletd/migrationwizard1.ui +++ /dev/null @@ -1,122 +0,0 @@ - - - MigrationPage1 - - - - 0 - 0 - 523 - 377 - - - - - - - The KDE Wallet System - - - - - - - Congratulations! The system detected that you're running the latest version of the KWallet, using KDE Frameworks 5. - -It seems that you also have KDE4 wallet(s) on your system. - -Would you like them to be migrated to this new KWallet version? The operation will only take one minute to be performed. - - - - true - - - true - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - &Yes, migrate my wallets now. - - - true - - - - - - - No, I'd rather do this upon ne&xt session start, -and I'll cancel this wizard for now. - - - - - - - No, and p&lease do not prompt me again. - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 102 - - - - - - - - - KTitleWidget - QWidget -
ktitlewidget.h
-
-
- - -
diff --git a/src/runtime/kwalletd/migrationwizard2.ui b/src/runtime/kwalletd/migrationwizard2.ui deleted file mode 100644 --- a/src/runtime/kwalletd/migrationwizard2.ui +++ /dev/null @@ -1,51 +0,0 @@ - - - MigrationPage2 - - - - 0 - 0 - 521 - 377 - - - - - - - The KDE Wallet System - - - - - - - QTextEdit::AutoBulletList - - - true - - - false - - - true - - - Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - KTitleWidget - QWidget -
ktitlewidget.h
-
-
- - -
diff --git a/src/runtime/kwalletd/org.kde.kwalletd.service b/src/runtime/kwalletd/org.kde.kwalletd.service deleted file mode 100644 --- a/src/runtime/kwalletd/org.kde.kwalletd.service +++ /dev/null @@ -1,6 +0,0 @@ -# this installs an activatable service for the legacy, KDE4, kwalletd -# NOTE this file assumes the kwalletd daemon is installed in the usual /usr/bin directory -# that is because we have no means here, in KF5, to know about the KDE4 prefix -[D-BUS Service] -Name=org.kde.kwalletd -Exec=/usr/bin/kwalletd