Move GnomeKeyring to separate files

This commit is contained in:
Frank Osterfeld 2014-01-04 13:15:08 +01:00
parent 048b50f164
commit ce025cac0c
6 changed files with 206 additions and 177 deletions

View File

@ -102,7 +102,7 @@ if(APPLE)
endif()
if(UNIX AND NOT APPLE)
list(APPEND qtkeychain_SOURCES keychain_dbus.cpp)
list(APPEND qtkeychain_SOURCES keychain_unix.cpp gnomekeyring.cpp)
qt_add_dbus_interface(qtkeychain_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/org.kde.KWallet.xml kwallet_interface KWalletInterface)
list(APPEND qtkeychain_LIBRARIES ${QTDBUS_LIBRARIES})
endif()

68
gnomekeyring.cpp Normal file
View File

@ -0,0 +1,68 @@
#include "gnomekeyring_p.h"
const char* GnomeKeyring::GNOME_KEYRING_DEFAULT = NULL;
bool GnomeKeyring::isSupported()
{
const GnomeKeyring& keyring = instance();
return keyring.isLoaded() &&
keyring.NETWORK_PASSWORD &&
keyring.find_password &&
keyring.store_password &&
keyring.delete_password;
}
GnomeKeyring::gpointer GnomeKeyring::store_network_password( const gchar* keyring, const gchar* display_name,
const gchar* user, const gchar* server, const gchar* password,
OperationDoneCallback callback, gpointer data, GDestroyNotify destroy_data )
{
if ( !isSupported() )
return 0;
return instance().store_password( instance().NETWORK_PASSWORD,
keyring, display_name, password, callback, data, destroy_data,
"user", user, "server", server, static_cast<char*>(0) );
}
GnomeKeyring::gpointer GnomeKeyring::find_network_password( const gchar* user, const gchar* server,
OperationGetStringCallback callback, gpointer data, GDestroyNotify destroy_data )
{
if ( !isSupported() )
return 0;
return instance().find_password( instance().NETWORK_PASSWORD,
callback, data, destroy_data,
"user", user, "server", server, static_cast<char*>(0) );
}
GnomeKeyring::gpointer GnomeKeyring::delete_network_password( const gchar* user,
const gchar* server,
OperationDoneCallback callback,
gpointer data,
GDestroyNotify destroy_data )
{
if ( !isSupported() )
return 0;
return instance().delete_password( instance().NETWORK_PASSWORD,
callback, data, destroy_data,
"user", user, "server", server, static_cast<char*>(0) );
}
GnomeKeyring::GnomeKeyring()
: QLibrary("gnome-keyring", 0)
{
static const PasswordSchema schema = {
ITEM_NETWORK_PASSWORD,
{{ "user", ATTRIBUTE_TYPE_STRING },
{ "server", ATTRIBUTE_TYPE_STRING },
{ 0, static_cast<AttributeType>( 0 ) }}
};
NETWORK_PASSWORD = &schema;
find_password = reinterpret_cast<find_password_fn*>( resolve( "gnome_keyring_find_password" ) );
store_password = reinterpret_cast<store_password_fn*>( resolve( "gnome_keyring_store_password" ) );
delete_password = reinterpret_cast<delete_password_fn*>( resolve( "gnome_keyring_delete_password" ) );
}
GnomeKeyring& GnomeKeyring::instance() {
static GnomeKeyring keyring;
return keyring;
}

84
gnomekeyring_p.h Normal file
View File

