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

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