Skip to contentSkip to conversation

extrausers.bbclass: use '+=' for ROOTFS_POSTPROCESS_COMMAND

PATCH New [email protected] 1 participant 2 messages Dec 17, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/2 extrausers.bbclass: use '+=' for ROOTFS_POSTPROCESS_COMMAND

From: Chen Qi <[email protected]>

This is the only place in oe-core that still uses apppend for ROOTFS_POSTPROCESS_COMMAND. It's modifying users and groups and such behavior does not need to run as the last step. So change to use '+='.

---
 meta/classes/extrausers.bbclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/classes/extrausers.bbclass +1 -1
index c825c06df9..bfb70b7180 100644
@@ -23,7 +23,7 @@ inherit useradd_base
 PACKAGE_INSTALL:append = " ${@['', 'base-passwd shadow'][bool(d.getVar('EXTRA_USERS_PARAMS'))]}"
 
 # Image level user / group settings
-ROOTFS_POSTPROCESS_COMMAND:append = " set_user_group"
+ROOTFS_POSTPROCESS_COMMAND += "set_user_group"
 
 # Image level user / group settings
 set_user_group () {
Signature · 1 line
2.43.0
#1 lore raw

PATCH v6 2/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, below are configurations to make an image requiring setting a root password on first boot, but without having to first enter a static initial password:

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;"

Adding such banner is only meaningful when base-passwd and baes-files are installed. In case of container image, they might not be installed (e.g., container-test-image). So add extra checking for it. With the above logic, we avoid breaking the following oe-selftest test case:
containerimage.ContainerImageTests.test_expected_files

---
 meta/classes-recipe/rootfs-postcommands.bbclass | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
meta/classes-recipe/rootfs-postcommands.bbclass +12 -3
index f4fbc4c57e..2a36840f29 100644
@@ -5,7 +5,7 @@
 #
 
 # 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)}'
+ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "empty-root-password", "", "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)}'
@@ -58,6 +58,9 @@ inherit image-artifact-names
 SORT_PASSWD_POSTPROCESS_COMMAND ??= "tidy_shadowutils_files"
 ROOTFS_POSTPROCESS_COMMAND += '${SORT_PASSWD_POSTPROCESS_COMMAND}'
 
+# Check and add 'no root password' banner.
+ROOTFS_POSTPROCESS_COMMAND += "add_empty_root_password_note"
+
 #
 # Note that useradd-staticids.bbclass has to be used to ensure that
 # the numeric IDs of dynamically created entries remain stable.
@@ -259,8 +262,14 @@ 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)." >> ${IMAGE_ROOTFS}/etc/issue
-	echo "" >> ${IMAGE_ROOTFS}/etc/issue
+	if [ -e ${IMAGE_ROOTFS}/etc/shadow -a -e ${IMAGE_ROOTFS}/etc/issue ]; then
+		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)." >> ${IMAGE_ROOTFS}/etc/issue
+			echo "" >> ${IMAGE_ROOTFS}/etc/issue
+		fi
+	fi
 }
 
 #
Signature · 1 line
2.43.0