config/buildsystem: generate password hash in add_user using python

Python3's crypt module is capable of generating password hashes. Use that
instead of busybox:host's cryptpw function.

Move password hashing into config/function's add_user(), so one need not
remember to generate the hash and then pass it into add_user().

Signed-off-by: Ian Leonard <antonlacon@gmail.com>
This commit is contained in:
Ian Leonard 2021-06-28 21:51:09 +00:00
parent e0f9e2db10
commit 2cb6f17526
2 changed files with 3 additions and 3 deletions

View File

@ -1480,6 +1480,8 @@ add_user() {
PASSWORD="$2"
if [ "$PASSWORD" = "x" ]; then
PASSWORD="*"
else
PASSWORD=$(python -c "import crypt; print(crypt.crypt('$PASSWORD', crypt.mksalt(crypt.METHOD_SHA512)))")
fi
if ! grep -q "^$1:" ${INSTALL}/usr/cache/shadow; then
echo "$1:$PASSWORD:::::::" >> ${INSTALL}/usr/cache/shadow

View File

@ -180,12 +180,10 @@ makeinstall_target() {
}
post_install() {
ROOT_PWD="$(${TOOLCHAIN}/bin/cryptpw -m sha512 ${ROOT_PASSWORD})"
echo "chmod 4755 ${INSTALL}/usr/bin/busybox" >> ${FAKEROOT_SCRIPT}
echo "chmod 000 ${INSTALL}/usr/cache/shadow" >> ${FAKEROOT_SCRIPT}
add_user root "${ROOT_PWD}" 0 0 "Root User" "/storage" "/bin/sh"
add_user root "${ROOT_PASSWORD}" 0 0 "Root User" "/storage" "/bin/sh"
add_group root 0
add_group users 100