[Pkg-shadow-commits] r3151 - in upstream/trunk: . libmisc src
Nicolas FRANÇOIS
nekral-guest at alioth.debian.org
Thu Mar 18 11:53:49 UTC 2010
Author: nekral-guest
Date: 2010-03-18 11:53:49 +0000 (Thu, 18 Mar 2010)
New Revision: 3151
Modified:
upstream/trunk/ChangeLog
upstream/trunk/libmisc/strtoday.c
upstream/trunk/src/chage.c
upstream/trunk/src/useradd.c
upstream/trunk/src/usermod.c
Log:
* libmisc/strtoday.c: Add support for numerical dates, assuming
they are already specified in number of days since Epoch. Return
-2 in case of errors to support the specification of -1.
* src/usermod.c, src/useradd.c: Adapt to the new error value of
strtoday().
* src/chage.c: Remove isnum(). Adapt to the new error value of
strtoday(). Support for numerical dates is moved to strtoday().
Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog 2010-03-18 10:54:32 UTC (rev 3150)
+++ upstream/trunk/ChangeLog 2010-03-18 11:53:49 UTC (rev 3151)
@@ -1,5 +1,15 @@
2010-03-18 Nicolas François <nicolas.francois at centraliens.net>
+ * libmisc/strtoday.c: Add support for numerical dates, assuming
+ they are already specified in number of days since Epoch. Return
+ -2 in case of errors to support the specification of -1.
+ * src/usermod.c, src/useradd.c: Adapt to the new error value of
+ strtoday().
+ * src/chage.c: Remove isnum(). Adapt to the new error value of
+ strtoday(). Support for numerical dates is moved to strtoday().
+
+2010-03-18 Nicolas François <nicolas.francois at centraliens.net>
+
* man/po/fr.po: Harmonize name of parameters.
2010-03-18 Nicolas François <nicolas.francois at centraliens.net>
Modified: upstream/trunk/libmisc/strtoday.c
===================================================================
--- upstream/trunk/libmisc/strtoday.c 2010-03-18 10:54:32 UTC (rev 3150)
+++ upstream/trunk/libmisc/strtoday.c 2010-03-18 11:53:49 UTC (rev 3151)
@@ -36,6 +36,8 @@
#include <config.h>
+#include <ctype.h>
+
#ident "$Id$"
#include "defines.h"
@@ -44,6 +46,7 @@
#ifndef USE_GETDATE
#define USE_GETDATE 1
#endif
+
#if USE_GETDATE
#include "getdate.h"
/*
@@ -63,6 +66,8 @@
long strtoday (const char *str)
{
time_t t;
+ bool isnum = true;
+ const char *s = str;
/*
* get_date() interprets an empty string as the current date,
@@ -70,12 +75,35 @@
* (useradd sets sp_expire = current date for new lusers)
*/
if ((NULL == str) || ('\0' == *str)) {
- return -1;
+ return -2;
}
- t = get_date (str, (time_t *) 0);
+ /* If a numerical value is provided, this is already a number of
+ * days since EPOCH.
+ */
+ if ('-' == *s) {
+ s++;
+ }
+ while (' ' == *s) {
+ s++;
+ }
+ while (isnum && ('\0' != *s)) {
+ if (!isdigit (*s)) {
+ isnum = false;
+ }
+ s++;
+ }
+ if (isnum) {
+ long retdate;
+ if (getlong (str, &retdate) == 0) {
+ return -2;
+ }
+ return retdate;
+ }
+
+ t = get_date (str, NULL);
if ((time_t) - 1 == t) {
- return -1;
+ return -2;
}
/* convert seconds to days since 1970-01-01 */
return (long) (t + DAY / 2) / DAY;
Modified: upstream/trunk/src/chage.c
===================================================================
--- upstream/trunk/src/chage.c 2010-03-18 10:54:32 UTC (rev 3150)
+++ upstream/trunk/src/chage.c 2010-03-18 11:53:49 UTC (rev 3151)
@@ -93,7 +93,6 @@
#define EPOCH "1969-12-31"
/* local function prototypes */
-static bool isnum (const char *s);
static void usage (int status);
static void date_to_str (char *buf, size_t maxsize, time_t date);
static int new_fields (void);
@@ -139,20 +138,6 @@
}
/*
- * isnum - determine whether or not a string is a number
- */
-static bool isnum (const char *s)
-{
- while ('\0' != *s) {
- if (!isdigit (*s)) {
- return false;
- }
- s++;
- }
- return true;
-}
-
-/*
* usage - print command line syntax and exit
*/
static void usage (int status)
@@ -226,7 +211,7 @@
lstchgdate = -1;
} else {
lstchgdate = strtoday (buf);
- if (lstchgdate == -1) {
+ if (lstchgdate < -1) {
return 0;
}
}
@@ -254,7 +239,7 @@
expdate = -1;
} else {
expdate = strtoday (buf);
- if (expdate == -1) {
+ if (expdate < -1) {
return 0;
}
}
@@ -409,10 +394,8 @@
switch (c) {
case 'd':
dflg = true;
- if (!isnum (optarg)) {
- lstchgdate = strtoday (optarg);
- } else if ( (getlong (optarg, &lstchgdate) == 0)
- || (lstchgdate < -1)) {
+ lstchgdate = strtoday (optarg);
+ if (lstchgdate < -1) {
fprintf (stderr,
_("%s: invalid date '%s'\n"),
Prog, optarg);
@@ -421,10 +404,8 @@
break;
case 'E':
Eflg = true;
- if (!isnum (optarg)) {
- expdate = strtoday (optarg);
- } else if ( (getlong (optarg, &expdate) == 0)
- || (expdate < -1)) {
+ expdate = strtoday (optarg);
+ if (expdate < -1) {
fprintf (stderr,
_("%s: invalid date '%s'\n"),
Prog, optarg);
Modified: upstream/trunk/src/useradd.c
===================================================================
--- upstream/trunk/src/useradd.c 2010-03-18 10:54:32 UTC (rev 3150)
+++ upstream/trunk/src/useradd.c 2010-03-18 11:53:49 UTC (rev 3151)
@@ -1041,7 +1041,7 @@
case 'e':
if ('\0' != *optarg) {
user_expire = strtoday (optarg);
- if (user_expire == -1) {
+ if (user_expire < -1) {
fprintf (stderr,
_("%s: invalid date '%s'\n"),
Prog, optarg);
Modified: upstream/trunk/src/usermod.c
===================================================================
--- upstream/trunk/src/usermod.c 2010-03-18 10:54:32 UTC (rev 3150)
+++ upstream/trunk/src/usermod.c 2010-03-18 11:53:49 UTC (rev 3151)
@@ -940,7 +940,7 @@
case 'e':
if ('\0' != *optarg) {
user_newexpire = strtoday (optarg);
- if (user_newexpire == -1) {
+ if (user_newexpire < -1) {
fprintf (stderr,
_("%s: invalid date '%s'\n"),
Prog, optarg);
More information about the Pkg-shadow-commits
mailing list