summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Vovk <adrianvovk@gmail.com>2022-05-02 16:53:43 +0000
committerJan Rybar <jrybar@redhat.com>2022-05-02 16:53:43 +0000
commitaf533784a33040ce91b03744c6fd5ba9aff3e007 (patch)
tree1220cdcb2c8827c42c4efe699f847bf52442f093 /src
parent74164aaf5a266c3f8a2527e60ecf29afa294b791 (diff)
downloadpolkit-af533784a33040ce91b03744c6fd5ba9aff3e007.tar.gz
pkexec: Don't chdir(~)
Diffstat (limited to 'src')
-rw-r--r--src/programs/pkexec.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/programs/pkexec.c b/src/programs/pkexec.c
index a45aa12..a67a1f7 100644
--- a/src/programs/pkexec.c
+++ b/src/programs/pkexec.c
@@ -73,7 +73,7 @@ usage (int argc, char *argv[])
g_printerr ("pkexec --version |\n"
" --help |\n"
" --disable-internal-agent |\n"
- " [--user username] [PROGRAM] [ARGUMENTS...]\n"
+ " [--keep-cwd] [--user username] [PROGRAM] [ARGUMENTS...]\n"
"\n"
"See the pkexec manual page for more details.\n"
"\n"
@@ -440,6 +440,7 @@ main (int argc, char *argv[])
gboolean opt_show_help;
gboolean opt_show_version;
gboolean opt_disable_internal_agent;
+ gboolean opt_keep_cwd;
PolkitAuthority *authority;
PolkitAuthorizationResult *result;
PolkitSubject *subject;
@@ -540,6 +541,7 @@ main (int argc, char *argv[])
opt_show_help = FALSE;
opt_show_version = FALSE;
opt_disable_internal_agent = FALSE;
+ opt_keep_cwd = FALSE;
for (n = 1; n < (guint) argc; n++)
{
if (strcmp (argv[n], "--help") == 0)
@@ -570,6 +572,10 @@ main (int argc, char *argv[])
{
opt_disable_internal_agent = TRUE;
}
+ else if (strcmp (argv[n], "--keep-cwd") == 0)
+ {
+ opt_keep_cwd = TRUE;
+ }
else
{
break;
@@ -1007,10 +1013,13 @@ main (int argc, char *argv[])
}
/* change to home directory */
- if (chdir (pw->pw_dir) != 0)
- {
- g_printerr ("Error changing to home directory %s: %s\n", pw->pw_dir, g_strerror (errno));
- goto out;
+ if (!opt_keep_cwd)
+ {
+ if (chdir (pw->pw_dir) != 0)
+ {
+ g_printerr ("Error changing to home directory %s: %s\n", pw->pw_dir, g_strerror (errno));
+ goto out;
+ }
}
/* Log the fact that we're executing a command */