Blame SOURCES/0002-daemon-Support-X-servers-built-with-Dlisten_tcp-true.patch

4e44f9
From cc67c8de39358031fddc5ca7d8c993271d6606a7 Mon Sep 17 00:00:00 2001
4e44f9
From: Alan Coopersmith <alan.coopersmith@oracle.com>
4e44f9
Date: Thu, 7 Oct 2021 18:22:11 -0700
4e44f9
Subject: [PATCH 2/2] daemon: Support X servers built with -Dlisten_tcp=true
4e44f9
4e44f9
Xorg since version 1.17 doesn't listen to tcp sockets by default
4e44f9
unless it's explicitly built with -Dlisten_tcp=true.
4e44f9
4e44f9
GDM currently assumes X servers 1.17 and later are always built
4e44f9
without specifying -Dlisten_tcp=true and doesn't work properly
4e44f9
otherwise.
4e44f9
4e44f9
This commit enhances GDM to better handle these non-standard builds by
4e44f9
always passing '-nolisten tcp' on the command line when tcp should
4e44f9
be disabled, and likewise always passing '-listen tcp' on the command
4e44f9
line, assuming the X server is new enough to support it, when tcp
4e44f9
should be enabled.
4e44f9
4e44f9
Related #704
4e44f9
---
4e44f9
 daemon/gdm-server.c    | 21 +++++++++++----------
4e44f9
 daemon/gdm-x-session.c | 12 ++++++------
4e44f9
 meson.build            |  4 ++--
4e44f9
 3 files changed, 19 insertions(+), 18 deletions(-)
4e44f9
4e44f9
diff --git a/daemon/gdm-server.c b/daemon/gdm-server.c
4e44f9
index 1ba00d45..e5d23521 100644
4e44f9
--- a/daemon/gdm-server.c
4e44f9
+++ b/daemon/gdm-server.c
4e44f9
@@ -290,72 +290,73 @@ gdm_server_resolve_command_line (GdmServer  *server,
4e44f9
                 if (strcmp (arg, "-query") == 0 ||
4e44f9
                     strcmp (arg, "-indirect") == 0)
4e44f9
                         query_in_arglist = TRUE;
4e44f9
         }
4e44f9
 
4e44f9
         argv = g_renew (char *, argv, len + 12);
4e44f9
         /* shift args down one */
4e44f9
         for (i = len - 1; i >= 1; i--) {
4e44f9
                 argv[i+1] = argv[i];
4e44f9
         }
4e44f9
 
4e44f9
         /* server number is the FIRST argument, before any others */
4e44f9
         argv[1] = g_strdup (server->display_name);
4e44f9
         len++;
4e44f9
 
4e44f9
         if (server->auth_file != NULL) {
4e44f9
                 argv[len++] = g_strdup ("-auth");
4e44f9
                 argv[len++] = g_strdup (server->auth_file);
4e44f9
         }
4e44f9
 
4e44f9
         if (server->display_seat_id != NULL) {
4e44f9
                 argv[len++] = g_strdup ("-seat");
4e44f9
                 argv[len++] = g_strdup (server->display_seat_id);
4e44f9
         }
4e44f9
 
4e44f9
         /* If we were compiled with Xserver >= 1.17 we need to specify
4e44f9
          * '-listen tcp' as the X server dosen't listen on tcp sockets
4e44f9
          * by default anymore. In older versions we need to pass
4e44f9
          * -nolisten tcp to disable listening on tcp sockets.
4e44f9
          */
