From: Tobias Stoeckmann Date: Wed, 13 Dec 2023 20:25:51 +0000 (+0000) Subject: lib/, src/: Remove SCALE definition X-Git-Tag: 4.15.0-rc1~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ecc3508877d254bbdc4579cf8f08c07697a578c9;p=thirdparty%2Fshadow.git lib/, src/: Remove SCALE definition SCALE is always DAY (and has to be always DAY), so replace it with DAY in source code and remove unneeded calculations. Signed-off-by: Tobias Stoeckmann Link: Signed-off-by: Alejandro Colomar --- diff --git a/lib/age.c b/lib/age.c index 931ecdb77..d9ef88c4c 100644 --- a/lib/age.c +++ b/lib/age.c @@ -139,7 +139,7 @@ int expire (const struct passwd *pw, /*@null@*/const struct spwd *sp) void agecheck (/*@null@*/const struct spwd *sp) { - long now = time(NULL) / SCALE; + long now = time(NULL) / DAY; long remain; if (NULL == sp) { @@ -164,7 +164,6 @@ void agecheck (/*@null@*/const struct spwd *sp) remain = sp->sp_lstchg + sp->sp_max - now; if (remain <= sp->sp_warn) { - remain /= DAY / SCALE; if (remain > 1) { (void) printf (_("Your password will expire in %ld days.\n"), remain); diff --git a/lib/defines.h b/lib/defines.h index 049c0506c..361f89c65 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -139,7 +139,6 @@ * * DAY - seconds / day * WEEK - seconds / week - * SCALE - seconds / aging unit */ /* Solaris defines this in shadow.h */ @@ -149,8 +148,6 @@ #define WEEK (7*DAY) -#define SCALE DAY - #ifndef PASSWD_FILE #define PASSWD_FILE "/etc/passwd" #endif diff --git a/lib/isexpired.c b/lib/isexpired.c index 738b8ef5a..45c7601ec 100644 --- a/lib/isexpired.c +++ b/lib/isexpired.c @@ -40,7 +40,7 @@ int isexpired (const struct passwd *pw, /*@null@*/const struct spwd *sp) { long now; - now = time(NULL) / SCALE; + now = time(NULL) / DAY; if (NULL == sp) { return 0; @@ -84,7 +84,7 @@ int isexpired (const struct passwd *pw, /*@null@*/const struct spwd *sp) if ( (-1 == sp->sp_lstchg) || (-1 == sp->sp_max) - || (sp->sp_max >= ((10000L * DAY) / SCALE))) { + || (sp->sp_max >= 10000)) { return 0; } diff --git a/lib/pwd2spwd.c b/lib/pwd2spwd.c index 5f87cc53d..eea951982 100644 --- a/lib/pwd2spwd.c +++ b/lib/pwd2spwd.c @@ -39,8 +39,8 @@ struct spwd *pwd_to_spwd (const struct passwd *pw) * Defaults used if there is no pw_age information. */ sp.sp_min = 0; - sp.sp_max = (10000L * DAY) / SCALE; - sp.sp_lstchg = gettime () / SCALE; + sp.sp_max = 10000; + sp.sp_lstchg = gettime () / DAY; if (0 == sp.sp_lstchg) { /* Better disable aging than requiring a password * change */ diff --git a/src/chage.c b/src/chage.c index 4e7ae2869..4277e9d81 100644 --- a/src/chage.c +++ b/src/chage.c @@ -179,10 +179,10 @@ static int new_fields (void) return 0; } - if (-1 == lstchgdate || lstchgdate > LONG_MAX / SCALE) { + if (-1 == lstchgdate || lstchgdate > LONG_MAX / DAY) { strcpy (buf, "-1"); } else { - date_to_str (sizeof(buf), buf, lstchgdate * SCALE); + date_to_str (sizeof(buf), buf, lstchgdate * DAY); } change_field (buf, sizeof buf, _("Last Password Change (YYYY-MM-DD)")); @@ -210,10 +210,10 @@ static int new_fields (void) return 0; } - if (-1 == expdate || LONG_MAX / SCALE < expdate) { + if (-1 == expdate || LONG_MAX / DAY < expdate) { strcpy (buf, "-1"); } else { - date_to_str (sizeof(buf), buf, expdate * SCALE); + date_to_str (sizeof(buf), buf, expdate * DAY); } change_field (buf, sizeof buf, @@ -262,12 +262,12 @@ static void list_fields (void) * was last modified. The date is the number of days since 1/1/1970. */ (void) fputs (_("Last password change\t\t\t\t\t: "), stdout); - if (lstchgdate < 0 || lstchgdate > LONG_MAX / SCALE) { + if (lstchgdate < 0 || lstchgdate > LONG_MAX / DAY) { (void) puts (_("never")); } else if (lstchgdate == 0) { (void) puts (_("password must be changed")); } else { - changed = lstchgdate * SCALE; + changed = lstchgdate * DAY; print_date (changed); } @@ -279,12 +279,12 @@ static void list_fields (void) if (lstchgdate == 0) { (void) puts (_("password must be changed")); } else if ( (lstchgdate < 0) - || (maxdays >= (10000 * (DAY / SCALE))) + || (maxdays >= 10000) || (maxdays < 0) - || ((LONG_MAX - changed) / SCALE < maxdays)) { + || ((LONG_MAX - changed) / DAY < maxdays)) { (void) puts (_("never")); } else { - expires = changed + maxdays * SCALE; + expires = changed + maxdays * DAY; print_date (expires); } @@ -299,13 +299,13 @@ static void list_fields (void) (void) puts (_("password must be changed")); } else if ( (lstchgdate < 0) || (inactdays < 0) - || (maxdays >= (10000 * (DAY / SCALE))) + || (maxdays >= 10000) || (maxdays < 0) || (maxdays > LONG_MAX - inactdays) - || ((LONG_MAX - changed) / SCALE < maxdays + inactdays)) { + || ((LONG_MAX - changed) / DAY < maxdays + inactdays)) { (void) puts (_("never")); } else { - expires = changed + (maxdays + inactdays) * SCALE; + expires = changed + (maxdays + inactdays) * DAY; print_date (expires); } @@ -314,10 +314,10 @@ static void list_fields (void) * password expiring or not. */ (void) fputs (_("Account expires\t\t\t\t\t\t: "), stdout); - if (expdate < 0 || LONG_MAX / SCALE < expdate) { + if (expdate < 0 || LONG_MAX / DAY < expdate) { (void) puts (_("never")); } else { - expires = expdate * SCALE; + expires = expdate * DAY; print_date (expires); } diff --git a/src/chpasswd.c b/src/chpasswd.c index 8bc920e44..c2546ec50 100644 --- a/src/chpasswd.c +++ b/src/chpasswd.c @@ -621,7 +621,7 @@ int main (int argc, char **argv) if (NULL != sp) { newsp = *sp; newsp.sp_pwdp = cp; - newsp.sp_lstchg = gettime () / SCALE; + newsp.sp_lstchg = gettime () / DAY; if (0 == newsp.sp_lstchg) { /* Better disable aging than requiring a * password change */ diff --git a/src/newusers.c b/src/newusers.c index 86167b673..bb34e9701 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -529,7 +529,7 @@ static int add_passwd (struct passwd *pwd, const char *password) } spent.sp_pwdp = cp; } - spent.sp_lstchg = gettime () / SCALE; + spent.sp_lstchg = gettime () / DAY; if (0 == spent.sp_lstchg) { /* Better disable aging than requiring a password * change */ @@ -586,7 +586,7 @@ static int add_passwd (struct passwd *pwd, const char *password) */ spent.sp_pwdp = "!"; #endif - spent.sp_lstchg = gettime () / SCALE; + spent.sp_lstchg = gettime () / DAY; if (0 == spent.sp_lstchg) { /* Better disable aging than requiring a password change */ spent.sp_lstchg = -1; diff --git a/src/passwd.c b/src/passwd.c index aef5b0512..ef7bee85f 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -388,9 +388,9 @@ static void check_password (const struct passwd *pw, const struct spwd *sp) */ if (sp->sp_lstchg > 0) { time_t ok; - ok = (time_t) sp->sp_lstchg * SCALE; + ok = (time_t) sp->sp_lstchg * DAY; if (sp->sp_min > 0) { - ok += (time_t) sp->sp_min * SCALE; + ok += (time_t) sp->sp_min * DAY; } if (now < ok) { @@ -425,15 +425,15 @@ static void print_status (const struct passwd *pw) sp = prefix_getspnam (pw->pw_name); /* local, no need for xprefix_getspnam */ if (NULL != sp) { - date_to_str (sizeof(date), date, sp->sp_lstchg * SCALE), - (void) printf ("%s %s %s %lld %lld %lld %lld\n", + date_to_str (sizeof(date), date, sp->sp_lstchg * DAY), + (void) printf ("%s %s %s %ld %ld %ld %ld\n", pw->pw_name, pw_status (sp->sp_pwdp), date, - ((long long)sp->sp_min * SCALE) / DAY, - ((long long)sp->sp_max * SCALE) / DAY, - ((long long)sp->sp_warn * SCALE) / DAY, - ((long long)sp->sp_inact * SCALE) / DAY); + sp->sp_min, + sp->sp_max, + sp->sp_warn, + sp->sp_inact); } else if (NULL != pw->pw_passwd) { (void) printf ("%s %s\n", pw->pw_name, pw_status (pw->pw_passwd)); @@ -611,21 +611,21 @@ static void update_shadow (void) } nsp->sp_pwdp = update_crypt_pw (nsp->sp_pwdp); if (xflg) { - nsp->sp_max = (age_max * DAY) / SCALE; + nsp->sp_max = age_max; } if (nflg) { - nsp->sp_min = (age_min * DAY) / SCALE; + nsp->sp_min = age_min; } if (wflg) { - nsp->sp_warn = (warn * DAY) / SCALE; + nsp->sp_warn = warn; } if (iflg) { - nsp->sp_inact = (inact * DAY) / SCALE; + nsp->sp_inact = inact; } if (!use_pam) { if (do_update_age) { - nsp->sp_lstchg = gettime () / SCALE; + nsp->sp_lstchg = gettime () / DAY; if (0 == nsp->sp_lstchg) { /* Better disable aging than requiring a password * change */ diff --git a/src/pwck.c b/src/pwck.c index 982eea63b..535ba4e59 100644 --- a/src/pwck.c +++ b/src/pwck.c @@ -609,7 +609,7 @@ static void check_pw_file (int *errors, bool *changed) sp.sp_inact = -1; sp.sp_expire = -1; sp.sp_flag = SHADOW_SP_FLAG_UNSET; - sp.sp_lstchg = gettime () / SCALE; + sp.sp_lstchg = gettime () / DAY; if (0 == sp.sp_lstchg) { /* Better disable aging than * requiring a password change @@ -816,7 +816,7 @@ static void check_spw_file (int *errors, bool *changed) if (!quiet) { time_t t = time (NULL); if ( (t != 0) - && (spw->sp_lstchg > (long) t / SCALE)) { + && (spw->sp_lstchg > (long) t / DAY)) { printf (_("user %s: last password change in the future\n"), spw->sp_namp); *errors += 1; diff --git a/src/pwconv.c b/src/pwconv.c index 4f388d256..3670d95e5 100644 --- a/src/pwconv.c +++ b/src/pwconv.c @@ -249,7 +249,7 @@ int main (int argc, char **argv) spent.sp_flag = SHADOW_SP_FLAG_UNSET; } spent.sp_pwdp = pw->pw_passwd; - spent.sp_lstchg = gettime () / SCALE; + spent.sp_lstchg = gettime () / DAY; if (0 == spent.sp_lstchg) { /* Better disable aging than requiring a password * change */ diff --git a/src/useradd.c b/src/useradd.c index dcf3fec38..31d89686e 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -217,7 +217,6 @@ static struct group * get_local_group (char * grp_name); NORETURN static void usage (int status); static void new_pwent (struct passwd *); -static long scale_age (long); static void new_spent (struct spwd *); static void grp_update (void); @@ -982,15 +981,6 @@ static void new_pwent (struct passwd *pwent) pwent->pw_shell = (char *) user_shell; } -static long scale_age (long x) -{ - if (x <= 0) { - return x; - } - - return x * (DAY / SCALE); -} - /* * new_spent - initialize the values in a shadow password file entry * @@ -1002,17 +992,17 @@ static void new_spent (struct spwd *spent) memzero (spent, sizeof *spent); spent->sp_namp = (char *) user_name; spent->sp_pwdp = (char *) user_pass; - spent->sp_lstchg = gettime () / SCALE; + spent->sp_lstchg = gettime () / DAY; if (0 == spent->sp_lstchg) { /* Better disable aging than requiring a password change */ spent->sp_lstchg = -1; } if (!rflg) { - spent->sp_min = scale_age (getdef_num ("PASS_MIN_DAYS", -1)); - spent->sp_max = scale_age (getdef_num ("PASS_MAX_DAYS", -1)); - spent->sp_warn = scale_age (getdef_num ("PASS_WARN_AGE", -1)); - spent->sp_inact = scale_age (def_inactive); - spent->sp_expire = scale_age (user_expire); + spent->sp_min = getdef_num ("PASS_MIN_DAYS", -1); + spent->sp_max = getdef_num ("PASS_MAX_DAYS", -1); + spent->sp_warn = getdef_num ("PASS_WARN_AGE", -1); + spent->sp_inact = def_inactive; + spent->sp_expire = user_expire; } else { spent->sp_min = -1; spent->sp_max = -1; diff --git a/src/usermod.c b/src/usermod.c index 285c2636d..6ec67da34 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -617,7 +617,7 @@ static void new_spent (struct spwd *spent) spent->sp_pwdp = new_pw_passwd (spent->sp_pwdp); if (pflg) { - spent->sp_lstchg = gettime () / SCALE; + spent->sp_lstchg = gettime () / DAY; if (0 == spent->sp_lstchg) { /* Better disable aging than requiring a password * change. */ @@ -1064,7 +1064,6 @@ static void process_flags (int argc, char **argv) Prog, optarg); exit (E_BAD_ARG); } - user_newexpire *= DAY / SCALE; eflg = true; break; case 'f': @@ -1742,7 +1741,7 @@ static void usr_update (void) spent.sp_pwdp = xstrdup (pwent.pw_passwd); pwent.pw_passwd = xstrdup (SHADOW_PASSWD_STRING); - spent.sp_lstchg = gettime () / SCALE; + spent.sp_lstchg = gettime () / DAY; if (0 == spent.sp_lstchg) { /* Better disable aging than * requiring a password change */