24#include "config-kwallet.h"
26#include <QtGui/QApplication>
27#include <QtCore/QPointer>
28#include <QtGui/QWidget>
29#include <QtDBus/QtDBus>
36#include <kdeversion.h>
42#ifdef HAVE_KSECRETSSERVICE
43#include "ksecretsservice/ksecretsservicecollection.h"
46#include "kwallet_interface.h"
48#ifdef HAVE_KSECRETSSERVICE
63 org::kde::KWallet &getInterface();
69 bool m_useKSecretsService;
70 org::kde::KWallet *m_wallet;
88 return qApp->applicationName();
93 static bool registered =
false;
95#ifdef HAVE_KSECRETSSERVICE
96 qDBusRegisterMetaType<KSecretsService::StringStringMap>();
97 qDBusRegisterMetaType<StringToStringStringMapMap>();
99 qDBusRegisterMetaType<StringByteArrayMap>();
104bool Wallet::isUsingKSecretsService()
106 return walletLauncher->m_useKSecretsService;
109const QString Wallet::LocalWallet() {
112 if (!cfg.
readEntry(
"Use One Wallet",
true)) {
113 QString tmp = cfg.
readEntry(
"Local Wallet",
"localwallet");
115 return "localwallet";
120 QString tmp = cfg.
readEntry(
"Default Wallet",
"kdewallet");
127const QString Wallet::NetworkWallet() {
131 QString tmp = cfg.
readEntry(
"Default Wallet",
"kdewallet");
138const QString Wallet::PasswordFolder() {
142const QString Wallet::FormDataFolder() {
146class Wallet::WalletPrivate
149 WalletPrivate(
Wallet *wallet,
int h,
const QString &n)
150 : q(wallet), name(n), handle(h)
151#ifdef HAVE_KSECRETSSERVICE
152 , secretsCollection(0)
156 void walletServiceUnregistered();
158#ifdef HAVE_KSECRETSSERVICE
159 template <
typename T>
160 int writeEntry(
const QString& key,
const T &value, Wallet::EntryType entryType ) {
162 KSecretsService::Secret secret;
163 secret.setValue( QVariant::fromValue<T>(value) );
165 KSecretsService::StringStringMap attrs;
168 KSecretsService::CreateCollectionItemJob *createItemJob = secretsCollection->createItem( key, attrs, secret );
170 if ( !createItemJob->exec() ) {
171 kDebug(285) <<
"Cannot execute CreateCollectionItemJob : " << createItemJob->errorString();
173 rc = createItemJob->error();
177 QExplicitlySharedDataPointer<KSecretsService::SecretItem> findItem(
const QString& key )
const;
178 template <
typename T>
int readEntry(
const QString& key, T& value )
const;
179 bool readSecret(
const QString& key, KSecretsService::Secret& value )
const;
181 template <
typename V>
182 int forEachItemThatMatches(
const QString &key, V verb ) {
184 KSecretsService::StringStringMap attrs;
186 KSecretsService::SearchCollectionItemsJob *searchItemsJob = secretsCollection->searchItems(attrs);
187 if ( searchItemsJob->exec() ) {
188 QRegExp re(key, Qt::CaseSensitive, QRegExp::Wildcard);
189 foreach( KSecretsService::SearchCollectionItemsJob::Item item , searchItemsJob->items() ) {
190 KSecretsService::ReadItemPropertyJob *readLabelJob = item->label();
191 if ( readLabelJob->exec() ) {
192 QString
label = readLabelJob->propertyValue().toString();
193 if ( re.exactMatch( label ) ) {
194 if ( verb(
this, label, item.data() ) ) {
200 kDebug(285) <<
"Cannot execute ReadItemPropertyJob " << readLabelJob->errorString();
205 kDebug(285) <<
"Cannot execute KSecretsService::SearchCollectionItemsJob " << searchItemsJob->errorString();
210 void createDefaultFolders();
212 struct InsertIntoEntryList;
213 struct InsertIntoMapList;
214 struct InsertIntoPasswordList;
216 KSecretsService::Collection *secretsCollection;
226#ifdef HAVE_KSECRETSSERVICE
227void Wallet::WalletPrivate::createDefaultFolders()
232 QString strDummy(
"");
233 folder = PasswordFolder();
236 folder = FormDataFolder();
243Wallet::Wallet(
int handle,
const QString& name)
244 :
QObject(0L), d(new WalletPrivate(this, handle, name))
246 if (walletLauncher->m_useKSecretsService) {
250 QDBusServiceWatcher *watcher =
new QDBusServiceWatcher(QString::fromLatin1(
s_kwalletdServiceName), QDBusConnection::sessionBus(),
251 QDBusServiceWatcher::WatchForUnregistration,
this);
252 connect(watcher, SIGNAL(serviceUnregistered(QString)),
253 this, SLOT(walletServiceUnregistered()));
255 connect(&walletLauncher->getInterface(), SIGNAL(
walletClosed(
int)), SLOT(slotWalletClosed(
int)));
256 connect(&walletLauncher->getInterface(), SIGNAL(
folderListUpdated(QString)), SLOT(slotFolderListUpdated(QString)));
257 connect(&walletLauncher->getInterface(), SIGNAL(
folderUpdated(QString,QString)), SLOT(slotFolderUpdated(QString,QString)));
258 connect(&walletLauncher->getInterface(), SIGNAL(applicationDisconnected(QString,QString)), SLOT(slotApplicationDisconnected(QString,QString)));
261 if (d->handle != -1) {
262 QDBusReply<bool> r = walletLauncher->getInterface().isOpen(d->handle);
263 if (r.isValid() && !r) {
273#ifdef HAVE_KSECRETSSERVICE
274 if (walletLauncher->m_useKSecretsService) {
277 delete d->secretsCollection;
281 if (d->handle != -1) {
282 if (!walletLauncher.isDestroyed()) {
283 walletLauncher->getInterface().close(d->handle,
false,
appid());
285 kDebug(285) <<
"Problem with static destruction sequence."
286 "Destroy any static Wallet before the event-loop exits.";
292#ifdef HAVE_KSECRETSSERVICE
301#ifdef HAVE_KSECRETSSERVICE
302 if (walletLauncher->m_useKSecretsService) {
303 KSecretsService::ListCollectionsJob *listJob = KSecretsService::Collection::listCollections();
304 if ( listJob->exec() ) {
305 result = listJob->collections();
308 kDebug(285) <<
"Cannot execute ListCollectionsJob: " << listJob->errorString();
313 QDBusReply<QStringList> r = walletLauncher->getInterface().wallets();
317 kDebug(285) <<
"Invalid DBus reply: " << r.error();
321#ifdef HAVE_KSECRETSSERVICE
330 kDebug(285) <<
"Pass a valid window to KWallet::Wallet::changePassword().";
334#ifdef HAVE_KSECRETSSERVICE
335 if (walletLauncher->m_useKSecretsService) {
336 KSecretsService::Collection *coll = KSecretsService::Collection::findCollection( name );
337 KSecretsService::ChangeCollectionPasswordJob* changePwdJob = coll->changePassword();
338 if ( !changePwdJob->exec() ) {
339 kDebug(285) <<
"Cannot execute change password job: " << changePwdJob->errorString();
345 walletLauncher->getInterface().changePassword(name, (qlonglong)w,
appid());
346#ifdef HAVE_KSECRETSSERVICE
353#ifdef HAVE_KSECRETSSERVICE
354 if (walletLauncher->m_useKSecretsService) {
355 return walletLauncher->m_cgroup.readEntry(
"Enabled",
true);
359 QDBusReply<bool> r = walletLauncher->getInterface().isEnabled();
363 kDebug(285) <<
"Invalid DBus reply: " << r.error();
368#ifdef HAVE_KSECRETSSERVICE
375#ifdef HAVE_KSECRETSSERVICE
376 if (walletLauncher->m_useKSecretsService) {
377 KSecretsService::Collection *coll = KSecretsService::Collection::findCollection( name, KSecretsService::Collection::OpenOnly );
378 KSecretsService::ReadCollectionPropertyJob *readLocked = coll->isLocked();
379 if ( readLocked->exec() ) {
380 return !readLocked->propertyValue().toBool();
383 kDebug() <<
"ReadLocked job failed";
389 QDBusReply<bool> r = walletLauncher->getInterface().isOpen(name);
393 kDebug(285) <<
"Invalid DBus reply: " << r.error();
398#ifdef HAVE_KSECRETSSERVICE
404#ifdef HAVE_KSECRETSSERVICE
405 if (walletLauncher->m_useKSecretsService) {
406 kDebug(285) <<
"Wallet::closeWallet NOOP";
411 QDBusReply<int> r = walletLauncher->getInterface().close(name, force);
415 kDebug(285) <<
"Invalid DBus reply: " << r.error();
420#ifdef HAVE_KSECRETSSERVICE
427#ifdef HAVE_KSECRETSSERVICE
428 if (walletLauncher->m_useKSecretsService) {
429 KSecretsService::Collection *coll = KSecretsService::Collection::findCollection(name, KSecretsService::Collection::OpenOnly);
430 KJob *deleteJob = coll->deleteCollection();
431 if (!deleteJob->
exec()) {
434 return deleteJob->
error();
438 QDBusReply<int> r = walletLauncher->getInterface().deleteWallet(name);
442 kDebug(285) <<
"Invalid DBus reply: " << r.error();
447#ifdef HAVE_KSECRETSSERVICE
454 kDebug(285) <<
"Pass a valid window to KWallet::Wallet::openWallet().";
456#ifdef HAVE_KSECRETSSERVICE
457 if (walletLauncher->m_useKSecretsService) {
460 wallet->d->secretsCollection = KSecretsService::Collection::findCollection(name, KSecretsService::Collection::CreateCollection, QVariantMap(), w);
461 connect( wallet->d->secretsCollection, SIGNAL(statusChanged(
int)), wallet, SLOT(slotCollectionStatusChanged(
int)) );
462 connect( wallet->d->secretsCollection, SIGNAL(deleted()), wallet, SLOT(slotCollectionDeleted()) );
464 kDebug() <<
"WARNING openWallet OpenType=Synchronous requested";
476 connect(&walletLauncher->getInterface(), SIGNAL(walletAsyncOpened(
int,
int)),
477 wallet, SLOT(walletAsyncOpened(
int,
int)));
482 org::kde::KWallet &
interface = walletLauncher->getInterface();
487 interface.setTimeout(0x7FFFFFFF);
488 r = interface.open(name, (qlonglong)w,
appid());
489 interface.setTimeout(-1);
494 r = interface.openAsync(name, (qlonglong)w,
appid(),
true);
495 }
else if (ot ==
Path) {
496 r = interface.openPathAsync(name, (qlonglong)w,
appid(),
true);
503 kDebug(285) <<
"Invalid DBus reply: " << r.error();
507 wallet->d->transactionId = r.value();
511 if (wallet->d->transactionId < 0) {
515 wallet->d->handle = r.value();
518 if (wallet->d->transactionId < 0) {
519 QTimer::singleShot(0, wallet, SLOT(emitWalletAsyncOpenError()));
525#ifdef HAVE_KSECRETSSERVICE
530void Wallet::slotCollectionStatusChanged(
int status)
532#ifdef HAVE_KSECRETSSERVICE
533 KSecretsService::Collection::Status collStatus = (KSecretsService::Collection::Status)status;
534 switch ( collStatus ) {
535 case KSecretsService::Collection::NewlyCreated:
536 d->createDefaultFolders();
538 case KSecretsService::Collection::FoundExisting:
541 case KSecretsService::Collection::Deleted:
542 case KSecretsService::Collection::Invalid:
543 case KSecretsService::Collection::Pending:
546 case KSecretsService::Collection::NotFound:
547 emitWalletAsyncOpenError();
553void Wallet::slotCollectionDeleted()
561#ifdef HAVE_KSECRETSSERVICE
562 if (walletLauncher->m_useKSecretsService) {
563 kDebug() <<
"Wallet::disconnectApplication NOOP";
568 QDBusReply<bool> r = walletLauncher->getInterface().disconnectApplication(wallet, app);
572 kDebug(285) <<
"Invalid DBus reply: " << r.error();
577#ifdef HAVE_KSECRETSSERVICE
584#ifdef HAVE_KSECRETSSERVICE
585 if (walletLauncher->m_useKSecretsService) {
586 kDebug() <<
"KSecretsService does not handle users list";
587 return QStringList();
591 QDBusReply<QStringList> r = walletLauncher->getInterface().users(name);
594 kDebug(285) <<
"Invalid DBus reply: " << r.error();
595 return QStringList();
599#ifdef HAVE_KSECRETSSERVICE
606#ifdef HAVE_KSECRETSSERVICE
607 if (walletLauncher->m_useKSecretsService) {
612 if (d->handle == -1) {
616 walletLauncher->getInterface().sync(d->handle,
appid());
617#ifdef HAVE_KSECRETSSERVICE
625#ifdef HAVE_KSECRETSSERVICE
626 if (walletLauncher->m_useKSecretsService) {
627 KSecretsService::CollectionLockJob *lockJob = d->secretsCollection->lock();
628 if (lockJob->exec()) {
633 kDebug(285) <<
"Cannot execute KSecretsService::CollectionLockJob : " << lockJob->errorString();
636 return lockJob->error();
640 if (d->handle == -1) {
644 QDBusReply<int> r = walletLauncher->getInterface().close(d->handle,
true,
appid());
652 kDebug(285) <<
"Invalid DBus reply: " << r.error();
655#ifdef HAVE_KSECRETSSERVICE
667#ifdef HAVE_KSECRETSSERVICE
668 if (walletLauncher->m_useKSecretsService) {
669 return !d->secretsCollection->isLocked();
673 return d->handle != -1;
674#ifdef HAVE_KSECRETSSERVICE
682 kDebug(285) <<
"Pass a valid window to KWallet::Wallet::requestChangePassword().";
684#ifdef HAVE_KSECRETSSERVICE
685 if (walletLauncher->m_useKSecretsService) {
686 KSecretsService::ChangeCollectionPasswordJob *changePwdJob = d->secretsCollection->changePassword();
687 if (!changePwdJob->exec()) {
688 kDebug(285) <<
"Cannot execute ChangeCollectionPasswordJob : " << changePwdJob->errorString();
693 if (d->handle == -1) {
700 walletLauncher->getInterface().changePassword(d->name, (qlonglong)w,
appid());
701#ifdef HAVE_KSECRETSSERVICE
707void Wallet::slotWalletClosed(
int handle) {
708#ifdef HAVE_KSECRETSSERVICE
709 if (walletLauncher->m_useKSecretsService) {
715 if (d->handle == handle) {
721#ifdef HAVE_KSECRETSSERVICE
728#ifdef HAVE_KSECRETSSERVICE
729 if (walletLauncher->m_useKSecretsService) {
732 KSecretsService::StringStringMap attrs;
734 KSecretsService::SearchCollectionItemsJob *searchJob = d->secretsCollection->searchItems(attrs);
736 if (searchJob->exec()) {
737 KSecretsService::ReadCollectionItemsJob::ItemList itemList = searchJob->items();
738 foreach(
const KSecretsService::ReadCollectionItemsJob::Item &item, itemList ) {
739 KSecretsService::ReadItemPropertyJob *readAttrsJob = item->attributes();
740 if (readAttrsJob->exec()) {
741 KSecretsService::StringStringMap attrs = readAttrsJob->propertyValue().value<KSecretsService::StringStringMap>();
743 if (!folder.isEmpty() && !result.contains(folder)) {
744 result.append(folder);
748 kDebug(285) <<
"Cannot read item attributes : " << readAttrsJob->errorString();
753 kDebug(285) <<
"Cannot execute ReadCollectionItemsJob : " << searchJob->errorString();
759 if (d->handle == -1) {
760 return QStringList();
763 QDBusReply<QStringList> r = walletLauncher->getInterface().folderList(d->handle,
appid());
766 kDebug(285) <<
"Invalid DBus reply: " << r.error();
767 return QStringList();
771#ifdef HAVE_KSECRETSSERVICE
778#ifdef HAVE_KSECRETSSERVICE
779 if (walletLauncher->m_useKSecretsService) {
781 KSecretsService::StringStringMap attrs;
783 KSecretsService::SearchCollectionItemsJob *readItemsJob = d->secretsCollection->searchItems( attrs );
784 if ( readItemsJob->exec() ) {
785 foreach( KSecretsService::SearchCollectionItemsJob::Item item, readItemsJob->items() ) {
786 KSecretsService::ReadItemPropertyJob *readLabelJob = item->label();
787 if ( readLabelJob->exec() ) {
788 result.append( readLabelJob->propertyValue().toString() );
791 kDebug(285) <<
"Cannot execute readLabelJob" << readItemsJob->errorString();
796 kDebug(285) <<
"Cannot execute readItemsJob" << readItemsJob->errorString();
802 if (d->handle == -1) {
803 return QStringList();
806 QDBusReply<QStringList> r = walletLauncher->getInterface().entryList(d->handle, d->folder,
appid());
809 kDebug(285) <<
"Invalid DBus reply: " << r.error();
810 return QStringList();
814#ifdef HAVE_KSECRETSSERVICE
821#ifdef HAVE_KSECRETSSERVICE
822 if (walletLauncher->m_useKSecretsService) {
827 return folders.contains(f);
831 if (d->handle == -1) {
835 QDBusReply<bool> r = walletLauncher->getInterface().hasFolder(d->handle, f,
appid());
838 kDebug(285) <<
"Invalid DBus reply: " << r.error();
843#ifdef HAVE_KSECRETSSERVICE
850#ifdef HAVE_KSECRETSSERVICE
851 if (walletLauncher->m_useKSecretsService) {
852 QString strDummy(
"");
859 if (d->handle == -1) {
864 QDBusReply<bool> r = walletLauncher->getInterface().createFolder(d->handle, f,
appid());
868 kDebug(285) <<
"Invalid DBus reply: " << r.error();
876#ifdef HAVE_KSECRETSSERVICE
885#ifdef HAVE_KSECRETSSERVICE
886 if (walletLauncher->m_useKSecretsService) {
894 if (d->handle == -1) {
900 if (f == d->folder) {
909#ifdef HAVE_KSECRETSSERVICE
918#ifdef HAVE_KSECRETSSERVICE
919 if (walletLauncher->m_useKSecretsService) {
922 KSecretsService::StringStringMap attrs;
924 KSecretsService::SearchCollectionItemsJob *searchJob = d->secretsCollection->searchItems(attrs);
925 if (searchJob->exec()) {
926 KSecretsService::SearchCollectionItemsJob::ItemList itemList = searchJob->items();
927 if ( !itemList.isEmpty() ) {
929 foreach(
const KSecretsService::SearchCollectionItemsJob::Item &item, itemList ) {
930 KSecretsService::SecretItemDeleteJob *deleteJob = item->deleteItem();
931 if (!deleteJob->exec()) {
932 kDebug(285) <<
"Cannot delete item : " << deleteJob->errorString();
940 kDebug(285) <<
"Cannot execute KSecretsService::SearchCollectionItemsJob : " << searchJob->errorString();
946 if (d->handle == -1) {
950 QDBusReply<bool> r = walletLauncher->getInterface().removeFolder(d->handle, f,
appid());
951 if (d->folder == f) {
957 kDebug(285) <<
"Invalid DBus reply: " << r.error();
962#ifdef HAVE_KSECRETSSERVICE
972#ifdef HAVE_KSECRETSSERVICE
973QExplicitlySharedDataPointer<KSecretsService::SecretItem> Wallet::WalletPrivate::findItem(
const QString& key )
const
975 QExplicitlySharedDataPointer<KSecretsService::SecretItem> result;
976 KSecretsService::StringStringMap attrs;
978 attrs[
"Label"] = key;
979 KSecretsService::SearchCollectionItemsJob *searchJob = secretsCollection->searchItems(attrs);
980 if (searchJob->exec()) {
981 KSecretsService::SearchCollectionItemsJob::ItemList itemList = searchJob->items();
982 if ( !itemList.isEmpty() ) {
983 result = itemList.first();
986 kDebug(285) <<
"entry named " << key <<
" not found in folder " << folder;
990 kDebug(285) <<
"Cannot exec KSecretsService::SearchCollectionItemsJob : " << searchJob->errorString();
997int Wallet::WalletPrivate::readEntry(
const QString& key, T& value)
const
1000 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = findItem(key);
1002 KSecretsService::GetSecretItemSecretJob *readJob = item->getSecret();
1003 if ( readJob->exec() ) {
1004 KSecretsService::Secret theSecret = readJob->secret();
1005 kDebug(285) <<
"Secret contentType is " << theSecret.contentType();
1006 value = theSecret.value().value<
T>();
1010 kDebug(285) <<
"Cannot exec GetSecretItemSecretJob : " << readJob->errorString();
1016bool Wallet::WalletPrivate::readSecret(
const QString& key, KSecretsService::Secret& value)
const
1018 bool result =
false;
1019 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = findItem(key);
1021 KSecretsService::GetSecretItemSecretJob *readJob = item->getSecret();
1022 if ( readJob->exec() ) {
1023 value = readJob->secret();
1027 kDebug(285) <<
"Cannot exec GetSecretItemSecretJob : " << readJob->errorString();
1037#ifdef HAVE_KSECRETSSERVICE
1038 if (walletLauncher->m_useKSecretsService) {
1039 return d->readEntry<QByteArray>(key, value);
1043 if (d->handle == -1) {
1047 QDBusReply<QByteArray> r = walletLauncher->getInterface().readEntry(d->handle, d->folder, key,
appid());
1052#ifdef HAVE_KSECRETSSERVICE
1059#ifdef HAVE_KSECRETSSERVICE
1060struct Wallet::WalletPrivate::InsertIntoEntryList {
1062 bool operator() ( Wallet::WalletPrivate*,
const QString& label, KSecretsService::SecretItem* item ) {
1063 bool result =
false;
1064 KSecretsService::GetSecretItemSecretJob *readSecretJob = item->getSecret();
1065 if ( readSecretJob->exec() ) {
1066 _value.insert( label, readSecretJob->secret().value().toByteArray() );
1070 kDebug(285) <<
"Cannot execute GetSecretItemSecretJob " << readSecretJob->errorString();
1082#ifdef HAVE_KSECRETSSERVICE
1083 if (walletLauncher->m_useKSecretsService) {
1084 rc = d->forEachItemThatMatches( key, WalletPrivate::InsertIntoEntryList( value ) );
1090 if (d->handle == -1) {
1094 QDBusReply<QVariantMap> r = walletLauncher->getInterface().readEntryList(d->handle, d->folder, key,
appid());
1098 const QVariantMap val = r.value();
1099 for( QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it ) {
1100 value.insert(it.key(), it.value().toByteArray());
1103#ifdef HAVE_KSECRETSSERVICE
1114#ifdef HAVE_KSECRETSSERVICE
1115 if (walletLauncher->m_useKSecretsService) {
1116 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = d->findItem(oldName);
1118 KSecretsService::WriteItemPropertyJob *writeJob = item->setLabel(newName);
1119 if (!writeJob->exec()) {
1120 kDebug(285) <<
"Cannot exec WriteItemPropertyJob : " << writeJob->errorString();
1122 rc = writeJob->error();
1125 kDebug(285) <<
"Cannot locate item " << oldName <<
" in folder " << d->folder;
1130 if (d->handle == -1) {
1134 QDBusReply<int> r = walletLauncher->getInterface().renameEntry(d->handle, d->folder, oldName, newName,
appid());
1138#ifdef HAVE_KSECRETSSERVICE
1149#ifdef HAVE_KSECRETSSERVICE
1150 if (walletLauncher->m_useKSecretsService) {
1152 rc = d->readEntry< QByteArray >(key, ba);
1153 if ( rc == 0 && !ba.isEmpty()){
1154 QDataStream ds( &ba, QIODevice::ReadOnly );
1162 if (d->handle == -1) {
1166 QDBusReply<QByteArray> r = walletLauncher->getInterface().readMap(d->handle, d->folder, key,
appid());
1171 QDataStream ds(&v, QIODevice::ReadOnly);
1175#ifdef HAVE_KSECRETSSERVICE
1182#ifdef HAVE_KSECRETSSERVICE
1183struct Wallet::WalletPrivate::InsertIntoMapList {
1185 bool operator() ( Wallet::WalletPrivate* d,
const QString& label, KSecretsService::SecretItem* ) {
1186 bool result =
false;
1189 _value.insert( label, map );
1201#ifdef HAVE_KSECRETSSERVICE
1202 if (walletLauncher->m_useKSecretsService) {
1203 rc = d->forEachItemThatMatches( key, WalletPrivate::InsertIntoMapList( value ) );
1209 if (d->handle == -1) {
1213 QDBusReply<QVariantMap> r =
1214 walletLauncher->getInterface().readMapList(d->handle, d->folder, key,
appid());
1217 const QVariantMap val = r.value();
1218 for( QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it ) {
1219 QByteArray mapData = it.value().toByteArray();
1220 if (!mapData.isEmpty()) {
1221 QDataStream ds(&mapData, QIODevice::ReadOnly);
1224 value.insert(it.key(), v);
1228#ifdef HAVE_KSECRETSSERVICE
1239#ifdef HAVE_KSECRETSSERVICE
1240 if (walletLauncher->m_useKSecretsService) {
1241 rc = d->readEntry<QString>(key, value);
1245 if (d->handle == -1) {
1249 QDBusReply<QString> r = walletLauncher->getInterface().readPassword(d->handle, d->folder, key,
appid());
1254#ifdef HAVE_KSECRETSSERVICE
1261#ifdef HAVE_KSECRETSSERVICE
1262struct Wallet::WalletPrivate::InsertIntoPasswordList {
1264 bool operator() ( Wallet::WalletPrivate* d,
const QString& label, KSecretsService::SecretItem* ) {
1265 bool result =
false;
1267 if ( d->readEntry<QString>( label, pwd ) == 0 ) {
1268 _value.insert( label, pwd );
1280#ifdef HAVE_KSECRETSSERVICE
1281 if (walletLauncher->m_useKSecretsService) {
1282 rc = d->forEachItemThatMatches( key, WalletPrivate::InsertIntoPasswordList( value ) );
1288 if (d->handle == -1) {
1292 QDBusReply<QVariantMap> r = walletLauncher->getInterface().readPasswordList(d->handle, d->folder, key,
appid());
1295 const QVariantMap val = r.value();
1296 for( QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it ) {
1297 value.insert(it.key(), it.value().toString());
1300#ifdef HAVE_KSECRETSSERVICE
1311#ifdef HAVE_KSECRETSSERVICE
1312 if (walletLauncher->m_useKSecretsService) {
1313 rc = d->writeEntry( key, value,
entryType );
1317 if (d->handle == -1) {
1321 QDBusReply<int> r = walletLauncher->getInterface().writeEntry(d->handle, d->folder, key, value,
int(
entryType),
appid());
1325#ifdef HAVE_KSECRETSSERVICE
1336#ifdef HAVE_KSECRETSSERVICE
1337 if (walletLauncher->m_useKSecretsService) {
1342 if (d->handle == -1) {
1346 QDBusReply<int> r = walletLauncher->getInterface().writeEntry(d->handle, d->folder, key, value,
appid());
1350#ifdef HAVE_KSECRETSSERVICE
1361#ifdef HAVE_KSECRETSSERVICE
1362 if (walletLauncher->m_useKSecretsService) {
1363 d->writeEntry( key, value,
Map );
1369 if (d->handle == -1) {
1374 QDataStream ds(&mapData, QIODevice::WriteOnly);
1376 QDBusReply<int> r = walletLauncher->getInterface().writeMap(d->handle, d->folder, key, mapData,
appid());
1380#ifdef HAVE_KSECRETSSERVICE
1391#ifdef HAVE_KSECRETSSERVICE
1392 if (walletLauncher->m_useKSecretsService) {
1393 rc = d->writeEntry( key, value,
Password );
1397 if (d->handle == -1) {
1401 QDBusReply<int> r = walletLauncher->getInterface().writePassword(d->handle, d->folder, key, value,
appid());
1405#ifdef HAVE_KSECRETSSERVICE
1414#ifdef HAVE_KSECRETSSERVICE
1415 if (walletLauncher->m_useKSecretsService) {
1416 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = d->findItem( key );
1421 if (d->handle == -1) {
1425 QDBusReply<bool> r = walletLauncher->getInterface().hasEntry(d->handle, d->folder, key,
appid());
1428 kDebug(285) <<
"Invalid DBus reply: " << r.error();
1433#ifdef HAVE_KSECRETSSERVICE
1442#ifdef HAVE_KSECRETSSERVICE
1443 if (walletLauncher->m_useKSecretsService) {
1444 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = d->findItem( key );
1446 KSecretsService::SecretItemDeleteJob *deleteJob = item->deleteItem();
1447 if ( !deleteJob->exec() ) {
1448 kDebug(285) <<
"Cannot execute SecretItemDeleteJob " << deleteJob->errorString();
1450 rc = deleteJob->error();
1455 if (d->handle == -1) {
1459 QDBusReply<int> r = walletLauncher->getInterface().removeEntry(d->handle, d->folder, key,
appid());
1463#ifdef HAVE_KSECRETSSERVICE
1474#ifdef HAVE_KSECRETSSERVICE
1475 if (walletLauncher->m_useKSecretsService) {
1476 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = d->findItem( key );
1478 KSecretsService::ReadItemPropertyJob *readAttrsJob = item->attributes();
1479 if ( readAttrsJob->exec() ) {
1480 KSecretsService::StringStringMap attrs = readAttrsJob->propertyValue().value<KSecretsService::StringStringMap>();
1492 kDebug(285) <<
"Cannot execute GetSecretItemSecretJob " << readAttrsJob->errorString();
1498 if (d->handle == -1) {
1502 QDBusReply<int> r = walletLauncher->getInterface().entryType(d->handle, d->folder, key,
appid());
1506#ifdef HAVE_KSECRETSSERVICE
1513void Wallet::WalletPrivate::walletServiceUnregistered()
1516 q->slotWalletClosed(handle);
1520void Wallet::slotFolderUpdated(
const QString& wallet,
const QString& folder) {
1521#ifdef HAVE_KSECRETSSERVICE
1522 if (walletLauncher->m_useKSecretsService) {
1528 if (d->name == wallet) {
1531#ifdef HAVE_KSECRETSSERVICE
1537void Wallet::slotFolderListUpdated(
const QString& wallet) {
1538#ifdef HAVE_KSECRETSSERVICE
1539 if (walletLauncher->m_useKSecretsService) {
1545 if (d->name == wallet) {
1548#ifdef HAVE_KSECRETSSERVICE
1554void Wallet::slotApplicationDisconnected(
const QString& wallet,
const QString& application) {
1555#ifdef HAVE_KSECRETSSERVICE
1556 if (walletLauncher->m_useKSecretsService) {
1563 && d->name == wallet
1564 && application ==
appid()) {
1565 slotWalletClosed(d->handle);
1567#ifdef HAVE_KSECRETSSERVICE
1572void Wallet::walletAsyncOpened(
int tId,
int handle) {
1573#ifdef HAVE_KSECRETSSERVICE
1574 if (walletLauncher->m_useKSecretsService) {
1581 if (d->transactionId != tId || d->handle != -1) {
1586 disconnect(
this, SLOT(walletAsyncOpened(
int,
int)));
1590#ifdef HAVE_KSECRETSSERVICE
1595void Wallet::emitWalletAsyncOpenError() {
1599void Wallet::emitWalletOpened() {
1605#ifdef HAVE_KSECRETSSERVICE
1606 if (walletLauncher->m_useKSecretsService) {
1607 kDebug(285) <<
"WARNING: changing semantics of folderDoesNotExist with KSS: will prompt for the password";
1618 QDBusReply<bool> r = walletLauncher->getInterface().folderDoesNotExist(wallet, folder);
1621 kDebug(285) <<
"Invalid DBus reply: " << r.error();
1626#ifdef HAVE_KSECRETSSERVICE
1634#ifdef HAVE_KSECRETSSERVICE
1635 if (walletLauncher->m_useKSecretsService) {
1636 kDebug(285) <<
"WARNING: changing semantics of keyDoesNotExist with KSS: will prompt for the password";
1645 QDBusReply<bool> r = walletLauncher->getInterface().keyDoesNotExist(wallet, folder, key);
1648 kDebug(285) <<
"Invalid DBus reply: " << r.error();
1653#ifdef HAVE_KSECRETSSERVICE
1663KWalletDLauncher::KWalletDLauncher()
1667 m_useKSecretsService = m_cgroup.readEntry(
"UseKSecretsService",
false);
1668#ifdef HAVE_KSECRETSSERVICE
1669 if (m_useKSecretsService) {
1674 m_wallet =
new org::kde::KWallet(QString::fromLatin1(
s_kwalletdServiceName),
"/modules/kwalletd", QDBusConnection::sessionBus());
1675#ifdef HAVE_KSECRETSSERVICE
1680KWalletDLauncher::~KWalletDLauncher()
1685org::kde::KWallet &KWalletDLauncher::getInterface()
1688 Q_ASSERT(m_wallet != 0);
1691 if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QString::fromLatin1(
s_kwalletdServiceName)))
1694 bool walletEnabled = m_cgroup.readEntry(
"Enabled",
true);
1695 if (walletEnabled) {
1701 kError(285) <<
"Couldn't start kwalletd: " << error << endl;
1705 (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QString::fromLatin1(
s_kwalletdServiceName))) {
1706 kDebug(285) <<
"The kwalletd service is still not registered";
1708 kDebug(285) <<
"The kwalletd service has been registered";
1711 kError(285) <<
"The kwalletd service has been disabled";
1720#include "kwallet.moc"
QString programName() const
QString componentName() const
const KAboutData * aboutData() const
QString readEntry(const char *key, const char *aDefault=0) const
virtual QString errorString() const
static KSharedConfig::Ptr openConfig(const KComponentData &componentData, const QString &fileName=QString(), OpenFlags mode=FullConfig, const char *resourceType="config")
int readEntryList(const QString &key, QMap< QString, QByteArray > &value)
Read the entries matching key from the current folder.
virtual void virtual_hook(int id, void *data)
virtual int renameEntry(const QString &oldName, const QString &newName)
Rename the entry oldName to newName.
virtual int sync()
This syncs the wallet file on disk with what is in memory.
virtual bool createFolder(const QString &f)
Created the folder f.
virtual int lockWallet()
This closes and locks the current wallet.
static QStringList users(const QString &wallet)
List the applications that are using the wallet wallet.
virtual int removeEntry(const QString &key)
Remove the entry key from the current folder.
void folderUpdated(const QString &folder)
Emitted when a folder in this wallet is updated.
static int closeWallet(const QString &name, bool force)
Close the wallet name.
virtual bool hasEntry(const QString &key)
Determine if the current folder has they entry key.
virtual QStringList folderList()
Obtain the list of all folders contained in the wallet.
virtual ~Wallet()
Destroy a KWallet object.
static QStringList walletList()
List all the wallets available.
virtual bool isOpen() const
Determine if the current wallet is open, and is a valid wallet handle.
virtual const QString & currentFolder() const
Determine the current working folder in the wallet.
void walletClosed()
Emitted when this wallet is closed.
static int deleteWallet(const QString &name)
Delete the wallet name.
void folderListUpdated()
Emitted when the folder list is changed in this wallet.
virtual int writeEntry(const QString &key, const QByteArray &value, EntryType entryType)
Write key = value as a binary entry to the current folder.
int readPasswordList(const QString &key, QMap< QString, QString > &value)
Read the password entry key from the current folder.
virtual bool hasFolder(const QString &f)
Determine if the folder f exists in the wallet.
static void changePassword(const QString &name, WId w)
Request to the wallet service to change the password of the wallet name.
virtual int readEntry(const QString &key, QByteArray &value)
Read the entry key from the current folder.
virtual QStringList entryList()
Return the list of keys of all entries in this folder.
int readMapList(const QString &key, QMap< QString, QMap< QString, QString > > &value)
Read the map entry key from the current folder.
virtual int readMap(const QString &key, QMap< QString, QString > &value)
Read the map entry key from the current folder.
virtual void requestChangePassword(WId w)
Request to the wallet service to change the password of the current wallet.
static bool isEnabled()
Determine if the KDE wallet is enabled.
static bool disconnectApplication(const QString &wallet, const QString &app)
Disconnect the application app from wallet.
virtual bool removeFolder(const QString &f)
Remove the folder f and all its entries from the wallet.
static bool folderDoesNotExist(const QString &wallet, const QString &folder)
Determine if a folder does not exist in a wallet.
virtual EntryType entryType(const QString &key)
Determine the type of the entry key in this folder.
virtual int readPassword(const QString &key, QString &value)
Read the password entry key from the current folder.
static Wallet * openWallet(const QString &name, WId w, OpenType ot=Synchronous)
Open the wallet name.
virtual int writePassword(const QString &key, const QString &value)
Write key = value as a password to the current folder.
virtual const QString & walletName() const
The name of the current wallet.
virtual bool setFolder(const QString &f)
Set the current working folder to f.
void walletOpened(bool success)
Emitted when a wallet is opened in asynchronous mode.
static bool keyDoesNotExist(const QString &wallet, const QString &folder, const QString &key)
Determine if an entry in a folder does not exist in a wallet.
virtual int writeMap(const QString &key, const QMap< QString, QString > &value)
Write key = value as a map to the current folder.
static void allowExternalProcessWindowActivation(int pid=-1)
Allows a window from another process to raise and activate itself.
#define K_GLOBAL_STATIC(TYPE, NAME)
KAutostart::StartPhase readEntry(const KConfigGroup &group, const char *key, const KAutostart::StartPhase &aDefault)
QMap< QString, QByteArray > StringByteArrayMap
#define KSS_ATTR_WALLETTYPE
#define KSS_ATTR_ENTRYFOLDER
NOTE: KSecretsService folder semantics The KWallet API uses folders for organising items.
QMap< QString, StringStringMap > StringToStringStringMapMap
const KComponentData & mainComponent()
QString label(StandardShortcut id)
Returns a localized label for user-visible display.
static void registerTypes()
static const char s_kwalletdServiceName[]