diff --git a/mountd.c.orig b/mountd.c --- a/mountd.c.orig +++ b/mountd.c @@ -3518,6 +3518,8 @@ struct group *gr; gid_t groups[NGROUPS_MAX + 1]; int ngroups; + unsigned long name_ul; + char *end = NULL; /* * Set up the unprivileged user. @@ -3532,10 +3534,17 @@ names = namelist; name = strsep_quote(&names, ":"); /* Bug? name could be NULL here */ - if (isdigit(*name) || *name == '-') - pw = getpwuid(atoi(name)); - else + name_ul = strtoul(name, &end, 10); + if (end == NULL || *end != '\0' || end == name) { pw = getpwnam(name); + } else { + pw = getpwuid((uid_t)name_ul); + } + if (pw == NULL) { + syslog(LOG_ERR, "unknown user: %s", name); + return; + } + /* * Credentials specified as those of a user. */ @@ -3573,24 +3582,34 @@ * Explicit credential specified as a colon separated list: * uid:gid:gid:... */ - if (pw != NULL) + if (pw != NULL) { cr->cr_uid = pw->pw_uid; - else if (isdigit(*name) || *name == '-') - cr->cr_uid = atoi(name); - else { - syslog(LOG_ERR, "unknown user: %s", name); - return; + } else { + name_ul = strtoul(name, &end, 10); + if (end == NULL || *end != '\0' || end == name) { + pw = getpwnam(name); + } else { + pw = getpwuid((uid_t)name_ul); + } + if (pw == NULL) { + syslog(LOG_ERR, "unknown user: %s", name); + return; + } } + cr->cr_ngroups = 0; while (names != NULL && *names != '\0' && cr->cr_ngroups < NGROUPS_MAX) { name = strsep_quote(&names, ":"); - if (isdigit(*name) || *name == '-') { - groups[cr->cr_ngroups++] = atoi(name); + name_ul = strtoul(name, &end, 10); + if (end == NULL || *end != '\0' || end == name) { + gr = getgrnam(name); } else { - if ((gr = getgrnam(name)) == NULL) { - syslog(LOG_ERR, "unknown group: %s", name); - continue; - } + gr = getgrgid((gid_t)name_ul); + } + if (gr == NULL) { + syslog(LOG_ERR, "unknown group: %s", name); + continue; + } else { groups[cr->cr_ngroups++] = gr->gr_gid; } }