shared-storage.c revision e930af34580510d2fe58628d270dbaf786e86248
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen/* Copyright (c) 2008-2009 Dovecot authors, see the included COPYING file */
f3e1593a7d9b02090575fb20db90a235e10145a5Timo Sirainen MODULE_CONTEXT(obj, shared_mailbox_list_module)
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(shared_mailbox_list_module,
acc8c0647873b1c847bfa362ddefd0d219d0aa91Timo Sirainen pool = pool_alloconly_create("shared storage", 1024);
acc8c0647873b1c847bfa362ddefd0d219d0aa91Timo Sirainen storage = p_new(pool, struct shared_storage, 1);
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen storage->storage.storage_class = &shared_storage;
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen storage->base_dir = p_strdup(pool, getenv("BASE_DIR"));
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainenstatic int shared_create(struct mail_storage *_storage, const char *data,
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen const char **error_r)
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen struct shared_storage *storage = (struct shared_storage *)_storage;
f3e1593a7d9b02090575fb20db90a235e10145a5Timo Sirainen const char *driver, *p;
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen /* data must begin with the actual mailbox driver */
9446c7a5d400cba60d097c528bd08312552438e3Timo Sirainen *error_r = "Shared mailbox location not prefixed with driver";
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen storage->location = p_strdup(_storage->pool, data);
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen storage->storage_class = mail_storage_find_class(driver);
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen *error_r = t_strconcat("Unknown shared storage driver: ",
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen _storage->mailbox_is_file = storage->storage_class->mailbox_is_file;
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen wildcardp = strchr(_storage->ns->prefix, '%');
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen *error_r = "Shared namespace prefix doesn't contain %";
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen storage->ns_prefix_pattern = p_strdup(_storage->pool, wildcardp);
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen for (p = storage->ns_prefix_pattern; *p != '\0'; p++) {
e6bdf53eb0143af99e3eb977ff0f8a496ecd1a8dTimo Sirainen if (*p != '%')
9446c7a5d400cba60d097c528bd08312552438e3Timo Sirainen if (*++p == '\0')
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen if (*p != '\0') {
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen *error_r = "Shared namespace prefix contains unknown variables";
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen *error_r = "Shared namespace prefix doesn't contain %u or %n";
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen if (mailbox_list_alloc("shared", &_storage->list, error_r) < 0)
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen MODULE_CONTEXT_SET_FULL(_storage->list, shared_mailbox_list_module,
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen list_set.mail_storage_flags = &_storage->flags;
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen list_set.lock_method = &_storage->lock_method;
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen mailbox_list_init(_storage->list, _storage->ns, &list_set,
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen mail_storage_get_list_flags(_storage->flags));
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainenget_nonexisting_user_location(struct shared_storage *storage,
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen /* user wasn't found. we'll still need to create the storage
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen to avoid exposing which users exist and which don't. */
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen str_append(location, storage->storage_class->name);
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen /* use a reachable but non-existing path as the mail root directory */
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainenint shared_storage_get_namespace(struct mail_storage *_storage,
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen const char **_name,
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen struct shared_storage *storage = (struct shared_storage *)_storage;
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen static struct var_expand_table static_tab[] = {
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen const char *domain = NULL, *username = NULL, *userdomain = NULL;
int ret;
if (*p != *name)
p++; name++;
i_unreached();
domain++;
if (ret > 0)
const char *str;
static struct mailbox *
return NULL;
return NULL;
return box;
int ret;
if (ret < 0)
return ret;
NULL,
NULL,
NULL,