changeset 8325:74720db3bef7 HEAD

Give a nicer error message if %h is used while there is no home directory.
author Timo Sirainen <tss@iki.fi>
date Sat, 25 Oct 2008 15:20:04 +0300
parents 66e0eaf4d536
children ccc0322c6804
files src/master/mail-process.c
diffstat 1 files changed, 22 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/master/mail-process.c	Sat Oct 25 15:19:37 2008 +0300
+++ b/src/master/mail-process.c	Sat Oct 25 15:20:04 2008 +0300
@@ -173,6 +173,7 @@
 		     const char *local_ip, const char *remote_ip,
 		     pid_t pid, uid_t uid)
 {
+#define VAR_EXPAND_HOME_IDX 4
 	static struct var_expand_table static_tab[] = {
 		{ 'u', NULL },
 		{ 'n', NULL },
@@ -195,8 +196,7 @@
 	tab[2].value = user == NULL ? NULL : strchr(user, '@');
 	if (tab[2].value != NULL) tab[2].value++;
 	tab[3].value = t_str_ucase(protocol);
-	tab[4].value = home != NULL ? home :
-		"/HOME_DIRECTORY_USED_BUT_NOT_GIVEN_BY_USERDB";
+	tab[VAR_EXPAND_HOME_IDX].value = home;
 	tab[5].value = local_ip;
 	tab[6].value = remote_ip;
 	tab[7].value = dec2str(pid);
@@ -205,6 +205,15 @@
 	return tab;
 }
 
+static bool
+has_missing_used_home(const char *str, const struct var_expand_table *table)
+{
+	i_assert(table[VAR_EXPAND_HOME_IDX].key == 'h');
+
+	return table[VAR_EXPAND_HOME_IDX].value == NULL &&
+		var_has_key(str, 'h');
+}
+
 static const char *
 expand_mail_env(const char *env, const struct var_expand_table *table)
 {
@@ -224,6 +233,11 @@
 		str_append_c(str, *env++);
 	}
 
+	if (has_missing_used_home(env, table)) {
+		i_fatal("userdb didn't return a home directory, "
+			"but mail location used it (%%h): %s", env);
+	}
+
 	/* expand %vars */
 	var_expand(str, env, table);
 	return str_c(str);
@@ -403,6 +417,12 @@
 		str_truncate(str, 0);
 		var_expand(str, envs[i+1], var_expand_table);
 
+		if (has_missing_used_home(envs[i+1], var_expand_table)) {
+			i_error("userdb didn't return a home directory, "
+				"but it's used in plugin setting %s: %s",
+				envs[i], envs[i+1]);
+		}
+
 		env_put(t_strconcat(t_str_ucase(envs[i]), "=",
 				    str_c(str), NULL));
 	}