From b66a182a85b0fee9b4acc746c90eb128c4033012 Mon Sep 17 00:00:00 2001 From: Frank Osterfeld Date: Sat, 12 Oct 2013 19:57:48 +0200 Subject: [PATCH] KWallet: Return error for non-existant entries Before, an empty password was returned, so one couldn't tell if the entry wasn't available, or the entry contained an empty password. Fixes #5 --- keychain_dbus.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/keychain_dbus.cpp b/keychain_dbus.cpp index 15e0ee1..da523d4 100644 --- a/keychain_dbus.cpp +++ b/keychain_dbus.cpp @@ -319,6 +319,14 @@ void ReadPasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watch connect( nextWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(kwalletEntryTypeFinished(QDBusPendingCallWatcher*)) ); } +//Must be in sync with KWallet::EntryType (kwallet.h) +enum KWalletEntryType { + Unknown=0, + Password, + Stream, + Map +}; + void ReadPasswordJobPrivate::kwalletEntryTypeFinished( QDBusPendingCallWatcher* watcher ) { watcher->deleteLater(); if ( watcher->isError() ) { @@ -328,8 +336,25 @@ void ReadPasswordJobPrivate::kwalletEntryTypeFinished( QDBusPendingCallWatcher* } const QDBusPendingReply reply = *watcher; + const int value = reply.value(); - dataType = reply.value() == 1/*Password*/ ? Text : Binary; + switch ( value ) { + case Unknown: + q->emitFinishedWithError( EntryNotFound, tr("Entry not found") ); + return; + case Password: + dataType = Text; + break; + case Stream: + dataType = Binary; + break; + case Map: + q->emitFinishedWithError( EntryNotFound, tr("Unsupported entry type 'Map'") ); + return; + default: + q->emitFinishedWithError( OtherError, tr("Unknown kwallet entry type '%1'").arg( value ) ); + return; + } const QDBusPendingCall nextReply = dataType == Text ? QDBusPendingCall( iface->readPassword( walletHandle, q->service(), key, q->service() ) )