]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Check the version of the X server we are running so we correctly pass -listen tcp...
authorRobert Ancell <robert.ancell@canonical.com>
Wed, 14 Oct 2015 16:00:30 +0000 (17:00 +0100)
committerRobert Ancell <robert.ancell@canonical.com>
Wed, 14 Oct 2015 16:00:30 +0000 (17:00 +0100)
Also add tests for xserver-allow-tcp function and check in all cases we are listening on tcp/unix only when appropriate.

14 files changed:
src/x-server-local.c
src/x-server-local.h
tests/Makefile.am
tests/scripts/allow-tcp-xorg-1.16.conf [new file with mode: 0644]
tests/scripts/allow-tcp-xorg-1.17.conf [new file with mode: 0644]
tests/scripts/xdmcp-client.conf
tests/scripts/xdmcp-server-autologin.conf
tests/scripts/xdmcp-server-double-login.conf
tests/scripts/xdmcp-server-guest.conf
tests/scripts/xdmcp-server-login.conf
tests/scripts/xdmcp-server-open-file-descriptors.conf
tests/src/X.c
tests/test-allow-tcp-xorg-1.16 [new file with mode: 0755]
tests/test-allow-tcp-xorg-1.17 [new file with mode: 0755]

index caff9b46e685c1c009423b7aca6ef8d62bc344cf..d9b039823c46797772ea3d12cd48b5aad77d5555 100644 (file)
@@ -74,8 +74,65 @@ struct XServerLocalPrivate
 
 G_DEFINE_TYPE (XServerLocal, x_server_local, X_SERVER_TYPE);
 
+static gchar *version = NULL;
+static guint version_major = 0, version_minor = 0;
 static GList *display_numbers = NULL;
 
+#define XORG_VERSION_PREFIX "X.Org X Server "
+
+static gchar *
+find_version (const gchar *line)
+{
+    if (!g_str_has_prefix (line, XORG_VERSION_PREFIX))
+        return NULL;
+
+    return g_strdup (line + strlen (XORG_VERSION_PREFIX));
+}
+
+const gchar *
+x_server_local_get_version (void)
+{
+    gchar *stderr_text;
+    gint exit_status;
+    gchar **tokens;
+    guint n_tokens;
+
+    if (version)
+        return version;
+
+    if (!g_spawn_command_line_sync ("X -version", NULL, &stderr_text, &exit_status, NULL))
+        return NULL;
+    if (exit_status == EXIT_SUCCESS)
+    {
+        gchar **lines;
+        int i;
+
+        lines = g_strsplit (stderr_text, "\n", -1);
+        for (i = 0; lines[i] && !version; i++)
+            version = find_version (lines[i]);
+        g_strfreev (lines);
+    }
+    g_free (stderr_text);
+
+    tokens = g_strsplit (version, ".", 3);
+    n_tokens = g_strv_length (tokens);
+    version_major = n_tokens > 0 ? atoi (tokens[0]) : 0;
+    version_minor = n_tokens > 1 ? atoi (tokens[1]) : 0;
+    g_strfreev (tokens);
+
+    return version;
+}
+
+gint
+x_server_local_version_compare (guint major, guint minor)
+{
+    x_server_local_get_version ();
+    if (major == version_major)
+        return version_minor - minor;
+    else
+        return version_major - major;
+}
+
 static gboolean
 display_number_in_use (guint display_number)
 {
@@ -483,7 +540,12 @@ x_server_local_start (DisplayServer *display_server)
         if (server->priv->xdmcp_key)
             g_string_append_printf (command, " -cookie %s", server->priv->xdmcp_key);
     }
-    else if (!server->priv->allow_tcp)
+    else if (server->priv->allow_tcp)
+    {
+        if (x_server_local_version_compare (1, 17) >= 0)
+            g_string_append (command, " -listen tcp");
+    }
+    else
         g_string_append (command, " -nolisten tcp");
 
     if (server->priv->vt >= 0)
index 7ed5732c86193bbc9ae59a4f49151491e30e3175..e20a86cd2e116edcf2c7039a5c9e119df694540a 100644 (file)
@@ -33,6 +33,10 @@ typedef struct
     XServerClass parent_class;
 } XServerLocalClass;
 
+const gchar *x_server_local_get_version (void);
+
+gint x_server_local_version_compare (guint major, guint minor);
+
 guint x_server_local_get_unused_display_number (void);
 
 void x_server_local_release_display_number (guint display_number);
index 11c97287e8ebafa6fc3d67d9bd493d9d17af3bc4..9c2241d0bfe50c968416d32b272c2550591f5441 100644 (file)
@@ -34,6 +34,8 @@ TESTS = \
        test-autologin-new-authtok \
        test-autologin-timeout-gobject \
        test-autologin-guest-timeout-gobject \
