1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/internal
Alan D. Salewski c15cddd1d5 Allow Dir.home to work for non-login procs when $HOME not set
Allow the 'Dir.home' method to reliably locate the user's home directory when
all three of the following are true at the same time:

    1. Ruby is running on a Unix-like OS
    2. The $HOME environment variable is not set
    3. The process is not a descendant of login(1) (or a work-alike)

The prior behavior was that the lookup could only work for login-descended
processes.

This is accomplished by looking up the user's record in the password database
by uid (getpwuid_r(3)) as a fallback to the lookup by name (getpwname_r(3))
which is still attempted first (based on the name, if any, returned by
getlogin_r(3)).

If getlogin_r(3), getpwnam_r(3), and/or getpwuid_r(3) is not available at
compile time, will fallback on using their respective non-*_r() variants:
getlogin(3), getpwnam(3), and/or getpwuid(3).

The rationale for attempting to do the lookup by name prior to doing it by uid
is to accommodate the possibility of multiple login names (each with its own
record in the password database, so each with a potentially different home
directory) being mapped to the same uid (as is explicitly allowed for by
POSIX; see getlogin(3posix)).

Preserves the existing behavior for login-descended processes, and adds the
new capability of having Dir.home being able to find the user's home directory
for non-login-descended processes.

Fixes [Bug #16787]

Related discussion:
    https://bugs.ruby-lang.org/issues/16787
    https://github.com/ruby/ruby/pull/3034
2020-05-23 23:16:28 +09:00
..
array.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
bignum.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
bits.h Fix a typo [ci skip] 2020-05-18 17:42:50 +09:00
class.h Fix origin iclass pointer for modules 2020-05-22 20:31:23 -07:00
compar.h add #include guard hack 2020-04-13 16:06:00 +09:00
compile.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
compilers.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
complex.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
cont.h add #include guard hack 2020-04-13 16:06:00 +09:00
dir.h add #include guard hack 2020-04-13 16:06:00 +09:00
enc.h add #include guard hack 2020-04-13 16:06:00 +09:00
encoding.h add #include guard hack 2020-04-13 16:06:00 +09:00
enum.h add #include guard hack 2020-04-13 16:06:00 +09:00
enumerator.h add #include guard hack 2020-04-13 16:06:00 +09:00
error.h Merge pull request #3047 from mame/suppress-backtrace 2020-05-15 01:22:56 +09:00
eval.h add #include guard hack 2020-04-13 16:06:00 +09:00
file.h add #include guard hack 2020-04-13 16:06:00 +09:00
fixnum.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
gc.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
hash.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
imemo.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
inits.h add #include guard hack 2020-04-13 16:06:00 +09:00
io.h add #include guard hack 2020-04-13 16:06:00 +09:00
load.h add #include guard hack 2020-04-13 16:06:00 +09:00
loadpath.h add #include guard hack 2020-04-13 16:06:00 +09:00
math.h add #include guard hack 2020-04-13 16:06:00 +09:00
missing.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
mjit.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
numeric.h add #include guard hack 2020-04-13 16:06:00 +09:00
object.h add #include guard hack 2020-04-13 16:06:00 +09:00
parse.h add #include guard hack 2020-04-13 16:06:00 +09:00
proc.h add #include guard hack 2020-04-13 16:06:00 +09:00
process.h Allow Dir.home to work for non-login procs when $HOME not set 2020-05-23 23:16:28 +09:00
random.h add #include guard hack 2020-04-13 16:06:00 +09:00
range.h add #include guard hack 2020-04-13 16:06:00 +09:00
rational.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
re.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
sanitizers.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
serial.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
signal.h add #include guard hack 2020-04-13 16:06:00 +09:00
static_assert.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
string.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
struct.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
symbol.h add #include guard hack 2020-04-13 16:06:00 +09:00
thread.h add #include guard hack 2020-04-13 16:06:00 +09:00
time.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
transcode.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
util.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
variable.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
vm.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00
warnings.h sed -i 's|ruby/impl|ruby/internal|' 2020-05-11 09:24:08 +09:00