From 177851c9b7857a4860c5653137a656503c6e7be7 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 17 Jun 2019 14:52:12 +0100 Subject: [PATCH] gdbus-tool: Require message bus connections for most commands Previously, if the `--address` option was passed to `gdbus-tool`, it would treat the connection as peer to peer. However, almost all the commands `gdbus-tool` supports require a message bus (introspection, calling a method with a destination, etc.). Only the `signal` command would ever work on a peer-to-peer connection (if no `--dest` was specified). So change the `--address` option to generally create message bus connections. Signed-off-by: Philip Withnall Fixes: #938 --- gio/gdbus-tool.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/gio/gdbus-tool.c b/gio/gdbus-tool.c index 57978f1c2..863a5e80a 100644 --- a/gio/gdbus-tool.c +++ b/gio/gdbus-tool.c @@ -414,7 +414,8 @@ connection_get_group (void) } static GDBusConnection * -connection_get_dbus_connection (GError **error) +connection_get_dbus_connection (gboolean require_message_bus, + GError **error) { GDBusConnection *c; @@ -450,8 +451,11 @@ connection_get_dbus_connection (GError **error) } else if (opt_connection_address != NULL) { + GDBusConnectionFlags flags = G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT; + if (require_message_bus) + flags |= G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION; c = g_dbus_connection_new_for_address_sync (opt_connection_address, - G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT, + flags, NULL, /* GDBusAuthObserver */ NULL, /* GCancellable */ error); @@ -649,7 +653,7 @@ handle_emit (gint *argc, } error = NULL; - c = connection_get_dbus_connection (&error); + c = connection_get_dbus_connection ((opt_emit_dest != NULL), &error); if (c == NULL) { if (request_completion) @@ -956,7 +960,7 @@ handle_call (gint *argc, } error = NULL; - c = connection_get_dbus_connection (&error); + c = connection_get_dbus_connection (TRUE, &error); if (c == NULL) { if (request_completion) @@ -1750,7 +1754,7 @@ handle_introspect (gint *argc, } error = NULL; - c = connection_get_dbus_connection (&error); + c = connection_get_dbus_connection (TRUE, &error); if (c == NULL) { if (request_completion) @@ -1982,7 +1986,7 @@ handle_monitor (gint *argc, } error = NULL; - c = connection_get_dbus_connection (&error); + c = connection_get_dbus_connection (TRUE, &error); if (c == NULL) { if (request_completion) @@ -2202,7 +2206,7 @@ handle_wait (gint *argc, } error = NULL; - c = connection_get_dbus_connection (&error); + c = connection_get_dbus_connection (TRUE, &error); if (c == NULL) { if (request_completion)