+       test-allow-tcp-xorg-1.16 \
+       test-allow-tcp-xorg-1.17 \    
        test-change-authentication \
        test-restart-authentication \
        test-cancel-authentication-gobject \
@@ -367,6 +369,8 @@ EXTRA_DIST = \
        scripts/additional-config-priority.conf \
        scripts/additional-system-config.conf \
        scripts/additional-system-config-priority.conf \
+       scripts/allow-tcp-xorg-1.16.conf \
+       scripts/allow-tcp-xorg-1.17.conf \    
        scripts/audit-autologin.conf \
        scripts/autologin.conf \
        scripts/autologin-guest.conf \
diff --git a/tests/scripts/allow-tcp-xorg-1.16.conf b/tests/scripts/allow-tcp-xorg-1.16.conf
new file mode 100644 (file)
index 0000000..bd6341a
--- /dev/null
@@ -0,0 +1,34 @@
+#
+# Check can enable TCP listening in X.Org < 1.17 (default is listening enabled)
+#
+
+[test-xserver-config]
+version=1.16.0
+
+[Seat:*]
+autologin-user=have-password1
+user-session=default
+xserver-allow-tcp=true
+
+#?*START-DAEMON
+#?RUNNER DAEMON-START
+
+# X server starts
+#?XSERVER-0 START VT=7 LISTEN-TCP SEAT=seat0
+
+# Daemon connects when X server is ready
+#?*XSERVER-0 INDICATE-READY
+#?XSERVER-0 INDICATE-READY
+#?XSERVER-0 ACCEPT-CONNECT
+
+# Session starts
+#?SESSION-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_GREETER_DATA_DIR=.*/have-password1 XDG_SESSION_TYPE=x11 XDG_SESSION_DESKTOP=default USER=have-password1
+#?LOGIN1 ACTIVATE-SESSION SESSION=c0
+#?XSERVER-0 ACCEPT-CONNECT
+#?SESSION-X-0 CONNECT-XSERVER
+
+# Cleanup
+#?*STOP-DAEMON
+#?SESSION-X-0 TERMINATE SIGNAL=15
+#?XSERVER-0 TERMINATE SIGNAL=15
+#?RUNNER DAEMON-EXIT STATUS=0
diff --git a/tests/scripts/allow-tcp-xorg-1.17.conf b/tests/scripts/allow-tcp-xorg-1.17.conf
new file mode 100644 (file)
index 0000000..14b5915
--- /dev/null
@@ -0,0 +1,34 @@
+#
+# Check can enable TCP listening in X.Org >= 1.17 (default is listening disabled)
+#
+
+[test-xserver-config]
+version=1.17.0
+
+[Seat:*]
+autologin-user=have-password1
+user-session=default
+xserver-allow-tcp=true
+
+#?*START-DAEMON
+#?RUNNER DAEMON-START
+
+# X server starts
+#?XSERVER-0 START VT=7 LISTEN-TCP SEAT=seat0
+
+# Daemon connects when X server is ready
+#?*XSERVER-0 INDICATE-READY
+#?XSERVER-0 INDICATE-READY
+#?XSERVER-0 ACCEPT-CONNECT
+
+# Session starts
+#?SESSION-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_GREETER_DATA_DIR=.*/have-password1 XDG_SESSION_TYPE=x11 XDG_SESSION_DESKTOP=default USER=have-password1
+#?LOGIN1 ACTIVATE-SESSION SESSION=c0
+#?XSERVER-0 ACCEPT-CONNECT
+#?SESSION-X-0 CONNECT-XSERVER
+
+# Cleanup
+#?*STOP-DAEMON
+#?SESSION-X-0 TERMINATE SIGNAL=15
+#?XSERVER-0 TERMINATE SIGNAL=15
+#?RUNNER DAEMON-EXIT STATUS=0
index b24860a9c6ab6ca78a77dfe2efbe8854251b22c6..f29bb41cd0e5ffea3da835c3a68eea5b270c773d 100644 (file)
@@ -9,7 +9,7 @@ xdmcp-manager=127.0.0.1
 #?RUNNER DAEMON-START
 
 # X server starts
-#?XSERVER-0 START VT=7 SEAT=seat0
+#?XSERVER-0 START VT=7 LISTEN-TCP SEAT=seat0
 #?*XSERVER-0 INDICATE-READY
 #?XSERVER-0 INDICATE-READY
 #?XSERVER-0 ACCEPT-CONNECT
index dd7a9502bc4774a3dcb48157b013eb7b27e1d41c..92a45f1dccb58c9a57801502f453ff7cc7ef479c 100644 (file)
@@ -18,7 +18,7 @@ autologin-user=have-password1
 
 # Start a remote X server to log in with XDMCP
 #?*START-XSERVER ARGS=":98 -query 127.0.0.1 -nolisten unix"
