Commit 75a1b939 authored by Sjoerd Simons's avatar Sjoerd Simons

Merge branch 'master' into 'master'

Add NSS_UNKNOWN_HOME with some tests

See merge request !1
parents 3faffd5f 764dc6ce
image: debian:buster-slim
before_script:
- apt update
- apt-get install --no-install-recommends -y
build-essential
meson
libnss3-dev
sharness
libnss-wrapper
test:
script:
- meson _build/ .
- cd _build/
- ninja
- meson test -v
artifacts:
when: always
paths:
- _build/meson-logs
- _build/test-results
......@@ -3,4 +3,9 @@ project('libnss-unknown',
version: '0.0.1')
sources = [ 'src/nss-unknown.c' ]
shared_library('nss_unknown', sources, soversion: '2', install: true)
shlib = shared_library('nss_unknown', sources, soversion: '2', install: true)
testenv = environment()
testenv.set('MESON_BUILD_ROOT', meson.build_root())
test('Resolve unknown current user', find_program('tests/resolve-unknown-current-user.t'), env: testenv, depends:shlib)
......@@ -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;
......
#!/bin/sh
# SPDX-License-Identifier: LGPL-2.1+
#
# Copyright (C) 2018 Collabora ltd.
# @author Emanuele Aina <emanuele.aina@collabora.com>
test_description="Use nss_wrapper to pretend the current user is not in the db"
. /usr/share/sharness/sharness.sh
test_debug "export NSS_WRAPPER_DEBUGLEVEL=3"
get_passwd_entry () {
USERID=$1
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 \
NSS_WRAPPER_MODULE_SO_PATH="${MESON_BUILD_ROOT}/libnss_unknown.so" \
NSS_WRAPPER_MODULE_FN_PREFIX=unknown \
getent passwd "$USERID"
}
export HOME="/fakehome"
entry=$(get_passwd_entry $(id -u))
test_debug "echo entry = '$entry'"
test_expect_success 'A passwd entry is returned' \
'test -n "$entry"'
username=$(echo "$entry" | cut -f 1 -d ":")
shell=$(echo "$entry" | cut -f 7 -d ":")
home=$(echo "$entry" | cut -f 6 -d ":")
test_debug "echo username = '$username'"
test_expect_success 'A made-up username is returned for the unknown user' \
'test "$username" = uid-$(id -u)'
test_debug "echo shell = '$shell'"
test_expect_success 'The nologin command is returned as the user shell' \
'test "$shell" = /sbin/nologin'
test_debug "echo home = '$home'"
test_expect_success 'The $HOME env var is returned as the user homedir' \
'test "$home" = "$HOME"'
unset HOME
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 '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