summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2015-10-14 17:00:30 +0100
committerRobert Ancell <robert.ancell@canonical.com>2015-10-14 17:00:30 +0100
commit2bd4dab1a29df610e4cd07c9d89cdc8d6cd43fc9 (patch)
tree445f924570f61311b2a98f8779c48e4ec900ed37
parent819a37da75251b5fee553721e25cf30d07fc950a (diff)
downloadlightdm-2bd4dab1a29df610e4cd07c9d89cdc8d6cd43fc9.tar.gz
Check the version of the X server we are running so we correctly pass -listen tcp when required.
Also add tests for xserver-allow-tcp function and check in all cases we are listening on tcp/unix only when appropriate.
-rw-r--r--src/x-server-local.c64
-rw-r--r--src/x-server-local.h4
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/scripts/allow-tcp-xorg-1.16.conf34
-rw-r--r--tests/scripts/allow-tcp-xorg-1.17.conf34
-rw-r--r--tests/scripts/xdmcp-client.conf2
-rw-r--r--tests/scripts/xdmcp-server-autologin.conf2
-rw-r--r--tests/scripts/xdmcp-server-double-login.conf4
-rw-r--r--tests/scripts/xdmcp-server-guest.conf2
-rw-r--r--tests/scripts/xdmcp-server-login.conf2
-rw-r--r--tests/scripts/xdmcp-server-open-file-descriptors.conf2
-rw-r--r--tests/src/X.c63
-rwxr-xr-xtests/test-allow-tcp-xorg-1.162
-rwxr-xr-xtests/test-allow-tcp-xorg-1.172
14 files changed, 208 insertions, 13 deletions
diff --git a/src/x-server-local.c b/src/x-server-local.c
index caff9b46..d9b03982 100644
--- a/src/x-server-local.c
+++ b/src/x-server-local.c
@@ -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)
diff --git a/src/x-server-local.h b/src/x-server-local.h
index 7ed5732c..e20a86cd 100644
--- a/src/x-server-local.h
+++ b/src/x-server-local.h
@@ -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);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 11c97287..9c2241d0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 00000000..bd6341ae
--- /dev/null
+++ b/tests/scripts/allow-tcp-xorg-1.16.conf
@@ -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
index 00000000..14b59151
--- /dev/null
+++ b/tests/scripts/allow-tcp-xorg-1.17.conf
@@ -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
diff --git a/tests/scripts/xdmcp-client.conf b/tests/scripts/xdmcp-client.conf
index b24860a9..f29bb41c 100644
--- a/tests/scripts/xdmcp-client.conf
+++ b/tests/scripts/xdmcp-client.conf
@@ -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
diff --git a/tests/scripts/xdmcp-server-autologin.conf b/tests/scripts/xdmcp-server-autologin.conf
index dd7a9502..92a45f1d 100644
--- a/tests/scripts/xdmcp-server-autologin.conf
+++ b/tests/scripts/xdmcp-server-autologin.conf
@@ -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
diff --git a/tests/scripts/xdmcp-server-double-login.conf b/tests/scripts/xdmcp-server-double-login.conf
index 552f4be7..bc3acdbe 100644
--- a/tests/scripts/xdmcp-server-double-login.conf
+++ b/tests/scripts/xdmcp-server-double-login.conf
@@ -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
diff --git a/tests/scripts/xdmcp-server-guest.conf b/tests/scripts/xdmcp-server-guest.conf
index 1fb8869f..6f5301de 100644
--- a/tests/scripts/xdmcp-server-guest.conf
+++ b/tests/scripts/xdmcp-server-guest.conf
@@ -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
diff --git a/tests/scripts/xdmcp-server-login.conf b/tests/scripts/xdmcp-server-login.conf
index c73f855d..fb3f8090 100644
--- a/tests/scripts/xdmcp-server-login.conf
+++ b/tests/scripts/xdmcp-server-login.conf
@@ -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
diff --git a/tests/scripts/xdmcp-server-open-file-descriptors.conf b/tests/scripts/xdmcp-server-open-file-descriptors.conf
index 28719e7c..c0c89f4a 100644
--- a/tests/scripts/xdmcp-server-open-file-descriptors.conf
+++ b/tests/scripts/xdmcp-server-open-file-descriptors.conf
@@ -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
diff --git a/tests/src/X.c b/tests/src/X.c
index c8865af9..105fafb6 100644
--- a/tests/src/X.c
+++ b/tests/src/X.c
@@ -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
index 00000000..08c07744
--- /dev/null
+++ b/tests/test-allow-tcp-xorg-1.16
@@ -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
index 00000000..db2a80b1
--- /dev/null
+++ b/tests/test-allow-tcp-xorg-1.17
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner allow-tcp-xorg-1.17 test-gobject-greeter