~ubuntu-branches/ubuntu/utopic/dovecot/utopic-proposed

« back to all changes in this revision

Viewing changes to src/imap/cmd-resetkey.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "imap-common.h"
 
4
#include "imap-resp-code.h"
 
5
#include "imap-commands.h"
 
6
#include "imap-urlauth.h"
 
7
 
 
8
static bool cmd_resetkey_all(struct client_command_context *cmd)
 
9
{
 
10
        if (imap_urlauth_reset_all_keys(cmd->client->urlauth_ctx) < 0) {
 
11
                client_send_internal_error(cmd);
 
12
                return TRUE;
 
13
        }
 
14
 
 
15
        client_send_tagline(cmd, "OK All keys removed.");
 
16
        return TRUE;
 
17
}
 
18
 
 
19
static bool
 
20
cmd_resetkey_mailbox(struct client_command_context *cmd,
 
21
                     const char *mailbox, const struct imap_arg *mech_args)
 
22
{
 
23
        struct mail_namespace *ns;
 
24
        enum mailbox_flags flags = MAILBOX_FLAG_READONLY;
 
25
        struct mailbox *box;
 
26
 
 
27
        /* check mechanism arguments (we support only INTERNAL mechanism) */
 
28
        while (!IMAP_ARG_IS_EOL(mech_args)) {
 
29
                const char *mechanism;
 
30
 
 
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.");
 
35
                                return TRUE;
 
36
                        }
 
37
                } else {
 
38
                        client_send_command_error(cmd, "Invalid arguments.");
 
39
                        return TRUE;
 
40
                }
 
41
 
 
42
                mech_args++;
 
43
        }
 
44
 
 
45
        /* find mailbox namespace */
 
46
        ns = client_find_namespace(cmd, &mailbox);
 
47
        if (ns == NULL)
 
48
                return TRUE;
 
49
 
 
50
        /* open 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));
 
54
                mailbox_free(&box);
 
55
                return TRUE;
 
56
        }
 
57
 
 
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);
 
61
                mailbox_free(&box);
 
62
                return TRUE;
 
63
        }
 
64
 
 
65
        /* confirm success */
 
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
 
70
           index. */
 
71
        client_send_tagline(cmd, "OK [URLMECH INTERNAL] Key removed.");
 
72
        mailbox_free(&box);
 
73
        return TRUE;
 
74
}
 
75
 
 
76
bool cmd_resetkey(struct client_command_context *cmd)
 
77
{
 
78
        const struct imap_arg *args;
 
79
        const char *mailbox;
 
80
 
 
81
        if (cmd->client->urlauth_ctx == NULL) {
 
82
                client_send_command_error(cmd, "URLAUTH disabled.");
 
83
                return TRUE;
 
84
        }
 
85
 
 
86
        if (!client_read_args(cmd, 0, 0, &args))
 
87
                return FALSE;
 
88
 
 
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]);
 
93
 
 
94
        client_send_command_error(cmd, "Invalid arguments.");
 
95
        return TRUE;
 
96
}