From 16257ef4d1baefbad5759f48e290c6460b923ec4 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 8 Sep 2012 23:40:09 +0200 Subject: [PATCH] Create XAUTHORITY from HOME if unset --- src/programs/pkexec.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/programs/pkexec.c b/src/programs/pkexec.c index 840eb3c..12a29e5 100644 --- a/src/programs/pkexec.c +++ b/src/programs/pkexec.c @@ -608,6 +608,27 @@ main (int argc, char *argv[]) g_ptr_array_add (saved_env, g_strdup (value)); } + /* xauth defaults to $HOME/.Xauthority if XAUTHORITY is not set. */ + if (g_getenv("XAUTHORITY") == NULL) + { + const gchar *key = "XAUTHORITY"; + const gchar *xauthfile = "/.Xauthority"; + const gchar *home = g_getenv("HOME"); + gchar *value; + + /* An empty or unset $HOME variable will yield /.Xauthority. */ + if (home == NULL) + value = g_strdup (xauthfile); + else + value = g_strconcat (home, xauthfile, NULL); + + if (!validate_environment_variable (key, value)) + goto out; + + g_ptr_array_add (saved_env, g_strdup (key)); + g_ptr_array_add (saved_env, value); + } + /* Nuke the environment to get a well-known and sanitized environment to avoid attacks * via e.g. the DBUS_SYSTEM_BUS_ADDRESS environment variable and similar. */ -- 1.7.12