mail-user.c revision 39993536eaef0a23954105e41040dcf88afd2e7e
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2008-2012 Dovecot authors, see the included COPYING file */
56f45b3f3ae20e5c933701f4657dda5ef1916855Timo Sirainenstruct mail_user_module_register mail_user_module_register = { 0 };
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenstruct auth_master_connection *mail_user_auth_master_conn;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenstatic void mail_user_deinit_base(struct mail_user *user)
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainenstruct mail_user *mail_user_alloc(const char *username,
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen pool = pool_alloconly_create("mail user", 16*1024);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen user->unexpanded_set = settings_dup(set_info, set, pool);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen user->set = settings_dup(set_info, set, pool);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen user->service = master_service_get_name(master_service);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* check settings so that the duplicated structure will again
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen contain the parsed fields */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (!settings_check(set_info, pool, user->set, &error))
659fe5d24825b160cae512538088020d97a60239Timo Sirainen i_panic("Settings check unexpectedly failed: %s", error);
232d5bef3c709e90e24f0874a36854b92187bb6cTimo Sirainen p_array_init(&user->module_contexts, user->pool, 5);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenmail_user_expand_plugins_envs(struct mail_user *user, const char **error_r)
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen unsigned int i, count;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (!array_is_created(&user->set->plugin_envs))
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen envs = array_get_modifiable(&user->set->plugin_envs, &count);
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen "userdb didn't return a home directory, "
d143077bd518de129b8d446fb58e003903e50867Timo Sirainen "but plugin setting %s used it (%%h): %s",
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen var_expand(str, envs[i+1], mail_user_var_expand_table(user));
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenint mail_user_init(struct mail_user *user, const char **error_r)
d143077bd518de129b8d446fb58e003903e50867Timo Sirainen settings_vars_have_key(user->set_info, user->set,
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* expand mail_home setting before calling mail_user_get_home() */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen settings_var_expand(user->set_info, user->set,
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen user->pool, mail_user_var_expand_table(user));
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen if (need_home_dir && mail_user_get_home(user, &home) <= 0) {
a928e7efabb1672b1476e597106d4b4b81ac6f3cTimo Sirainen "userdb didn't return a home directory, "
0d70a702dec63d22535684fec6a7247c5f153208Timo Sirainen if (mail_user_expand_plugins_envs(user, error_r) < 0)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen mail_set = mail_user_set_get_storage_set(user);
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen /* call deinit() with refcount=1, otherwise we may assert-crash in
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen mail_user_ref() that is called by some deinit() handler. */
c680a6b35b459045e92814778908da5a93922107Timo Sirainenstruct mail_user *mail_user_find(struct mail_user *user, const char *name)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen for (ns = user->namespaces; ns != NULL; ns = ns->next) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (ns->owner != NULL && strcmp(ns->owner->username, name) == 0)
ccffbed92cb02c24fd717808a84138240bf1885bTimo Sirainenvoid mail_user_set_vars(struct mail_user *user, const char *service,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen user->service = p_strdup(user->pool, service);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (local_ip != NULL && local_ip->family != 0) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen user->local_ip = p_new(user->pool, struct ip_addr, 1);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (remote_ip != NULL && remote_ip->family != 0) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen user->remote_ip = p_new(user->pool, struct ip_addr, 1);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmail_user_var_expand_table(struct mail_user *user)
93b29720c5141f787bd1861796867e4595c9d084Timo Sirainen static struct var_expand_table static_tab[] = {
a050ca9def13949dbaa67bd6574a41c4f397ae26Timo Sirainen tab = p_malloc(user->pool, sizeof(static_tab));
902222fb0928d1701f20a384b73f327b1d9a15ddTimo Sirainen tab[1].value = p_strdup(user->pool, t_strcut(user->username, '@'));
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen tab[4].value = user->_home; /* don't look it up unless we need it */
return path;
int ret;
if (ret > 0) {
return ret;
int ret;
if (ret < 0)
const char *const *plugins;
bool ret;
T_BEGIN {
} T_END;
return ret;
const char *name)
const char *const *envs;
unsigned int i, count;
return NULL;
return NULL;
return NULL;
const char **error_r)
const char *mounts_path;
return TRUE;
return FALSE;
return TRUE;