bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
bf7dc750b95039981c0e9d728f313d50cf38a156Martti Rannanjärvi#define DSYNC_COMMON_GETOPT_ARGS "+1a:dDEfg:I:l:m:n:NO:Pr:Rs:t:e:T:Ux:"
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen/* The broken_char is mainly set to get a proper error message when trying to
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen convert a mailbox with a name that can't be used properly translated between
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen vname/storage_name and would otherwise be mixed up with a normal "mailbox
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen doesn't exist" error message. This could be any control character, since
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen none of them are allowed to be created in regular mailbox names. */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen#define DSYNC_DEFAULT_IO_STREAM_TIMEOUT_SECS (60*10)
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen size_t input_orig_bufsize, output_orig_bufsize;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenstatic void dsync_cmd_switch_ioloop_to(struct dsync_cmd_context *ctx,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen i_stream_switch_ioloop_to(ctx->input, ioloop);
36723cf206a7b64b9d972ab0719bbfaacc9316faTimo Sirainen o_stream_switch_ioloop_to(ctx->output, ioloop);
36723cf206a7b64b9d972ab0719bbfaacc9316faTimo Sirainenstatic void remote_error_input(struct dsync_cmd_context *ctx)
cabf98de0145c8e233e41073fe3f8c1cc85ed1ebTimo Sirainen data = i_stream_get_data(ctx->err_stream, &size);
cabf98de0145c8e233e41073fe3f8c1cc85ed1ebTimo Sirainen while ((line = i_stream_next_line(ctx->err_stream)) != NULL)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenrun_cmd(struct dsync_cmd_context *ctx, const char *const *args)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen struct doveadm_cmd_context *cctx = ctx->ctx.cctx;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen ctx->remote_cmd_args = p_strarray_dup(ctx->ctx.pool, args);
4f7951e71128c120d8a502d6406cc603fcc8eb0bTimo Sirainen if (pipe(fd_in) < 0 || pipe(fd_out) < 0 || pipe(fd_err) < 0)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen /* child, which will execute the proxy server. stdin/stdout
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen goes to pipes which we'll pass to proxy client. */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (write_full(ctx->fd_out, prefix, strlen(prefix)) < 0)
19e161dd9e2c3a2ffc96ee8852bec0720cb30d1cTimo Sirainen ctx->err_stream = i_stream_create_fd(ctx->fd_err, IO_BLOCK_SIZE);
71e88fae3be360e9a93b3398e743f99a6f05d2edTimo Sirainen i_stream_set_return_partial_line(ctx->err_stream, TRUE);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenmirror_get_remote_cmd_line(const char *const *argv,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen const char *const **cmd_args_r)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen unsigned int i;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen const char *p;
4f7951e71128c120d8a502d6406cc603fcc8eb0bTimo Sirainen /* we're executing dsync */
4f7951e71128c120d8a502d6406cc603fcc8eb0bTimo Sirainen p = "server";
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen /* we're executing doveadm */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen p = "dsync-server";
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenstatic const char *const *
const char *user,
const char *const **cmd_args_r)
return TRUE;
if (!i_isalnum(*p)) {
return FALSE;
return TRUE;
return TRUE;
const char **changes_during_sync_r,
*mail_error_r = 0;
i_unreached();
if (ret < 0) {
if (doveadm_is_killed()) {
*changes_during_sync_r = t_strdup(dsync_brain_get_unexpected_changes_reason(brain2, &remote_only_changes));
const char *const *remote_cmd_args)
static struct dsync_ibc *
const char *state_str)
if (doveadm_debug)
case DSYNC_RUN_TYPE_LOCAL:
case DSYNC_RUN_TYPE_CMD:
case DSYNC_RUN_TYPE_STREAM:
if (ret < 0) {
if (mail_error2 != 0 &&
return ret;
void *context)
switch (exit_code) {
case EX_NOUSER:
const char **error_r)
if (ssl) {
if (doveadm_verbose_proctitle) {
if (doveadm_debug)
if (doveadm_verbose_proctitle) {
const char *location,
const char **error_r)
const char *const args[])
str++;
return FALSE;
return TRUE;
return _ctx;
if (!cli) {
return DOVEADM_EX_NOREPLICATE;
if (!cli) {
return FALSE;
return TRUE;
"[-1fPRU] [-l <secs>] [-r <rawlog path>] [-m <mailbox>] [-g <mailbox_guid>] [-n <namespace> | -N] [-x <exclude>] [-s <state>] [-t <start date>] -d|<dest>"
"[-fPRU] [-l <secs>] [-r <rawlog path>] [-m <mailbox>] [-g <mailbox_guid>] [-n <namespace> | -N] [-x <exclude>] [-s <state>] [-t <start date>] -d|<dest>"
if (flag_m) {
if (flag_u) {
if (flag_C) {
if (!dsync_server) {
if (flag_f)
if (flag_R)