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

« back to all changes in this revision

Viewing changes to src/dsync/dsync-data.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) 2009-2011 Dovecot authors, see the included COPYING file */
2
 
 
3
 
#include "lib.h"
4
 
#include "array.h"
5
 
#include "hex-binary.h"
6
 
#include "sha1.h"
7
 
#include "dsync-data.h"
8
 
 
9
 
struct dsync_mailbox *
10
 
dsync_mailbox_dup(pool_t pool, const struct dsync_mailbox *box)
11
 
{
12
 
        struct dsync_mailbox *dest;
13
 
        const char *const *cache_fields = NULL, *dup;
14
 
        unsigned int i, count = 0;
15
 
 
16
 
        dest = p_new(pool, struct dsync_mailbox, 1);
17
 
        *dest = *box;
18
 
        dest->name = p_strdup(pool, box->name);
19
 
 
20
 
        if (array_is_created(&box->cache_fields))
21
 
                cache_fields = array_get(&box->cache_fields, &count);
22
 
        if (count == 0)
23
 
                memset(&dest->cache_fields, 0, sizeof(dest->cache_fields));
24
 
        else {
25
 
                p_array_init(&dest->cache_fields, pool, count);
26
 
                for (i = 0; i < count; i++) {
27
 
                        dup = p_strdup(pool, cache_fields[i]);
28
 
                        array_append(&dest->cache_fields, &dup, 1);
29
 
                }
30
 
        }
31
 
        return dest;
32
 
}
33
 
 
34
 
struct dsync_message *
35
 
dsync_message_dup(pool_t pool, const struct dsync_message *msg)
36
 
{
37
 
        struct dsync_message *dest;
38
 
        const char **keywords;
39
 
        unsigned int i, count;
40
 
 
41
 
        dest = p_new(pool, struct dsync_message, 1);
42
 
        *dest = *msg;
43
 
        dest->guid = p_strdup(pool, msg->guid);
44
 
        if (msg->keywords != NULL) {
45
 
                count = str_array_length(msg->keywords);
46
 
                keywords = p_new(pool, const char *, count+1);
47
 
                for (i = 0; i < count; i++)
48
 
                        keywords[i] = p_strdup(pool, msg->keywords[i]);
49
 
                dest->keywords = keywords;
50
 
        }
51
 
        return dest;
52
 
}
53
 
 
54
 
int dsync_mailbox_guid_cmp(const struct dsync_mailbox *box1,
55
 
                           const struct dsync_mailbox *box2)
56
 
{
57
 
        return memcmp(box1->mailbox_guid.guid, box2->mailbox_guid.guid,
58
 
                      sizeof(box1->mailbox_guid.guid));
59
 
}
60
 
 
61
 
int dsync_mailbox_p_guid_cmp(struct dsync_mailbox *const *box1,
62
 
                             struct dsync_mailbox *const *box2)
63
 
{
64
 
        return dsync_mailbox_guid_cmp(*box1, *box2);
65
 
}
66
 
 
67
 
int dsync_mailbox_name_sha1_cmp(const struct dsync_mailbox *box1,
68
 
                                const struct dsync_mailbox *box2)
69
 
{
70
 
        int ret;
71
 
 
72
 
        ret = memcmp(box1->name_sha1.guid, box2->name_sha1.guid,
73
 
                     sizeof(box1->name_sha1.guid));
74
 
        if (ret != 0)
75
 
                return ret;
76
 
 
77
 
        return strcmp(box1->name, box2->name);
78
 
}
79
 
 
80
 
int dsync_mailbox_p_name_sha1_cmp(struct dsync_mailbox *const *box1,
81
 
                                  struct dsync_mailbox *const *box2)
82
 
{
83
 
        return dsync_mailbox_name_sha1_cmp(*box1, *box2);
84
 
}
85
 
 
86
 
bool dsync_keyword_list_equals(const char *const *k1, const char *const *k2)
87
 
{
88
 
        unsigned int i;
89
 
 
90
 
        if (k1 == NULL)
91
 
                return k2 == NULL || k2[0] == NULL;
92
 
        if (k2 == NULL)
93
 
                return k1[0] == NULL;
94
 
 
95
 
        for (i = 0;; i++) {
96
 
                if (k1[i] == NULL)
97
 
                        return k2[i] == NULL;
98
 
                if (k2[i] == NULL)
99
 
                        return FALSE;
100
 
 
101
 
                if (strcasecmp(k1[i], k2[i]) != 0)
102
 
                        return FALSE;
103
 
        }
104
 
}
105
 
 
106
 
bool dsync_guid_equals(const mailbox_guid_t *guid1,
107
 
                       const mailbox_guid_t *guid2)
108
 
{
109
 
        return memcmp(guid1->guid, guid2->guid, sizeof(guid1->guid)) == 0;
110
 
}
111
 
 
112
 
int dsync_guid_cmp(const mailbox_guid_t *guid1, const mailbox_guid_t *guid2)
113
 
{
114
 
        return memcmp(guid1->guid, guid2->guid, sizeof(guid1->guid));
115
 
}
116
 
 
117
 
const char *dsync_guid_to_str(const mailbox_guid_t *guid)
118
 
{
119
 
        return mail_guid_128_to_string(guid->guid);
120
 
}
121
 
 
122
 
const char *dsync_get_guid_128_str(const char *guid, unsigned char *dest,
123
 
                                   unsigned int dest_len)
124
 
{
125
 
        uint8_t guid_128[MAIL_GUID_128_SIZE];
126
 
        buffer_t guid_128_buf;
127
 
 
128
 
        i_assert(dest_len >= MAIL_GUID_128_SIZE * 2 + 1);
129
 
        buffer_create_data(&guid_128_buf, dest, dest_len);
130
 
        mail_generate_guid_128_hash(guid, guid_128);
131
 
        if (mail_guid_128_is_empty(guid_128))
132
 
                return "";
133
 
        binary_to_hex_append(&guid_128_buf, guid_128, sizeof(guid_128));
134
 
        buffer_append_c(&guid_128_buf, '\0');
135
 
        return guid_128_buf.data;
136
 
}
137
 
 
138
 
void dsync_str_sha_to_guid(const char *str, mailbox_guid_t *guid)
139
 
{
140
 
        unsigned char sha[SHA1_RESULTLEN];
141
 
 
142
 
        sha1_get_digest(str, strlen(str), sha);
143
 
        memcpy(guid->guid, sha, I_MIN(sizeof(guid->guid), sizeof(sha)));
144
 
}