-#?XSERVER-98 START
+#?XSERVER-98 START LISTEN-TCP NO-LISTEN-UNIX
 
 # Start sending XDMCP queries
 #?*XSERVER-98 START-XDMCP
index 552f4be78118b97312909a1cbe730db3ecd473f9..bc3acdbeba5aa9eb64bb3d7d35f8becf612ead7c 100644 (file)
@@ -17,7 +17,7 @@ user-session=default
 
 # Start a remote X server to log in with XDMCP
 #?*START-XSERVER ARGS=":98 -query 127.0.0.1 -nolisten unix"
-#?XSERVER-98 START
+#?XSERVER-98 START LISTEN-TCP NO-LISTEN-UNIX
 
 # Start sending XDMCP queries
 #?*XSERVER-98 START-XDMCP
@@ -56,7 +56,7 @@ user-session=default
 
 # Start a second remote X server to log in with XDMCP
 #?*START-XSERVER ARGS=":99 -query 127.0.0.1 -nolisten unix"
-#?XSERVER-99 START
+#?XSERVER-99 START LISTEN-TCP NO-LISTEN-UNIX
 
 # Start sending XDMCP queries
 #?*XSERVER-99 START-XDMCP
index 1fb8869fb601c5283510d5f77622986e621b1fbe..6f5301dee7e4a99b9112690ba523ef065517b54a 100644 (file)
@@ -17,7 +17,7 @@ user-session=default
 
 # Start a remote X server to log in with XDMCP
 #?*START-XSERVER ARGS=":98 -query 127.0.0.1 -nolisten unix"
-#?XSERVER-98 START
+#?XSERVER-98 START LISTEN-TCP NO-LISTEN-UNIX
 
 # Start sending XDMCP queries
 #?*XSERVER-98 START-XDMCP
index c73f855d953787a8387d5ebfe84efb878e1f61bc..fb3f809042f9b2fe07db3ab9a21ef2036a959bea 100644 (file)
@@ -17,7 +17,7 @@ user-session=default
 
 # Start a remote X server to log in with XDMCP
 #?*START-XSERVER ARGS=":98 -query 127.0.0.1 -nolisten unix"
-#?XSERVER-98 START
+#?XSERVER-98 START LISTEN-TCP NO-LISTEN-UNIX
 
 # Start sending XDMCP queries
 #?*XSERVER-98 START-XDMCP
index 28719e7c1fa138edd3f9d4c6a224d73ff6edfd8e..c0c89f4a0d8a77a0b0741ef1088bef11b1e1dede 100644 (file)
@@ -17,7 +17,7 @@ user-session=default
 
 # Start a remote X server to log in with XDMCP
 #?*START-XSERVER ARGS=":98 -query 127.0.0.1 -nolisten unix"
-#?XSERVER-98 START
+#?XSERVER-98 START LISTEN-TCP NO-LISTEN-UNIX
 
 # Start sending XDMCP queries
 #?*XSERVER-98 START-XDMCP
index c8865af94363bef621853799c0ea955c4817595e..105fafb6afccbe421843050534452d8b56a1e7be 100644 (file)
@@ -18,9 +18,19 @@ static int exit_status = EXIT_SUCCESS;
 
 static GKeyFile *config;
 
+/* Version to pretend to be */
+static gchar *xorg_version;
+static gint xorg_version_major, xorg_version_minor;
+
 /* Path to lock file */
 static gchar *lock_path = NULL;
 
+/* TRUE if we allow TCP connections */
+static gboolean listen_tcp = TRUE;
+
+/* TRUE if we allow Unix connections */
+static gboolean listen_unix = TRUE;
+
 /* Path to authority database to use */
 static gchar *auth_path = NULL;
 
@@ -194,10 +204,20 @@ request_cb (const gchar *name, GHashTable *params)
     }
 }
 
+static int
+version_compare (int major, int minor)
+{
+    if (major == xorg_version_major)
+        return xorg_version_minor - minor;
+    else
+        return xorg_version_major - major;
+}
+
 int
 main (int argc, char **argv)
 {
     int i;
+    gchar **tokens;
     char *pid_string;
     gboolean do_xdmcp = FALSE;
     guint xdmcp_port = 0;
@@ -218,6 +238,20 @@ main (int argc, char **argv)
     g_unix_signal_add (SIGTERM, sigterm_cb, NULL);
     g_unix_signal_add (SIGHUP, sighup_cb, NULL);
 
+    config = g_key_file_new ();
+    g_key_file_load_from_file (config, g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "script", NULL), G_KEY_FILE_NONE, NULL);
+
+    xorg_version = g_key_file_get_string (config, "test-xserver-config", "version", NULL);
+    if (!xorg_version)
+        xorg_version = g_strdup ("1.16.0");
+    tokens = g_strsplit (xorg_version, ".", -1);
+    xorg_version_major = g_strv_length (tokens) > 0 ? atoi (tokens[0]) : 0;
+    xorg_version_minor = g_strv_length (tokens) > 1 ? atoi (tokens[1]) : 0;
+    g_strfreev (tokens);
+
+    /* TCP listening default changed in 1.17.0 */
+    listen_tcp = version_compare (1, 17) < 0;
+
     for (i = 1; i < argc; i++)
     {
         char *arg = argv[i];
@@ -231,14 +265,23 @@ main (int argc, char **argv)
             auth_path = argv[i+1];
             i++;
         }
