]> granicus.if.org Git - sudo/commitdiff
Use sudo_strtoid() now that it is located in the same library.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 13 Jul 2014 13:09:00 +0000 (07:09 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 13 Jul 2014 13:09:00 +0000 (07:09 -0600)
lib/util/getgrouplist.c

index ac6652c4e35574a4090e79716bfb04d9d7b57a7a..c42afadc54411ff31fe5230e977d2f0da7697a50 100644 (file)
@@ -37,6 +37,7 @@
 #endif /* HAVE_STRINGS_H */
 #include <grp.h>
 #ifdef HAVE_NSS_SEARCH
+# include <errno.h>
 # include <limits.h>
 # include <nsswitch.h>
 # ifdef HAVE_NSS_DBDEFS_H
@@ -113,43 +114,6 @@ _nss_initf_group(nss_db_params_t *params)
 }
 #endif
 
-static id_t
-strtoid(const char *p, int *errval)
-{
-    char *ep;
-    id_t rval = 0;
-
-    errno = 0;
-    if (*p == '-') {
-       long lval = strtol(p, &ep, 10);
-       if (ep == p || *ep != '\0') {
-           *errval = EINVAL;
-           goto done;
-       }
-       if ((errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN)) ||
-           (lval > INT_MAX || lval < INT_MIN)) {
-           *errval = ERANGE;
-           goto done;
-       }
-       rval = (id_t)lval;
-       *errval = 0;
-    } else {
-       unsigned long ulval = strtoul(p, &ep, 10);
-       if (ep == p || *ep != '\0') {
-           *errval = EINVAL;
-           goto done;
-       }
-       if ((errno == ERANGE && ulval == ULONG_MAX) || ulval > UINT_MAX) {
-           *errval = ERANGE;
-           goto done;
-       }
-       rval = (id_t)ulval;
-       *errval = 0;
-    }
-done:
-    return rval;
-}
-
 /*
  * Convert a groups file string (instr) to a struct group (ent) using
  * buf for storage.  
@@ -160,7 +124,8 @@ str2grp(const char *instr, int inlen, void *ent, char *buf, int buflen)
     struct group *grp = ent;
     char *cp, *fieldsep = buf;
     char **gr_mem, **gr_end;
-    int errval, yp = 0;
+    const char *errstr;
+    int yp = 0;
     id_t id;
 
     /* Must at least have space to copy instr -> buf. */
@@ -195,13 +160,13 @@ str2grp(const char *instr, int inlen, void *ent, char *buf, int buflen)
     if ((fieldsep = strchr(cp = fieldsep, ':')) == NULL)
        return yp ? NSS_STR_PARSE_SUCCESS : NSS_STR_PARSE_PARSE;
     *fieldsep++ = '\0';
-    id = strtoid(cp, &errval);
-    if (errval != 0) {
+    id = sudo_strtoid(cp, NULL, NULL, &errstr);
+    if (errstr != NULL) {
        /*
         * A range error is always a fatal error, but ignore garbage
         * at the end of YP entries since it has no meaning.
         */
-       if (errval == ERANGE)
+       if (errno == ERANGE)
            return NSS_STR_PARSE_ERANGE;
        return yp ? NSS_STR_PARSE_SUCCESS : NSS_STR_PARSE_PARSE;
     }