From 0441d265f2bb9da249c7abf333f0f771fadb4ab5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 19:36:47 +0200 Subject: Adding upstream version 1:2.3.21+dfsg1. Signed-off-by: Daniel Baumann --- src/replication/Makefile.am | 4 + src/replication/Makefile.in | 773 ++++++++++++++++++ src/replication/aggregator/Makefile.am | 29 + src/replication/aggregator/Makefile.in | 828 +++++++++++++++++++ src/replication/aggregator/aggregator-settings.c | 85 ++ src/replication/aggregator/aggregator-settings.h | 12 + src/replication/aggregator/aggregator.c | 74 ++ src/replication/aggregator/notify-connection.c | 154 ++++ src/replication/aggregator/notify-connection.h | 9 + src/replication/aggregator/replicator-connection.c | 326 ++++++++ src/replication/aggregator/replicator-connection.h | 25 + src/replication/replication-common.h | 48 ++ src/replication/replicator/Makefile.am | 60 ++ src/replication/replicator/Makefile.in | 897 +++++++++++++++++++++ src/replication/replicator/doveadm-connection.c | 354 ++++++++ src/replication/replicator/doveadm-connection.h | 11 + src/replication/replicator/dsync-client.c | 274 +++++++ src/replication/replicator/dsync-client.h | 37 + src/replication/replicator/notify-connection.c | 206 +++++ src/replication/replicator/notify-connection.h | 13 + src/replication/replicator/replicator-brain.c | 202 +++++ src/replication/replicator/replicator-brain.h | 20 + src/replication/replicator/replicator-queue-auth.c | 37 + src/replication/replicator/replicator-queue.c | 527 ++++++++++++ src/replication/replicator/replicator-queue.h | 104 +++ src/replication/replicator/replicator-settings.c | 86 ++ src/replication/replicator/replicator-settings.h | 16 + src/replication/replicator/replicator.c | 117 +++ src/replication/replicator/test-replicator-queue.c | 260 ++++++ 29 files changed, 5588 insertions(+) create mode 100644 src/replication/Makefile.am create mode 100644 src/replication/Makefile.in create mode 100644 src/replication/aggregator/Makefile.am create mode 100644 src/replication/aggregator/Makefile.in create mode 100644 src/replication/aggregator/aggregator-settings.c create mode 100644 src/replication/aggregator/aggregator-settings.h create mode 100644 src/replication/aggregator/aggregator.c create mode 100644 src/replication/aggregator/notify-connection.c create mode 100644 src/replication/aggregator/notify-connection.h create mode 100644 src/replication/aggregator/replicator-connection.c create mode 100644 src/replication/aggregator/replicator-connection.h create mode 100644 src/replication/replication-common.h create mode 100644 src/replication/replicator/Makefile.am create mode 100644 src/replication/replicator/Makefile.in create mode 100644 src/replication/replicator/doveadm-connection.c create mode 100644 src/replication/replicator/doveadm-connection.h create mode 100644 src/replication/replicator/dsync-client.c create mode 100644 src/replication/replicator/dsync-client.h create mode 100644 src/replication/replicator/notify-connection.c create mode 100644 src/replication/replicator/notify-connection.h create mode 100644 src/replication/replicator/replicator-brain.c create mode 100644 src/replication/replicator/replicator-brain.h create mode 100644 src/replication/replicator/replicator-queue-auth.c create mode 100644 src/replication/replicator/replicator-queue.c create mode 100644 src/replication/replicator/replicator-queue.h create mode 100644 src/replication/replicator/replicator-settings.c create mode 100644 src/replication/replicator/replicator-settings.h create mode 100644 src/replication/replicator/replicator.c create mode 100644 src/replication/replicator/test-replicator-queue.c (limited to 'src/replication') diff --git a/src/replication/Makefile.am b/src/replication/Makefile.am new file mode 100644 index 0000000..c9ddbd0 --- /dev/null +++ b/src/replication/Makefile.am @@ -0,0 +1,4 @@ +SUBDIRS = aggregator replicator + +noinst_HEADERS = \ + replication-common.h diff --git a/src/replication/Makefile.in b/src/replication/Makefile.in new file mode 100644 index 0000000..a9dd5bb --- /dev/null +++ b/src/replication/Makefile.in @@ -0,0 +1,773 @@ +# Makefile.in generated by automake 1.16.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2020 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = src/replication +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ac_checktype2.m4 \ + $(top_srcdir)/m4/ac_typeof.m4 $(top_srcdir)/m4/arc4random.m4 \ + $(top_srcdir)/m4/blockdev.m4 $(top_srcdir)/m4/c99_vsnprintf.m4 \ + $(top_srcdir)/m4/clock_gettime.m4 $(top_srcdir)/m4/crypt.m4 \ + $(top_srcdir)/m4/crypt_xpg6.m4 $(top_srcdir)/m4/dbqlk.m4 \ + $(top_srcdir)/m4/dirent_dtype.m4 $(top_srcdir)/m4/dovecot.m4 \ + $(top_srcdir)/m4/fd_passing.m4 $(top_srcdir)/m4/fdatasync.m4 \ + $(top_srcdir)/m4/flexible_array_member.m4 \ + $(top_srcdir)/m4/glibc.m4 $(top_srcdir)/m4/gmtime_max.m4 \ + $(top_srcdir)/m4/gmtime_tm_gmtoff.m4 \ + $(top_srcdir)/m4/ioloop.m4 $(top_srcdir)/m4/iovec.m4 \ + $(top_srcdir)/m4/ipv6.m4 $(top_srcdir)/m4/libcap.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/libwrap.m4 \ + $(top_srcdir)/m4/linux_mremap.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/mmap_write.m4 \ + $(top_srcdir)/m4/mntctl.m4 $(top_srcdir)/m4/modules.m4 \ + $(top_srcdir)/m4/notify.m4 $(top_srcdir)/m4/nsl.m4 \ + $(top_srcdir)/m4/off_t_max.m4 $(top_srcdir)/m4/pkg.m4 \ + $(top_srcdir)/m4/pr_set_dumpable.m4 \ + $(top_srcdir)/m4/q_quotactl.m4 $(top_srcdir)/m4/quota.m4 \ + $(top_srcdir)/m4/random.m4 $(top_srcdir)/m4/rlimit.m4 \ + $(top_srcdir)/m4/sendfile.m4 $(top_srcdir)/m4/size_t_signed.m4 \ + $(top_srcdir)/m4/sockpeercred.m4 $(top_srcdir)/m4/sql.m4 \ + $(top_srcdir)/m4/ssl.m4 $(top_srcdir)/m4/st_tim.m4 \ + $(top_srcdir)/m4/static_array.m4 $(top_srcdir)/m4/test_with.m4 \ + $(top_srcdir)/m4/time_t.m4 $(top_srcdir)/m4/typeof.m4 \ + $(top_srcdir)/m4/typeof_dev_t.m4 \ + $(top_srcdir)/m4/uoff_t_max.m4 $(top_srcdir)/m4/vararg.m4 \ + $(top_srcdir)/m4/want_apparmor.m4 \ + $(top_srcdir)/m4/want_bsdauth.m4 \ + $(top_srcdir)/m4/want_bzlib.m4 \ + $(top_srcdir)/m4/want_cassandra.m4 \ + $(top_srcdir)/m4/want_cdb.m4 \ + $(top_srcdir)/m4/want_checkpassword.m4 \ + $(top_srcdir)/m4/want_clucene.m4 $(top_srcdir)/m4/want_db.m4 \ + $(top_srcdir)/m4/want_gssapi.m4 $(top_srcdir)/m4/want_icu.m4 \ + $(top_srcdir)/m4/want_ldap.m4 $(top_srcdir)/m4/want_lua.m4 \ + $(top_srcdir)/m4/want_lz4.m4 $(top_srcdir)/m4/want_lzma.m4 \ + $(top_srcdir)/m4/want_mysql.m4 $(top_srcdir)/m4/want_pam.m4 \ + $(top_srcdir)/m4/want_passwd.m4 $(top_srcdir)/m4/want_pgsql.m4 \ + $(top_srcdir)/m4/want_prefetch.m4 \ + $(top_srcdir)/m4/want_shadow.m4 \ + $(top_srcdir)/m4/want_sodium.m4 $(top_srcdir)/m4/want_solr.m4 \ + $(top_srcdir)/m4/want_sqlite.m4 \ + $(top_srcdir)/m4/want_stemmer.m4 \ + $(top_srcdir)/m4/want_systemd.m4 \ + $(top_srcdir)/m4/want_textcat.m4 \ + $(top_srcdir)/m4/want_unwind.m4 $(top_srcdir)/m4/want_zlib.m4 \ + $(top_srcdir)/m4/want_zstd.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +SOURCES = +DIST_SOURCES = +RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ + ctags-recursive dvi-recursive html-recursive info-recursive \ + install-data-recursive install-dvi-recursive \ + install-exec-recursive install-html-recursive \ + install-info-recursive install-pdf-recursive \ + install-ps-recursive install-recursive installcheck-recursive \ + installdirs-recursive pdf-recursive ps-recursive \ + tags-recursive uninstall-recursive +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +am__recursive_targets = \ + $(RECURSIVE_TARGETS) \ + $(RECURSIVE_CLEAN_TARGETS) \ + $(am__extra_recursive_targets) +AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ + distdir distdir-am +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) +am__DIST_COMMON = $(srcdir)/Makefile.in +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +am__relativize = \ + dir0=`pwd`; \ + sed_first='s,^\([^/]*\)/.*$$,\1,'; \ + sed_rest='s,^[^/]*/*,,'; \ + sed_last='s,^.*/\([^/]*\)$$,\1,'; \ + sed_butlast='s,/*[^/]*$$,,'; \ + while test -n "$$dir1"; do \ + first=`echo "$$dir1" | sed -e "$$sed_first"`; \ + if test "$$first" != "."; then \ + if test "$$first" = ".."; then \ + dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ + dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ + else \ + first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ + if test "$$first2" = "$$first"; then \ + dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ + else \ + dir2="../$$dir2"; \ + fi; \ + dir0="$$dir0"/"$$first"; \ + fi; \ + fi; \ + dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ + done; \ + reldir="$$dir2" +ACLOCAL = @ACLOCAL@ +ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +APPARMOR_LIBS = @APPARMOR_LIBS@ +AR = @AR@ +AUTH_CFLAGS = @AUTH_CFLAGS@ +AUTH_LIBS = @AUTH_LIBS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BINARY_CFLAGS = @BINARY_CFLAGS@ +BINARY_LDFLAGS = @BINARY_LDFLAGS@ +BISON = @BISON@ +CASSANDRA_CFLAGS = @CASSANDRA_CFLAGS@ +CASSANDRA_LIBS = @CASSANDRA_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CDB_LIBS = @CDB_LIBS@ +CFLAGS = @CFLAGS@ +CLUCENE_CFLAGS = @CLUCENE_CFLAGS@ +CLUCENE_LIBS = @CLUCENE_LIBS@ +COMPRESS_LIBS = @COMPRESS_LIBS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CRYPT_LIBS = @CRYPT_LIBS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DICT_LIBS = @DICT_LIBS@ +DLLIB = @DLLIB@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +FLEX = @FLEX@ +FUZZER_CPPFLAGS = @FUZZER_CPPFLAGS@ +FUZZER_LDFLAGS = @FUZZER_LDFLAGS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +KRB5CONFIG = @KRB5CONFIG@ +KRB5_CFLAGS = @KRB5_CFLAGS@ +KRB5_LIBS = @KRB5_LIBS@ +LD = @LD@ +LDAP_LIBS = @LDAP_LIBS@ +LDFLAGS = @LDFLAGS@ +LD_NO_WHOLE_ARCHIVE = @LD_NO_WHOLE_ARCHIVE@ +LD_WHOLE_ARCHIVE = @LD_WHOLE_ARCHIVE@ +LIBCAP = @LIBCAP@ +LIBDOVECOT = @LIBDOVECOT@ +LIBDOVECOT_COMPRESS = @LIBDOVECOT_COMPRESS@ +LIBDOVECOT_DEPS = @LIBDOVECOT_DEPS@ +LIBDOVECOT_DSYNC = @LIBDOVECOT_DSYNC@ +LIBDOVECOT_LA_LIBS = @LIBDOVECOT_LA_LIBS@ +LIBDOVECOT_LDA = @LIBDOVECOT_LDA@ +LIBDOVECOT_LDAP = @LIBDOVECOT_LDAP@ +LIBDOVECOT_LIBFTS = @LIBDOVECOT_LIBFTS@ +LIBDOVECOT_LIBFTS_DEPS = @LIBDOVECOT_LIBFTS_DEPS@ +LIBDOVECOT_LOGIN = @LIBDOVECOT_LOGIN@ +LIBDOVECOT_LUA = @LIBDOVECOT_LUA@ +LIBDOVECOT_LUA_DEPS = @LIBDOVECOT_LUA_DEPS@ +LIBDOVECOT_SQL = @LIBDOVECOT_SQL@ +LIBDOVECOT_STORAGE = @LIBDOVECOT_STORAGE@ +LIBDOVECOT_STORAGE_DEPS = @LIBDOVECOT_STORAGE_DEPS@ +LIBEXTTEXTCAT_CFLAGS = @LIBEXTTEXTCAT_CFLAGS@ +LIBEXTTEXTCAT_LIBS = @LIBEXTTEXTCAT_LIBS@ +LIBICONV = @LIBICONV@ +LIBICU_CFLAGS = @LIBICU_CFLAGS@ +LIBICU_LIBS = @LIBICU_LIBS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBSODIUM_CFLAGS = @LIBSODIUM_CFLAGS@ +LIBSODIUM_LIBS = @LIBSODIUM_LIBS@ +LIBTIRPC_CFLAGS = @LIBTIRPC_CFLAGS@ +LIBTIRPC_LIBS = @LIBTIRPC_LIBS@ +LIBTOOL = @LIBTOOL@ +LIBUNWIND_CFLAGS = @LIBUNWIND_CFLAGS@ +LIBUNWIND_LIBS = @LIBUNWIND_LIBS@ +LIBWRAP_LIBS = @LIBWRAP_LIBS@ +LINKED_STORAGE_LDADD = @LINKED_STORAGE_LDADD@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +LUA_CFLAGS = @LUA_CFLAGS@ +LUA_LIBS = @LUA_LIBS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +MODULE_LIBS = @MODULE_LIBS@ +MODULE_SUFFIX = @MODULE_SUFFIX@ +MYSQL_CFLAGS = @MYSQL_CFLAGS@ +MYSQL_CONFIG = @MYSQL_CONFIG@ +MYSQL_LIBS = @MYSQL_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +NOPLUGIN_LDFLAGS = @NOPLUGIN_LDFLAGS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANDOC = @PANDOC@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PGSQL_CFLAGS = @PGSQL_CFLAGS@ +PGSQL_LIBS = @PGSQL_LIBS@ +PG_CONFIG = @PG_CONFIG@ +PIE_CFLAGS = @PIE_CFLAGS@ +PIE_LDFLAGS = @PIE_LDFLAGS@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +QUOTA_LIBS = @QUOTA_LIBS@ +RANLIB = @RANLIB@ +RELRO_LDFLAGS = @RELRO_LDFLAGS@ +RPCGEN = @RPCGEN@ +RUN_TEST = @RUN_TEST@ +SED = @SED@ +SETTING_FILES = @SETTING_FILES@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SQLITE_CFLAGS = @SQLITE_CFLAGS@ +SQLITE_LIBS = @SQLITE_LIBS@ +SQL_CFLAGS = @SQL_CFLAGS@ +SQL_LIBS = @SQL_LIBS@ +SSL_CFLAGS = @SSL_CFLAGS@ +SSL_LIBS = @SSL_LIBS@ +STRIP = @STRIP@ +SYSTEMD_CFLAGS = @SYSTEMD_CFLAGS@ +SYSTEMD_LIBS = @SYSTEMD_LIBS@ +VALGRIND = @VALGRIND@ +VERSION = @VERSION@ +ZSTD_CFLAGS = @ZSTD_CFLAGS@ +ZSTD_LIBS = @ZSTD_LIBS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +dict_drivers = @dict_drivers@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +moduledir = @moduledir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +rundir = @rundir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sql_drivers = @sql_drivers@ +srcdir = @srcdir@ +ssldir = @ssldir@ +statedir = @statedir@ +sysconfdir = @sysconfdir@ +systemdservicetype = @systemdservicetype@ +systemdsystemunitdir = @systemdsystemunitdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +SUBDIRS = aggregator replicator +noinst_HEADERS = \ + replication-common.h + +all: all-recursive + +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/replication/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/replication/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +# This directory's subdirectories are mostly independent; you can cd +# into them and run 'make' without going through this Makefile. +# To change the values of 'make' variables: instead of editing Makefiles, +# (1) if the variable is set in 'config.status', edit 'config.status' +# (which will cause the Makefiles to be regenerated when you run 'make'); +# (2) otherwise, pass the desired values on the 'make' command line. +$(am__recursive_targets): + @fail=; \ + if $(am__make_keepgoing); then \ + failcom='fail=yes'; \ + else \ + failcom='exit 1'; \ + fi; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-recursive +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-recursive + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-recursive + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + $(am__make_dryrun) \ + || test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ + $(am__relativize); \ + new_distdir=$$reldir; \ + dir1=$$subdir; dir2="$(top_distdir)"; \ + $(am__relativize); \ + new_top_distdir=$$reldir; \ + echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ + echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ + ($(am__cd) $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$new_top_distdir" \ + distdir="$$new_distdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + am__skip_mode_fix=: \ + distdir) \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-recursive +all-am: Makefile $(HEADERS) +installdirs: installdirs-recursive +installdirs-am: +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-recursive + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +html-am: + +info: info-recursive + +info-am: + +install-data-am: + +install-dvi: install-dvi-recursive + +install-dvi-am: + +install-exec-am: + +install-html: install-html-recursive + +install-html-am: + +install-info: install-info-recursive + +install-info-am: + +install-man: + +install-pdf: install-pdf-recursive + +install-pdf-am: + +install-ps: install-ps-recursive + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: + +.MAKE: $(am__recursive_targets) install-am install-strip + +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \ + check-am clean clean-generic clean-libtool cscopelist-am ctags \ + ctags-am distclean distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + installdirs-am maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \ + ps ps-am tags tags-am uninstall uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/replication/aggregator/Makefile.am b/src/replication/aggregator/Makefile.am new file mode 100644 index 0000000..a0b3501 --- /dev/null +++ b/src/replication/aggregator/Makefile.am @@ -0,0 +1,29 @@ +pkglibexecdir = $(libexecdir)/dovecot + +pkglibexec_PROGRAMS = aggregator + +AM_CPPFLAGS = \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-settings \ + -I$(top_srcdir)/src/lib-auth \ + -I$(top_srcdir)/src/lib-master \ + -I$(top_srcdir)/src/replication \ + -DPKG_STATEDIR=\""$(statedir)"\" \ + $(BINARY_CFLAGS) + +aggregator_LDFLAGS = -export-dynamic \ + $(BINARY_LDFLAGS) + +aggregator_LDADD = $(LIBDOVECOT) +aggregator_DEPENDENCIES = $(LIBDOVECOT_DEPS) + +aggregator_SOURCES = \ + aggregator.c \ + aggregator-settings.c \ + notify-connection.c \ + replicator-connection.c + +noinst_HEADERS = \ + aggregator-settings.h \ + notify-connection.h \ + replicator-connection.h diff --git a/src/replication/aggregator/Makefile.in b/src/replication/aggregator/Makefile.in new file mode 100644 index 0000000..a7bfbe5 --- /dev/null +++ b/src/replication/aggregator/Makefile.in @@ -0,0 +1,828 @@ +# Makefile.in generated by automake 1.16.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2020 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +pkglibexec_PROGRAMS = aggregator$(EXEEXT) +subdir = src/replication/aggregator +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ac_checktype2.m4 \ + $(top_srcdir)/m4/ac_typeof.m4 $(top_srcdir)/m4/arc4random.m4 \ + $(top_srcdir)/m4/blockdev.m4 $(top_srcdir)/m4/c99_vsnprintf.m4 \ + $(top_srcdir)/m4/clock_gettime.m4 $(top_srcdir)/m4/crypt.m4 \ + $(top_srcdir)/m4/crypt_xpg6.m4 $(top_srcdir)/m4/dbqlk.m4 \ + $(top_srcdir)/m4/dirent_dtype.m4 $(top_srcdir)/m4/dovecot.m4 \ + $(top_srcdir)/m4/fd_passing.m4 $(top_srcdir)/m4/fdatasync.m4 \ + $(top_srcdir)/m4/flexible_array_member.m4 \ + $(top_srcdir)/m4/glibc.m4 $(top_srcdir)/m4/gmtime_max.m4 \ + $(top_srcdir)/m4/gmtime_tm_gmtoff.m4 \ + $(top_srcdir)/m4/ioloop.m4 $(top_srcdir)/m4/iovec.m4 \ + $(top_srcdir)/m4/ipv6.m4 $(top_srcdir)/m4/libcap.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/libwrap.m4 \ + $(top_srcdir)/m4/linux_mremap.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/mmap_write.m4 \ + $(top_srcdir)/m4/mntctl.m4 $(top_srcdir)/m4/modules.m4 \ + $(top_srcdir)/m4/notify.m4 $(top_srcdir)/m4/nsl.m4 \ + $(top_srcdir)/m4/off_t_max.m4 $(top_srcdir)/m4/pkg.m4 \ + $(top_srcdir)/m4/pr_set_dumpable.m4 \ + $(top_srcdir)/m4/q_quotactl.m4 $(top_srcdir)/m4/quota.m4 \ + $(top_srcdir)/m4/random.m4 $(top_srcdir)/m4/rlimit.m4 \ + $(top_srcdir)/m4/sendfile.m4 $(top_srcdir)/m4/size_t_signed.m4 \ + $(top_srcdir)/m4/sockpeercred.m4 $(top_srcdir)/m4/sql.m4 \ + $(top_srcdir)/m4/ssl.m4 $(top_srcdir)/m4/st_tim.m4 \ + $(top_srcdir)/m4/static_array.m4 $(top_srcdir)/m4/test_with.m4 \ + $(top_srcdir)/m4/time_t.m4 $(top_srcdir)/m4/typeof.m4 \ + $(top_srcdir)/m4/typeof_dev_t.m4 \ + $(top_srcdir)/m4/uoff_t_max.m4 $(top_srcdir)/m4/vararg.m4 \ + $(top_srcdir)/m4/want_apparmor.m4 \ + $(top_srcdir)/m4/want_bsdauth.m4 \ + $(top_srcdir)/m4/want_bzlib.m4 \ + $(top_srcdir)/m4/want_cassandra.m4 \ + $(top_srcdir)/m4/want_cdb.m4 \ + $(top_srcdir)/m4/want_checkpassword.m4 \ + $(top_srcdir)/m4/want_clucene.m4 $(top_srcdir)/m4/want_db.m4 \ + $(top_srcdir)/m4/want_gssapi.m4 $(top_srcdir)/m4/want_icu.m4 \ + $(top_srcdir)/m4/want_ldap.m4 $(top_srcdir)/m4/want_lua.m4 \ + $(top_srcdir)/m4/want_lz4.m4 $(top_srcdir)/m4/want_lzma.m4 \ + $(top_srcdir)/m4/want_mysql.m4 $(top_srcdir)/m4/want_pam.m4 \ + $(top_srcdir)/m4/want_passwd.m4 $(top_srcdir)/m4/want_pgsql.m4 \ + $(top_srcdir)/m4/want_prefetch.m4 \ + $(top_srcdir)/m4/want_shadow.m4 \ + $(top_srcdir)/m4/want_sodium.m4 $(top_srcdir)/m4/want_solr.m4 \ + $(top_srcdir)/m4/want_sqlite.m4 \ + $(top_srcdir)/m4/want_stemmer.m4 \ + $(top_srcdir)/m4/want_systemd.m4 \ + $(top_srcdir)/m4/want_textcat.m4 \ + $(top_srcdir)/m4/want_unwind.m4 $(top_srcdir)/m4/want_zlib.m4 \ + $(top_srcdir)/m4/want_zstd.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(pkglibexecdir)" +PROGRAMS = $(pkglibexec_PROGRAMS) +am_aggregator_OBJECTS = aggregator.$(OBJEXT) \ + aggregator-settings.$(OBJEXT) notify-connection.$(OBJEXT) \ + replicator-connection.$(OBJEXT) +aggregator_OBJECTS = $(am_aggregator_OBJECTS) +am__DEPENDENCIES_1 = +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +aggregator_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(aggregator_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/aggregator-settings.Po \ + ./$(DEPDIR)/aggregator.Po ./$(DEPDIR)/notify-connection.Po \ + ./$(DEPDIR)/replicator-connection.Po +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(aggregator_SOURCES) +DIST_SOURCES = $(aggregator_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +pkglibexecdir = $(libexecdir)/dovecot +ACLOCAL = @ACLOCAL@ +ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +APPARMOR_LIBS = @APPARMOR_LIBS@ +AR = @AR@ +AUTH_CFLAGS = @AUTH_CFLAGS@ +AUTH_LIBS = @AUTH_LIBS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BINARY_CFLAGS = @BINARY_CFLAGS@ +BINARY_LDFLAGS = @BINARY_LDFLAGS@ +BISON = @BISON@ +CASSANDRA_CFLAGS = @CASSANDRA_CFLAGS@ +CASSANDRA_LIBS = @CASSANDRA_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CDB_LIBS = @CDB_LIBS@ +CFLAGS = @CFLAGS@ +CLUCENE_CFLAGS = @CLUCENE_CFLAGS@ +CLUCENE_LIBS = @CLUCENE_LIBS@ +COMPRESS_LIBS = @COMPRESS_LIBS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CRYPT_LIBS = @CRYPT_LIBS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DICT_LIBS = @DICT_LIBS@ +DLLIB = @DLLIB@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +FLEX = @FLEX@ +FUZZER_CPPFLAGS = @FUZZER_CPPFLAGS@ +FUZZER_LDFLAGS = @FUZZER_LDFLAGS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +KRB5CONFIG = @KRB5CONFIG@ +KRB5_CFLAGS = @KRB5_CFLAGS@ +KRB5_LIBS = @KRB5_LIBS@ +LD = @LD@ +LDAP_LIBS = @LDAP_LIBS@ +LDFLAGS = @LDFLAGS@ +LD_NO_WHOLE_ARCHIVE = @LD_NO_WHOLE_ARCHIVE@ +LD_WHOLE_ARCHIVE = @LD_WHOLE_ARCHIVE@ +LIBCAP = @LIBCAP@ +LIBDOVECOT = @LIBDOVECOT@ +LIBDOVECOT_COMPRESS = @LIBDOVECOT_COMPRESS@ +LIBDOVECOT_DEPS = @LIBDOVECOT_DEPS@ +LIBDOVECOT_DSYNC = @LIBDOVECOT_DSYNC@ +LIBDOVECOT_LA_LIBS = @LIBDOVECOT_LA_LIBS@ +LIBDOVECOT_LDA = @LIBDOVECOT_LDA@ +LIBDOVECOT_LDAP = @LIBDOVECOT_LDAP@ +LIBDOVECOT_LIBFTS = @LIBDOVECOT_LIBFTS@ +LIBDOVECOT_LIBFTS_DEPS = @LIBDOVECOT_LIBFTS_DEPS@ +LIBDOVECOT_LOGIN = @LIBDOVECOT_LOGIN@ +LIBDOVECOT_LUA = @LIBDOVECOT_LUA@ +LIBDOVECOT_LUA_DEPS = @LIBDOVECOT_LUA_DEPS@ +LIBDOVECOT_SQL = @LIBDOVECOT_SQL@ +LIBDOVECOT_STORAGE = @LIBDOVECOT_STORAGE@ +LIBDOVECOT_STORAGE_DEPS = @LIBDOVECOT_STORAGE_DEPS@ +LIBEXTTEXTCAT_CFLAGS = @LIBEXTTEXTCAT_CFLAGS@ +LIBEXTTEXTCAT_LIBS = @LIBEXTTEXTCAT_LIBS@ +LIBICONV = @LIBICONV@ +LIBICU_CFLAGS = @LIBICU_CFLAGS@ +LIBICU_LIBS = @LIBICU_LIBS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBSODIUM_CFLAGS = @LIBSODIUM_CFLAGS@ +LIBSODIUM_LIBS = @LIBSODIUM_LIBS@ +LIBTIRPC_CFLAGS = @LIBTIRPC_CFLAGS@ +LIBTIRPC_LIBS = @LIBTIRPC_LIBS@ +LIBTOOL = @LIBTOOL@ +LIBUNWIND_CFLAGS = @LIBUNWIND_CFLAGS@ +LIBUNWIND_LIBS = @LIBUNWIND_LIBS@ +LIBWRAP_LIBS = @LIBWRAP_LIBS@ +LINKED_STORAGE_LDADD = @LINKED_STORAGE_LDADD@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +LUA_CFLAGS = @LUA_CFLAGS@ +LUA_LIBS = @LUA_LIBS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +MODULE_LIBS = @MODULE_LIBS@ +MODULE_SUFFIX = @MODULE_SUFFIX@ +MYSQL_CFLAGS = @MYSQL_CFLAGS@ +MYSQL_CONFIG = @MYSQL_CONFIG@ +MYSQL_LIBS = @MYSQL_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +NOPLUGIN_LDFLAGS = @NOPLUGIN_LDFLAGS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANDOC = @PANDOC@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PGSQL_CFLAGS = @PGSQL_CFLAGS@ +PGSQL_LIBS = @PGSQL_LIBS@ +PG_CONFIG = @PG_CONFIG@ +PIE_CFLAGS = @PIE_CFLAGS@ +PIE_LDFLAGS = @PIE_LDFLAGS@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +QUOTA_LIBS = @QUOTA_LIBS@ +RANLIB = @RANLIB@ +RELRO_LDFLAGS = @RELRO_LDFLAGS@ +RPCGEN = @RPCGEN@ +RUN_TEST = @RUN_TEST@ +SED = @SED@ +SETTING_FILES = @SETTING_FILES@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SQLITE_CFLAGS = @SQLITE_CFLAGS@ +SQLITE_LIBS = @SQLITE_LIBS@ +SQL_CFLAGS = @SQL_CFLAGS@ +SQL_LIBS = @SQL_LIBS@ +SSL_CFLAGS = @SSL_CFLAGS@ +SSL_LIBS = @SSL_LIBS@ +STRIP = @STRIP@ +SYSTEMD_CFLAGS = @SYSTEMD_CFLAGS@ +SYSTEMD_LIBS = @SYSTEMD_LIBS@ +VALGRIND = @VALGRIND@ +VERSION = @VERSION@ +ZSTD_CFLAGS = @ZSTD_CFLAGS@ +ZSTD_LIBS = @ZSTD_LIBS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +dict_drivers = @dict_drivers@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +moduledir = @moduledir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +rundir = @rundir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sql_drivers = @sql_drivers@ +srcdir = @srcdir@ +ssldir = @ssldir@ +statedir = @statedir@ +sysconfdir = @sysconfdir@ +systemdservicetype = @systemdservicetype@ +systemdsystemunitdir = @systemdsystemunitdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +AM_CPPFLAGS = \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-settings \ + -I$(top_srcdir)/src/lib-auth \ + -I$(top_srcdir)/src/lib-master \ + -I$(top_srcdir)/src/replication \ + -DPKG_STATEDIR=\""$(statedir)"\" \ + $(BINARY_CFLAGS) + +aggregator_LDFLAGS = -export-dynamic \ + $(BINARY_LDFLAGS) + +aggregator_LDADD = $(LIBDOVECOT) +aggregator_DEPENDENCIES = $(LIBDOVECOT_DEPS) +aggregator_SOURCES = \ + aggregator.c \ + aggregator-settings.c \ + notify-connection.c \ + replicator-connection.c + +noinst_HEADERS = \ + aggregator-settings.h \ + notify-connection.h \ + replicator-connection.h + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/replication/aggregator/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/replication/aggregator/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-pkglibexecPROGRAMS: $(pkglibexec_PROGRAMS) + @$(NORMAL_INSTALL) + @list='$(pkglibexec_PROGRAMS)'; test -n "$(pkglibexecdir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(pkglibexecdir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(pkglibexecdir)" || exit 1; \ + fi; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p \ + || test -f $$p1 \ + ; then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' \ + -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(pkglibexecdir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(pkglibexecdir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-pkglibexecPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(pkglibexec_PROGRAMS)'; test -n "$(pkglibexecdir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' \ + `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(pkglibexecdir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(pkglibexecdir)" && rm -f $$files + +clean-pkglibexecPROGRAMS: + @list='$(pkglibexec_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list + +aggregator$(EXEEXT): $(aggregator_OBJECTS) $(aggregator_DEPENDENCIES) $(EXTRA_aggregator_DEPENDENCIES) + @rm -f aggregator$(EXEEXT) + $(AM_V_CCLD)$(aggregator_LINK) $(aggregator_OBJECTS) $(aggregator_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/aggregator-settings.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/aggregator.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/notify-connection.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/replicator-connection.Po@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(pkglibexecdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-pkglibexecPROGRAMS \ + mostlyclean-am + +distclean: distclean-am + -rm -f ./$(DEPDIR)/aggregator-settings.Po + -rm -f ./$(DEPDIR)/aggregator.Po + -rm -f ./$(DEPDIR)/notify-connection.Po + -rm -f ./$(DEPDIR)/replicator-connection.Po + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-pkglibexecPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f ./$(DEPDIR)/aggregator-settings.Po + -rm -f ./$(DEPDIR)/aggregator.Po + -rm -f ./$(DEPDIR)/notify-connection.Po + -rm -f ./$(DEPDIR)/replicator-connection.Po + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-pkglibexecPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ + clean-generic clean-libtool clean-pkglibexecPROGRAMS \ + cscopelist-am ctags ctags-am distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-pkglibexecPROGRAMS install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am uninstall-pkglibexecPROGRAMS + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/replication/aggregator/aggregator-settings.c b/src/replication/aggregator/aggregator-settings.c new file mode 100644 index 0000000..98597bd --- /dev/null +++ b/src/replication/aggregator/aggregator-settings.c @@ -0,0 +1,85 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "buffer.h" +#include "settings-parser.h" +#include "service-settings.h" +#include "aggregator-settings.h" + +/* */ +static struct file_listener_settings aggregator_unix_listeners_array[] = { + { "replication-notify", 0600, "", "" } +}; +static struct file_listener_settings *aggregator_unix_listeners[] = { + &aggregator_unix_listeners_array[0] +}; +static buffer_t aggregator_unix_listeners_buf = { + { { aggregator_unix_listeners, sizeof(aggregator_unix_listeners) } } +}; + +static struct file_listener_settings aggregator_fifo_listeners_array[] = { + { "replication-notify-fifo", 0600, "", "" } +}; +static struct file_listener_settings *aggregator_fifo_listeners[] = { + &aggregator_fifo_listeners_array[0] +}; +static buffer_t aggregator_fifo_listeners_buf = { + { { aggregator_fifo_listeners, sizeof(aggregator_fifo_listeners) } } +}; +/* */ + +struct service_settings aggregator_service_settings = { + .name = "aggregator", + .protocol = "", + .type = "", + .executable = "aggregator", + .user = "$default_internal_user", + .group = "", + .privileged_group = "", + .extra_groups = "", + .chroot = ".", + + .drop_priv_before_exec = FALSE, + + .process_min_avail = 0, + .process_limit = 0, + .client_limit = 0, + .service_count = 0, + .idle_kill = 0, + .vsz_limit = UOFF_T_MAX, + + .unix_listeners = { { &aggregator_unix_listeners_buf, + sizeof(aggregator_unix_listeners[0]) } }, + .fifo_listeners = { { &aggregator_fifo_listeners_buf, + sizeof(aggregator_fifo_listeners[0]) } }, + .inet_listeners = ARRAY_INIT +}; + +#undef DEF +#define DEF(type, name) \ + SETTING_DEFINE_STRUCT_##type(#name, name, struct aggregator_settings) + +static const struct setting_define aggregator_setting_defines[] = { + DEF(STR, replicator_host), + DEF(IN_PORT, replicator_port), + + SETTING_DEFINE_LIST_END +}; + +const struct aggregator_settings aggregator_default_settings = { + .replicator_host = "replicator", + .replicator_port = 0 +}; + +const struct setting_parser_info aggregator_setting_parser_info = { + .module_name = "aggregator", + .defines = aggregator_setting_defines, + .defaults = &aggregator_default_settings, + + .type_offset = SIZE_MAX, + .struct_size = sizeof(struct aggregator_settings), + + .parent_offset = SIZE_MAX +}; + +const struct aggregator_settings *aggregator_settings; diff --git a/src/replication/aggregator/aggregator-settings.h b/src/replication/aggregator/aggregator-settings.h new file mode 100644 index 0000000..06c8ac3 --- /dev/null +++ b/src/replication/aggregator/aggregator-settings.h @@ -0,0 +1,12 @@ +#ifndef AGGREGATOR_SETTINGS_H +#define AGGREGATOR_SETTINGS_H + +struct aggregator_settings { + const char *replicator_host; + in_port_t replicator_port; +}; + +extern const struct setting_parser_info aggregator_setting_parser_info; +extern const struct aggregator_settings *aggregator_settings; + +#endif diff --git a/src/replication/aggregator/aggregator.c b/src/replication/aggregator/aggregator.c new file mode 100644 index 0000000..1677f9f --- /dev/null +++ b/src/replication/aggregator/aggregator.c @@ -0,0 +1,74 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "restrict-access.h" +#include "master-service.h" +#include "master-service-settings.h" +#include "aggregator-settings.h" +#include "notify-connection.h" +#include "replicator-connection.h" + +struct replicator_connection *replicator; + +static void client_connected(struct master_service_connection *conn) +{ + master_service_client_connection_accept(conn); + notify_connection_create(conn->fd, conn->fifo); +} + +static void main_preinit(void) +{ + struct ip_addr *ips; + unsigned int ips_count; + const struct aggregator_settings *set; + void **sets; + int ret; + + sets = master_service_settings_get_others(master_service); + set = sets[0]; + + if (set->replicator_port != 0) { + ret = net_gethostbyname(set->replicator_host, &ips, &ips_count); + if (ret != 0) { + i_fatal("replicator_host: gethostbyname(%s) failed: %s", + set->replicator_host, net_gethosterror(ret)); + } + replicator = replicator_connection_create_inet(ips, ips_count, + set->replicator_port, + notify_connection_sync_callback); + } else { + replicator = replicator_connection_create_unix(set->replicator_host, + notify_connection_sync_callback); + } +} + +int main(int argc, char *argv[]) +{ + const struct setting_parser_info *set_roots[] = { + &aggregator_setting_parser_info, + NULL + }; + const char *error; + + master_service = master_service_init("aggregator", 0, &argc, &argv, ""); + if (master_getopt(master_service) > 0) + return FATAL_DEFAULT; + + if (master_service_settings_read_simple(master_service, set_roots, + &error) < 0) + i_fatal("Error reading configuration: %s", error); + master_service_init_log(master_service); + + main_preinit(); + + restrict_access_by_env(RESTRICT_ACCESS_FLAG_ALLOW_ROOT, NULL); + restrict_access_allow_coredumps(TRUE); + master_service_init_finish(master_service); + + master_service_run(master_service, client_connected); + + notify_connections_destroy_all(); + replicator_connection_destroy(&replicator); + master_service_deinit(&master_service); + return 0; +} diff --git a/src/replication/aggregator/notify-connection.c b/src/replication/aggregator/notify-connection.c new file mode 100644 index 0000000..f9587fe --- /dev/null +++ b/src/replication/aggregator/notify-connection.c @@ -0,0 +1,154 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "ioloop.h" +#include "net.h" +#include "istream.h" +#include "ostream.h" +#include "llist.h" +#include "strescape.h" +#include "master-service.h" +#include "replication-common.h" +#include "replicator-connection.h" +#include "notify-connection.h" + +#define MAX_INBUF_SIZE 8192 + +#define CONNECTION_IS_FIFO(conn) \ + ((conn)->output == NULL) + +struct notify_connection { + struct notify_connection *prev, *next; + int refcount; + + int fd; + struct io *io; + struct istream *input; + struct ostream *output; +}; + +static struct notify_connection *conns = NULL; + +static void notify_connection_unref(struct notify_connection *conn); +static void notify_connection_destroy(struct notify_connection *conn); + +static bool notify_input_error(struct notify_connection *conn) +{ + if (CONNECTION_IS_FIFO(conn)) + return TRUE; + notify_connection_destroy(conn); + return FALSE; +} + +void notify_connection_sync_callback(bool success, void *context) +{ + struct notify_connection *conn = context; + + o_stream_nsend_str(conn->output, success ? "+\n" : "-\n"); + notify_connection_unref(conn); +} + +static int +notify_input_line(struct notify_connection *conn, const char *line) +{ + const char *const *args; + enum replication_priority priority; + + /* \t */ + args = t_strsplit_tabescaped(line); + if (str_array_length(args) < 2) { + i_error("Client sent invalid input"); + return -1; + } + if (replication_priority_parse(args[1], &priority) < 0) { + i_error("Client sent invalid priority: %s", args[1]); + return -1; + } + if (priority != REPLICATION_PRIORITY_SYNC) + replicator_connection_notify(replicator, args[0], priority); + else { + conn->refcount++; + replicator_connection_notify_sync(replicator, args[0], conn); + } + return 0; +} + +static void notify_input(struct notify_connection *conn) +{ + const char *line; + int ret; + + switch (i_stream_read(conn->input)) { + case -2: + /* buffer full */ + i_error("Client sent too long line"); + (void)notify_input_error(conn); + return; + case -1: + /* disconnected */ + notify_connection_destroy(conn); + return; + } + + while ((line = i_stream_next_line(conn->input)) != NULL) { + T_BEGIN { + ret = notify_input_line(conn, line); + } T_END; + if (ret < 0) { + if (!notify_input_error(conn)) + return; + } + } +} + +void notify_connection_create(int fd, bool fifo) +{ + struct notify_connection *conn; + + conn = i_new(struct notify_connection, 1); + conn->refcount = 1; + conn->fd = fd; + conn->io = io_add(fd, IO_READ, notify_input, conn); + conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE); + if (!fifo) { + conn->output = o_stream_create_fd(fd, SIZE_MAX); + o_stream_set_no_error_handling(conn->output, TRUE); + } + + DLLIST_PREPEND(&conns, conn); +} + +static void notify_connection_unref(struct notify_connection *conn) +{ + i_assert(conn->refcount > 0); + if (--conn->refcount > 0) + return; + + i_stream_destroy(&conn->input); + o_stream_destroy(&conn->output); + i_free(conn); +} + +static void notify_connection_destroy(struct notify_connection *conn) +{ + i_assert(conn->fd != -1); + + if (!CONNECTION_IS_FIFO(conn)) + master_service_client_connection_destroyed(master_service); + + DLLIST_REMOVE(&conns, conn); + + io_remove(&conn->io); + i_stream_close(conn->input); + o_stream_close(conn->output); + net_disconnect(conn->fd); + conn->fd = -1; + + notify_connection_unref(conn); +} + +void notify_connections_destroy_all(void) +{ + while (conns != NULL) + notify_connection_destroy(conns); +} diff --git a/src/replication/aggregator/notify-connection.h b/src/replication/aggregator/notify-connection.h new file mode 100644 index 0000000..790ae45 --- /dev/null +++ b/src/replication/aggregator/notify-connection.h @@ -0,0 +1,9 @@ +#ifndef NOTIFY_CONNECTION_H +#define NOTIFY_CONNECTION_H + +void notify_connection_create(int fd, bool fifo); +void notify_connections_destroy_all(void); + +void notify_connection_sync_callback(bool success, void *context); + +#endif diff --git a/src/replication/aggregator/replicator-connection.c b/src/replication/aggregator/replicator-connection.c new file mode 100644 index 0000000..9275376 --- /dev/null +++ b/src/replication/aggregator/replicator-connection.c @@ -0,0 +1,326 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "ioloop.h" +#include "net.h" +#include "istream.h" +#include "ostream.h" +#include "buffer.h" +#include "hash.h" +#include "llist.h" +#include "strescape.h" +#include "replicator-connection.h" + +#define MAX_INBUF_SIZE 1024 +#define REPLICATOR_RECONNECT_MSECS 5000 +#define REPLICATOR_MEMBUF_MAX_SIZE 1024*1024 +#define REPLICATOR_HANDSHAKE "VERSION\treplicator-notify\t1\t0\n" + +struct replicator_connection { + char *path; + struct ip_addr *ips; + unsigned int ips_count, ip_idx; + in_port_t port; + + int fd; + struct io *io; + struct istream *input; + struct ostream *output; + struct timeout *to; + + buffer_t *queue[REPLICATION_PRIORITY_SYNC + 1]; + + HASH_TABLE(void *, void *) requests; + unsigned int request_id_counter; + replicator_sync_callback_t *callback; +}; + +static void replicator_connection_disconnect(struct replicator_connection *conn); + +static int +replicator_input_line(struct replicator_connection *conn, const char *line) +{ + void *context; + unsigned int id; + + /* <+|-> \t */ + if ((line[0] != '+' && line[0] != '-') || line[1] != '\t' || + str_to_uint(line+2, &id) < 0 || id == 0) { + i_error("Replicator sent invalid input: %s", line); + return -1; + } + + context = hash_table_lookup(conn->requests, POINTER_CAST(id)); + if (context == NULL) { + i_error("Replicator sent invalid ID: %u", id); + return -1; + } + hash_table_remove(conn->requests, POINTER_CAST(id)); + conn->callback(line[0] == '+', context); + return 0; +} + +static void replicator_input(struct replicator_connection *conn) +{ + const char *line; + + switch (i_stream_read(conn->input)) { + case -2: + /* buffer full */ + i_error("Replicator sent too long line"); + replicator_connection_disconnect(conn); + return; + case -1: + /* disconnected */ + replicator_connection_disconnect(conn); + return; + } + + while ((line = i_stream_next_line(conn->input)) != NULL) + (void)replicator_input_line(conn, line); +} + +static bool +replicator_send_buf(struct replicator_connection *conn, buffer_t *buf) +{ + const unsigned char *data = buf->data; + size_t len = IO_BLOCK_SIZE; + + /* try to send about IO_BLOCK_SIZE amount of data, + but only full lines */ + if (len > buf->used) + len = buf->used; + for (;; len++) { + i_assert(len < buf->used); /* there is always LF */ + if (data[len] == '\n') { + len++; + break; + } + } + + if (o_stream_send(conn->output, data, len) < 0) { + replicator_connection_disconnect(conn); + return FALSE; + } + buffer_delete(buf, 0, len); + return TRUE; +} + +static int replicator_output(struct replicator_connection *conn) +{ + enum replication_priority p; + + if (o_stream_flush(conn->output) < 0) { + replicator_connection_disconnect(conn); + return 1; + } + + for (p = REPLICATION_PRIORITY_SYNC;;) { + if (o_stream_get_buffer_used_size(conn->output) > 0) { + o_stream_set_flush_pending(conn->output, TRUE); + break; + } + /* output buffer is empty, send more data */ + if (conn->queue[p]->used > 0) { + if (!replicator_send_buf(conn, conn->queue[p])) + break; + } else { + if (p == REPLICATION_PRIORITY_LOW) + break; + p--; + } + } + return 1; +} + +static void replicator_connection_connect(struct replicator_connection *conn) +{ + unsigned int n; + int fd = -1; + + if (conn->fd != -1) + return; + + if (conn->port == 0) { + fd = net_connect_unix(conn->path); + if (fd == -1) + i_error("net_connect_unix(%s) failed: %m", conn->path); + } else { + for (n = 0; n < conn->ips_count; n++) { + unsigned int idx = conn->ip_idx; + + conn->ip_idx = (conn->ip_idx + 1) % conn->ips_count; + fd = net_connect_ip(&conn->ips[idx], conn->port, NULL); + if (fd != -1) + break; + i_error("connect(%s, %u) failed: %m", + net_ip2addr(&conn->ips[idx]), conn->port); + } + } + + if (fd == -1) { + if (conn->to == NULL) { + conn->to = timeout_add(REPLICATOR_RECONNECT_MSECS, + replicator_connection_connect, + conn); + } + return; + } + + timeout_remove(&conn->to); + conn->fd = fd; + conn->io = io_add(fd, IO_READ, replicator_input, conn); + conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE); + conn->output = o_stream_create_fd(fd, SIZE_MAX); + o_stream_set_no_error_handling(conn->output, TRUE); + o_stream_nsend_str(conn->output, REPLICATOR_HANDSHAKE); + o_stream_set_flush_callback(conn->output, replicator_output, conn); +} + +static void replicator_abort_all_requests(struct replicator_connection *conn) +{ + struct hash_iterate_context *iter; + void *key, *value; + + iter = hash_table_iterate_init(conn->requests); + while (hash_table_iterate(iter, conn->requests, &key, &value)) + conn->callback(FALSE, value); + hash_table_iterate_deinit(&iter); + hash_table_clear(conn->requests, TRUE); +} + +static void replicator_connection_disconnect(struct replicator_connection *conn) +{ + if (conn->fd == -1) + return; + + replicator_abort_all_requests(conn); + io_remove(&conn->io); + i_stream_destroy(&conn->input); + o_stream_destroy(&conn->output); + net_disconnect(conn->fd); + conn->fd = -1; +} + +static struct replicator_connection *replicator_connection_create(void) +{ + struct replicator_connection *conn; + unsigned int i; + + conn = i_new(struct replicator_connection, 1); + conn->fd = -1; + hash_table_create_direct(&conn->requests, default_pool, 0); + for (i = REPLICATION_PRIORITY_LOW; i <= REPLICATION_PRIORITY_SYNC; i++) + conn->queue[i] = buffer_create_dynamic(default_pool, 1024); + return conn; +} + +struct replicator_connection * +replicator_connection_create_unix(const char *path, + replicator_sync_callback_t *callback) +{ + struct replicator_connection *conn; + + conn = replicator_connection_create(); + conn->callback = callback; + conn->path = i_strdup(path); + return conn; +} + +struct replicator_connection * +replicator_connection_create_inet(const struct ip_addr *ips, + unsigned int ips_count, in_port_t port, + replicator_sync_callback_t *callback) +{ + struct replicator_connection *conn; + + conn = replicator_connection_create(); + conn->callback = callback; + conn->ips = i_new(struct ip_addr, ips_count); + memcpy(conn->ips, ips, sizeof(*ips) * ips_count); + conn->ips_count = ips_count; + conn->port = port; + return conn; +} + +void replicator_connection_destroy(struct replicator_connection **_conn) +{ + struct replicator_connection *conn = *_conn; + unsigned int i; + + *_conn = NULL; + replicator_connection_disconnect(conn); + + for (i = REPLICATION_PRIORITY_LOW; i <= REPLICATION_PRIORITY_SYNC; i++) + buffer_free(&conn->queue[i]); + + timeout_remove(&conn->to); + hash_table_destroy(&conn->requests); + i_free(conn->ips); + i_free(conn->path); + i_free(conn); +} + +static void +replicator_send(struct replicator_connection *conn, + enum replication_priority priority, const char *data) +{ + size_t data_len = strlen(data); + + if (conn->fd != -1 && + o_stream_get_buffer_used_size(conn->output) == 0) { + /* we can send data immediately */ + o_stream_nsend(conn->output, data, data_len); + } else if (conn->queue[priority]->used + data_len >= + REPLICATOR_MEMBUF_MAX_SIZE) { + /* FIXME: compress duplicates, start writing to file */ + } else { + /* queue internally to separate queues */ + buffer_append(conn->queue[priority], data, data_len); + if (conn->output != NULL) + o_stream_set_flush_pending(conn->output, TRUE); + } +} + +void replicator_connection_notify(struct replicator_connection *conn, + const char *username, + enum replication_priority priority) +{ + const char *priority_str = ""; + + replicator_connection_connect(conn); + + switch (priority) { + case REPLICATION_PRIORITY_NONE: + case REPLICATION_PRIORITY_SYNC: + i_unreached(); + case REPLICATION_PRIORITY_LOW: + priority_str = "low"; + break; + case REPLICATION_PRIORITY_HIGH: + priority_str = "high"; + break; + } + + T_BEGIN { + replicator_send(conn, priority, t_strdup_printf( + "U\t%s\t%s\n", str_tabescape(username), priority_str)); + } T_END; +} + +void replicator_connection_notify_sync(struct replicator_connection *conn, + const char *username, void *context) +{ + unsigned int id; + + replicator_connection_connect(conn); + + id = ++conn->request_id_counter; + if (id == 0) id++; + hash_table_insert(conn->requests, POINTER_CAST(id), context); + + T_BEGIN { + replicator_send(conn, REPLICATION_PRIORITY_SYNC, t_strdup_printf( + "U\t%s\tsync\t%u\n", str_tabescape(username), id)); + } T_END; +} diff --git a/src/replication/aggregator/replicator-connection.h b/src/replication/aggregator/replicator-connection.h new file mode 100644 index 0000000..bc2c82a --- /dev/null +++ b/src/replication/aggregator/replicator-connection.h @@ -0,0 +1,25 @@ +#ifndef REPLICATOR_CONNECTION_H +#define REPLICATOR_CONNECTION_H + +#include "replication-common.h" + +typedef void replicator_sync_callback_t(bool success, void *context); + +struct replicator_connection * +replicator_connection_create_unix(const char *path, + replicator_sync_callback_t *callback); +struct replicator_connection * +replicator_connection_create_inet(const struct ip_addr *ips, + unsigned int ips_count, in_port_t port, + replicator_sync_callback_t *callback); +void replicator_connection_destroy(struct replicator_connection **conn); + +void replicator_connection_notify(struct replicator_connection *conn, + const char *username, + enum replication_priority priority); +void replicator_connection_notify_sync(struct replicator_connection *conn, + const char *username, void *context); + +extern struct replicator_connection *replicator; + +#endif diff --git a/src/replication/replication-common.h b/src/replication/replication-common.h new file mode 100644 index 0000000..77f711c --- /dev/null +++ b/src/replication/replication-common.h @@ -0,0 +1,48 @@ +#ifndef REPLICATION_COMMON_H +#define REPLICATION_COMMON_H + +enum replication_priority { + /* user is fully replicated, as far as we know */ + REPLICATION_PRIORITY_NONE = 0, + /* flag changes, expunges, etc. */ + REPLICATION_PRIORITY_LOW, + /* new emails */ + REPLICATION_PRIORITY_HIGH, + /* synchronously wait for new emails to be replicated */ + REPLICATION_PRIORITY_SYNC +}; + +static inline const char * +replicator_priority_to_str(enum replication_priority priority) +{ + switch (priority) { + case REPLICATION_PRIORITY_NONE: + return "none"; + case REPLICATION_PRIORITY_LOW: + return "low"; + case REPLICATION_PRIORITY_HIGH: + return "high"; + case REPLICATION_PRIORITY_SYNC: + return "sync"; + } + i_unreached(); +} + +static inline int +replication_priority_parse(const char *str, + enum replication_priority *priority_r) +{ + if (strcmp(str, "none") == 0) + *priority_r = REPLICATION_PRIORITY_NONE; + else if (strcmp(str, "low") == 0) + *priority_r = REPLICATION_PRIORITY_LOW; + else if (strcmp(str, "high") == 0) + *priority_r = REPLICATION_PRIORITY_HIGH; + else if (strcmp(str, "sync") == 0) + *priority_r = REPLICATION_PRIORITY_SYNC; + else + return -1; + return 0; +} + +#endif diff --git a/src/replication/replicator/Makefile.am b/src/replication/replicator/Makefile.am new file mode 100644 index 0000000..dd2fc1d --- /dev/null +++ b/src/replication/replicator/Makefile.am @@ -0,0 +1,60 @@ +pkglibexecdir = $(libexecdir)/dovecot + +pkglibexec_PROGRAMS = replicator + +AM_CPPFLAGS = \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-test \ + -I$(top_srcdir)/src/lib-settings \ + -I$(top_srcdir)/src/lib-auth \ + -I$(top_srcdir)/src/lib-master \ + -I$(top_srcdir)/src/replication \ + -DPKG_STATEDIR=\""$(statedir)"\" \ + $(BINARY_CFLAGS) + +replicator_LDFLAGS = -export-dynamic \ + $(BINARY_LDFLAGS) + +replicator_LDADD = $(LIBDOVECOT) +replicator_DEPENDENCIES = $(LIBDOVECOT_DEPS) + +replicator_SOURCES = \ + doveadm-connection.c \ + dsync-client.c \ + replicator.c \ + replicator-brain.c \ + replicator-queue.c \ + replicator-queue-auth.c \ + replicator-settings.c \ + notify-connection.c + +noinst_HEADERS = \ + doveadm-connection.h \ + dsync-client.h \ + replicator-brain.h \ + replicator-queue.h \ + replicator-settings.h \ + notify-connection.h + +test_programs = \ + test-replicator-queue + +noinst_PROGRAMS = $(test_programs) + +test_libs = \ + ../../lib-test/libtest.la \ + ../../lib/liblib.la + +test_deps = $(test_libs) + +test_replicator_queue_SOURCES = \ + replicator-queue.c \ + replicator-settings.c \ + test-replicator-queue.c +test_replicator_queue_LDADD = $(test_libs) +test_replicator_queue_DEPENDENCIES = $(test_deps) + +check-local: + for bin in $(test_programs); do \ + if ! $(RUN_TEST) ./$$bin; then exit 1; fi; \ + done diff --git a/src/replication/replicator/Makefile.in b/src/replication/replicator/Makefile.in new file mode 100644 index 0000000..8547161 --- /dev/null +++ b/src/replication/replicator/Makefile.in @@ -0,0 +1,897 @@ +# Makefile.in generated by automake 1.16.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2020 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +pkglibexec_PROGRAMS = replicator$(EXEEXT) +noinst_PROGRAMS = $(am__EXEEXT_1) +subdir = src/replication/replicator +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ac_checktype2.m4 \ + $(top_srcdir)/m4/ac_typeof.m4 $(top_srcdir)/m4/arc4random.m4 \ + $(top_srcdir)/m4/blockdev.m4 $(top_srcdir)/m4/c99_vsnprintf.m4 \ + $(top_srcdir)/m4/clock_gettime.m4 $(top_srcdir)/m4/crypt.m4 \ + $(top_srcdir)/m4/crypt_xpg6.m4 $(top_srcdir)/m4/dbqlk.m4 \ + $(top_srcdir)/m4/dirent_dtype.m4 $(top_srcdir)/m4/dovecot.m4 \ + $(top_srcdir)/m4/fd_passing.m4 $(top_srcdir)/m4/fdatasync.m4 \ + $(top_srcdir)/m4/flexible_array_member.m4 \ + $(top_srcdir)/m4/glibc.m4 $(top_srcdir)/m4/gmtime_max.m4 \ + $(top_srcdir)/m4/gmtime_tm_gmtoff.m4 \ + $(top_srcdir)/m4/ioloop.m4 $(top_srcdir)/m4/iovec.m4 \ + $(top_srcdir)/m4/ipv6.m4 $(top_srcdir)/m4/libcap.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/libwrap.m4 \ + $(top_srcdir)/m4/linux_mremap.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/mmap_write.m4 \ + $(top_srcdir)/m4/mntctl.m4 $(top_srcdir)/m4/modules.m4 \ + $(top_srcdir)/m4/notify.m4 $(top_srcdir)/m4/nsl.m4 \ + $(top_srcdir)/m4/off_t_max.m4 $(top_srcdir)/m4/pkg.m4 \ + $(top_srcdir)/m4/pr_set_dumpable.m4 \ + $(top_srcdir)/m4/q_quotactl.m4 $(top_srcdir)/m4/quota.m4 \ + $(top_srcdir)/m4/random.m4 $(top_srcdir)/m4/rlimit.m4 \ + $(top_srcdir)/m4/sendfile.m4 $(top_srcdir)/m4/size_t_signed.m4 \ + $(top_srcdir)/m4/sockpeercred.m4 $(top_srcdir)/m4/sql.m4 \ + $(top_srcdir)/m4/ssl.m4 $(top_srcdir)/m4/st_tim.m4 \ + $(top_srcdir)/m4/static_array.m4 $(top_srcdir)/m4/test_with.m4 \ + $(top_srcdir)/m4/time_t.m4 $(top_srcdir)/m4/typeof.m4 \ + $(top_srcdir)/m4/typeof_dev_t.m4 \ + $(top_srcdir)/m4/uoff_t_max.m4 $(top_srcdir)/m4/vararg.m4 \ + $(top_srcdir)/m4/want_apparmor.m4 \ + $(top_srcdir)/m4/want_bsdauth.m4 \ + $(top_srcdir)/m4/want_bzlib.m4 \ + $(top_srcdir)/m4/want_cassandra.m4 \ + $(top_srcdir)/m4/want_cdb.m4 \ + $(top_srcdir)/m4/want_checkpassword.m4 \ + $(top_srcdir)/m4/want_clucene.m4 $(top_srcdir)/m4/want_db.m4 \ + $(top_srcdir)/m4/want_gssapi.m4 $(top_srcdir)/m4/want_icu.m4 \ + $(top_srcdir)/m4/want_ldap.m4 $(top_srcdir)/m4/want_lua.m4 \ + $(top_srcdir)/m4/want_lz4.m4 $(top_srcdir)/m4/want_lzma.m4 \ + $(top_srcdir)/m4/want_mysql.m4 $(top_srcdir)/m4/want_pam.m4 \ + $(top_srcdir)/m4/want_passwd.m4 $(top_srcdir)/m4/want_pgsql.m4 \ + $(top_srcdir)/m4/want_prefetch.m4 \ + $(top_srcdir)/m4/want_shadow.m4 \ + $(top_srcdir)/m4/want_sodium.m4 $(top_srcdir)/m4/want_solr.m4 \ + $(top_srcdir)/m4/want_sqlite.m4 \ + $(top_srcdir)/m4/want_stemmer.m4 \ + $(top_srcdir)/m4/want_systemd.m4 \ + $(top_srcdir)/m4/want_textcat.m4 \ + $(top_srcdir)/m4/want_unwind.m4 $(top_srcdir)/m4/want_zlib.m4 \ + $(top_srcdir)/m4/want_zstd.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__EXEEXT_1 = test-replicator-queue$(EXEEXT) +am__installdirs = "$(DESTDIR)$(pkglibexecdir)" +PROGRAMS = $(noinst_PROGRAMS) $(pkglibexec_PROGRAMS) +am_replicator_OBJECTS = doveadm-connection.$(OBJEXT) \ + dsync-client.$(OBJEXT) replicator.$(OBJEXT) \ + replicator-brain.$(OBJEXT) replicator-queue.$(OBJEXT) \ + replicator-queue-auth.$(OBJEXT) replicator-settings.$(OBJEXT) \ + notify-connection.$(OBJEXT) +replicator_OBJECTS = $(am_replicator_OBJECTS) +am__DEPENDENCIES_1 = +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +replicator_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(replicator_LDFLAGS) $(LDFLAGS) -o $@ +am_test_replicator_queue_OBJECTS = replicator-queue.$(OBJEXT) \ + replicator-settings.$(OBJEXT) test-replicator-queue.$(OBJEXT) +test_replicator_queue_OBJECTS = $(am_test_replicator_queue_OBJECTS) +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/doveadm-connection.Po \ + ./$(DEPDIR)/dsync-client.Po ./$(DEPDIR)/notify-connection.Po \ + ./$(DEPDIR)/replicator-brain.Po \ + ./$(DEPDIR)/replicator-queue-auth.Po \ + ./$(DEPDIR)/replicator-queue.Po \ + ./$(DEPDIR)/replicator-settings.Po ./$(DEPDIR)/replicator.Po \ + ./$(DEPDIR)/test-replicator-queue.Po +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(replicator_SOURCES) $(test_replicator_queue_SOURCES) +DIST_SOURCES = $(replicator_SOURCES) $(test_replicator_queue_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +pkglibexecdir = $(libexecdir)/dovecot +ACLOCAL = @ACLOCAL@ +ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +APPARMOR_LIBS = @APPARMOR_LIBS@ +AR = @AR@ +AUTH_CFLAGS = @AUTH_CFLAGS@ +AUTH_LIBS = @AUTH_LIBS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BINARY_CFLAGS = @BINARY_CFLAGS@ +BINARY_LDFLAGS = @BINARY_LDFLAGS@ +BISON = @BISON@ +CASSANDRA_CFLAGS = @CASSANDRA_CFLAGS@ +CASSANDRA_LIBS = @CASSANDRA_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CDB_LIBS = @CDB_LIBS@ +CFLAGS = @CFLAGS@ +CLUCENE_CFLAGS = @CLUCENE_CFLAGS@ +CLUCENE_LIBS = @CLUCENE_LIBS@ +COMPRESS_LIBS = @COMPRESS_LIBS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CRYPT_LIBS = @CRYPT_LIBS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DICT_LIBS = @DICT_LIBS@ +DLLIB = @DLLIB@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +FLEX = @FLEX@ +FUZZER_CPPFLAGS = @FUZZER_CPPFLAGS@ +FUZZER_LDFLAGS = @FUZZER_LDFLAGS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +KRB5CONFIG = @KRB5CONFIG@ +KRB5_CFLAGS = @KRB5_CFLAGS@ +KRB5_LIBS = @KRB5_LIBS@ +LD = @LD@ +LDAP_LIBS = @LDAP_LIBS@ +LDFLAGS = @LDFLAGS@ +LD_NO_WHOLE_ARCHIVE = @LD_NO_WHOLE_ARCHIVE@ +LD_WHOLE_ARCHIVE = @LD_WHOLE_ARCHIVE@ +LIBCAP = @LIBCAP@ +LIBDOVECOT = @LIBDOVECOT@ +LIBDOVECOT_COMPRESS = @LIBDOVECOT_COMPRESS@ +LIBDOVECOT_DEPS = @LIBDOVECOT_DEPS@ +LIBDOVECOT_DSYNC = @LIBDOVECOT_DSYNC@ +LIBDOVECOT_LA_LIBS = @LIBDOVECOT_LA_LIBS@ +LIBDOVECOT_LDA = @LIBDOVECOT_LDA@ +LIBDOVECOT_LDAP = @LIBDOVECOT_LDAP@ +LIBDOVECOT_LIBFTS = @LIBDOVECOT_LIBFTS@ +LIBDOVECOT_LIBFTS_DEPS = @LIBDOVECOT_LIBFTS_DEPS@ +LIBDOVECOT_LOGIN = @LIBDOVECOT_LOGIN@ +LIBDOVECOT_LUA = @LIBDOVECOT_LUA@ +LIBDOVECOT_LUA_DEPS = @LIBDOVECOT_LUA_DEPS@ +LIBDOVECOT_SQL = @LIBDOVECOT_SQL@ +LIBDOVECOT_STORAGE = @LIBDOVECOT_STORAGE@ +LIBDOVECOT_STORAGE_DEPS = @LIBDOVECOT_STORAGE_DEPS@ +LIBEXTTEXTCAT_CFLAGS = @LIBEXTTEXTCAT_CFLAGS@ +LIBEXTTEXTCAT_LIBS = @LIBEXTTEXTCAT_LIBS@ +LIBICONV = @LIBICONV@ +LIBICU_CFLAGS = @LIBICU_CFLAGS@ +LIBICU_LIBS = @LIBICU_LIBS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBSODIUM_CFLAGS = @LIBSODIUM_CFLAGS@ +LIBSODIUM_LIBS = @LIBSODIUM_LIBS@ +LIBTIRPC_CFLAGS = @LIBTIRPC_CFLAGS@ +LIBTIRPC_LIBS = @LIBTIRPC_LIBS@ +LIBTOOL = @LIBTOOL@ +LIBUNWIND_CFLAGS = @LIBUNWIND_CFLAGS@ +LIBUNWIND_LIBS = @LIBUNWIND_LIBS@ +LIBWRAP_LIBS = @LIBWRAP_LIBS@ +LINKED_STORAGE_LDADD = @LINKED_STORAGE_LDADD@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +LUA_CFLAGS = @LUA_CFLAGS@ +LUA_LIBS = @LUA_LIBS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +MODULE_LIBS = @MODULE_LIBS@ +MODULE_SUFFIX = @MODULE_SUFFIX@ +MYSQL_CFLAGS = @MYSQL_CFLAGS@ +MYSQL_CONFIG = @MYSQL_CONFIG@ +MYSQL_LIBS = @MYSQL_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +NOPLUGIN_LDFLAGS = @NOPLUGIN_LDFLAGS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANDOC = @PANDOC@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PGSQL_CFLAGS = @PGSQL_CFLAGS@ +PGSQL_LIBS = @PGSQL_LIBS@ +PG_CONFIG = @PG_CONFIG@ +PIE_CFLAGS = @PIE_CFLAGS@ +PIE_LDFLAGS = @PIE_LDFLAGS@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +QUOTA_LIBS = @QUOTA_LIBS@ +RANLIB = @RANLIB@ +RELRO_LDFLAGS = @RELRO_LDFLAGS@ +RPCGEN = @RPCGEN@ +RUN_TEST = @RUN_TEST@ +SED = @SED@ +SETTING_FILES = @SETTING_FILES@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SQLITE_CFLAGS = @SQLITE_CFLAGS@ +SQLITE_LIBS = @SQLITE_LIBS@ +SQL_CFLAGS = @SQL_CFLAGS@ +SQL_LIBS = @SQL_LIBS@ +SSL_CFLAGS = @SSL_CFLAGS@ +SSL_LIBS = @SSL_LIBS@ +STRIP = @STRIP@ +SYSTEMD_CFLAGS = @SYSTEMD_CFLAGS@ +SYSTEMD_LIBS = @SYSTEMD_LIBS@ +VALGRIND = @VALGRIND@ +VERSION = @VERSION@ +ZSTD_CFLAGS = @ZSTD_CFLAGS@ +ZSTD_LIBS = @ZSTD_LIBS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +dict_drivers = @dict_drivers@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +moduledir = @moduledir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +rundir = @rundir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sql_drivers = @sql_drivers@ +srcdir = @srcdir@ +ssldir = @ssldir@ +statedir = @statedir@ +sysconfdir = @sysconfdir@ +systemdservicetype = @systemdservicetype@ +systemdsystemunitdir = @systemdsystemunitdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +AM_CPPFLAGS = \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-test \ + -I$(top_srcdir)/src/lib-settings \ + -I$(top_srcdir)/src/lib-auth \ + -I$(top_srcdir)/src/lib-master \ + -I$(top_srcdir)/src/replication \ + -DPKG_STATEDIR=\""$(statedir)"\" \ + $(BINARY_CFLAGS) + +replicator_LDFLAGS = -export-dynamic \ + $(BINARY_LDFLAGS) + +replicator_LDADD = $(LIBDOVECOT) +replicator_DEPENDENCIES = $(LIBDOVECOT_DEPS) +replicator_SOURCES = \ + doveadm-connection.c \ + dsync-client.c \ + replicator.c \ + replicator-brain.c \ + replicator-queue.c \ + replicator-queue-auth.c \ + replicator-settings.c \ + notify-connection.c + +noinst_HEADERS = \ + doveadm-connection.h \ + dsync-client.h \ + replicator-brain.h \ + replicator-queue.h \ + replicator-settings.h \ + notify-connection.h + +test_programs = \ + test-replicator-queue + +test_libs = \ + ../../lib-test/libtest.la \ + ../../lib/liblib.la + +test_deps = $(test_libs) +test_replicator_queue_SOURCES = \ + replicator-queue.c \ + replicator-settings.c \ + test-replicator-queue.c + +test_replicator_queue_LDADD = $(test_libs) +test_replicator_queue_DEPENDENCIES = $(test_deps) +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/replication/replicator/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/replication/replicator/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstPROGRAMS: + @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +install-pkglibexecPROGRAMS: $(pkglibexec_PROGRAMS) + @$(NORMAL_INSTALL) + @list='$(pkglibexec_PROGRAMS)'; test -n "$(pkglibexecdir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(pkglibexecdir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(pkglibexecdir)" || exit 1; \ + fi; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p \ + || test -f $$p1 \ + ; then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' \ + -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(pkglibexecdir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(pkglibexecdir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-pkglibexecPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(pkglibexec_PROGRAMS)'; test -n "$(pkglibexecdir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' \ + `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(pkglibexecdir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(pkglibexecdir)" && rm -f $$files + +clean-pkglibexecPROGRAMS: + @list='$(pkglibexec_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list + +replicator$(EXEEXT): $(replicator_OBJECTS) $(replicator_DEPENDENCIES) $(EXTRA_replicator_DEPENDENCIES) + @rm -f replicator$(EXEEXT) + $(AM_V_CCLD)$(replicator_LINK) $(replicator_OBJECTS) $(replicator_LDADD) $(LIBS) + +test-replicator-queue$(EXEEXT): $(test_replicator_queue_OBJECTS) $(test_replicator_queue_DEPENDENCIES) $(EXTRA_test_replicator_queue_DEPENDENCIES) + @rm -f test-replicator-queue$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(test_replicator_queue_OBJECTS) $(test_replicator_queue_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/doveadm-connection.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dsync-client.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/notify-connection.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/replicator-brain.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/replicator-queue-auth.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/replicator-queue.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/replicator-settings.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/replicator.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-replicator-queue.Po@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) check-local +check: check-am +all-am: Makefile $(PROGRAMS) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(pkglibexecdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \ + clean-pkglibexecPROGRAMS mostlyclean-am + +distclean: distclean-am + -rm -f ./$(DEPDIR)/doveadm-connection.Po + -rm -f ./$(DEPDIR)/dsync-client.Po + -rm -f ./$(DEPDIR)/notify-connection.Po + -rm -f ./$(DEPDIR)/replicator-brain.Po + -rm -f ./$(DEPDIR)/replicator-queue-auth.Po + -rm -f ./$(DEPDIR)/replicator-queue.Po + -rm -f ./$(DEPDIR)/replicator-settings.Po + -rm -f ./$(DEPDIR)/replicator.Po + -rm -f ./$(DEPDIR)/test-replicator-queue.Po + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-pkglibexecPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f ./$(DEPDIR)/doveadm-connection.Po + -rm -f ./$(DEPDIR)/dsync-client.Po + -rm -f ./$(DEPDIR)/notify-connection.Po + -rm -f ./$(DEPDIR)/replicator-brain.Po + -rm -f ./$(DEPDIR)/replicator-queue-auth.Po + -rm -f ./$(DEPDIR)/replicator-queue.Po + -rm -f ./$(DEPDIR)/replicator-settings.Po + -rm -f ./$(DEPDIR)/replicator.Po + -rm -f ./$(DEPDIR)/test-replicator-queue.Po + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-pkglibexecPROGRAMS + +.MAKE: check-am install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am \ + check-local clean clean-generic clean-libtool \ + clean-noinstPROGRAMS clean-pkglibexecPROGRAMS cscopelist-am \ + ctags ctags-am distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-pkglibexecPROGRAMS install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am \ + uninstall-pkglibexecPROGRAMS + +.PRECIOUS: Makefile + + +check-local: + for bin in $(test_programs); do \ + if ! $(RUN_TEST) ./$$bin; then exit 1; fi; \ + done + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/replication/replicator/doveadm-connection.c b/src/replication/replicator/doveadm-connection.c new file mode 100644 index 0000000..1932bc6 --- /dev/null +++ b/src/replication/replicator/doveadm-connection.c @@ -0,0 +1,354 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "array.h" +#include "connection.h" +#include "ostream.h" +#include "str.h" +#include "strescape.h" +#include "wildcard-match.h" +#include "master-service.h" +#include "replicator-brain.h" +#include "replicator-queue.h" +#include "replicator-settings.h" +#include "dsync-client.h" +#include "doveadm-connection.h" + +#include + +#define REPLICATOR_DOVEADM_MAJOR_VERSION 1 +#define REPLICATOR_DOVEADM_MINOR_VERSION 0 + +struct doveadm_connection { + struct connection conn; + struct replicator_brain *brain; +}; +static struct connection_list *doveadm_connections; + +static int client_input_status_overview(struct doveadm_connection *client) +{ + struct replicator_queue *queue = + replicator_brain_get_queue(client->brain); + struct replicator_queue_iter *iter; + struct replicator_user *user; + enum replication_priority priority; + unsigned int pending_counts[REPLICATION_PRIORITY_SYNC+1]; + unsigned int user_count, next_secs, pending_failed_count; + unsigned int pending_full_resync_count, waiting_failed_count; + string_t *str = t_str_new(256); + + memset(pending_counts, 0, sizeof(pending_counts)); + pending_failed_count = 0; waiting_failed_count = 0; + pending_full_resync_count = 0; + + user_count = 0; + iter = replicator_queue_iter_init(queue); + while ((user = replicator_queue_iter_next(iter)) != NULL) { + if (user->priority != REPLICATION_PRIORITY_NONE) + pending_counts[user->priority]++; + else if (replicator_queue_want_sync_now(user, &next_secs)) { + if (user->last_sync_failed) + pending_failed_count++; + else + pending_full_resync_count++; + } else { + if (user->last_sync_failed) + waiting_failed_count++; + } + user_count++; + } + replicator_queue_iter_deinit(&iter); + + for (priority = REPLICATION_PRIORITY_SYNC; priority > 0; priority--) { + str_printfa(str, "Queued '%s' requests\t%u\n", + replicator_priority_to_str(priority), + pending_counts[priority]); + } + str_printfa(str, "Queued 'failed' requests\t%u\n", + pending_failed_count); + str_printfa(str, "Queued 'full resync' requests\t%u\n", + pending_full_resync_count); + str_printfa(str, "Waiting 'failed' requests\t%u\n", + waiting_failed_count); + str_printfa(str, "Total number of known users\t%u\n", user_count); + str_append_c(str, '\n'); + o_stream_nsend(client->conn.output, str_data(str), str_len(str)); + return 0; +} + +static int +client_input_status(struct doveadm_connection *client, const char *const *args) +{ + struct replicator_queue *queue = + replicator_brain_get_queue(client->brain); + struct replicator_queue_iter *iter; + struct replicator_user *user; + const char *mask = args[0]; + unsigned int next_secs; + string_t *str = t_str_new(128); + + if (mask == NULL) + return client_input_status_overview(client); + + iter = replicator_queue_iter_init(queue); + while ((user = replicator_queue_iter_next(iter)) != NULL) { + if (!wildcard_match(user->username, mask)) + continue; + + str_truncate(str, 0); + str_append_tabescaped(str, user->username); + str_append_c(str, '\t'); + str_append(str, replicator_priority_to_str(user->priority)); + if (replicator_queue_want_sync_now(user, &next_secs)) + next_secs = 0; + str_printfa(str, "\t%lld\t%lld\t%d\t%lld\t%u\n", + (long long)user->last_fast_sync, + (long long)user->last_full_sync, + user->last_sync_failed ? 1 : 0, + (long long)user->last_successful_sync, + next_secs); + o_stream_nsend(client->conn.output, str_data(str), str_len(str)); + } + replicator_queue_iter_deinit(&iter); + o_stream_nsend(client->conn.output, "\n", 1); + return 0; +} + +static int +client_input_status_dsyncs(struct doveadm_connection *client) +{ + string_t *str = t_str_new(256); + const ARRAY_TYPE(dsync_client) *clients; + struct dsync_client *dsync_client; + const char *username; + + clients = replicator_brain_get_dsync_clients(client->brain); + array_foreach_elem(clients, dsync_client) { + username = dsync_client_get_username(dsync_client); + if (username != NULL) { + str_append_tabescaped(str, username); + str_append_c(str, '\t'); + switch (dsync_client_get_type(dsync_client)) { + case DSYNC_TYPE_FULL: + str_append(str, "full"); + break; + case DSYNC_TYPE_NORMAL: + str_append(str, "normal"); + break; + case DSYNC_TYPE_INCREMENTAL: + str_append(str, "incremental"); + break; + } + } else { + str_append(str, "\t-"); + } + str_append_c(str, '\t'); + str_append_tabescaped(str, dsync_client_get_state(dsync_client)); + str_append_c(str, '\n'); + } + + str_append_c(str, '\n'); + o_stream_nsend(client->conn.output, str_data(str), str_len(str)); + return 0; +} + +static int +client_input_replicate(struct doveadm_connection *client, const char *const *args) +{ + struct replicator_queue *queue = + replicator_brain_get_queue(client->brain); + struct replicator_queue_iter *iter; + struct replicator_user *user; + const char *usermask; + enum replication_priority priority; + unsigned int match_count; + bool full; + + /* | */ + if (str_array_length(args) != 3) { + i_error("%s: REPLICATE: Invalid parameters", client->conn.name); + return -1; + } + if (replication_priority_parse(args[0], &priority) < 0) { + o_stream_nsend_str(client->conn.output, "-Invalid priority\n"); + return 0; + } + full = strchr(args[1], 'f') != NULL; + usermask = args[2]; + if (strchr(usermask, '*') == NULL && strchr(usermask, '?') == NULL) { + struct replicator_user *user = + replicator_queue_get(queue, usermask); + if (full) + user->force_full_sync = TRUE; + replicator_queue_update(queue, user, priority); + replicator_queue_add(queue, user); + o_stream_nsend_str(client->conn.output, "+1\n"); + return 0; + } + + match_count = 0; + iter = replicator_queue_iter_init(queue); + while ((user = replicator_queue_iter_next(iter)) != NULL) { + if (!wildcard_match(user->username, usermask)) + continue; + if (full) + user->force_full_sync = TRUE; + replicator_queue_update(queue, user, priority); + replicator_queue_add(queue, user); + match_count++; + } + replicator_queue_iter_deinit(&iter); + o_stream_nsend_str(client->conn.output, + t_strdup_printf("+%u\n", match_count)); + return 0; +} + +static int +client_input_add(struct doveadm_connection *client, const char *const *args) +{ + struct replicator_queue *queue = + replicator_brain_get_queue(client->brain); + const struct replicator_settings *set = + replicator_brain_get_settings(client->brain); + + /* */ + if (str_array_length(args) != 1) { + i_error("%s: ADD: Invalid parameters", client->conn.name); + return -1; + } + + if (strchr(args[0], '*') == NULL && strchr(args[0], '?') == NULL) { + struct replicator_user *user = + replicator_queue_get(queue, args[0]); + replicator_queue_add(queue, user); + } else { + replicator_queue_add_auth_users(queue, set->auth_socket_path, + args[0], ioloop_time); + } + o_stream_nsend_str(client->conn.output, "+\n"); + return 0; +} + +static int +client_input_remove(struct doveadm_connection *client, const char *const *args) +{ + struct replicator_queue *queue = + replicator_brain_get_queue(client->brain); + struct replicator_user *user; + + /* */ + if (str_array_length(args) != 1) { + i_error("%s: REMOVE: Invalid parameters", client->conn.name); + return -1; + } + user = replicator_queue_lookup(queue, args[0]); + if (user == NULL) + o_stream_nsend_str(client->conn.output, "-User not found\n"); + else { + replicator_queue_remove(queue, &user); + o_stream_nsend_str(client->conn.output, "+\n"); + } + return 0; +} + +static int +client_input_notify(struct doveadm_connection *client, const char *const *args) +{ + struct replicator_queue *queue = + replicator_brain_get_queue(client->brain); + struct replicator_user *user; + + /* */ + if (str_array_length(args) < 3) { + i_error("%s: NOTIFY: Invalid parameters", client->conn.name); + return -1; + } + + user = replicator_queue_get(queue, args[0]); + if (args[1][0] == 'f') + user->last_full_sync = ioloop_time; + user->last_fast_sync = ioloop_time; + user->last_update = ioloop_time; + replicator_queue_add(queue, user); + + if (args[2][0] != '\0') { + i_free(user->state); + user->state = i_strdup(args[2]); + } + o_stream_nsend_str(client->conn.output, "+\n"); + return 0; +} + +static int client_input_args(struct connection *conn, const char *const *args) +{ + struct doveadm_connection *client = (struct doveadm_connection *)conn; + const char *cmd = args[0]; + + if (cmd == NULL) { + i_error("%s: Empty command", conn->name); + return 0; + } + args++; + + if (strcmp(cmd, "STATUS") == 0) + return client_input_status(client, args); + else if (strcmp(cmd, "STATUS-DSYNC") == 0) + return client_input_status_dsyncs(client); + else if (strcmp(cmd, "REPLICATE") == 0) + return client_input_replicate(client, args); + else if (strcmp(cmd, "ADD") == 0) + return client_input_add(client, args); + else if (strcmp(cmd, "REMOVE") == 0) + return client_input_remove(client, args); + else if (strcmp(cmd, "NOTIFY") == 0) + return client_input_notify(client, args); + i_error("%s: Unknown command: %s", conn->name, cmd); + return -1; +} + +static void client_destroy(struct connection *conn) +{ + struct doveadm_connection *client = (struct doveadm_connection *)conn; + + connection_deinit(&client->conn); + i_free(client); + + master_service_client_connection_destroyed(master_service); +} + +void doveadm_connection_create(struct replicator_brain *brain, int fd) +{ + struct doveadm_connection *client; + + client = i_new(struct doveadm_connection, 1); + client->brain = brain; + connection_init_server(doveadm_connections, &client->conn, + "doveadm-client", fd, fd); +} + +static struct connection_settings doveadm_conn_set = { + .service_name_in = "replicator-doveadm-client", + .service_name_out = "replicator-doveadm-server", + .major_version = REPLICATOR_DOVEADM_MAJOR_VERSION, + .minor_version = REPLICATOR_DOVEADM_MINOR_VERSION, + + .input_max_size = SIZE_MAX, + .output_max_size = SIZE_MAX, + .client = FALSE +}; + +static const struct connection_vfuncs doveadm_conn_vfuncs = { + .destroy = client_destroy, + .input_args = client_input_args +}; + +void doveadm_connections_init(void) +{ + doveadm_connections = connection_list_init(&doveadm_conn_set, + &doveadm_conn_vfuncs); +} + +void doveadm_connections_deinit(void) +{ + connection_list_deinit(&doveadm_connections); +} diff --git a/src/replication/replicator/doveadm-connection.h b/src/replication/replicator/doveadm-connection.h new file mode 100644 index 0000000..066fc7b --- /dev/null +++ b/src/replication/replicator/doveadm-connection.h @@ -0,0 +1,11 @@ +#ifndef DOVEADM_CONNECTION_H +#define DOVEADM_CONNECTION_H + +struct replicator_brain; + +void doveadm_connection_create(struct replicator_brain *brain, int fd); + +void doveadm_connections_init(void); +void doveadm_connections_deinit(void); + +#endif diff --git a/src/replication/replicator/dsync-client.c b/src/replication/replicator/dsync-client.c new file mode 100644 index 0000000..2df12da --- /dev/null +++ b/src/replication/replicator/dsync-client.c @@ -0,0 +1,274 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "ioloop.h" +#include "net.h" +#include "istream.h" +#include "ostream.h" +#include "str.h" +#include "strescape.h" +#include "dsync-client.h" + +#include + +#define DSYNC_FAIL_TIMEOUT_MSECS (1000*5) +#define DOVEADM_HANDSHAKE "VERSION\tdoveadm-server\t1\t0\n" + +struct dsync_client { + char *path; + int fd; + struct io *io; + struct istream *input; + struct ostream *output; + struct timeout *to; + + char *dsync_params; + char *username; + char *state; + enum dsync_type sync_type; + dsync_callback_t *callback; + void *context; + + time_t last_connect_failure; + bool handshaked:1; + bool cmd_sent:1; +}; + +struct dsync_client * +dsync_client_init(const char *path, const char *dsync_params) +{ + struct dsync_client *client; + + client = i_new(struct dsync_client, 1); + client->path = i_strdup(path); + client->fd = -1; + client->dsync_params = i_strdup(dsync_params); + return client; +} + +static void dsync_callback(struct dsync_client *client, + const char *state, enum dsync_reply reply) +{ + dsync_callback_t *callback = client->callback; + void *context = client->context; + + timeout_remove(&client->to); + + client->callback = NULL; + client->context = NULL; + + /* make sure callback doesn't try to reuse this connection, since + we can't currently handle it */ + i_assert(!client->cmd_sent); + client->cmd_sent = TRUE; + callback(reply, state, context); + client->cmd_sent = FALSE; +} + +static void dsync_close(struct dsync_client *client) +{ + client->cmd_sent = FALSE; + client->handshaked = FALSE; + i_free_and_null(client->state); + i_free_and_null(client->username); + + if (client->fd == -1) + return; + + io_remove(&client->io); + o_stream_destroy(&client->output); + i_stream_destroy(&client->input); + if (close(client->fd) < 0) + i_error("close(dsync) failed: %m"); + client->fd = -1; +} + +static void dsync_disconnect(struct dsync_client *client) +{ + dsync_close(client); + if (client->callback != NULL) + dsync_callback(client, "", DSYNC_REPLY_FAIL); +} + +void dsync_client_deinit(struct dsync_client **_client) +{ + struct dsync_client *client = *_client; + + *_client = NULL; + + dsync_disconnect(client); + i_free(client->dsync_params); + i_free(client->path); + i_free(client); +} + +static int dsync_input_line(struct dsync_client *client, const char *line) +{ + const char *state; + + if (!client->handshaked) { + if (strcmp(line, "+") != 0) { + i_error("%s: Unexpected handshake: %s", + client->path, line); + return -1; + } + client->handshaked = TRUE; + return 0; + } + if (client->callback == NULL) { + i_error("%s: Unexpected input: %s", client->path, line); + return -1; + } + if (client->state == NULL) { + client->state = i_strdup(t_strcut(line, '\t')); + return 0; + } + state = t_strdup(client->state); + line = t_strdup(line); + dsync_close(client); + + if (line[0] == '+') + dsync_callback(client, state, DSYNC_REPLY_OK); + else if (line[0] == '-') { + if (strcmp(line+1, "NOUSER") == 0) + dsync_callback(client, "", DSYNC_REPLY_NOUSER); + else if (strcmp(line+1, "NOREPLICATE") == 0) + dsync_callback(client, "", DSYNC_REPLY_NOREPLICATE); + else + dsync_callback(client, "", DSYNC_REPLY_FAIL); + } else { + i_error("%s: Invalid input: %s", client->path, line); + return -1; + } + /* FIXME: disconnect after each request for now. + doveadm server's getopt() handling seems to break otherwise. + also with multiple UIDs doveadm-server fails because setid() fails */ + return -1; +} + +static void dsync_input(struct dsync_client *client) +{ + const char *line; + + while ((line = i_stream_read_next_line(client->input)) != NULL) { + if (dsync_input_line(client, line) < 0) { + dsync_disconnect(client); + return; + } + } + if (client->input->eof) + dsync_disconnect(client); +} + +static int dsync_connect(struct dsync_client *client) +{ + if (client->fd != -1) + return 0; + + if (client->last_connect_failure == ioloop_time) + return -1; + + client->fd = net_connect_unix(client->path); + if (client->fd == -1) { + i_error("net_connect_unix(%s) failed: %m", client->path); + client->last_connect_failure = ioloop_time; + return -1; + } + client->last_connect_failure = 0; + client->io = io_add(client->fd, IO_READ, dsync_input, client); + client->input = i_stream_create_fd(client->fd, SIZE_MAX); + client->output = o_stream_create_fd(client->fd, SIZE_MAX); + o_stream_set_no_error_handling(client->output, TRUE); + o_stream_nsend_str(client->output, DOVEADM_HANDSHAKE); + return 0; +} + +static void dsync_fail_timeout(struct dsync_client *client) +{ + dsync_disconnect(client); +} + +void dsync_client_sync(struct dsync_client *client, + const char *username, const char *state, bool full, + dsync_callback_t *callback, void *context) +{ + string_t *cmd; + unsigned int pos; + char *p; + + i_assert(callback != NULL); + i_assert(!dsync_client_is_busy(client)); + + client->username = i_strdup(username); + client->cmd_sent = TRUE; + client->callback = callback; + client->context = context; + if (full) + client->sync_type = DSYNC_TYPE_FULL; + else if (state != NULL && state[0] != '\0') + client->sync_type = DSYNC_TYPE_INCREMENTAL; + else + client->sync_type = DSYNC_TYPE_NORMAL; + + if (dsync_connect(client) < 0) { + i_assert(client->to == NULL); + client->to = timeout_add(DSYNC_FAIL_TIMEOUT_MSECS, + dsync_fail_timeout, client); + } else { + /* [] */ + cmd = t_str_new(256); + str_append_c(cmd, '\t'); + str_append_tabescaped(cmd, username); + str_append(cmd, "\tsync\t"); + pos = str_len(cmd); + /* insert the parameters. we can do it simply by converting + spaces into tabs, it's unlikely we'll ever need anything + more complex here. */ + str_append(cmd, client->dsync_params); + p = str_c_modifiable(cmd) + pos; + for (; *p != '\0'; p++) { + if (*p == ' ') + *p = '\t'; + } + if (full) + str_append(cmd, "\t-f"); + str_append(cmd, "\t-s\t"); + if (state != NULL) + str_append(cmd, state); + str_append_c(cmd, '\n'); + o_stream_nsend(client->output, str_data(cmd), str_len(cmd)); + } +} + +bool dsync_client_is_busy(struct dsync_client *client) +{ + return client->cmd_sent; +} + +const char *dsync_client_get_username(struct dsync_client *conn) +{ + return conn->username; +} + +enum dsync_type dsync_client_get_type(struct dsync_client *conn) +{ + return conn->sync_type; +} + +const char *dsync_client_get_state(struct dsync_client *conn) +{ + if (conn->fd == -1) { + if (conn->last_connect_failure == 0) + return "Not connected"; + return t_strdup_printf("Failed to connect to '%s' - last attempt %ld secs ago", conn->path, + (long)(ioloop_time - conn->last_connect_failure)); + } + if (!dsync_client_is_busy(conn)) + return "Idle"; + if (!conn->handshaked) + return "Waiting for handshake"; + if (conn->state == NULL) + return "Waiting for dsync to finish"; + else + return "Waiting for dsync to finish (second line)"; +} diff --git a/src/replication/replicator/dsync-client.h b/src/replication/replicator/dsync-client.h new file mode 100644 index 0000000..c55b815 --- /dev/null +++ b/src/replication/replicator/dsync-client.h @@ -0,0 +1,37 @@ +#ifndef DSYNC_CLIENT_H +#define DSYNC_CLIENT_H + +struct dsync_client; + +enum dsync_reply { + DSYNC_REPLY_OK, + DSYNC_REPLY_FAIL, + DSYNC_REPLY_NOUSER, + DSYNC_REPLY_NOREPLICATE, +}; + +enum dsync_type { + DSYNC_TYPE_FULL, + DSYNC_TYPE_NORMAL, + DSYNC_TYPE_INCREMENTAL +}; + +ARRAY_DEFINE_TYPE(dsync_client, struct dsync_client *); + +typedef void dsync_callback_t(enum dsync_reply reply, + const char *state, void *context); + +struct dsync_client * +dsync_client_init(const char *path, const char *dsync_params); +void dsync_client_deinit(struct dsync_client **conn); + +void dsync_client_sync(struct dsync_client *conn, + const char *username, const char *state, bool full, + dsync_callback_t *callback, void *context); +bool dsync_client_is_busy(struct dsync_client *conn); + +const char *dsync_client_get_username(struct dsync_client *conn); +enum dsync_type dsync_client_get_type(struct dsync_client *conn); +const char *dsync_client_get_state(struct dsync_client *conn); + +#endif diff --git a/src/replication/replicator/notify-connection.c b/src/replication/replicator/notify-connection.c new file mode 100644 index 0000000..0f2c386 --- /dev/null +++ b/src/replication/replicator/notify-connection.c @@ -0,0 +1,206 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "llist.h" +#include "istream.h" +#include "ostream.h" +#include "strescape.h" +#include "master-service.h" +#include "replicator-queue.h" +#include "notify-connection.h" + +#include + +#define MAX_INBUF_SIZE (1024*64) +#define NOTIFY_CLIENT_PROTOCOL_MAJOR_VERSION 1 +#define NOTIFY_CLIENT_PROTOCOL_MINOR_VERSION 0 + +struct notify_connection { + struct notify_connection *prev, *next; + int refcount; + + int fd; + struct io *io; + struct istream *input; + struct ostream *output; + + struct replicator_queue *queue; + + bool version_received:1; + bool destroyed:1; +}; + +struct notify_sync_request { + struct notify_connection *conn; + unsigned int id; +}; + +static struct notify_connection *connections; + +static void notify_connection_destroy(struct notify_connection *conn); + +static void notify_sync_callback(bool success, void *context) +{ + struct notify_sync_request *request = context; + + o_stream_nsend_str(request->conn->output, t_strdup_printf( + "%c\t%u\n", success ? '+' : '-', request->id)); + + notify_connection_unref(&request->conn); + i_free(request); +} + +static int +notify_connection_input_line(struct notify_connection *conn, const char *line) +{ + struct notify_sync_request *request; + const char *const *args; + enum replication_priority priority; + unsigned int id; + + /* U \t \t [\t ] */ + args = t_strsplit_tabescaped(line); + if (str_array_length(args) < 2) { + i_error("notify client sent invalid input: %s", line); + return -1; + } + if (strcmp(args[0], "U") != 0) { + i_error("notify client sent unknown command: %s", args[0]); + return -1; + } + if (replication_priority_parse(args[2], &priority) < 0) { + i_error("notify client sent invalid priority: %s", args[2]); + return -1; + } + if (priority != REPLICATION_PRIORITY_SYNC) { + struct replicator_user *user = + replicator_queue_get(conn->queue, args[1]); + replicator_queue_update(conn->queue, user, priority); + replicator_queue_add(conn->queue, user); + } else if (args[3] == NULL || str_to_uint(args[3], &id) < 0) { + i_error("notify client sent invalid sync id: %s", line); + return -1; + } else { + request = i_new(struct notify_sync_request, 1); + request->conn = conn; + request->id = id; + notify_connection_ref(conn); + struct replicator_user *user = + replicator_queue_get(conn->queue, args[1]); + replicator_queue_update(conn->queue, user, + REPLICATION_PRIORITY_SYNC); + replicator_queue_add_sync_callback(conn->queue, user, + notify_sync_callback, + request); + } + return 0; +} + +static void notify_connection_input(struct notify_connection *conn) +{ + const char *line; + int ret; + + switch (i_stream_read(conn->input)) { + case -2: + i_error("BUG: Client connection sent too much data"); + notify_connection_destroy(conn); + return; + case -1: + notify_connection_destroy(conn); + return; + } + + if (!conn->version_received) { + if ((line = i_stream_next_line(conn->input)) == NULL) + return; + + if (!version_string_verify(line, "replicator-notify", + NOTIFY_CLIENT_PROTOCOL_MAJOR_VERSION)) { + i_error("Notify client not compatible with this server " + "(mixed old and new binaries?)"); + notify_connection_destroy(conn); + return; + } + conn->version_received = TRUE; + } + + while ((line = i_stream_next_line(conn->input)) != NULL) { + T_BEGIN { + ret = notify_connection_input_line(conn, line); + } T_END; + if (ret < 0) { + notify_connection_destroy(conn); + break; + } + } +} + +struct notify_connection * +notify_connection_create(int fd, struct replicator_queue *queue) +{ + struct notify_connection *conn; + + i_assert(fd >= 0); + + conn = i_new(struct notify_connection, 1); + conn->refcount = 1; + conn->queue = queue; + conn->fd = fd; + conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE); + conn->output = o_stream_create_fd(fd, SIZE_MAX); + o_stream_set_no_error_handling(conn->output, TRUE); + conn->io = io_add(fd, IO_READ, notify_connection_input, conn); + conn->queue = queue; + + DLLIST_PREPEND(&connections, conn); + return conn; +} + +static void notify_connection_destroy(struct notify_connection *conn) +{ + if (conn->destroyed) + return; + conn->destroyed = TRUE; + + DLLIST_REMOVE(&connections, conn); + + io_remove(&conn->io); + i_stream_close(conn->input); + o_stream_close(conn->output); + if (close(conn->fd) < 0) + i_error("close(notify connection) failed: %m"); + conn->fd = -1; + + notify_connection_unref(&conn); + master_service_client_connection_destroyed(master_service); +} + +void notify_connection_ref(struct notify_connection *conn) +{ + i_assert(conn->refcount > 0); + + conn->refcount++; +} + +void notify_connection_unref(struct notify_connection **_conn) +{ + struct notify_connection *conn = *_conn; + + i_assert(conn->refcount > 0); + + *_conn = NULL; + if (--conn->refcount > 0) + return; + + notify_connection_destroy(conn); + i_stream_unref(&conn->input); + o_stream_unref(&conn->output); + i_free(conn); +} + +void notify_connections_destroy_all(void) +{ + while (connections != NULL) + notify_connection_destroy(connections); +} diff --git a/src/replication/replicator/notify-connection.h b/src/replication/replicator/notify-connection.h new file mode 100644 index 0000000..fa62fc7 --- /dev/null +++ b/src/replication/replicator/notify-connection.h @@ -0,0 +1,13 @@ +#ifndef NOTIFY_CONNECTION_H +#define NOTIFY_CONNECTION_H + +struct replicator_queue; + +struct notify_connection * +notify_connection_create(int fd, struct replicator_queue *queue); +void notify_connection_ref(struct notify_connection *conn); +void notify_connection_unref(struct notify_connection **conn); + +void notify_connections_destroy_all(void); + +#endif diff --git a/src/replication/replicator/replicator-brain.c b/src/replication/replicator/replicator-brain.c new file mode 100644 index 0000000..65cfcec --- /dev/null +++ b/src/replication/replicator/replicator-brain.c @@ -0,0 +1,202 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "array.h" +#include "ioloop.h" +#include "dsync-client.h" +#include "replicator-settings.h" +#include "replicator-queue.h" +#include "replicator-brain.h" + +struct replicator_sync_context { + struct replicator_brain *brain; + struct replicator_user *user; +}; + +struct replicator_brain { + pool_t pool; + struct replicator_queue *queue; + const struct replicator_settings *set; + struct timeout *to; + + ARRAY_TYPE(dsync_client) dsync_clients; + + bool deinitializing:1; +}; + +static void replicator_brain_fill(struct replicator_brain *brain); + +static void replicator_brain_timeout(struct replicator_brain *brain) +{ + timeout_remove(&brain->to); + replicator_brain_fill(brain); +} + +static void replicator_brain_queue_changed(void *context) +{ + struct replicator_brain *brain = context; + + /* Delay a bit filling the replication. We could have gotten here + before the replicator_user change was fully filled out. */ + timeout_remove(&brain->to); + brain->to = timeout_add_short(0, replicator_brain_timeout, brain); +} + +struct replicator_brain * +replicator_brain_init(struct replicator_queue *queue, + const struct replicator_settings *set) +{ + struct replicator_brain *brain; + pool_t pool; + + pool = pool_alloconly_create("replication brain", 1024); + brain = p_new(pool, struct replicator_brain, 1); + brain->pool = pool; + brain->queue = queue; + brain->set = set; + p_array_init(&brain->dsync_clients, pool, 16); + replicator_queue_set_change_callback(queue, + replicator_brain_queue_changed, brain); + replicator_brain_fill(brain); + return brain; +} + +void replicator_brain_deinit(struct replicator_brain **_brain) +{ + struct replicator_brain *brain = *_brain; + struct dsync_client *conn; + + *_brain = NULL; + + brain->deinitializing = TRUE; + array_foreach_elem(&brain->dsync_clients, conn) + dsync_client_deinit(&conn); + timeout_remove(&brain->to); + pool_unref(&brain->pool); +} + +struct replicator_queue * +replicator_brain_get_queue(struct replicator_brain *brain) +{ + return brain->queue; +} + +const struct replicator_settings * +replicator_brain_get_settings(struct replicator_brain *brain) +{ + return brain->set; +} + +const ARRAY_TYPE(dsync_client) * +replicator_brain_get_dsync_clients(struct replicator_brain *brain) +{ + return &brain->dsync_clients; +} + +static struct dsync_client * +get_dsync_client(struct replicator_brain *brain) +{ + struct dsync_client *conn; + + array_foreach_elem(&brain->dsync_clients, conn) { + if (!dsync_client_is_busy(conn)) + return conn; + } + if (array_count(&brain->dsync_clients) == + brain->set->replication_max_conns) + return NULL; + + conn = dsync_client_init(brain->set->doveadm_socket_path, + brain->set->replication_dsync_parameters); + array_push_back(&brain->dsync_clients, &conn); + return conn; +} + +static void dsync_callback(enum dsync_reply reply, const char *state, + void *context) +{ + struct replicator_sync_context *ctx = context; + struct replicator_user *user = ctx->user; + + if (!replicator_user_unref(&user)) { + /* user was already removed */ + } else if (reply == DSYNC_REPLY_NOUSER || + reply == DSYNC_REPLY_NOREPLICATE) { + /* user no longer exists, or is not wanted for replication, + remove from replication */ + replicator_queue_remove(ctx->brain->queue, &ctx->user); + } else { + i_free(ctx->user->state); + ctx->user->state = i_strdup_empty(state); + ctx->user->last_sync_failed = reply != DSYNC_REPLY_OK; + if (reply == DSYNC_REPLY_OK) + ctx->user->last_successful_sync = ioloop_time; + replicator_queue_push(ctx->brain->queue, ctx->user); + } + if (!ctx->brain->deinitializing) + replicator_brain_fill(ctx->brain); + i_free(ctx); +} + +static bool +dsync_replicate(struct replicator_brain *brain, struct replicator_user *user) +{ + struct replicator_sync_context *ctx; + struct dsync_client *conn; + time_t next_full_sync; + bool full; + + conn = get_dsync_client(brain); + if (conn == NULL) + return FALSE; + + next_full_sync = user->last_full_sync + + brain->set->replication_full_sync_interval; + full = next_full_sync <= ioloop_time; + /* update the sync times immediately. if the replication fails we still + wouldn't want it to be retried immediately. */ + user->last_fast_sync = ioloop_time; + if (full || user->force_full_sync) { + user->last_full_sync = ioloop_time; + user->force_full_sync = FALSE; + } + /* reset priority also. if more updates arrive during replication + we'll do another replication to make sure nothing gets lost */ + user->priority = REPLICATION_PRIORITY_NONE; + + ctx = i_new(struct replicator_sync_context, 1); + ctx->brain = brain; + ctx->user = user; + replicator_user_ref(user); + dsync_client_sync(conn, user->username, user->state, full, + dsync_callback, ctx); + return TRUE; +} + +static bool replicator_brain_fill_next(struct replicator_brain *brain) +{ + struct replicator_user *user; + unsigned int next_secs; + + user = replicator_queue_pop(brain->queue, &next_secs); + if (user == NULL) { + /* nothing more to do */ + timeout_remove(&brain->to); + brain->to = timeout_add(next_secs * 1000, + replicator_brain_timeout, brain); + return FALSE; + } + + if (!dsync_replicate(brain, user)) { + /* all connections were full, put the user back to queue */ + replicator_queue_push(brain->queue, user); + return FALSE; + } + /* replication started for the user */ + return TRUE; +} + +static void replicator_brain_fill(struct replicator_brain *brain) +{ + while (replicator_brain_fill_next(brain)) ; +} diff --git a/src/replication/replicator/replicator-brain.h b/src/replication/replicator/replicator-brain.h new file mode 100644 index 0000000..6e9ae23 --- /dev/null +++ b/src/replication/replicator/replicator-brain.h @@ -0,0 +1,20 @@ +#ifndef REPLICATOR_BRAIN_H +#define REPLICATOR_BRAIN_H + +struct replicator_settings; +struct replicator_queue; + +struct replicator_brain * +replicator_brain_init(struct replicator_queue *queue, + const struct replicator_settings *set); +void replicator_brain_deinit(struct replicator_brain **brain); + +struct replicator_queue * +replicator_brain_get_queue(struct replicator_brain *brain); +const struct replicator_settings * +replicator_brain_get_settings(struct replicator_brain *brain); + +const ARRAY_TYPE(dsync_client) * +replicator_brain_get_dsync_clients(struct replicator_brain *brain); + +#endif diff --git a/src/replication/replicator/replicator-queue-auth.c b/src/replication/replicator/replicator-queue-auth.c new file mode 100644 index 0000000..eedb814 --- /dev/null +++ b/src/replication/replicator/replicator-queue-auth.c @@ -0,0 +1,37 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "auth-master.h" +#include "replicator-queue.h" + +#define REPLICATOR_AUTH_SERVICE_NAME "replicator" + +void replicator_queue_add_auth_users(struct replicator_queue *queue, + const char *auth_socket_path, + const char *usermask, time_t last_update) +{ + struct auth_master_connection *auth_conn; + struct auth_master_user_list_ctx *ctx; + struct auth_user_info user_info; + struct replicator_user *user; + const char *username; + + auth_conn = auth_master_init(auth_socket_path, + AUTH_MASTER_FLAG_NO_IDLE_TIMEOUT); + + i_zero(&user_info); + user_info.service = REPLICATOR_AUTH_SERVICE_NAME; + + /* add all users into replication queue, so that we can start doing + full syncs for everyone whose state can't be found */ + ctx = auth_master_user_list_init(auth_conn, usermask, &user_info); + while ((username = auth_master_user_list_next(ctx)) != NULL) { + user = replicator_queue_get(queue, username); + replicator_queue_update(queue, user, REPLICATION_PRIORITY_NONE); + replicator_queue_add(queue, user); + user->last_update = last_update; + } + if (auth_master_user_list_deinit(&ctx) < 0) + i_error("listing users failed, can't replicate existing data"); + auth_master_deinit(&auth_conn); +} diff --git a/src/replication/replicator/replicator-queue.c b/src/replication/replicator/replicator-queue.c new file mode 100644 index 0000000..31f296a --- /dev/null +++ b/src/replication/replicator/replicator-queue.c @@ -0,0 +1,527 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "array.h" +#include "ioloop.h" +#include "istream.h" +#include "ostream.h" +#include "str.h" +#include "strescape.h" +#include "hash.h" +#include "replicator-queue.h" + +#include +#include + +struct replicator_sync_lookup { + struct replicator_user *user; + + replicator_sync_callback_t *callback; + void *context; + + bool wait_for_next_push; +}; + +struct replicator_queue { + struct priorityq *user_queue; + /* username => struct replicator_user* */ + HASH_TABLE(char *, struct replicator_user *) user_hash; + + ARRAY(struct replicator_sync_lookup) sync_lookups; + + unsigned int full_sync_interval; + unsigned int failure_resync_interval; + + void (*change_callback)(void *context); + void *change_context; +}; + +struct replicator_queue_iter { + struct replicator_queue *queue; + struct hash_iterate_context *iter; +}; + +static unsigned int replicator_full_sync_interval = 0; +static unsigned int replicator_failure_resync_interval = 0; + +static time_t replicator_user_next_sync_time(const struct replicator_user *user) +{ + /* The idea is that the higher the priority, the more likely it will + be prioritized over low priority syncs. However, to avoid permanent + starvation of lower priority users, the priority boost is only + temporary. + + The REPLICATION_PRIORITY_*_SECS macros effectively specify how long + lower priority requests are allowed to be waiting. */ +#define REPLICATION_PRIORITY_LOW_SECS (60*15) +#define REPLICATION_PRIORITY_HIGH_SECS (60*30) +#define REPLICATION_PRIORITY_SYNC_SECS (60*45) + /* When priority != none, user needs to be replicated ASAP. + The question is just whether the queue is already busy and other + users need to be synced even more faster. */ + if (user->last_fast_sync == 0) { + /* User has never been synced yet. These will be replicated + first. Still, try to replicate higher priority users faster + than lower priority users. */ + if (user->priority != REPLICATION_PRIORITY_NONE) + return REPLICATION_PRIORITY_SYNC - user->priority; + } + switch (user->priority) { + case REPLICATION_PRIORITY_NONE: + break; + case REPLICATION_PRIORITY_LOW: + i_assert(user->last_update >= REPLICATION_PRIORITY_LOW_SECS); + return user->last_update - REPLICATION_PRIORITY_LOW_SECS; + case REPLICATION_PRIORITY_HIGH: + i_assert(user->last_update >= REPLICATION_PRIORITY_HIGH_SECS); + return user->last_update - REPLICATION_PRIORITY_HIGH_SECS; + case REPLICATION_PRIORITY_SYNC: + i_assert(user->last_update >= REPLICATION_PRIORITY_HIGH_SECS); + return user->last_update - REPLICATION_PRIORITY_SYNC_SECS; + } + if (user->last_sync_failed) { + /* failures need to be retried at specific intervals */ + return user->last_fast_sync + + replicator_failure_resync_interval; + } + /* full resyncs should be done at configured intervals */ + return user->last_full_sync + replicator_full_sync_interval; +} + +static int user_priority_cmp(const void *p1, const void *p2) +{ + const struct replicator_user *user1 = p1, *user2 = p2; + time_t next_sync1 = replicator_user_next_sync_time(user1); + time_t next_sync2 = replicator_user_next_sync_time(user2); + if (next_sync1 < next_sync2) + return -1; + if (next_sync1 > next_sync2) + return 1; + return 0; +} + +struct replicator_queue * +replicator_queue_init(unsigned int full_sync_interval, + unsigned int failure_resync_interval) +{ + struct replicator_queue *queue; + + /* priorityq callback needs to access these */ + i_assert(replicator_full_sync_interval == 0 || + replicator_full_sync_interval == full_sync_interval); + replicator_full_sync_interval = full_sync_interval; + i_assert(replicator_failure_resync_interval == 0 || + replicator_failure_resync_interval == failure_resync_interval); + replicator_full_sync_interval = full_sync_interval; + replicator_failure_resync_interval = failure_resync_interval; + + queue = i_new(struct replicator_queue, 1); + queue->full_sync_interval = full_sync_interval; + queue->failure_resync_interval = failure_resync_interval; + queue->user_queue = priorityq_init(user_priority_cmp, 1024); + hash_table_create(&queue->user_hash, default_pool, 1024, + str_hash, strcmp); + i_array_init(&queue->sync_lookups, 32); + return queue; +} + +void replicator_queue_deinit(struct replicator_queue **_queue) +{ + struct replicator_queue *queue = *_queue; + struct priorityq_item *item; + + *_queue = NULL; + + queue->change_callback = NULL; + + while ((item = priorityq_pop(queue->user_queue)) != NULL) { + struct replicator_user *user = (struct replicator_user *)item; + + user->popped = TRUE; + replicator_queue_remove(queue, &user); + } + + priorityq_deinit(&queue->user_queue); + hash_table_destroy(&queue->user_hash); + i_assert(array_count(&queue->sync_lookups) == 0); + array_free(&queue->sync_lookups); + i_free(queue); +} + +void replicator_queue_set_change_callback(struct replicator_queue *queue, + void (*callback)(void *context), + void *context) +{ + queue->change_callback = callback; + queue->change_context = context; +} + +void replicator_user_ref(struct replicator_user *user) +{ + i_assert(user->refcount > 0); + user->refcount++; +} + +bool replicator_user_unref(struct replicator_user **_user) +{ + struct replicator_user *user = *_user; + + i_assert(user->refcount > 0); + *_user = NULL; + if (--user->refcount > 0) + return TRUE; + + i_free(user->state); + i_free(user->username); + i_free(user); + return FALSE; +} + +struct replicator_user * +replicator_queue_lookup(struct replicator_queue *queue, const char *username) +{ + return hash_table_lookup(queue->user_hash, username); +} + +struct replicator_user * +replicator_queue_get(struct replicator_queue *queue, const char *username) +{ + struct replicator_user *user; + + user = replicator_queue_lookup(queue, username); + if (user == NULL) { + user = i_new(struct replicator_user, 1); + user->refcount = 1; + user->username = i_strdup(username); + user->last_update = ioloop_time; + hash_table_insert(queue->user_hash, user->username, user); + if (!user->popped) + priorityq_add(queue->user_queue, &user->item); + } + return user; +} + +void replicator_queue_update(struct replicator_queue *queue ATTR_UNUSED, + struct replicator_user *user, + enum replication_priority priority) +{ + if (user->priority >= priority) { + /* user already has at least this high priority */ + return; + } + user->priority = priority; + user->last_update = ioloop_time; +} + +void replicator_queue_add(struct replicator_queue *queue, + struct replicator_user *user) +{ + if (!user->popped) { + priorityq_remove(queue->user_queue, &user->item); + priorityq_add(queue->user_queue, &user->item); + } + if (queue->change_callback != NULL) + queue->change_callback(queue->change_context); +} + +void replicator_queue_add_sync_callback(struct replicator_queue *queue, + struct replicator_user *user, + replicator_sync_callback_t *callback, + void *context) +{ + struct replicator_sync_lookup *lookup; + + i_assert(user->priority == REPLICATION_PRIORITY_SYNC); + + lookup = array_append_space(&queue->sync_lookups); + lookup->user = user; + lookup->callback = callback; + lookup->context = context; + lookup->wait_for_next_push = user->popped; + + replicator_queue_add(queue, user); +} + +void replicator_queue_remove(struct replicator_queue *queue, + struct replicator_user **_user) +{ + struct replicator_user *user = *_user; + + *_user = NULL; + if (!user->popped) + priorityq_remove(queue->user_queue, &user->item); + hash_table_remove(queue->user_hash, user->username); + replicator_user_unref(&user); + + if (queue->change_callback != NULL) + queue->change_callback(queue->change_context); +} + +unsigned int replicator_queue_count(struct replicator_queue *queue) +{ + return priorityq_count(queue->user_queue); +} + +bool replicator_queue_want_sync_now(struct replicator_user *user, + unsigned int *next_secs_r) +{ + time_t next_sync = replicator_user_next_sync_time(user); + if (next_sync <= ioloop_time) { + *next_secs_r = 0; + return TRUE; + } + *next_secs_r = next_sync - ioloop_time; + return FALSE; +} + +struct replicator_user * +replicator_queue_peek(struct replicator_queue *queue, + unsigned int *next_secs_r) +{ + struct priorityq_item *item; + struct replicator_user *user; + + item = priorityq_peek(queue->user_queue); + if (item == NULL) { + /* no users defined. we shouldn't normally get here */ + *next_secs_r = 3600; + return NULL; + } + user = (struct replicator_user *)item; + (void)replicator_queue_want_sync_now(user, next_secs_r); + return user; +} + +struct replicator_user * +replicator_queue_pop(struct replicator_queue *queue, + unsigned int *next_secs_r) +{ + struct replicator_user *user; + + user = replicator_queue_peek(queue, next_secs_r); + if (*next_secs_r > 0) { + /* we don't want to sync the user yet */ + return NULL; + } + if (user != NULL) { + priorityq_remove(queue->user_queue, &user->item); + user->popped = TRUE; + } + return user; +} + +static void +replicator_queue_handle_sync_lookups(struct replicator_queue *queue, + struct replicator_user *user) +{ + struct replicator_sync_lookup *lookups; + ARRAY(struct replicator_sync_lookup) callbacks; + unsigned int i, count; + bool success = !user->last_sync_failed; + + t_array_init(&callbacks, 8); + lookups = array_get_modifiable(&queue->sync_lookups, &count); + for (i = 0; i < count; ) { + if (lookups[i].user != user) + i++; + else if (lookups[i].wait_for_next_push) { + /* another sync request came while user was being + replicated */ + i_assert(user->priority == REPLICATION_PRIORITY_SYNC); + lookups[i].wait_for_next_push = FALSE; + i++; + } else { + array_push_back(&callbacks, &lookups[i]); + array_delete(&queue->sync_lookups, i, 1); + } + } + + array_foreach_modifiable(&callbacks, lookups) + lookups->callback(success, lookups->context); +} + +void replicator_queue_push(struct replicator_queue *queue, + struct replicator_user *user) +{ + i_assert(user->popped); + + priorityq_add(queue->user_queue, &user->item); + user->popped = FALSE; + + T_BEGIN { + replicator_queue_handle_sync_lookups(queue, user); + } T_END; +} + +static int +replicator_queue_import_line(struct replicator_queue *queue, const char *line) +{ + const char *const *args, *username, *state; + unsigned int priority; + struct replicator_user *user, tmp_user; + + /* + */ + args = t_strsplit_tabescaped(line); + if (str_array_length(args) < 7) + return -1; + + i_zero(&tmp_user); + username = args[0]; + state = t_strdup_noconst(args[6]); + if (username[0] == '\0' || + str_to_uint(args[1], &priority) < 0 || + str_to_time(args[2], &tmp_user.last_update) < 0 || + str_to_time(args[3], &tmp_user.last_fast_sync) < 0 || + str_to_time(args[4], &tmp_user.last_full_sync) < 0) + return -1; + tmp_user.priority = priority; + tmp_user.last_sync_failed = args[5][0] != '0'; + + if (str_array_length(args) >= 8) { + if (str_to_time(args[7], &tmp_user.last_successful_sync) < 0) + return -1; + } else { + tmp_user.last_successful_sync = 0; + /* On-disk format didn't have this yet */ + } + + user = hash_table_lookup(queue->user_hash, username); + if (user != NULL) { + if (user->last_update > tmp_user.last_update) { + /* we already have a newer state */ + return 0; + } + if (user->last_update == tmp_user.last_update) { + /* either one of these could be newer. use the one + with higher priority. */ + if (user->priority > tmp_user.priority) + return 0; + } + } else { + user = replicator_queue_get(queue, username); + } + user->priority = tmp_user.priority; + user->last_update = tmp_user.last_update; + user->last_fast_sync = tmp_user.last_fast_sync; + user->last_full_sync = tmp_user.last_full_sync; + user->last_successful_sync = tmp_user.last_successful_sync; + user->last_sync_failed = tmp_user.last_sync_failed; + i_free(user->state); + user->state = i_strdup(state); + replicator_queue_add(queue, user); + return 0; +} + +int replicator_queue_import(struct replicator_queue *queue, const char *path) +{ + struct istream *input; + const char *line; + int fd, ret = 0; + + fd = open(path, O_RDONLY); + if (fd == -1) { + if (errno == ENOENT) + return 0; + i_error("open(%s) failed: %m", path); + return -1; + } + + input = i_stream_create_fd_autoclose(&fd, SIZE_MAX); + while ((line = i_stream_read_next_line(input)) != NULL) { + T_BEGIN { + ret = replicator_queue_import_line(queue, line); + } T_END; + if (ret < 0) { + i_error("Corrupted replicator record in %s: %s", + path, line); + break; + } + } + if (input->stream_errno != 0) { + i_error("read(%s) failed: %s", path, i_stream_get_error(input)); + ret = -1; + } + i_stream_destroy(&input); + return ret; +} + +static void +replicator_queue_export_user(struct replicator_user *user, string_t *str) +{ + str_append_tabescaped(str, user->username); + str_printfa(str, "\t%d\t%lld\t%lld\t%lld\t%d\t", (int)user->priority, + (long long)user->last_update, + (long long)user->last_fast_sync, + (long long)user->last_full_sync, + user->last_sync_failed ? 1 : 0); + if (user->state != NULL) + str_append_tabescaped(str, user->state); + str_printfa(str, "\t%lld\n", (long long)user->last_successful_sync); +} + +int replicator_queue_export(struct replicator_queue *queue, const char *path) +{ + struct replicator_queue_iter *iter; + struct replicator_user *user; + struct ostream *output; + string_t *str; + int fd, ret = 0; + + fd = creat(path, 0600); + if (fd == -1) { + i_error("creat(%s) failed: %m", path); + return -1; + } + output = o_stream_create_fd_file_autoclose(&fd, 0); + o_stream_cork(output); + + str = t_str_new(128); + iter = replicator_queue_iter_init(queue); + while ((user = replicator_queue_iter_next(iter)) != NULL) { + str_truncate(str, 0); + replicator_queue_export_user(user, str); + if (o_stream_send(output, str_data(str), str_len(str)) < 0) + break; + } + replicator_queue_iter_deinit(&iter); + if (o_stream_finish(output) < 0) { + i_error("write(%s) failed: %s", path, o_stream_get_error(output)); + ret = -1; + } + o_stream_destroy(&output); + return ret; +} + +struct replicator_queue_iter * +replicator_queue_iter_init(struct replicator_queue *queue) +{ + struct replicator_queue_iter *iter; + + iter = i_new(struct replicator_queue_iter, 1); + iter->queue = queue; + iter->iter = hash_table_iterate_init(queue->user_hash); + return iter; +} + +struct replicator_user * +replicator_queue_iter_next(struct replicator_queue_iter *iter) +{ + struct replicator_user *user; + char *username; + + if (!hash_table_iterate(iter->iter, iter->queue->user_hash, + &username, &user)) + return NULL; + return user; +} + +void replicator_queue_iter_deinit(struct replicator_queue_iter **_iter) +{ + struct replicator_queue_iter *iter = *_iter; + + *_iter = NULL; + + hash_table_iterate_deinit(&iter->iter); + i_free(iter); +} diff --git a/src/replication/replicator/replicator-queue.h b/src/replication/replicator/replicator-queue.h new file mode 100644 index 0000000..4e021e2 --- /dev/null +++ b/src/replication/replicator/replicator-queue.h @@ -0,0 +1,104 @@ +#ifndef REPLICATOR_QUEUE_H +#define REPLICATOR_QUEUE_H + +#include "priorityq.h" +#include "replication-common.h" + +struct replicator_user { + struct priorityq_item item; + + char *username; + /* dsync state for incremental syncing */ + char *state; + /* last time this user's state was updated */ + time_t last_update; + /* last_fast_sync is always >= last_full_sync. */ + time_t last_fast_sync, last_full_sync, last_successful_sync; + + int refcount; + enum replication_priority priority; + /* User isn't currently in replication queue */ + bool popped:1; + /* Last replication sync failed */ + bool last_sync_failed:1; + /* Force a full sync on the next replication */ + bool force_full_sync:1; +}; + +typedef void replicator_sync_callback_t(bool success, void *context); + +struct replicator_queue * +replicator_queue_init(unsigned int full_sync_interval, + unsigned int failure_resync_interval); +void replicator_queue_deinit(struct replicator_queue **queue); + +/* Call the specified callback when data is added/removed/moved in queue + via _add(), _add_sync() or _remove() functions (not push/pop). */ +void replicator_queue_set_change_callback(struct replicator_queue *queue, + void (*callback)(void *context), + void *context); + +/* Reference the user */ +void replicator_user_ref(struct replicator_user *user); +/* Unreference the user. Returns TRUE if refcount is still >0. */ +bool replicator_user_unref(struct replicator_user **user); + +/* Lookup an existing user */ +struct replicator_user * +replicator_queue_lookup(struct replicator_queue *queue, const char *username); +/* Lookup or create a user and return it. Afterwards replicator_queue_add() + must be called to add/move the user to the proper place in the queue. */ +struct replicator_user * +replicator_queue_get(struct replicator_queue *queue, const char *username); +/* Update user's priority if it's currently lower. */ +void replicator_queue_update(struct replicator_queue *queue, + struct replicator_user *user, + enum replication_priority priority); +void replicator_queue_add(struct replicator_queue *queue, + struct replicator_user *user); +/* Call the callback when user with SYNC priority has finished syncing. */ +void replicator_queue_add_sync_callback(struct replicator_queue *queue, + struct replicator_user *user, + replicator_sync_callback_t *callback, + void *context); +/* Remove user from replication queue and free it. */ +void replicator_queue_remove(struct replicator_queue *queue, + struct replicator_user **user); +/* Return the number of users in the queue. */ +unsigned int replicator_queue_count(struct replicator_queue *queue); + +/* Return the next user from replication queue and how many seconds from now + the returned user should be synced (0 = immediately). Returns NULL only if + there are no users in the queue. */ +struct replicator_user * +replicator_queue_peek(struct replicator_queue *queue, + unsigned int *next_secs_r); +/* Return the next user from replication queue, and remove it from the queue. + If there's nothing to be replicated currently, returns NULL and sets + next_secs_r to when there should be more work to do. */ +struct replicator_user * +replicator_queue_pop(struct replicator_queue *queue, + unsigned int *next_secs_r); +/* Add user back to queue. */ +void replicator_queue_push(struct replicator_queue *queue, + struct replicator_user *user); + +int replicator_queue_import(struct replicator_queue *queue, const char *path); +int replicator_queue_export(struct replicator_queue *queue, const char *path); + +/* Returns TRUE if user replication can be started now, FALSE if not. When + returning FALSE, next_secs_r is set to user's next replication time. */ +bool replicator_queue_want_sync_now(struct replicator_user *user, + unsigned int *next_secs_r); +/* Iterate through all users in the queue. */ +struct replicator_queue_iter * +replicator_queue_iter_init(struct replicator_queue *queue); +struct replicator_user * +replicator_queue_iter_next(struct replicator_queue_iter *iter); +void replicator_queue_iter_deinit(struct replicator_queue_iter **iter); + +void replicator_queue_add_auth_users(struct replicator_queue *queue, + const char *auth_socket_path, + const char *usermask, time_t last_update); + +#endif diff --git a/src/replication/replicator/replicator-settings.c b/src/replication/replicator/replicator-settings.c new file mode 100644 index 0000000..3965100 --- /dev/null +++ b/src/replication/replicator/replicator-settings.c @@ -0,0 +1,86 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "buffer.h" +#include "settings-parser.h" +#include "service-settings.h" +#include "replicator-settings.h" + +/* */ +static struct file_listener_settings replicator_unix_listeners_array[] = { + { "replicator", 0600, "$default_internal_user", "" }, + { "replicator-doveadm", 0, "$default_internal_user", "" } +}; +static struct file_listener_settings *replicator_unix_listeners[] = { + &replicator_unix_listeners_array[0], + &replicator_unix_listeners_array[1] +}; +static buffer_t replicator_unix_listeners_buf = { + { { replicator_unix_listeners, sizeof(replicator_unix_listeners) } } +}; +/* */ + +struct service_settings replicator_service_settings = { + .name = "replicator", + .protocol = "", + .type = "", + .executable = "replicator", + .user = "", + .group = "", + .privileged_group = "", + .extra_groups = "", + .chroot = "", + + .drop_priv_before_exec = FALSE, + + .process_min_avail = 0, + .process_limit = 1, + .client_limit = 0, + .service_count = 0, + .idle_kill = UINT_MAX, + .vsz_limit = UOFF_T_MAX, + + .unix_listeners = { { &replicator_unix_listeners_buf, + sizeof(replicator_unix_listeners[0]) } }, + .fifo_listeners = ARRAY_INIT, + .inet_listeners = ARRAY_INIT, + + .process_limit_1 = TRUE +}; + +#undef DEF +#define DEF(type, name) \ + SETTING_DEFINE_STRUCT_##type(#name, name, struct replicator_settings) + +static const struct setting_define replicator_setting_defines[] = { + DEF(STR, auth_socket_path), + DEF(STR, doveadm_socket_path), + DEF(STR, replication_dsync_parameters), + + DEF(TIME, replication_full_sync_interval), + DEF(UINT, replication_max_conns), + + SETTING_DEFINE_LIST_END +}; + +const struct replicator_settings replicator_default_settings = { + .auth_socket_path = "auth-userdb", + .doveadm_socket_path = "doveadm-server", + .replication_dsync_parameters = "-d -N -l 30 -U", + + .replication_full_sync_interval = 60*60*24, + .replication_max_conns = 10 +}; + +const struct setting_parser_info replicator_setting_parser_info = { + .module_name = "replicator", + .defines = replicator_setting_defines, + .defaults = &replicator_default_settings, + + .type_offset = SIZE_MAX, + .struct_size = sizeof(struct replicator_settings), + + .parent_offset = SIZE_MAX +}; + +const struct replicator_settings *replicator_settings; diff --git a/src/replication/replicator/replicator-settings.h b/src/replication/replicator/replicator-settings.h new file mode 100644 index 0000000..947bcf8 --- /dev/null +++ b/src/replication/replicator/replicator-settings.h @@ -0,0 +1,16 @@ +#ifndef REPLICATOR_SETTINGS_H +#define REPLICATOR_SETTINGS_H + +struct replicator_settings { + const char *auth_socket_path; + const char *doveadm_socket_path; + const char *replication_dsync_parameters; + + unsigned int replication_full_sync_interval; + unsigned int replication_max_conns; +}; + +extern const struct setting_parser_info replicator_setting_parser_info; +extern const struct replicator_settings *replicator_settings; + +#endif diff --git a/src/replication/replicator/replicator.c b/src/replication/replicator/replicator.c new file mode 100644 index 0000000..3600934 --- /dev/null +++ b/src/replication/replicator/replicator.c @@ -0,0 +1,117 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "ioloop.h" +#include "restrict-access.h" +#include "auth-master.h" +#include "master-service.h" +#include "master-service-settings.h" +#include "notify-connection.h" +#include "doveadm-connection.h" +#include "replicator-brain.h" +#include "replicator-queue.h" +#include "replicator-settings.h" + +#define REPLICATOR_DB_DUMP_INTERVAL_MSECS (1000*60*15) +/* if syncing fails, try again in 5 minutes */ +#define REPLICATOR_FAILURE_RESYNC_INTERVAL_SECS (60*5) +#define REPLICATOR_DB_FNAME "replicator.db" + +static struct replicator_queue *queue; +static struct replicator_brain *brain; +static const struct master_service_settings *service_set; +static const struct replicator_settings *set; +static struct timeout *to_dump; + +static void client_connected(struct master_service_connection *conn) +{ + master_service_client_connection_accept(conn); + if (strcmp(conn->name, "replicator-doveadm") == 0) + doveadm_connection_create(brain, conn->fd); + else + (void)notify_connection_create(conn->fd, queue); +} + +static void replication_add_users(struct replicator_queue *queue) +{ + const char *path; + + replicator_queue_add_auth_users(queue, set->auth_socket_path, "*", 0); + + /* add updates from replicator db, if it exists */ + path = t_strconcat(service_set->state_dir, "/"REPLICATOR_DB_FNAME, NULL); + (void)replicator_queue_import(queue, path); +} + +static void ATTR_NULL(1) +replicator_dump_timeout(void *context ATTR_UNUSED) +{ + const char *path; + + path = t_strconcat(service_set->state_dir, "/"REPLICATOR_DB_FNAME, NULL); + (void)replicator_queue_export(queue, path); +} + +static void main_init(void) +{ + void **sets; + + service_set = master_service_settings_get(master_service); + sets = master_service_settings_get_others(master_service); + set = sets[0]; + + queue = replicator_queue_init(set->replication_full_sync_interval, + REPLICATOR_FAILURE_RESYNC_INTERVAL_SECS); + replication_add_users(queue); + to_dump = timeout_add(REPLICATOR_DB_DUMP_INTERVAL_MSECS, + replicator_dump_timeout, NULL); + brain = replicator_brain_init(queue, set); + doveadm_connections_init(); +} + +static void main_deinit(void) +{ + const char *path; + + doveadm_connections_deinit(); + notify_connections_destroy_all(); + replicator_brain_deinit(&brain); + timeout_remove(&to_dump); + path = t_strconcat(service_set->state_dir, "/"REPLICATOR_DB_FNAME, NULL); + (void)replicator_queue_export(queue, path); + replicator_queue_deinit(&queue); +} + +int main(int argc, char *argv[]) +{ + const struct setting_parser_info *set_roots[] = { + &replicator_setting_parser_info, + NULL + }; + const enum master_service_flags service_flags = + MASTER_SERVICE_FLAG_NO_IDLE_DIE; + const char *error; + + master_service = master_service_init("replicator", service_flags, + &argc, &argv, ""); + if (master_getopt(master_service) > 0) + return FATAL_DEFAULT; + + if (master_service_settings_read_simple(master_service, set_roots, + &error) < 0) + i_fatal("Error reading configuration: %s", error); + master_service_init_log(master_service); + + restrict_access_by_env(RESTRICT_ACCESS_FLAG_ALLOW_ROOT, NULL); + restrict_access_allow_coredumps(TRUE); + /* finish init before we get list of users from auth, because that + can take long enough for master process to kill us otherwise. */ + master_service_init_finish(master_service); + + main_init(); + master_service_run(master_service, client_connected); + main_deinit(); + + master_service_deinit(&master_service); + return 0; +} diff --git a/src/replication/replicator/test-replicator-queue.c b/src/replication/replicator/test-replicator-queue.c new file mode 100644 index 0000000..9ffa5ff --- /dev/null +++ b/src/replication/replicator/test-replicator-queue.c @@ -0,0 +1,260 @@ +/* Copyright (c) 2022 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "ioloop.h" +#include "test-common.h" +#include "replicator-queue.h" + +#define TEST_REPLICATION_FULL_SYNC_INTERVAL 60 +#define TEST_REPLICATION_FAILURE_RESYNC_INTERVAL 10 + +static void test_replicator_queue(void) +{ + struct replicator_queue *queue; + struct replicator_user *user1, *user2, *user3, *user4; + unsigned int next_secs; + + test_begin("replicator queue"); + queue = replicator_queue_init(TEST_REPLICATION_FULL_SYNC_INTERVAL, + TEST_REPLICATION_FAILURE_RESYNC_INTERVAL); + ioloop_time = time(NULL); + + /* 1) Add users */ + + /* add the 1st user with priority=none */ + user1 = replicator_queue_get(queue, "user1"); + replicator_queue_update(queue, user1, REPLICATION_PRIORITY_NONE); + replicator_queue_add(queue, user1); + test_assert(replicator_queue_count(queue) == 1); + test_assert(replicator_queue_peek(queue, &next_secs) == user1 && next_secs == 0); + + /* add the 2nd user with priority=none */ + user2 = replicator_queue_get(queue, "user2"); + replicator_queue_update(queue, user2, REPLICATION_PRIORITY_NONE); + replicator_queue_add(queue, user2); + test_assert(replicator_queue_count(queue) == 2); + test_assert(replicator_queue_peek(queue, &next_secs) == user1 && next_secs == 0); + + /* add the 3rd user with priority=none */ + user3 = replicator_queue_get(queue, "user3"); + replicator_queue_update(queue, user3, REPLICATION_PRIORITY_NONE); + replicator_queue_add(queue, user3); + test_assert(replicator_queue_count(queue) == 3); + test_assert(replicator_queue_peek(queue, &next_secs) == user1 && next_secs == 0); + + /* 2) User hasn't been synced yet, but priority is updated */ + + /* update the 2nd user's priority to low */ + user2 = replicator_queue_get(queue, "user2"); + replicator_queue_update(queue, user2, REPLICATION_PRIORITY_LOW); + replicator_queue_add(queue, user2); + test_assert(replicator_queue_peek(queue, &next_secs) == user2 && next_secs == 0); + + /* update the 1st user's priority to high */ + user1 = replicator_queue_get(queue, "user1"); + replicator_queue_update(queue, user1, REPLICATION_PRIORITY_HIGH); + replicator_queue_add(queue, user1); + test_assert(replicator_queue_peek(queue, &next_secs) == user1 && next_secs == 0); + + /* update the 2nd user's priority to sync */ + user2 = replicator_queue_get(queue, "user2"); + replicator_queue_update(queue, user2, REPLICATION_PRIORITY_SYNC); + replicator_queue_add(queue, user2); + test_assert(replicator_queue_peek(queue, &next_secs) == user2 && next_secs == 0); + + /* 3) User hasn't been synced, and priority is being updated. + user1 was synced 1 second before user2. */ + user1->last_fast_sync = ioloop_time; + user1->last_full_sync = ioloop_time; + user1->priority = REPLICATION_PRIORITY_NONE; + replicator_queue_add(queue, user1); + ioloop_time++; + user2->last_fast_sync = ioloop_time; + user2->last_full_sync = ioloop_time; + user2->priority = REPLICATION_PRIORITY_NONE; + replicator_queue_add(queue, user2); + ioloop_time++; + user3->last_fast_sync = ioloop_time; + user3->last_full_sync = ioloop_time; + user3->priority = REPLICATION_PRIORITY_NONE; + replicator_queue_add(queue, user3); + test_assert(replicator_queue_peek(queue, &next_secs) == user1 && next_secs > 0); + + /* update the 2nd user's priority to low */ + user2 = replicator_queue_get(queue, "user2"); + replicator_queue_update(queue, user2, REPLICATION_PRIORITY_LOW); + replicator_queue_add(queue, user2); + test_assert(replicator_queue_peek(queue, &next_secs) == user2 && next_secs == 0); + + /* update the 1st user's priority to high */ + user1 = replicator_queue_get(queue, "user1"); + replicator_queue_update(queue, user1, REPLICATION_PRIORITY_HIGH); + replicator_queue_add(queue, user1); + test_assert(replicator_queue_peek(queue, &next_secs) == user1 && next_secs == 0); + + /* update the 2nd user's priority to sync */ + user2 = replicator_queue_get(queue, "user2"); + replicator_queue_update(queue, user2, REPLICATION_PRIORITY_SYNC); + replicator_queue_add(queue, user2); + test_assert(replicator_queue_peek(queue, &next_secs) == user2 && next_secs == 0); + + /* 4) Test failed sync with a new user */ + user1->priority = REPLICATION_PRIORITY_NONE; + replicator_queue_add(queue, user1); + user2->priority = REPLICATION_PRIORITY_NONE; + replicator_queue_add(queue, user2); + + user4 = replicator_queue_get(queue, "user4"); + user4->last_fast_sync = ioloop_time - 5; + user4->last_sync_failed = TRUE; + replicator_queue_add(queue, user4); + + test_assert(replicator_queue_count(queue) == 4); + test_assert(replicator_queue_peek(queue, &next_secs) == user4 && + next_secs == TEST_REPLICATION_FAILURE_RESYNC_INTERVAL - 5); + + /* low priority sync is prioritized over failed sync */ + replicator_queue_update(queue, user1, REPLICATION_PRIORITY_LOW); + replicator_queue_add(queue, user1); + test_assert(replicator_queue_peek(queue, &next_secs) == user1 && next_secs == 0); + + /* However, if the last failure was old enough it will be before + the low priority one. Test the edge case. */ + user4->last_fast_sync = ioloop_time - + TEST_REPLICATION_FAILURE_RESYNC_INTERVAL - + (60*15) - 1; + replicator_queue_add(queue, user4); + test_assert(replicator_queue_peek(queue, &next_secs) == user4 && next_secs == 0); + user4->last_fast_sync++; + replicator_queue_add(queue, user4); + test_assert(replicator_queue_peek(queue, &next_secs) == user1 && next_secs == 0); + + /* 5) Test priority starvation */ + + /* high priority is normally prioritized over low priority */ + i_assert(user1->priority == REPLICATION_PRIORITY_LOW); + user2 = replicator_queue_get(queue, "user2"); + replicator_queue_update(queue, user2, REPLICATION_PRIORITY_HIGH); + replicator_queue_add(queue, user2); + test_assert(replicator_queue_peek(queue, &next_secs) == user2 && next_secs == 0); + + /* if low priority is old enough, it gets prioritized over high */ + user1->last_update = ioloop_time - (60*15) - 1; + replicator_queue_add(queue, user1); + test_assert(replicator_queue_peek(queue, &next_secs) == user1 && next_secs == 0); + user1->last_update++; + replicator_queue_add(queue, user1); + test_assert(replicator_queue_peek(queue, &next_secs) == user2 && next_secs == 0); + + /* similarly low priority eventually gets prioritized over sync + priority */ + replicator_queue_update(queue, user2, REPLICATION_PRIORITY_SYNC); + replicator_queue_add(queue, user2); + user1->last_update = ioloop_time - (60*30) - 1; + replicator_queue_add(queue, user1); + test_assert(replicator_queue_peek(queue, &next_secs) == user1 && next_secs == 0); + user1->last_update++; + replicator_queue_add(queue, user1); + test_assert(replicator_queue_peek(queue, &next_secs) == user2 && next_secs == 0); + + /* likewise for none priority also */ + user1->priority = REPLICATION_PRIORITY_NONE; + user1->last_update = ioloop_time; + user1->last_fast_sync = ioloop_time; + user1->last_full_sync = ioloop_time - (60*45) - + TEST_REPLICATION_FULL_SYNC_INTERVAL - 1; + replicator_queue_add(queue, user1); + test_assert(replicator_queue_peek(queue, &next_secs) == user1 && next_secs == 0); + user1->last_full_sync++; + replicator_queue_add(queue, user1); + test_assert(replicator_queue_peek(queue, &next_secs) == user2 && next_secs == 0); + + replicator_queue_deinit(&queue); + test_end(); +} + +static void test_replicator_queue_verify_drained(struct replicator_queue *queue) +{ + struct replicator_queue_iter *iter = + replicator_queue_iter_init(queue); + struct replicator_user *user; + while ((user = replicator_queue_iter_next(iter)) != NULL) { + i_assert(user->priority == REPLICATION_PRIORITY_NONE); + i_assert(user->last_sync_failed || + ioloop_time - user->last_full_sync < TEST_REPLICATION_FULL_SYNC_INTERVAL); + } + replicator_queue_iter_deinit(&iter); +} + +static void test_replicator_queue_drain(struct replicator_queue *queue) +{ + struct replicator_user *user; + unsigned int next_secs; + enum replication_priority prev_priority = REPLICATION_PRIORITY_SYNC; + time_t prev_sync = INT_MAX; + + while ((user = replicator_queue_pop(queue, &next_secs)) != NULL) { + if (user->priority < prev_priority) { + prev_sync = INT_MAX; + } else { + test_assert(user->priority == prev_priority); + if (user->priority == REPLICATION_PRIORITY_NONE) { + test_assert(user->last_full_sync <= prev_sync); + prev_sync = user->last_full_sync; + } else { + test_assert(user->last_fast_sync <= prev_sync); + prev_sync = user->last_fast_sync; + } + } + user->priority = REPLICATION_PRIORITY_NONE; + user->last_fast_sync = user->last_full_sync = ioloop_time-1; + /* dsync runs here */ + if (i_rand_limit(5) == 0) + user->last_sync_failed = TRUE; + else { + user->last_successful_sync = ioloop_time; + user->last_sync_failed = FALSE; + } + replicator_queue_push(queue, user); + } + test_replicator_queue_verify_drained(queue); +} + +static void test_replicator_queue_random(void) +{ + struct replicator_queue *queue; + struct replicator_user *user; + + test_begin("replicator queue random"); + queue = replicator_queue_init(TEST_REPLICATION_FULL_SYNC_INTERVAL, + TEST_REPLICATION_FAILURE_RESYNC_INTERVAL); + /* fill some users */ + ioloop_time = time(NULL); + for (unsigned int i = 0; i < 1000; i++) T_BEGIN { + enum replication_priority priority = + i_rand_minmax(REPLICATION_PRIORITY_NONE, + REPLICATION_PRIORITY_SYNC); + const char *username = + t_strdup_printf("test%u", i_rand_minmax(1, 200)); + user = replicator_queue_get(queue, username); + replicator_queue_update(queue, user, priority); + replicator_queue_add(queue, user); + ioloop_time++; + } T_END; + for (unsigned int i = 0; i < 1000; i++) { + test_replicator_queue_drain(queue); + ioloop_time++; + } + replicator_queue_deinit(&queue); + test_end(); +} + +int main(void) +{ + static void (*const test_functions[])(void) = { + test_replicator_queue, + test_replicator_queue_random, + NULL + }; + return test_run(test_functions); +} -- cgit v1.2.3