summaryrefslogtreecommitdiff
path: root/src/x-server.c
diff options
context:
space:
mode:
authorCorentin Noël <corentin.noel@collabora.com>2023-01-28 03:24:26 +0100
committerRobert Ancell <robert.ancell@gmail.com>2023-04-26 16:48:32 +1200
commit75bf8fb062e3f409d6252449dae631440aa95b72 (patch)
treeef7a6dc9658c3bfe7a657d7f29bf2e43755383e3 /src/x-server.c
parentc2ee2b96eeb880ab5b463e8cbef940bcfc0fa661 (diff)
downloadlightdm-git-75bf8fb062e3f409d6252449dae631440aa95b72.tar.gz
x-server: Avoid reusing the local X server if the hostname has changed
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.
Diffstat (limited to 'src/x-server.c')
-rw-r--r--src/x-server.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/x-server.c b/src/x-server.c
index ae64808a..f17a842d 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,21 @@ x_server_set_authority (XServer *server, XAuthority *authority)
priv->authority = g_object_ref (authority);
}
+void
+x_server_set_local_authority (XServer *server)
+{
+ XServerPrivate *priv = x_server_get_instance_private (server);
+
+ g_return_if_fail (server != NULL);
+
+ g_clear_object (&priv->authority);
+ char display_number[12];
+ g_snprintf(display_number, sizeof(display_number), "%d", x_server_get_display_number (server));
+
+ gethostname (priv->local_hostname, 1024);
+ 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 +126,18 @@ x_server_get_session_type (DisplayServer *server)
static gboolean
x_server_get_can_share (DisplayServer *server)
{
- return TRUE;
+ XServerPrivate *priv = x_server_get_instance_private ((XServer*) server);
+ gchar actual_local_hostname[1024];
+
+ g_return_val_if_fail (server != NULL, FALSE);
+
+ 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, 1024);
+ return g_strcmp0 (actual_local_hostname, priv->local_hostname) == 0;
}
static gboolean