~james-page/ubuntu/raring/dovecot/autopkgtest

« back to all changes in this revision

Viewing changes to src/plugins/virtual/virtual-config.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 11:11:54 UTC
  • mfrom: (1.15.2) (4.1.27 sid)
  • Revision ID: package-import@ubuntu.com-20120611111154-678cwbdj6ktgsv1h
Tags: 1:2.1.7-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/{control,rules}: enable PIE hardening.
  + 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.
  + d/control: Added Pre-Depends: dpkg (>= 1.15.6) to dovecot-dbg to support
    xz compression in Ubuntu.
  + d/control: Demote dovecot-common Recommends: to Suggests: to prevent
    install of extra packages on upgrade.
  + d/patches/dovecot-drac.patch: Updated with version for dovecot >= 2.0.0.
  + d/control: Drop B-D on systemd.
* Dropped changes:
  + d/patches/fix-racey-restart.patch: part of 2.1.x, no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2008-2011 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2008-2012 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "array.h"
5
5
#include "crc32.h"
6
6
#include "istream.h"
7
7
#include "str.h"
 
8
#include "unichar.h"
8
9
#include "imap-parser.h"
9
10
#include "imap-match.h"
10
11
#include "mail-namespace.h"
36
37
        const struct imap_arg *args;
37
38
        struct mail_search_parser *parser;
38
39
        struct mail_search_args *sargs;
 
40
        const char *charset = "UTF-8";
39
41
        bool fatal;
40
42
        int ret;
41
43
 
56
58
        } else {
57
59
                parser = mail_search_parser_init_imap(args);
58
60
                if (mail_search_build(mail_search_register_get_imap(),
59
 
                                      parser, "UTF-8", &sargs, error_r) < 0)
 
61
                                      parser, &charset, &sargs, error_r) < 0)
60
62
                        sargs = NULL;
61
63
                mail_search_parser_deinit(&parser);
62
64
        }
63
65
 
64
 
        imap_parser_destroy(&imap_parser);
 
66
        imap_parser_unref(&imap_parser);
65
67
        i_stream_destroy(&input);
66
68
        return sargs;
67
69
}
137
139
        if (*line == '-' || *line == '+' || *line == '!') line++;
138
140
        bbox->ns = strcasecmp(line, "INBOX") == 0 ?
139
141
                mail_namespace_find_inbox(user->namespaces) :
140
 
                mail_namespace_find(user->namespaces, &line);
 
142
                mail_namespace_find(user->namespaces, line);
 
143
        if (!uni_utf8_str_is_valid(bbox->name)) {
 
144
                *error_r = t_strdup_printf("Mailbox name not UTF-8: %s",
 
145
                                           bbox->name);
 
146
                return -1;
 
147
        }
141
148
        if (bbox->ns == NULL) {
142
149
                *error_r = t_strdup_printf("Namespace not found for %s",
143
150
                                           bbox->name);
238
245
        array_append(&ctx->mbox->backend_boxes, &bbox, 1);
239
246
}
240
247
 
 
248
static bool virtual_ns_match(struct mail_namespace *config_ns,
 
249
                             struct mail_namespace *iter_ns)
 
250
{
 
251
        /* we match only one namespace for each pattern, except with shared
 
252
           namespaces match also autocreated children */
 
253
        if (config_ns == iter_ns)
 
254
                return TRUE;
 
255
        if (config_ns->type == iter_ns->type &&
 
256
            (config_ns->flags & NAMESPACE_FLAG_AUTOCREATED) == 0 &&
 
257
            (iter_ns->flags & NAMESPACE_FLAG_AUTOCREATED) != 0)
 
258
                return TRUE;
 
259
        return FALSE;
 
260
}
 
261
 
241
262
static bool virtual_config_match(const struct mailbox_info *info,
242
263
                                 ARRAY_TYPE(virtual_backend_box) *boxes_arr,
243
264
                                 unsigned int *idx_r)
248
269
        boxes = array_get_modifiable(boxes_arr, &count);
249
270
        for (i = 0; i < count; i++) {
250
271
                if (boxes[i]->glob != NULL) {
251
 
                        /* we match only one namespace for each pattern. */
252
 
                        if (boxes[i]->ns == info->ns &&
 
272
                        if (virtual_ns_match(boxes[i]->ns, info->ns) &&
253
273
                            imap_match(boxes[i]->glob,
254
274
                                       info->name) == IMAP_MATCH_YES) {
255
275
                                *idx_r = i;
334
354
        struct mail_storage *storage = mbox->box.storage;
335
355
        struct virtual_parse_context ctx;
336
356
        struct stat st;
337
 
        const char *path, *line, *error;
 
357
        const char *box_path, *path, *line, *error;
338
358
        unsigned int linenum = 0;
339
359
        int fd, ret = 0;
340
360
 
341
361
        i_array_init(&mbox->backend_boxes, 8);
342
362
        mbox->search_args_crc32 = (uint32_t)-1;
343
363
 
344
 
        path = t_strconcat(mbox->box.path, "/"VIRTUAL_CONFIG_FNAME, NULL);
 
364
        box_path = mailbox_get_path(&mbox->box);
 
365
        path = t_strconcat(box_path, "/"VIRTUAL_CONFIG_FNAME, NULL);
345
366
        fd = open(path, O_RDONLY);
346
367
        if (fd == -1) {
347
368
                if (errno == EACCES) {
348
369
                        mail_storage_set_critical(storage, "%s",
349
 
                                mail_error_eacces_msg("stat", mbox->box.path));
 
370
                                mail_error_eacces_msg("open", path));
350
371
                } else if (errno != ENOENT) {
351
372
                        mail_storage_set_critical(storage,
352
373
                                                  "open(%s) failed: %m", path);
353
 
                } else if (stat(mbox->box.path, &st) == 0) {
 
374
                } else if (stat(box_path, &st) == 0) {
354
375
                        mail_storage_set_error(storage, MAIL_ERROR_NOTPOSSIBLE,
355
376
                                "Virtual mailbox missing configuration file");
356
377
                } else if (errno == ENOENT) {
358
379
                                T_MAIL_ERR_MAILBOX_NOT_FOUND(mbox->box.name));
359
380
                } else {
360
381
                        mail_storage_set_critical(storage,
361
 
                                "stat(%s) failed: %m", mbox->box.path);
 
382
                                "stat(%s) failed: %m", box_path);
362
383
                }
363
384
                return -1;
364
385
        }