From 0ce48e51a0302014f4a8fcc39e32933c534c8df4 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sat, 25 Oct 2008 15:20:04 +0300 Subject: [PATCH] Give a nicer error message if %h is used while there is no home directory. --HG-- branch : HEAD --- src/master/mail-process.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/master/mail-process.c b/src/master/mail-process.c index 3775212c2c..102ad276a3 100644 --- a/src/master/mail-process.c +++ b/src/master/mail-process.c @@ -173,6 +173,7 @@ get_var_expand_table(const char *protocol, 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 @@ get_var_expand_table(const char *protocol, 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 @@ get_var_expand_table(const char *protocol, 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 @@ expand_mail_env(const char *env, const struct var_expand_table *table) 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 @@ mail_process_set_environment(struct settings *set, const char *mail, 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)); } -- 2.47.3