From 95be983f7221ee560fd6278771af2ec831cc90da Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Tue, 20 Oct 2020 19:46:11 +0200 Subject: kerberos-identity-manager: Shuffle some code around A subsequent commit will start using notifications from Kerberos KCM credential caches as supported by the KCM implementation in SSSD. This rearranges the code to make it easier to enable notifications for different credential cache types. https://gitlab.gnome.org/GNOME/gnome-online-accounts/-/merge_requests/61 --- src/goaidentity/goakerberosidentitymanager.c | 57 +++++++++++++--------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/src/goaidentity/goakerberosidentitymanager.c b/src/goaidentity/goakerberosidentitymanager.c index aa38761..7a676bd 100644 --- a/src/goaidentity/goakerberosidentitymanager.c +++ b/src/goaidentity/goakerberosidentitymanager.c @@ -1379,7 +1379,6 @@ monitor_credentials_cache (GoaKerberosIdentityManager *self, GFileMonitor *monitor = NULL; krb5_error_code error_code; GError *monitoring_error = NULL; - gboolean can_monitor = TRUE; error_code = krb5_cc_default (self->kerberos_context, &default_cache); @@ -1400,13 +1399,6 @@ monitor_credentials_cache (GoaKerberosIdentityManager *self, cache_type = krb5_cc_get_type (self->kerberos_context, default_cache); g_assert (cache_type != NULL); - if (strcmp (cache_type, "FILE") != 0 && strcmp (cache_type, "DIR") != 0) - { - g_warning ("GoaKerberosIdentityManager: Using polling for change notification for credential cache type '%s'", - cache_type); - can_monitor = FALSE; - } - g_free (self->credentials_cache_type); self->credentials_cache_type = g_strdup (cache_type); @@ -1428,38 +1420,41 @@ monitor_credentials_cache (GoaKerberosIdentityManager *self, if (cache_path[0] == ':') cache_path++; - if (can_monitor) + if (strcmp (cache_type, "FILE") == 0) { GFile *file; file = g_file_new_for_path (cache_path); monitoring_error = NULL; - if (strcmp (cache_type, "FILE") == 0) - { - monitor = g_file_monitor_file (file, - G_FILE_MONITOR_NONE, - NULL, - &monitoring_error); - } - else if (strcmp (cache_type, "DIR") == 0) - { - GFile *directory; + monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &monitoring_error); - directory = g_file_get_parent (file); - monitor = g_file_monitor_directory (directory, - G_FILE_MONITOR_NONE, - NULL, - &monitoring_error); - g_object_unref (directory); + g_object_unref (file); + } + else if (strcmp (cache_type, "DIR") == 0) + { + GFile *directory; + GFile *file; - } + file = g_file_new_for_path (cache_path); + directory = g_file_get_parent (file); + + monitoring_error = NULL; + monitor = g_file_monitor_directory (directory, G_FILE_MONITOR_NONE, NULL, &monitoring_error); + + g_object_unref (directory); g_object_unref (file); } if (monitor == NULL) { - if (monitoring_error != NULL) + if (monitoring_error == NULL) + { + g_warning ("GoaKerberosIdentityManager: Using polling for change notification for credential " + "cache type '%s'", + cache_type); + } + else { g_warning ("GoaKerberosIdentityManager: Could not monitor credentials for %s (type %s), reverting to " "polling: %s", @@ -1468,7 +1463,10 @@ monitor_credentials_cache (GoaKerberosIdentityManager *self, monitoring_error != NULL? monitoring_error->message : ""); g_clear_error (&monitoring_error); } - can_monitor = FALSE; + + self->polling_timeout_id = g_timeout_add_seconds (FALLBACK_POLLING_INTERVAL, + (GSourceFunc) on_polling_timeout, + self); } else { @@ -1476,9 +1474,6 @@ monitor_credentials_cache (GoaKerberosIdentityManager *self, self->credentials_cache_monitor = monitor; } - if (!can_monitor) - self->polling_timeout_id = g_timeout_add_seconds (FALLBACK_POLLING_INTERVAL, (GSourceFunc) on_polling_timeout, self); - krb5_cc_close (self->kerberos_context, default_cache); return TRUE; -- cgit v1.2.1