Skip to content

Commit 2bd4dab

Browse files
committed
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.
1 parent 819a37d commit 2bd4dab

14 files changed

+208
-13
lines changed

src/x-server-local.c

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,65 @@ struct XServerLocalPrivate
7474

7575
G_DEFINE_TYPE (XServerLocal, x_server_local, X_SERVER_TYPE);
7676

77+
static gchar *version = NULL;
78+
static guint version_major = 0, version_minor = 0;
7779
static GList *display_numbers = NULL;
7880

81+
#define XORG_VERSION_PREFIX "X.Org X Server "
82+
83+
static gchar *
84+
find_version (const gchar *line)
85+
{
86+
if (!g_str_has_prefix (line, XORG_VERSION_PREFIX))
87+
return NULL;
88+
89+
return g_strdup (line + strlen (XORG_VERSION_PREFIX));
90+
}
91+
92+
const gchar *
93+
x_server_local_get_version (void)
94+
{
95+
gchar *stderr_text;
96+
gint exit_status;
97+
gchar **tokens;
98+
guint n_tokens;
99+
100+
if (version)
101+
return version;
102+
103+
if (!g_spawn_command_line_sync ("X -version", NULL, &stderr_text, &exit_status, NULL))
104+
return NULL;
105+
if (exit_status == EXIT_SUCCESS)
106+
{
107+
gchar **lines;
108+
int i;
109+
110+
lines = g_strsplit (stderr_text, "\n", -1);
111+
for (i = 0; lines[i] && !version; i++)
112+
version = find_version (lines[i]);
113+
g_strfreev (lines);
114+
}
115+
g_free (stderr_text);
116+
117+
tokens = g_strsplit (version, ".", 3);
118+
n_tokens = g_strv_length (tokens);
119+
version_major = n_tokens > 0 ? atoi (tokens[0]) : 0;
120+
version_minor = n_tokens > 1 ? atoi (tokens[1]) : 0;
121+
g_strfreev (tokens);
122+
123+
return version;
124+
}
125+
126+
gint
127+
x_server_local_version_compare (guint major, guint minor)
128+
{
129+
x_server_local_get_version ();
130+
if (major == version_major)
131+
return version_minor - minor;
132+
else
133+
return version_major - major;
134+
}
135+
79136
static gboolean
80137
display_number_in_use (guint display_number)
81138
{
@@ -483,7 +540,12 @@ x_server_local_start (DisplayServer *display_server)
483540
if (server->priv->xdmcp_key)
484541
g_string_append_printf (command, " -cookie %s", server->priv->xdmcp_key);
485542
}
486-
else if (!server->priv->allow_tcp)
543+
else if (server->priv->allow_tcp)
544+
{
545+
if (x_server_local_version_compare (1, 17) >= 0)
546+
g_string_append (command, " -listen tcp");
547+
}
548+
else
487549
g_string_append (command, " -nolisten tcp");
488550

489551
if (server->priv->vt >= 0)

src/x-server-local.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ typedef struct
3333
XServerClass parent_class;
3434
} XServerLocalClass;
3535

36+
const gchar *x_server_local_get_version (void);
37+
38+
gint x_server_local_version_compare (guint major, guint minor);
39+
3640
guint x_server_local_get_unused_display_number (void);
3741

3842
void x_server_local_release_display_number (guint display_number);

