diff options
author | Daniel Carl <danielcarl@gmx.de> | 2018-10-08 23:31:10 +0200 |
---|---|---|
committer | Daniel Carl <danielcarl@gmx.de> | 2018-10-08 23:59:07 +0200 |
commit | 4f3af00ca1a0b4450f8b05bdb181d9cf531096de (patch) | |
tree | dbefad5d0304552c9a2120d32d228724c33cb419 /src | |
parent | 10a1bf450927aba9e2910b1d8e58cf25477f8dd2 (diff) |
Use glib example code for dbus auth observer #438.
Diffstat (limited to 'src')
-rw-r--r-- | src/ext-proxy.c | 26 | ||||
-rw-r--r-- | src/webextension/ext-main.c | 27 |
2 files changed, 27 insertions, 26 deletions
diff --git a/src/ext-proxy.c b/src/ext-proxy.c index e69cbeb..da00a3b 100644 --- a/src/ext-proxy.c +++ b/src/ext-proxy.c @@ -95,23 +95,23 @@ out: static gboolean on_authorize_authenticated_peer(GDBusAuthObserver *observer, GIOStream *stream, GCredentials *credentials, gpointer data) { - static GCredentials *own_credentials = NULL; - GError *error = NULL; + gboolean authorized = FALSE; - if (!own_credentials) { - own_credentials = g_credentials_new(); - } - - if (credentials && g_credentials_is_same_user(credentials, own_credentials, &error)) { - return TRUE; - } + if (credentials) { + GCredentials *own_credentials; - if (error) { - g_warning("Failed to authorize web extension connection: %s", error->message); - g_error_free(error); + GError *error = NULL; + own_credentials = g_credentials_new(); + if (g_credentials_is_same_user(credentials, own_credentials, &error)) { + authorized = TRUE; + } else { + g_warning("Failed to authorize web extension connection: %s", error->message); + g_error_free(error); + } + g_object_unref(own_credentials); } - return FALSE; + return authorized; } static gboolean on_new_connection(GDBusServer *server, diff --git a/src/webextension/ext-main.c b/src/webextension/ext-main.c index ccfe6aa..b7c3108 100644 --- a/src/webextension/ext-main.c +++ b/src/webextension/ext-main.c @@ -136,23 +136,24 @@ void webkit_web_extension_initialize_with_user_data(WebKitWebExtension *extensio static gboolean on_authorize_authenticated_peer(GDBusAuthObserver *observer, GIOStream *stream, GCredentials *credentials, gpointer extension) { - static GCredentials *own_credentials = NULL; - GError *error = NULL; + gboolean authorized = FALSE; + if (credentials) { + GCredentials *own_credentials; - if (!own_credentials) { + GError *error = NULL; own_credentials = g_credentials_new(); + if (g_credentials_is_same_user(credentials, own_credentials, &error)) { + authorized = TRUE; + } else { + g_warning("Failed to authorize web extension connection: %s", error->message); + g_error_free(error); + } + g_object_unref(own_credentials); + } else { + g_warning ("No credentials received from UI process.\n"); } - if (credentials && g_credentials_is_same_user(credentials, own_credentials, &error)) { - return TRUE; - } - - if (error) { - g_warning("Failed to authorize connection to ui: %s", error->message); - g_error_free(error); - } - - return FALSE; + return authorized; } static void on_dbus_connection_created(GObject *source_object, |