Commit 11492f2e authored by Natanael Copa's avatar Natanael Copa
Browse files

setup-user: avoid eternal loop on adduser failure

Make sure we dont loop forever if adduser fails to create the user.

fixes https://gitlab.alpinelinux.org/alpine/alpine-conf/-/issues/10519
parent ac908aa7
Pipeline #126807 passed with stage
in 22 seconds
......@@ -55,6 +55,10 @@ while true; do
else
suggest=no
fi
# dont suggest something that has failed before
if [ "$suggest" = "$failed_username" ]; then
suggest=
fi
ask "Setup a user? (enter a lower-case loginname, or 'no')" $suggest
case "$resp" in
no) exit 0;;
......@@ -76,6 +80,8 @@ while true; do
if ! [ -n "$interactive" ]; then
exit 1
fi
failed_username="$username"
username=
done
if [ -n "$interactive" ] && [ -z "$keysopt" ]; then
......
......@@ -7,6 +7,7 @@ init_tests \
setup_user_interactive_no \
setup_user_interactive \
setup_user_interactive_fullname \
setup_user_interactive_fullname_existing \
setup_user_interactive_singlename \
setup_user_interactive_suggest_ssh \
setup_user_groups_commas \
......@@ -74,6 +75,20 @@ setup_user_interactive_fullname_body() {
setup-user -f "Joe User" -k none <answers
}
setup_user_interactive_fullname_existing_body() {
init_env
(
echo "existinguser"
echo "testuser"
) >answers
ADDUSER_EXIST=existinguser atf_check -s exit:0 \
-o match:"Setup a user.*\[existinguser\]" \
-o match:"Setup a user.*\) adduser" \
-o match:"adduser.* -g existinguser .*testuser" \
-e match:"adduser: user 'existinguser' in use" \
setup-user -f "existinguser" -k none <answers
}
setup_user_interactive_singlename_body() {
init_env
echo "" >answers
......
Supports Markdown
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