diff --git a/lib/core.sh b/lib/core.sh index dc29c34..75e405c 100644 --- a/lib/core.sh +++ b/lib/core.sh @@ -420,11 +420,17 @@ function _provide_bindings_as_user(){ # None ####################################### function _build_passwd_and_group(){ - if ! getent_cmd passwd > ${JUNEST_HOME}/etc/junest/passwd + # Enumeration of users/groups is disabled/limited depending on how nsswitch.conf + # is configured. + # Try to at least get the current user via `getent passwd $USER` since it uses + # a more reliable and faster system call (getpwnam(3)). + if ! getent_cmd passwd > ${JUNEST_HOME}/etc/junest/passwd || \ + ! getent_cmd passwd ${USER} >> ${JUNEST_HOME}/etc/junest/passwd then warn "getent command failed or does not exist. Binding directly from /etc/passwd." cp_cmd /etc/passwd ${JUNEST_HOME}/etc/junest/passwd fi + if ! getent_cmd group > ${JUNEST_HOME}/etc/junest/group then warn "getent command failed or does not exist. Binding directly from /etc/group." diff --git a/tests/unit-tests/test-core.sh b/tests/unit-tests/test-core.sh index a009510..1483d26 100755 --- a/tests/unit-tests/test-core.sh +++ b/tests/unit-tests/test-core.sh @@ -265,7 +265,7 @@ function test_build_passwd_and_group(){ echo $@ } GETENT=getent_cmd_mock assertCommandSuccess _build_passwd_and_group - assertEquals "passwd" "$(cat $JUNEST_HOME/etc/junest/passwd)" + assertEquals "$(echo -e "passwd\npasswd $USER")" "$(cat $JUNEST_HOME/etc/junest/passwd)" assertEquals "group" "$(cat $JUNEST_HOME/etc/junest/group)" } @@ -325,11 +325,11 @@ function test_delete_env(){ } function test_nested_env(){ - JUNEST_ENV=1 assertCommandFailOnStatus 106 bash -ic "source $JUNEST_ROOT/lib/utils.sh; source $JUNEST_ROOT/lib/core.sh" + JUNEST_ENV=1 assertCommandFailOnStatus 106 bash -c "source $JUNEST_ROOT/lib/utils.sh; source $JUNEST_ROOT/lib/core.sh" } function test_nested_env_not_set_variable(){ - JUNEST_ENV=aaa assertCommandFailOnStatus 107 bash -ic "source $JUNEST_ROOT/lib/utils.sh; source $JUNEST_ROOT/lib/core.sh" + JUNEST_ENV=aaa assertCommandFailOnStatus 107 bash -c "source $JUNEST_ROOT/lib/utils.sh; source $JUNEST_ROOT/lib/core.sh" } function test_qemu() {