Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/deliver/duplicate.c @ 9464:939edf3ed09b HEAD
maildir: Having a lot of keywords assert-crashed with "stack frame changed".
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 02 Nov 2009 17:54:17 -0500 |
parents | b9faf4db2a9f |
children | 00cd9aacd03c |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8573
diff
changeset
|
1 /* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */ |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "ioloop.h" |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "istream.h" |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "ostream.h" |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "home-expand.h" |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "file-dotlock.h" |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "hash.h" |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "duplicate.h" |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 |
4968
1baf9dd3fc40
Added dotlock_use_excl setting.
Timo Sirainen <tss@iki.fi>
parents:
4589
diff
changeset
|
12 #include <stdlib.h> |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include <fcntl.h> |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #include <unistd.h> |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #define DUPLICATE_PATH "~/.dovecot.lda-dupes" |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 #define COMPRESS_PERCENTAGE 10 |
6427
c242677f2aa9
Don't crash if duplicate database contains broken entries.
Timo Sirainen <tss@iki.fi>
parents:
6417
diff
changeset
|
18 #define DUPLICATE_BUFSIZE 4096 |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
19 #define DUPLICATE_VERSION 2 |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 struct duplicate { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 const void *id; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 unsigned int id_size; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 const char *user; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 time_t time; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 }; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
29 struct duplicate_file_header { |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
30 uint32_t version; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
31 }; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
32 |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
33 struct duplicate_record_header { |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
34 uint32_t stamp; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
35 uint32_t id_size; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
36 uint32_t user_size; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
37 }; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
38 |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 struct duplicate_file { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 pool_t pool; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 struct hash_table *hash; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 const char *path; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 int new_fd; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 struct dotlock *dotlock; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 unsigned int changed:1; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 }; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 static struct dotlock_settings duplicate_dotlock_set = { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 MEMBER(temp_prefix) NULL, |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 MEMBER(lock_suffix) NULL, |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
53 MEMBER(timeout) 20, |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
54 MEMBER(stale_timeout) 10, |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 MEMBER(callback) NULL, |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 MEMBER(context) NULL, |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 MEMBER(use_excl_lock) FALSE |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 }; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 static struct duplicate_file *duplicate_file = NULL; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 static int duplicate_cmp(const void *p1, const void *p2) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 const struct duplicate *d1 = p1, *d2 = p2; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 return (d1->id_size == d2->id_size && |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 memcmp(d1->id, d2->id, d1->id_size) == 0 && |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 strcasecmp(d1->user, d2->user) == 0) ? 0 : 1; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 static unsigned int duplicate_hash(const void *p) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 /* a char* hash function from ASU -- from glib */ |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 const struct duplicate *d = p; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 const unsigned char *s = d->id, *end = s + d->id_size; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 unsigned int g, h = 0; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 while (s != end) { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 h = (h << 4) + *s; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 if ((g = h & 0xf0000000UL)) { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 h = h ^ (g >> 24); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 h = h ^ g; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 s++; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 return h ^ strcase_hash(d->user); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
90 |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
91 static int |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
92 duplicate_read_records(struct duplicate_file *file, struct istream *input, |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
93 unsigned int record_size) |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
94 { |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
95 const unsigned char *data; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
96 struct duplicate_record_header hdr; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
97 size_t size; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
98 unsigned int change_count; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
99 |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
100 change_count = 0; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
101 while (i_stream_read_data(input, &data, &size, record_size) > 0) { |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
102 if (record_size == sizeof(hdr)) |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
103 memcpy(&hdr, data, sizeof(hdr)); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
104 else { |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
105 /* FIXME: backwards compatibility with v1.0 */ |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
106 time_t stamp; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
107 |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
108 i_assert(record_size == |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
109 sizeof(time_t) + sizeof(uint32_t)*2); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
110 memcpy(&stamp, data, sizeof(stamp)); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
111 hdr.stamp = stamp; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
112 memcpy(&hdr.id_size, data + sizeof(time_t), |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
113 sizeof(hdr.id_size)); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
114 memcpy(&hdr.user_size, |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
115 data + sizeof(time_t) + sizeof(uint32_t), |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
116 sizeof(hdr.user_size)); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
117 } |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
118 i_stream_skip(input, record_size); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
119 |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
120 if (hdr.id_size == 0 || hdr.user_size == 0 || |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
121 hdr.id_size > DUPLICATE_BUFSIZE || |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
122 hdr.user_size > DUPLICATE_BUFSIZE) { |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
123 i_error("broken duplicate file %s", file->path); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
124 return -1; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
125 } |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
126 |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
127 if (i_stream_read_data(input, &data, &size, |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
128 hdr.id_size + hdr.user_size - 1) <= 0) { |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
129 i_error("unexpected end of file in %s", file->path); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
130 return -1; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
131 } |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
132 |
7043
7708a8c166d6
Compiler warning fixes on 32bit systems.
Timo Sirainen <tss@iki.fi>
parents:
6772
diff
changeset
|
133 if ((time_t)hdr.stamp >= ioloop_time) { |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
134 /* still valid, save it */ |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
135 struct duplicate *d; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
136 void *new_id; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
137 |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
138 new_id = p_malloc(file->pool, hdr.id_size); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
139 memcpy(new_id, data, hdr.id_size); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
140 |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
141 d = p_new(file->pool, struct duplicate, 1); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
142 d->id = new_id; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
143 d->id_size = hdr.id_size; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
144 d->user = p_strndup(file->pool, |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
145 data + hdr.id_size, hdr.user_size); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
146 d->time = hdr.stamp; |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7561
diff
changeset
|
147 hash_table_insert(file->hash, d, d); |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
148 } else { |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
149 change_count++; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
150 } |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
151 i_stream_skip(input, hdr.id_size + hdr.user_size); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
152 } |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
153 |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7561
diff
changeset
|
154 if (hash_table_count(file->hash) * |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7561
diff
changeset
|
155 COMPRESS_PERCENTAGE / 100 > change_count) |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
156 file->changed = TRUE; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
157 return 0; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
158 } |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
159 |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 static int duplicate_read(struct duplicate_file *file) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
161 { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 struct istream *input; |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
163 struct duplicate_file_header hdr; |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
164 const unsigned char *data; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 size_t size; |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
166 int fd; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
167 unsigned int record_size = 0; |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 fd = open(file->path, O_RDONLY); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 if (fd == -1) { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 if (errno == ENOENT) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 return 0; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 i_error("open(%s) failed: %m", file->path); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
174 return -1; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 /* <timestamp> <id_size> <user_size> <id> <user> */ |
6427
c242677f2aa9
Don't crash if duplicate database contains broken entries.
Timo Sirainen <tss@iki.fi>
parents:
6417
diff
changeset
|
178 input = i_stream_create_fd(fd, DUPLICATE_BUFSIZE, FALSE); |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
179 if (i_stream_read_data(input, &data, &size, sizeof(hdr)) > 0) { |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
180 memcpy(&hdr, data, sizeof(hdr)); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
181 if (hdr.version == 0 || hdr.version > DUPLICATE_VERSION + 10) { |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
182 /* FIXME: backwards compatibility with v1.0 */ |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
183 record_size = sizeof(time_t) + sizeof(uint32_t)*2; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
184 } else if (hdr.version == DUPLICATE_VERSION) { |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
185 record_size = sizeof(struct duplicate_record_header); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
186 i_stream_skip(input, sizeof(hdr)); |
6427
c242677f2aa9
Don't crash if duplicate database contains broken entries.
Timo Sirainen <tss@iki.fi>
parents:
6417
diff
changeset
|
187 } |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
190 if (record_size == 0 || |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
191 duplicate_read_records(file, input, record_size) < 0) { |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
192 if (unlink(file->path) < 0 && errno != ENOENT) |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
193 i_error("unlink(%s) failed: %m", file->path); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
194 } |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
195 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 i_stream_unref(&input); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 if (close(fd) < 0) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 i_error("close(%s) failed: %m", file->path); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 return 0; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 static struct duplicate_file *duplicate_new(const char *path) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 struct duplicate_file *file; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
205 pool_t pool; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
206 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 pool = pool_alloconly_create("duplicates", 10240); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 file = p_new(pool, struct duplicate_file, 1); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 file->pool = pool; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 file->path = p_strdup(pool, path); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 file->new_fd = file_dotlock_open(&duplicate_dotlock_set, path, 0, |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
213 &file->dotlock); |
6772
b78cfc60f6a1
Added missing error logging for file_dotlock_create/open calls.
Timo Sirainen <tss@iki.fi>
parents:
6592
diff
changeset
|
214 if (file->new_fd == -1) |
b78cfc60f6a1
Added missing error logging for file_dotlock_create/open calls.
Timo Sirainen <tss@iki.fi>
parents:
6592
diff
changeset
|
215 i_error("file_dotlock_create(%s) failed: %m", path); |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7561
diff
changeset
|
216 file->hash = hash_table_create(default_pool, pool, 0, |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7561
diff
changeset
|
217 duplicate_hash, duplicate_cmp); |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 (void)duplicate_read(file); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
219 return file; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
221 |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
222 static void duplicate_free(struct duplicate_file **_file) |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 { |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
224 struct duplicate_file *file = *_file; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
225 |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
226 *_file = NULL; |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 if (file->dotlock != NULL) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 file_dotlock_delete(&file->dotlock); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7561
diff
changeset
|
230 hash_table_destroy(&file->hash); |
6428
7cad076906eb
pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6427
diff
changeset
|
231 pool_unref(&file->pool); |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
232 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 int duplicate_check(const void *id, size_t id_size, const char *user) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
235 { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
236 struct duplicate d; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 if (duplicate_file == NULL) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 duplicate_file = duplicate_new(home_expand(DUPLICATE_PATH)); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 d.id = id; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
242 d.id_size = id_size; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 d.user = user; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
244 |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7561
diff
changeset
|
245 return hash_table_lookup(duplicate_file->hash, &d) != NULL; |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
248 void duplicate_mark(const void *id, size_t id_size, |
7561
1a58b18652a6
Avoid using shadow variables. Unfortunately -Wshadow also complains about
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
249 const char *user, time_t timestamp) |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 struct duplicate *d; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
252 void *new_id; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 if (duplicate_file == NULL) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 duplicate_file = duplicate_new(home_expand(DUPLICATE_PATH)); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 new_id = p_malloc(duplicate_file->pool, id_size); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 memcpy(new_id, id, id_size); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
260 d = p_new(duplicate_file->pool, struct duplicate, 1); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 d->id = new_id; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
262 d->id_size = id_size; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 d->user = p_strdup(duplicate_file->pool, user); |
7561
1a58b18652a6
Avoid using shadow variables. Unfortunately -Wshadow also complains about
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
264 d->time = timestamp; |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 duplicate_file->changed = TRUE; |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7561
diff
changeset
|
267 hash_table_insert(duplicate_file->hash, d, d); |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 void duplicate_flush(void) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
271 { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 struct duplicate_file *file = duplicate_file; |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
273 struct duplicate_file_header hdr; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
274 struct duplicate_record_header rec; |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 struct ostream *output; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
276 struct hash_iterate_context *iter; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 void *key, *value; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
278 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
279 if (duplicate_file == NULL || !file->changed || file->new_fd == -1) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
280 return; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
281 |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
282 memset(&hdr, 0, sizeof(hdr)); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
283 hdr.version = DUPLICATE_VERSION; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
284 |
6161
c62f7ee79446
Split o_stream_create_file() to _create_fd() and _create_fd_file().
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
285 output = o_stream_create_fd_file(file->new_fd, 0, FALSE); |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
286 o_stream_send(output, &hdr, sizeof(hdr)); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
287 |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
288 memset(&rec, 0, sizeof(rec)); |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7561
diff
changeset
|
289 iter = hash_table_iterate_init(file->hash); |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7561
diff
changeset
|
290 while (hash_table_iterate(iter, &key, &value)) { |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 struct duplicate *d = value; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
292 |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
293 rec.stamp = d->time; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
294 rec.id_size = d->id_size; |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
295 rec.user_size = strlen(d->user); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
296 |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
297 o_stream_send(output, &rec, sizeof(rec)); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
298 o_stream_send(output, d->id, rec.id_size); |
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
299 o_stream_send(output, d->user, rec.user_size); |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
300 } |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7561
diff
changeset
|
301 hash_table_iterate_deinit(&iter); |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
302 o_stream_unref(&output); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
303 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
304 file->changed = FALSE; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
305 if (file_dotlock_replace(&file->dotlock, 0) < 0) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
306 i_error("file_dotlock_replace(%s) failed: %m", file->path); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 file->new_fd = -1; |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
309 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 void duplicate_init(void) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 { |
4968
1baf9dd3fc40
Added dotlock_use_excl setting.
Timo Sirainen <tss@iki.fi>
parents:
4589
diff
changeset
|
312 duplicate_dotlock_set.use_excl_lock = |
1baf9dd3fc40
Added dotlock_use_excl setting.
Timo Sirainen <tss@iki.fi>
parents:
4589
diff
changeset
|
313 getenv("DOTLOCK_USE_EXCL") != NULL; |
6592
b6631550cf84
dotlocks: Flush NFS attribute cache only if nfs_flush setting is TRUE.
Timo Sirainen <tss@iki.fi>
parents:
6591
diff
changeset
|
314 duplicate_dotlock_set.nfs_flush = |
b6631550cf84
dotlocks: Flush NFS attribute cache only if nfs_flush setting is TRUE.
Timo Sirainen <tss@iki.fi>
parents:
6591
diff
changeset
|
315 getenv("MAIL_NFS_STORAGE") != NULL; |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
316 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
318 void duplicate_deinit(void) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 if (duplicate_file != NULL) { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 duplicate_flush(); |
6591
f74e84fd11fc
Use a new format for duplicate file which can handle moving between 32bit
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
322 duplicate_free(&duplicate_file); |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
323 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
324 } |