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
This commit is contained in:
Frank Osterfeld 2013-10-12 19:57:48 +02:00
parent 6747027ce7
commit b66a182a85
1 changed files with 26 additions and 1 deletions

View File

@ -319,6 +319,14 @@ void ReadPasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watch
connect( nextWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(kwalletEntryTypeFinished(QDBusPendingCallWatcher*)) ); 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 ) { void ReadPasswordJobPrivate::kwalletEntryTypeFinished( QDBusPendingCallWatcher* watcher ) {
watcher->deleteLater(); watcher->deleteLater();
if ( watcher->isError() ) { if ( watcher->isError() ) {
@ -328,8 +336,25 @@ void ReadPasswordJobPrivate::kwalletEntryTypeFinished( QDBusPendingCallWatcher*
} }
const QDBusPendingReply<int> reply = *watcher; const QDBusPendingReply<int> 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 const QDBusPendingCall nextReply = dataType == Text
? QDBusPendingCall( iface->readPassword( walletHandle, q->service(), key, q->service() ) ) ? QDBusPendingCall( iface->readPassword( walletHandle, q->service(), key, q->service() ) )