tests/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ TESTS = \
3434
test-autologin-new-authtok \
3535
test-autologin-timeout-gobject \
3636
test-autologin-guest-timeout-gobject \
37+
test-allow-tcp-xorg-1.16 \
38+
test-allow-tcp-xorg-1.17 \
3739
test-change-authentication \
3840
test-restart-authentication \
3941
test-cancel-authentication-gobject \
@@ -367,6 +369,8 @@ EXTRA_DIST = \
367369
scripts/additional-config-priority.conf \
368370
scripts/additional-system-config.conf \
369371
scripts/additional-system-config-priority.conf \
372+
scripts/allow-tcp-xorg-1.16.conf \
373+
scripts/allow-tcp-xorg-1.17.conf \
370374
scripts/audit-autologin.conf \
371375
scripts/autologin.conf \
372376
scripts/autologin-guest.conf \
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Check can enable TCP listening in X.Org < 1.17 (default is listening enabled)
3+
#
4+
5+
[test-xserver-config]
6+
version=1.16.0
7+
8+
[Seat:*]
9+
autologin-user=have-password1
10+
user-session=default
11+
xserver-allow-tcp=true
12+
13+
#?*START-DAEMON
14+
#?RUNNER DAEMON-START
15+
16+
# X server starts
17+
#?XSERVER-0 START VT=7 LISTEN-TCP SEAT=seat0
18+
19+
# Daemon connects when X server is ready
20+
#?*XSERVER-0 INDICATE-READY
21+
#?XSERVER-0 INDICATE-READY
22+
#?XSERVER-0 ACCEPT-CONNECT
23+
24+
# Session starts
25+
#?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
26+
#?LOGIN1 ACTIVATE-SESSION SESSION=c0
27+
#?XSERVER-0 ACCEPT-CONNECT
28+
#?SESSION-X-0 CONNECT-XSERVER
29+
30+
# Cleanup
31+
#?*STOP-DAEMON
32+
#?SESSION-X-0 TERMINATE SIGNAL=15
33+
#?XSERVER-0 TERMINATE SIGNAL=15
34+
#?RUNNER DAEMON-EXIT STATUS=0
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Check can enable TCP listening in X.Org >= 1.17 (default is listening disabled)
3+
#
4+
5+
[test-xserver-config]
6+
version=1.17.0
7+
8+
[Seat:*]
9+
autologin-user=have-password1
10+
user-session=default
11+
xserver-allow-tcp=true
12+
13+
#?*START-DAEMON
14+
#?RUNNER DAEMON-START
15+
16+
# X server starts
17+
#?XSERVER-0 START VT=7 LISTEN-TCP SEAT=seat0
18+
19+
# Daemon connects when X server is ready
20+
#?*XSERVER-0 INDICATE-READY
21+
#?XSERVER-0 INDICATE-READY
22+
#?XSERVER-0 ACCEPT-CONNECT
23+
24+
# Session starts
25+
#?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
26+
#?LOGIN1 ACTIVATE-SESSION SESSION=c0
27+
#?XSERVER-0 ACCEPT-CONNECT
28+
#?SESSION-X-0 CONNECT-XSERVER
29+
30+
# Cleanup
31+
#?*STOP-DAEMON
32+
#?SESSION-X-0 TERMINATE SIGNAL=15
33+
#?XSERVER-0 TERMINATE SIGNAL=15
34+
#?RUNNER DAEMON-EXIT STATUS=0

tests/scripts/xdmcp-client.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ xdmcp-manager=127.0.0.1
99
#?RUNNER DAEMON-START
1010

1111
# X server starts
12-
#?XSERVER-0 START VT=7 SEAT=seat0
12+
#?XSERVER-0 START VT=7 LISTEN-TCP SEAT=seat0
1313
#?*XSERVER-0 INDICATE-READY
1414
#?XSERVER-0 INDICATE-READY
1515
#?XSERVER-0 ACCEPT-CONNECT

tests/scripts/xdmcp-server-autologin.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ autologin-user=have-password1
1818

1919
# Start a remote X server to log in with XDMCP
2020
#?*START-XSERVER ARGS=":98 -query 127.0.0.1 -nolisten unix"
21-
#?XSERVER-98 START
21+
#?XSERVER-98 START LISTEN-TCP NO-LISTEN-UNIX
2222

2323
# Start sending XDMCP queries
2424
#?*XSERVER-98 START-XDMCP

tests/scripts/xdmcp-server-double-login.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ user-session=default
1717

1818
# Start a remote X server to log in with XDMCP
1919
#?*START-XSERVER ARGS=":98 -query 127.0.0.1 -nolisten unix"
20-
#?XSERVER-98 START
20+
#?XSERVER-98 START LISTEN-TCP NO-LISTEN-UNIX
2121

2222
# Start sending XDMCP queries
2323
#?*XSERVER-98 START-XDMCP
@@ -56,7 +56,7 @@ user-session=default
5656

