Skip to content

Commit

Permalink
src/chage.c: Simplify, by calling a2sl() instead of str2sl()
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Colomar <alx@kernel.org>
  • Loading branch information
alejandro-colomar committed Jan 29, 2024
1 parent ce1dbc6 commit 7bcc656
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions src/chage.c
Expand Up @@ -27,7 +27,7 @@
#include <pwd.h>

#include "alloc.h"
#include "atoi/str2i.h"
#include "atoi/a2i.h"
#include "prototypes.h"
#include "defines.h"
#include "memzero.h"
Expand Down Expand Up @@ -168,17 +168,13 @@ static int new_fields (void)

SNPRINTF(buf, "%ld", mindays);
change_field (buf, sizeof buf, _("Minimum Password Age"));
if ( (str2sl(&mindays, buf) == -1)
|| (mindays < -1)) {
if (a2sl(&mindays, buf, NULL, 0, -1, LONG_MAX) == -1)
return 0;
}

SNPRINTF(buf, "%ld", maxdays);
change_field (buf, sizeof buf, _("Maximum Password Age"));
if ( (str2sl(&maxdays, buf) == -1)
|| (maxdays < -1)) {
if (a2sl(&maxdays, buf, NULL, 0, -1, LONG_MAX) == -1)
return 0;
}

if (-1 == lstchgdate || lstchgdate > LONG_MAX / DAY) {
strcpy (buf, "-1");
Expand All @@ -199,17 +195,13 @@ static int new_fields (void)

SNPRINTF(buf, "%ld", warndays);
change_field (buf, sizeof buf, _("Password Expiration Warning"));
if ( (str2sl(&warndays, buf) == -1)
|| (warndays < -1)) {
if (a2sl(&warndays, buf, NULL, 0, -1, LONG_MAX) == -1)
return 0;
}

SNPRINTF(buf, "%ld", inactdays);
change_field (buf, sizeof buf, _("Password Inactive"));
if ( (str2sl(&inactdays, buf) == -1)
|| (inactdays < -1)) {
if (a2sl(&inactdays, buf, NULL, 0, -1, LONG_MAX) == -1)
return 0;
}

if (-1 == expdate || LONG_MAX / DAY < expdate) {
strcpy (buf, "-1");
Expand Down Expand Up @@ -394,8 +386,7 @@ static void process_flags (int argc, char **argv)
break;
case 'I':
Iflg = true;
if ( (str2sl(&inactdays, optarg) == -1)
|| (inactdays < -1)) {
if (a2sl(&inactdays, optarg, NULL, 0, -1, LONG_MAX) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
Expand All @@ -407,8 +398,7 @@ static void process_flags (int argc, char **argv)
break;
case 'm':
mflg = true;
if ( (str2sl(&mindays, optarg) == -1)
|| (mindays < -1)) {
if (a2sl(&mindays, optarg, NULL, 0, -1, LONG_MAX) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
Expand All @@ -417,8 +407,7 @@ static void process_flags (int argc, char **argv)
break;
case 'M':
Mflg = true;
if ( (str2sl(&maxdays, optarg) == -1)
|| (maxdays < -1)) {
if (a2sl(&maxdays, optarg, NULL, 0, -1, LONG_MAX) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
Expand All @@ -431,8 +420,7 @@ static void process_flags (int argc, char **argv)
break;
case 'W':
Wflg = true;
if ( (str2sl(&warndays, optarg) == -1)
|| (warndays < -1)) {
if (a2sl(&warndays, optarg, NULL, 0, -1, LONG_MAX) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
Expand Down

0 comments on commit 7bcc656

Please sign in to comment.