#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
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. */
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