mailbox-list.c revision 8a0ad174adb1eb5108511b90e97f4e5f9089b0ee
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen/* Copyright (c) 2006-2008 Dovecot authors, see the included COPYING file */
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen/* 20 * (200+1) < 4096 which is the standard PATH_MAX. Having these settings
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen prevents malicious user from creating eg. "a/a/a/.../a" mailbox name and
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen then start renaming them to larger names from end to beginning, which
49e513d090753ccbf95560b2f3a21f081a5b6c51Timo Sirainen eventually would start causing the failures when trying to use too
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen long mailbox names. */
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen/* Message to show to users when critical error occurs */
473080c7c0d25ddfdf77e7dfa0ba8f73c6c669d5Timo Sirainen "Internal error occurred. Refer to server log for more information."
473080c7c0d25ddfdf77e7dfa0ba8f73c6c669d5Timo Sirainen#define CRITICAL_MSG_STAMP CRITICAL_MSG " [%Y-%m-%d %H:%M:%S]"
473080c7c0d25ddfdf77e7dfa0ba8f73c6c669d5Timo Sirainenstruct mailbox_list_module_register mailbox_list_module_register = { 0 };
356303df200c991580bd24041996a070ad08c05eTimo Sirainenvoid (*hook_mailbox_list_created)(struct mailbox_list *list);
49e513d090753ccbf95560b2f3a21f081a5b6c51Timo Sirainenstatic ARRAY_DEFINE(mailbox_list_drivers, const struct mailbox_list *);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenstatic bool mailbox_list_driver_find(const char *name, unsigned int *idx_r)
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen unsigned int i, count;
d5abbb932a0a598f002da39a8b3326643b1b5efcTimo Sirainen drivers = array_get(&mailbox_list_drivers, &count);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen for (i = 0; i < count; i++) {
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen if (strcasecmp(drivers[i]->name, name) == 0) {
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainenvoid mailbox_list_register(const struct mailbox_list *list)
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen unsigned int idx;
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen if (mailbox_list_driver_find(list->name, &idx)) {
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen i_fatal("mailbox_list_register(%s): duplicate driver",
3b94ff5951db4d4eddb7a80ed4e3f61207202635Timo Sirainen array_append(&mailbox_list_drivers, &list, 1);
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainenvoid mailbox_list_unregister(const struct mailbox_list *list)
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen unsigned int idx;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen if (!mailbox_list_driver_find(list->name, &idx)) {
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen i_fatal("mailbox_list_unregister(%s): unknown driver",
6fabfb7bbfd88d0c1de66981e52850f26067623bTimo Sirainenint mailbox_list_alloc(const char *driver, struct mailbox_list **list_r,
22535a9e685e29214082878e37a267157044618eTimo Sirainen const char **error_r)
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen unsigned int idx;
356303df200c991580bd24041996a070ad08c05eTimo Sirainen if (!mailbox_list_driver_find(driver, &idx)) {
49e513d090753ccbf95560b2f3a21f081a5b6c51Timo Sirainen *error_r = t_strdup_printf("Unknown mailbox list driver: %s",
e15f1d736c225c7ce6f3d08a37c1b2ae66b57c50Timo Sirainen class_p = array_idx(&mailbox_list_drivers, idx);
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen array_create(&list->module_contexts, list->pool, sizeof(void *), 5);
6fabfb7bbfd88d0c1de66981e52850f26067623bTimo Sirainenint mailbox_list_settings_parse(const char *data,
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen const char **error_r)
6fabfb7bbfd88d0c1de66981e52850f26067623bTimo Sirainen /* <root dir> */
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen else if (strcmp(key, "ALT") == 0 && alt_dir_r != NULL)
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen *error_r = t_strdup_printf("Unknown setting: %s", key);
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen if (set->index_dir != NULL && strcmp(set->index_dir, "MEMORY") == 0)
c5383a0ed56a188a7d5efaaa4c6f8243af432d65Timo Sirainenvoid mailbox_list_init(struct mailbox_list *list, struct mail_namespace *ns,
c5383a0ed56a188a7d5efaaa4c6f8243af432d65Timo Sirainen i_assert(set->root_dir == NULL || *set->root_dir != '\0');
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen /* copy settings */
d5abbb932a0a598f002da39a8b3326643b1b5efcTimo Sirainen list->set.root_dir = p_strdup(list->pool, set->root_dir);
d5abbb932a0a598f002da39a8b3326643b1b5efcTimo Sirainen list->set.index_dir = set->index_dir == NULL ||
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen strcmp(set->index_dir, set->root_dir) == 0 ? NULL :
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen list->set.control_dir = set->control_dir == NULL ||
const char *path;
path);
const char *pattern)
const char *name)
const char *name)
return pattern;
const char *name,
struct mailbox_list_iterate_context *
struct mailbox_list_iterate_context *
const char *const *patterns,
const struct mailbox_info *
const char *name)
if (created) {
if (create_flags != 0)
if (!match_parents)
if (p == NULL)
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 *error_string;
return FALSE;
return TRUE;