Commit adff9ca6 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Start to port to QKeychain

parent 3a5f08e8
Pipeline #40781 canceled with stage
in 3 minutes and 39 seconds
......@@ -37,7 +37,7 @@ find_package(Qt5Keychain CONFIG)
set_package_properties(Qt5Keychain PROPERTIES
DESCRIPTION "Provides support for secure credentials storage"
URL "https://github.com/frankosterfeld/qtkeychain"
TYPE OPTIONAL)
TYPE REQUIRED)
# tell what is missing without doctools
set_package_properties(KF5DocTools PROPERTIES DESCRIPTION "Provides tools to generate documentation in various format from DocBook files"
......
......@@ -87,6 +87,7 @@ PRIVATE
KF5::CoreAddons
KF5::KIOCore
${kldap_EXTRA_LIBS}
qt5keychain
)
target_include_directories(KF5Ldap INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF5}/KLDAP>")
......
......@@ -5,6 +5,7 @@
*/
#include "ldapclientsearchconfig.h"
#include "ldapclient_debug.h"
#include <kldap/ldapserver.h>
#include <KConfig>
......@@ -12,7 +13,8 @@
#include <KMessageBox>
#include <KLocalizedString>
#include <kwallet.h>
#include <qt5keychain/keychain.h>
using namespace QKeychain;
using namespace KLDAP;
class Q_DECL_HIDDEN LdapClientSearchConfig::Private
......@@ -106,10 +108,10 @@ void LdapClientSearchConfig::readConfig(KLDAP::LdapServer &server, KConfigGroup
QString pwdBindDN = config.readEntry(pwdBindBNEntry, QString());
if (!pwdBindDN.isEmpty()) {
if (d->askWallet && KMessageBox::Yes == KMessageBox::questionYesNo(nullptr, i18n("LDAP password is stored as clear text, do you want to store it in kwallet?"),
i18n("Store clear text password in KWallet"),
i18n("Store clear text password in Wallet"),
KStandardGuiItem::yes(),
KStandardGuiItem::no(),
QStringLiteral("DoAskToStoreToKwallet"))) {
QStringLiteral("DoAskToStoreToWallet"))) {
d->wallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet(), 0);
if (d->wallet) {
connect(d->wallet, &KWallet::Wallet::walletClosed, this, &LdapClientSearchConfig::slotWalletClosed);
......@@ -186,15 +188,15 @@ void LdapClientSearchConfig::writeConfig(const KLDAP::LdapServer &server, KConfi
const QString passwordEntry = prefix + QStringLiteral("PwdBind%1").arg(j);
const QString password = server.password();
if (!password.isEmpty()) {
if (d->useWallet && !d->wallet) {
d->wallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet(), 0);
}
if (d->wallet) {
d->wallet->writePassword(passwordEntry, password);
} else {
config.writeEntry(passwordEntry, password);
d->useWallet = false;
}
auto writeJob = new WritePasswordJob(QStringLiteral("ldapclient"), this);
connect(writeJob, &Job::finished, this, [this](QKeychain::Job *baseJob) {
if (baseJob->error()) {
qCWarning(LDAPCLIENT_LOG) << "Error writing password using QKeychain:" << baseJob->errorString();
}
});
writeJob->setKey(passwordEntry);
writeJob->setTextData(password);
writeJob->start();
}
config.writeEntry(prefix + QStringLiteral("TimeLimit%1").arg(j), server.timeLimit());
......
......@@ -50,7 +50,7 @@ public:
void writeConfig(const KLDAP::LdapServer &server, KConfigGroup &group, int clientNumber, bool active);
/**
* Should LdapClientSearchConfig ask, if it should use the KWallet to store passwords
* Should LdapClientSearchConfig ask, if it should use the Wallet to store passwords
*/
void askForWallet(bool askForWallet);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment