From: "seb (Sebastian Unger) via ruby-core" Date: 2023-06-12T03:06:40+00:00 Subject: [ruby-core:113879] [Ruby master Bug#19724] Dir.home returns incorrect home directory Issue #19724 has been reported by seb (Sebastian Unger). ---------------------------------------- Bug #19724: Dir.home returns incorrect home directory https://bugs.ruby-lang.org/issues/19724 * Author: seb (Sebastian Unger) * Status: Open * Priority: Normal * ruby -v: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux-gnu] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- 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 -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. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/