* src/chage.c: More strtol() replaced by getlong().

This commit is contained in:
nekral-guest 2009-04-10 22:34:36 +00:00
parent 66e39884e2
commit 52238dd6a7
2 changed files with 48 additions and 17 deletions

View File

@ -1,3 +1,7 @@
2009-04-06 Nicolas François <nicolas.francois@centraliens.net>
* src/chage.c: More strtol() replaced by getlong().
2009-04-06 Nicolas François <nicolas.francois@centraliens.net> 2009-04-06 Nicolas François <nicolas.francois@centraliens.net>
* lib/prototypes.h: pwd_to_spwd() should be declared if USE_PAM is * lib/prototypes.h: pwd_to_spwd() should be declared if USE_PAM is

View File

@ -195,23 +195,20 @@ static void date_to_str (char *buf, size_t maxsize, time_t date)
static int new_fields (void) static int new_fields (void)
{ {
char buf[200]; char buf[200];
char *cp;
(void) puts (_("Enter the new value, or press ENTER for the default")); (void) puts (_("Enter the new value, or press ENTER for the default"));
(void) puts (""); (void) puts ("");
snprintf (buf, sizeof buf, "%ld", mindays); snprintf (buf, sizeof buf, "%ld", mindays);
change_field (buf, sizeof buf, _("Minimum Password Age")); change_field (buf, sizeof buf, _("Minimum Password Age"));
mindays = strtol (buf, &cp, 10); if ( (getlong (buf, &mindays) == 0)
if ( ((0 == mindays) && ('\0' != *cp))
|| (mindays < -1)) { || (mindays < -1)) {
return 0; return 0;
} }
snprintf (buf, sizeof buf, "%ld", maxdays); snprintf (buf, sizeof buf, "%ld", maxdays);
change_field (buf, sizeof buf, _("Maximum Password Age")); change_field (buf, sizeof buf, _("Maximum Password Age"));
maxdays = strtol (buf, &cp, 10); if ( (getlong (buf, &maxdays) == 0)
if ( ((0 == maxdays) && ('\0' != *cp))
|| (maxdays < -1)) { || (maxdays < -1)) {
return 0; return 0;
} }
@ -231,16 +228,14 @@ static int new_fields (void)
snprintf (buf, sizeof buf, "%ld", warndays); snprintf (buf, sizeof buf, "%ld", warndays);
change_field (buf, sizeof buf, _("Password Expiration Warning")); change_field (buf, sizeof buf, _("Password Expiration Warning"));
warndays = strtol (buf, &cp, 10); if ( (getlong (buf, &warndays) == 0)
if ( ((warndays == 0) && ('\0' != *cp))
|| (warndays < -1)) { || (warndays < -1)) {
return 0; return 0;
} }
snprintf (buf, sizeof buf, "%ld", inactdays); snprintf (buf, sizeof buf, "%ld", inactdays);
change_field (buf, sizeof buf, _("Password Inactive")); change_field (buf, sizeof buf, _("Password Inactive"));
inactdays = strtol (buf, &cp, 10); if ( (getlong (buf, &inactdays) == 0)
if ( ((inactdays == 0) && ('\0' != *cp))
|| (inactdays < -1)) { || (inactdays < -1)) {
return 0; return 0;
} }
@ -411,16 +406,24 @@ static void process_flags (int argc, char **argv)
dflg = true; dflg = true;
if (!isnum (optarg)) { if (!isnum (optarg)) {
lastday = strtoday (optarg); lastday = strtoday (optarg);
} else { } else if ( (getlong (optarg, &lastday) == 0)
lastday = strtol (optarg, 0, 10); || (lastday < -1)) {
fprintf (stderr,
_("%s: invalid date '%s'\n"),
Prog, optarg);
usage ();
} }
break; break;
case 'E': case 'E':
Eflg = true; Eflg = true;
if (!isnum (optarg)) { if (!isnum (optarg)) {
expdays = strtoday (optarg); expdays = strtoday (optarg);
} else { } else if ( (getlong (optarg, &expdays) == 0)
expdays = strtol (optarg, 0, 10); || (expdays < -1)) {
fprintf (stderr,
_("%s: invalid date '%s'\n"),
Prog, optarg);
usage ();
} }
break; break;
case 'h': case 'h':
@ -428,22 +431,46 @@ static void process_flags (int argc, char **argv)
break; break;
case 'I': case 'I':
Iflg = true; Iflg = true;
inactdays = strtol (optarg, 0, 10); if ( (getlong (optarg, &inactdays) == 0)
|| (inactdays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
usage ();
}
break; break;
case 'l': case 'l':
lflg = true; lflg = true;
break; break;
case 'm': case 'm':
mflg = true; mflg = true;
mindays = strtol (optarg, 0, 10); if ( (getlong (optarg, &mindays) == 0)
|| (mindays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
usage ();
}
break; break;
case 'M': case 'M':
Mflg = true; Mflg = true;
maxdays = strtol (optarg, 0, 10); if ( (getlong (optarg, &maxdays) == 0)
|| (maxdays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
usage ();
}
break; break;
case 'W': case 'W':
Wflg = true; Wflg = true;
warndays = strtol (optarg, 0, 10); if ( (getlong (optarg, &warndays) == 0)
|| (warndays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
usage ();
}
break; break;
default: default:
usage (); usage ();