Skip to content

Commit

Permalink
Explicitly use chdir("/") instead of relying on ~user being set properly
Browse files Browse the repository at this point in the history
On non-systemd systems if the user is changed manually, polkitd will
also change directory. The homedir of the user might not be set
correctly, so just change to /.

This is a no-op on systemd systems, as the user is set in the unit
file, so this code never runs.
  • Loading branch information
mbiebl authored and bluca committed Dec 17, 2024
1 parent c1369cd commit 0acdcb5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/polkitbackend/polkitd.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ become_user (const gchar *user,
goto out;
}

if (chdir (pw->pw_dir) != 0)
if (chdir ("/") != 0)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Error changing to home directory %s: %m",
"Error changing to root directory %s: %m",
pw->pw_dir);
goto out;
}
Expand Down

0 comments on commit 0acdcb5

Please sign in to comment.