[Xfce4-commits] <terminal:master> Add display check in D-Bus API (bug #6414).

Nick Schermer noreply at xfce.org
Tue Apr 27 19:54:01 CEST 2010


Updating branch refs/heads/master
         to 9ed0e8a940f624dfb64a1a7e9b321db564fe7c64 (commit)
       from 04fa0e5a36c2b4f75125c586a78b923e5f169f7b (commit)

commit 9ed0e8a940f624dfb64a1a7e9b321db564fe7c64
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Apr 27 19:29:27 2010 +0200

    Add display check in D-Bus API (bug #6414).
    
    Add check in D-Bus messge to make sure the terminal does not
    attach to another instance on a different display. This to avoid
    craches if the display the service is running on is closed.
    
    D-Bus version had been increased to 4.

 configure.ac.in               |    2 +-
 terminal/main.c               |    8 ++++++--
 terminal/terminal-app.h       |    2 ++
 terminal/terminal-config.h.in |    1 +
 terminal/terminal-dbus.c      |   21 +++++++++++++++++++++
 5 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/configure.ac.in b/configure.ac.in
index 2702782..a0ffee8 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -14,7 +14,7 @@ m4_define([terminal_version_micro], [4])
 m4_define([terminal_version_nano], [])
 m4_define([terminal_version_build], [@REVISION@])
 m4_define([terminal_version_tag], [git])
-m4_define([terminal_version_dbus], [3])
+m4_define([terminal_version_dbus], [4])
 m4_define([terminal_version], [terminal_version_major().terminal_version_minor().terminal_version_micro()ifelse(terminal_version_nano(), [], [], [.terminal_version_nano()])ifelse(terminal_version_tag(), [git], [terminal_version_tag()-terminal_version_build()], [terminal_version_tag()])])
 
 dnl *******************************************
diff --git a/terminal/main.c b/terminal/main.c
index cf78da2..80e0155 100644
--- a/terminal/main.c
+++ b/terminal/main.c
@@ -197,12 +197,16 @@ main (int argc, char **argv)
       else
         {
           if (error->domain == TERMINAL_ERROR
-              && error->code == TERMINAL_ERROR_USER_MISMATCH)
+              && (error->code == TERMINAL_ERROR_USER_MISMATCH
+                  || error->code == TERMINAL_ERROR_DISPLAY_MISMATCH))
             {
               /* don't try to establish another service here */
               disable_server = TRUE;
+
 #ifndef NDEBUG
-              g_debug ("User mismatch when invoking remote terminal: %s", error->message);
+              g_debug ("%s mismatch when invoking remote terminal: %s",
+                       error->code == TERMINAL_ERROR_USER_MISMATCH ? "User" : "Display",
+                       error->message);
 #endif
             }
           else if (error->domain == TERMINAL_ERROR
diff --git a/terminal/terminal-app.h b/terminal/terminal-app.h
index e949734..0971c81 100644
--- a/terminal/terminal-app.h
+++ b/terminal/terminal-app.h
@@ -36,6 +36,8 @@ enum _TerminalError
   TERMINAL_ERROR_LINKER_FAILURE,
   /* different user id in service */
   TERMINAL_ERROR_USER_MISMATCH,
+  /* different display in service */
+  TERMINAL_ERROR_DISPLAY_MISMATCH,
   /* parsing the options failed */
   TERMINAL_ERROR_OPTIONS,
   /* general failure */
diff --git a/terminal/terminal-config.h.in b/terminal/terminal-config.h.in
index cbddbd4..28fade4 100644
--- a/terminal/terminal-config.h.in
+++ b/terminal/terminal-config.h.in
@@ -29,6 +29,7 @@ G_BEGIN_DECLS
 #define TERMINAL_DBUS_INTERFACE     "org.xfce.Terminal at TERMINAL_VERSION_DBUS@"
 #define TERMINAL_DBUS_SERVICE       "org.xfce.Terminal at TERMINAL_VERSION_DBUS@"
 #define TERMINAL_DBUS_ERROR_USER    "org.xfce.Terminal at TERMINAL_VERSION_DBUS@.ErrorUser"
+#define TERMINAL_DBUS_ERROR_DISPLAY "org.xfce.Terminal at TERMINAL_VERSION_DBUS@.ErrorDisplay"
 #define TERMINAL_DBUS_ERROR_GENERAL "org.xfce.Terminal at TERMINAL_VERSION_DBUS@.ErrorGeneral"
 #define TERMINAL_DBUS_ERROR_OPTIONS "org.xfce.Terminal at TERMINAL_VERSION_DBUS@.ErrorOptions"
 #define TERMINAL_DBUS_PATH          "/org/xfce/Terminal"
diff --git a/terminal/terminal-dbus.c b/terminal/terminal-dbus.c
index 9f80774..7bd203e 100644
--- a/terminal/terminal-dbus.c
+++ b/terminal/terminal-dbus.c
@@ -61,6 +61,7 @@ handle_message (DBusConnection *connection,
   dbus_int64_t user_id;
   gchar      **argv;
   gint         argc;
+  gchar       *display_name;
 
   /* The D-BUS interface currently looks like this:
    *
@@ -70,6 +71,10 @@ handle_message (DBusConnection *connection,
    *  - UserId:int64
    *    This is the real user id of the calling process.
    *
+   *  - DisplayName:string
+   *    Name of the display the service is running on, this to prevent
+   *    craching terminals if a display is disconnected.
+   *
    *  - Arguments:string array
    *    The argument array as passed to main(), with some
    *    additions.
@@ -93,6 +98,7 @@ handle_message (DBusConnection *connection,
       /* query the list of arguments to this call */
       if (!dbus_message_get_args (message, &derror,
                                   DBUS_TYPE_INT64, &user_id,
+                                  DBUS_TYPE_STRING, &display_name,
                                   DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &argv, &argc,
                                   DBUS_TYPE_INVALID))
         {
@@ -106,6 +112,12 @@ handle_message (DBusConnection *connection,
                                           TERMINAL_DBUS_ERROR_USER,
                                           _("User id mismatch"));
         }
+      else if (!exo_str_is_equal (display_name, g_getenv ("DISPLAY")))
+        {
+          reply = dbus_message_new_error (message,
+                                          TERMINAL_DBUS_ERROR_DISPLAY,
+                                          _("Display mismatch"));
+        }
       else if (!terminal_app_process (app, argv, argc, &error))
         {
           reply = dbus_message_new_error (message,
@@ -225,6 +237,7 @@ terminal_dbus_invoke_launch (gint     argc,
   DBusError       derror;
   gint            code;
   gboolean        retval = TRUE;
+  const gchar    *display_name;
 
   terminal_return_val_if_fail (argc > 0, FALSE);
   terminal_return_val_if_fail (argv != NULL, FALSE);
@@ -249,12 +262,18 @@ terminal_dbus_invoke_launch (gint     argc,
 
   uid = getuid ();
 
+  display_name = g_getenv ("DISPLAY");
+  if (G_UNLIKELY (display_name == NULL))
+    display_name = "";
+
   dbus_message_append_args (message,
 #ifdef DBUS_USE_NEW_API
                             DBUS_TYPE_INT64, &uid,
+                            DBUS_TYPE_STRING, &display_name,
                             DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &argv, argc,
 #else
                             DBUS_TYPE_INT64, uid,
+                            DBUS_TYPE_STRING, display_name,
                             DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, argv, argc,
 #endif
                             DBUS_TYPE_INVALID);
@@ -270,6 +289,8 @@ terminal_dbus_invoke_launch (gint     argc,
 set_error:
       if (dbus_error_has_name (&derror, TERMINAL_DBUS_ERROR_USER))
         code = TERMINAL_ERROR_USER_MISMATCH;
+      if (dbus_error_has_name (&derror, TERMINAL_DBUS_ERROR_DISPLAY))
+        code = TERMINAL_ERROR_DISPLAY_MISMATCH;
       else if (dbus_error_has_name (&derror, TERMINAL_DBUS_ERROR_OPTIONS))
         code = TERMINAL_ERROR_OPTIONS;
       else



More information about the Xfce4-commits mailing list