~ubuntu-dev/ubuntu/lucid/dovecot/lucid-201002101918

« back to all changes in this revision

Viewing changes to src/lib-storage/index/shared/shared-list.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:
 
1
/* Copyright (c) 2008-2009 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "lib.h"
 
4
#include "imap-match.h"
 
5
#include "mailbox-list-private.h"
 
6
#include "index-storage.h"
 
7
#include "shared-storage.h"
 
8
 
 
9
struct shared_mailbox_list_iterate_context {
 
10
        struct mailbox_list_iterate_context ctx;
 
11
        struct mail_namespace *cur_ns;
 
12
        struct imap_match_glob *glob;
 
13
        struct mailbox_info info;
 
14
};
 
15
 
 
16
extern struct mailbox_list shared_mailbox_list;
 
17
 
 
18
static struct mailbox_list *shared_list_alloc(void)
 
19
{
 
20
        struct mailbox_list *list;
 
21
        pool_t pool;
 
22
 
 
23
        pool = pool_alloconly_create("shared list", 1024);
 
24
        list = p_new(pool, struct mailbox_list, 1);
 
25
        *list = shared_mailbox_list;
 
26
        list->pool = pool;
 
27
        return list;
 
28
}
 
29
 
 
30
static void shared_list_deinit(struct mailbox_list *list)
 
31
{
 
32
        pool_unref(&list->pool);
 
33
}
 
34
 
 
35
static void shared_list_copy_error(struct mailbox_list *shared_list,
 
36
                                   struct mail_namespace *backend_ns)
 
37
{
 
38
        const char *str;
 
39
        enum mail_error error;
 
40
 
 
41
        str = mailbox_list_get_last_error(backend_ns->list, &error);
 
42
        mailbox_list_set_error(shared_list, error, str);
 
43
}
 
44
 
 
45
static int
 
46
shared_get_storage(struct mailbox_list *list, const char **name,
 
47
                   struct mail_storage **storage_r)
 
48
{
 
49
        struct mail_namespace *ns;
 
50
 
 
51
        if (shared_storage_get_namespace(list->ns->storage, name, &ns) < 0)
 
52
                return -1;
 
53
        *storage_r = ns->storage;
 
54
        return 0;
 
55
}
 
56
 
 
57
static bool
 
58
shared_is_valid_pattern(struct mailbox_list *list, const char *pattern)
 
59
{
 
60
        struct mail_namespace *ns;
 
61
 
 
62
        if (shared_storage_get_namespace(list->ns->storage, &pattern, &ns) < 0)
 
63
                return FALSE;
 
64
        return mailbox_list_is_valid_pattern(ns->list, pattern);
 
65
}
 
66
 
 
67
static bool
 
68
shared_is_valid_existing_name(struct mailbox_list *list, const char *name)
 
69
{
 
70
        struct mail_namespace *ns;
 
71
 
 
72
        if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
 
73
                return FALSE;
 
74
        return mailbox_list_is_valid_existing_name(ns->list, name);
 
75
}
 
76
 
 
77
static bool
 
78
shared_is_valid_create_name(struct mailbox_list *list, const char *name)
 
79
{
 
80
        struct mail_namespace *ns;
 
81
 
 
82
        if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
 
83
                return FALSE;
 
84
        return mailbox_list_is_valid_create_name(ns->list, name);
 
85
}
 
86
 
 
87
static const char *
 
88
shared_list_get_path(struct mailbox_list *list, const char *name,
 
89
                     enum mailbox_list_path_type type)
 
90
{
 
91
        struct mail_namespace *ns;
 
92
 
 
93
        if (list->ns->storage == NULL || name == NULL ||
 
94
            shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0) {
 
95
                switch (type) {
 
96
                case MAILBOX_LIST_PATH_TYPE_DIR:
 
97
                case MAILBOX_LIST_PATH_TYPE_MAILBOX:
 
98
                case MAILBOX_LIST_PATH_TYPE_CONTROL:
 
99
                        break;
 
100
                case MAILBOX_LIST_PATH_TYPE_INDEX:
 
101
                        /* we can safely say we don't use indexes */
 
102
                        return "";
 
103
                }
 
104
                /* we don't have a directory we can use. */
 
105
                return NULL;
 
106
        }
 
107
        return mailbox_list_get_path(ns->list, name, type);
 
108
}
 
109
 
 
110
static int
 
111
shared_list_get_mailbox_name_status(struct mailbox_list *list, const char *name,
 
112
                                    enum mailbox_name_status *status_r)
 
