From 2cb6f17526e01a36f2657f25f9ec81cabed7eaf9 Mon Sep 17 00:00:00 2001 From: Ian Leonard Date: Mon, 28 Jun 2021 21:51:09 +0000 Subject: [PATCH] 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 --- config/functions | 2 ++ packages/sysutils/busybox/package.mk | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/functions b/config/functions index a909cb6d67..32e83460c2 100644 --- a/config/functions +++ b/config/functions @@ -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 diff --git a/packages/sysutils/busybox/package.mk b/packages/sysutils/busybox/package.mk index a1497d7e98..5bdc5e40d8 100644 --- a/packages/sysutils/busybox/package.mk +++ b/packages/sysutils/busybox/package.mk @@ -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