[2/2] classes/image-account-extension: Add flag to force password change on first login

Message ID 20220511131338.450234-3-Quirin.Gylstorff@siemens.com
State Superseded, archived
Headers show
Series Fix possible build errors due to expired root account | expand

Commit Message

Quirin Gylstorff May 11, 2022, 5:13 a.m. UTC
From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

This avoids possible errors if `passwd --expire root` is
set during package installation.

This flag is necesssary as

```
USER_root[expire] = "1970-01-01"
```

disables the root account and displays the message:

If the user tries to login the following message is displayed:

```
Your account has expired; please contact your system administrator.
Authentication failure
``` 

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 doc/user_manual.md                           | 1 +
 meta/classes/image-account-extension.bbclass | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

Patch

diff --git a/doc/user_manual.md b/doc/user_manual.md
index cdb73224..02874b6d 100644
--- a/doc/user_manual.md
+++ b/doc/user_manual.md
@@ -678,6 +678,7 @@  The `USERS` and `USER_<username>` variable works similar to the `GROUPS` and `GR
    - `system` - `useradd` will be called with `--system`.
    - `allow-empty-password` - Even if the `password` flag is empty, it will still be set. This results in a login without password.
    - `clear-text-password` - The `password` flag of the given user contains a clear-text password and not an encrypted version of it.
+   - `force-passwd-change` - Force the user to change to password on first login.
 
 #### Home directory contents prefilling
 
diff --git a/meta/classes/image-account-extension.bbclass b/meta/classes/image-account-extension.bbclass
index caa962a0..99de8b0d 100644
--- a/meta/classes/image-account-extension.bbclass
+++ b/meta/classes/image-account-extension.bbclass
@@ -17,7 +17,7 @@  USERS ??= ""
 #USER_root[home] = "/home/root"
 #USER_root[shell] = "/bin/sh"
 #USER_root[groups] = "audio video"
-#USER_root[flags] = "no-create-home create-home system allow-empty-password clear-text-password"
+#USER_root[flags] = "no-create-home create-home system allow-empty-password clear-text-password force-passwd-change"
 
 GROUPS ??= ""
 
@@ -258,5 +258,10 @@  image_configure_accounts() {
             printf '%s:%s' "$name" "$password" | sudo chroot '${ROOTFSDIR}' \
                 /usr/sbin/chpasswd $chpasswd_args
         fi
+        if [ "${flags}" != "${flags%*,force-passwd-change,*}" ]; then
+            echo "Execute passwd to force password change on first boot for \"$name\""
+            sudo -E chroot '${ROOTFSDIR}' \
+                /usr/bin/passwd --expire "$name"
+        fi
     done
 }