@ -0,0 +1,84 @@
#ifndef QTKEYCHAIN_GNOME_P_H
#define QTKEYCHAIN_GNOME_P_H
#include <QLibrary>
class GnomeKeyring : private QLibrary {
public:
enum Result {
RESULT_OK,
RESULT_DENIED,
RESULT_NO_KEYRING_DAEMON,
RESULT_ALREADY_UNLOCKED,
RESULT_NO_SUCH_KEYRING,
RESULT_BAD_ARGUMENTS,
RESULT_IO_ERROR,
RESULT_CANCELLED,
RESULT_KEYRING_ALREADY_EXISTS,
RESULT_NO_MATCH
};
enum ItemType {
ITEM_GENERIC_SECRET = 0,
ITEM_NETWORK_PASSWORD,
ITEM_NOTE,
ITEM_CHAINED_KEYRING_PASSWORD,
ITEM_ENCRYPTION_KEY_PASSWORD,
ITEM_PK_STORAGE = 0x100
};
enum AttributeType {
ATTRIBUTE_TYPE_STRING,
ATTRIBUTE_TYPE_UINT32
};
typedef char gchar;
typedef void* gpointer;
typedef struct {
ItemType item_type;
struct {
const gchar* name;
AttributeType type;
} attributes[32];
} PasswordSchema;
typedef void ( *OperationGetStringCallback )( Result result, const char* string, gpointer data );
typedef void ( *OperationDoneCallback )( Result result, gpointer data );
typedef void ( *GDestroyNotify )( gpointer data );
static const char* GNOME_KEYRING_DEFAULT;
static bool isSupported();
static gpointer store_network_password( const gchar* keyring, const gchar* display_name,
const gchar* user, const gchar* server, const gchar* password,
OperationDoneCallback callback, gpointer data, GDestroyNotify destroy_data );
static gpointer find_network_password( const gchar* user, const gchar* server,
OperationGetStringCallback callback, gpointer data, GDestroyNotify destroy_data );
static gpointer delete_network_password( const gchar* user, const gchar* server,
OperationDoneCallback callback, gpointer data, GDestroyNotify destroy_data );
private:
GnomeKeyring();
static GnomeKeyring& instance();
const PasswordSchema* NETWORK_PASSWORD;
typedef gpointer ( store_password_fn )( const PasswordSchema* schema, const gchar* keyring,
const gchar* display_name, const gchar* password,
OperationDoneCallback callback, gpointer data, GDestroyNotify destroy_data,
... );
typedef gpointer ( find_password_fn )( const PasswordSchema* schema,
OperationGetStringCallback callback, gpointer data, GDestroyNotify destroy_data,
... );
typedef gpointer ( delete_password_fn )( const PasswordSchema* schema,
OperationDoneCallback callback, gpointer data, GDestroyNotify destroy_data,
... );
find_password_fn* find_password;
store_password_fn* store_password;
delete_password_fn* delete_password;
};
#endif

View File

