PolicyKit: Branch 'master'

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon May 2 16:53:44 UTC 2022


 docs/man/pkexec.xml   |    9 +++++++++
 src/programs/pkexec.c |   19 ++++++++++++++-----
 2 files changed, 23 insertions(+), 5 deletions(-)

New commits:
commit af533784a33040ce91b03744c6fd5ba9aff3e007
Author: Adrian Vovk <adrianvovk at gmail.com>
Date:   Mon May 2 16:53:43 2022 +0000

    pkexec: Don't chdir(~)

diff --git a/docs/man/pkexec.xml b/docs/man/pkexec.xml
index eda9841..013b56d 100644
--- a/docs/man/pkexec.xml
+++ b/docs/man/pkexec.xml
@@ -31,6 +31,9 @@
 
     <cmdsynopsis>
       <command>pkexec</command>
+      <arg choise="plain">
+		<option>--keep-cwd</option>
+      </arg>
       <group>
         <arg choice="plain">
           <option>--user</option>
@@ -106,6 +109,12 @@
       should only be used for legacy programs.
     </para>
 
+    <para>
+      <command>pkexec</command> will run <replaceable>PROGRAM</replaceable>
+      in <replaceable>username</replaceable>'s home directory, unless
+      <option>--keep-cwd</option> is used to override this behavior
+    </para>
+
     <para>
       Note that <command>pkexec</command> does no validation of
       the <replaceable>ARGUMENTS</replaceable> passed
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 */


More information about the hal-commit mailing list