mirror of
https://github.com/fsquillace/junest.git
synced 2026-01-23 02:34:30 +00:00
Mitigate user missing from getent enumeration
Sometimes `getent passwd` does not give the user information.
This change tries to at least get the current user via
`getent passwd $USER` since it uses
a more reliable and faster system call (getpwnam(3)).
Reference:
be748493a3
This commit is contained in:
parent
6d4e5f7404
commit
6568430add
2 changed files with 10 additions and 4 deletions
|
|
@ -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."
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue