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

« back to all changes in this revision

Viewing changes to src/lib-storage/index/dbox-common/dbox-storage.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) 2007-2011 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2007-2012 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "ioloop.h"
21
21
                set->layout = MAILBOX_LIST_NAME_FS;
22
22
        if (set->subscription_fname == NULL)
23
23
                set->subscription_fname = DBOX_SUBSCRIPTION_FILE_NAME;
24
 
        if (set->maildir_name == NULL)
 
24
        if (*set->maildir_name == '\0')
25
25
                set->maildir_name = DBOX_MAILDIR_NAME;
26
 
        if (set->mailbox_dir_name == NULL)
 
26
        if (*set->mailbox_dir_name == '\0')
27
27
                set->mailbox_dir_name = DBOX_MAILBOX_DIR_NAME;
28
28
}
29
29
 
 
30
static bool
 
31
dbox_alt_path_has_changed(const char *root_dir,
 
32
                          const char *alt_path, const char *alt_symlink_path)
 
33
{
 
34
        char buf[PATH_MAX];
 
35
        ssize_t ret;
 
36
 
 
37
        ret = readlink(alt_symlink_path, buf, sizeof(buf)-1);
 
38
        if (ret < 0) {
 
39
                if (errno == ENOENT)
 
40
                        return alt_path != NULL;
 
41
                i_error("readlink(%s) failed: %m", alt_symlink_path);
 
42
                return FALSE;
 
43
        }
 
44
        buf[ret] = '\0';
 
45
 
 
46
        if (alt_path == NULL) {
 
47
                i_warning("dbox %s: Original ALT=%s, "
 
48
                          "but currently no ALT path set", root_dir, buf);
 
49
                return TRUE;
 
50
        } else if (strcmp(buf, alt_path) != 0) {
 
51
                i_warning("dbox %s: Original ALT=%s, "
 
52
                          "but currently ALT=%s", root_dir, buf, alt_path);
 
53
                return TRUE;
 
54
        }
 
55
        return FALSE;
 
56
}
 
57
 
 
58
static void dbox_verify_alt_path(struct mailbox_list *list)
 
59
{
 
60
        const char *root_dir, *alt_symlink_path, *alt_path;
 
61
 
 
62
        root_dir = mailbox_list_get_path(list, NULL,
 
63
                                         MAILBOX_LIST_PATH_TYPE_DIR);
 
64
        alt_symlink_path =
 
65
                t_strconcat(root_dir, "/"DBOX_ALT_SYMLINK_NAME, NULL);
 
66
        alt_path = mailbox_list_get_path(list, NULL,
 
67
                                         MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX);
 
68
        if (!dbox_alt_path_has_changed(root_dir, alt_path, alt_symlink_path))
 
69
                return;
 
70
 
 
71
        /* unlink/create the current alt path symlink */
 
72
        if (unlink(alt_symlink_path) < 0 && errno != ENOENT)
 
73
                i_error("unlink(%s) failed: %m", alt_symlink_path);
 
74
        if (alt_path != NULL) {
 
75
                if (symlink(alt_path, alt_symlink_path) < 0 &&
 
76
                    errno != EEXIST) {
 
77
                        i_error("symlink(%s, %s) failed: %m",
 
78
                                alt_path, alt_symlink_path);
 
79
                }
 
80
        }
 
81
}
 
82
 
30
83
int dbox_storage_create(struct mail_storage *_storage,
31
84
                        struct mail_namespace *ns,
32
85
                        const char **error_r ATTR_UNUSED)
53
106
                storage->attachment_dir = p_strdup(_storage->pool, dir);
54
107
                storage->attachment_fs = fs_init(name, args, &fs_set);
55
108
        } T_END;
 
109
 
 
110
        dbox_verify_alt_path(ns->list);
56
111
        return 0;
57
112
}
58
113
 
92
147
dbox_cleanup_if_exists(struct mailbox_list *list, const char *path)
93
148
{
94
149
        struct stat st;
 
150
        unsigned int interval = list->mail_set->mail_temp_scan_interval;
95
151
 
96
152
        if (stat(path, &st) < 0)
97
153
                return FALSE;
98
154
 
99
155
        /* check once in a while if there are temp files to clean up */
100
 
        if (st.st_atime > st.st_ctime + DBOX_TMP_DELETE_SECS) {
 
156
        if (interval == 0) {
 
157
                /* disabled */
 
158
        } else if (st.st_atime > st.st_ctime + DBOX_TMP_DELETE_SECS) {
101
159
                /* there haven't been any changes to this directory since we
102
160
                   last checked it. */
103
 
        } else if (st.st_atime < ioloop_time - DBOX_TMP_SCAN_SECS) {
 
161
        } else if (st.st_atime < ioloop_time - interval) {
104
162
                /* time to scan */
105
163
                const char *prefix =
106
164
                        mailbox_list_get_global_temp_prefix(list);
113
171
 
114
172
int dbox_mailbox_open(struct mailbox *box)
115
173
{
116
 
        if (dbox_cleanup_if_exists(box->list, box->path)) {
117
 
                return index_storage_mailbox_open(box, FALSE);
118
 
        } else if (errno == ENOENT) {
 
174
        const char *box_path = mailbox_get_path(box);
 
175
 
 
176
        if (dbox_cleanup_if_exists(box->list, box_path))
 
177
                ;
 
178
        else if (errno == ENOENT || errno == ENAMETOOLONG) {
119
179
                mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
120
180
                        T_MAIL_ERR_MAILBOX_NOT_FOUND(box->name));
121
181
                return -1;
122
182
        } else if (errno == EACCES) {
123
183
                mail_storage_set_critical(box->storage, "%s",
124
 
                        mail_error_eacces_msg("stat", box->path));
 
184
                        mail_error_eacces_msg("stat", box_path));
125
185
                return -1;
126
186
        } else {
127
187
                mail_storage_set_critical(box->storage,
128
 
                                          "stat(%s) failed: %m", box->path);
 
188
                                          "stat(%s) failed: %m", box_path);
129
189
                return -1;
130
190
        }
 
191
 
 
192
        if (index_storage_mailbox_open(box, FALSE) < 0)
 
193
                return -1;
 
194
        mail_index_set_fsync_mode(box->index,
 
195
                                  box->storage->set->parsed_fsync_mode,
 
196
                                  MAIL_INDEX_SYNC_TYPE_APPEND |
 
197
                                  MAIL_INDEX_SYNC_TYPE_EXPUNGE);
 
198
        return 0;
131
199
}
132
200
 
133
201
static int dir_is_empty(struct mail_storage *storage, const char *path)