From: Timo Sirainen Date: Fri, 13 Mar 2009 22:36:50 +0000 (-0400) Subject: auth: Improved getpwnam() and getgrnam() error handling. X-Git-Tag: 1.2.beta2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1213eb8287aedfd21af361abbc877569f63103fe;p=thirdparty%2Fdovecot%2Fcore.git auth: Improved getpwnam() and getgrnam() error handling. --HG-- branch : HEAD --- diff --git a/src/auth/main.c b/src/auth/main.c index 8a97046058..0735c005c2 100644 --- a/src/auth/main.c +++ b/src/auth/main.c @@ -80,8 +80,19 @@ static uid_t get_uid(const char *user) if (is_numeric(user, '\0')) return strtoul(user, NULL, 10); - if ((pw = getpwnam(user)) == NULL) + errno = 0; + if ((pw = getpwnam(user)) == NULL) { + if (errno != 0) + i_fatal("User '%s' lookup failed: %m", user); + setpwent(); + if (getpwent() == NULL) { + if (errno != 0) + i_fatal("getpwent() failed: %m"); + i_fatal("getpwnam() failed for some reason. " + "Is auth_process_size set to too low?"); + } i_fatal("User doesn't exist: %s", user); + } return pw->pw_uid; } @@ -94,8 +105,13 @@ static gid_t get_gid(const char *group) if (is_numeric(group, '\0')) return strtoul(group, NULL, 10); - if ((gr = getgrnam(group)) == NULL) - i_fatal("Group doesn't exist: %s", group); + errno = 0; + if ((gr = getgrnam(group)) == NULL) { + if (errno != 0) + i_fatal("Group '%s' lookup failed: %m", group); + else + i_fatal("Group doesn't exist: %s", group); + } return gr->gr_gid; }