Blame SOURCES/xwayland-xauth-xhost-user.patch

a5bca9
From 8e756d48ed31bcacf12b99cbd82fb2052503f51e Mon Sep 17 00:00:00 2001
a5bca9
From: Hans de Goede <hdegoede@redhat.com>
a5bca9
Date: Tue, 18 Jun 2019 16:12:46 +0200
a5bca9
Subject: [PATCH 1/4] xwayland: Generate a Xauth file and pass this to Xwayland
a5bca9
 when starting it
a5bca9
a5bca9
Before this commit, sudo x11-app, e.g. sudo gvim /etc/some-file, fails
a5bca9
when running a Wayland session. Where as doing this under a "GNOME on Xorg"
a5bca9
session works fine. For a user switching from the Xorg session to the
a5bca9
Wayland session, this is regression, which we want to avoid.
a5bca9
a5bca9
This commit fixes this by creating and passing an xauth file to Xwayland when
a5bca9
mutter starts it. Just like gdm or startx pass a xauth file to Xorg when they
a5bca9
start Xorg.
a5bca9
a5bca9
Fixes #643
a5bca9
a5bca9
https://gitlab.gnome.org/GNOME/mutter/issues/643
a5bca9
---
a5bca9
 meson.build                        |  1 +
a5bca9
 src/meson.build                    |  1 +
a5bca9
 src/wayland/meta-wayland-private.h |  1 +
a5bca9
 src/wayland/meta-wayland.c         | 11 +++-
a5bca9
 src/wayland/meta-xwayland.c        | 81 ++++++++++++++++++++++++++++++
a5bca9
 5 files changed, 94 insertions(+), 1 deletion(-)
a5bca9
a5bca9
diff --git a/meson.build b/meson.build
a5bca9
index 8ef592bc58..2a404857ce 100644
a5bca9
--- a/meson.build
a5bca9
+++ b/meson.build
a5bca9
@@ -117,6 +117,7 @@ xrandr_dep = dependency('xrandr', version: xrandr_req)
a5bca9
 xcb_randr_dep = dependency('xcb-randr')
a5bca9
 xcb_res_dep = dependency('xcb-res')
a5bca9
 xinerama_dep = dependency('xinerama')
a5bca9
+xau_dep = dependency('xau')
a5bca9
 ice_dep = dependency('ice')
a5bca9
 atk_dep = dependency('atk', version: atk_req)
a5bca9
 libcanberra_dep = dependency('libcanberra', version: libcanberra_req)
a5bca9
diff --git a/src/meson.build b/src/meson.build
a5bca9
index 7cced8f534..91fe74b99a 100644
a5bca9
--- a/src/meson.build
a5bca9
+++ b/src/meson.build
a5bca9
@@ -101,6 +101,7 @@ if have_x11
a5bca9
     x11_xcb_dep,
a5bca9
     xcb_randr_dep,
a5bca9
     xcb_res_dep,
a5bca9
+    xau_dep,
a5bca9
   ]
a5bca9
 
a5bca9
   if have_sm
a5bca9
diff --git a/src/wayland/meta-wayland-private.h b/src/wayland/meta-wayland-private.h
a5bca9
index 07a71f82b1..5bcb0ea4f9 100644
a5bca9
--- a/src/wayland/meta-wayland-private.h
a5bca9
+++ b/src/wayland/meta-wayland-private.h
a5bca9
@@ -51,6 +51,7 @@ typedef struct
a5bca9
   struct wl_client *client;
a5bca9
   struct wl_resource *xserver_resource;
a5bca9
   char *display_name;
a5bca9
+  char *auth_file;
a5bca9
 
a5bca9
   GCancellable *xserver_died_cancellable;
a5bca9
   GSubprocess *proc;
a5bca9
diff --git a/src/wayland/meta-wayland.c b/src/wayland/meta-wayland.c
a5bca9
index a593f0a7b7..129da8e20d 100644
a5bca9
--- a/src/wayland/meta-wayland.c
a5bca9
+++ b/src/wayland/meta-wayland.c
a5bca9
@@ -362,6 +362,12 @@ meta_wayland_override_display_name (const char *display_name)
a5bca9
   _display_name_override = g_strdup (display_name);
a5bca9
 }
a5bca9
 
