public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
From: "Joseph Reynolds" <jrey@linux.ibm.com>
To: OE-core <openembedded-core@lists.openembedded.org>
Subject: [PATCH] add new extrausers command passwd-expire
Date: Mon, 26 Oct 2020 15:41:20 -0500	[thread overview]
Message-ID: <978bccd7-a2f4-9aa0-9c77-9c10c81e068f@linux.ibm.com> (raw)

This enhances extrausers with a new passwd-expire command that causes
a local user's password to be expired as if the `passwd --expire`
command was run, so the password needs to be changed on initial login.

Example: EXTRA_USERS_PARAMS += " useradd ... sofia; passwd-expire sofia;"

Tested: on useradd accounts
When configured with Linux-PAM, console login prompts for and can
successfully change the password.  OpenSSH server works.  Dropbear
SSH server notes the password must be changed but does not offer a
password change dialog and rejects the login request.

Signed-off-by: Joseph Reynolds <joseph-reynolds@charter.net>
---
  meta/classes/extrausers.bbclass   |  3 +++
  meta/classes/useradd_base.bbclass | 18 ++++++++++++++++++
  2 files changed, 21 insertions(+)

diff --git a/meta/classes/extrausers.bbclass 
b/meta/classes/extrausers.bbclass
index 32569e9..90811bf 100644
--- a/meta/classes/extrausers.bbclass
+++ b/meta/classes/extrausers.bbclass
@@ -46,6 +46,9 @@ set_user_group () {
              usermod)
                  perform_usermod "${IMAGE_ROOTFS}" "-R ${IMAGE_ROOTFS} 
$opts"
                  ;;
+            passwd-expire)
+                perform_passwd_expire "${IMAGE_ROOTFS}" "$opts"
+                ;;
              groupmod)
                  perform_groupmod "${IMAGE_ROOTFS}" "-R ${IMAGE_ROOTFS} 
$opts"
                  ;;
diff --git a/meta/classes/useradd_base.bbclass 
b/meta/classes/useradd_base.bbclass
index 0d0bdb8..7f5b9b7 100644
--- a/meta/classes/useradd_base.bbclass
+++ b/meta/classes/useradd_base.bbclass
@@ -145,3 +145,21 @@ perform_usermod () {
      fi
      set -e
  }
+
+perform_passwd_expire () {
+    local rootdir="$1"
+    local opts="$2"
+    bbnote "${PN}: Performing equivalent of passwd --expire with [$opts]"
+    # Directly set sp_lstchg to 0 without using the passwd command: 
Only root can do that
+    local username=`echo "$opts" | awk '{ print $NF }'`
+    local user_exists="`grep "^$username:" $rootdir/etc/passwd || true`"
+    if test "x$user_exists" != "x"; then
+        eval flock -x $rootdir${sysconfdir} -c \"$PSEUDO sed -i 
\''s/^\('$username':[^:]*\):[^:]*:/\1:0:/'\' $rootdir/etc/shadow \" || tru
e
+        local passwd_lastchanged="`grep "^$username:" 
$rootdir/etc/shadow | cut -d: -f3`"
+        if test "x$passwd_lastchanged" != "x0"; then
+            bbfatal "${PN}: passwd --expire operation did not succeed."
+        fi
+    else
+        bbnote "${PN}: user $username doesn't exist, not expiring its 
password"
+    fi
+}
-- 
2.7.2


             reply	other threads:[~2020-10-26 20:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 20:41 Joseph Reynolds [this message]
2020-10-27 19:41 ` [OE-core] [PATCH] add new extrausers command passwd-expire Richard Purdie
2020-10-27 23:19   ` [OE-core] [PATCH] add new extrausers command passwd-expire - moved to PR 63 Joseph Reynolds
2020-10-27 23:40     ` Richard Purdie
  -- strict thread matches above, loose matches on Subject: below --
2020-11-10  3:56 [PATCH 0/1] Resend the patch from Joseph kai
2020-11-10  3:56 ` [PATCH] add new extrausers command passwd-expire kai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=978bccd7-a2f4-9aa0-9c77-9c10c81e068f@linux.ibm.com \
    --to=jrey@linux.ibm.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox