From 0192cb1539206a6950a43ade5d6230ad876b5e0f Mon Sep 17 00:00:00 2001 From: liuxinhao Date: Mon, 8 May 2023 18:08:49 +0800 Subject: [PATCH] x-server: Avoid reusing the local X server if the hostname --- ...id-reusing-the-local-X-server-if-the.patch | 153 ++++++++++++++++++ lightdm.spec | 6 +- 2 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 1002-fix-x-server-Avoid-reusing-the-local-X-server-if-the.patch diff --git a/1002-fix-x-server-Avoid-reusing-the-local-X-server-if-the.patch b/1002-fix-x-server-Avoid-reusing-the-local-X-server-if-the.patch new file mode 100644 index 0000000..836b23a --- /dev/null +++ b/1002-fix-x-server-Avoid-reusing-the-local-X-server-if-the.patch @@ -0,0 +1,153 @@ +From 00730089ab023e91c3da06897f7c461d8c89369d Mon Sep 17 00:00:00 2001 +From: liuxinhao +Date: Sat, 13 May 2023 10:02:48 +0800 +Subject: [PATCH] fix(x-server): Avoid reusing the local X server if the + hostname + +- If the hostname has changed while using a local seat, we will fail to connect and return to the greeter. Avoid this behavior by recreating the server, upstream commit: https://github.com/canonical/lightdm/pull/288/commits/7aa342e9f78fd276c7c47cfd6a28faf9c0e20a69 +--- + src/seat-local.c | 4 +--- + src/seat-xvnc.c | 4 +--- + src/x-authority.c | 8 -------- + src/x-authority.h | 2 -- + src/x-server.c | 34 +++++++++++++++++++++++++++++++++- + src/x-server.h | 2 ++ + 6 files changed, 37 insertions(+), 17 deletions(-) + +diff --git a/src/seat-local.c b/src/seat-local.c +index aa6a0b0..90bb145 100644 +--- a/src/seat-local.c ++++ b/src/seat-local.c +@@ -175,9 +175,7 @@ create_x_server (SeatLocal *seat) + if (command) + x_server_local_set_command (x_server, command); + +- g_autofree gchar *number = g_strdup_printf ("%d", x_server_get_display_number (X_SERVER (x_server))); +- g_autoptr(XAuthority) cookie = x_authority_new_local_cookie (number); +- x_server_set_authority (X_SERVER (x_server), cookie); ++ x_server_set_local_authority (X_SERVER (x_server)); + + const gchar *layout = seat_get_string_property (SEAT (seat), "xserver-layout"); + if (layout) +diff --git a/src/seat-xvnc.c b/src/seat-xvnc.c +index a726a9d..47658df 100644 +--- a/src/seat-xvnc.c ++++ b/src/seat-xvnc.c +@@ -57,9 +57,7 @@ seat_xvnc_create_display_server (Seat *seat, Session *session) + + g_autoptr(XServerXVNC) x_server = x_server_xvnc_new (); + priv->x_server = g_object_ref (x_server); +- g_autofree gchar *number = g_strdup_printf ("%d", x_server_get_display_number (X_SERVER (x_server))); +- g_autoptr(XAuthority) cookie = x_authority_new_local_cookie (number); +- x_server_set_authority (X_SERVER (x_server), cookie); ++ x_server_set_local_authority (X_SERVER (x_server)); + x_server_xvnc_set_socket (x_server, g_socket_get_fd (priv->connection)); + + const gchar *command = config_get_string (config_get_instance (), "VNCServer", "command"); +diff --git a/src/x-authority.c b/src/x-authority.c +index baaf4be..a1500bd 100644 +--- a/src/x-authority.c ++++ b/src/x-authority.c +@@ -65,14 +65,6 @@ x_authority_new_cookie (guint16 family, const guint8 *address, gsize address_len + return x_authority_new (family, address, address_length, number, "MIT-MAGIC-COOKIE-1", cookie, 16); + } + +-XAuthority * +-x_authority_new_local_cookie (const gchar *number) +-{ +- gchar hostname[1024]; +- gethostname (hostname, 1024); +- return x_authority_new_cookie (XAUTH_FAMILY_LOCAL, (guint8 *) hostname, strlen (hostname), number); +-} +- + void + x_authority_set_family (XAuthority *auth, guint16 family) + { +diff --git a/src/x-authority.h b/src/x-authority.h +index 1ddb852..d9f0e0b 100644 +--- a/src/x-authority.h ++++ b/src/x-authority.h +@@ -55,8 +55,6 @@ XAuthority *x_authority_new (guint16 family, const guint8 *address, gsize addres + + XAuthority *x_authority_new_cookie (guint16 family, const guint8 *address, gsize address_length, const gchar *number); + +-XAuthority *x_authority_new_local_cookie (const gchar *number); +- + void x_authority_set_family (XAuthority *auth, guint16 family); + + guint16 x_authority_get_family (XAuthority *auth); +diff --git a/src/x-server.c b/src/x-server.c +index ae64808..a6ab5ef 100644 +--- a/src/x-server.c ++++ b/src/x-server.c +@@ -27,6 +27,9 @@ typedef struct + /* Authority */ + XAuthority *authority; + ++ /* Cached hostname for the authority */ ++ gchar local_hostname[1024]; ++ + /* Connection to this X server */ + xcb_connection_t *connection; + } XServerPrivate; +@@ -91,6 +94,23 @@ x_server_set_authority (XServer *server, XAuthority *authority) + priv->authority = g_object_ref (authority); + } + ++void ++x_server_set_local_authority (XServer *server) ++{ ++ XServerPrivate *priv = NULL; ++ char display_number[12]; ++ ++ g_return_if_fail (server != NULL); ++ ++ priv = x_server_get_instance_private (server); ++ ++ gethostname (priv->local_hostname, sizeof(priv->local_hostname)); ++ ++ g_clear_object (&priv->authority); ++ g_snprintf(display_number, sizeof(display_number), "%d", x_server_get_display_number (server)); ++ priv->authority = x_authority_new_cookie (XAUTH_FAMILY_LOCAL, (guint8 *) priv->local_hostname, strlen (priv->local_hostname), display_number); ++} ++ + XAuthority * + x_server_get_authority (XServer *server) + { +@@ -108,7 +128,19 @@ x_server_get_session_type (DisplayServer *server) + static gboolean + x_server_get_can_share (DisplayServer *server) + { +- return TRUE; ++ XServerPrivate *priv = NULL; ++ gchar actual_local_hostname[1024]; ++ ++ g_return_val_if_fail (server != NULL, FALSE); ++ ++ priv = x_server_get_instance_private ((XServer*) server); ++ if (priv->local_hostname[0] == '\0') ++ return TRUE; ++ ++ /* The XAuthority depends on the hostname so we can't share the display ++ * server if the hostname has been changed */ ++ gethostname (actual_local_hostname, sizeof(actual_local_hostname)); ++ return g_strcmp0 (actual_local_hostname, priv->local_hostname) == 0; + } + + static gboolean +diff --git a/src/x-server.h b/src/x-server.h +index 18b9163..4d125b2 100644 +--- a/src/x-server.h ++++ b/src/x-server.h +@@ -55,6 +55,8 @@ gsize x_server_get_authentication_data_length (XServer *server); + + void x_server_set_authority (XServer *server, XAuthority *authority); + ++void x_server_set_local_authority (XServer *server); ++ + XAuthority *x_server_get_authority (XServer *server); + + G_END_DECLS +-- +2.33.0 + diff --git a/lightdm.spec b/lightdm.spec index 879d9dd..d45b08f 100644 --- a/lightdm.spec +++ b/lightdm.spec @@ -7,7 +7,7 @@ Name: lightdm Summary: A cross-desktop Display Manager Version: 1.30.0 -Release: 13 +Release: 14 # library/bindings are LGPLv2 or LGPLv3, the rest GPLv3+ License: (LGPLv2 or LGPLv3) and GPLv3+ @@ -44,6 +44,7 @@ Patch9002: 9002-dm-tool-lock-function-patch.patch # kylin Patch1001: 1001-fix-translator-fixed-the-issue-that-lightdm-s-PAM-me.patch +Patch1002: 1002-fix-x-server-Avoid-reusing-the-local-X-server-if-the.patch BuildRequires: gettext BuildRequires: gnome-common @@ -314,6 +315,9 @@ fi %changelog +* Mon May 08 2023 liuxinhao - 1.30.0-14 +- x-server: Avoid reusing the local X server if the hostname + * Thu Feb 24 2022 Wenlong.Ding - 1.30.0-13 - Fixed the problem that lightdm.service start with not found systemd-pam.so error. -- Gitee