shared-storage.c revision 1ba47b1a31e60c533631c8810400b365f785870a
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes/* Copyright (c) 2008-2010 Dovecot authors, see the included COPYING file */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic struct mail_storage *shared_storage_alloc(void)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes pool = pool_alloconly_create("shared storage", 1024);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesshared_storage_create(struct mail_storage *_storage, struct mail_namespace *ns,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const char **error_r)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes struct shared_storage *storage = (struct shared_storage *)_storage;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const char *driver, *p;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* location must begin with the actual mailbox driver */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes *error_r = "Shared mailbox location not prefixed with driver";
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes storage->location = p_strdup(_storage->pool, ns->set->location);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes p_strdup(_storage->pool, ns->unexpanded_set->location);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes storage->storage_class = mail_storage_find_class(driver);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes *error_r = t_strconcat("Unknown shared storage driver: ",
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes _storage->class_flags = storage->storage_class->class_flags;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes *error_r = "Shared namespace prefix doesn't contain %";
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes storage->ns_prefix_pattern = p_strdup(_storage->pool, wildcardp);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes for (p = storage->ns_prefix_pattern; *p != '\0'; p++) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (*p != '%')
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (*p != '\0') {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes *error_r = "Shared namespace prefix contains unknown variables";
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes *error_r = "Shared namespace prefix doesn't contain %u or %n";
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* truncate prefix after the above checks are done, so they can log
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes the full prefix in error conditions */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesshared_storage_get_list_settings(const struct mail_namespace *ns ATTR_UNUSED,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesget_nonexistent_user_location(struct shared_storage *storage,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* user wasn't found. we'll still need to create the storage
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes to avoid exposing which users exist and which don't. */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes str_append(location, storage->storage_class->name);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* use a reachable but nonexistent path as the mail root directory */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes str_append(location, storage->storage.user->set->base_dir);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesint shared_storage_get_namespace(struct mail_namespace **_ns,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const char **_name)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes struct shared_storage *storage = (struct shared_storage *)_storage;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes struct mail_namespace_settings *ns_set, *unexpanded_ns_set;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const char *domain = NULL, *username = NULL, *userdomain = NULL;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (*p != '%') {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes switch (*++p) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* we checked this already above */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (*p != '\0') {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* trying to open <prefix>/<user> mailbox */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "Invalid namespace prefix %s vs %s",
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* successfully matched the name. */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* user@domain given */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* trying to open namespace "shared/domain"
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes namespace prefix. */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* no domain given, use ours (if we have one) */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "Empty username doesn't exist");
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* expand the namespace prefix and see if it already exists.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes this should normally happen only when the mailbox is being opened */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes var_expand(prefix, storage->ns_prefix_pattern, tab);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes *_ns = mail_namespace_find_prefix(user->namespaces, str_c(prefix));
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes owner = mail_user_alloc(userdomain, user->set_info,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* we'll need to look up the user's home directory */
f2f3f241c00a7a4bd597e57a19023940e072918abnicholes if ((ret = mail_user_get_home(owner, &tab[3].value)) < 0) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes mailbox_list_set_critical(list, "Namespace '%s': "
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "Could not lookup home for user %s",
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "Couldn't create namespace '%s' for user %s: %s",
if (ret > 0)
NULL,
NULL,
NULL,
NULL,
NULL,