Skip to contentSkip to conversation

rootfs-postcommands.bbclass: fix adding 'no password' banner

PATCH Superseded [email protected] 2 participants 5 messages Nov 29, 2025 – Dec 1, 2025

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 rootfs-postcommands.bbclass: fix adding 'no password' banner

From: Chen Qi <[email protected]>

It's possible that users use EXTRA_USERS_PARAMS to set password for root or explicitly expire root password. So we need to check these two cases to ensure the 'no password' banner is not misleading.

As an example:
In conf/toolcfg.cfg:
OE_FRAGMENTS += "distro/poky core/yocto/root-login-with-empty-password In local.conf:
INHERIT += "extrausers"
EXTRA_USERS_PARAMS += " passwd-expire root;"

Note that allowing 'empty-root-password' image feature + setting/expiring root password has been working since available. This patch focuses on the banner. We want to ensure that it's there only when root really has empty password.

We need to ensure that the function runs after set_user_group function from extrausers.bbclass. This is because the check is valid only after things set in EXTRA_USERS_PARAMS are done. So change to use :append.

---
 meta/classes-recipe/rootfs-postcommands.bbclass | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
meta/classes-recipe/rootfs-postcommands.bbclass +7 -3
index d3a569ba3e..bcc25798b9 100644
@@ -4,8 +4,8 @@
 # SPDX-License-Identifier: MIT
 #
 
-# Zap the root password if empty-root-password feature is not enabled
-ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "empty-root-password", "add_empty_root_password_note", "zap_empty_root_password ",d)}'
+# Zap the root password if empty-root-password feature is not enabled else add a 'no password' banner if appropriate
+ROOTFS_POSTPROCESS_COMMAND:append = ' ${@bb.utils.contains("IMAGE_FEATURES", "empty-root-password", "add_empty_root_password_note", "zap_empty_root_password ",d)}'
 
 # Allow dropbear/openssh to accept logins from accounts with an empty password string if allow-empty-password is enabled
 ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "allow-empty-password", "ssh_allow_empty_password ", "",d)}'
