62 lines
1.8 KiB
Diff
62 lines
1.8 KiB
Diff
From 3b5ba41d3e9dfc3bf058f0f31529c08201265241 Mon Sep 17 00:00:00 2001
|
|
From: Tobias Stoeckmann <tobias@stoeckmann.org>
|
|
Date: Thu, 14 Dec 2023 11:54:00 +0100
|
|
Subject: [PATCH] src/passwd.c: Switch to day precision
|
|
|
|
The size of time_t varies across systems, but since data type long is
|
|
more than enough to calculate with days (precision of shadow file),
|
|
use it instead.
|
|
|
|
Just in case a shadow file contains huge values, check for a possible
|
|
signed integer overflow.
|
|
|
|
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
|
|
Link: <https://github.com/shadow-maint/shadow/pull/876>
|
|
Signed-off-by: Alejandro Colomar <alx@kernel.org>
|
|
|
|
Reference: https://github.com/shadow-maint/shadow/commit/3b5ba41d3e9dfc3bf058f0f31529c08201265241
|
|
Conflict: src/chpasswd.c
|
|
---
|
|
src/passwd.c | 10 ++++------
|
|
1 file changed, 4 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/src/passwd.c b/src/passwd.c
|
|
index 336bbc9..d79767a 100644
|
|
--- a/src/passwd.c
|
|
+++ b/src/passwd.c
|
|
@@ -390,7 +390,6 @@ static int new_password (const struct passwd *pw)
|
|
*/
|
|
static void check_password (const struct passwd *pw, const struct spwd *sp)
|
|
{
|
|
- time_t now;
|
|
int exp_status;
|
|
|
|
exp_status = isexpired (pw, sp);
|
|
@@ -410,8 +409,6 @@ static void check_password (const struct passwd *pw, const struct spwd *sp)
|
|
return;
|
|
}
|
|
|
|
- (void) time (&now);
|
|
-
|
|
/*
|
|
* Expired accounts cannot be changed ever. Passwords which are
|
|
* locked may not be changed. Passwords where min > max may not be
|
|
@@ -434,10 +431,11 @@ static void check_password (const struct passwd *pw, const struct spwd *sp)
|
|
* Passwords may only be changed after sp_min time is up.
|
|
*/
|
|
if (sp->sp_lstchg > 0) {
|
|
- time_t ok;
|
|
- ok = (time_t) sp->sp_lstchg * SCALE;
|
|
+ long now, ok;
|
|
+ now = time(NULL) / DAY;
|
|
+ ok = sp->sp_lstchg;
|
|
if (sp->sp_min > 0) {
|
|
- ok += (time_t) sp->sp_min * SCALE;
|
|
+ ok += sp->sp_min;
|
|
}
|
|
|
|
if (now < ok) {
|
|
--
|
|
2.33.0
|
|
|