Merge pull request #13 from xhochy/fix-kwallet-earlier-dbus-fallback
Fallback earlier if D-Bus is not available
This commit is contained in:
commit
dcfebad35d
|
@ -15,10 +15,49 @@
|
||||||
using namespace QKeychain;
|
using namespace QKeychain;
|
||||||
|
|
||||||
void ReadPasswordJobPrivate::scheduledStart() {
|
void ReadPasswordJobPrivate::scheduledStart() {
|
||||||
|
if ( QDBusConnection::sessionBus().isConnected() )
|
||||||
|
{
|
||||||
iface = new org::kde::KWallet( QLatin1String("org.kde.kwalletd"), QLatin1String("/modules/kwalletd"), QDBusConnection::sessionBus(), this );
|
iface = new org::kde::KWallet( QLatin1String("org.kde.kwalletd"), QLatin1String("/modules/kwalletd"), QDBusConnection::sessionBus(), this );
|
||||||
const QDBusPendingReply<int> reply = iface->open( QLatin1String("kdewallet"), 0, q->service() );
|
const QDBusPendingReply<int> reply = iface->open( QLatin1String("kdewallet"), 0, q->service() );
|
||||||
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher( reply, this );
|
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher( reply, this );
|
||||||
connect( watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(kwalletOpenFinished(QDBusPendingCallWatcher*)) );
|
connect( watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(kwalletOpenFinished(QDBusPendingCallWatcher*)) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// D-Bus is not reachable so none can tell us something about KWalletd
|
||||||
|
QDBusError err( QDBusError::NoServer, "D-Bus is not running" );
|
||||||
|
fallbackOnError( err );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReadPasswordJobPrivate::fallbackOnError(const QDBusError& err )
|
||||||
|
{
|
||||||
|
std::auto_ptr<QSettings> local( !q->settings() ? new QSettings( q->service() ) : 0 );
|
||||||
|
QSettings* actual = q->settings() ? q->settings() : local.get();
|
||||||
|
WritePasswordJobPrivate::Mode mode;
|
||||||
|
|
||||||
|
if ( q->insecureFallback() && actual->contains( dataKey() ) ) {
|
||||||
|
|
||||||
|
mode = (WritePasswordJobPrivate::Mode)actual->value( typeKey() ).toInt();
|
||||||
|
data = actual->value( dataKey() ).toByteArray();
|
||||||
|
|
||||||
|
q->emitFinished();
|
||||||
|
} else {
|
||||||
|
if ( err.type() == QDBusError::ServiceUnknown ) //KWalletd not running
|
||||||
|
q->emitFinishedWithError( NoBackendAvailable, tr("No keychain service available") );
|
||||||
|
else
|
||||||
|
q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString ReadPasswordJobPrivate::typeKey()
|
||||||
|
{
|
||||||
|
return QString( "%1/type" ).arg( key );
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString ReadPasswordJobPrivate::dataKey()
|
||||||
|
{
|
||||||
|
return QString( "%1/data" ).arg( key );
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadPasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watcher ) {
|
void ReadPasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watcher ) {
|
||||||
|
@ -29,35 +68,17 @@ void ReadPasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watch
|
||||||
QSettings* actual = q->settings() ? q->settings() : local.get();
|
QSettings* actual = q->settings() ? q->settings() : local.get();
|
||||||
WritePasswordJobPrivate::Mode mode;
|
WritePasswordJobPrivate::Mode mode;
|
||||||
|
|
||||||
const QString typeKey = QString( "%1/type" ).arg( key );
|
|
||||||
const QString dataKey = QString( "%1/data" ).arg( key );
|
|
||||||
if ( reply.isError() ) {
|
if ( reply.isError() ) {
|
||||||
const QDBusError err = reply.error();
|
fallbackOnError( reply.error() );
|
||||||
|
|
||||||
if ( q->insecureFallback() && actual->contains( dataKey ) ) {
|
|
||||||
|
|
||||||
mode = (WritePasswordJobPrivate::Mode)actual->value( typeKey ).toInt();
|
|
||||||
data = actual->value( dataKey ).toByteArray();
|
|
||||||
|
|
||||||
q->emitFinished();
|
|
||||||
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
if ( err.type() == QDBusError::ServiceUnknown ) //KWalletd not running
|
|
||||||
q->emitFinishedWithError( NoBackendAvailable, tr("No keychain service available") );
|
|
||||||
else
|
|
||||||
q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( actual->contains( dataKey ) ) {
|
if ( actual->contains( dataKey() ) ) {
|
||||||
// We previously stored data in the insecure QSettings, but now have KWallet available.
|
// We previously stored data in the insecure QSettings, but now have KWallet available.
|
||||||
// Do the migration
|
// Do the migration
|
||||||
|
|
||||||
data = actual->value( dataKey ).toByteArray();
|
data = actual->value( dataKey() ).toByteArray();
|
||||||
mode = (WritePasswordJobPrivate::Mode)actual->value( typeKey ).toInt();
|
mode = (WritePasswordJobPrivate::Mode)actual->value( typeKey() ).toInt();
|
||||||
actual->remove( key );
|
actual->remove( key );
|
||||||
|
|
||||||
q->emitFinished();
|
q->emitFinished();
|
||||||
|
@ -129,20 +150,26 @@ void ReadPasswordJobPrivate::kwalletReadFinished( QDBusPendingCallWatcher* watch
|
||||||
}
|
}
|
||||||
|
|
||||||
void WritePasswordJobPrivate::scheduledStart() {
|
void WritePasswordJobPrivate::scheduledStart() {
|
||||||
|
if ( QDBusConnection::sessionBus().isConnected() )
|
||||||
|
{
|
||||||
iface = new org::kde::KWallet( QLatin1String("org.kde.kwalletd"), QLatin1String("/modules/kwalletd"), QDBusConnection::sessionBus(), this );
|
iface = new org::kde::KWallet( QLatin1String("org.kde.kwalletd"), QLatin1String("/modules/kwalletd"), QDBusConnection::sessionBus(), this );
|
||||||
const QDBusPendingReply<int> reply = iface->open( QLatin1String("kdewallet"), 0, q->service() );
|
const QDBusPendingReply<int> reply = iface->open( QLatin1String("kdewallet"), 0, q->service() );
|
||||||
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher( reply, this );
|
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher( reply, this );
|
||||||
connect( watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(kwalletOpenFinished(QDBusPendingCallWatcher*)) );
|
connect( watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(kwalletOpenFinished(QDBusPendingCallWatcher*)) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// D-Bus is not reachable so none can tell us something about KWalletd
|
||||||
|
QDBusError err( QDBusError::NoServer, "D-Bus is not running" );
|
||||||
|
fallbackOnError( err );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WritePasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watcher ) {
|
void WritePasswordJobPrivate::fallbackOnError(const QDBusError &err)
|
||||||
watcher->deleteLater();
|
{
|
||||||
QDBusPendingReply<int> reply = *watcher;
|
|
||||||
|
|
||||||
std::auto_ptr<QSettings> local( !q->settings() ? new QSettings( q->service() ) : 0 );
|
std::auto_ptr<QSettings> local( !q->settings() ? new QSettings( q->service() ) : 0 );
|
||||||
QSettings* actual = q->settings() ? q->settings() : local.get();
|
QSettings* actual = q->settings() ? q->settings() : local.get();
|
||||||
|
|
||||||
if ( reply.isError() ) {
|
|
||||||
if ( q->insecureFallback() ) {
|
if ( q->insecureFallback() ) {
|
||||||
if ( mode == Delete ) {
|
if ( mode == Delete ) {
|
||||||
actual->remove( key );
|
actual->remove( key );
|
||||||
|
@ -161,9 +188,19 @@ void WritePasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watc
|
||||||
|
|
||||||
q->emitFinished();
|
q->emitFinished();
|
||||||
} else {
|
} else {
|
||||||
const QDBusError err = reply.error();
|
|
||||||
q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
|
q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WritePasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watcher ) {
|
||||||
|
watcher->deleteLater();
|
||||||
|
QDBusPendingReply<int> reply = *watcher;
|
||||||
|
|
||||||
|
std::auto_ptr<QSettings> local( !q->settings() ? new QSettings( q->service() ) : 0 );
|
||||||
|
QSettings* actual = q->settings() ? q->settings() : local.get();
|
||||||
|
|
||||||
|
if ( reply.isError() ) {
|
||||||
|
fallbackOnError( reply.error() );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,10 @@ public:
|
||||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
|
#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
|
||||||
org::kde::KWallet* iface;
|
org::kde::KWallet* iface;
|
||||||
friend class QKeychain::JobExecutor;
|
friend class QKeychain::JobExecutor;
|
||||||
|
void fallbackOnError(const QDBusError& err);
|
||||||
|
|
||||||
|
const QString typeKey();
|
||||||
|
const QString dataKey();
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void kwalletOpenFinished( QDBusPendingCallWatcher* watcher );
|
void kwalletOpenFinished( QDBusPendingCallWatcher* watcher );
|
||||||
void kwalletEntryTypeFinished( QDBusPendingCallWatcher* watcher );
|
void kwalletEntryTypeFinished( QDBusPendingCallWatcher* watcher );
|
||||||
|
@ -102,7 +105,7 @@ public:
|
||||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
|
#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
|
||||||
org::kde::KWallet* iface;
|
org::kde::KWallet* iface;
|
||||||
friend class QKeychain::JobExecutor;
|
friend class QKeychain::JobExecutor;
|
||||||
|
void fallbackOnError(const QDBusError& err);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void kwalletOpenFinished( QDBusPendingCallWatcher* watcher );
|
void kwalletOpenFinished( QDBusPendingCallWatcher* watcher );
|
||||||
|
|
Loading…
Reference in New Issue