dovecot-1.2: auth: Improved getpwnam() and getgrnam() error hand...

dovecot at dovecot.org dovecot at dovecot.org
Sat Mar 14 00:36:55 EET 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/d6acde4e9fe0
changeset: 8830:d6acde4e9fe0
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Mar 13 18:36:50 2009 -0400
description:
auth: Improved getpwnam() and getgrnam() error handling.

diffstat:

1 file changed, 19 insertions(+), 3 deletions(-)
src/auth/main.c |   22 +++++++++++++++++++---

diffs (40 lines):

diff -r f67a966f2792 -r d6acde4e9fe0 src/auth/main.c
--- a/src/auth/main.c	Fri Mar 13 18:05:10 2009 -0400
+++ b/src/auth/main.c	Fri Mar 13 18:36:50 2009 -0400
@@ -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;
 }
 


More information about the dovecot-cvs mailing list