Commit 3cdc7448 authored by David Zeuthen's avatar David Zeuthen
Browse files

Save original cwd in pkexec(1) since it will change during the life-time


Signed-off-by: default avatarDavid Zeuthen <davidz@redhat.com>
parent 12e4ee33
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <polkit/polkit.h> #include <polkit/polkit.h>
static gchar *original_user_name = NULL; static gchar *original_user_name = NULL;
static gchar *original_cwd = NULL;
static gchar *command_line = NULL; static gchar *command_line = NULL;
static struct passwd *pw; static struct passwd *pw;
...@@ -77,7 +78,6 @@ log_message (gint level, ...@@ -77,7 +78,6 @@ log_message (gint level,
static gboolean is_log_open = FALSE; static gboolean is_log_open = FALSE;
va_list var_args; va_list var_args;
gchar *s; gchar *s;
const gchar *cwd;
const gchar *tty; const gchar *tty;
if (!is_log_open) if (!is_log_open)
...@@ -92,7 +92,6 @@ log_message (gint level, ...@@ -92,7 +92,6 @@ log_message (gint level,
s = g_strdup_vprintf (format, var_args); s = g_strdup_vprintf (format, var_args);
va_end (var_args); va_end (var_args);
cwd = get_current_dir_name ();
tty = ttyname (0); tty = ttyname (0);
if (tty == NULL) if (tty == NULL)
tty = "unknown"; tty = "unknown";
...@@ -104,7 +103,7 @@ log_message (gint level, ...@@ -104,7 +103,7 @@ log_message (gint level,
s, s,
pw->pw_name, pw->pw_name,
tty, tty,
cwd, original_cwd,
command_line); command_line);
/* and then on stderr */ /* and then on stderr */
...@@ -332,7 +331,7 @@ validate_environment_variable (const gchar *key, ...@@ -332,7 +331,7 @@ validate_environment_variable (const gchar *key,
if (!is_valid_shell (value)) if (!is_valid_shell (value))
{ {
log_message (LOG_CRIT, TRUE, log_message (LOG_CRIT, TRUE,
"The value for the SHELL variable was not found the /etc/shells file."); "The value for the SHELL variable was not found the /etc/shells file");
g_printerr ("\n" g_printerr ("\n"
"This incident has been reported.\n"); "This incident has been reported.\n");
goto out; goto out;
...@@ -343,7 +342,7 @@ validate_environment_variable (const gchar *key, ...@@ -343,7 +342,7 @@ validate_environment_variable (const gchar *key,
strstr (value, "..") != NULL) strstr (value, "..") != NULL)
{ {
log_message (LOG_CRIT, TRUE, log_message (LOG_CRIT, TRUE,
"The value for environment variable %s contains suscipious content.", "The value for environment variable %s contains suscipious content",
key); key);
g_printerr ("\n" g_printerr ("\n"
"This incident has been reported.\n"); "This incident has been reported.\n");
...@@ -433,6 +432,18 @@ main (int argc, char *argv[]) ...@@ -433,6 +432,18 @@ main (int argc, char *argv[])
} }
original_user_name = g_strdup (g_get_user_name ()); original_user_name = g_strdup (g_get_user_name ());
if (original_user_name == NULL)
{
g_print ("Error getting user name.\n");
goto out;
}
original_cwd = g_strdup (get_current_dir_name ());
if (original_cwd == NULL)
{
g_print ("Error getting cwd.\n");
goto out;
}
/* First process options and find the command-line to invoke. Avoid using fancy library routines /* First process options and find the command-line to invoke. Avoid using fancy library routines
* that depend on environtment variables since we haven't cleared the environment just yet. * that depend on environtment variables since we haven't cleared the environment just yet.
...@@ -801,6 +812,7 @@ main (int argc, char *argv[]) ...@@ -801,6 +812,7 @@ main (int argc, char *argv[])
g_free (command_line); g_free (command_line);
g_free (opt_user); g_free (opt_user);
g_free (original_user_name); g_free (original_user_name);
g_free (original_cwd);
return ret; return ret;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment