passwd/fix-incorrect-S-output.patch
xueyamao d445a991da fix incorrect -S output
There is a password information set in /etc/shadow,but the password field in /etc/passwd is empty.

Signed-off-by: xueyamao <xueyamao@kylinos.cn>
2022-08-19 15:52:42 +08:00

66 lines
2.0 KiB
Diff

From c023fa6c17c083caefe4ef41627556c3232fea08 Mon Sep 17 00:00:00 2001
From: Jiri Kucera <jkucera@redhat.com>
Date: Dec 03 2019 13:41:36 +0000
https://pagure.io/passwd/c/ff60631b73e48ab28fc984cd8f8206d18e369b82.patch
Subject: [PATCH] fix incorrect -S output
Fix incorrect -S output when password field in /etc/passwd is empty
but the password information in /etc/shadow is set.
---
libuser.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/libuser.c b/libuser.c
index f5bedc1..4ccd74c 100644
--- a/libuser.c
+++ b/libuser.c
@@ -245,6 +245,7 @@ pwdb_display_status(const char *username)
struct lu_ent *ent;
struct lu_error *error = NULL;
char *current;
+ char *current_user;
char *realname;
const char *msg;
int shadow = 1;
@@ -268,9 +269,10 @@ pwdb_display_status(const char *username)
goto bail;
}
current = lu_ent_get_first_value_strdup(ent, LU_SHADOWPASSWORD);
+ current_user = lu_ent_get_first_value_strdup(ent, LU_USERPASSWORD);
if (current == NULL) {
shadow = 0;
- current = lu_ent_get_first_value_strdup(ent, LU_USERPASSWORD);
+ current = current_user;
} else {
sp_lstchg = (time_t) ent_value_int64(ent, LU_SHADOWLASTCHANGE);
sp_min = ent_value_int64(ent, LU_SHADOWMIN);
@@ -313,6 +315,13 @@ pwdb_display_status(const char *username)
msg = _("Password set, DES crypt.");
}
if (shadow) {
+ if (status[0] != 'N' && current_user && strlen(current_user) == 0) {
+ fprintf(stderr, "%s: %s\n", progname,
+ _("There is a password information set in /etc/shadow,"
+ " but the password field in /etc/passwd is empty."));
+ msg = _("Empty password.");
+ status = "NP";
+ }
sp_lstchg = sp_lstchg * 24L * 3600L;
localtime_r(&sp_lstchg, &tm);
strftime(date, sizeof(date), "%Y-%m-%d", &tm);
@@ -322,6 +331,9 @@ pwdb_display_status(const char *username)
printf("%s %s (%s)\n", realname, status, msg);
}
g_free(current);
+ if (shadow && current_user) {
+ g_free(current_user);
+ }
} else {
printf(_("No password set.\n"));
}
--
2.33.0