5757
# Start a second remote X server to log in with XDMCP
5858
#?*START-XSERVER ARGS=":99 -query 127.0.0.1 -nolisten unix"
59-
#?XSERVER-99 START
59+
#?XSERVER-99 START LISTEN-TCP NO-LISTEN-UNIX
6060

6161
# Start sending XDMCP queries
6262
#?*XSERVER-99 START-XDMCP

tests/scripts/xdmcp-server-guest.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ user-session=default
1717

1818
# Start a remote X server to log in with XDMCP
1919
#?*START-XSERVER ARGS=":98 -query 127.0.0.1 -nolisten unix"
20-
#?XSERVER-98 START
20+
#?XSERVER-98 START LISTEN-TCP NO-LISTEN-UNIX
2121

2222
# Start sending XDMCP queries
2323
#?*XSERVER-98 START-XDMCP

tests/scripts/xdmcp-server-login.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ user-session=default
1717

1818
# Start a remote X server to log in with XDMCP
1919
#?*START-XSERVER ARGS=":98 -query 127.0.0.1 -nolisten unix"
20-
#?XSERVER-98 START
20+
#?XSERVER-98 START LISTEN-TCP NO-LISTEN-UNIX
2121

2222
# Start sending XDMCP queries
2323
#?*XSERVER-98 START-XDMCP

tests/scripts/xdmcp-server-open-file-descriptors.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ user-session=default
1717

1818
# Start a remote X server to log in with XDMCP
1919
#?*START-XSERVER ARGS=":98 -query 127.0.0.1 -nolisten unix"
20-
#?XSERVER-98 START
20+
#?XSERVER-98 START LISTEN-TCP NO-LISTEN-UNIX
2121

2222
# Start sending XDMCP queries
2323
#?*XSERVER-98 START-XDMCP

tests/src/X.c

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,19 @@ static int exit_status = EXIT_SUCCESS;
1818

1919
static GKeyFile *config;
2020

21+
/* Version to pretend to be */
22+
static gchar *xorg_version;
23+
static gint xorg_version_major, xorg_version_minor;
24+
2125
/* Path to lock file */
2226
static gchar *lock_path = NULL;
2327

28+
/* TRUE if we allow TCP connections */
29+
static gboolean listen_tcp = TRUE;
30+
31+
/* TRUE if we allow Unix connections */
32+
static gboolean listen_unix = TRUE;
33+
2434
/* Path to authority database to use */
2535
static gchar *auth_path = NULL;
2636

@@ -194,10 +204,20 @@ request_cb (const gchar *name, GHashTable *params)
194204
}
195205
}
196206

