Skip to content

Commit

Permalink
Merge pull request #739 from infosiftr/improved-root-password-test
Browse files Browse the repository at this point in the history
Improve no-root-password with more knowledge from the manpages
  • Loading branch information
yosifkit committed May 15, 2015
2 parents e23e1e7 + a06f6b8 commit 221fefd
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion test/tests/no-root-password/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,28 @@
set -e

pass="$(docker run --rm --entrypoint awk "$1" -F ':' '$1 == "root" { print $2 }' /etc/passwd)"

if [ "$pass" = 'x' ]; then
# 'x' means password is in /etc/shadow instead
pass="$(docker run --rm --entrypoint awk --user root "$1" -F ':' '$1 == "root" { print $2 }' /etc/shadow)"
fi
[ -z "$pass" -o "$pass" = '*' ]

if [ -z "$pass" -o "$pass" = '*' ]; then
# '*' and '' mean no password
exit 0
fi

if [ "${pass:0:1}" = '!' ]; then
# '!anything' means "locked" password
echo >&2 "warning: locked password detected for root: '$pass'"
exit 0
fi

if [ "${pass:0:1}" = '$' ]; then
# gotta be crypt ($id$salt$encrypted), must be a fail
echo >&2 "error: crypt password detected for root: '$pass'"
exit 1
fi

echo >&2 "warning: garbage password detected for root: '$pass'"
exit 0

0 comments on commit 221fefd

Please sign in to comment.