[Pkg-owncloud-commits] [qtkeychain] 43/115: Allow insecure fallback on linux when no kwallet is found
Sandro Knauß
hefee-guest at moszumanska.debian.org
Sat Mar 15 19:25:44 UTC 2014
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository qtkeychain.
commit 89eb6be733f4f4c24e2003cd1cdad79202066926
Author: Leo Franchi <lfranchi at kde.org>
Date: Sat Jun 9 22:11:16 2012 +0200
Allow insecure fallback on linux when no kwallet is found
---
keychain.cpp | 8 +++++
keychain.h | 3 ++
keychain_dbus.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++----
keychain_p.h | 4 ++-
4 files changed, 97 insertions(+), 6 deletions(-)
diff --git a/keychain.cpp b/keychain.cpp
index 1694036..6b4bd61 100644
--- a/keychain.cpp
+++ b/keychain.cpp
@@ -44,6 +44,14 @@ void Job::setAutoDelete( bool autoDelete ) {
d->autoDelete = autoDelete;
}
+bool Job::insecureFallback() const {
+ return d->insecureFallback;
+}
+
+void Job::setInsecureFallback( bool insecureFallback ) {
+ d->insecureFallback = insecureFallback;
+}
+
void Job::emitFinished() {
emit finished( this );
if ( d->autoDelete )
diff --git a/keychain.h b/keychain.h
index 0eab557..dd56d4f 100644
--- a/keychain.h
+++ b/keychain.h
@@ -54,6 +54,9 @@ public:
bool autoDelete() const;
void setAutoDelete( bool autoDelete );
+ bool insecureFallback() const;
+ void setInsecureFallback( bool insecureFallback );
+
Q_SIGNALS:
void finished( QKeychain::Job* );
diff --git a/keychain_dbus.cpp b/keychain_dbus.cpp
index c142507..7110f6a 100644
--- a/keychain_dbus.cpp
+++ b/keychain_dbus.cpp
@@ -11,6 +11,8 @@
#include <QSettings>
+#include <auto_ptr.h>
+
using namespace QKeychain;
JobExecutor::JobExecutor()
@@ -81,12 +83,58 @@ void ReadPasswordJobPrivate::scheduledStart() {
void ReadPasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watcher ) {
watcher->deleteLater();
const QDBusPendingReply<int> reply = *watcher;
+
+ std::auto_ptr<QSettings> local( !q->settings() ? new QSettings( q->service() ) : 0 );
+ QSettings* actual = q->settings() ? q->settings() : local.get();
+ WritePasswordJobPrivate::Mode mode;
+
+ const QString typeKey = QString( "%1/type" ).arg( key );
+ const QString dataKey = QString( "%1/data" ).arg( key );
if ( reply.isError() ) {
const QDBusError err = reply.error();
- if ( err.type() == QDBusError::ServiceUnknown ) //KWalletd not running
- q->emitFinishedWithError( NoBackendAvailable, tr("No keychain service available") );
+
+ 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;
+ }
+ }
+
+ if ( actual->contains( dataKey ) ) {
+ // We previously stored data in the insecure QSettings, but now have KWallet available.
+ // Do the migration
+
+ data = actual->value( dataKey ).toByteArray();
+ mode = (WritePasswordJobPrivate::Mode)actual->value( typeKey ).toInt();
+ actual->remove( key );
+
+ q->emitFinished();
+
+
+ WritePasswordJob* j = new WritePasswordJob( q->service(), 0 );
+ j->setSettings( q->settings() );
+ j->setKey( key );
+ j->setAutoDelete( true );
+ if ( mode == WritePasswordJobPrivate::Binary )
+ j->setBinaryData( data );
+ else if ( mode == WritePasswordJobPrivate::Text )
+ j->setTextData( QString::fromUtf8( data ) );
else
- q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
+ Q_ASSERT( false );
+
+ j->start();
+
return;
}
@@ -153,12 +201,42 @@ void WritePasswordJobPrivate::scheduledStart() {
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() ) {
- const QDBusError err = reply.error();
- q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
+ if ( q->insecureFallback() ) {
+ if ( mode == Delete ) {
+ actual->remove( key );
+ actual->sync();
+
+ q->emitFinished();
+ return;
+ }
+
+ actual->setValue( QString( "%1/type" ).arg( key ), (int)mode );
+ if ( mode == Text )
+ actual->setValue( QString( "%1/data" ).arg( key ), textData.toUtf8() );
+ else if ( mode == Binary )
+ actual->setValue( QString( "%1/data" ).arg( key ), binaryData );
+ actual->sync();
+
+ q->emitFinished();
+ } else {
+ const QDBusError err = reply.error();
+ q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
+ }
return;
}
+ if ( actual->contains( key ) )
+ {
+ // If we had previously written to QSettings, but we now have a kwallet available, migrate and delete old insecure data
+ actual->remove( key );
+ actual->sync();
+ }
+
const int handle = reply.value();
if ( handle < 0 ) {
diff --git a/keychain_p.h b/keychain_p.h
index c2a1dee..912ca8e 100644
--- a/keychain_p.h
+++ b/keychain_p.h
@@ -37,12 +37,14 @@ public:
JobPrivate( const QString& service_ )
: error( NoError )
, service( service_ )
- , autoDelete( true ) {}
+ , autoDelete( true )
+ , insecureFallback( false ) {}
QKeychain::Error error;
QString errorString;
QString service;
bool autoDelete;
+ bool insecureFallback;
QPointer<QSettings> settings;
};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/qtkeychain.git
More information about the Pkg-owncloud-commits
mailing list