#include <config.h>
#include <sys/types.h>
+#include "prototypes.h"
+#include "defines.h"
#include <pwd.h>
#include <time.h>
-#include "adds.h"
-#include "defines.h"
-#include "prototypes.h"
-
#ident "$Id$"
*/
int isexpired (const struct passwd *pw, /*@null@*/const struct spwd *sp)
{
- long now;
+ long now;
now = time(NULL) / DAY;
if ( (sp->sp_lstchg > 0)
&& (sp->sp_max >= 0)
&& (sp->sp_inact >= 0)
- && (now >= addsl(sp->sp_lstchg, sp->sp_max, sp->sp_inact)))
- {
+ && (now >= (sp->sp_lstchg + sp->sp_max + sp->sp_inact))) {
return 2;
}
* the password has expired.
*/
- if (now >= addsl(sp->sp_lstchg, sp->sp_max))
+ if (now >= (sp->sp_lstchg + sp->sp_max)) {
return 1;
-
+ }
return 0;
}
/* local function prototypes */
NORETURN static void usage (int status);
static int new_fields (void);
-static void print_day_as_date (long day);
+static void print_date (time_t date);
static void list_fields (void);
static void process_flags (int argc, char **argv);
static void check_flags (int argc, int opt_index);
return 1;
}
-
-static void
-print_day_as_date(long day)
+static void print_date (time_t date)
{
- char buf[80];
- time_t date;
- struct tm *tp;
-
- if (day < 0) {
- puts(_("never"));
- return;
- }
- if (__builtin_mul_overflow(day, DAY, &date)) {
- puts(_("future"));
- return;
- }
+ struct tm *tp;
+ char buf[80];
tp = gmtime (&date);
if (NULL == tp) {
}
}
-
/*
* list_fields - display the current values of the expiration fields
*
*/
static void list_fields (void)
{
+ long changed = 0;
+ long expires;
+
/*
* The "last change" date is either "never" or the date the password
* 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) {
+ if (lstchgdate < 0 || lstchgdate > LONG_MAX / DAY) {
+ (void) puts (_("never"));
+ } else if (lstchgdate == 0) {
(void) puts (_("password must be changed"));
} else {
- print_day_as_date(lstchgdate);
+ changed = lstchgdate * DAY;
+ print_date (changed);
}
/*
} else if ( (lstchgdate < 0)
|| (maxdays >= 10000)
|| (maxdays < 0)
- || (LONG_MAX - lstchgdate < maxdays))
- {
+ || ((LONG_MAX - changed) / DAY < maxdays)) {
(void) puts (_("never"));
} else {
- print_day_as_date(lstchgdate + maxdays);
+ expires = changed + maxdays * DAY;
+ print_date (expires);
}
/*
|| (inactdays < 0)
|| (maxdays >= 10000)
|| (maxdays < 0)
- || (LONG_MAX - inactdays < maxdays)
- || (LONG_MAX - lstchgdate < maxdays + inactdays))
- {
+ || (maxdays > LONG_MAX - inactdays)
+ || ((LONG_MAX - changed) / DAY < maxdays + inactdays)) {
(void) puts (_("never"));
} else {
- print_day_as_date(lstchgdate + maxdays + inactdays);
+ expires = changed + (maxdays + inactdays) * DAY;
+ print_date (expires);
}
/*
* password expiring or not.
*/
(void) fputs (_("Account expires\t\t\t\t\t\t: "), stdout);
- print_day_as_date(expdate);
+ if (expdate < 0 || LONG_MAX / DAY < expdate) {
+ (void) puts (_("never"));
+ } else {
+ expires = expdate * DAY;
+ print_date (expires);
+ }
/*
* Start with the easy numbers - the number of days before the
char orig[PASS_MAX + 1]; /* Original password */
char pass[PASS_MAX + 1]; /* New password */
int i; /* Counter for retries */
- int ret;
bool warned;
int pass_max_len = -1;
const char *method;
if (warned && (strcmp (pass, cp) != 0)) {
warned = false;
}
- ret = STRTCPY (pass, cp);
+ STRFCPY (pass, cp);
erase_pass (cp);
- if (ret == -1) {
- (void) fputs (_("Password is too long.\n"), stderr);
- memzero (orig, sizeof orig);
- memzero (pass, sizeof pass);
- return -1;
- }
if (!amroot && (!obscure (orig, pass, pw) || reuse (pass, pw))) {
(void) puts (_("Try again."));