]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Remove SCALE definition
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 13 Dec 2023 20:25:51 +0000 (20:25 +0000)
committerSerge Hallyn <serge@hallyn.com>
Fri, 5 Jan 2024 21:41:12 +0000 (15:41 -0600)
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>
12 files changed:
lib/age.c
lib/defines.h
lib/isexpired.c
lib/pwd2spwd.c
src/chage.c
src/chpasswd.c
src/newusers.c
src/passwd.c
src/pwck.c
src/pwconv.c
src/useradd.c
src/usermod.c

index 931ecdb7799db01994fb288d52dd9d5b75baae45..d9ef88c4c8a026f88611812ec4ab0f2aaf657513 100644 (file)
--- 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);
index 049c0506ced134727cf9075c025661a025e4093a..361f89c651a69c292008d1fc83a2f2015aae4cfd 100644 (file)
  *
  * DAY - seconds / day
  * WEEK - seconds / week
- * SCALE - seconds / aging unit
  */
 
 /* Solaris defines this in shadow.h */
 
 #define WEEK (7*DAY)
 
-#define SCALE DAY
-
 #ifndef PASSWD_FILE
 #define PASSWD_FILE "/etc/passwd"
 #endif
index 738b8ef5af1a639ec8049127ed2d063eb0bdb924..45c7601ec4bef15ef750d454bba281bd2b78b430 100644 (file)
@@ -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;
        }
 
index 5f87cc53d57de20132f96e904e41758770aacbfe..eea951982aa1af78e00c840439b6ba87828ccf6f 100644 (file)
@@ -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 */
index 4e7ae2869698689d373b922d95d183e0af2aae69..4277e9d819710ee1d23cc167bcf72fb0e8047165 100644 (file)
@@ -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);
        }
 
index 8bc920e44b8c6c6f754feda9f01f98fc0cd45a69..c2546ec50ca3fa29fc87442de8735a368741bfb0 100644 (file)
@@ -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 */
index 86167b673e8cf343297abd9d06b51cded5ee36da..bb34e9701747f468010efc2743f38a934ece4e83 100644 (file)
@@ -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;
index aef5b0512c14937a942a735f35eb9e5fa8916625..ef7bee85fff608a02a0136da9a51c5efa07dcbec 100644 (file)
@@ -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 */
index 982eea63b211f12f0e16d50fc577a788f61b39f1..535ba4e598a81a4ab77a9d752299b92970a2e4a8 100644 (file)
@@ -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;
index 4f388d256a9cb052aacbfdba15ef37b6da027e0d..3670d95e52d0f137d9460acd682cedfc72b8d27d 100644 (file)
@@ -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 */
index dcf3fec38238efdcc098fee2c04998805aa222e1..31d89686e0eb22ae507b584af4a026c07fb39ede 100644 (file)
@@ -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;
index 285c2636db3b954ea0f5378c6f9f775defc4d69c..6ec67da342c02dd5a558955d428e95eee9c16fd7 100644 (file)
@@ -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 */