]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/chage.c: Simplify, by calling a2sl() instead of str2sl()
authorAlejandro Colomar <alx@kernel.org>
Tue, 9 Jan 2024 20:44:05 +0000 (21:44 +0100)
committerAlejandro Colomar <alx@kernel.org>
Tue, 2 Jul 2024 20:52:31 +0000 (22:52 +0200)
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/chage.c

index 9b85b425a96427fbfd470b49bac664fd36ab3ecb..4b482be7af6b40d78862272c80b9795944b78ac6 100644 (file)
@@ -26,7 +26,7 @@
 #endif                         /* ACCT_TOOLS_SETUID */
 #include <pwd.h>
 
-#include "atoi/str2i.h"
+#include "atoi/a2i.h"
 #include "defines.h"
 #include "memzero.h"
 #include "prototypes.h"
@@ -171,17 +171,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");
@@ -201,17 +197,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");
@@ -397,8 +389,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);
@@ -410,8 +401,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);
@@ -420,8 +410,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);
@@ -434,8 +423,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);