a5bca9
+static const char *
a5bca9
+meta_wayland_get_xwayland_auth_file (MetaWaylandCompositor *compositor)
a5bca9
+{
a5bca9
+  return compositor->xwayland_manager.auth_file;
a5bca9
+}
a5bca9
+
a5bca9
 void
a5bca9
 meta_wayland_init (void)
a5bca9
 {
a5bca9
@@ -439,7 +445,10 @@ meta_wayland_init (void)
a5bca9
     }
a5bca9
 
a5bca9
   if (meta_should_autostart_x11_display ())
a5bca9
-    set_gnome_env ("DISPLAY", meta_wayland_get_xwayland_display_name (compositor));
a5bca9
+    {
a5bca9
+      set_gnome_env ("DISPLAY", meta_wayland_get_xwayland_display_name (compositor));
a5bca9
+      set_gnome_env ("XAUTHORITY", meta_wayland_get_xwayland_auth_file (compositor));
a5bca9
+    }
a5bca9
 
a5bca9
   set_gnome_env ("WAYLAND_DISPLAY", meta_wayland_get_wayland_display_name (compositor));
a5bca9
 }
a5bca9
diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c
a5bca9
index f3df9766ee..c883eb3d6f 100644
a5bca9
--- a/src/wayland/meta-xwayland.c
a5bca9
+++ b/src/wayland/meta-xwayland.c
a5bca9
@@ -32,6 +32,9 @@
a5bca9
 #include <sys/socket.h>
a5bca9
 #include <sys/stat.h>
a5bca9
 #include <sys/un.h>
a5bca9
+#include <sys/random.h>
a5bca9
+#include <unistd.h>
a5bca9
+#include <X11/Xauth.h>
a5bca9
 
a5bca9
 #include "compositor/meta-surface-actor-wayland.h"
a5bca9
 #include "meta/main.h"
a5bca9
@@ -525,6 +528,75 @@ choose_xdisplay (MetaXWaylandManager *manager)
a5bca9
   return TRUE;
a5bca9
 }
a5bca9
 
a5bca9
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (FILE, fclose)
a5bca9
+
a5bca9
+static gboolean
a5bca9
+prepare_auth_file (MetaXWaylandManager *manager)
a5bca9
+{
a5bca9
+  Xauth auth_entry = { 0 };
a5bca9
+  g_autoptr (FILE) fp = NULL;
a5bca9
+  char hostname[HOST_NAME_MAX + 1];
a5bca9
+  char auth_data[16];
a5bca9
+  int fd;
a5bca9
+
a5bca9
+  manager->auth_file = g_build_filename (g_get_user_runtime_dir (),
a5bca9
+                                         ".mutter-Xwaylandauth.XXXXXX",
a5bca9
+                                         NULL);
a5bca9
+
a5bca9
+  if (gethostname (hostname, HOST_NAME_MAX) < 0)
a5bca9
+    g_strlcpy (hostname, "localhost", HOST_NAME_MAX);
a5bca9
+
a5bca9
+  if (getrandom (auth_data, sizeof (auth_data), 0) != sizeof (auth_data))
a5bca9
+    {
a5bca9
+      g_warning ("Failed to get random data: %s", g_strerror (errno));
a5bca9
+      return FALSE;
a5bca9
+    }
a5bca9
+
a5bca9
+  auth_entry.family = FamilyLocal;
a5bca9
+  auth_entry.address = hostname;
a5bca9
+  auth_entry.address_length = strlen (auth_entry.address);
a5bca9
+  auth_entry.name = (char *) "MIT-MAGIC-COOKIE-1";
a5bca9
+  auth_entry.name_length = strlen (auth_entry.name);
a5bca9
+  auth_entry.data = auth_data;
a5bca9
+  auth_entry.data_length = sizeof (auth_data);
a5bca9
+
a5bca9
+  fd = g_mkstemp (manager->auth_file);
a5bca9
+  if (fd < 0)
a5bca9
+    {
a5bca9
+      g_warning ("Failed to open Xauthority file: %s", g_strerror (errno));
a5bca9
+      return FALSE;
a5bca9
+    }
a5bca9
+
a5bca9
+  fp = fdopen (fd, "w+");
a5bca9
+  if (!fp)
a5bca9
+    {
a5bca9
+      g_warning ("Failed to open Xauthority stream: %s", g_strerror (errno));
a5bca9
+      close (fd);
a5bca9
+      return FALSE;
a5bca9
+    }
a5bca9
+
a5bca9
+  if (!XauWriteAuth (fp, &auth_entry))
a5bca9
+    {
a5bca9
+      g_warning ("Error writing to Xauthority file: %s", g_strerror (errno));
a5bca9
+      return FALSE;
a5bca9
+    }
a5bca9
+
a5bca9
+  auth_entry.family = FamilyWild;
a5bca9
+  if (!XauWriteAuth (fp, &auth_entry))
a5bca9
+    {
a5bca9
+      g_warning ("Error writing to Xauthority file: %s", g_strerror (errno));
a5bca9
+      return FALSE;
a5bca9
+    }
a5bca9
+
a5bca9
+  if (fflush (fp) == EOF)
a5bca9
+    {
a5bca9
+      g_warning ("Error writing to Xauthority file: %s", g_strerror (errno));
a5bca9
+      return FALSE;
a5bca9
+    }
a5bca9
+
a5bca9
+  return TRUE;
a5bca9
+}
a5bca9
+
a5bca9
 static void
