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

« back to all changes in this revision

Viewing changes to src/plugins/fts/doveadm-fts.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) 2011-2012 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "lib.h"
 
4
#include "mail-namespace.h"
 
5
#include "fts-storage.h"
 
6
#include "doveadm-mail.h"
 
7
#include "doveadm-fts.h"
 
8
 
 
9
const char *doveadm_fts_plugin_version = DOVECOT_VERSION;
 
10
 
 
11
static int
 
12
fts_namespace_find(struct mail_user *user, const char *ns_prefix,
 
13
                   struct mail_namespace **ns_r)
 
14
{
 
15
        struct mail_namespace *ns;
 
16
 
 
17
        if (ns_prefix == NULL)
 
18
                ns = mail_namespace_find_inbox(user->namespaces);
 
19
        else {
 
20
                ns = mail_namespace_find_prefix(user->namespaces, ns_prefix);
 
21
                if (ns == NULL) {
 
22
                        i_error("Namespace prefix not found: %s", ns_prefix);
 
23
                        return -1;
 
24
                }
 
25
        }
 
26
 
 
27
        if (fts_list_backend(ns->list) == NULL) {
 
28
                i_error("fts not enabled for user's namespace %s", ns_prefix);
 
29
                return -1;
 
30
        }
 
31
        *ns_r = ns;
 
32
        return 0;
 
33
}
 
34
 
 
35
static int
 
36
cmd_fts_optimize_run(struct doveadm_mail_cmd_context *ctx,
 
37
                     struct mail_user *user)
 
38
{
 
39
        const char *ns_prefix = ctx->args[0];
 
40
        struct mail_namespace *ns;
 
41
        struct fts_backend *backend;
 
42
 
 
43
        if (fts_namespace_find(user, ns_prefix, &ns) < 0) {
 
44
                doveadm_mail_failed_error(ctx, MAIL_ERROR_NOTFOUND);
 
45
                return -1;
 
46
        }
 
47
        backend = fts_list_backend(ns->list);
 
48
        if (fts_backend_optimize(backend) < 0) {
 
49
                i_error("fts optimize failed");
 
50
                doveadm_mail_failed_error(ctx, MAIL_ERROR_TEMP);
 
51
                return -1;
 
52
        }
 
53
        return 0;
 
54
}
 
55
 
 
56
static void
 
57
cmd_fts_optimize_init(struct doveadm_mail_cmd_context *ctx ATTR_UNUSED,
 
58
                      const char *const args[])
 
59
{
 
60
        if (str_array_length(args) > 1)
 
61
                doveadm_mail_help_name("fts optimize");
 
62
}
 
63
 
 
64
static struct doveadm_mail_cmd_context *
 
65
cmd_fts_optimize_alloc(void)
 
66
{
 
67
        struct doveadm_mail_cmd_context *ctx;
 
68
 
 
69
        ctx = doveadm_mail_cmd_alloc(struct doveadm_mail_cmd_context);
 
70
        ctx->v.run = cmd_fts_optimize_run;
 
71
        ctx->v.init = cmd_fts_optimize_init;
 
72
        return ctx;
 
73
}
 
74
 
 
75
static int
 
76
cmd_fts_rescan_run(struct doveadm_mail_cmd_context *ctx, struct mail_user *user)
 
77
{
 
78
        const char *ns_prefix = ctx->args[0];
 
79
        struct mail_namespace *ns;
 
80
        struct fts_backend *backend;
 
81
 
 
82
        if (fts_namespace_find(user, ns_prefix, &ns) < 0) {
 
83
                doveadm_mail_failed_error(ctx, MAIL_ERROR_NOTFOUND);
 
84
                return -1;
 
85
        }
 
86
        backend = fts_list_backend(ns->list);
 
87
        if (fts_backend_rescan(backend) < 0) {
 
88
                i_error("fts rescan failed");
 
89
                doveadm_mail_failed_error(ctx, MAIL_ERROR_TEMP);
 
90
                return -1;
 
91
        }
 
92
        return 0;
 
93
}
 
94
 
 
95
static void
 
96
cmd_fts_rescan_init(struct doveadm_mail_cmd_context *ctx ATTR_UNUSED,
 
97
                    const char *const args[])
 
98
{
 
99
        if (str_array_length(args) > 1)
 
100
                doveadm_mail_help_name("fts rescan");
 
101
}
 
102
 
 
103
static struct doveadm_mail_cmd_context *
 
104
cmd_fts_rescan_alloc(void)
 
105
{
 
106
        struct doveadm_mail_cmd_context *ctx;
 
107
 
 
108
        ctx = doveadm_mail_cmd_alloc(struct doveadm_mail_cmd_context);
 
109
        ctx->v.run = cmd_fts_rescan_run;
 
110
        ctx->v.init = cmd_fts_rescan_init;
 
111
        return ctx;
 
112
}
 
113
 
 
114
static struct doveadm_mail_cmd fts_commands[] = {
 
115
        { cmd_fts_optimize_alloc, "fts optimize", "[<namespace>]" },
 
116
        { cmd_fts_rescan_alloc, "fts rescan", "[<namespace>]" }
 
117
};
 
118
 
 
119
void doveadm_fts_plugin_init(struct module *module ATTR_UNUSED)
 
120
{
 
121
        unsigned int i;
 
122
 
 
123
        for (i = 0; i < N_ELEMENTS(fts_commands); i++)
 
124
                doveadm_mail_register_cmd(&fts_commands[i]);
 
125
        doveadm_dump_fts_expunge_log_init();
 
126
}
 
127
 
 
128
void doveadm_fts_plugin_deinit(void)
 
129
{
 
130
}