mail-user.c revision 8633c38d4c5e62ca8d68d64a8e07e85dc11d035a
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* Copyright (c) 2008-2009 Dovecot authors, see the included COPYING file */
34435ce4a468dc13b23db69dbdd09fe20be88816Timo Sirainenstruct mail_user_module_register mail_user_module_register = { 0 };
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenvoid (*hook_mail_user_created)(struct mail_user *user) = NULL;
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenstatic struct auth_master_connection *auth_master_conn;
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenstatic void mail_user_deinit_base(struct mail_user *user)
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainenstruct mail_user *mail_user_alloc(const char *username,
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen pool = pool_alloconly_create("mail user", 8192);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen settings_dup(&mail_user_setting_parser_info, set, pool);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen user->set = settings_dup(&mail_user_setting_parser_info, set, pool);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen p_array_init(&user->module_contexts, user->pool, 5);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenmail_user_expand_plugins_envs(struct mail_user *user, const char **error_r)
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen unsigned int i, count;
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen if (!array_is_created(&user->set->plugin_envs))
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen envs = array_get_modifiable(&user->set->plugin_envs, &count);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen "userdb didn't return a home directory, "
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen "but plugin setting %s used it (%%h): %s",
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen var_expand(str, envs[i+1], mail_user_var_expand_table(user));
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainenint mail_user_init(struct mail_user *user, const char **error_r)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen settings_vars_have_key(&mail_user_setting_parser_info, user->set,
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen "userdb didn't return a home directory, "
fe363b433b8038a69b55169da9dca27892ad7d18Timo Sirainen settings_var_expand(&mail_user_setting_parser_info, user->set,
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen user->pool, mail_user_var_expand_table(user));
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen if (mail_user_expand_plugins_envs(user, error_r) < 0)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen mail_set = mail_user_set_get_storage_set(user->set);
f8512649cd4db427a8dc5dc8f45c8e379ffd4d76Timo Sirainenstruct mail_user *mail_user_find(struct mail_user *user, const char *name)
f8512649cd4db427a8dc5dc8f45c8e379ffd4d76Timo Sirainen for (ns = user->namespaces; ns != NULL; ns = ns->next) {
63a2f941c1ad029061129ba6384d1d2a02382220Timo Sirainen if (ns->owner != NULL && strcmp(ns->owner->username, name) == 0)
3785910c303507db5f629684e6dde2cc7f83668eTimo Sirainenvoid mail_user_set_vars(struct mail_user *user, uid_t uid, const char *service,
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen user->service = p_strdup(user->pool, service);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen if (local_ip != NULL && local_ip->family != 0) {
0a70a2e71658d168f75d1f075661d7936701343cTimo Sirainen user->local_ip = p_new(user->pool, struct ip_addr, 1);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen if (remote_ip != NULL && remote_ip->family != 0) {
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen user->remote_ip = p_new(user->pool, struct ip_addr, 1);
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainenmail_user_var_expand_table(struct mail_user *user)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen static struct var_expand_table static_tab[] = {
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen tab = p_malloc(user->pool, sizeof(static_tab));
3785910c303507db5f629684e6dde2cc7f83668eTimo Sirainen tab[1].value = p_strdup(user->pool, t_strcut(user->username, '@'));
74f810327aca91b3375d3fc963bce8076785b1cbTimo Sirainen tab[4].value = user->_home; /* don't look it up unless we need it */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen tab[5].value = user->local_ip == NULL ? NULL :
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen p_strdup(user->pool, net_ip2addr(user->local_ip));
fe363b433b8038a69b55169da9dca27892ad7d18Timo Sirainen tab[6].value = user->remote_ip == NULL ? NULL :
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen p_strdup(user->pool, net_ip2addr(user->remote_ip));
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen tab[8].value = p_strdup(user->pool, dec2str(user->uid));
106e86d8bfdfebd3ff55241845920ea3b47e0ba2Timo Sirainenvoid mail_user_set_home(struct mail_user *user, const char *home)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenvoid mail_user_add_namespace(struct mail_user *user,
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen struct mail_namespace **tmp, *next, *ns = *namespaces;
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen if (strlen(ns->prefix) < strlen((*tmp)->prefix))
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenvoid mail_user_drop_useless_namespaces(struct mail_user *user)
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen for (ns = user->namespaces; ns != NULL; ns = next) {
34435ce4a468dc13b23db69dbdd09fe20be88816Timo Sirainen if ((ns->flags & NAMESPACE_FLAG_USABLE) == 0 &&
34435ce4a468dc13b23db69dbdd09fe20be88816Timo Sirainen (ns->flags & NAMESPACE_FLAG_AUTOCREATED) != 0)
34435ce4a468dc13b23db69dbdd09fe20be88816Timo Sirainenconst char *mail_user_home_expand(struct mail_user *user, const char *path)
return path;
int ret;
if (ret < 0)
return ret;
const char *name)
const char *const *envs;
unsigned int i, count;
return NULL;
return NULL;
return NULL;
void mail_users_deinit(void)