From b1d87d540c2229dc9954efe73feebcaf5aad41eb Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Wed, 27 May 2015 15:15:09 +0200 Subject: [PATCH 01/12] daemon: Style fixes Use the name 'self' to refer to the instance. --- src/daemon/goadaemon.c | 138 ++++++++++++++++++++++++------------------------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c index 89cbed8..55a576d 100644 --- a/src/daemon/goadaemon.c +++ b/src/daemon/goadaemon.c @@ -1,6 +1,6 @@ /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ /* - * Copyright (C) 2011, 2012 Red Hat, Inc. + * Copyright (C) 2011, 2012, 2015 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -71,39 +71,39 @@ static gboolean on_account_handle_ensure_credentials (GoaAccount *acc GDBusMethodInvocation *invocation, gpointer user_data); -static void goa_daemon_reload_configuration (GoaDaemon *daemon); +static void goa_daemon_reload_configuration (GoaDaemon *self); G_DEFINE_TYPE (GoaDaemon, goa_daemon, G_TYPE_OBJECT); static void goa_daemon_finalize (GObject *object) { - GoaDaemon *daemon = GOA_DAEMON (object); + GoaDaemon *self = GOA_DAEMON (object); - if (daemon->config_timeout_id != 0) + if (self->config_timeout_id != 0) { - g_source_remove (daemon->config_timeout_id); + g_source_remove (self->config_timeout_id); } - if (daemon->system_conf_dir_monitor != NULL) + if (self->system_conf_dir_monitor != NULL) { - g_signal_handlers_disconnect_by_func (daemon->system_conf_dir_monitor, on_file_monitor_changed, daemon); - g_object_unref (daemon->system_conf_dir_monitor); + g_signal_handlers_disconnect_by_func (self->system_conf_dir_monitor, on_file_monitor_changed, self); + g_object_unref (self->system_conf_dir_monitor); } - if (daemon->home_conf_dir_monitor != NULL) + if (self->home_conf_dir_monitor != NULL) { - g_signal_handlers_disconnect_by_func (daemon->home_conf_dir_monitor, on_file_monitor_changed, daemon); - g_object_unref (daemon->home_conf_dir_monitor); + g_signal_handlers_disconnect_by_func (self->home_conf_dir_monitor, on_file_monitor_changed, self); + g_object_unref (self->home_conf_dir_monitor); } - if (daemon->home_conf_file_monitor != NULL) + if (self->home_conf_file_monitor != NULL) { - g_signal_handlers_disconnect_by_func (daemon->home_conf_file_monitor, on_file_monitor_changed, daemon); - g_object_unref (daemon->home_conf_file_monitor); + g_signal_handlers_disconnect_by_func (self->home_conf_file_monitor, on_file_monitor_changed, self); + g_object_unref (self->home_conf_file_monitor); } - g_object_unref (daemon->manager); - g_object_unref (daemon->object_manager); - g_object_unref (daemon->connection); + g_object_unref (self->manager); + g_object_unref (self->object_manager); + g_object_unref (self->connection); G_OBJECT_CLASS (goa_daemon_parent_class)->finalize (object); } @@ -138,11 +138,11 @@ create_monitor (const gchar *path, gboolean is_dir) static gboolean on_config_file_monitor_timeout (gpointer user_data) { - GoaDaemon *daemon = GOA_DAEMON (user_data); + GoaDaemon *self = GOA_DAEMON (user_data); - daemon->config_timeout_id = 0; + self->config_timeout_id = 0; g_info ("Reloading configuration files\n"); - goa_daemon_reload_configuration (daemon); + goa_daemon_reload_configuration (self); return FALSE; } @@ -154,17 +154,17 @@ on_file_monitor_changed (GFileMonitor *monitor, GFileMonitorEvent event_type, gpointer user_data) { - GoaDaemon *daemon = GOA_DAEMON (user_data); + GoaDaemon *self = GOA_DAEMON (user_data); - if (daemon->config_timeout_id == 0) + if (self->config_timeout_id == 0) { - daemon->config_timeout_id = g_timeout_add (200, on_config_file_monitor_timeout, daemon); + self->config_timeout_id = g_timeout_add (200, on_config_file_monitor_timeout, self); } } #ifdef GOA_KERBEROS_ENABLED static void -activate_identity_service (GoaDaemon *daemon) +activate_identity_service (GoaDaemon *self) { GoaProvider *provider; @@ -183,7 +183,7 @@ activate_identity_service (GoaDaemon *daemon) #endif static void -goa_daemon_init (GoaDaemon *daemon) +goa_daemon_init (GoaDaemon *self) { static volatile GQuark goa_error_domain = 0; GoaObjectSkeleton *object; @@ -196,20 +196,20 @@ goa_daemon_init (GoaDaemon *daemon) goa_error_domain; /* shut up -Wunused-but-set-variable */ /* TODO: maybe nicer to pass in a GDBusConnection* construct property */ - daemon->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); + self->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); /* Create object manager */ - daemon->object_manager = g_dbus_object_manager_server_new ("/org/gnome/OnlineAccounts"); + self->object_manager = g_dbus_object_manager_server_new ("/org/gnome/OnlineAccounts"); /* Create and export Manager */ - daemon->manager = goa_manager_skeleton_new (); - g_signal_connect (daemon->manager, + self->manager = goa_manager_skeleton_new (); + g_signal_connect (self->manager, "handle-add-account", G_CALLBACK (on_manager_handle_add_account), - daemon); + self); object = goa_object_skeleton_new ("/org/gnome/OnlineAccounts/Manager"); - goa_object_skeleton_set_manager (object, daemon->manager); - g_dbus_object_manager_server_export (daemon->object_manager, G_DBUS_OBJECT_SKELETON (object)); + goa_object_skeleton_set_manager (object, self->manager); + g_dbus_object_manager_server_export (self->object_manager, G_DBUS_OBJECT_SKELETON (object)); g_object_unref (object); /* create ~/.config/goa-1.0 directory */ @@ -222,19 +222,19 @@ goa_daemon_init (GoaDaemon *daemon) /* set up file monitoring */ path = g_strdup_printf ("%s/goa-1.0/accounts.conf", g_get_user_config_dir ()); - daemon->home_conf_file_monitor = create_monitor (path, FALSE); - if (daemon->home_conf_file_monitor != NULL) - g_signal_connect (daemon->home_conf_file_monitor, "changed", G_CALLBACK (on_file_monitor_changed), daemon); + self->home_conf_file_monitor = create_monitor (path, FALSE); + if (self->home_conf_file_monitor != NULL) + g_signal_connect (self->home_conf_file_monitor, "changed", G_CALLBACK (on_file_monitor_changed), self); g_free (path); /* prime the list of accounts */ - goa_daemon_reload_configuration (daemon); + goa_daemon_reload_configuration (self); /* Export objects */ - g_dbus_object_manager_server_set_connection (daemon->object_manager, daemon->connection); + g_dbus_object_manager_server_set_connection (self->object_manager, self->connection); #ifdef GOA_KERBEROS_ENABLED - activate_identity_service (daemon); + activate_identity_service (self); #endif } @@ -331,7 +331,7 @@ key_file_data_new (GKeyFile *key_file, /* ---------------------------------------------------------------------------------------------------- */ static void -add_config_file (GoaDaemon *daemon, +add_config_file (GoaDaemon *self, const gchar *path, GHashTable *group_name_to_key_file_data, GList **key_files_to_free) @@ -363,7 +363,7 @@ add_config_file (GoaDaemon *daemon, gsize num_groups; guint n; - guid = g_dbus_connection_get_guid (daemon->connection); + guid = g_dbus_connection_get_guid (self->connection); groups = g_key_file_get_groups (key_file, &num_groups); for (n = 0; n < num_groups; n++) { @@ -421,7 +421,7 @@ add_config_file (GoaDaemon *daemon, /* returns FALSE if object is not (or no longer) valid */ static gboolean -update_account_object (GoaDaemon *daemon, +update_account_object (GoaDaemon *self, GoaObjectSkeleton *object, const gchar *path, const gchar *group, @@ -439,7 +439,7 @@ update_account_object (GoaDaemon *daemon, gchar *serialized_icon; GError *error; - g_return_val_if_fail (GOA_IS_DAEMON (daemon), FALSE); + g_return_val_if_fail (GOA_IS_DAEMON (self), FALSE); g_return_val_if_fail (G_IS_DBUS_OBJECT_SKELETON (object), FALSE); g_return_val_if_fail (group != NULL, FALSE); g_return_val_if_fail (key_file != NULL, FALSE); @@ -480,7 +480,7 @@ update_account_object (GoaDaemon *daemon, goa_account_set_presentation_identity (account, presentation_identity); error = NULL; - if (!goa_provider_build_object (provider, object, key_file, group, daemon->connection, just_added, &error)) + if (!goa_provider_build_object (provider, object, key_file, group, self->connection, just_added, &error)) { g_warning ("Error parsing account: %s (%s, %d)", error->message, g_quark_to_string (error->domain), error->code); @@ -519,7 +519,7 @@ object_path_to_group (const gchar *object_path) } static void -process_config_entries (GoaDaemon *daemon, +process_config_entries (GoaDaemon *self, GHashTable *group_name_to_key_file_data) { GHashTableIter iter; @@ -535,7 +535,7 @@ process_config_entries (GoaDaemon *daemon, existing_object_paths = NULL; { GList *existing_objects; - existing_objects = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (daemon->object_manager)); + existing_objects = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (self->object_manager)); for (l = existing_objects; l != NULL; l = l->next) { GoaObject *object = GOA_OBJECT (l->data); @@ -579,13 +579,13 @@ process_config_entries (GoaDaemon *daemon, { const gchar *object_path = l->data; GoaObject *object; - object = GOA_OBJECT (g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (daemon->object_manager), object_path)); + object = GOA_OBJECT (g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (self->object_manager), object_path)); g_warn_if_fail (object != NULL); g_signal_handlers_disconnect_by_func (goa_object_peek_account (object), G_CALLBACK (on_account_handle_remove), daemon); g_debug ("removing %s", object_path); - g_warn_if_fail (g_dbus_object_manager_server_unexport (daemon->object_manager, object_path)); + g_warn_if_fail (g_dbus_object_manager_server_unexport (self->object_manager, object_path)); } for (l = added; l != NULL; l = l->next) { @@ -600,22 +600,22 @@ process_config_entries (GoaDaemon *daemon, g_warn_if_fail (key_file_data != NULL); object = goa_object_skeleton_new (object_path); - if (update_account_object (daemon, + if (update_account_object (self, object, key_file_data->path, group, key_file_data->key_file, TRUE)) { - g_dbus_object_manager_server_export (daemon->object_manager, G_DBUS_OBJECT_SKELETON (object)); + g_dbus_object_manager_server_export (self->object_manager, G_DBUS_OBJECT_SKELETON (object)); g_signal_connect (goa_object_peek_account (GOA_OBJECT (object)), "handle-remove", G_CALLBACK (on_account_handle_remove), - daemon); + self); g_signal_connect (goa_object_peek_account (GOA_OBJECT (object)), "handle-ensure-credentials", G_CALLBACK (on_account_handle_ensure_credentials), - daemon); + self); } g_object_unref (object); g_free (group); @@ -632,9 +632,9 @@ process_config_entries (GoaDaemon *daemon, key_file_data = g_hash_table_lookup (group_name_to_key_file_data, group); g_warn_if_fail (key_file_data != NULL); - object = GOA_OBJECT (g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (daemon->object_manager), object_path)); + object = GOA_OBJECT (g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (self->object_manager), object_path)); g_warn_if_fail (object != NULL); - if (!update_account_object (daemon, + if (!update_account_object (self, GOA_OBJECT_SKELETON (object), key_file_data->path, group, @@ -643,11 +643,11 @@ process_config_entries (GoaDaemon *daemon, { g_signal_handlers_disconnect_by_func (goa_object_peek_account (object), G_CALLBACK (on_account_handle_remove), - daemon); + self); g_signal_handlers_disconnect_by_func (goa_object_peek_account (object), G_CALLBACK (on_account_handle_ensure_credentials), - daemon); - g_warn_if_fail (g_dbus_object_manager_server_unexport (daemon->object_manager, object_path)); + self); + g_warn_if_fail (g_dbus_object_manager_server_unexport (self->object_manager, object_path)); } g_object_unref (object); g_free (group); @@ -664,14 +664,14 @@ process_config_entries (GoaDaemon *daemon, /* * goa_daemon_reload_configuration: - * @daemon: A #GoaDaemon + * @self: A #GoaDaemon * * Updates the accounts_objects member from stored configuration - * typically called at startup or when a change on the configuration * files has been detected. */ static void -goa_daemon_reload_configuration (GoaDaemon *daemon) +goa_daemon_reload_configuration (GoaDaemon *self) { GList *key_files_to_free; GHashTable *group_name_to_key_file_data; @@ -685,11 +685,11 @@ goa_daemon_reload_configuration (GoaDaemon *daemon) /* Read the main user config file at $HOME/.config/goa-1.0/accounts.conf */ path = g_strdup_printf ("%s/goa-1.0/accounts.conf", g_get_user_config_dir ()); - add_config_file (daemon, path, group_name_to_key_file_data, &key_files_to_free); + add_config_file (self, path, group_name_to_key_file_data, &key_files_to_free); g_free (path); /* now process the group_name_to_key_file_data hash table */ - process_config_entries (daemon, group_name_to_key_file_data); + process_config_entries (self, group_name_to_key_file_data); g_hash_table_unref (group_name_to_key_file_data); g_list_foreach (key_files_to_free, (GFunc) g_key_file_free, NULL); @@ -697,7 +697,7 @@ goa_daemon_reload_configuration (GoaDaemon *daemon) } static gchar * -generate_new_id (GoaDaemon *daemon) +generate_new_id (GoaDaemon *self) { static guint counter = 0; GDateTime *dt; @@ -915,11 +915,11 @@ on_manager_handle_add_account (GoaManager *manager, GVariant *details, gpointer user_data) { - GoaDaemon *daemon = GOA_DAEMON (user_data); + GoaDaemon *self = GOA_DAEMON (user_data); AddAccountData *data; data = g_slice_new0 (AddAccountData); - data->daemon = g_object_ref (daemon); + data->daemon = g_object_ref (self); data->manager = g_object_ref (manager); data->invocation = g_object_ref (invocation); data->provider_type = g_strdup (provider_type); @@ -940,7 +940,7 @@ on_account_handle_remove (GoaAccount *account, GDBusMethodInvocation *invocation, gpointer user_data) { - GoaDaemon *daemon = GOA_DAEMON (user_data); + GoaDaemon *self = GOA_DAEMON (user_data); GoaProvider *provider; GKeyFile *key_file; const gchar *provider_type; @@ -1037,7 +1037,7 @@ on_account_handle_remove (GoaAccount *account, goto out; } - goa_daemon_reload_configuration (daemon); + goa_daemon_reload_configuration (self); goa_account_complete_remove (account, invocation); @@ -1062,13 +1062,13 @@ typedef struct } EnsureData; static EnsureData * -ensure_data_new (GoaDaemon *daemon, +ensure_data_new (GoaDaemon *self, GoaObject *object, GDBusMethodInvocation *invocation) { EnsureData *data; data = g_slice_new0 (EnsureData); - data->daemon = g_object_ref (daemon); + data->daemon = g_object_ref (self); data->object = g_object_ref (object); data->invocation = invocation; return data; @@ -1156,7 +1156,7 @@ on_account_handle_ensure_credentials (GoaAccount *account, GDBusMethodInvocation *invocation, gpointer user_data) { - GoaDaemon *daemon = GOA_DAEMON (user_data); + GoaDaemon *self = GOA_DAEMON (user_data); GoaProvider *provider = NULL; GoaObject *object; @@ -1177,7 +1177,7 @@ on_account_handle_ensure_credentials (GoaAccount *account, object, NULL, /* GCancellable */ (GAsyncReadyCallback) ensure_credentials_cb, - ensure_data_new (daemon, object, invocation)); + ensure_data_new (self, object, invocation)); out: g_clear_object (&provider); -- 2.1.0 From dec43aa3281420cc8bbb51e70b0db27886d0080a Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Wed, 27 May 2015 17:17:42 +0200 Subject: [PATCH 02/12] daemon: Use G_SOURCE_REMOVE instead of FALSE --- src/daemon/goadaemon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c index 55a576d..a7b2967 100644 --- a/src/daemon/goadaemon.c +++ b/src/daemon/goadaemon.c @@ -144,7 +144,7 @@ on_config_file_monitor_timeout (gpointer user_data) g_info ("Reloading configuration files\n"); goa_daemon_reload_configuration (self); - return FALSE; + return G_SOURCE_REMOVE; } static void -- 2.1.0 From 1e6a783a779efab7524b981c0c164bfa393577ae Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Wed, 27 May 2015 19:07:39 +0200 Subject: [PATCH 03/12] daemon: Use g_clear_object wherever applicable https://bugzilla.gnome.org/show_bug.cgi?id=693578 --- src/daemon/goadaemon.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c index a7b2967..e6a559d 100644 --- a/src/daemon/goadaemon.c +++ b/src/daemon/goadaemon.c @@ -445,6 +445,8 @@ update_account_object (GoaDaemon *self, g_return_val_if_fail (key_file != NULL, FALSE); ret = FALSE; + account = NULL; + provider = NULL; identity = NULL; type = NULL; account = NULL; @@ -499,12 +501,10 @@ update_account_object (GoaDaemon *self, out: g_free (serialized_icon); - if (icon != NULL) - g_object_unref (icon); + g_clear_object (&icon); g_free (name); - if (provider != NULL) - g_object_unref (provider); - g_object_unref (account); + g_clear_object (&provider); + g_clear_object (&account); g_free (type); g_free (identity); g_free (presentation_identity); @@ -1042,8 +1042,7 @@ on_account_handle_remove (GoaAccount *account, goa_account_complete_remove (account, invocation); out: - if (provider != NULL) - g_object_unref (provider); + g_clear_object (&provider); g_free (data); if (key_file != NULL) g_key_file_free (key_file); -- 2.1.0 From 6f91a7a8c3106d4c3e7c11e819e07316cd3aa4c8 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Wed, 27 May 2015 19:11:54 +0200 Subject: [PATCH 04/12] daemon: Use g_list_free_full wherever applicable https://bugzilla.gnome.org/show_bug.cgi?id=693578 --- src/daemon/goadaemon.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c index e6a559d..79d6f26 100644 --- a/src/daemon/goadaemon.c +++ b/src/daemon/goadaemon.c @@ -544,8 +544,7 @@ process_config_entries (GoaDaemon *self, if (g_str_has_prefix (object_path, "/org/gnome/OnlineAccounts/Accounts/")) existing_object_paths = g_list_prepend (existing_object_paths, g_strdup (object_path)); } - g_list_foreach (existing_objects, (GFunc) g_object_unref, NULL); - g_list_free (existing_objects); + g_list_free_full (existing_objects, g_object_unref); } config_object_paths = NULL; @@ -656,10 +655,8 @@ process_config_entries (GoaDaemon *self, g_list_free (removed); g_list_free (added); g_list_free (unchanged); - g_list_foreach (existing_object_paths, (GFunc) g_free, NULL); - g_list_free (existing_object_paths); - g_list_foreach (config_object_paths, (GFunc) g_free, NULL); - g_list_free (config_object_paths); + g_list_free_full (existing_object_paths, g_free); + g_list_free_full (config_object_paths, g_free); } /* @@ -692,8 +689,7 @@ goa_daemon_reload_configuration (GoaDaemon *self) process_config_entries (self, group_name_to_key_file_data); g_hash_table_unref (group_name_to_key_file_data); - g_list_foreach (key_files_to_free, (GFunc) g_key_file_free, NULL); - g_list_free (key_files_to_free); + g_list_free_full (key_files_to_free, (GDestroyNotify) g_key_file_free); } static gchar * -- 2.1.0 From df7b534a62e49be6b32360e01ea19f542b5ea548 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Wed, 27 May 2015 19:13:18 +0200 Subject: [PATCH 05/12] daemon: Remove redundant NULL check https://bugzilla.gnome.org/show_bug.cgi?id=693578 --- src/daemon/goadaemon.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c index 79d6f26..eeb49e6 100644 --- a/src/daemon/goadaemon.c +++ b/src/daemon/goadaemon.c @@ -881,8 +881,7 @@ get_all_providers_cb (GObject *source, out: g_free (object_path); - if (providers != NULL) - g_list_free_full (providers, g_object_unref); + g_list_free_full (providers, g_object_unref); g_free (key_file_data); g_free (group); g_free (id); -- 2.1.0 From e1568184f6e6a18b0a10ff94f18729fd29892edb Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Thu, 28 May 2015 13:26:06 +0200 Subject: [PATCH 06/12] daemon: Remove redundant function call https://bugzilla.gnome.org/show_bug.cgi?id=693578 --- src/daemon/goadaemon.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c index eeb49e6..f933e69 100644 --- a/src/daemon/goadaemon.c +++ b/src/daemon/goadaemon.c @@ -1138,9 +1138,7 @@ ensure_credentials_cb (GoaProvider *provider, g_message ("%s: Setting AttentionNeeded to FALSE because EnsureCredentials() succeded\n", g_dbus_object_get_object_path (G_DBUS_OBJECT (data->object))); } - goa_account_complete_ensure_credentials (goa_object_peek_account (data->object), - data->invocation, - expires_in); + goa_account_complete_ensure_credentials (account, data->invocation, expires_in); } ensure_data_unref (data); } -- 2.1.0 From b8d56056ecb1ddb62c21a9eae90daf97d275b8bf Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Thu, 28 May 2015 15:51:23 +0200 Subject: [PATCH 07/12] daemon: Check & refresh credentials during startup and network changes https://bugzilla.gnome.org/show_bug.cgi?id=693578 --- src/daemon/goadaemon.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 2 deletions(-) diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c index f933e69..efa7ba7 100644 --- a/src/daemon/goadaemon.c +++ b/src/daemon/goadaemon.c @@ -36,11 +36,14 @@ struct _GoaDaemon GFileMonitor *home_conf_file_monitor; GFileMonitor *home_conf_dir_monitor; + GNetworkMonitor *network_monitor; + GDBusObjectManagerServer *object_manager; GoaManager *manager; guint config_timeout_id; + guint credentials_timeout_id; }; typedef struct @@ -71,6 +74,7 @@ static gboolean on_account_handle_ensure_credentials (GoaAccount *acc GDBusMethodInvocation *invocation, gpointer user_data); +static void goa_daemon_check_credentials (GoaDaemon *self); static void goa_daemon_reload_configuration (GoaDaemon *self); G_DEFINE_TYPE (GoaDaemon, goa_daemon, G_TYPE_OBJECT); @@ -85,6 +89,11 @@ goa_daemon_finalize (GObject *object) g_source_remove (self->config_timeout_id); } + if (self->credentials_timeout_id != 0) + { + g_source_remove (self->credentials_timeout_id); + } + if (self->system_conf_dir_monitor != NULL) { g_signal_handlers_disconnect_by_func (self->system_conf_dir_monitor, on_file_monitor_changed, self); @@ -162,6 +171,35 @@ on_file_monitor_changed (GFileMonitor *monitor, } } +static gboolean +on_check_credentials_timeout (gpointer user_data) +{ + GoaDaemon *self = GOA_DAEMON (user_data); + + self->credentials_timeout_id = 0; + g_info ("Checking credentials\n"); + goa_daemon_check_credentials (self); + + return G_SOURCE_REMOVE; +} + +static void +queue_check_credentials (GoaDaemon *self) +{ + if (self->credentials_timeout_id != 0) + { + g_source_remove (self->credentials_timeout_id); + } + + self->credentials_timeout_id = g_timeout_add_seconds (1, on_check_credentials_timeout, self); +} + +static void +on_network_monitor_network_changed (GoaDaemon *self, gboolean available) +{ + queue_check_credentials (self); +} + #ifdef GOA_KERBEROS_ENABLED static void activate_identity_service (GoaDaemon *self) @@ -230,9 +268,18 @@ goa_daemon_init (GoaDaemon *self) /* prime the list of accounts */ goa_daemon_reload_configuration (self); + self->network_monitor = g_network_monitor_get_default (); + g_signal_connect_object (self->network_monitor, + "network-changed", + G_CALLBACK (on_network_monitor_network_changed), + self, + G_CONNECT_SWAPPED); + /* Export objects */ g_dbus_object_manager_server_set_connection (self->object_manager, self->connection); + queue_check_credentials (self); + #ifdef GOA_KERBEROS_ENABLED activate_identity_service (self); #endif @@ -1123,7 +1170,14 @@ ensure_credentials_cb (GoaProvider *provider, error->message, g_quark_to_string (error->domain), error->code); } } - g_dbus_method_invocation_take_error (data->invocation, error); + + if (data->invocation != NULL) + { + g_dbus_method_invocation_take_error (data->invocation, error); + error = NULL; + } + + g_clear_error (&error); } else { @@ -1138,7 +1192,9 @@ ensure_credentials_cb (GoaProvider *provider, g_message ("%s: Setting AttentionNeeded to FALSE because EnsureCredentials() succeded\n", g_dbus_object_get_object_path (G_DBUS_OBJECT (data->object))); } - goa_account_complete_ensure_credentials (account, data->invocation, expires_in); + + if (data->invocation != NULL) + goa_account_complete_ensure_credentials (account, data->invocation, expires_in); } ensure_data_unref (data); } @@ -1175,3 +1231,46 @@ on_account_handle_ensure_credentials (GoaAccount *account, g_clear_object (&provider); return TRUE; /* invocation was handled */ } + +/* + * goa_daemon_check_credentials: + * @self: A #GoaDaemon + * + * Checks whether credentials are valid and tries to refresh them if + * not. It also reports whether accounts are usable with the current + * network. + */ +static void +goa_daemon_check_credentials (GoaDaemon *self) +{ + GList *l; + GList *objects; + + objects = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (self->object_manager)); + for (l = objects; l != NULL; l = l->next) + { + GoaAccount *account; + GoaObject *object = GOA_OBJECT (l->data); + GoaProvider *provider = NULL; + const gchar *provider_type; + + account = goa_object_peek_account (object); + if (account == NULL) + continue; + + provider_type = goa_account_get_provider_type (account); + provider = goa_provider_get_for_provider_type (provider_type); + if (provider == NULL) + continue; + + goa_provider_ensure_credentials (provider, + object, + NULL, /* GCancellable */ + (GAsyncReadyCallback) ensure_credentials_cb, + ensure_data_new (self, object, NULL)); + + g_clear_object (&provider); + } + + g_list_free_full (objects, g_object_unref); +} -- 2.1.0 From f261c93bfddfc96f261a7388d1c46524d408d4e6 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Thu, 28 May 2015 16:20:57 +0200 Subject: [PATCH 08/12] kerberos: Mark EnsureCredentials failures as authorization errors Otherwise GoaAccount:attention-needed won't be set and the UI won't reflect reality. Fall out from 7ba73645e6068935f331969e14d56a39544ebca5 https://bugzilla.gnome.org/show_bug.cgi?id=693578 --- src/goabackend/goakerberosprovider.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/goabackend/goakerberosprovider.c b/src/goabackend/goakerberosprovider.c index 2eb6b67..33dc1ad 100644 --- a/src/goabackend/goakerberosprovider.c +++ b/src/goabackend/goakerberosprovider.c @@ -1406,18 +1406,29 @@ ensure_credentials_sync (GoaProvider *provider, if (identity == NULL || !goa_identity_service_identity_get_is_signed_in (identity)) { + GError *lookup_error; gboolean ticket_synced; + lookup_error = NULL; + g_mutex_unlock (&identity_manager_mutex); ticket_synced = get_ticket_sync (GOA_KERBEROS_PROVIDER (provider), object, FALSE /* Don't allow interaction */, cancellable, - error); + &lookup_error); g_mutex_lock (&identity_manager_mutex); if (!ticket_synced) - goto out; + { + translate_error (&lookup_error); + g_set_error_literal (error, + GOA_ERROR, + GOA_ERROR_NOT_AUTHORIZED, + lookup_error->message); + g_error_free (lookup_error); + goto out; + } if (identity == NULL) identity = get_identity_from_object_manager (GOA_KERBEROS_PROVIDER (provider), -- 2.1.0 From 77f5b03632b779499e29b2e91c55a562c362cfc9 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 29 May 2015 15:40:32 +0200 Subject: [PATCH 09/12] client, identity: Use g_list_free_full wherever applicable https://bugzilla.gnome.org/show_bug.cgi?id=693578 --- src/goa/goaclient.c | 3 +-- src/goaidentity/goakerberosidentitymanager.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/goa/goaclient.c b/src/goa/goaclient.c index 89d52c8..20d6e88 100644 --- a/src/goa/goaclient.c +++ b/src/goa/goaclient.c @@ -471,8 +471,7 @@ goa_client_get_accounts (GoaClient *client) if (goa_object_peek_account (object) != NULL) ret = g_list_prepend (ret, g_object_ref (object)); } - g_list_foreach (objects, (GFunc) g_object_unref, NULL); - g_list_free (objects); + g_list_free_full (objects, g_object_unref); return ret; } diff --git a/src/goaidentity/goakerberosidentitymanager.c b/src/goaidentity/goakerberosidentitymanager.c index a1898c9..162cf3f 100644 --- a/src/goaidentity/goakerberosidentitymanager.c +++ b/src/goaidentity/goakerberosidentitymanager.c @@ -594,8 +594,7 @@ identity_sort_func (GoaIdentity *a, static void free_identity_list (GList *list) { - g_list_foreach (list, (GFunc) g_object_unref, NULL); - g_list_free (list); + g_list_free_full (list, g_object_unref); } static void -- 2.1.0 From 3939e2be726b532dba0debfc3d4b933ae8d54e1a Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 29 May 2015 15:45:10 +0200 Subject: [PATCH 10/12] identity: Simplify the destruction GoaKerberosIdentityQuery doesn't hold any references so there is no need to free the list in dispose. We can use the dummy finalize that we already have and avoid the complexity. https://bugzilla.gnome.org/show_bug.cgi?id=693578 --- src/goaidentity/goakerberosidentityinquiry.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/goaidentity/goakerberosidentityinquiry.c b/src/goaidentity/goakerberosidentityinquiry.c index 7c9a84a..4560b35 100644 --- a/src/goaidentity/goakerberosidentityinquiry.c +++ b/src/goaidentity/goakerberosidentityinquiry.c @@ -102,15 +102,15 @@ goa_kerberos_identity_inquiry_dispose (GObject *object) g_clear_object (&self->priv->identity); g_clear_pointer (&self->priv->name, (GDestroyNotify) g_free); g_clear_pointer (&self->priv->banner, (GDestroyNotify) g_free); - - g_list_foreach (self->priv->queries, - (GFunc) goa_kerberos_identity_query_free, NULL); - g_clear_pointer (&self->priv->queries, (GDestroyNotify) g_list_free); } static void goa_kerberos_identity_inquiry_finalize (GObject *object) { + GoaKerberosIdentityInquiry *self = GOA_KERBEROS_IDENTITY_INQUIRY (object); + + g_list_free_full (self->priv->queries, (GDestroyNotify) goa_kerberos_identity_query_free); + G_OBJECT_CLASS (goa_kerberos_identity_inquiry_parent_class)->finalize (object); } -- 2.1.0 From b7340b085604b291f4f894fe747ab109c19edc03 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 29 May 2015 15:46:09 +0200 Subject: [PATCH 11/12] identity: Chain up during dispose https://bugzilla.gnome.org/show_bug.cgi?id=693578 --- src/goaidentity/goakerberosidentityinquiry.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/goaidentity/goakerberosidentityinquiry.c b/src/goaidentity/goakerberosidentityinquiry.c index 4560b35..67a8a60 100644 --- a/src/goaidentity/goakerberosidentityinquiry.c +++ b/src/goaidentity/goakerberosidentityinquiry.c @@ -102,6 +102,8 @@ goa_kerberos_identity_inquiry_dispose (GObject *object) g_clear_object (&self->priv->identity); g_clear_pointer (&self->priv->name, (GDestroyNotify) g_free); g_clear_pointer (&self->priv->banner, (GDestroyNotify) g_free); + + G_OBJECT_CLASS (goa_kerberos_identity_inquiry_parent_class)->dispose (object); } static void -- 2.1.0 From 59061d81175411c2b38c4d87dfd94b0f3893b765 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 29 May 2015 17:51:33 +0200 Subject: [PATCH 12/12] kerberos: Don't leak the GCancellable --- src/goabackend/goakerberosprovider.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/goabackend/goakerberosprovider.c b/src/goabackend/goakerberosprovider.c index 33dc1ad..69a1c91 100644 --- a/src/goabackend/goakerberosprovider.c +++ b/src/goabackend/goakerberosprovider.c @@ -990,9 +990,10 @@ perform_initial_sign_in (GoaKerberosProvider *self, object); g_simple_async_result_set_check_cancellable (operation_result, cancellable); - g_object_set_data (G_OBJECT (operation_result), - "cancellable", - cancellable); + g_object_set_data_full (G_OBJECT (operation_result), + "cancellable", + g_object_ref (cancellable), + g_object_unref); g_object_set_data (G_OBJECT (operation_result), "principal", (gpointer) @@ -1003,6 +1004,8 @@ perform_initial_sign_in (GoaKerberosProvider *self, (GAsyncReadyCallback) on_system_prompt_open_for_initial_sign_in, operation_result); + + g_object_unref (cancellable); } static char * -- 2.1.0