gdbusdaemon: Use require-same-user flag to avoid auth observer signal

This doesn’t change the `GDBusDaemon` behaviour, but does simplify the
code a little.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1804
This commit is contained in:
Philip Withnall 2020-12-15 13:01:38 +00:00
parent 1a6aa9a493
commit 5d0ffe73b7

View File

@ -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
/* Dont require authentication on Windows as that hasnt 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;
}