~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/imap/commands-util.c

  • Committer: Bazaar Package Importer
  • Author(s): CHuck Short, Chuck Short
  • Date: 2009-11-06 00:47:29 UTC
  • mfrom: (4.1.9 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091106004729-i39n7v9e7d4h51f6
Tags: 1:1.2.6-1ubuntu1
* Merge from debian testing, remaining changes:
  Add new binary pkg dovecot-postfix that integrates postfix and dovecot
  automatically: (LP: #164837)
  + debian/control:
    - add new binary with short description
    - set Architecture all for dovecot-postfix (LP: #329878)
  + debian/dovecot-postfix.postinst:
    - create initial certificate symlinks to snakeoil.
    - set up postfix with postconf to:
      - use Maildir/ as the default mailbox.
      - use dovecot as the sasl authentication server.
      - use dovecot LDA (deliver).
      - use tls for smtp{d} services.
    - fix certificates paths in postfix' main.cf
    - add reject_unauth_destination to postfix' recipient restrictions
    - add reject_unknown_sender_domain to postfix' sender restrictions
    - rename configuration name on remove, delete on purge
    - restart dovecot after linking certificates
    - handle use case when postfix is unconfigurated
   + debian/dovecot-postfix.dirs: create backup directory for postfix's configuration
   + restart postfix and dovecot.
   + debian/dovecot-postfix.postrm:
     - remove all dovecot related configuration from postfix.
     - restart postfix and dovecot.
   + debian/dovecot-common.init:
     - check if /etc/dovecot/dovecot-postfix.conf exists and use it
       as the configuration file if so.
   + debian/patches/warning-ubuntu-postfix.dpatch
     - add warning about dovecot-postfix.conf in dovecot default 
       configuration file
   + debian/patches/dovecot-postfix.conf.diff:
     - Ubuntu server custom changes to the default dovecot configuration for
       better interfation with postfix
     - enable sieve plugin
   + debian/patches/dovecot-postfix.conf.diff:
     + Ubuntu server custom changes to the default dovecot configuration for
       better integration with postfix:
       - enable imap, pop3, imaps, pop3s and managesieve by default.
       - enable dovecot LDA (deliver).
       - enable SASL auth socket in postfix private directory.
   + debian/rules:
     - copy, patch and install dovecot-postfix.conf in /etc/dovecot/.
     - build architecure independent packages too
   + Use Snakeoil SSL certificates by default.
     - debian/control: Depend on ssl-cert.
     - debian/patches/ssl-cert-snakeoil.dpatch: Change default SSL cert
       paths to snakeoil.
     - debian/dovecot-common.postinst: Relax grep for SSL_* a bit.
   + Add autopkgtest to debian/tests/*.
   + Fast TearDown: Update the lsb init header to not stop in level 6.
   + Add ufw integration:
     - Created debian/dovecot-common.ufw.profile.
     - debian/rules:
       + install profile
     - debian/control:
       + Suggest ufw
   + debian/{control,rules}: enable PIE hardening.
   + dovecot-imapd, dovecot-pop3: Replaces dovecot-common (<< 1:1.1). LP: #254721
   + debian/control:
     - Update Vcs-* headers.
   + debian/rules:
     - Create emtpy stamp.h.in files in dovecot-sieve/ and dovecot-managesieve/
       if they're not there since empty files are not included in the diff.gz 
       file.
   + Add SMTP-AUTH support for Outlook (login auth mechanism)
   + Dropped:
     - debian/patches/security-CVE-2009-3235: Applied upstream.
     - debian/patches/fix-pop3-assertion.dpatch: Applied upstream.
     - dovecot-sieve and dovecot-managesieve: Use the debian patches instead.

  [Chuck Short]
  - Updated dovecot-sieve to 0.1.13.
  - Updated dovecot-managesieve to 0.11.9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#include "buffer.h"
6
6
#include "str.h"
7
7
#include "str-sanitize.h"
8
 
#include "mail-storage.h"
9
 
#include "commands-util.h"
 
8
#include "imap-resp-code.h"
10
9
#include "imap-parser.h"
11
10
#include "imap-sync.h"
12
11
#include "imap-util.h"
 
12
#include "mail-storage.h"
13
13
#include "mail-namespace.h"
 
14
#include "commands-util.h"
14
15
 
15
16
/* Maximum length for mailbox name, including it's path. This isn't fully
16
17
   exact since the user can create folder hierarchy with small names, then
23
24
{
24
25
        struct mail_namespace *ns;
25
26
 
26
 
        ns = mail_namespace_find(cmd->client->namespaces, mailbox);
 
27
        ns = mail_namespace_find(cmd->client->user->namespaces, mailbox);
27
28
        if (ns != NULL)
28
29
                return ns;
29
30
 
36
37
{
37
38
        struct mail_namespace *ns;
38
39
 
 
40
        if (!client_verify_mailbox_name(cmd, *mailbox,
 
41
                                        CLIENT_VERIFY_MAILBOX_NAME))
 
42
                return NULL;
 
43
 
39
44
        ns = client_find_namespace(cmd, mailbox);
40
 
        return ns == NULL ? NULL : ns->storage;
 
45
        if (ns == NULL)
 
46
                return NULL;
 
47
 
 
48
        return ns->storage;
41
49
}
42
50
 
43
51
bool client_verify_mailbox_name(struct client_command_context *cmd,
44
52
                                const char *mailbox,
45
 
                                bool should_exist, bool should_not_exist)
 
53
                                enum client_verify_mailbox_mode mode)
46
54
{
47
55
        struct mail_namespace *ns;
48
56
        struct mailbox_list *list;
49
57
        enum mailbox_name_status mailbox_status;
50
 
        const char *orig_mailbox, *p;
 
58
        const char *orig_mailbox, *p, *resp_code;
51
59
 
52
60
        orig_mailbox = mailbox;
53
61
        ns = client_find_namespace(cmd, &mailbox);
55
63
                return FALSE;
56
64
 
57
65
        /* make sure it even looks valid */
58
 
        if (*mailbox == '\0') {
 
66
        if (*mailbox == '\0' && !(*orig_mailbox != '\0' && ns->list)) {
59
67
                client_send_tagline(cmd, "NO Empty mailbox name.");
60
68
                return FALSE;
61
69
        }
90
98
 
91
99
        /* check what our storage thinks of it */
92
100
        list = mail_storage_get_list(ns->storage);
93
 
        if (mailbox_list_get_mailbox_name_status(list, mailbox,
94
 
                                                 &mailbox_status) < 0) {
95
 
                client_send_storage_error(cmd, ns->storage);
 
101
        if (mode == CLIENT_VERIFY_MAILBOX_NAME) {
 
102
                mailbox_status =
 
103
                        mailbox_list_is_valid_existing_name(list, mailbox) ?
 
104
                        MAILBOX_NAME_VALID : MAILBOX_NAME_INVALID;
 
105
        } else if (mailbox_list_get_mailbox_name_status(list, mailbox,
 
106
                                                        &mailbox_status) < 0) {
 
107
                client_send_list_error(cmd, list);
96
108
                return FALSE;
97
109
        }
98
110
 
99
111
        switch (mailbox_status) {
100
112
        case MAILBOX_NAME_EXISTS:
101
 
                if (should_exist || !should_not_exist)
102
 
                        return TRUE;
103
 
 
104
 
                client_send_tagline(cmd, "NO Mailbox exists.");
 
113
                switch (mode) {
 
114
                case CLIENT_VERIFY_MAILBOX_NAME:
 
115
                case CLIENT_VERIFY_MAILBOX_SHOULD_EXIST:
 
116
                case CLIENT_VERIFY_MAILBOX_SHOULD_EXIST_TRYCREATE:
 
117
                        return TRUE;
 
118
                case CLIENT_VERIFY_MAILBOX_SHOULD_NOT_EXIST:
 
119
                        break;
 
120
                }
 
121
 
 
122
                if (mode == CLIENT_VERIFY_MAILBOX_NAME ||
 
123
                    mode == CLIENT_VERIFY_MAILBOX_SHOULD_EXIST)
 
124
                        return TRUE;
 
125
 
 
126
                client_send_tagline(cmd, t_strconcat(
 
127
                        "NO [", IMAP_RESP_CODE_ALREADYEXISTS,
 
128
                        "] Mailbox exists.", NULL));
105
129
                break;
106
130
 
107
131
        case MAILBOX_NAME_VALID:
108
 
                if (!should_exist)
 
132
                switch (mode) {
 
133
                case CLIENT_VERIFY_MAILBOX_NAME:
 
134
                case CLIENT_VERIFY_MAILBOX_SHOULD_NOT_EXIST:
109
135
                        return TRUE;
 
136
                case CLIENT_VERIFY_MAILBOX_SHOULD_EXIST:
 
137
                        resp_code = IMAP_RESP_CODE_NONEXISTENT;
 
138
                        break;
 
139
                case CLIENT_VERIFY_MAILBOX_SHOULD_EXIST_TRYCREATE:
 
140
                        resp_code = "TRYCREATE";
 
141
                        break;
 
142
                default:
 
143
                        resp_code = NULL;
 
144
                        i_unreached();
 
145
                }
110
146
 
111
147
                client_send_tagline(cmd, t_strconcat(
112
 
                        "NO [TRYCREATE] Mailbox doesn't exist: ",
 
148
                        "NO [", resp_code, "] Mailbox doesn't exist: ",
113
149
                        str_sanitize(orig_mailbox, MAILBOX_MAX_NAME_LEN),
114
150
                        NULL));
115
151
                break;
143
179
        }
144
180
}
145
181
 
 
182
static const char *
 
183
get_error_string(const char *error_string, enum mail_error error)
 
184
{
 
185
        const char *resp_code = NULL;
 
186
 
 
187
        switch (error) {
 
188
        case MAIL_ERROR_NONE:
 
189
                break;
 
190
        case MAIL_ERROR_TEMP:
 
191
                resp_code = IMAP_RESP_CODE_SERVERBUG;
 
192
                break;
 
193
        case MAIL_ERROR_NOTPOSSIBLE:
 
194
        case MAIL_ERROR_PARAMS:
 
195
                resp_code = IMAP_RESP_CODE_CANNOT;
 
196
                break;
 
197
        case MAIL_ERROR_PERM:
 
198
                resp_code = IMAP_RESP_CODE_NOPERM;
 
199
                break;
 
200
        case MAIL_ERROR_NOSPACE:
 
201
                resp_code = IMAP_RESP_CODE_OVERQUOTA;
 
202
                break;
 
203
        case MAIL_ERROR_NOTFOUND:
 
204
                resp_code = IMAP_RESP_CODE_NONEXISTENT;
 
205
                break;
 
206
        case MAIL_ERROR_EXISTS:
 
207
                resp_code = IMAP_RESP_CODE_ALREADYEXISTS;
 
208
                break;
 
209
        case MAIL_ERROR_EXPUNGED:
 
210
                resp_code = IMAP_RESP_CODE_EXPUNGEISSUED;
 
211
                break;
 
212
        case MAIL_ERROR_INUSE:
 
213
                resp_code = IMAP_RESP_CODE_INUSE;
 
214
                break;
 
215
        }
 
216
        if (resp_code == NULL || *error_string == '[')
 
217
                return t_strconcat("NO ", error_string, NULL);
 
218
        else
 
219
                return t_strdup_printf("NO [%s] %s", resp_code, error_string);
 
220
}
 
221
 
146
222
void client_send_list_error(struct client_command_context *cmd,
147
223
                            struct mailbox_list *list)
148
224
{
150
226
        enum mail_error error;
151
227
 
152
228
        error_string = mailbox_list_get_last_error(list, &error);
153
 
        client_send_tagline(cmd, t_strconcat("NO ", error_string, NULL));
 
229
        client_send_tagline(cmd, get_error_string(error_string, error));
154
230
}
155
231
 
156
232
void client_send_storage_error(struct client_command_context *cmd,
168
244
        }
169
245
 
170
246
        error_string = mail_storage_get_last_error(storage, &error);
171
 
        client_send_tagline(cmd, t_strconcat("NO ", error_string, NULL));
 
247
        client_send_tagline(cmd, get_error_string(error_string, error));
172
248
}
173
249
 
174
250
void client_send_untagged_storage_error(struct client *client,
321
397
        return array_idx(dest, 0);
322
398
}
323
399
 
324
 
bool mailbox_equals(struct mailbox *box1, struct mail_storage *storage2,
325
 
                    const char *name2)
 
400
bool mailbox_equals(const struct mailbox *box1,
 
401
                    const struct mail_storage *storage2, const char *name2)
326
402
{
327
403
        struct mail_storage *storage1 = mailbox_get_storage(box1);
328
404
        const char *name1;