+        else if (strcmp (arg, "-listen") == 0 && version_compare (1, 17) >= 0)
+        {
+            char *protocol = argv[i+1];
+            i++;
+            if (strcmp (protocol, "tcp") == 0)
+                listen_tcp = TRUE;
+            else if (strcmp (protocol, "unix") == 0)
+                listen_unix = TRUE;
+        }
         else if (strcmp (arg, "-nolisten") == 0)
         {
             char *protocol = argv[i+1];
             i++;
             if (strcmp (protocol, "tcp") == 0)
-                ;//listen_tcp = FALSE;
+                listen_tcp = FALSE;
             else if (strcmp (protocol, "unix") == 0)
-                ;//listen_unix = FALSE;
+                listen_unix = FALSE;
         }
         else if (strcmp (arg, "-nr") == 0)
         {
@@ -257,11 +300,13 @@ main (int argc, char **argv)
         {
             do_xdmcp = TRUE;
             xdmcp_host = argv[i+1];
+            listen_tcp = TRUE;
             i++;
         }
         else if (strcmp (arg, "-broadcast") == 0)
         {
             do_xdmcp = TRUE;
+            listen_tcp = TRUE;
         }
         else if (g_str_has_prefix (arg, "vt"))
         {
@@ -286,12 +331,18 @@ main (int argc, char **argv)
             /* FIXME */
             i++;
         }
+        else if (strcmp (arg, "-version") == 0)
+        {
+            fprintf (stderr, "\nX.Org X Server %s\nBlah blah blah\n", xorg_version);
+            return EXIT_SUCCESS;
+        }
         else
         {
             g_printerr ("Unrecognized option: %s\n"
                         "Use: %s [:<display>] [option]\n"
                         "-auth file             Select authorization file\n"
                         "-nolisten protocol     Don't listen on protocol\n"
+                        "-listen protocol       Listen on protocol\n"
                         "-background [none]     Create root window with no background\n"
                         "-nr                    (Ubuntu-specific) Synonym for -background none\n"
                         "-query host-name       Contact named host for XDMCP\n"
@@ -300,6 +351,7 @@ main (int argc, char **argv)
                         "-seat string           seat to run on\n"
                         "-mir id                Mir ID to use\n"
                         "-mirSocket name        Mir socket to use\n"
+                        "-version               show the server version\n"
                         "vtxx                   Use virtual terminal xx instead of the next available\n",
                         arg, argv[0]);
             return EXIT_FAILURE;
@@ -318,6 +370,10 @@ main (int argc, char **argv)
     g_string_printf (status_text, "%s START", id);
     if (vt_number >= 0)
         g_string_append_printf (status_text, " VT=%d", vt_number);
+    if (listen_tcp)
+        g_string_append (status_text, " LISTEN-TCP");
+    if (!listen_unix)
+        g_string_append (status_text, " NO-LISTEN-UNIX");
     if (seat != NULL)
         g_string_append_printf (status_text, " SEAT=%s", seat);
     if (mir_id != NULL)
@@ -325,9 +381,6 @@ main (int argc, char **argv)
     status_notify ("%s", status_text->str);
     g_string_free (status_text, TRUE);
 
-    config = g_key_file_new ();
-    g_key_file_load_from_file (config, g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "script", NULL), G_KEY_FILE_NONE, NULL);
-
     if (g_key_file_has_key (config, "test-xserver-config", "return-value", NULL))
     {
         int return_value = g_key_file_get_integer (config, "test-xserver-config", "return-value", NULL);
diff --git a/tests/test-allow-tcp-xorg-1.16 b/tests/test-allow-tcp-xorg-1.16
new file mode 100755 (executable)
index 0000000..08c0774
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner allow-tcp-xorg-1.16 test-gobject-greeter
diff --git a/tests/test-allow-tcp-xorg-1.17 b/tests/test-allow-tcp-xorg-1.17
new file mode 100755 (executable)
index 0000000..db2a80b
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner allow-tcp-xorg-1.17 test-gobject-greeter