]> granicus.if.org Git - shadow/commitdiff
* src/useradd.c: Use getlong instead of get_number.
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Fri, 10 Apr 2009 22:33:50 +0000 (22:33 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Fri, 10 Apr 2009 22:33:50 +0000 (22:33 +0000)
ChangeLog
src/useradd.c

index 8a71bb2ee3b7e11075ada9c973936ed07f4374a8..7cd368fab618162460307ca02d5f971dd4855d58 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-04-06  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * src/useradd.c: Use getlong instead of get_number.
+
 2009-04-06  Nicolas François  <nicolas.francois@centraliens.net>
 
        * src/usermod.c: Re-indent.
index e90108ed8b5ca1baaacd9b6a9f2e8bf2f582b790..da6fd0cdf7092ab4fdc510623847e4cbc542aa0d 100644 (file)
@@ -170,7 +170,6 @@ static bool home_added = false;
 /* local function prototypes */
 static void fail_exit (int);
 static struct group *getgr_nam_gid (const char *);
-static long get_number (const char *);
 static void get_defaults (void);
 static void show_defaults (void);
 static int set_defaults (void);
@@ -281,22 +280,6 @@ static struct group *getgr_nam_gid (const char *grname)
        return xgetgrnam (grname);
 }
 
-static long get_number (const char *numstr)
-{
-       long val;
-       char *endptr;
-
-       errno = 0;
-       val = strtol (numstr, &endptr, 10);
-       if (('\0' == *numstr) || ('\0' != *endptr) || (ERANGE == errno)) {
-               fprintf (stderr,
-                        _("%s: invalid numeric argument '%s'\n"),
-                        Prog, numstr);
-               exit (E_BAD_ARG);
-       }
-       return val;
-}
-
 #define MATCH(x,y) (strncmp((x),(y),strlen(y)) == 0)
 
 /*
@@ -1053,15 +1036,21 @@ static void process_flags (int argc, char **argv)
                                eflg = true;
                                break;
                        case 'f':
-                               def_inactive = get_number (optarg);
+                               if (   (getlong (optarg, &def_inactive) == 0)
+                                   || (def_inactive < -1)) {
+                                       fprintf (stderr,
+                                                _("%s: invalid numeric argument '%s'\n"),
+                                                Prog, optarg);
+                                       usage ();
+                               }
                                /*
-                                * -f -1 is allowed - it's a no-op without /etc/shadow
+                                * -f -1 is allowed
+                                * it's a no-op without /etc/shadow
                                 */
                                if ((-1 != def_inactive) && !is_shadow_pwd) {
                                        fprintf (stderr,
-                                                _
-                                                ("%s: shadow passwords required for -f\n"),
-                                                Prog);
+                                                _("%s: shadow passwords required for -f\n"),
+                                                Prog);
                                        exit (E_USAGE);
                                }
                                fflg = true;