a5bca9
 xserver_finished_init (MetaXWaylandManager *manager)
a5bca9
 {
a5bca9
@@ -566,6 +638,9 @@ meta_xwayland_start (MetaXWaylandManager *manager,
a5bca9
   if (!choose_xdisplay (manager))
a5bca9
     goto out;
a5bca9
 
a5bca9
+  if (!prepare_auth_file (manager))
a5bca9
+    goto out;
a5bca9
+
a5bca9
   /* We want xwayland to be a wayland client so we make a socketpair to setup a
a5bca9
    * wayland protocol connection. */
a5bca9
   if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, xwayland_client_fd) < 0)
a5bca9
@@ -610,6 +685,7 @@ meta_xwayland_start (MetaXWaylandManager *manager,
a5bca9
                                                "-terminate",
a5bca9
                                                "-accessx",
a5bca9
                                                "-core",
a5bca9
+                                               "-auth", manager->auth_file,
a5bca9
                                                "-listen", "4",
a5bca9
                                                "-listen", "5",
a5bca9
                                                "-displayfd", "6",
a5bca9
@@ -678,6 +754,11 @@ meta_xwayland_stop (MetaXWaylandManager *manager)
a5bca9
   unlink (path);
a5bca9
 
a5bca9
   g_clear_pointer (&manager->display_name, g_free);
a5bca9
+  if (manager->auth_file)
a5bca9
+    {
a5bca9
+      unlink (manager->auth_file);
a5bca9
+      g_clear_pointer (&manager->auth_file, g_free);
a5bca9
+    }
a5bca9
   if (manager->lock_file)
a5bca9
     {
a5bca9
       unlink (manager->lock_file);
a5bca9
-- 
a5bca9
2.31.1
a5bca9
a5bca9
a5bca9
From fdf6969cf89dc9127fc9f4d03d9408e54ccd1b40 Mon Sep 17 00:00:00 2001
a5bca9
From: Olivier Fourdan <ofourdan@redhat.com>
a5bca9
Date: Mon, 19 Aug 2019 15:36:32 +0200
a5bca9
Subject: [PATCH 2/4] xwayland: pass the X11 display
a5bca9
a5bca9
Pass the X11 display to `meta_xwayland_complete_init()` so that it can
a5bca9
be used without poking into GDK.
a5bca9
a5bca9
https://gitlab.gnome.org/GNOME/mutter/merge_requests/735
a5bca9
---
a5bca9
 src/wayland/meta-xwayland-private.h | 3 ++-
a5bca9
 src/wayland/meta-xwayland.c         | 3 ++-
a5bca9
 src/x11/meta-x11-display.c          | 5 ++---
a5bca9
 3 files changed, 6 insertions(+), 5 deletions(-)
a5bca9
a5bca9
diff --git a/src/wayland/meta-xwayland-private.h b/src/wayland/meta-xwayland-private.h
a5bca9
index 38874eda3f..abcb09e49b 100644
a5bca9
--- a/src/wayland/meta-xwayland-private.h
a5bca9
+++ b/src/wayland/meta-xwayland-private.h
a5bca9
@@ -29,7 +29,8 @@ meta_xwayland_start (MetaXWaylandManager *manager,
a5bca9
                      struct wl_display   *display);
a5bca9
 
a5bca9
 void
a5bca9
-meta_xwayland_complete_init (MetaDisplay *display);
a5bca9
+meta_xwayland_complete_init (MetaDisplay *display,
a5bca9
+                             Display     *xdisplay);
a5bca9
 
a5bca9
 void
a5bca9
 meta_xwayland_stop (MetaXWaylandManager *manager);
a5bca9
diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c
a5bca9
index c883eb3d6f..350626dfdb 100644
a5bca9
--- a/src/wayland/meta-xwayland.c
a5bca9
+++ b/src/wayland/meta-xwayland.c
a5bca9
@@ -727,7 +727,8 @@ on_x11_display_closing (MetaDisplay *display)
a5bca9
 
a5bca9
 /* To be called right after connecting */
a5bca9
 void
a5bca9
-meta_xwayland_complete_init (MetaDisplay *display)
a5bca9
+meta_xwayland_complete_init (MetaDisplay *display,
a5bca9
+                             Display     *xdisplay)
a5bca9
 {
a5bca9
   /* We install an X IO error handler in addition to the child watch,
a5bca9
      because after Xlib connects our child watch may not be called soon
a5bca9
diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c
a5bca9
index 065ffcdda5..d40dcfa3f8 100644
a5bca9
--- a/src/x11/meta-x11-display.c
a5bca9
+++ b/src/x11/meta-x11-display.c
a5bca9
@@ -1066,14 +1066,13 @@ meta_x11_display_new (MetaDisplay *display, GError **error)
a5bca9
 
a5bca9
   g_assert (prepared_gdk_display);
a5bca9
   gdk_display = g_steal_pointer (&prepared_gdk_display);
a5bca9
+  xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display);
a5bca9
 
a5bca9
 #ifdef HAVE_WAYLAND
a5bca9
   if (meta_is_wayland_compositor ())
a5bca9
-    meta_xwayland_complete_init (display);
a5bca9
+    meta_xwayland_complete_init (display, xdisplay);
a5bca9
 #endif
a5bca9
 
a5bca9
-  xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display);
a5bca9
-
a5bca9
   if (meta_is_syncing ())
a5bca9
     XSynchronize (xdisplay, True);
a5bca9
 
a5bca9
-- 
a5bca9
2.31.1
a5bca9
a5bca9
a5bca9
From 25a0945aa69c479d6356a970b39e6ae42e43c877 Mon Sep 17 00:00:00 2001
a5bca9
From: Olivier Fourdan <ofourdan@redhat.com>
a5bca9
Date: Mon, 19 Aug 2019 15:48:17 +0200
a5bca9
Subject: [PATCH 3/4] xwayland: Use given X11 display for DnD setup
a5bca9
a5bca9
Use the provided X11 display instead of poking into GDK to get the X11
a5bca9
display.
a5bca9
a5bca9
https://gitlab.gnome.org/GNOME/mutter/merge_requests/735
a5bca9
---
a5bca9
 src/wayland/meta-xwayland-private.h   |  4 ++--
a5bca9
 src/wayland/meta-xwayland-selection.c | 18 +++++++++---------
a5bca9
 src/wayland/meta-xwayland.c           |  7 +++++--
a5bca9
 3 files changed, 16 insertions(+), 13 deletions(-)
a5bca9
a5bca9
diff --git a/src/wayland/meta-xwayland-private.h b/src/wayland/meta-xwayland-private.h
a5bca9
index abcb09e49b..f562d7c96d 100644
a5bca9
--- a/src/wayland/meta-xwayland-private.h
a5bca9
+++ b/src/wayland/meta-xwayland-private.h
a5bca9
@@ -36,8 +36,8 @@ void
a5bca9
 meta_xwayland_stop (MetaXWaylandManager *manager);
a5bca9
 
a5bca9
 /* wl_data_device/X11 selection interoperation */
a5bca9
-void     meta_xwayland_init_selection         (void);
a5bca9
-void     meta_xwayland_shutdown_selection     (void);
a5bca9
+void     meta_xwayland_init_selection         (Display *xdisplay);
a5bca9
+void     meta_xwayland_shutdown_selection     (Display *xdisplay);
a5bca9
 gboolean meta_xwayland_selection_handle_event (XEvent *xevent);
a5bca9
 
a5bca9
 const MetaWaylandDragDestFuncs * meta_xwayland_selection_get_drag_dest_funcs (void);
a5bca9
diff --git a/src/wayland/meta-xwayland-selection.c b/src/wayland/meta-xwayland-selection.c
a5bca9
index 808f913339..122bb76e1c 100644
a5bca9
--- a/src/wayland/meta-xwayland-selection.c
a5bca9
+++ b/src/wayland/meta-xwayland-selection.c
a5bca9
@@ -353,9 +353,9 @@ xdnd_send_status (MetaXWaylandSelection *selection_data,
a5bca9
 }
a5bca9
 
a5bca9
 static void
a5bca9
-meta_xwayland_init_dnd (MetaXWaylandManager *manager)
a5bca9
+meta_xwayland_init_dnd (MetaXWaylandManager *manager,
a5bca9
+                        Display             *xdisplay)
a5bca9
 {
a5bca9
-  Display *xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
a5bca9
   MetaDndBridge *dnd = &manager->selection_data->dnd;
a5bca9
   XSetWindowAttributes attributes;
a5bca9
   guint32 i, version = XDND_VERSION;
a5bca9
@@ -382,12 +382,12 @@ meta_xwayland_init_dnd (MetaXWaylandManager *manager)
a5bca9
 }
a5bca9
 
a5bca9
 static void
a5bca9
-meta_xwayland_shutdown_dnd (MetaXWaylandManager *manager)
a5bca9
+meta_xwayland_shutdown_dnd (MetaXWaylandManager *manager,
a5bca9
+                            Display             *xdisplay)
a5bca9
 {
a5bca9
   MetaDndBridge *dnd = &manager->selection_data->dnd;
a5bca9
 
a5bca9
-  XDestroyWindow (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
a5bca9
-                  dnd->dnd_window);
a5bca9
+  XDestroyWindow (xdisplay, dnd->dnd_window);
a5bca9
   dnd->dnd_window = None;
a5bca9
 }
a5bca9
 
a5bca9
@@ -1755,7 +1755,7 @@ shutdown_selection_bridge (MetaSelectionBridge *selection)
a5bca9
 }
a5bca9
 
a5bca9
 void
a5bca9
-meta_xwayland_init_selection (void)
a5bca9
+meta_xwayland_init_selection (Display *xdisplay)
a5bca9
 {
a5bca9
   MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
a5bca9
   MetaXWaylandManager *manager = &compositor->xwayland_manager;
a5bca9
@@ -1764,7 +1764,7 @@ meta_xwayland_init_selection (void)
a5bca9
 
a5bca9
   manager->selection_data = g_slice_new0 (MetaXWaylandSelection);
a5bca9
 
a5bca9
-  meta_xwayland_init_dnd (manager);
a5bca9
+  meta_xwayland_init_dnd (manager, xdisplay);
a5bca9
   init_selection_bridge (&manager->selection_data->clipboard,
a5bca9
                          gdk_x11_get_xatom_by_name ("CLIPBOARD"),
a5bca9
                          &compositor->seat->data_device.selection_ownership_signal);
a5bca9
@@ -1777,7 +1777,7 @@ meta_xwayland_init_selection (void)
a5bca9
 }
a5bca9
 
a5bca9
 void
a5bca9
-meta_xwayland_shutdown_selection (void)
a5bca9
+meta_xwayland_shutdown_selection (Display *xdisplay)
a5bca9
 {
a5bca9
   MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
a5bca9
   MetaXWaylandManager *manager = &compositor->xwayland_manager;
a5bca9
@@ -1787,7 +1787,7 @@ meta_xwayland_shutdown_selection (void)
a5bca9
 
a5bca9
   g_clear_object (&selection->clipboard.source);
a5bca9
 
a5bca9
-  meta_xwayland_shutdown_dnd (manager);
a5bca9
+  meta_xwayland_shutdown_dnd (manager, xdisplay);
a5bca9
   shutdown_selection_bridge (&selection->clipboard);
a5bca9
   shutdown_selection_bridge (&selection->primary);
a5bca9
   shutdown_selection_bridge (&selection->dnd.selection);
a5bca9
diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c
a5bca9
index 350626dfdb..3236711482 100644
a5bca9
--- a/src/wayland/meta-xwayland.c
a5bca9
+++ b/src/wayland/meta-xwayland.c
a5bca9
@@ -38,6 +38,7 @@
a5bca9
 
a5bca9
 #include "compositor/meta-surface-actor-wayland.h"
a5bca9
 #include "meta/main.h"
a5bca9
+#include "meta/meta-x11-display.h"
a5bca9
 #include "wayland/meta-wayland-actor-surface.h"
a5bca9
 
a5bca9
 enum
a5bca9
@@ -722,7 +723,9 @@ out:
a5bca9
 static void
a5bca9
 on_x11_display_closing (MetaDisplay *display)
a5bca9
 {
a5bca9
-  meta_xwayland_shutdown_selection ();
a5bca9
+  Display *xdisplay = meta_x11_display_get_xdisplay (display->x11_display);
a5bca9
+
a5bca9
+  meta_xwayland_shutdown_selection (xdisplay);
a5bca9
 }
a5bca9
 
a5bca9
 /* To be called right after connecting */
a5bca9
@@ -739,7 +742,7 @@ meta_xwayland_complete_init (MetaDisplay *display,
a5bca9
 
a5bca9
   g_signal_connect (display, "x11-display-closing",
a5bca9
                     G_CALLBACK (on_x11_display_closing), NULL);
a5bca9
-  meta_xwayland_init_selection ();
a5bca9
+  meta_xwayland_init_selection (xdisplay);
a5bca9
 }
a5bca9
 
a5bca9
 void
a5bca9
-- 
a5bca9
2.31.1
a5bca9
a5bca9
a5bca9
From a398699a53b9cc6efda4aa8abe0e3176bab80e92 Mon Sep 17 00:00:00 2001
a5bca9
From: Olivier Fourdan <ofourdan@redhat.com>
a5bca9
Date: Mon, 19 Aug 2019 15:50:54 +0200
a5bca9
Subject: [PATCH 4/4] xwayland: Add local user to xhost
a5bca9
a5bca9
With the addition of xauth support (commit a8984a81c), Xwayland would
a5bca9
rely only on the provided cookies for authentication.
a5bca9
a5bca9
As a result, running an Xclient from another VT (hence without the
a5bca9
XAUTHORITY environment variable set) would result in an access denied.
a5bca9
a5bca9
The same on X11 is granted because the local user is automatically
a5bca9
granted access to Xserver by the startup scripts.
a5bca9
a5bca9
Add the local user to xhost at startup on Xwayland so that the user can
a5bca9
still run a client by setting the DISPLAY as long as it's the same user
a5bca9
on the same host.
a5bca9
a5bca9
https://gitlab.gnome.org/GNOME/mutter/merge_requests/735
a5bca9
---
a5bca9
 src/wayland/meta-xwayland.c | 18 ++++++++++++++++++
a5bca9
 1 file changed, 18 insertions(+)
a5bca9
a5bca9
diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c
a5bca9
index 3236711482..275aeb78cb 100644
a5bca9
--- a/src/wayland/meta-xwayland.c
a5bca9
+++ b/src/wayland/meta-xwayland.c
a5bca9
@@ -598,6 +598,23 @@ prepare_auth_file (MetaXWaylandManager *manager)
a5bca9
   return TRUE;
a5bca9
 }
a5bca9
 
a5bca9
+static void
a5bca9
+add_local_user_to_xhost (Display *xdisplay)
a5bca9
+{
a5bca9
+  XHostAddress host_entry;
a5bca9
+  XServerInterpretedAddress siaddr;
a5bca9
+
a5bca9
+  siaddr.type = (char *) "localuser";
a5bca9
+  siaddr.typelength = strlen (siaddr.type);
a5bca9
+  siaddr.value = (char *) g_get_user_name();
a5bca9
+  siaddr.valuelength = strlen (siaddr.value);
a5bca9
+
a5bca9
+  host_entry.family = FamilyServerInterpreted;
a5bca9
+  host_entry.address = (char *) &siaddr;
a5bca9
+
a5bca9
+  XAddHost (xdisplay, &host_entry);
a5bca9
+}
a5bca9
+
a5bca9
 static void
a5bca9
 xserver_finished_init (MetaXWaylandManager *manager)
a5bca9
 {
a5bca9
@@ -743,6 +760,7 @@ meta_xwayland_complete_init (MetaDisplay *display,
a5bca9
   g_signal_connect (display, "x11-display-closing",
a5bca9
                     G_CALLBACK (on_x11_display_closing), NULL);
a5bca9
   meta_xwayland_init_selection (xdisplay);
a5bca9
+  add_local_user_to_xhost (xdisplay);
a5bca9
 }
a5bca9
 
a5bca9
 void
a5bca9
-- 
a5bca9
2.31.1
a5bca9