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

« back to all changes in this revision

Viewing changes to src/lib-storage/index/mbox/mbox-lock.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) 2002-2011 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2002-2012 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "eacces-error.h"
174
174
                   be sure that the file is latest, but mbox files get rarely
175
175
                   deleted and the flushing might cause errors (e.g. EBUSY for
176
176
                   trying to flush a /var/mail mountpoint) */
177
 
                if (nfs_safe_stat(mbox->box.path, &st) < 0) {
 
177
                if (nfs_safe_stat(mailbox_get_path(&mbox->box), &st) < 0) {
178
178
                        if (errno == ENOENT)
179
179
                                mailbox_set_deleted(&mbox->box);
180
180
                        else
250
250
                                      struct dotlock_settings *set,
251
251
                                      enum mbox_dotlock_op op)
252
252
{
253
 
        const char *dir, *fname;
 
253
        const char *box_path, *dir, *fname;
254
254
        int ret = -1, orig_dir_fd, orig_errno;
255
255
 
256
256
        orig_dir_fd = open(".", O_RDONLY);
268
268
              privileged group
269
269
            - DoS other users by dotlocking their mailboxes infinitely
270
270
        */
271
 
        fname = strrchr(mbox->box.path, '/');
 
271
        box_path = mailbox_get_path(&mbox->box);
 
272
        fname = strrchr(box_path, '/');
272
273
        if (fname == NULL) {
273
274
                /* already relative */
274
 
                fname = mbox->box.path;
 
275
                fname = box_path;
275
276
        } else {
276
 
                dir = t_strdup_until(mbox->box.path, fname);
 
277
                dir = t_strdup_until(box_path, fname);
277
278
                if (chdir(dir) < 0) {
278
279
                        mail_storage_set_critical(&mbox->storage->storage,
279
280
                                "chdir(%s) failed: %m", dir);
285
286
        if (op == MBOX_DOTLOCK_OP_LOCK) {
286
287
                if (access(fname, R_OK) < 0) {
287
288
                        mail_storage_set_critical(&mbox->storage->storage,
288
 
                                "access(%s) failed: %m", mbox->box.path);
 
289
                                "access(%s) failed: %m", box_path);
289
290
                        return -1;
290
291
                }
291
292
        }
417
418
        set.callback = dotlock_callback;
418
419
        set.context = ctx;
419
420
 
420
 
        ret = file_dotlock_create(&set, mbox->box.path, 0,
 
421
        ret = file_dotlock_create(&set, mailbox_get_path(&mbox->box), 0,
421
422
                                  &mbox->mbox_dotlock);
422
423
        if (ret >= 0) {
423
424
                /* success / timeout */
427
428
                ret = mbox_dotlock_privileged_op(mbox, &set,
428
429
                                                 MBOX_DOTLOCK_OP_LOCK);
429
430
        } else if (errno == EACCES)
430
 
                mbox_dotlock_log_eacces_error(mbox, mbox->box.path);
 
431
                mbox_dotlock_log_eacces_error(mbox, mailbox_get_path(&mbox->box));
431
432
        else
432
433
                mbox_set_syscall_error(mbox, "file_dotlock_create()");
433
434
 
637
638
                        mail_storage_set_critical(&ctx->mbox->storage->storage,
638
639
                                "fcntl() failed with mbox file %s: "
639
640
                                "File is locked by another process (EACCES)",
640
 
                                ctx->mbox->box.path);
 
641
                                mailbox_get_path(&ctx->mbox->box));
641
642
                        return -1;
642
643
                }
643
644
 
709
710
 
710
711
        if (mbox->mbox_fd == -1 && mbox->mbox_file_stream != NULL) {
711
712
                /* read-only mbox stream. no need to lock. */
712
 
                i_assert(mbox->box.backend_readonly);
 
713
                i_assert(mbox_is_backend_readonly(mbox));
713
714
                mbox->mbox_lock_type = lock_type;
714
715
                return 1;
715
716
        }
774
775
int mbox_lock(struct mbox_mailbox *mbox, int lock_type,
775
776
              unsigned int *lock_id_r)
776
777
{
777
 
        const char *path = mbox->box.path;
 
778
        const char *path = mailbox_get_path(&mbox->box);
778
779
        int mbox_fd = mbox->mbox_fd;
779
780
        bool fcntl_locked;
780
781
        int ret;
783
784
        i_assert(lock_type == F_RDLCK || lock_type == F_WRLCK);
784
785
        i_assert(lock_type == F_RDLCK || mbox->mbox_lock_type != F_RDLCK);
785
786
 
786
 
        /* mbox must be locked before index */
787
 
        i_assert(mbox->box.index->lock_type != F_WRLCK);
 
787
        /* mbox must be locked before index (the NULL check is for
 
788
           MAILBOX_FLAG_KEEP_LOCKED) */
 
789
        i_assert(mbox->box.index == NULL ||
 
790
                 mbox->box.index->lock_type != F_WRLCK);
788
791
 
789
792
        if (mbox->mbox_lock_type == F_UNLCK) {
790
793
                ret = mbox_update_locking(mbox, lock_type, &fcntl_locked);