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

« back to all changes in this revision

Viewing changes to src/lib-storage/index/mbox/mbox-md5.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) 2004-2011 Dovecot authors, see the included COPYING file */
2
 
 
3
 
#include "lib.h"
4
 
#include "md5.h"
5
 
#include "message-parser.h"
6
 
#include "mbox-md5.h"
7
 
 
8
 
#include <stdlib.h>
9
 
 
10
 
struct mbox_md5_context {
11
 
        struct md5_context hdr_md5_ctx;
12
 
        bool seen_received_hdr;
13
 
};
14
 
 
15
 
struct mbox_md5_header_func {
16
 
        const char *header;
17
 
        bool (*func)(struct mbox_md5_context *ctx,
18
 
                     struct message_header_line *hdr);
19
 
};
20
 
 
21
 
static bool parse_date(struct mbox_md5_context *ctx,
22
 
                       struct message_header_line *hdr)
23
 
{
24
 
        if (!ctx->seen_received_hdr) {
25
 
                /* Received-header contains date too, and more trusted one */
26
 
                md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
27
 
        }
28
 
        return TRUE;
29
 
}
30
 
 
31
 
static bool parse_delivered_to(struct mbox_md5_context *ctx,
32
 
                               struct message_header_line *hdr)
33
 
{
34
 
        md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
35
 
        return TRUE;
36
 
}
37
 
 
38
 
static bool parse_message_id(struct mbox_md5_context *ctx,
39
 
                             struct message_header_line *hdr)
40
 
{
41
 
        if (!ctx->seen_received_hdr) {
42
 
                /* Received-header contains unique ID too,
43
 
                   and more trusted one */
44
 
                md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
45
 
        }
46
 
        return TRUE;
47
 
}
48
 
 
49
 
static bool parse_received(struct mbox_md5_context *ctx,
50
 
                           struct message_header_line *hdr)
51
 
{
52
 
        if (!ctx->seen_received_hdr) {
53
 
                /* get only the first received-header */
54
 
                md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
55
 
                if (!hdr->continues)
56
 
                        ctx->seen_received_hdr = TRUE;
57
 
        }
58
 
        return TRUE;
59
 
}
60
 
 
61
 
static bool parse_x_delivery_id(struct mbox_md5_context *ctx,
62
 
                                struct message_header_line *hdr)
63
 
{
64
 
        /* Let the local delivery agent help generate unique ID's but don't
65
 
           blindly trust this header alone as it could just as easily come from
66
 
           the remote. */
67
 
        md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
68
 
        return TRUE;
69
 
}
70
 
 
71
 
 
72
 
static struct mbox_md5_header_func md5_header_funcs[] = {
73
 
        { "Date", parse_date },
74
 
        { "Delivered-To", parse_delivered_to },
75
 
        { "Message-ID", parse_message_id },
76
 
        { "Received", parse_received },
77
 
        { "X-Delivery-ID", parse_x_delivery_id }
78
 
};
79
 
 
80
 
static int bsearch_header_func_cmp(const void *p1, const void *p2)
81
 
{
82
 
        const char *key = p1;
83
 
        const struct mbox_md5_header_func *func = p2;
84
 
 
85
 
        return strcasecmp(key, func->header);
86
 
}
87
 
 
88
 
struct mbox_md5_context *mbox_md5_init(void)
89
 
{
90
 
        struct mbox_md5_context *ctx;
91
 
 
92
 
        ctx = i_new(struct mbox_md5_context, 1);
93
 
        md5_init(&ctx->hdr_md5_ctx);
94
 
        return ctx;
95
 
}
96
 
 
97
 
void mbox_md5_continue(struct mbox_md5_context *ctx,
98
 
                       struct message_header_line *hdr)
99
 
{
100
 
        struct mbox_md5_header_func *func;
101
 
 
102
 
        func = bsearch(hdr->name, md5_header_funcs,
103
 
                       N_ELEMENTS(md5_header_funcs), sizeof(*md5_header_funcs),
104
 
                       bsearch_header_func_cmp);
105
 
        if (func != NULL)
106
 
                (void)func->func(ctx, hdr);
107
 
}
108
 
 
109
 
void mbox_md5_finish(struct mbox_md5_context *ctx,
110
 
                     unsigned char result[16])
111
 
{
112
 
        md5_final(&ctx->hdr_md5_ctx, result);
113
 
        i_free(ctx);
114
 
}