/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "buffer.h"
#include "hex-binary.h"
#include "randgen.h"
#include "mail-user.h"
#include "mail-storage.h"
#include "mailbox-list-iter.h"
#include "imap-urlauth-private.h"
#include "imap-urlauth-backend.h"
static int
unsigned char mailbox_key_r[IMAP_URLAUTH_KEY_LEN],
const char **error_r,
enum mail_error *error_code_r)
{
int ret;
if (mailbox_open(box) < 0) {
return -1;
}
struct mailbox_transaction_context *t =
__func__);
/* create new key */
if (mailbox_transaction_commit(&t) < 0) {
ret = -1;
}
return ret;
}
static int
bool create,
unsigned char mailbox_key_r[IMAP_URLAUTH_KEY_LEN],
const char **error_r,
enum mail_error *error_code_r)
{
int ret;
*error_r = "Internal server error";
if (ret < 0)
return -1;
if (user->mail_debug) {
i_debug("imap-urlauth: %skey found for mailbox %s",
}
if (ret == 0) {
if (!create)
return 0;
if (ret < 0)
return -1;
if (user->mail_debug) {
i_debug("imap-urlauth: created key for mailbox %s",
}
} else {
/* read existing key */
i_error("imap-urlauth: key found for mailbox %s is invalid",
return -1;
}
}
return 1;
}
unsigned char mailbox_key_r[IMAP_URLAUTH_KEY_LEN],
const char **error_r,
enum mail_error *error_code_r)
{
int ret;
ret = imap_urlauth_backend_trans_get_mailbox_key(box, create, mailbox_key_r, error_r, error_code_r);
return ret;
}
{
struct mailbox_transaction_context *t;
int ret;
__func__);
if (mailbox_transaction_commit(&t) < 0)
ret = -1;
return ret;
}
{
const char *errstr;
if (mailbox_open(box) < 0) {
return 0;
i_error("urlauth key reset: Couldn't open mailbox %s: %s",
return -1;
}
}
{
int ret = 0;
if (imap_urlauth_backend_mailbox_reset_key(box) < 0)
ret = -1;
mailbox_free(&box);
}
if (mailbox_list_iter_deinit(&iter) < 0) {
i_error("urlauth key reset: Couldn't iterate mailboxes: %s",
ret = -1;
}
return ret;
}