113
{
 
114
        struct mail_namespace *ns;
 
115
        int ret;
 
116
 
 
117
        if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
 
118
                return -1;
 
119
        ret = mailbox_list_get_mailbox_name_status(ns->list, name, status_r);
 
120
        if (ret < 0)
 
121
                shared_list_copy_error(list, ns);
 
122
        return ret;
 
123
}
 
124
 
 
125
static const char *
 
126
shared_list_get_temp_prefix(struct mailbox_list *list, bool global ATTR_UNUSED)
 
127
{
 
128
        i_panic("shared mailbox list: Can't return a temp prefix for '%s'",
 
129
                list->ns->prefix);
 
130
        return NULL;
 
131
}
 
132
 
 
133
static const char *
 
134
shared_list_join_refpattern(struct mailbox_list *list,
 
135
                            const char *ref, const char *pattern)
 
136
{
 
137
        struct mail_namespace *ns;
 
138
        const char *ns_ref, *prefix = list->ns->prefix;
 
139
        unsigned int prefix_len = strlen(prefix);
 
140
 
 
141
        if (*ref != '\0' && strncmp(ref, prefix, prefix_len) == 0)
 
142
                ns_ref = ref + prefix_len;
 
143
        else
 
144
                ns_ref = NULL;
 
145
 
 
146
        if (ns_ref != NULL &&
 
147
            shared_storage_get_namespace(list->ns->storage,
 
148
                                         &ns_ref, &ns) == 0)
 
149
                return mailbox_list_join_refpattern(ns->list, ns_ref, pattern);
 
150
 
 
151
        /* fallback to default behavior */
 
152
        if (*ref != '\0')
 
153
                pattern = t_strconcat(ref, pattern, NULL);
 
154
        return pattern;
 
155
}
 
156
 
 
157
static struct mailbox_list_iterate_context *
 
158
shared_list_iter_init(struct mailbox_list *list, const char *const *patterns,
 
159
                      enum mailbox_list_iter_flags flags)
 
160
{
 
161
        struct shared_mailbox_list_iterate_context *ctx;
 
162
 
 
163
        ctx = i_new(struct shared_mailbox_list_iterate_context, 1);
 
164
        ctx->ctx.list = list;
 
165
        ctx->ctx.flags = flags;
 
166
        ctx->cur_ns = list->ns->user->namespaces;
 
167
        ctx->info.ns = list->ns;
 
168
        ctx->info.flags = MAILBOX_NONEXISTENT;
 
169
        ctx->glob = imap_match_init_multiple(default_pool, patterns,
 
170
                                             FALSE, list->ns->sep);
 
171
        return &ctx->ctx;
 
172
}
 
173
 
 
174
static const struct mailbox_info *
 
175
shared_list_iter_next(struct mailbox_list_iterate_context *_ctx)
 
176
{
 
177
        struct shared_mailbox_list_iterate_context *ctx =
 
178
                (struct shared_mailbox_list_iterate_context *)_ctx;
 
179
        struct mail_namespace *ns = ctx->cur_ns;
 
180
 
 
181
        for (; ns != NULL; ns = ns->next) {
 
182
                if (ns->type != NAMESPACE_SHARED ||
 
183
                    (ns->flags & NAMESPACE_FLAG_AUTOCREATED) == 0)
 
184
                        continue;
 
185
                if ((ns->flags & (NAMESPACE_FLAG_LIST_PREFIX |
 
186
                                  NAMESPACE_FLAG_LIST_CHILDREN)) == 0)
 
187
                        continue;
 
188
 
 
189
                if (ns->prefix_len < ctx->info.ns->prefix_len ||
 
190
                    strncmp(ns->prefix, ctx->info.ns->prefix,
 
191
                            ctx->info.ns->prefix_len) != 0)
 
192
                        continue;
 
193
 
 
194
                /* visible and listable namespace under ourself, see if the
 
195
                   prefix matches without the trailing separator */
 
196
                i_assert(ns->prefix_len > 0);
 
197
                ctx->info.name = t_strndup(ns->prefix, ns->prefix_len - 1);
 
198
                if ((_ctx->flags & MAILBOX_LIST_ITER_VIRTUAL_NAMES) == 0)
 
199
                        ctx->info.name += ctx->info.ns->prefix_len;
 
200
                if (imap_match(ctx->glob, ctx->info.name) == IMAP_MATCH_YES) {
 
201
                        ctx->cur_ns = ns->next;
 
202
                        return &ctx->info;
 
203
                }
 
204
        }
 
205
 
 
206
        ctx->cur_ns = NULL;
 
207
        return NULL;
 
208
}
 
