changeset 7136:24526ffec9a2 HEAD

If USER and HOME environments both exists, never do getpwuid() lookup. If HOME doesn't exist, do the lookup but don't fail unless also USER doesn't exist.
author Timo Sirainen <tss@iki.fi>
date Mon, 07 Jan 2008 12:42:18 +0200
parents 9fef306a0d95
children c33c87781ab4
files src/deliver/deliver.c
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/deliver/deliver.c	Mon Jan 07 07:38:16 2008 +0200
+++ b/src/deliver/deliver.c	Mon Jan 07 12:42:18 2008 +0200
@@ -801,12 +801,15 @@
 		/* we're non-root. get our username and possibly our home. */
 		struct passwd *pw;
 
-		pw = getpwuid(process_euid);
-		if (pw != NULL) {
+		user = getenv("USER");
+		home = getenv("HOME");
+		if (user != NULL && home != NULL) {
+			/* no need for a pw lookup */
+		} else if ((pw = getpwuid(process_euid)) != NULL) {
 			user = t_strdup(pw->pw_name);
-			if (getenv("HOME") == NULL)
+			if (home == NULL)
 				env_put(t_strconcat("HOME=", pw->pw_dir, NULL));
-		} else {
+		} else if (user == NULL) {
 			i_fatal("Couldn't lookup our username (uid=%s)",
 				dec2str(process_euid));
 		}