static int mbox_mailbox_open_existing(struct mbox_mailbox *mbox) { struct mailbox *box = &mbox->box; const char *rootdir, *box_path = mailbox_get_path(box); bool move_to_memory; move_to_memory = want_memory_indexes(mbox->storage, box_path); if (box->inbox_any || strcmp(box->name, "INBOX") == 0) { /* if INBOX isn't under the root directory, it's probably in /var/mail and we want to allow privileged dotlocking */ rootdir = mailbox_list_get_root_forced(box->list, MAILBOX_LIST_PATH_TYPE_DIR); if (strncmp(box_path, rootdir, strlen(rootdir)) != 0) mbox->mbox_privileged_locking = TRUE; } if ((box->flags & MAILBOX_FLAG_KEEP_LOCKED) != 0) { if (mbox_lock(mbox, F_WRLCK, &mbox->mbox_global_lock_id) <= 0) return -1; if (mbox->mbox_dotlock != NULL) { mbox->keep_lock_to = timeout_add(MBOX_LOCK_TOUCH_MSECS, mbox_lock_touch_timeout, mbox); } } return mbox_mailbox_open_finish(mbox, move_to_memory); }
static int mbox_mailbox_open_existing(struct mbox_mailbox *mbox) { struct mailbox *box = &mbox->box; const char *rootdir; bool move_to_memory; if (access(box->path, R_OK|W_OK) < 0) { if (errno != EACCES) { mbox_set_syscall_error(mbox, "access()"); return -1; } mbox->box.backend_readonly = TRUE; } move_to_memory = want_memory_indexes(mbox->storage, box->path); if (box->inbox_any || strcmp(box->name, "INBOX") == 0) { /* if INBOX isn't under the root directory, it's probably in /var/mail and we want to allow privileged dotlocking */ rootdir = mailbox_list_get_path(box->list, NULL, MAILBOX_LIST_PATH_TYPE_DIR); if (strncmp(box->path, rootdir, strlen(rootdir)) != 0) mbox->mbox_privileged_locking = TRUE; } if ((box->flags & MAILBOX_FLAG_KEEP_LOCKED) != 0) { if (mbox_lock(mbox, F_WRLCK, &mbox->mbox_global_lock_id) <= 0) return -1; if (mbox->mbox_dotlock != NULL) { mbox->keep_lock_to = timeout_add(MBOX_LOCK_TOUCH_MSECS, mbox_lock_touch_timeout, mbox); } } return index_storage_mailbox_open(box, move_to_memory); }