int virtual_config_read(struct virtual_mailbox *mbox)
{
- struct mail_user *user = mbox->storage->storage.user;
+ struct mail_storage *storage = mbox->box.storage;
struct virtual_parse_context ctx;
+ struct stat st;
const char *path, *line, *error;
unsigned int linenum = 0;
int fd, ret = 0;
path = t_strconcat(mbox->box.path, "/"VIRTUAL_CONFIG_FNAME, NULL);
fd = open(path, O_RDONLY);
if (fd == -1) {
- if (errno == ENOENT) {
- mail_storage_set_error(mbox->box.storage,
- MAIL_ERROR_NOTPOSSIBLE,
+ if (errno == EACCES) {
+ mail_storage_set_critical(storage, "%s",
+ mail_error_eacces_msg("stat", mbox->box.path));
+ } else if (errno != ENOENT) {
+ mail_storage_set_critical(storage,
+ "open(%s) failed: %m", path);
+ } else if (stat(mbox->box.path, &st) == 0) {
+ mail_storage_set_error(storage, MAIL_ERROR_NOTPOSSIBLE,
"Virtual mailbox missing configuration file");
- return -1;
+ } else if (errno == ENOENT) {
+ mail_storage_set_error(storage, MAIL_ERROR_NOTFOUND,
+ T_MAIL_ERR_MAILBOX_NOT_FOUND(mbox->box.name));
+ } else {
+ mail_storage_set_critical(storage,
+ "stat(%s) failed: %m", mbox->box.path);
}
- mail_storage_set_critical(mbox->box.storage,
- "open(%s) failed: %m", path);
return -1;
}
memset(&ctx, 0, sizeof(ctx));
- ctx.sep = mail_namespaces_get_root_sep(user->namespaces);
+ ctx.sep = mail_namespaces_get_root_sep(storage->user->namespaces);
ctx.mbox = mbox;
ctx.pool = mbox->box.pool;
ctx.rule = t_str_new(256);
else
ret = virtual_config_parse_line(&ctx, line, &error);
if (ret < 0) {
- mail_storage_set_critical(mbox->box.storage,
+ mail_storage_set_critical(storage,
"%s: Error at line %u: %s",
path, linenum, error);
break;
if (ret == 0) {
ret = virtual_config_add_rule(&ctx, &error);
if (ret < 0) {
- mail_storage_set_critical(mbox->box.storage,
+ mail_storage_set_critical(storage,
"%s: Error at line %u: %s",
path, linenum, error);
}
ret = virtual_config_expand_wildcards(&ctx);
if (ret == 0 && array_count(&mbox->backend_boxes) == 0) {
- mail_storage_set_critical(mbox->box.storage,
+ mail_storage_set_critical(storage,
"%s: No mailboxes defined", path);
ret = -1;
}
static int virtual_mailbox_open(struct mailbox *box)
{
struct virtual_mailbox *mbox = (struct virtual_mailbox *)box;
- struct stat st;
int ret = 0;
if (virtual_mailbox_is_in_open_stack(mbox->storage, box->name)) {
return -1;
}
- if (stat(box->path, &st) == 0) {
- /* exists, open it */
- } else if (errno == ENOENT) {
- mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
- T_MAIL_ERR_MAILBOX_NOT_FOUND(box->name));
- return -1;
- } else if (errno == EACCES) {
- mail_storage_set_critical(box->storage, "%s",
- mail_error_eacces_msg("stat", box->path));
- return -1;
- } else {
- mail_storage_set_critical(box->storage,
- "stat(%s) failed: %m", box->path);
- return -1;
- }
-
if (!array_is_created(&mbox->backend_boxes))
ret = virtual_config_read(mbox);
if (ret == 0) {
array_delete(&mbox->storage->open_stack,
array_count(&mbox->storage->open_stack)-1, 1);
}
-
if (ret < 0) {
virtual_mailbox_close_internal(mbox);
return -1;