]> granicus.if.org Git - sudo/commitdiff
Use private version of atoid() to avoid a dependency on libcommon.a
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 7 Aug 2013 22:52:50 +0000 (16:52 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 7 Aug 2013 22:52:50 +0000 (16:52 -0600)
(since that already depends on libreplace.a).

compat/getgrouplist.c

index cf0b0de06210dcf491ff38df37a557033124ac9c..8573c349873d0116eacc9542bdf0c544a382423e 100644 (file)
@@ -100,7 +100,43 @@ done:
 #endif
 
 extern void _nss_initf_group(nss_db_params_t *);
-extern id_t atoid(const char *str, const char **errstr);
+
+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
@@ -110,10 +146,9 @@ static int
 str2grp(const char *instr, int inlen, void *ent, char *buf, int buflen)
 {
     struct group *grp = ent;
-    char *cp, *ep, *fieldsep = buf;
+    char *cp, *fieldsep = buf;
     char **gr_mem, **gr_end;
-    const char *errstr;
-    int yp = 0;
+    int errval, yp = 0;
     id_t id;
 
     /* Must at least have space to copy instr -> buf. */
@@ -148,20 +183,19 @@ 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';
-    errno = 0;
-    id = atoid(cp, &errstr);
-    if (errstr == NULL) {
+    id = strtoid(cp, &errval);
+    if (errval != 0) {
        /*
         * A range error is always a fatal error, but ignore garbage
         * at the end of YP entries since it has no meaning.
         */
-       if (errno == ERANGE)
+       if (errval == ERANGE)
            return NSS_STR_PARSE_ERANGE;
        return yp ? NSS_STR_PARSE_SUCCESS : NSS_STR_PARSE_PARSE;
     }
 #ifdef GID_NOBODY
     /* Negative gids get mapped to nobody on Solaris. */
-    if (*cp == '-' && gid != 0)
+    if (*cp == '-' && id != 0)
        grp->gr_gid = GID_NOBODY;
     else
 #endif