From ffd3e43ad85ade2ad20c948b77fe354362b22daf Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Fri, 10 Apr 2009 22:34:04 +0000 Subject: [PATCH] * src/useradd.c: Get rid of strtol. * src/useradd.c: Provide better warning in case a default GROUP or INACTIVE value is not valid in /etc/default/useradd. --- ChangeLog | 3 +++ src/useradd.c | 27 +++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6575fb2e..e00d1110 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ * src/useradd.c: Re-indent. * src/useradd.c: Use getlong instead of get_number. + * src/useradd.c: Get rid of strtol. + * src/useradd.c: Provide better warning in case a default GROUP or + INACTIVE value is not valid in /etc/default/useradd. 2009-04-06 Nicolas François diff --git a/src/useradd.c b/src/useradd.c index b277b8eb..dce0d1f4 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -330,6 +330,9 @@ static void get_defaults (void) fprintf (stderr, _("%s: group '%s' does not exist\n"), Prog, cp); + fprintf (stderr, + _("%s: the %s configuration in %s will be ignored\n"), + Prog, DGROUP, def_file); } else { def_group = grp->gr_gid; def_gname = xstrdup (grp->gr_name); @@ -354,14 +357,14 @@ static void get_defaults (void) * Default Password Inactive value */ else if (MATCH (buf, INACT)) { - long val = strtol (cp, &ep, 10); - - if ( ('\0' != *cp) - && ('\0' == *ep) - && (ERANGE != errno) - && (val >= 0)) { - def_inactive = val; - } else { + if ( (getlong (cp, &def_inactive) == 0) + || (def_inactive < -1)) { + fprintf (stderr, + _("%s: invalid numeric argument '%s'\n"), + Prog, optarg); + fprintf (stderr, + _("%s: the %s configuration in %s will be ignored\n"), + Prog, INACT, def_file); def_inactive = -1; } } @@ -971,9 +974,9 @@ static void process_flags (int argc, char **argv) {"user-group", no_argument, NULL, 'U'}, {NULL, 0, NULL, '\0'} }; - while ((c = - getopt_long (argc, argv, "b:c:d:De:f:g:G:k:K:lmMNop:rs:u:U", - long_options, NULL)) != -1) { + while ((c = getopt_long (argc, argv, + "b:c:d:De:f:g:G:k:K:lmMNop:rs:u:U", + long_options, NULL)) != -1) { switch (c) { case 'b': if ( ( !VALID (optarg) ) @@ -1247,7 +1250,7 @@ static void process_flags (int argc, char **argv) char *uh; uh = xmalloc (strlen (def_home) + - strlen (user_name) + 2); + strlen (user_name) + 2); sprintf (uh, "%s/%s", def_home, user_name); user_home = uh; } -- 2.40.0