Blame 0011-lslogins-improve-prefixes-interpretation.patch

Karel Zak 18b0e4
From 53339f53ab71c138578d4102a4e4011344d33b2d Mon Sep 17 00:00:00 2001
Karel Zak 18b0e4
From: Karel Zak <kzak@redhat.com>
Karel Zak 18b0e4
Date: Tue, 7 Jun 2022 09:11:56 +0200
Karel Zak 18b0e4
Subject: lslogins: improve prefixes interpretation
Karel Zak 18b0e4
Karel Zak 18b0e4
It seems that for example 'passwd --lock' uses two exclamation marks
Karel Zak 18b0e4
in password  field. It seems better to assume arbitrary number of '!'
Karel Zak 18b0e4
and '*' prefixes.
Karel Zak 18b0e4
Karel Zak 18b0e4
The patch also makes description of the PWD-EMPTY output field more
Karel Zak 18b0e4
explicit.
Karel Zak 18b0e4
Karel Zak 18b0e4
Upstream: http://github.com/util-linux/util-linux/commit/c51cba1e838ae7e36a843ec785543492bb8737cd
Karel Zak 18b0e4
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2094216
Karel Zak 18b0e4
Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak 18b0e4
---
Karel Zak 18b0e4
 login-utils/lslogins.c | 33 ++++++++++++++++++++++++++-------
Karel Zak 18b0e4
 1 file changed, 26 insertions(+), 7 deletions(-)
Karel Zak 18b0e4
Karel Zak 18b0e4
diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
Karel Zak 18b0e4
index c37df9096..1332a9925 100644
Karel Zak 18b0e4
--- a/login-utils/lslogins.c
Karel Zak 18b0e4
+++ b/login-utils/lslogins.c
Karel Zak 18b0e4
@@ -225,7 +225,7 @@ static const struct lslogins_coldesc coldescs[] =
Karel Zak 18b0e4
 {
Karel Zak 18b0e4
 	[COL_USER]          = { "USER",		N_("user name"), N_("Username"), 0.1, SCOLS_FL_NOEXTREMES },
Karel Zak 18b0e4
 	[COL_UID]           = { "UID",		N_("user ID"), "UID", 1, SCOLS_FL_RIGHT},
Karel Zak 18b0e4
-	[COL_PWDEMPTY]      = { "PWD-EMPTY",	N_("password not required"), N_("Password not required"), 1, SCOLS_FL_RIGHT },
Karel Zak 18b0e4
+	[COL_PWDEMPTY]      = { "PWD-EMPTY",	N_("password not defined"), N_("Password not required (empty)"), 1, SCOLS_FL_RIGHT },
Karel Zak 18b0e4
 	[COL_PWDDENY]       = { "PWD-DENY",	N_("login by password disabled"), N_("Login by password disabled"), 1, SCOLS_FL_RIGHT },
Karel Zak 18b0e4
 	[COL_PWDLOCK]       = { "PWD-LOCK",	N_("password defined, but locked"), N_("Password is locked"), 1, SCOLS_FL_RIGHT },
Karel Zak 18b0e4
 	[COL_PWDMETHOD]     = { "PWD-METHOD",   N_("password encryption method"), N_("Password encryption method"), 0.1 },
Karel Zak 18b0e4
@@ -817,23 +817,42 @@ static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const c
Karel Zak 18b0e4
 			break;
Karel Zak 18b0e4
 		case COL_PWDEMPTY:
Karel Zak 18b0e4
 			if (shadow) {
Karel Zak 18b0e4
-				if (!*shadow->sp_pwdp) /* '\0' */
Karel Zak 18b0e4
+				const char *p = shadow->sp_pwdp;
Karel Zak 18b0e4
+
Karel Zak 18b0e4
+				while (p && (*p == '!' || *p == '*'))
Karel Zak 18b0e4
+					p++;
Karel Zak 18b0e4
+
Karel Zak 18b0e4
+				if (!p || !*p)
Karel Zak 18b0e4
 					user->pwd_empty = STATUS_TRUE;
Karel Zak 18b0e4
 			} else
Karel Zak 18b0e4
 				user->pwd_empty = STATUS_UNKNOWN;
Karel Zak 18b0e4
 			break;
Karel Zak 18b0e4
 		case COL_PWDDENY:
Karel Zak 18b0e4
 			if (shadow) {
Karel Zak 18b0e4
-				if ((*shadow->sp_pwdp == '!' ||
Karel Zak 18b0e4
-				     *shadow->sp_pwdp == '*') &&
Karel Zak 18b0e4
-				    !valid_pwd(shadow->sp_pwdp + 1))
Karel Zak 18b0e4
+				const char *p = shadow->sp_pwdp;
Karel Zak 18b0e4
+
Karel Zak 18b0e4
+				while (p && (*p == '!' || *p == '*'))
Karel Zak 18b0e4
+					p++;
Karel Zak 18b0e4
+
Karel Zak 18b0e4
+				if (p && *p && p != shadow->sp_pwdp && !valid_pwd(p))
Karel Zak 18b0e4
 					user->pwd_deny = STATUS_TRUE;
Karel Zak 18b0e4
 			} else
Karel Zak 18b0e4
 				user->pwd_deny = STATUS_UNKNOWN;
Karel Zak 18b0e4
 			break;
Karel Zak 18b0e4
 		case COL_PWDLOCK:
Karel Zak 18b0e4
 			if (shadow) {
Karel Zak 18b0e4
-				if (*shadow->sp_pwdp == '!' && valid_pwd(shadow->sp_pwdp + 1))
Karel Zak 18b0e4
+				const char *p = shadow->sp_pwdp;
Karel Zak 18b0e4
+				int i = 0;
Karel Zak 18b0e4
+
Karel Zak 18b0e4
+				/* 'passwd --lock' uses two exclamation marks,
Karel Zak 18b0e4
+				 * shadow(5) describes the lock as "field which
Karel Zak 18b0e4
+				 * starts with an exclamation mark". Let's
Karel Zak 18b0e4
+				 * support more '!' ...
Karel Zak 18b0e4
+				 */
Karel Zak 18b0e4
+				while (p && *p == '!')
Karel Zak 18b0e4
+					p++, i++;
Karel Zak 18b0e4
+
Karel Zak 18b0e4
+				if (i != 0 && (!*p || valid_pwd(p)))
Karel Zak 18b0e4
 					user->pwd_lock = STATUS_TRUE;
Karel Zak 18b0e4
 			} else
Karel Zak 18b0e4
 				user->pwd_lock = STATUS_UNKNOWN;
Karel Zak 18b0e4
@@ -842,7 +861,7 @@ static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const c
Karel Zak 18b0e4
 			if (shadow) {
Karel Zak 18b0e4
 				const char *p = shadow->sp_pwdp;
Karel Zak 18b0e4
 
Karel Zak 18b0e4
-				if (*p == '!' || *p == '*')
Karel Zak 18b0e4
+				while (p && (*p == '!' || *p == '*'))
Karel Zak 18b0e4
 					p++;
Karel Zak 18b0e4
 				user->pwd_method = get_pwd_method(p, NULL, NULL);
Karel Zak 18b0e4
 			} else
Karel Zak 18b0e4
-- 
Karel Zak 18b0e4
2.36.1
Karel Zak 18b0e4