Project

General

Profile

Actions

Bug #19724

closed

Dir.home returns incorrect home directory

Added by seb (Sebastian Unger) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux-gnu]
[ruby-core:113879]

Description

This is probably related to 16787.

From the patch on that issue I conclude that ruby uses getlogin and co to obtain the name of the logged-in user, but that is not valid. Ruby must use the uid of the running process since the user that logged in may since have switched to a different user-id (e.g. using sudo -u <user> -i). This will cause getlogin to still report the name that the user logged in at the current terminal, but that is not the user that ruby should be using.

E.g., If I ssh into a machine as root, and then use sudo -u user -i and then run a ruby process that tries to write to "my" home directory it fails (most commonly in trying to access /root/.gem or similar).

I know why ruby originally wanted to use getlogin (at least according to comments on the above issue), which was to support multiple login names having the same UID but different home directories. To the best of my knowledge, this was always an invalid configuration. Usernames and UIDs in the PW DB should have a 1-to-1 mapping. In any case getlogin is not the right answer, since it does not yield the login name of the running process.

It is particularly bad since ruby uses this method even if ${HOME} is set!

This is on current up-to-date Ubuntu 22.04.

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0