From 5d0ffe73b76288bd43f01ea2b20416d646c5dca3 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 15 Dec 2020 13:01:38 +0000 Subject: [PATCH] gdbusdaemon: Use require-same-user flag to avoid auth observer signal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This doesn’t change the `GDBusDaemon` behaviour, but does simplify the code a little. Signed-off-by: Philip Withnall Helps: #1804 --- gio/gdbusdaemon.c | 46 +++++----------------------------------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/gio/gdbusdaemon.c b/gio/gdbusdaemon.c index ef902d65a..5dfe62cd3 100644 --- a/gio/gdbusdaemon.c +++ b/gio/gdbusdaemon.c @@ -1538,34 +1538,6 @@ on_new_connection (GDBusServer *server, return TRUE; } -static gboolean -on_authorize_authenticated_peer (GDBusAuthObserver *observer, - GIOStream *stream, - GCredentials *credentials, - gpointer user_data) -{ - gboolean authorized = FALSE; - - if (credentials != NULL) - { - GCredentials *own_credentials; - - own_credentials = g_credentials_new (); - authorized = g_credentials_is_same_user (credentials, own_credentials, NULL); - g_object_unref (own_credentials); - } -#ifdef G_OS_WIN32 - else - { - /* We allow ANONYMOUS authentication on Windows for now, in - * combination with the nonce-tcp transport. */ - authorized = TRUE; - } -#endif - - return authorized; -} - static void g_dbus_daemon_finalize (GObject *object) { @@ -1615,7 +1587,6 @@ initable_init (GInitable *initable, GError **error) { GDBusDaemon *daemon = G_DBUS_DAEMON (initable); - GDBusAuthObserver *observer; GDBusServerFlags flags; flags = G_DBUS_SERVER_FLAGS_NONE; @@ -1629,24 +1600,23 @@ initable_init (GInitable *initable, daemon->tmpdir = g_dir_make_tmp ("gdbus-daemon-XXXXXX", NULL); daemon->address = g_strdup_printf ("unix:tmpdir=%s", daemon->tmpdir); } + flags |= G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER; #else + /* Don’t require authentication on Windows as that hasn’t been + * implemented yet. */ daemon->address = g_strdup ("nonce-tcp:"); flags |= G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS; #endif } - observer = g_dbus_auth_observer_new (); daemon->server = g_dbus_server_new_sync (daemon->address, flags, daemon->guid, - observer, + NULL, cancellable, error); if (daemon->server == NULL) - { - g_object_unref (observer); - return FALSE; - } + return FALSE; g_dbus_server_start (daemon->server); @@ -1654,12 +1624,6 @@ initable_init (GInitable *initable, g_signal_connect (daemon->server, "new-connection", G_CALLBACK (on_new_connection), daemon); - g_signal_connect (observer, - "authorize-authenticated-peer", - G_CALLBACK (on_authorize_authenticated_peer), - daemon); - - g_object_unref (observer); return TRUE; }