@ -7,6 +7,7 @@
* details, check the accompanying file 'COPYING'. *
*****************************************************************************/
#include "keychain_p.h"
#include "gnomekeyring_p.h"
#include <QSettings>
@ -24,130 +25,6 @@ static QString dataKey( const QString& key )
return QString::fromLatin1( "%1/data" ).arg( key );
}
class GnomeKeyring : private QLibrary {
public:
enum Result {
RESULT_OK,
RESULT_DENIED,
RESULT_NO_KEYRING_DAEMON,
RESULT_ALREADY_UNLOCKED,
RESULT_NO_SUCH_KEYRING,
RESULT_BAD_ARGUMENTS,
RESULT_IO_ERROR,
RESULT_CANCELLED,
RESULT_KEYRING_ALREADY_EXISTS,
RESULT_NO_MATCH
};
enum ItemType {
ITEM_GENERIC_SECRET = 0,
ITEM_NETWORK_PASSWORD,
ITEM_NOTE,
ITEM_CHAINED_KEYRING_PASSWORD,
ITEM_ENCRYPTION_KEY_PASSWORD,
ITEM_PK_STORAGE = 0x100
};
enum AttributeType {
ATTRIBUTE_TYPE_STRING,
ATTRIBUTE_TYPE_UINT32
};
typedef char gchar;
typedef void* gpointer;
typedef struct {
ItemType item_type;
struct {
const gchar* name;
AttributeType type;
} attributes[32];
} PasswordSchema;
typedef void ( *OperationGetStringCallback )( Result result, const char* string, gpointer data );
typedef void ( *OperationDoneCallback )( Result result, gpointer data );
typedef void ( *GDestroyNotify )( gpointer data );
static const char* GNOME_KEYRING_DEFAULT;
static bool isSupported()
{
const GnomeKeyring& keyring = instance();
return keyring.isLoaded() &&
keyring.NETWORK_PASSWORD &&
keyring.find_password &&
keyring.store_password &&
keyring.delete_password;
}
static gpointer store_network_password( const gchar* keyring, const gchar* display_name,
const gchar* user, const gchar* server, const gchar* password,
OperationDoneCallback callback, gpointer data, GDestroyNotify destroy_data )
{
if ( !isSupported() )
return 0;
return instance().store_password( instance().NETWORK_PASSWORD,
keyring, display_name, password, callback, data, destroy_data,
"user", user, "server", server, static_cast<char*>(0) );
}
static gpointer find_network_password( const gchar* user, const gchar* server,
OperationGetStringCallback callback, gpointer data, GDestroyNotify destroy_data )
{
if ( !isSupported() )
return 0;
return instance().find_password( instance().NETWORK_PASSWORD,
callback, data, destroy_data,
"user", user, "server", server, static_cast<char*>(0) );
}
static gpointer delete_network_password( const gchar* user, const gchar* server,
OperationDoneCallback callback, gpointer data, GDestroyNotify destroy_data )
{
if ( !isSupported() )
return 0;
return instance().delete_password( instance().NETWORK_PASSWORD,
callback, data, destroy_data,
"user", user, "server", server, static_cast<char*>(0) );
}
private:
GnomeKeyring(): QLibrary("gnome-keyring", 0) {
static const PasswordSchema schema = {
ITEM_NETWORK_PASSWORD,
{{ "user", ATTRIBUTE_TYPE_STRING },
{ "server", ATTRIBUTE_TYPE_STRING },
{ 0, static_cast<AttributeType>( 0 ) }}
};
NETWORK_PASSWORD = &schema;
find_password = reinterpret_cast<find_password_fn*>( resolve( "gnome_keyring_find_password" ) );
store_password = reinterpret_cast<store_password_fn*>( resolve( "gnome_keyring_store_password" ) );
delete_password = reinterpret_cast<delete_password_fn*>( resolve( "gnome_keyring_delete_password" ) );
}
static GnomeKeyring& instance() {
static GnomeKeyring keyring;
return keyring;
}
const PasswordSchema* NETWORK_PASSWORD;
typedef gpointer ( store_password_fn )( const PasswordSchema* schema, const gchar* keyring,
const gchar* display_name, const gchar* password,
OperationDoneCallback callback, gpointer data, GDestroyNotify destroy_data,
... );
typedef gpointer ( find_password_fn )( const PasswordSchema* schema,
OperationGetStringCallback callback, gpointer data, GDestroyNotify destroy_data,
... );
typedef gpointer ( delete_password_fn )( const PasswordSchema* schema,
OperationDoneCallback callback, gpointer data, GDestroyNotify destroy_data,
... );
find_password_fn* find_password;
store_password_fn* store_password;
delete_password_fn* delete_password;
};
const char* GnomeKeyring::GNOME_KEYRING_DEFAULT = NULL;
enum KeyringBackend {
Backend_GnomeKeyring,
Backend_Kwallet

View File

@ -4,47 +4,47 @@
<context>
<name>QKeychain::ReadPasswordJobPrivate</name>
<message>
<location filename="../keychain_dbus.cpp" line="176"/>
<location filename="../keychain_unix.cpp" line="53"/>
<source>Unknown error</source>
<translation>Unbekannter Fehler</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="190"/>
<location filename="../keychain_unix.cpp" line="67"/>
<source>D-Bus is not running</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="267"/>
<location filename="../keychain_unix.cpp" line="144"/>
<source>No keychain service available</source>
<translation>Kein Schlüsselbund-Dienst verfügbar</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="269"/>
<location filename="../keychain_unix.cpp" line="146"/>
<source>Could not open wallet: %1; %2</source>
<translation>Konnte Brieftasche nicht öffnen: %1; %2</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="315"/>
<location filename="../keychain_unix.cpp" line="192"/>
<source>Access to keychain denied</source>
<translation>Zugriff auf Schlüsselbund verweigert</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="336"/>
<location filename="../keychain_unix.cpp" line="213"/>
<source>Could not determine data type: %1; %2</source>
<translation>Datentyp kann nicht ermittelt werden: %1: %2</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="354"/>
<location filename="../keychain_unix.cpp" line="231"/>
<source>Unsupported entry type &apos;Map&apos;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="357"/>
<location filename="../keychain_unix.cpp" line="234"/>
<source>Unknown kwallet entry type &apos;%1&apos;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="372"/>
<location filename="../keychain_unix.cpp" line="249"/>
<source>Could not read password: %1; %2</source>
<translation>Passwort konnte nicht ausgelesen werden: %1; %2</translation>
</message>
@ -54,7 +54,7 @@
<translation>Passwort nicht gefunden</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="345"/>
<location filename="../keychain_unix.cpp" line="222"/>
<location filename="../keychain_win.cpp" line="27"/>
<source>Entry not found</source>
<translation>Eintrag nicht gefunden</translation>
@ -68,24 +68,24 @@
<context>
<name>QKeychain::WritePasswordJobPrivate</name>
<message>
<location filename="../keychain_dbus.cpp" line="393"/>
<location filename="../keychain_dbus.cpp" line="401"/>
<location filename="../keychain_unix.cpp" line="270"/>
<location filename="../keychain_unix.cpp" line="278"/>
<source>Unknown error</source>
<translation>Unbekannter Fehler</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="416"/>
<location filename="../keychain_unix.cpp" line="293"/>
<source>D-Bus is not running</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="457"/>
<location filename="../keychain_dbus.cpp" line="533"/>
<location filename="../keychain_unix.cpp" line="334"/>
<location filename="../keychain_unix.cpp" line="410"/>
<source>Could not open wallet: %1; %2</source>
<translation>Konnte Brieftasche nicht öffnen: %1; %2</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="511"/>
<location filename="../keychain_unix.cpp" line="388"/>
<source>Access to keychain denied</source>
<translation>Zugriff auf Schlüsselbund verweigert</translation>
</message>
@ -118,52 +118,52 @@
<context>
<name>QObject</name>
<message>
<location filename="../keychain_dbus.cpp" line="212"/>
<location filename="../keychain_unix.cpp" line="89"/>
<source>Access to keychain denied</source>
<translation>Zugriff auf Schlüsselbund verweigert</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="214"/>
<location filename="../keychain_unix.cpp" line="91"/>
<source>No keyring daemon</source>
<translation>Kein Schlüsselbund-Dienst </translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="216"/>
<location filename="../keychain_unix.cpp" line="93"/>
<source>Already unlocked</source>
<translation>Bereits entsperrt</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="218"/>
<location filename="../keychain_unix.cpp" line="95"/>
<source>No such keyring</source>
<translation>Kein solcher Schlüsselbund</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="220"/>
<location filename="../keychain_unix.cpp" line="97"/>
<source>Bad arguments</source>
<translation>Ungültige Argumente</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="222"/>
<location filename="../keychain_unix.cpp" line="99"/>
<source>I/O error</source>
<translation>Ein-/Ausgabe-Fehler</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="224"/>
<location filename="../keychain_unix.cpp" line="101"/>
<source>Cancelled</source>
<translation>Abgebrochen</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="226"/>
<location filename="../keychain_unix.cpp" line="103"/>
<source>Keyring already exists</source>
<translation>Schlüsselbund existiert bereits</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="228"/>
<location filename="../keychain_unix.cpp" line="105"/>
<source>No match</source>
<translation>Kein Treffer</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="233"/>
<location filename="../keychain_unix.cpp" line="110"/>
<source>Unknown error</source>
<translation>Unbekannter Fehler</translation>
</message>

View File

@ -4,48 +4,48 @@
<context>
<name>QKeychain::ReadPasswordJobPrivate</name>
<message>
<location filename="../keychain_dbus.cpp" line="176"/>
<location filename="../keychain_unix.cpp" line="53"/>
<source>Unknown error</source>
<translation>Eroare necunoscută</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="190"/>
<location filename="../keychain_unix.cpp" line="67"/>
<source>D-Bus is not running</source>
<translation>D-Bus nu rulează</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="267"/>
<location filename="../keychain_unix.cpp" line="144"/>
<source>No keychain service available</source>
<translatorcomment>Nu există niciun serviciu de chei disponibil</translatorcomment>
<translation>Kein Schlüsselbund-Dienst verfügbar</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="269"/>
<location filename="../keychain_unix.cpp" line="146"/>
<source>Could not open wallet: %1; %2</source>
<translation>Nu se poate deschide portofelul: %1; %2</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="315"/>
<location filename="../keychain_unix.cpp" line="192"/>
<source>Access to keychain denied</source>
<translation>Acces interzis la serviciul de chei</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="336"/>
<location filename="../keychain_unix.cpp" line="213"/>
<source>Could not determine data type: %1; %2</source>
<translation>Nu se poate stabili tipul de date: %1: %2</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="354"/>
<location filename="../keychain_unix.cpp" line="231"/>
<source>Unsupported entry type &apos;Map&apos;</source>
<translation>Tip de înregistrare nesuportat &apos;Map&apos;</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="357"/>
<location filename="../keychain_unix.cpp" line="234"/>
<source>Unknown kwallet entry type &apos;%1&apos;</source>
<translation>Tip de înregistrare kwallet necunoscut &apos;%1&apos;</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="372"/>
<location filename="../keychain_unix.cpp" line="249"/>
<source>Could not read password: %1; %2</source>
<translation>Nu se poate citi parola: %1; %2</translation>
</message>
@ -55,7 +55,7 @@
<translation>Parola nu a fost găsită</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="345"/>
<location filename="../keychain_unix.cpp" line="222"/>
<location filename="../keychain_win.cpp" line="27"/>
<source>Entry not found</source>
<translation>Înregistrarea nu a fost găsită</translation>
@ -69,24 +69,24 @@
<context>
<name>QKeychain::WritePasswordJobPrivate</name>
<message>
<location filename="../keychain_dbus.cpp" line="393"/>
<location filename="../keychain_dbus.cpp" line="401"/>
<location filename="../keychain_unix.cpp" line="270"/>
<location filename="../keychain_unix.cpp" line="278"/>
<source>Unknown error</source>
<translation>Eroare necunoscută</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="416"/>
<location filename="../keychain_unix.cpp" line="293"/>
<source>D-Bus is not running</source>
<translation>D-Bus nu rulează</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="457"/>
<location filename="../keychain_dbus.cpp" line="533"/>
<location filename="../keychain_unix.cpp" line="334"/>
<location filename="../keychain_unix.cpp" line="410"/>
<source>Could not open wallet: %1; %2</source>
<translation>Nu se poate deschide portofelul: %1; %2</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="511"/>
<location filename="../keychain_unix.cpp" line="388"/>
<source>Access to keychain denied</source>
<translation>Acces interzis la serviciul de chei</translation>
</message>
@ -119,52 +119,52 @@
<context>
<name>QObject</name>
<message>
<location filename="../keychain_dbus.cpp" line="212"/>
<location filename="../keychain_unix.cpp" line="89"/>
<source>Access to keychain denied</source>
<translation>Acces interzis la serviciul de chei</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="214"/>
<location filename="../keychain_unix.cpp" line="91"/>
<source>No keyring daemon</source>
<translation>Niciun demon pentru inelul de chei</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="216"/>
<location filename="../keychain_unix.cpp" line="93"/>
<source>Already unlocked</source>
<translation>Deja deblocat</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="218"/>
<location filename="../keychain_unix.cpp" line="95"/>
<source>No such keyring</source>
<translation>Nu există astfel de inel de chei</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="220"/>
<location filename="../keychain_unix.cpp" line="97"/>
<source>Bad arguments</source>
<translation>Argumente greșite</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="222"/>
<location filename="../keychain_unix.cpp" line="99"/>
<source>I/O error</source>
<translation>Eroare de I/E</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="224"/>
<location filename="../keychain_unix.cpp" line="101"/>
<source>Cancelled</source>
<translation>Anulat</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="226"/>
<location filename="../keychain_unix.cpp" line="103"/>
<source>Keyring already exists</source>
<translation>Inelul de chei deja există</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="228"/>
<location filename="../keychain_unix.cpp" line="105"/>
<source>No match</source>
<translation>Nicio potrivire</translation>
</message>
<message>
<location filename="../keychain_dbus.cpp" line="233"/>
<location filename="../keychain_unix.cpp" line="110"/>
<source>Unknown error</source>
<translation>Eroare necunoscută</translation>
</message>