mailbox-list.c revision e91543761d0b7b97a1dc28e036e44d76405545c2
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen/* Copyright (c) 2006-2009 Dovecot authors, see the included COPYING file */
f7539a17ea306191b53b8f5e752e228937df9ec3Timo Sirainen/* 20 * (200+1) < 4096 which is the standard PATH_MAX. Having these settings
f7539a17ea306191b53b8f5e752e228937df9ec3Timo Sirainen prevents malicious user from creating eg. "a/a/a/.../a" mailbox name and
f7539a17ea306191b53b8f5e752e228937df9ec3Timo Sirainen then start renaming them to larger names from end to beginning, which
f7539a17ea306191b53b8f5e752e228937df9ec3Timo Sirainen eventually would start causing the failures when trying to use too
f7539a17ea306191b53b8f5e752e228937df9ec3Timo Sirainen long mailbox names. */
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen struct mailbox_list_iterate_context *backend_ctx;
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenstruct mailbox_list_module_register mailbox_list_module_register = { 0 };
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenvoid (*hook_mailbox_list_created)(struct mailbox_list *list);
e5fd6dfd0a492e4708d4dbb7971d7fc5d7b8fd85Timo Sirainenstatic ARRAY_DEFINE(mailbox_list_drivers, const struct mailbox_list *);
d22301419109ed4a38351715e6760011421dadecTimo Sirainenstatic bool mailbox_list_driver_find(const char *name, unsigned int *idx_r)
d22301419109ed4a38351715e6760011421dadecTimo Sirainen unsigned int i, count;
e5fd6dfd0a492e4708d4dbb7971d7fc5d7b8fd85Timo Sirainen drivers = array_get(&mailbox_list_drivers, &count);
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen for (i = 0; i < count; i++) {
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen if (strcasecmp(drivers[i]->name, name) == 0) {
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenvoid mailbox_list_register(const struct mailbox_list *list)
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen unsigned int idx;
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen if (mailbox_list_driver_find(list->name, &idx)) {
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen i_fatal("mailbox_list_register(%s): duplicate driver",
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen array_append(&mailbox_list_drivers, &list, 1);
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainenvoid mailbox_list_unregister(const struct mailbox_list *list)
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen unsigned int idx;
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen if (!mailbox_list_driver_find(list->name, &idx)) {
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen i_fatal("mailbox_list_unregister(%s): unknown driver",
df00412606a00714a6e85383fa87fbdc7cc1fb5bTimo Sirainenint mailbox_list_alloc(const char *driver, struct mailbox_list **list_r,
df00412606a00714a6e85383fa87fbdc7cc1fb5bTimo Sirainen const char **error_r)
df00412606a00714a6e85383fa87fbdc7cc1fb5bTimo Sirainen unsigned int idx;
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen if (!mailbox_list_driver_find(driver, &idx)) {
17ad2164c747cedbf81dae1893063e71a3df0356Timo Sirainen *error_r = t_strdup_printf("Unknown mailbox list driver: %s",
3c493c276f599d9b9cd10764876d648003046954Timo Sirainen class_p = array_idx(&mailbox_list_drivers, idx);
17ad2164c747cedbf81dae1893063e71a3df0356Timo Sirainen array_create(&list->module_contexts, list->pool, sizeof(void *), 5);
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenstatic int fix_path(struct mail_namespace *ns, const char *path,
f81f4bc282cd1944cec187bae89c0701a416ed2aTimo Sirainen const char **path_r)
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen if (mail_user_try_home_expand(ns->user, &path) < 0)
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainenint mailbox_list_settings_parse(const char *data,
ac26a4607cb12b156f6a42f1ead2881bedd43d94Timo Sirainen const char **error_r)
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen /* <root dir> */
306cfd77100131c08b243de10f6d40500f4c27c6Timo Sirainen "Home directory not set, can't expand ~/ for "
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen else if (strcmp(key, "ALT") == 0 && alt_dir_r != NULL)
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen *error_r = t_strdup_printf("Unknown setting: %s", key);
struct mail_namespace *
return mode;
const char *path;
path);
const char *name,
const char *pattern)
const char *name)
const char *name)
int ret;
T_BEGIN {
} T_END;
return pattern;
const char *name,
struct mailbox_list_iterate_context *
struct mailbox_list_iterate_context *
const char *const *patterns,
static const struct mailbox_info *
return info;
int ret;
return ret;
struct mailbox_list_iterate_context *
const char *const *patterns,
unsigned int i, count;
for (i = 0; i < count; i++)
const struct mailbox_info *
return info;
const char *name)
const char *name)
if (created) {
if (create_flags != 0)
if (p == NULL)
const char *name)
T_BEGIN {
} T_END;
return TRUE;
levels++;
level_len = 0;
level_len++;
return TRUE;
return TRUE;
return FALSE;
#ifdef HAVE_DIRENT_D_TYPE
switch (d->d_type) {
case DT_UNKNOWN:
case DT_REG:
case DT_DIR:
case DT_LNK:
return type;
const char **name)
return FALSE;
return TRUE;
return FALSE;
return TRUE;
return TRUE;
return FALSE;
const char *error_string;
return FALSE;
return TRUE;