1
/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
3
#include "imap-common.h"
4
#include "imap-resp-code.h"
5
#include "imap-commands.h"
6
#include "imap-urlauth.h"
8
static bool cmd_resetkey_all(struct client_command_context *cmd)
10
if (imap_urlauth_reset_all_keys(cmd->client->urlauth_ctx) < 0) {
11
client_send_internal_error(cmd);
15
client_send_tagline(cmd, "OK All keys removed.");
20
cmd_resetkey_mailbox(struct client_command_context *cmd,
21
const char *mailbox, const struct imap_arg *mech_args)
23
struct mail_namespace *ns;
24
enum mailbox_flags flags = MAILBOX_FLAG_READONLY;
27
/* check mechanism arguments (we support only INTERNAL mechanism) */
28
while (!IMAP_ARG_IS_EOL(mech_args)) {
29
const char *mechanism;
31
if (imap_arg_get_astring(mech_args, &mechanism)) {
32
if (strcasecmp(mechanism, "INTERNAL") != 0) {
33
client_send_tagline(cmd,
34
"NO Unsupported URLAUTH mechanism.");
38
client_send_command_error(cmd, "Invalid arguments.");
45
/* find mailbox namespace */
46
ns = client_find_namespace(cmd, &mailbox);
51
box = mailbox_alloc(ns->list, mailbox, flags);
52
if (mailbox_open(box) < 0) {
53
client_send_storage_error(cmd, mailbox_get_storage(box));
58
/* check urlauth environment and reset requested key */
59
if (imap_urlauth_reset_mailbox_key(cmd->client->urlauth_ctx, box) < 0) {
60
client_send_internal_error(cmd);
66
/* FIXME: RFC Says: `Any current IMAP session logged in as the user
67
that has the mailbox selected will receive an untagged OK response
68
with the URLMECH status response code'. We currently don't do that
69
at all. We could probably do it by communicating via mailbox list
71
client_send_tagline(cmd, "OK [URLMECH INTERNAL] Key removed.");
76
bool cmd_resetkey(struct client_command_context *cmd)
78
const struct imap_arg *args;
81
if (cmd->client->urlauth_ctx == NULL) {
82
client_send_command_error(cmd, "URLAUTH disabled.");
86
if (!client_read_args(cmd, 0, 0, &args))
89
if (IMAP_ARG_IS_EOL(&args[0]))
90
return cmd_resetkey_all(cmd);
91
else if (imap_arg_get_astring(&args[0], &mailbox))
92
return cmd_resetkey_mailbox(cmd, mailbox, &args[1]);
94
client_send_command_error(cmd, "Invalid arguments.");