14604f
From 818cd2018ca66e804ea30066c44572ca128a24a7 Mon Sep 17 00:00:00 2001
14604f
From: Karel Zak <kzak@redhat.com>
14604f
Date: Tue, 7 Jun 2022 09:11:56 +0200
14604f
Subject: lslogins: improve prefixes interpretation
14604f
14604f
It seems that for example 'passwd --lock' uses two exclamation marks
14604f
in password  field. It seems better to assume arbitrary number of '!'
14604f
and '*' prefixes.
14604f
14604f
The patch also makes description of the PWD-EMPTY output field more
14604f
explicit.
14604f
14604f
Upstream: http://github.com/util-linux/util-linux/commit/c51cba1e838ae7e36a843ec785543492bb8737cd
14604f
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2093166
14604f
Signed-off-by: Karel Zak <kzak@redhat.com>
14604f
---
14604f
 login-utils/lslogins.c | 31 +++++++++++++++++++++++++------
14604f
 1 file changed, 25 insertions(+), 6 deletions(-)
14604f
14604f
diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
14604f
index 6f804aa35..b81afc6c7 100644
14604f
--- a/login-utils/lslogins.c
14604f
+++ b/login-utils/lslogins.c
14604f
@@ -216,7 +216,7 @@ static const struct lslogins_coldesc coldescs[] =
14604f
 {
14604f
 	[COL_USER]          = { "USER",		N_("user name"), N_("Username"), 0.1, SCOLS_FL_NOEXTREMES },
14604f
 	[COL_UID]           = { "UID",		N_("user ID"), "UID", 1, SCOLS_FL_RIGHT},
14604f
-	[COL_PWDEMPTY]      = { "PWD-EMPTY",	N_("password not required"), N_("Password not required"), 1, SCOLS_FL_RIGHT },
14604f
+	[COL_PWDEMPTY]      = { "PWD-EMPTY",	N_("password not defined"), N_("Password not required (empty)"), 1, SCOLS_FL_RIGHT },
14604f
 	[COL_PWDDENY]       = { "PWD-DENY",	N_("login by password disabled"), N_("Login by password disabled"), 1, SCOLS_FL_RIGHT },
14604f
 	[COL_PWDLOCK]       = { "PWD-LOCK",	N_("password defined, but locked"), N_("Password is locked"), 1, SCOLS_FL_RIGHT },
14604f
 	[COL_NOLOGIN]       = { "NOLOGIN",	N_("log in disabled by nologin(8) or pam_nologin(8)"), N_("No login"), 1, SCOLS_FL_RIGHT },
14604f
@@ -755,16 +755,24 @@ static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const c
14604f
 			break;
14604f
 		case COL_PWDEMPTY:
14604f
 			if (shadow) {
14604f
-				if (!*shadow->sp_pwdp) /* '\0' */
14604f
+				const char *p = shadow->sp_pwdp;
14604f
+
14604f
+				while (p && (*p == '!' || *p == '*'))
14604f
+					p++;
14604f
+
14604f
+				if (!p || !*p)
14604f
 					user->pwd_empty = STATUS_TRUE;
14604f
 			} else
14604f
 				user->pwd_empty = STATUS_UNKNOWN;
14604f
 			break;
14604f
 		case COL_PWDDENY:
14604f
 			if (shadow) {
14604f
-				if ((*shadow->sp_pwdp == '!' ||
14604f
-				     *shadow->sp_pwdp == '*') &&
14604f
-				    !valid_pwd(shadow->sp_pwdp + 1))
14604f
+				const char *p = shadow->sp_pwdp;
14604f
+
14604f
+				while (p && (*p == '!' || *p == '*'))
14604f
+					p++;
14604f
+
14604f
+				if (p && *p && p != shadow->sp_pwdp && !valid_pwd(p))
14604f
 					user->pwd_deny = STATUS_TRUE;
14604f
 			} else
14604f
 				user->pwd_deny = STATUS_UNKNOWN;
14604f
@@ -772,7 +780,18 @@ static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const c
14604f
 
14604f
 		case COL_PWDLOCK:
14604f
 			if (shadow) {
14604f
-				if (*shadow->sp_pwdp == '!' && valid_pwd(shadow->sp_pwdp + 1))
14604f
+				const char *p = shadow->sp_pwdp;
14604f
+				int i = 0;
14604f
+
14604f
+				/* 'passwd --lock' uses two exclamation marks,
14604f
+				 * shadow(5) describes the lock as "field which
14604f
+				 * starts with an exclamation mark". Let's
14604f
+				 * support more '!' ...
14604f
+				 */
14604f
+				while (p && *p == '!')
14604f
+					p++, i++;
14604f
+
14604f
+				if (i != 0 && (!*p || valid_pwd(p)))
14604f
 					user->pwd_lock = STATUS_TRUE;
14604f
 			} else
14604f
 				user->pwd_lock = STATUS_UNKNOWN;
14604f
-- 
14604f
2.36.1
14604f