4e44f9
-#ifdef HAVE_XSERVER_THAT_DEFAULTS_TO_LOCAL_ONLY
4e44f9
-        if (!server->disable_tcp && ! query_in_arglist) {
4e44f9
-                argv[len++] = g_strdup ("-listen");
4e44f9
-                argv[len++] = g_strdup ("tcp");
4e44f9
-        }
4e44f9
-#else
4e44f9
-        if (server->disable_tcp && ! query_in_arglist) {
4e44f9
-                argv[len++] = g_strdup ("-nolisten");
4e44f9
-                argv[len++] = g_strdup ("tcp");
4e44f9
-        }
4e44f9
+        if (!query_in_arglist) {
4e44f9
+                if (server->disable_tcp) {
4e44f9
+                        argv[len++] = g_strdup ("-nolisten");
4e44f9
+                        argv[len++] = g_strdup ("tcp");
4e44f9
+                }
4e44f9
 
4e44f9
+#ifdef HAVE_XSERVER_WITH_LISTEN
4e44f9
+                if (!server->disable_tcp) {
4e44f9
+                        argv[len++] = g_strdup ("-listen");
4e44f9
+                        argv[len++] = g_strdup ("tcp");
4e44f9
+                }
4e44f9
 #endif
4e44f9
+        }
4e44f9
 
4e44f9
         if (vtarg != NULL && ! gotvtarg) {
4e44f9
                 argv[len++] = g_strdup (vtarg);
4e44f9
         }
4e44f9
 
4e44f9
         argv[len++] = NULL;
4e44f9
 
4e44f9
         *argvp = argv;
4e44f9
         *argcp = len;
4e44f9
 
4e44f9
         return TRUE;
4e44f9
 }
4e44f9
 
4e44f9
 static void
4e44f9
 rotate_logs (const char *path,
4e44f9
              guint       n_copies)