@@ -259,7 +259,11 @@ zap_empty_root_password () {
 # This function adds a note to the login banner that the system is configured for root logins without password
 #
 add_empty_root_password_note () {
-	echo "Type 'root' to login with superuser privileges (no password will be asked).\n" >> ${IMAGE_ROOTFS}/etc/issue
+	rootpw="`grep '^root:' ${IMAGE_ROOTFS}/etc/shadow | cut -d':' -f2`"
+	rootpw_lastchanged="`grep "^root:" ${IMAGE_ROOTFS}/etc/shadow | cut -d: -f3`"
+	if [ -z "$rootpw" -a "$rootpw_lastchanged" != "0" ]; then
+		echo "Type 'root' to login with superuser privileges (no password will be asked).\n" >> ${IMAGE_ROOTFS}/etc/issue
+	fi
 }
 
 #
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 2/2 rootfs-postcommands.bbclass: fix echo + '\n' in 'no password' banner

From: Chen Qi <[email protected]>

The '\n' means hostname instead of new line in /etc/issues.

bash and dash have different behavior on echo + '\n'. So we avoid this '\n' and use an extra echo "" instead.

---
 meta/classes-recipe/rootfs-postcommands.bbclass | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
meta/classes-recipe/rootfs-postcommands.bbclass +2 -1
index bcc25798b9..a4e8517229 100644
@@ -262,7 +262,8 @@ add_empty_root_password_note () {
 	rootpw="`grep '^root:' ${IMAGE_ROOTFS}/etc/shadow | cut -d':' -f2`"
 	rootpw_lastchanged="`grep "^root:" ${IMAGE_ROOTFS}/etc/shadow | cut -d: -f3`"
 	if [ -z "$rootpw" -a "$rootpw_lastchanged" != "0" ]; then
-		echo "Type 'root' to login with superuser privileges (no password will be asked).\n" >> ${IMAGE_ROOTFS}/etc/issue
+		echo "Type 'root' to login with superuser privileges (no password will be asked)." >> ${IMAGE_ROOTFS}/etc/issue
+		echo "" >> ${IMAGE_ROOTFS}/etc/issue
 	fi
 }
 
Signature · 1 line
2.43.0
#2 lore raw

Re: [OE-core][PATCH V3 2/2] rootfs-postcommands.bbclass: fix echo + '\n' in 'no password' banner

This is ok, but you should probably order it to come first, so it can be taken regardless of what happens to the other patch in the set.

Alex

Quoted 39 lines · Chen Qi via lists.openembedded.org

From: Chen Qi <[email protected]>

The '\n' means hostname instead of new line in /etc/issues.

bash and dash have different behavior on echo + '\n'. So we avoid this '\n' and use an extra echo "" instead.

---
 meta/classes-recipe/rootfs-postcommands.bbclass | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
meta/classes-recipe/rootfs-postcommands.bbclass +2 -2
index bcc25798b9..a4e8517229 100644
@@ -262,7 +262,8 @@ add_empty_root_password_note () {
        rootpw="`grep '^root:' ${IMAGE_ROOTFS}/etc/shadow | cut -d':' -f2`"
        rootpw_lastchanged="`grep "^root:" ${IMAGE_ROOTFS}/etc/shadow | cut -d: -f3`"
        if [ -z "$rootpw" -a "$rootpw_lastchanged" != "0" ]; then
-               echo "Type 'root' to login with superuser privileges (no password will be asked).\n" >> ${IMAGE_ROOTFS}/etc/issue
+               echo "Type 'root' to login with superuser privileges (no password will be asked)." >> ${IMAGE_ROOTFS}/etc/issue
+               echo "" >> ${IMAGE_ROOTFS}/etc/issue
        fi
 }
 
--

2.43.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#226942): https://lists.openembedded.org/g/openembedded-core/message/226942
Mute This Topic: https://lists.openembedded.org/mt/116527246/1686489
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#3 lore raw
In reply to [email protected]
Quoted 11 lines · Chen Qi via lists.openembedded.org

It's possible that users use EXTRA_USERS_PARAMS to set password for root or explicitly expire root password. So we need to check these two cases to ensure the 'no password' banner is not misleading.

As an example:
In conf/toolcfg.cfg:
OE_FRAGMENTS += "distro/poky core/yocto/root-login-with-empty-password In local.conf:
INHERIT += "extrausers"
EXTRA_USERS_PARAMS += " passwd-expire root;"

Quoted 4 lines

Note that allowing 'empty-root-password' image feature + setting/expiring root password has been working since available. This patch focuses on the banner. We want to ensure that it's there only when root really has empty password.

Ok, it took me a moment (and an image build/runqemu execution) to figure out the use case for the above. Which is: make an image that requires setting a root password on first boot, but without having to first enter a static initial password. In which case the banner is indeed misleading.

The patch can probably be tweaked to ensure the check for needing to add a banner runs last (at the point where no further modifications to the root filesystem are going to happen), and it can be made unconditional, and only checking the actual content of the root filesystem, and not accessing IMAGE_FEATURES at all.

Is that ok? Can you do it like that? And tweak the commit message to explain what that configuration actually does :)

Alex

author
#4 lore raw
Quoted 29 lines · Alexander Kanavin
Quoted 11 lines · Chen Qi via lists.openembedded.org

It's possible that users use EXTRA_USERS_PARAMS to set password for root or explicitly expire root password. So we need to check these two cases to ensure the 'no password' banner is not misleading.

As an example:
In conf/toolcfg.cfg:
OE_FRAGMENTS += "distro/poky core/yocto/root-login-with-empty-password In local.conf:
INHERIT += "extrausers"
EXTRA_USERS_PARAMS += " passwd-expire root;"

Quoted 4 lines

Note that allowing 'empty-root-password' image feature + setting/expiring root password has been working since available. This patch focuses on the banner. We want to ensure that it's there only when root really has empty password.

Ok, it took me a moment (and an image build/runqemu execution) to figure out the use case for the above. Which is: make an image that requires setting a root password on first boot, but without having to first enter a static initial password. In which case the banner is indeed misleading.

The patch can probably be tweaked to ensure the check for needing to add a banner runs last (at the point where no further modifications to the root filesystem are going to happen), and it can be made unconditional, and only checking the actual content of the root filesystem, and not accessing IMAGE_FEATURES at all.

Quoted 4 lines

Is that ok? Can you do it like that? And tweak the commit message to explain what that configuration actually does :)

Alex

Yes. Good idea.

I'll use this method in V4. I'll also re-order these two patches.

Regards,
Qi