bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschstatic bool cmd_resetkey_all(struct client_command_context *cmd)
fd81c8f5a38df19d1ecdfd5d6605b114ab56841eTimo Sirainen if (imap_urlauth_reset_all_keys(cmd->client->urlauth_ctx) < 0) {
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch client_send_tagline(cmd, "OK All keys removed.");
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschcmd_resetkey_mailbox(struct client_command_context *cmd,
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch const char *mailbox, const struct imap_arg *mech_args)
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch enum mailbox_flags flags = MAILBOX_FLAG_READONLY;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch /* check mechanism arguments (we support only INTERNAL mechanism) */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch if (imap_arg_get_astring(mech_args, &mechanism)) {
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch "NO Unsupported URLAUTH mechanism.");
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch client_send_command_error(cmd, "Invalid arguments.");
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch /* find mailbox namespace */
005eb7a9e93a8799dd00341df9e06938371e644aTimo Sirainen /* open mailbox */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch box = mailbox_alloc(ns->list, mailbox, flags);
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch /* check urlauth environment and reset requested key */
fd81c8f5a38df19d1ecdfd5d6605b114ab56841eTimo Sirainen if (imap_urlauth_reset_mailbox_key(cmd->client->urlauth_ctx, box) < 0) {
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch /* confirm success */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch /* FIXME: RFC Says: `Any current IMAP session logged in as the user
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch that has the mailbox selected will receive an untagged OK response
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch with the URLMECH status response code'. We currently don't do that
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch at all. We could probably do it by communicating via mailbox list
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch client_send_tagline(cmd, "OK [URLMECH INTERNAL] Key removed.");
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschbool cmd_resetkey(struct client_command_context *cmd)
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch client_send_command_error(cmd, "URLAUTH disabled.");
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch else if (imap_arg_get_astring(&args[0], &mailbox))
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch return cmd_resetkey_mailbox(cmd, mailbox, &args[1]);
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch client_send_command_error(cmd, "Invalid arguments.");