[glib: 1/2] gdbus-tool: Require message bus connections for most commands



commit 177851c9b7857a4860c5653137a656503c6e7be7
Author: Philip Withnall <withnall endlessm com>
Date:   Mon Jun 17 14:52:12 2019 +0100

    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 <withnall endlessm com>
    
    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)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]