From: Timo Sirainen Date: Sat, 26 Feb 2022 20:20:23 +0000 (+0100) Subject: lib-storage: Change %home variable into function X-Git-Tag: 2.4.0~3371 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10eaf04197cfe7f6ab1fd4ab57c9f38e75b2889d;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Change %home variable into function This way home directory can be looked up on-demand rather than having to go through all settings to find out if it's needed. --- diff --git a/src/lib-storage/mail-user.c b/src/lib-storage/mail-user.c index 90bb438193..89ddd5fd61 100644 --- a/src/lib-storage/mail-user.c +++ b/src/lib-storage/mail-user.c @@ -158,19 +158,8 @@ int mail_user_var_expand(struct mail_user *user, int mail_user_init(struct mail_user *user, const char **error_r) { const struct mail_storage_settings *mail_set; - const char *home, *key, *value, *error; - bool need_home_dir; - - need_home_dir = user->_home == NULL && - settings_vars_have_key(user->set_info, user->set, - 'h', "home", &key, &value); - if (need_home_dir && mail_user_get_home(user, &home) <= 0) { - user->error = p_strdup_printf(user->pool, - "userdb didn't return a home directory, " - "but %s used it (%%h): %s", key, value); - } + const char *error; - /* expand settings after we can expand %h */ if (mail_user_var_expand(user, user->set_info, user->set, &error) <= 0) { user->error = p_strdup_printf(user->pool, @@ -299,11 +288,6 @@ void mail_user_set_vars(struct mail_user *user, const char *service, const struct var_expand_table * mail_user_var_expand_table(struct mail_user *user) { - /* use a cached table, unless home directory has been set afterwards */ - if (user->var_expand_table != NULL && - user->var_expand_table[4].value == user->_home) - return user->var_expand_table; - const char *username = p_strdup(user->pool, t_strcut(user->username, '@')); const char *domain = i_strchr_to_next(user->username, '@'); @@ -329,7 +313,6 @@ mail_user_var_expand_table(struct mail_user *user) { 'n', username, "username" }, { 'd', domain, "domain" }, { 's', user->service, "service" }, - { 'h', user->_home /* don't look it up unless we need it */, "home" }, { 'l', local_ip, "lip" }, { 'r', remote_ip, "rip" }, { 'p', my_pid, "pid" }, @@ -356,6 +339,20 @@ mail_user_var_expand_table(struct mail_user *user) return user->var_expand_table; } +static int +mail_user_var_expand_func_home(const char *data ATTR_UNUSED, void *context, + const char **value_r, const char **error_r) +{ + struct mail_user *user = context; + + if (mail_user_get_home(user, value_r) <= 0) { + *error_r = "Setting used home directory (%h) but there is no " + "mail_home and userdb didn't return it"; + return -1; + } + return 1; +} + static int mail_user_var_expand_func_userdb(const char *data, void *context, const char **value_r, @@ -878,6 +875,8 @@ mail_user_get_dict_op_settings(struct mail_user *user) } static const struct var_expand_func_table mail_user_var_expand_func_table_arr[] = { + { "h", mail_user_var_expand_func_home }, + { "home", mail_user_var_expand_func_home }, { "userdb", mail_user_var_expand_func_userdb }, { NULL, NULL } };