shared-storage.c revision d927bc5618696157fc55eb1f11b5cab05400ed52
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2008-2009 Dovecot authors, see the included COPYING file */
7e235b3a5f622813121cd18f351e036650aaf8f8Timo Sirainen MODULE_CONTEXT(obj, shared_mailbox_list_module)
471e447023ab73a73f0f78da2afc0c55905330ddTimo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(shared_mailbox_list_module,
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen pool = pool_alloconly_create("shared storage", 1024);
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen storage = p_new(pool, struct shared_storage, 1);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen storage->storage.storage_class = &shared_storage;
bbce20cb4e5739e9a06058cf8ee1f38a7f6884f6Timo Sirainen storage->base_dir = p_strdup(pool, getenv("BASE_DIR"));
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic int shared_create(struct mail_storage *_storage, const char *data,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char **error_r)
fc7b17677ac1a5fa3f7fe13d5ef7dcfea8d9b4a1Timo Sirainen struct shared_storage *storage = (struct shared_storage *)_storage;
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen const char *driver, *p;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* data must begin with the actual mailbox driver */
44ff75ca53188056ff5a3e50428e3f2078800b3cTimo Sirainen *error_r = "Shared mailbox location not prefixed with driver";
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen storage->location = p_strdup(_storage->pool, data);
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen storage->storage_class = mail_storage_find_class(driver);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen *error_r = t_strconcat("Unknown shared storage driver: ",
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen _storage->mailbox_is_file = storage->storage_class->mailbox_is_file;
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen wildcardp = strchr(_storage->ns->prefix, '%');
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen *error_r = "Shared namespace prefix doesn't contain %";
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen storage->ns_prefix_pattern = p_strdup(_storage->pool, wildcardp);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen for (p = storage->ns_prefix_pattern; *p != '\0'; p++) {
45e62043058738e294f89504c319d852e25943ccTimo Sirainen if (*p != '%')
45e62043058738e294f89504c319d852e25943ccTimo Sirainen if (*++p == '\0')
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen if (*p != '\0') {
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen *error_r = "Shared namespace prefix contains unknown variables";
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen *error_r = "Shared namespace prefix doesn't contain %u or %n";
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* truncate prefix after the above checks are done, so they can log
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen the full prefix in error conditions */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen if (mailbox_list_alloc("shared", &_storage->list, error_r) < 0)
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen MODULE_CONTEXT_SET_FULL(_storage->list, shared_mailbox_list_module,
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen list_set.mail_storage_flags = &_storage->flags;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen list_set.lock_method = &_storage->lock_method;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen mailbox_list_init(_storage->list, _storage->ns, &list_set, 0);
2e99f3f3bb35715ce5e0a75a2f2a9bac3ab4224bTimo Sirainenget_nonexisting_user_location(struct shared_storage *storage,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* user wasn't found. we'll still need to create the storage
902222fb0928d1701f20a384b73f327b1d9a15ddTimo Sirainen to avoid exposing which users exist and which don't. */
902222fb0928d1701f20a384b73f327b1d9a15ddTimo Sirainen str_append(location, storage->storage_class->name);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* use a reachable but non-existing path as the mail root directory */
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainenint shared_storage_get_namespace(struct mail_storage *_storage,
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen const char **_name,
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen struct shared_storage *storage = (struct shared_storage *)_storage;
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen static struct var_expand_table static_tab[] = {
int ret;
if (*p != *name)
p++; name++;
i_unreached();
domain++;
if (ret > 0)
const char *str;
int ret;
if (ret < 0)
return ret;
NULL,
NULL,
NULL,
NULL,
NULL,