4e44f9
 {
4e44f9
         int i;
4e44f9
 
4e44f9
         for (i = n_copies - 1; i > 0; i--) {
4e44f9
                 char *name_n;
4e44f9
                 char *name_n1;
4e44f9
 
4e44f9
                 name_n = g_strdup_printf ("%s.%d", path, i);
4e44f9
                 if (i > 1) {
4e44f9
                         name_n1 = g_strdup_printf ("%s.%d", path, i - 1);
4e44f9
                 } else {
4e44f9
                         name_n1 = g_strdup (path);
4e44f9
                 }
4e44f9
 
4e44f9
diff --git a/daemon/gdm-x-session.c b/daemon/gdm-x-session.c
4e44f9
index 5962da57..0b07ab5b 100644
4e44f9
--- a/daemon/gdm-x-session.c
4e44f9
+++ b/daemon/gdm-x-session.c
4e44f9
@@ -233,70 +233,70 @@ spawn_x_server (State        *state,
4e44f9
 
4e44f9
         if (g_getenv ("XDG_VTNR") != NULL) {
4e44f9
                 int vt;
4e44f9
 
4e44f9
                 vt = atoi (g_getenv ("XDG_VTNR"));
4e44f9
 
4e44f9
                 if (vt > 0 && vt < 64) {
4e44f9
                         vt_string = g_strdup_printf ("vt%d", vt);
4e44f9
                 }
4e44f9
         }
4e44f9
 
4e44f9
         display_fd_string = g_strdup_printf ("%d", DISPLAY_FILENO);
4e44f9
 
4e44f9
         g_ptr_array_add (arguments, X_SERVER);
4e44f9
 
4e44f9
         if (vt_string != NULL) {
4e44f9
                 g_ptr_array_add (arguments, vt_string);
4e44f9
         }
4e44f9
 
4e44f9
         g_ptr_array_add (arguments, "-displayfd");
4e44f9
         g_ptr_array_add (arguments, display_fd_string);
4e44f9
 
4e44f9
         g_ptr_array_add (arguments, "-auth");
4e44f9
         g_ptr_array_add (arguments, auth_file);
4e44f9
 
4e44f9
         /* If we were compiled with Xserver >= 1.17 we need to specify
4e44f9
          * '-listen tcp' as the X server doesn't listen on tcp sockets
4e44f9
          * by default anymore. In older versions we need to pass
4e44f9
          * -nolisten tcp to disable listening on tcp sockets.
4e44f9
          */
4e44f9
-#ifdef HAVE_XSERVER_THAT_DEFAULTS_TO_LOCAL_ONLY
4e44f9
-        if (allow_remote_connections) {
4e44f9
-                g_ptr_array_add (arguments, "-listen");
4e44f9
-                g_ptr_array_add (arguments, "tcp");
4e44f9
-        }
4e44f9
-#else
4e44f9
         if (!allow_remote_connections) {
4e44f9
                 g_ptr_array_add (arguments, "-nolisten");
4e44f9
                 g_ptr_array_add (arguments, "tcp");
4e44f9
         }
4e44f9
+
4e44f9
+#ifdef HAVE_XSERVER_WITH_LISTEN
4e44f9
+        if (allow_remote_connections) {
4e44f9
+                g_ptr_array_add (arguments, "-listen");
4e44f9
+                g_ptr_array_add (arguments, "tcp");
4e44f9
+        }
4e44f9
 #endif
4e44f9
 
4e44f9
         g_ptr_array_add (arguments, "-background");
4e44f9
         g_ptr_array_add (arguments, "none");
4e44f9
 
4e44f9
         g_ptr_array_add (arguments, "-noreset");
4e44f9
         g_ptr_array_add (arguments, "-keeptty");
4e44f9
         g_ptr_array_add (arguments, "-novtswitch");
4e44f9
 
4e44f9
         g_ptr_array_add (arguments, "-verbose");
4e44f9
         if (state->debug_enabled) {
4e44f9
                 g_ptr_array_add (arguments, "7");
4e44f9
         } else {
4e44f9
                 g_ptr_array_add (arguments, "3");
4e44f9
         }
4e44f9
 
4e44f9
         if (state->debug_enabled) {
4e44f9
                 g_ptr_array_add (arguments, "-core");
4e44f9
         }
4e44f9
         g_ptr_array_add (arguments, NULL);
4e44f9
 
4e44f9
         subprocess = g_subprocess_launcher_spawnv (launcher,
4e44f9
                                                    (const char * const *) arguments->pdata,
4e44f9
                                                    &error);
4e44f9
         g_free (display_fd_string);
4e44f9
         g_clear_object (&launcher);
4e44f9
         g_ptr_array_free (arguments, TRUE);
4e44f9
 
4e44f9
         if (subprocess == NULL) {
4e44f9
                 g_debug ("could not start X server: %s", error->message);
4e44f9
diff --git a/meson.build b/meson.build
4e44f9
index 52ac1941..02d609dc 100644
4e44f9
--- a/meson.build
4e44f9
+++ b/meson.build
4e44f9
@@ -44,61 +44,61 @@ glib_min_version = '2.56.0'
4e44f9
 glib_dep = dependency('glib-2.0', version: '>=' + glib_min_version)
4e44f9
 gobject_dep = dependency('gobject-2.0', version: '>=' + glib_min_version)
4e44f9
 gio_dep = dependency('gio-2.0', version: '>=' + glib_min_version)
4e44f9
 gio_unix_dep = dependency('gio-unix-2.0', version: '>=' + glib_min_version)
4e44f9
 gtk_dep = dependency('gtk+-3.0', version: '>= 2.91.1')
4e44f9
 libcanberra_gtk_dep = dependency('libcanberra-gtk3', version: '>= 0.4')
4e44f9
 accountsservice_dep = dependency('accountsservice', version: '>= 0.6.35')
4e44f9
 xcb_dep = dependency('xcb')
4e44f9
 keyutils_dep = dependency('libkeyutils', required: false)
4e44f9
 libselinux_dep = dependency('libselinux', required: get_option('selinux'))
4e44f9
 
4e44f9
 # udev
4e44f9
 if udev_dir == ''
4e44f9
   if udev_dep.found()
4e44f9
     udev_prefix = udev_dep.get_pkgconfig_variable('udevdir')
4e44f9
   else
4e44f9
     udev_prefix = gdm_prefix / 'lib' / 'udev'
4e44f9
   endif
4e44f9
   udev_dir = udev_prefix / 'rules.d'
4e44f9
 endif
4e44f9
 
4e44f9
 # X11
4e44f9
 x_deps = declare_dependency(
4e44f9
   dependencies: [
4e44f9
     dependency('x11'),
4e44f9
     dependency('xau'),
4e44f9
   ],
4e44f9
 )
4e44f9
 # Xserver 1.17 & later default to -nolisten and require -listen for remote access
4e44f9
 xserver_deps = dependency('xorg-server', version : '>=1.17', required : false)
4e44f9
-xserver_nolisten_default = xserver_deps.found()
4e44f9
+xserver_has_listen = xserver_deps.found()
4e44f9
 find_x_server_script = find_program('build-aux/find-x-server.sh', native: true)
4e44f9
 find_x_server_out = run_command(find_x_server_script).stdout().strip()
4e44f9
 if find_x_server_out != ''
4e44f9
   x_bin = find_x_server_out
4e44f9
   x_bin_path_split = x_bin.split('/')
4e44f9
   i = 0
4e44f9
   x_path = '/'
4e44f9
   foreach dir : x_bin_path_split
4e44f9
     if i < x_bin_path_split.length() - 1
4e44f9
       x_path = x_path / dir
4e44f9
     endif
4e44f9
     i = i + 1
4e44f9
   endforeach
4e44f9
 else
4e44f9
   # what to do, what to do, this is wrong, but this just sets the
4e44f9
   # defaults, perhaps this user is cross compiling or some such
4e44f9
   x_path = '/usr/bin/X11:/usr/X11R6/bin:/opt/X11R6/bin'
4e44f9
   x_bin = '/usr/bin/X'
4e44f9
 endif
4e44f9
 xdmcp_dep = cc.find_library('Xdmcp', required: get_option('xdmcp'))
4e44f9
 if xdmcp_dep.found() and get_option('tcp-wrappers')
4e44f9
   libwrap_dep = cc.find_library('wrap')
4e44f9
 endif
4e44f9
 # systemd
4e44f9
 systemd_dep = dependency('systemd')
4e44f9
 libsystemd_dep = dependency('libsystemd')
4e44f9
 if meson.version().version_compare('>= 0.53')
4e44f9
   systemd_multiseat_x = find_program('systemd-multi-seat-x',
4e44f9
     required: false,
4e44f9
     dirs: [
4e44f9
@@ -200,61 +200,61 @@ conf.set_quoted('SYSCONFDIR', gdm_prefix / get_option('sysconfdir'))
4e44f9
 conf.set_quoted('BINDIR', gdm_prefix / get_option('bindir'))
4e44f9
 conf.set_quoted('LIBDIR', gdm_prefix / get_option('libdir'))
4e44f9
 conf.set_quoted('LIBEXECDIR', gdm_prefix / get_option('libexecdir'))
4e44f9
 conf.set_quoted('LOGDIR', get_option('log-dir'))
4e44f9
 conf.set_quoted('DMCONFDIR', dmconfdir)
4e44f9
 conf.set_quoted('GDMCONFDIR', gdmconfdir)
4e44f9
 conf.set_quoted('GDM_SCREENSHOT_DIR', gdm_screenshot_dir)
4e44f9
 conf.set_quoted('GDM_XAUTH_DIR', gdm_xauth_dir)
4e44f9
 conf.set_quoted('GDM_RAN_ONCE_MARKER_DIR', ran_once_marker_dir)
4e44f9
 conf.set_quoted('GDM_RUN_DIR', gdm_run_dir)
4e44f9
 conf.set_quoted('GNOMELOCALEDIR', gdm_prefix / get_option('localedir'))
4e44f9
 conf.set_quoted('AT_SPI_REGISTRYD_DIR', at_spi_registryd_dir)
4e44f9
 conf.set_quoted('GDM_PID_FILE', gdm_pid_file)
4e44f9
 conf.set_quoted('GNOME_SETTINGS_DAEMON_DIR', gnome_settings_daemon_dir)
4e44f9
 conf.set_quoted('LANG_CONFIG_FILE', lang_config_file)
4e44f9
 conf.set('HAVE_ADT', have_adt)
4e44f9
 conf.set('HAVE_UTMP_H', have_utmp_header)
4e44f9
 conf.set('HAVE_UTMPX_H', have_utmpx_header)
4e44f9
 conf.set('HAVE_POSIX_GETPWNAM_R', have_posix_getpwnam_r)
4e44f9
 conf.set('UTMP', utmp_struct)
4e44f9
 conf.set('HAVE_GETUTXENT', cc.has_function('getutxent'))
4e44f9
 conf.set('HAVE_UPDWTMP', cc.has_function('updwtmp'))
4e44f9
 conf.set('HAVE_UPDWTMPX', cc.has_function('updwtmpx'))
4e44f9
 conf.set('HAVE_LOGIN', cc.has_function('login', args: '-lutil'))
4e44f9
 conf.set('HAVE_LOGOUT', cc.has_function('logout', args: '-lutil'))
4e44f9
 conf.set('HAVE_LOGWTMP', cc.has_function('logwtmp', args: '-lutil'))
4e44f9
 conf.set('HAVE_PAM_SYSLOG', have_pam_syslog)
4e44f9
 conf.set('HAVE_KEYUTILS', keyutils_dep.found())
4e44f9
 conf.set('SUPPORTS_PAM_EXTENSIONS', pam_extensions_supported)
4e44f9
 conf.set('HAVE_SELINUX', libselinux_dep.found())
4e44f9
-conf.set('HAVE_XSERVER_THAT_DEFAULTS_TO_LOCAL_ONLY', xserver_nolisten_default)
4e44f9
+conf.set('HAVE_XSERVER_WITH_LISTEN', xserver_has_listen)
4e44f9
 conf.set('ENABLE_USER_DISPLAY_SERVER', get_option('user-display-server'))
4e44f9
 conf.set('ENABLE_SYSTEMD_JOURNAL', get_option('systemd-journal'))
4e44f9
 conf.set('ENABLE_WAYLAND_SUPPORT', get_option('wayland-support'))
4e44f9
 conf.set('ENABLE_PROFILING', get_option('profiling'))
4e44f9
 conf.set('GDM_INITIAL_VT', get_option('initial-vt'))
4e44f9
 conf.set_quoted('GDM_DEFAULTS_CONF', gdm_defaults_conf)
4e44f9
 conf.set_quoted('GDM_CUSTOM_CONF', gdm_custom_conf)
4e44f9
 conf.set_quoted('GDM_RUNTIME_CONF', gdm_runtime_conf)
4e44f9
 conf.set_quoted('GDM_SESSION_DEFAULT_PATH', get_option('default-path'))
4e44f9
 conf.set_quoted('GDM_USERNAME', get_option('user'))
4e44f9
 conf.set_quoted('GDM_GROUPNAME', get_option('group'))
4e44f9
 conf.set('HAVE_LIBXDMCP', xdmcp_dep.found())
4e44f9
 conf.set_quoted('SYSTEMD_X_SERVER', systemd_x_server)
4e44f9
 conf.set('WITH_PLYMOUTH', plymouth_dep.found())
4e44f9
 conf.set_quoted('X_SERVER', x_bin)
4e44f9
 conf.set_quoted('X_PATH', x_path)
4e44f9
 conf.set('HAVE_UT_UT_HOST', utmp_has_host_field)
4e44f9
 conf.set('HAVE_UT_UT_PID', utmp_has_pid_field)
4e44f9
 conf.set('HAVE_UT_UT_ID', utmp_has_id_field)
4e44f9
 conf.set('HAVE_UT_UT_NAME', utmp_has_name_field)
4e44f9
 conf.set('HAVE_UT_UT_TYPE', utmp_has_type_field)
4e44f9
 conf.set('HAVE_UT_UT_EXIT_E_TERMINATION', utmp_has_exit_e_termination_field)
4e44f9
 conf.set('HAVE_UT_UT_USER', utmp_has_user_field)
4e44f9
 conf.set('HAVE_UT_UT_TIME', utmp_has_time_field)
4e44f9
 conf.set('HAVE_UT_UT_TV', utmp_has_tv_field)
4e44f9
 conf.set('HAVE_UT_UT_SYSLEN', utmp_has_syslen_field)
4e44f9
 conf.set('ENABLE_IPV6', get_option('ipv6'))
4e44f9
 configure_file(output: 'config.h', configuration: conf)
4e44f9
 
4e44f9
 # Subdirs
4e44f9
-- 
4e44f9
2.34.1
4e44f9