]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Give a nicer error message if %h is used while there is no home directory.
authorTimo Sirainen <tss@iki.fi>
Sat, 25 Oct 2008 12:20:04 +0000 (15:20 +0300)
committerTimo Sirainen <tss@iki.fi>
Sat, 25 Oct 2008 12:20:04 +0000 (15:20 +0300)
--HG--
branch : HEAD

src/master/mail-process.c

index 3775212c2c51b300ea8f394953d03417867ec0ea..102ad276a3c8d08065e8f6e43aa2ef6d53020bd7 100644 (file)
@@ -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));
        }