From fa96d1bb780c8a55b8fe2acc3d793550b0b5ab26 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Sun, 18 Sep 2011 20:24:36 +0000 Subject: [PATCH] * src/chage.c: EPOCH is not needed, it's converted to -1 by strtoday(). But we need to support "-1" specifically. * src/chage.c: Fix usage: LOGIN is mandatory. * src/chage.c: Display disabled expiry or last change as "-1" instead of 1969-12-31. 1969-12-31 is still supported as input from the user. * src/chage.c: Exit cleanly with fail_exit() (lock files were not removed). --- ChangeLog | 11 +++++++++++ src/chage.c | 28 +++++++++++++++++----------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 536b686d..0719280a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-09-18 Nicolas François + + * src/chage.c: EPOCH is not needed, it's converted to -1 by + strtoday(). But we need to support "-1" specifically. + * src/chage.c: Fix usage: LOGIN is mandatory. + * src/chage.c: Display disabled expiry or last change as "-1" + instead of 1969-12-31. 1969-12-31 is still supported as input from + the user. + * src/chage.c: Exit cleanly with fail_exit() (lock files were not + removed). + 2011-09-18 Nicolas François * src/useradd.c: Remove def_file. It was always set to diff --git a/src/chage.c b/src/chage.c index 110445a2..c5e8b469 100644 --- a/src/chage.c +++ b/src/chage.c @@ -2,7 +2,7 @@ * Copyright (c) 1989 - 1994, Julianne Frances Haugh * Copyright (c) 1996 - 2000, Marek Michałkiewicz * Copyright (c) 2000 - 2006, Tomasz Kłoczko - * Copyright (c) 2007 - 2009, Nicolas François + * Copyright (c) 2007 - 2011, Nicolas François * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -90,8 +90,6 @@ static long warndays; static long inactdays; static long expdate; -#define EPOCH "1969-12-31" - /* local function prototypes */ static void usage (int status); static void date_to_str (char *buf, size_t maxsize, time_t date); @@ -142,7 +140,7 @@ static void fail_exit (int code) */ static void usage (int status) { - fputs (_("Usage: chage [options] [LOGIN]\n" + fputs (_("Usage: chage [options] LOGIN\n" "\n" "Options:\n" " -d, --lastday LAST_DAY set date of last password change to LAST_DAY\n" @@ -203,15 +201,19 @@ static int new_fields (void) return 0; } - date_to_str (buf, sizeof buf, lstchgdate * SCALE); + if (-1 == lstchgdate) { + strcpy (buf, "-1"); + } else { + date_to_str (buf, sizeof buf, lstchgdate * SCALE); + } change_field (buf, sizeof buf, _("Last Password Change (YYYY-MM-DD)")); - if (strcmp (buf, EPOCH) == 0) { + if (strcmp (buf, "-1") == 0) { lstchgdate = -1; } else { lstchgdate = strtoday (buf); - if (lstchgdate < -1) { + if (lstchgdate <= -1) { return 0; } } @@ -230,16 +232,20 @@ static int new_fields (void) return 0; } - date_to_str (buf, sizeof buf, expdate * SCALE); + if (-1 == expdate) { + strcpy (buf, "-1"); + } else { + date_to_str (buf, sizeof buf, expdate * SCALE); + } change_field (buf, sizeof buf, _("Account Expiration Date (YYYY-MM-DD)")); - if (strcmp (buf, EPOCH) == 0) { + if (strcmp (buf, "-1") == 0) { expdate = -1; } else { expdate = strtoday (buf); - if (expdate < -1) { + if (expdate <= -1) { return 0; } } @@ -833,7 +839,7 @@ int main (int argc, char **argv) fprintf (stderr, _("%s: user '%s' does not exist in %s\n"), Prog, argv[optind], pw_dbname ()); closelog (); - exit (E_NOPERM); + fail_exit (E_NOPERM); } STRFCPY (user_name, pw->pw_name);