[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: ${HOME} vs. g_get_home_dir ()

Ivan Shmakov wrote:
>         I do remember filing a bug or two against packages that refer to
>         the getent () data to find the user's “home” directory instead
>         of using the HOME environment variable.
>         The environment is the preferred place to check for this kind of
>         things: it's (usually) under the full control of the user, and
>         it's quite possible to run several instances of a single program
>         using different environments (with different executable file
>         search PATH's, locales, time zones, etc.), which occasionally
>         turns to be an immense aid to debugging.  (Want to use the
>         all-defaults configuration for a program?  Just start it like:
>         $ HOME="$(mktemp -dt -- foo.XXXXXXXX)" foo)
>         Now, Glib has g_get_home_dir (), whose description reads [1]:
> --cut--
>     Gets the current user's home directory as defined in the password
>     database.
>     Note that in contrast to traditional UNIX tools, this function
>     prefers passwd entries over the HOME environment variable.
> --cut--
>         I believe that this behavior is buggy.

Agreed entirely.  In particular, it breaks the very common use case of
running a program with sudo.  "sudo foo" leaves $HOME set to the user's
home directory rather than root, so that foo will use the same
configuration either way.  A user can then use sudo -H or sudo -i if
they want a more rootish environment.  Other programs that don't respect
$HOME include ssh, which forces ugly workarounds like this:
sudo ssh -o UserKnownHostsFile=$HOME/.ssh/known_hosts ...

- Josh Triplett

Reply to: