dovecot-2.0: dsync: Verify that msg-get and msg-copy reply has t...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Apr 5 01:06:05 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/ba75ab0c3e10
changeset: 11031:ba75ab0c3e10
user: Timo Sirainen <tss at iki.fi>
date: Mon Apr 05 00:18:41 2010 +0300
description:
dsync: Verify that msg-get and msg-copy reply has the correct UID.
diffstat:
src/dsync/dsync-proxy-client.c | 37 ++++++++++++++++++++++++++++++++++---
src/dsync/dsync-proxy-server-cmd.c | 15 +++++++++++++--
src/dsync/dsync-proxy-server.h | 2 +-
src/dsync/dsync-worker-local.c | 1 -
4 files changed, 48 insertions(+), 7 deletions(-)
diffs (156 lines):
diff -r 4f23c349da0d -r ba75ab0c3e10 src/dsync/dsync-proxy-client.c
--- a/src/dsync/dsync-proxy-client.c Mon Apr 05 00:00:53 2010 +0300
+++ b/src/dsync/dsync-proxy-client.c Mon Apr 05 00:18:41 2010 +0300
@@ -27,6 +27,7 @@
struct proxy_client_request {
enum proxy_client_request_type type;
+ uint32_t uid;
union {
dsync_worker_msg_callback_t *get;
dsync_worker_copy_callback_t *copy;
@@ -137,10 +138,31 @@
}
static bool
-proxy_client_worker_next_copy(const struct proxy_client_request *request,
+proxy_client_worker_next_copy(struct proxy_client_dsync_worker *worker,
+ const struct proxy_client_request *request,
const char *line)
{
- request->callback.copy(*line == '1', request->context);
+ uint32_t uid;
+ bool success;
+
+ if (line[0] == '1' && line[1] == '\t')
+ success = TRUE;
+ else if (line[0] == '0' && line[1] == '\t')
+ success = FALSE;
+ else {
+ i_error("msg-copy returned invalid input: %s", line);
+ proxy_client_fail(worker);
+ return FALSE;
+ }
+ uid = strtoul(line + 2, NULL, 10);
+ if (uid != request->uid) {
+ i_error("msg-copy returned invalid uid: %u != %u",
+ uid, request->uid);
+ proxy_client_fail(worker);
+ return FALSE;
+ }
+
+ request->callback.copy(success, request->context);
return TRUE;
}
@@ -167,6 +189,13 @@
uid = strtoul(t_strcut(line, '\t'), NULL, 10);
line = p + 1;
+ if (uid != request->uid) {
+ i_error("msg-get returned invalid uid: %u != %u",
+ uid, request->uid);
+ proxy_client_fail(worker);
+ return FALSE;
+ }
+
if (dsync_proxy_msg_static_import(worker->msg_get_pool,
line, &worker->msg_get_data,
&error) < 0) {
@@ -230,7 +259,7 @@
switch (request.type) {
case PROXY_CLIENT_REQUEST_TYPE_COPY:
- ret = proxy_client_worker_next_copy(&request, line);
+ ret = proxy_client_worker_next_copy(worker, &request, line);
break;
case PROXY_CLIENT_REQUEST_TYPE_GET:
ret = proxy_client_worker_next_msg_get(worker, &request, line);
@@ -847,6 +876,7 @@
request.type = PROXY_CLIENT_REQUEST_TYPE_COPY;
request.callback.copy = callback;
request.context = context;
+ request.uid = src_uid;
aqueue_append(worker->request_queue, &request);
}
@@ -960,6 +990,7 @@
request.type = PROXY_CLIENT_REQUEST_TYPE_GET;
request.callback.get = callback;
request.context = context;
+ request.uid = uid;
aqueue_append(worker->request_queue, &request);
}
diff -r 4f23c349da0d -r ba75ab0c3e10 src/dsync/dsync-proxy-server-cmd.c
--- a/src/dsync/dsync-proxy-server-cmd.c Mon Apr 05 00:00:53 2010 +0300
+++ b/src/dsync/dsync-proxy-server-cmd.c Mon Apr 05 00:18:41 2010 +0300
@@ -364,8 +364,12 @@
static void copy_callback(bool success, void *context)
{
struct dsync_proxy_server *server = context;
+ const char *reply;
- o_stream_send(server->output, success ? "1\n" : "0\n", 2);
+ i_assert(server->copy_uid != 0);
+
+ reply = t_strdup_printf("%d\t%u\n", success ? 1 : 0, server->copy_uid);
+ o_stream_send_str(server->output, reply);
}
static int
@@ -390,8 +394,10 @@
args + 2, &msg, &error) < 0)
i_error("Invalid message input: %s", error);
+ server->copy_uid = src_uid;
dsync_worker_msg_copy(server->worker, &src_mailbox_guid, src_uid, &msg,
copy_callback, server);
+ server->copy_uid = 0;
return 1;
}
@@ -459,6 +465,8 @@
struct dsync_proxy_server *server = context;
string_t *str;
+ i_assert(server->get_uid != 0);
+
switch (result) {
case DSYNC_MSG_GET_RESULT_SUCCESS:
break;
@@ -507,7 +515,10 @@
dsync_worker_msg_get(server->worker, &mailbox_guid, uid,
cmd_msg_get_callback, server);
}
- return server->get_input == NULL ? 1 : 0;
+ if (server->get_input != NULL)
+ return 0;
+ server->get_uid = 0;
+ return 1;
}
static void cmd_finish_callback(bool success, void *context)
diff -r 4f23c349da0d -r ba75ab0c3e10 src/dsync/dsync-proxy-server.h
--- a/src/dsync/dsync-proxy-server.h Mon Apr 05 00:00:53 2010 +0300
+++ b/src/dsync/dsync-proxy-server.h Mon Apr 05 00:18:41 2010 +0300
@@ -28,7 +28,7 @@
struct istream *get_input;
bool get_input_last_lf;
- uint32_t get_uid;
+ uint32_t get_uid, copy_uid;
unsigned int handshake_received:1;
unsigned int subs_sending_unsubscriptions:1;
diff -r 4f23c349da0d -r ba75ab0c3e10 src/dsync/dsync-worker-local.c
--- a/src/dsync/dsync-worker-local.c Mon Apr 05 00:00:53 2010 +0300
+++ b/src/dsync/dsync-worker-local.c Mon Apr 05 00:18:41 2010 +0300
@@ -485,7 +485,6 @@
if (info == NULL)
return iter_next_deleted(iter, worker, dsync_box_r);
- storage_name = mail_namespace_get_storage_name(info->ns, info->name);
dsync_box_r->name = info->name;
dsync_box_r->name_sep = info->ns->sep;
More information about the dovecot-cvs
mailing list