207+
static int
208+
version_compare (int major, int minor)
209+
{
210+
if (major == xorg_version_major)
211+
return xorg_version_minor - minor;
212+
else
213+
return xorg_version_major - major;
214+
}
215+
197216
int
198217
main (int argc, char **argv)
199218
{
200219
int i;
220+
gchar **tokens;
201221
char *pid_string;
202222
gboolean do_xdmcp = FALSE;
203223
guint xdmcp_port = 0;
@@ -218,6 +238,20 @@ main (int argc, char **argv)
218238
g_unix_signal_add (SIGTERM, sigterm_cb, NULL);
219239
g_unix_signal_add (SIGHUP, sighup_cb, NULL);
220240

241+
config = g_key_file_new ();
242+
g_key_file_load_from_file (config, g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "script", NULL), G_KEY_FILE_NONE, NULL);
243+
244+
xorg_version = g_key_file_get_string (config, "test-xserver-config", "version", NULL);
245+
if (!xorg_version)
246+
xorg_version = g_strdup ("1.16.0");
247+
tokens = g_strsplit (xorg_version, ".", -1);
248+
xorg_version_major = g_strv_length (tokens) > 0 ? atoi (tokens[0]) : 0;
249+
xorg_version_minor = g_strv_length (tokens) > 1 ? atoi (tokens[1]) : 0;
250+
g_strfreev (tokens);
251+
252+
/* TCP listening default changed in 1.17.0 */
253+
listen_tcp = version_compare (1, 17) < 0;
254+
221255
for (i = 1; i < argc; i++)
222256
{
223257
char *arg = argv[i];
@@ -231,14 +265,23 @@ main (int argc, char **argv)
231265
auth_path = argv[i+1];
232266
i++;
233267
}
268+
else if (strcmp (arg, "-listen") == 0 && version_compare (1, 17) >= 0)
269+
{
270+
char *protocol = argv[i+1];
271+
i++;
272+
if (strcmp (protocol, "tcp") == 0)
273+
listen_tcp = TRUE;
274+
else if (strcmp (protocol, "unix") == 0)
275+
listen_unix = TRUE;
276+
}
234277
else if (strcmp (arg, "-nolisten") == 0)
235278
{
236279
char *protocol = argv[i+1];
237280
i++;
238281
if (strcmp (protocol, "tcp") == 0)
239-
;//listen_tcp = FALSE;
282+
listen_tcp = FALSE;
240283
else if (strcmp (protocol, "unix") == 0)
241-
;//listen_unix = FALSE;
284+
listen_unix = FALSE;
242285
}
243286
else if (strcmp (arg, "-nr") == 0)
244287
{
@@ -257,11 +300,13 @@ main (int argc, char **argv)
257300
{
258301
do_xdmcp = TRUE;
259302
xdmcp_host = argv[i+1];
303+
listen_tcp = TRUE;
260304
i++;
261305
}
262306
else if (strcmp (arg, "-broadcast") == 0)
263307
{
264308
do_xdmcp = TRUE;
309+
listen_tcp = TRUE;
265310
}
266311
else if (g_str_has_prefix (arg, "vt"))
267312
{
@@ -286,12 +331,18 @@ main (int argc, char **argv)
286331
/* FIXME */
287332
i++;
288333
}
334+
else if (strcmp (arg, "-version") == 0)
335+
{
336+
fprintf (stderr, "\nX.Org X Server %s\nBlah blah blah\n", xorg_version);
337+
return EXIT_SUCCESS;
338+
}
289339
else
290340
{
291341
g_printerr ("Unrecognized option: %s\n"
292342
"Use: %s [:<display>] [option]\n"
293343
"-auth file Select authorization file\n"
294344
"-nolisten protocol Don't listen on protocol\n"
345+
"-listen protocol Listen on protocol\n"
295346
"-background [none] Create root window with no background\n"
296347
"-nr (Ubuntu-specific) Synonym for -background none\n"
297348
"-query host-name Contact named host for XDMCP\n"
@@ -300,6 +351,7 @@ main (int argc, char **argv)
300351
"-seat string seat to run on\n"
301352
"-mir id Mir ID to use\n"
302353
"-mirSocket name Mir socket to use\n"
354+
"-version show the server version\n"
303355
"vtxx Use virtual terminal xx instead of the next available\n",
304356
arg, argv[0]);
305357
return EXIT_FAILURE;
@@ -318,16 +370,17 @@ main (int argc, char **argv)
318370
g_string_printf (status_text, "%s START", id);
319371
if (vt_number >= 0)
320372
g_string_append_printf (status_text, " VT=%d", vt_number);
373+
if (listen_tcp)
374+
g_string_append (status_text, " LISTEN-TCP");
375+
if (!listen_unix)
376+
g_string_append (status_text, " NO-LISTEN-UNIX");
321377
if (seat != NULL)
322378
g_string_append_printf (status_text, " SEAT=%s", seat);
323379
if (mir_id != NULL)
324380
g_string_append_printf (status_text, " MIR-ID=%s", mir_id);
325381
status_notify ("%s", status_text->str);
326382
g_string_free (status_text, TRUE);
327383

328-
config = g_key_file_new ();
329-
g_key_file_load_from_file (config, g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "script", NULL), G_KEY_FILE_NONE, NULL);
330-
331384
if (g_key_file_has_key (config, "test-xserver-config", "return-value", NULL))
332385
{
333386
int return_value = g_key_file_get_integer (config, "test-xserver-config", "return-value", NULL);

tests/test-allow-tcp-xorg-1.16

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
./src/dbus-env ./src/test-runner allow-tcp-xorg-1.16 test-gobject-greeter

tests/test-allow-tcp-xorg-1.17

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
./src/dbus-env ./src/test-runner allow-tcp-xorg-1.17 test-gobject-greeter

0 commit comments

Comments
 (0)