Commit 2017608f authored by Emanuele Aina's avatar Emanuele Aina

Make the homedir overridable with the NSS_UNKNOWN_HOME env var

By default `libnss-unknown` violates the assumption that the result of
calling `getpwent()`/`getpwuid()` does not change when the environment
changes as the value for the `pw_dir` field depends on the `$HOME` var.

For instance the `posix/wordexp-test` test in the glibc testsuite
breaks with `libnss-unknown`:

* the call to `getpwuid()` with `HOME=/dummy/home` returns
  `/dummy/home` due to `libnss-unknown`
* `unsetenv ("HOME")` is called
* any call to `getpwuid()` will now return `/` due to
  `libnss-unknown` as no `$HOME` is set
* test fails because results don't match

Setting `NSS_UNKNOWN_HOME` before running the test will get rid of the
dependency between `getpwuid()` and `$HOME`.
Signed-off-by: Emanuele Aina's avatarEmanuele Aina <emanuele.aina@collabora.com>
parent 58bd6d6a
......@@ -31,7 +31,11 @@ static char * determine_homedir (uid_t uid, char *buffer, size_t buflen)
if (uid != getuid())
return UNKNOWN_USER_DIR;
home = getenv ("HOME");
home = getenv ("NSS_UNKNOWN_HOME");
if (home == NULL)
home = getenv ("HOME");
if (home == NULL)
return UNKNOWN_USER_DIR;
......
......@@ -17,6 +17,7 @@ get_passwd_entry () {
env -i \
${HOME+HOME=$HOME} \
${NSS_WRAPPER_DEBUGLEVEL+NSS_WRAPPER_DEBUGLEVEL=$NSS_WRAPPER_DEBUGLEVEL} \
${NSS_UNKNOWN_HOME+NSS_UNKNOWN_HOME=$NSS_UNKNOWN_HOME} \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_PASSWD=/dev/null \
NSS_WRAPPER_GROUP=/dev/null \
......@@ -56,4 +57,13 @@ test_debug "echo home = '$home'"
test_expect_success 'Fallback to "/" if $HOME is not set' \
'test "$home" = "/"'
export NSS_UNKNOWN_HOME="/unknownhome"
export HOME="/fakehome"
entry=$(get_passwd_entry $(id -u))
home=$(echo "$entry" | cut -f 6 -d ":")
test_debug "echo entry = '$entry'"
test_debug "echo home = '$home'"
test_expect_success 'Check that NSS_UNKNOWN_HOME overrides HOME' \
'test "$home" = "$NSS_UNKNOWN_HOME"'
test_done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment