void agecheck (/*@null@*/const struct spwd *sp)
{
- long now = time(NULL) / SCALE;
+ long now = time(NULL) / DAY;
long remain;
if (NULL == 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);
*
* 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
{
long now;
- now = time(NULL) / SCALE;
+ now = time(NULL) / DAY;
if (NULL == sp) {
return 0;
if ( (-1 == sp->sp_lstchg)
|| (-1 == sp->sp_max)
- || (sp->sp_max >= ((10000L * DAY) / SCALE))) {
+ || (sp->sp_max >= 10000)) {
return 0;
}
* 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 */
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)"));
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,
* 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);
}
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);
}
(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);
}
* 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);
}
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 */
}
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 */
*/
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;
*/
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) {
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));
}
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 */
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
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;
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 */
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);
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
*
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;
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. */
Prog, optarg);
exit (E_BAD_ARG);
}
- user_newexpire *= DAY / SCALE;
eflg = true;
break;
case 'f':
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 */