209
 
 
210
static int shared_list_iter_deinit(struct mailbox_list_iterate_context *_ctx)
 
211
{
 
212
        struct shared_mailbox_list_iterate_context *ctx =
 
213
                (struct shared_mailbox_list_iterate_context *)_ctx;
 
214
 
 
215
        imap_match_deinit(&ctx->glob);
 
216
        i_free(ctx);
 
217
        return 0;
 
218
}
 
219
 
 
220
static int shared_list_set_subscribed(struct mailbox_list *list,
 
221
                                      const char *name, bool set)
 
222
{
 
223
        struct mail_namespace *ns;
 
224
        int ret;
 
225
 
 
226
        if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
 
227
                return -1;
 
228
        ret = mailbox_list_set_subscribed(ns->list, name, set);
 
229
        if (ret < 0)
 
230
                shared_list_copy_error(list, ns);
 
231
        return ret;
 
232
}
 
233
 
 
234
static int
 
235
shared_list_delete_mailbox(struct mailbox_list *list, const char *name)
 
236
{
 
237
        struct mail_namespace *ns;
 
238
        int ret;
 
239
 
 
240
        if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
 
241
                return -1;
 
242
        ret = mailbox_list_delete_mailbox(ns->list, name);
 
243
        if (ret < 0)
 
244
                shared_list_copy_error(list, ns);
 
245
        return ret;
 
246
}
 
247
 
 
248
static int shared_list_rename_get_ns(struct mailbox_list *list,
 
249
                                     const char **oldname, const char **newname,
 
250
                                     struct mail_namespace **ns_r)
 
251
{
 
252
        struct mail_namespace *old_ns, *new_ns;
 
253
 
 
254
        if (shared_storage_get_namespace(list->ns->storage,
 
255
                                         oldname, &old_ns) < 0 ||
 
256
            shared_storage_get_namespace(list->ns->storage,
 
257
                                         newname, &new_ns) < 0)
 
258
                return -1;
 
259
        if (old_ns != new_ns) {
 
260
                mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE,
 
261
                        "Can't rename mailboxes across storages");
 
262
                return -1;
 
263
        }
 
264
        *ns_r = old_ns;
 
265
        return 0;
 
266
}
 
267
 
 
268
static int shared_list_rename_mailbox(struct mailbox_list *list,
 
269
                                      const char *oldname, const char *newname)
 
270
{
 
271
        struct mail_namespace *ns;
 
272
        int ret;
 
273
 
 
274
        if (shared_list_rename_get_ns(list, &oldname, &newname, &ns) < 0)
 
275
                return -1;
 
276
        ret = mailbox_list_rename_mailbox(ns->list, oldname, newname);
 
277
        if (ret < 0)
 
278
                shared_list_copy_error(list, ns);
 
279
        return ret;
 
280
}
 
281
 
 
282
static int
 
283
shared_list_rename_mailbox_pre(struct mailbox_list *list,
 
284
                               const char *oldname, const char *newname)
 
285
{
 
286
        struct mail_namespace *ns;
 
287
        int ret;
 
288
 
 
289
        if (shared_list_rename_get_ns(list, &oldname, &newname, &ns) < 0)
 
290
                return -1;
 
291
        ret = ns->list->v.rename_mailbox_pre(ns->list, oldname, newname);
 
292
        if (ret < 0)
 
293
                shared_list_copy_error(list, ns);
 
294
        return ret;
 
295
}
 
296
 
 
297
struct mailbox_list shared_mailbox_list = {
 
298
        MEMBER(name) "shared",
 
299
        MEMBER(hierarchy_sep) '/',
 
300
        MEMBER(props) 0,
 
301
        MEMBER(mailbox_name_max_length) PATH_MAX,
 
302
 
 
303
        {
 
304
                shared_list_alloc,
 
305
                shared_list_deinit,
 
306
                shared_get_storage,
 
307
                shared_is_valid_pattern,
 
308
                shared_is_valid_existing_name,
 
309
                shared_is_valid_create_name,
 
310
                shared_list_get_path,
 
311
                shared_list_get_mailbox_name_status,
 
312
                shared_list_get_temp_prefix,
 
313
                shared_list_join_refpattern,
 
314
                shared_list_iter_init,
 
315
                shared_list_iter_next,
 
316
                shared_list_iter_deinit,
 
317
                NULL,
 
318
                shared_list_set_subscribed,
 
319
                shared_list_delete_mailbox,
 
320
                shared_list_rename_mailbox,
 
321
                shared_list_rename_mailbox_pre
 
322
        }
 
323
};