dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0082-lslogins-improve-prefixes-interpretation.patch

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