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 <tobias@stoeckmann.org> Link: <https://github.com/shadow-maint/shadow/pull/876> Signed-off-by: Alejandro Colomar <alx@kernel.org> Cherry-picked-from:ecc3508877("lib/, src/: Remove SCALE definition") Cc: "Serge E. Hallyn" <serge@hallyn.com> Link: <https://github.com/shadow-maint/shadow/pull/888> Link: <https://github.com/shadow-maint/shadow/pull/876> [alx: This is a pre-requisite for674409e226("lib/: Saturate addition to avoid overflow")] Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Alejandro Colomar
parent
25fd8eb404
commit
55f9635ecf
+14
-14
@@ -175,10 +175,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)"));
|
||||
@@ -206,10 +206,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,
|
||||
@@ -258,12 +258,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);
|
||||
}
|
||||
|
||||
@@ -275,12 +275,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);
|
||||
}
|
||||
|
||||
@@ -295,13 +295,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);
|
||||
}
|
||||
|
||||
@@ -310,10 +310,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);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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 */
|
||||
|
||||
+2
-2
@@ -527,7 +527,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 */
|
||||
@@ -584,7 +584,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;
|
||||
|
||||
+13
-13
@@ -414,9 +414,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) {
|
||||
@@ -451,15 +451,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));
|
||||
@@ -637,21 +637,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 */
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+1
-1
@@ -247,7 +247,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 */
|
||||
|
||||
+6
-16
@@ -214,7 +214,6 @@ static struct group * get_local_group (char * grp_name);
|
||||
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);
|
||||
|
||||
@@ -1008,15 +1007,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
|
||||
*
|
||||
@@ -1028,17 +1018,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;
|
||||
|
||||
+2
-3
@@ -613,7 +613,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. */
|
||||
@@ -1059,7 +1059,6 @@ static void process_flags (int argc, char **argv)
|
||||
Prog, optarg);
|
||||
exit (E_BAD_ARG);
|
||||
}
|
||||
user_newexpire *= DAY / SCALE;
|
||||
eflg = true;
|
||||
break;
|
||||
case 'f':
|
||||
@@ -1745,7 +1744,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 */
|
||||
|
||||
Reference in New Issue
Block a user