Skip to contentSkip to conversation

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

PATCH Superseded [email protected] 3 participants 9 messages Nov 29, 2025 2 messages not in the archive

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 v2 2/2 rootfs-postcommands.bbclass: remove the '\n' in 'no password' banner

From: Chen Qi <[email protected]>

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

---
 meta/classes-recipe/rootfs-postcommands.bbclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/classes-recipe/rootfs-postcommands.bbclass +1 -1
index bcc25798b9..3c4edc0301 100644
@@ -262,7 +262,7 @@ 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
 	fi
 }
 
Signature · 1 line
2.43.0
#2 lore raw

Re: [OE-core][PATCH V2 2/2] rootfs-postcommands.bbclass: remove the '\n' in 'no password' banner

meta/classes-recipe/rootfs-postcommands.bbclass add_empty_root_password_note () { · line 265

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

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

meta/classes-recipe/rootfs-postcommands.bbclass +1 -1
-               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

\n does not actually make it into /etc/issue and does get converted to a newline (as intended) somewhere on the way:

alex@Zen2:/srv/storage/alex/yocto/build-64$ cat
tmp/work/qemux86_64-poky-linux/core-image-minimal/1.0/rootfs/etc/issue
Poky (Yocto Project Reference Distro)
5.2.99+snapshot-449cd68248749daedc9990c4094ef5577907ea3d \n \l

Type 'root' to login with superuser privileges (no password will be asked).

alex@Zen2:/srv/storage/alex/yocto/build-64$

Is that not the case in your build?

Alex

author
#3 lore raw

RE: [OE-core][PATCH V2 2/2] rootfs-postcommands.bbclass: remove the '\n' in 'no password' banner

Hi Alex,

Without this patch:

In build directory:

$ cat tmp/work/qemux86_64-poky-linux/core-image-full-cmdline/1.0/rootfs/etc/issue
Poky (Yocto Project Reference Distro) 5.2.99+snapshot-0cd922ad0f9cf59226660c30b1db07e23c09460c \n \l

Type 'root' to login with superuser privileges (no password will be asked).\n

On target:
Poky (Yocto Project Reference Distro) 5.2.99+snapshot-0cd922ad0f9cf59226660c30b1db07e23c09460c qemux86-64 ttyS0

Type 'root' to login with superuser privileges (no password will be asked).qemux86-64

Regards,
Qi

-----Original Message-----
From: Alexander Kanavin <[email protected]>
Sent: Saturday, November 29, 2025 9:20 PM
To: Chen, Qi <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [OE-core][PATCH V2 2/2] rootfs-postcommands.bbclass: remove the '\n' in 'no password' banner

Review

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

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

(quoted diff) +2 -1
-               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

\n does not actually make it into /etc/issue and does get converted to a newline (as intended) somewhere on the way:

alex@Zen2:/srv/storage/alex/yocto/build-64$ cat tmp/work/qemux86_64-poky-linux/core-image-minimal/1.0/rootfs/etc/issue
Poky (Yocto Project Reference Distro)
5.2.99+snapshot-449cd68248749daedc9990c4094ef5577907ea3d \n \l

Type 'root' to login with superuser privileges (no password will be asked).

alex@Zen2:/srv/storage/alex/yocto/build-64$

Is that not the case in your build?

Alex

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#5 lore raw

RE: [OE-core][PATCH V2 2/2] rootfs-postcommands.bbclass: remove the '\n' in 'no password' banner

Hi Alex,

I think I know what's going on here.
Your sh symlinks to dash, right?

It seems that bash and dash have different behavior on echo + '\n'.

I'll send out V3 so that both dash and bash work as expected.

Regards,
Qi

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Chen Qi via lists.openembedded.org
Sent: Saturday, November 29, 2025 10:24 PM
To: Alexander Kanavin <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [OE-core][PATCH V2 2/2] rootfs-postcommands.bbclass: remove the '\n' in 'no password' banner

Hi Alex,

Without this patch:

In build directory:

$ cat tmp/work/qemux86_64-poky-linux/core-image-full-cmdline/1.0/rootfs/etc/issue
Poky (Yocto Project Reference Distro) 5.2.99+snapshot-0cd922ad0f9cf59226660c30b1db07e23c09460c \n \l

Type 'root' to login with superuser privileges (no password will be asked).\n

On target:
Poky (Yocto Project Reference Distro) 5.2.99+snapshot-0cd922ad0f9cf59226660c30b1db07e23c09460c qemux86-64 ttyS0

Type 'root' to login with superuser privileges (no password will be asked).qemux86-64

Regards,
Qi

-----Original Message-----
From: Alexander Kanavin <[email protected]>
Sent: Saturday, November 29, 2025 9:20 PM
To: Chen, Qi <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [OE-core][PATCH V2 2/2] rootfs-postcommands.bbclass: remove the '\n' in 'no password' banner

Review

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

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

(quoted diff) +2 -1
-               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

\n does not actually make it into /etc/issue and does get converted to a newline (as intended) somewhere on the way:

alex@Zen2:/srv/storage/alex/yocto/build-64$ cat tmp/work/qemux86_64-poky-linux/core-image-minimal/1.0/rootfs/etc/issue
Poky (Yocto Project Reference Distro)
5.2.99+snapshot-449cd68248749daedc9990c4094ef5577907ea3d \n \l

Type 'root' to login with superuser privileges (no password will be asked).

alex@Zen2:/srv/storage/alex/yocto/build-64$

Is that not the case in your build?

Alex

#6 lore raw

Re: [OE-core][PATCH V2 2/2] rootfs-postcommands.bbclass: remove the '\n' in 'no password' banner

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

I think I know what's going on here.
Your sh symlinks to dash, right?

It seems that bash and dash have different behavior on echo + '\n'.

bash's ‘echo’ requires the ‘-e’ option so that \n is interpreted as new line.

#7 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 8 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.

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.

If you are setting a password for root, then why at the same time you add root-login-with-empty-password to fragments? Aren't they contradicting each other, and you should pick one or the other, but not both? Yes up to now EXTRA_USERS_PARAMS setting took priority over the empty-password setting, and gave you the desired outcome, but that does not in itself make the combination a valid configuration with a well-defined behaviour that needs to be preserved.

Alex

author
#8 lore raw

This combination has been working for 10+ years. I do like banner. But it's sometimes misleading. See the example. This patch is trying to make it not misleading.

I don’t think erroring out in useradd_base.bbclass with special case is a good approach. Why so? I don't see any strong reason to break previous behavior. And that makes useradd_base.bbclass bundled with IMAGE_FEATURES.

Regards,
Qi

-----Original Message-----
From: Alexander Kanavin <[email protected]>
Sent: Saturday, November 29, 2025 6:16 PM
To: Chen, Qi <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [OE-core][PATCH V2 1/2] rootfs-postcommands.bbclass: fix adding 'no password' banner

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 8 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.

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.

If you are setting a password for root, then why at the same time you add root-login-with-empty-password to fragments? Aren't they contradicting each other, and you should pick one or the other, but not both? Yes up to now EXTRA_USERS_PARAMS setting took priority over the empty-password setting, and gave you the desired outcome, but that does not in itself make the combination a valid configuration with a well-defined behaviour that needs to be preserved.

Alex

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#10 lore raw

Hi Alex,

To make things clear, my major focus is on the 'no password' banner. This patch is to ensure that the banner is not displayed when not appropriate.

I can accept the behavior that 'no password for root' image feature errors out with root account manipulated (though I don't like it). I just don't think we should make useradd related bbclasses accessing IMAGE_FEATURES.

Please give these two patches a second thought. If you have other suggestion, please let me know.

Regards,
Qi

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Chen Qi via lists.openembedded.org
Sent: Saturday, November 29, 2025 10:19 PM
To: Alexander Kanavin <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [OE-core][PATCH V2 1/2] rootfs-postcommands.bbclass: fix adding 'no password' banner

This combination has been working for 10+ years. I do like banner. But it's sometimes misleading. See the example. This patch is trying to make it not misleading.

I don’t think erroring out in useradd_base.bbclass with special case is a good approach. Why so? I don't see any strong reason to break previous behavior. And that makes useradd_base.bbclass bundled with IMAGE_FEATURES.

Regards,
Qi

-----Original Message-----
From: Alexander Kanavin <[email protected]>
Sent: Saturday, November 29, 2025 6:16 PM
To: Chen, Qi <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [OE-core][PATCH V2 1/2] rootfs-postcommands.bbclass: fix adding 'no password' banner

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 8 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.

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.

If you are setting a password for root, then why at the same time you add root-login-with-empty-password to fragments? Aren't they contradicting each other, and you should pick one or the other, but not both? Yes up to now EXTRA_USERS_PARAMS setting took priority over the empty-password setting, and gave you the desired outcome, but that does not in itself make the combination a valid configuration with a well-defined behaviour that needs to be preserved.

Alex