Changeset View
Changeset View
Standalone View
Standalone View
libkdepim/ldap/ldapclientsearchconfig.cpp
Show All 20 Lines | |||||
#include <kldap/ldapserver.h> | #include <kldap/ldapserver.h> | ||||
#include <KStandardDirs> | #include <KStandardDirs> | ||||
#include <KConfig> | #include <KConfig> | ||||
#include <KConfigGroup> | #include <KConfigGroup> | ||||
#include <KMessageBox> | #include <KMessageBox> | ||||
#include <KLocale> | #include <KLocale> | ||||
#include <KDebug> | |||||
#include <kwallet.h> | #include <kwallet.h> | ||||
using namespace KLDAP; | using namespace KLDAP; | ||||
class LdapClientSearchConfig::Private | class LdapClientSearchConfig::Private | ||||
{ | { | ||||
public: | public: | ||||
Private() | Private(LdapClientSearchConfig *parent) | ||||
: useWallet( false ), | : q_ptr( parent ), | ||||
useWallet( false ), | |||||
askWallet( true ), | askWallet( true ), | ||||
wallet( 0 ) | mWallet( 0 ) | ||||
{ | { | ||||
} | } | ||||
~Private() | ~Private() | ||||
{ | { | ||||
if (useWallet) { | if (useWallet) { | ||||
wallet->deleteLater(); | mWallet->deleteLater(); | ||||
wallet = 0; | mWallet = 0; | ||||
} | } | ||||
} | } | ||||
KWallet::Wallet *wallet() | |||||
{ | |||||
Q_Q(LdapClientSearchConfig); | |||||
if (!mWallet) { | |||||
mWallet = KWallet::Wallet::openWallet( KWallet::Wallet::LocalWallet(), 0 ); | |||||
if (mWallet) { | |||||
q->connect(mWallet, SIGNAL(walletClosed()), q, SLOT(slotWalletClosed())); | |||||
} | |||||
} | |||||
return mWallet; | |||||
} | |||||
bool useWallet; | bool useWallet; | ||||
bool askWallet; | bool askWallet; | ||||
KWallet::Wallet* wallet; | KWallet::Wallet* mWallet; | ||||
LdapClientSearchConfig *const q_ptr; | |||||
Q_DECLARE_PUBLIC(LdapClientSearchConfig); | |||||
}; | }; | ||||
K_GLOBAL_STATIC_WITH_ARGS( KConfig, s_config, ( QLatin1String("kabldaprc"), KConfig::NoGlobals ) ) | K_GLOBAL_STATIC_WITH_ARGS( KConfig, s_config, ( QLatin1String("kabldaprc"), KConfig::NoGlobals ) ) | ||||
KConfig* LdapClientSearchConfig::config() | KConfig* LdapClientSearchConfig::config() | ||||
{ | { | ||||
return s_config; | return s_config; | ||||
} | } | ||||
LdapClientSearchConfig::LdapClientSearchConfig(QObject *parent) | LdapClientSearchConfig::LdapClientSearchConfig(QObject *parent) | ||||
: QObject(parent), d(new LdapClientSearchConfig::Private()) | : QObject(parent), d(new LdapClientSearchConfig::Private(this)) | ||||
{ | { | ||||
} | } | ||||
LdapClientSearchConfig::~LdapClientSearchConfig() | LdapClientSearchConfig::~LdapClientSearchConfig() | ||||
{ | { | ||||
delete d; | delete d; | ||||
} | } | ||||
Show All 33 Lines | void LdapClientSearchConfig::readConfig( KLDAP::LdapServer &server, KConfigGroup &config, int j, bool active ) | ||||
const QString pwdBindBNEntry = prefix + QString::fromLatin1( "PwdBind%1" ).arg( j ); | const QString pwdBindBNEntry = prefix + QString::fromLatin1( "PwdBind%1" ).arg( j ); | ||||
QString pwdBindDN = config.readEntry( pwdBindBNEntry, QString() ); | QString pwdBindDN = config.readEntry( pwdBindBNEntry, QString() ); | ||||
if ( !pwdBindDN.isEmpty() ) { | if ( !pwdBindDN.isEmpty() ) { | ||||
if ( d->askWallet && KMessageBox::Yes == KMessageBox::questionYesNo(0, i18n("LDAP password is stored as clear text, do you want to store it in kwallet?"), | if ( d->askWallet && KMessageBox::Yes == KMessageBox::questionYesNo(0, 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 KWallet"), | ||||
KStandardGuiItem::yes(), | KStandardGuiItem::yes(), | ||||
KStandardGuiItem::no(), | KStandardGuiItem::no(), | ||||
QLatin1String("DoAskToStoreToKwallet"))) { | QLatin1String("DoAskToStoreToKwallet"))) { | ||||
d->wallet = KWallet::Wallet::openWallet( KWallet::Wallet::LocalWallet(), 0 ); | |||||
if ( d->wallet ) { | KWallet::Wallet* wallet = d->wallet(); | ||||
connect(d->wallet, SIGNAL(walletClosed()), SLOT(slotWalletClosed())); | if ( wallet ) { | ||||
d->useWallet = true; | d->useWallet = true; | ||||
if ( !d->wallet->hasFolder( QLatin1String("ldapclient") ) ) { | if ( !wallet->hasFolder( QLatin1String("ldapclient") ) ) { | ||||
d->wallet->createFolder( QLatin1String("ldapclient") ); | wallet->createFolder( QLatin1String("ldapclient") ); | ||||
} | } | ||||
d->wallet->setFolder( QLatin1String("ldapclient") ); | wallet->setFolder( QLatin1String("ldapclient") ); | ||||
d->wallet->writePassword(pwdBindBNEntry, pwdBindDN ); | wallet->writePassword(pwdBindBNEntry, pwdBindDN ); | ||||
config.deleteEntry(pwdBindBNEntry); | config.deleteEntry(pwdBindBNEntry); | ||||
config.sync(); | config.sync(); | ||||
} | } | ||||
} | } | ||||
server.setPassword( pwdBindDN ); | server.setPassword( pwdBindDN ); | ||||
} else { //Look at in Wallet | } else { //Look at in Wallet | ||||
d->wallet = KWallet::Wallet::openWallet( KWallet::Wallet::LocalWallet(), 0 ); | KWallet::Wallet* wallet = d->wallet(); | ||||
if ( d->wallet ) { | if ( wallet ) { | ||||
d->useWallet = true; | d->useWallet = true; | ||||
if ( !d->wallet->setFolder( QLatin1String("ldapclient") ) ) { | if ( !wallet->setFolder( QLatin1String("ldapclient") ) ) { | ||||
d->wallet->createFolder( QLatin1String("ldapclient") ); | wallet->createFolder( QLatin1String("ldapclient") ); | ||||
d->wallet->setFolder( QLatin1String("ldapclient") ); | wallet->setFolder( QLatin1String("ldapclient") ); | ||||
} | } | ||||
d->wallet->readPassword( pwdBindBNEntry, pwdBindDN ); | wallet->readPassword( pwdBindBNEntry, pwdBindDN ); | ||||
if (!pwdBindDN.isEmpty()) | if (!pwdBindDN.isEmpty()) | ||||
server.setPassword( pwdBindDN ); | server.setPassword( pwdBindDN ); | ||||
} else { | } else { | ||||
d->useWallet = false; | d->useWallet = false; | ||||
} | } | ||||
} | } | ||||
server.setTimeLimit( config.readEntry( prefix + QString::fromLatin1( "TimeLimit%1" ).arg( j ), 0 ) ); | server.setTimeLimit( config.readEntry( prefix + QString::fromLatin1( "TimeLimit%1" ).arg( j ), 0 ) ); | ||||
Show All 34 Lines | void LdapClientSearchConfig::writeConfig( const KLDAP::LdapServer &server, KConfigGroup &config, int j, bool active ) | ||||
config.writeEntry( prefix + QString::fromLatin1( "Port%1" ).arg( j ), server.port() ); | config.writeEntry( prefix + QString::fromLatin1( "Port%1" ).arg( j ), server.port() ); | ||||
config.writeEntry( prefix + QString::fromLatin1( "Base%1" ).arg( j ), server.baseDn().toString() ); | config.writeEntry( prefix + QString::fromLatin1( "Base%1" ).arg( j ), server.baseDn().toString() ); | ||||
config.writeEntry( prefix + QString::fromLatin1( "User%1" ).arg( j ), server.user() ); | config.writeEntry( prefix + QString::fromLatin1( "User%1" ).arg( j ), server.user() ); | ||||
config.writeEntry( prefix + QString::fromLatin1( "Bind%1" ).arg( j ), server.bindDn() ); | config.writeEntry( prefix + QString::fromLatin1( "Bind%1" ).arg( j ), server.bindDn() ); | ||||
const QString passwordEntry = prefix + QString::fromLatin1( "PwdBind%1" ).arg( j ); | const QString passwordEntry = prefix + QString::fromLatin1( "PwdBind%1" ).arg( j ); | ||||
const QString password = server.password(); | const QString password = server.password(); | ||||
if (!password.isEmpty()) { | if (!password.isEmpty()) { | ||||
if (d->useWallet && !d->wallet) { | KWallet::Wallet* wallet = d->wallet(); | ||||
d->wallet = KWallet::Wallet::openWallet( KWallet::Wallet::LocalWallet(), 0 ); | if (d->useWallet && wallet) { | ||||
} | wallet->writePassword(passwordEntry, password ); | ||||
if (d->wallet) { | |||||
d->wallet->writePassword(passwordEntry, password ); | |||||
} else { | } else { | ||||
config.writeEntry( passwordEntry, password ); | config.writeEntry( passwordEntry, password ); | ||||
d->useWallet = false; | d->useWallet = false; | ||||
} | } | ||||
} | } | ||||
config.writeEntry( prefix + QString::fromLatin1( "TimeLimit%1" ).arg( j ), server.timeLimit() ); | config.writeEntry( prefix + QString::fromLatin1( "TimeLimit%1" ).arg( j ), server.timeLimit() ); | ||||
config.writeEntry( prefix + QString::fromLatin1( "SizeLimit%1" ).arg( j ), server.sizeLimit() ); | config.writeEntry( prefix + QString::fromLatin1( "SizeLimit%1" ).arg( j ), server.sizeLimit() ); | ||||
Show All 22 Lines | default: | ||||
tmp = QLatin1String("Anonymous"); | tmp = QLatin1String("Anonymous"); | ||||
} | } | ||||
config.writeEntry( prefix + QString::fromLatin1( "Auth%1" ).arg( j ), tmp ); | config.writeEntry( prefix + QString::fromLatin1( "Auth%1" ).arg( j ), tmp ); | ||||
config.writeEntry( prefix + QString::fromLatin1( "Mech%1" ).arg( j ), server.mech() ); | config.writeEntry( prefix + QString::fromLatin1( "Mech%1" ).arg( j ), server.mech() ); | ||||
} | } | ||||
void LdapClientSearchConfig::slotWalletClosed() | void LdapClientSearchConfig::slotWalletClosed() | ||||
{ | { | ||||
delete d->wallet; | kDebug(5300) << "wallet was closed"; | ||||
d->wallet = 0; | delete d->mWallet; | ||||
d->mWallet = 0; | |||||
} | } | ||||
void LdapClientSearchConfig::askForWallet(bool askForWallet) | void LdapClientSearchConfig::askForWallet(bool askForWallet) | ||||
{ | { | ||||
d->askWallet = askForWallet; | d->askWallet = askForWallet; | ||||
} | } | ||||