dbox-storage.c revision f1743785713e7632459d623d5df2108f4b93accb
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2007-2008 Dovecot authors, see the included COPYING file */
bf87a5247ca33660ab8f20c12556ad16d7159395Timo Sirainen#define CREATE_MODE 0770 /* umask() should limit it more */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(dbox_mailbox_list_module,
6cc0546c058f3e6253c6f99727b28dd602712974Timo Sirainendbox_list_delete_mailbox(struct mailbox_list *list, const char *name);
0ce5f96804e81cb0f857e7df32c0272f1eed9377Timo Sirainendbox_list_rename_mailbox(struct mailbox_list *list,
8b2cf1c1bd8ddcea0525b62fd35ba76e136828a1Timo Sirainendbox_list_rename_mailbox_pre(struct mailbox_list *list,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic int dbox_list_iter_is_mailbox(struct mailbox_list_iterate_context *ctx,
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainendbox_get_list_settings(struct mailbox_list_settings *list_set,
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainen const char *data, struct mail_storage *storage,
eb98a038ca8b0ef33d1d11794803ce09547496faTimo Sirainen const char **layout_r, const char **alt_dir_r,
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainen const char **error_r)
9b7eeffb5752b500ac62ba1fd01c4a8c4ada14e9Timo Sirainen bool debug = (storage->flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
93fa87cf1a96c4f279ec4f5c311820313ba12c34Timo Sirainen list_set->subscription_fname = DBOX_SUBSCRIPTION_FILE_NAME;
43834f87bf431198f986e86052a4f6e558fdb07dTimo Sirainen if (data == NULL || *data == '\0' || *data == ':') {
b565a6a7a66fb9f224d00c06a950e3c1c585c18eTimo Sirainen /* we won't do any guessing for this format. */
981139bb2e446bb2050c1158614725f8413fd709Timo Sirainen return mailbox_list_settings_parse(data, list_set, storage->ns,
f988b93c2ef773987bcdcbfb4cca39b955e3a392Timo Sirainen pool = pool_alloconly_create("dbox storage", 512+256);
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen storage = p_new(pool, struct dbox_storage, 1);
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen storage->storage.storage_class = &dbox_storage;
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenstatic int dbox_create(struct mail_storage *_storage, const char *data,
eb98a038ca8b0ef33d1d11794803ce09547496faTimo Sirainen const char **error_r)
eb98a038ca8b0ef33d1d11794803ce09547496faTimo Sirainen struct dbox_storage *storage = (struct dbox_storage *)_storage;
eb98a038ca8b0ef33d1d11794803ce09547496faTimo Sirainen if (dbox_get_list_settings(&list_set, data, _storage,
eb98a038ca8b0ef33d1d11794803ce09547496faTimo Sirainen list_set.mail_storage_flags = &_storage->flags;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen list_set.lock_method = &_storage->lock_method;
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen if ((_storage->flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) != 0) {
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainen "Root mail directory doesn't exist: %s",
27a44fcfd8d19bffe0f267f20a2b5d3fe7600fddTimo Sirainen "stat(%s) failed: %m",
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen *error_r = mail_storage_eacces_msg("mkdir", list_set.root_dir);
10ff47d5d6146995e16da00d36eca7d162064a7bTimo Sirainen *error_r = t_strdup_printf("mkdir(%s) failed: %m",
5238111c460098d9cc8cc22527026138a278b9a4Timo Sirainen if (mailbox_list_alloc(layout, &_storage->list, error_r) < 0)
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen storage->list_module_ctx.super = _storage->list->v;
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainen storage->alt_dir = p_strdup(_storage->pool, alt_dir);
de954ff15b495be13007a8aca2c09fd1d356a283Timo Sirainen _storage->list->v.iter_is_mailbox = dbox_list_iter_is_mailbox;
de954ff15b495be13007a8aca2c09fd1d356a283Timo Sirainen _storage->list->v.delete_mailbox = dbox_list_delete_mailbox;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen _storage->list->v.rename_mailbox = dbox_list_rename_mailbox;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen _storage->list->v.rename_mailbox_pre = dbox_list_rename_mailbox_pre;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen MODULE_CONTEXT_SET_FULL(_storage->list, dbox_mailbox_list_module,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen /* finish list init after we've overridden vfuncs */
0ce5f96804e81cb0f857e7df32c0272f1eed9377Timo Sirainen mailbox_list_init(_storage->list, _storage->ns, &list_set,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen mail_storage_get_list_flags(_storage->flags));
9de176ef7f3d28ff486c2a8805110b84389e4f19Timo Sirainenstatic int create_dbox(struct mail_storage *storage, const char *path)
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen mailbox_list_get_dir_permissions(storage->list, &mode, &gid);
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen if (mkdir_parents_chown(path, mode, (uid_t)-1, gid) < 0 &&
9de176ef7f3d28ff486c2a8805110b84389e4f19Timo Sirainen if (!mail_storage_set_error_from_errno(storage)) {
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainenstatic const char *
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainendbox_get_alt_path(struct dbox_storage *storage, const char *path)
6adf683655750bcb809275cd65dc75fd12214198Timo Sirainen unsigned int len;
6adf683655750bcb809275cd65dc75fd12214198Timo Sirainen root = mailbox_list_get_path(storage->storage.list, NULL,
b90fb7f78aca271243c26074ddd6587cce112a1eTimo Sirainen if (strncmp(path, root, len) != 0 && path[len] == '/') {
b90fb7f78aca271243c26074ddd6587cce112a1eTimo Sirainen /* can't determine the alt path - shouldn't happen */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen return t_strconcat(storage->alt_dir, path + len, NULL);
8cdb3234fe3c77e477c7a0e6934678f58fc54d4dTimo Sirainenstatic struct mailbox *
8cdb3234fe3c77e477c7a0e6934678f58fc54d4dTimo Sirainendbox_open(struct dbox_storage *storage, const char *name,
71da447014454c84828d9dface77219875554d7dTimo Sirainen struct mail_storage *_storage = &storage->storage;
sizeof(struct dbox_mail_index_record),
sizeof(uint32_t));
sizeof(struct dbox_index_header), 0, 0);
return FALSE;
const char *prefix =
return TRUE;
static struct mailbox *
const char *path;
return NULL;
return NULL;
path);
return NULL;
int ret = 0;
const char *name)
struct dirent *d;
unsigned int dir_len;
errno = 0;
path);
if (!unlinked_something) {
int ret;
path);
if (deleted)
path);
const char *path;
return FALSE;
return FALSE;
return TRUE;
newname) < 0)
const char *path;
ret = 0;
return ret;
static void dbox_class_init(void)
static void dbox_class_deinit(void)
NULL,
NULL,
NULL,
NULL,