Commit 35913a0d authored by Debarshi Ray's avatar Debarshi Ray
Browse files
parent 250c718d
......@@ -34,6 +34,7 @@ goa_daemon_CFLAGS = \
$(GLIB_CFLAGS) \
$(GTK_CFLAGS) \
$(REST_CFLAGS) \
$(SECRET_CFLAGS) \
$(NULL)
goa_daemon_LDADD = \
......@@ -42,6 +43,7 @@ goa_daemon_LDADD = \
$(top_builddir)/src/goabackend/libgoa-backend-1.0.la \
$(GTK_LIBS) \
$(REST_LIBS) \
$(SECRET_LIBS) \
$(NULL)
clean-local :
......
......@@ -24,6 +24,7 @@
#include <gio/gio.h>
#include <glib/gi18n.h>
#include <rest/rest-proxy.h>
#include <libsecret/secret.h>
#include <libsoup/soup.h>
#include "goadaemon.h"
......@@ -51,6 +52,9 @@ struct _GoaDaemon
GQueue *ensure_credentials_queue;
gboolean ensure_credentials_running;
SecretService *secret_service;
gchar *secret_service_bus_name;
guint config_timeout_id;
guint credentials_timeout_id;
};
......@@ -58,7 +62,8 @@ struct _GoaDaemon
enum
{
PROP_0,
PROP_CONNECTION
PROP_CONNECTION,
PROP_SECRET_SERVICE_BUS_NAME
};
static void on_file_monitor_changed (GFileMonitor *monitor,
......@@ -147,9 +152,6 @@ goa_daemon_constructed (GObject *object)
G_OBJECT_CLASS (goa_daemon_parent_class)->constructed (object);
/* prime the list of accounts */
goa_daemon_reload_configuration (self);
/* Export objects */
g_dbus_object_manager_server_set_connection (self->object_manager, self->connection);
}
......@@ -182,6 +184,8 @@ goa_daemon_finalize (GObject *object)
}
g_free (self->home_conf_file_path);
g_free (self->secret_service_bus_name);
g_clear_object (&self->secret_service);
g_object_unref (self->manager);
g_object_unref (self->object_manager);
g_object_unref (self->connection);
......@@ -201,6 +205,10 @@ goa_daemon_set_property (GObject *object, guint prop_id, const GValue *value, GP
self->connection = G_DBUS_CONNECTION (g_value_dup_object (value));
break;
case PROP_SECRET_SERVICE_BUS_NAME:
self->secret_service_bus_name = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -390,12 +398,39 @@ goa_daemon_class_init (GoaDaemonClass *klass)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS |
G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class,
PROP_SECRET_SERVICE_BUS_NAME,
g_param_spec_string ("secret-service-bus-name",
"Secret service bus name",
"The D-Bus service name of the secret service",
NULL,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS |
G_PARAM_WRITABLE));
}
static gboolean
goa_daemon_initable_init (GInitable *initable, GCancellable *cancellable, GError **error)
{
return TRUE;
GoaDaemon *self = GOA_DAEMON (initable);
gboolean ret_val = FALSE;
self->secret_service = secret_service_open_sync (SECRET_TYPE_SERVICE,
self->secret_service_bus_name,
SECRET_SERVICE_OPEN_SESSION,
cancellable,
error);
if (self->secret_service == NULL)
goto out;
/* prime the list of accounts */
goa_daemon_reload_configuration (self);
ret_val = TRUE;
out:
return ret_val;
}
static void
......@@ -405,13 +440,22 @@ goa_daemon_initable_iface_init (GInitableIface *iface)
}
GoaDaemon *
goa_daemon_new (GDBusConnection *connection, GCancellable *cancellable, GError **error)
goa_daemon_new (GDBusConnection *connection,
const gchar *secret_service_bus_name,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
g_return_val_if_fail (secret_service_bus_name != NULL && secret_service_bus_name[0] != '\0', NULL);
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
return GOA_DAEMON (g_initable_new (GOA_TYPE_DAEMON, cancellable, error, "connection", connection, NULL));
return GOA_DAEMON (g_initable_new (GOA_TYPE_DAEMON,
cancellable,
error,
"connection", connection,
"secret-service-bus-name", secret_service_bus_name,
NULL));
}
......@@ -597,7 +641,7 @@ add_config_file (GoaDaemon *self,
needs_update = g_key_file_remove_group (key_file, groups[n], NULL);
error = NULL;
if (!goa_utils_delete_credentials_for_id_sync (provider, id, NULL, &error))
if (!goa_utils_delete_credentials_for_id_sync (self->secret_service, provider, id, NULL, &error))
{
g_warning ("Unable to clean-up stale keyring entries: %s", error->message);
g_error_free (error);
......@@ -712,7 +756,14 @@ goa_daemon_update_account_object (GoaDaemon *self,
goa_account_set_is_temporary (account, is_temporary);
error = NULL;
if (!goa_provider_build_object (provider, object, key_file, group, self->connection, just_added, &error))
if (!goa_provider_build_object (provider,
object,
key_file,
group,
self->connection,
self->secret_service,
just_added,
&error))
{
g_warning ("Error parsing account: %s (%s, %d)",
error->message, g_quark_to_string (error->domain), error->code);
......@@ -1273,7 +1324,8 @@ get_all_providers_cb (GObject *source,
/* We don't want to fail AddAccount if we could not store the
* credentials in the keyring.
*/
goa_utils_store_credentials_for_id_sync (provider,
goa_utils_store_credentials_for_id_sync (self->secret_service,
provider,
id,
data->credentials,
NULL, /* GCancellable */
......@@ -1478,7 +1530,7 @@ on_account_handle_remove (GoaAccount *account,
}
error = NULL;
if (!goa_utils_delete_credentials_for_account_sync (provider, account, NULL, &error))
if (!goa_utils_delete_credentials_for_account_sync (self->secret_service, provider, account, NULL, &error))
{
g_dbus_method_invocation_take_error (invocation, error);
goto out;
......@@ -1657,6 +1709,7 @@ ensure_credentials_queue_check (GoaDaemon *self)
goa_provider_ensure_credentials (provider,
data->object,
self->secret_service,
NULL, /* GCancellable */
ensure_credentials_queue_collector,
task);
......
......@@ -27,6 +27,7 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GoaDaemon, goa_daemon, GOA, DAEMON, GObject);
GoaDaemon *goa_daemon_new (GDBusConnection *connection,
const gchar *secret_service_bus_name,
GCancellable *cancellable,
GError **error);
......
......@@ -26,6 +26,7 @@
#include <libintl.h>
#include "goadaemon.h"
#include "goabackend/goautils.h"
/* ---------------------------------------------------------------------------------------------------- */
......@@ -53,7 +54,7 @@ on_bus_acquired (GDBusConnection *connection,
g_debug ("Connected to the session bus");
error = NULL;
the_daemon = goa_daemon_new (connection, NULL, &error);
the_daemon = goa_daemon_new (connection, GOA_SECRET_SERVICE_BUS_NAME, NULL, &error);
if (error != NULL)
{
g_warning ("Unable to initialize GoaDaemon: %s (%s, %d)",
......
......@@ -162,13 +162,17 @@ libgoawebextension_la_SOURCES = \
$(NULL)
libgoawebextension_la_CFLAGS = \
$(GLIB_CFLAGS) \
$(REST_CFLAGS) \
$(SECRET_CFLAGS) \
$(WEBKIT_GTK_CFLAGS) \
$(NULL)
libgoawebextension_la_LIBADD = \
libgoa-backend-1.0.la \
$(GLIB_LIBS) \
$(REST_LIBS) \
$(SECRET_LIBS) \
$(WEBKIT_GTK_LIBS) \
$(NULL)
......
......@@ -18,6 +18,7 @@
#include "config.h"
#include <glib/gi18n-lib.h>
#include <libsecret/secret.h>
#include "goaewsclient.h"
#include "goaprovider.h"
......@@ -79,6 +80,7 @@ build_object (GoaProvider *provider,
GKeyFile *key_file,
const gchar *group,
GDBusConnection *connection,
SecretService *secret_service,
gboolean just_added,
GError **error)
{
......@@ -97,6 +99,7 @@ build_object (GoaProvider *provider,
key_file,
group,
connection,
secret_service,
just_added,
error))
goto out;
......@@ -109,10 +112,12 @@ build_object (GoaProvider *provider,
g_dbus_interface_skeleton_set_flags (G_DBUS_INTERFACE_SKELETON (password_based),
G_DBUS_INTERFACE_SKELETON_FLAGS_HANDLE_METHOD_INVOCATIONS_IN_THREAD);
goa_object_skeleton_set_password_based (object, password_based);
g_signal_connect (password_based,
"handle-get-password",
G_CALLBACK (on_handle_get_password),
NULL);
g_signal_connect_data (password_based,
"handle-get-password",
G_CALLBACK (on_handle_get_password),
g_object_ref (secret_service),
(GClosureNotify) g_object_unref,
0);
}
account = goa_object_get_account (GOA_OBJECT (object));
......@@ -198,6 +203,7 @@ build_object (GoaProvider *provider,
static gboolean
ensure_credentials_sync (GoaProvider *provider,
GoaObject *object,
SecretService *secret_service,
gint *out_expires_in,
GCancellable *cancellable,
GError **error)
......@@ -212,7 +218,14 @@ ensure_credentials_sync (GoaProvider *provider,
gchar *username = NULL;
gchar *password = NULL;
if (!goa_utils_get_credentials (provider, object, "password", &username, &password, cancellable, error))
if (!goa_utils_get_credentials (secret_service,
provider,
object,
"password",
&username,
&password,
cancellable,
error))
{
if (error != NULL)
{
......@@ -668,6 +681,7 @@ refresh_account (GoaProvider *provider,
GoaClient *client,
GoaObject *object,
GtkWindow *parent,
SecretService *secret_service,
GError **error)
{
AddAccountData data;
......@@ -787,7 +801,8 @@ refresh_account (GoaProvider *provider,
g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add (&builder, "{sv}", "password", g_variant_new_string (password));
if (!goa_utils_store_credentials_for_object_sync (provider,
if (!goa_utils_store_credentials_for_object_sync (secret_service,
provider,
object,
g_variant_builder_end (&builder),
NULL, /* GCancellable */
......@@ -846,6 +861,7 @@ on_handle_get_password (GoaPasswordBased *interface,
GoaAccount *account;
GoaProvider *provider;
GError *error;
SecretService *secret_service = SECRET_SERVICE (user_data);
const gchar *account_id;
const gchar *method_name;
const gchar *provider_type;
......@@ -863,7 +879,7 @@ on_handle_get_password (GoaPasswordBased *interface,
provider = goa_provider_get_for_provider_type (provider_type);
error = NULL;
if (!goa_utils_get_credentials (provider, object, "password", NULL, &password, NULL, &error))
if (!goa_utils_get_credentials (secret_service, provider, object, "password", NULL, &password, NULL, &error))
{
g_dbus_method_invocation_take_error (invocation, error);
goto out;
......
......@@ -276,6 +276,7 @@ build_object (GoaProvider *provider,
GKeyFile *key_file,
const gchar *group,
GDBusConnection *connection,
SecretService *secret_service,
gboolean just_added,
GError **error)
{
......@@ -290,6 +291,7 @@ build_object (GoaProvider *provider,
key_file,
group,
connection,
secret_service,
just_added,
error))
goto out;
......
......@@ -289,6 +289,7 @@ build_object (GoaProvider *provider,
GKeyFile *key_file,
const gchar *group,
GDBusConnection *connection,
SecretService *secret_service,
gboolean just_added,
GError **error)
{
......@@ -302,6 +303,7 @@ build_object (GoaProvider *provider,
key_file,
group,
connection,
secret_service,
just_added,
error))
goto out;
......
......@@ -280,6 +280,7 @@ build_object (GoaProvider *provider,
GKeyFile *key_file,
const gchar *group,
GDBusConnection *connection,
SecretService *secret_service,
gboolean just_added,
GError **error)
{
......@@ -293,6 +294,7 @@ build_object (GoaProvider *provider,
key_file,
group,
connection,
secret_service,
just_added,
error))
goto out;
......
......@@ -276,6 +276,7 @@ build_object (GoaProvider *provider,
GKeyFile *key_file,
const gchar *group,
GDBusConnection *connection,
SecretService *secret_service,
gboolean just_added,
GError **error)
{
......@@ -300,6 +301,7 @@ build_object (GoaProvider *provider,
key_file,
group,
connection,
secret_service,
just_added,
error))
goto out;
......
......@@ -19,6 +19,7 @@
#include "config.h"
#include <glib/gi18n-lib.h>
#include <libsecret/secret.h>
#include "goaimapauthlogin.h"
#include "goamailclient.h"
......@@ -92,6 +93,7 @@ build_object (GoaProvider *provider,
GKeyFile *key_file,
const gchar *group,
GDBusConnection *connection,
SecretService *secret_service,
gboolean just_added,
GError **error)
{
......@@ -136,6 +138,7 @@ build_object (GoaProvider *provider,
key_file,
group,
connection,
secret_service,
just_added,
error))
goto out;
......@@ -148,10 +151,12 @@ build_object (GoaProvider *provider,
g_dbus_interface_skeleton_set_flags (G_DBUS_INTERFACE_SKELETON (password_based),
G_DBUS_INTERFACE_SKELETON_FLAGS_HANDLE_METHOD_INVOCATIONS_IN_THREAD);
goa_object_skeleton_set_password_based (object, password_based);
g_signal_connect (password_based,
"handle-get-password",
G_CALLBACK (on_handle_get_password),
NULL);
g_signal_connect_data (password_based,
"handle-get-password",
G_CALLBACK (on_handle_get_password),
g_object_ref (secret_service),
(GClosureNotify) g_object_unref,
0);
}
account = goa_object_get_account (GOA_OBJECT (object));
......@@ -287,6 +292,7 @@ get_tls_type_from_string_id (const gchar *str)
static gboolean
ensure_credentials_sync (GoaProvider *provider,
GoaObject *object,
SecretService *secret_service,
gint *out_expires_in,
GCancellable *cancellable,
GError **error)
......@@ -324,7 +330,14 @@ ensure_credentials_sync (GoaProvider *provider,
ret = FALSE;
if (!goa_utils_get_credentials (provider, object, "imap-password", NULL, &imap_password, cancellable, error))
if (!goa_utils_get_credentials (secret_service,
provider,
object,
"imap-password",
NULL,
&imap_password,
cancellable,
error))
{
if (error != NULL)
{
......@@ -377,7 +390,14 @@ ensure_credentials_sync (GoaProvider *provider,
if (!goa_util_lookup_keyfile_boolean (object, "SmtpUseAuth"))
goto smtp_done;
if (!goa_utils_get_credentials (provider, object, "smtp-password", NULL, &smtp_password, cancellable, error))
if (!goa_utils_get_credentials (secret_service,
provider,
object,
"smtp-password",
NULL,
&smtp_password,
cancellable,
error))
{
if (error != NULL)
{
......@@ -1198,6 +1218,7 @@ refresh_account (GoaProvider *provider,
GoaClient *client,
GoaObject *object,
GtkWindow *parent,
SecretService *secret_service,
GError **error)
{
AddAccountData data;
......@@ -1228,6 +1249,7 @@ refresh_account (GoaProvider *provider,
g_return_val_if_fail (GOA_IS_CLIENT (client), FALSE);
g_return_val_if_fail (GOA_IS_OBJECT (object), FALSE);
g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), FALSE);
g_return_val_if_fail (SECRET_IS_SERVICE (secret_service), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
imap_auth = NULL;
......@@ -1449,7 +1471,8 @@ refresh_account (GoaProvider *provider,
if (smtp_use_auth)
g_variant_builder_add (&builder, "{sv}", "smtp-password", g_variant_new_string (smtp_password));
if (!goa_utils_store_credentials_for_object_sync (provider,
if (!goa_utils_store_credentials_for_object_sync (secret_service,
provider,
object,
g_variant_builder_end (&builder),
NULL, /* GCancellable */
......@@ -1613,6 +1636,7 @@ on_handle_get_password (GoaPasswordBased *interface,
GoaAccount *account;
GoaProvider *provider;
GError *error;
SecretService *secret_service = SECRET_SERVICE (user_data);
const gchar *account_id;
const gchar *method_name;
const gchar *provider_type;
......@@ -1632,7 +1656,7 @@ on_handle_get_password (GoaPasswordBased *interface,
provider = goa_provider_get_for_provider_type (provider_type);
error = NULL;
if (!goa_utils_get_credentials (provider, object, id, NULL, &password, NULL, &error))
if (!goa_utils_get_credentials (secret_service, provider, object, id, NULL, &password, NULL, &error))
{
g_dbus_method_invocation_take_error (invocation, error);
goto out;
......
......@@ -27,6 +27,7 @@
#include "goaidentitymanagererror.h"
#include <gcr/gcr.h>
#include <libsecret/secret.h>
#include "org.gnome.Identity.h"
......@@ -264,6 +265,7 @@ sign_in_identity_finish (GoaKerberosProvider *self,
static gboolean
get_ticket_sync (GoaKerberosProvider *self,
GoaObject *object,
SecretService *secret_service,
gboolean is_interactive,
GCancellable *cancellable,
GError **error)
......@@ -301,7 +303,8 @@ get_ticket_sync (GoaKerberosProvider *self,
password = NULL;
lookup_error = NULL;
credentials = goa_utils_lookup_credentials_sync (GOA_PROVIDER (self),
credentials = goa_utils_lookup_credentials_sync (secret_service,
GOA_PROVIDER (self),
object,
cancellable,
&lookup_error);
......@@ -385,12 +388,14 @@ notify_is_temporary_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
static gboolean
on_handle_get_ticket (GoaTicketing *interface,
GDBusMethodInvocation *invocation)
GDBusMethodInvocation *invocation,
gpointer user_data)
{
GoaObject *object;
GoaAccount *account;
GoaProvider *provider;
GError *error;
SecretService *secret_service = SECRET_SERVICE (user_data);
gboolean got_ticket;
const gchar *id;
const gchar *method_name;
......@@ -408,6 +413,7 @@ on_handle_get_ticket (GoaTicketing *interface,
error = NULL;
got_ticket = get_ticket_sync (GOA_KERBEROS_PROVIDER (provider),
object,
secret_service,
TRUE /* Allow interaction */,
NULL,
&error);
......@@ -427,6 +433,7 @@ build_object (GoaProvider *provider,
GKeyFile *key_file,
const gchar *group,
GDBusConnection *connection,
SecretService *secret_service,
gboolean just_added,
GError **error)
{
......@@ -440,6 +447,7 @@ build_object (GoaProvider *provider,
key_file,
group,
connection,
secret_service,
just_added,
error))
goto out;
......@@ -458,10 +466,12 @@ build_object (GoaProvider *provider,
ticketing = goa_ticketing_skeleton_new ();
g_signal_connect (ticketing,
"handle-get-ticket",
G_CALLBACK (on_handle_get_ticket),
NULL);
g_signal_connect_data (ticketing,
"handle-get-ticket",
G_CALLBACK (on_handle_get_ticket),
g_object_ref (secret_service),
(GClosureNotify) g_object_unref,
0);
goa_object_skeleton_set_ticketing (object, ticketing);
......@@ -778,6 +788,7 @@ refresh_account (GoaProvider *provider,
GoaClient *client,
GoaObject *object,
GtkWindow *parent,
SecretService *secret_service,
GError **error)
{
GoaKerberosProvider *self = GOA_KERBEROS_PROVIDER (provider);
......@@ -788,10 +799,12 @@ refresh_account (GoaProvider *provider,
g_return_val_if_fail (GOA_IS_CLIENT (client), FALSE);
g_return_val_if_fail (GOA_IS_OBJECT (object), FALSE);
g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), FALSE);
g_return_val_if_fail (SECRET_IS_SERVICE (secret_service), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
got_ticket = get_ticket_sync (self,
object,
secret_service,
TRUE /* Allow interaction */,
NULL,
&ticket_error);
......@@ -1337,6 +1350,7 @@ dbus_proxy_reload_properties_sync (GDBusProxy *proxy,
static gboolean
ensure_credentials_sync (GoaProvider *provider,
GoaObject *object,
SecretService *secret_service,
gint *out_expires_in,
GCancellable *cancellable,
GError **error)
......@@ -1374,6 +1388,7 @@ ensure_credentials_sync (GoaProvider *provider,
g_mutex_unlock (&identity_manager_mutex);
ticket_synced = get_ticket_sync (GOA_KERBEROS_PROVIDER (provider),