mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 17:56:17 +01:00
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:
parent
1a6aa9a493
commit
5d0ffe73b7
@ -1538,34 +1538,6 @@ on_new_connection (GDBusServer *server,
|
|||||||
return TRUE;
|
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
|
static void
|
||||||
g_dbus_daemon_finalize (GObject *object)
|
g_dbus_daemon_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
@ -1615,7 +1587,6 @@ initable_init (GInitable *initable,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GDBusDaemon *daemon = G_DBUS_DAEMON (initable);
|
GDBusDaemon *daemon = G_DBUS_DAEMON (initable);
|
||||||
GDBusAuthObserver *observer;
|
|
||||||
GDBusServerFlags flags;
|
GDBusServerFlags flags;
|
||||||
|
|
||||||
flags = G_DBUS_SERVER_FLAGS_NONE;
|
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->tmpdir = g_dir_make_tmp ("gdbus-daemon-XXXXXX", NULL);
|
||||||
daemon->address = g_strdup_printf ("unix:tmpdir=%s", daemon->tmpdir);
|
daemon->address = g_strdup_printf ("unix:tmpdir=%s", daemon->tmpdir);
|
||||||
}
|
}
|
||||||
|
flags |= G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER;
|
||||||
#else
|
#else
|
||||||
|
/* Don’t require authentication on Windows as that hasn’t been
|
||||||
|
* implemented yet. */
|
||||||
daemon->address = g_strdup ("nonce-tcp:");
|
daemon->address = g_strdup ("nonce-tcp:");
|
||||||
flags |= G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS;
|
flags |= G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
observer = g_dbus_auth_observer_new ();
|
|
||||||
daemon->server = g_dbus_server_new_sync (daemon->address,
|
daemon->server = g_dbus_server_new_sync (daemon->address,
|
||||||
flags,
|
flags,
|
||||||
daemon->guid,
|
daemon->guid,
|
||||||
observer,
|
NULL,
|
||||||
cancellable,
|
cancellable,
|
||||||
error);
|
error);
|
||||||
if (daemon->server == NULL)
|
if (daemon->server == NULL)
|
||||||
{
|
return FALSE;
|
||||||
g_object_unref (observer);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
g_dbus_server_start (daemon->server);
|
g_dbus_server_start (daemon->server);
|
||||||
@ -1654,12 +1624,6 @@ initable_init (GInitable *initable,
|
|||||||
g_signal_connect (daemon->server, "new-connection",
|
g_signal_connect (daemon->server, "new-connection",
|
||||||
G_CALLBACK (on_new_connection),
|
G_CALLBACK (on_new_connection),
|
||||||
daemon);
|
daemon);
|
||||||
g_signal_connect (observer,
|
|
||||||
"authorize-authenticated-peer",
|
|
||||||
G_CALLBACK (on_authorize_authenticated_peer),
|
|
||||||
daemon);
|
|
||||||
|
|
||||||
g_object_unref (observer);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user