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

dovecot at dovecot.org dovecot at dovecot.org
Sat Mar 14 00:37:06 EET 2009


details:   http://hg.dovecot.org/dovecot-1.1/rev/abef63c0613b
changeset: 8201:abef63c0613b
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Mar 13 18:37:02 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 34b6694adfcd -r abef63c0613b src/auth/main.c
--- a/src/auth/main.c	Fri Mar 13 18:06:14 2009 -0400
+++ b/src/auth/main.c	Fri Mar 13 18:37:02 2009 -0400
@@ -79,8 +79,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;
 }
 
@@ -93,8 +104,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