diff options
Diffstat (limited to 'src/log')
-rw-r--r-- | src/log/Makefile.am | 26 | ||||
-rw-r--r-- | src/log/Makefile.in | 825 | ||||
-rw-r--r-- | src/log/doveadm-connection.c | 86 | ||||
-rw-r--r-- | src/log/doveadm-connection.h | 6 | ||||
-rw-r--r-- | src/log/log-connection.c | 533 | ||||
-rw-r--r-- | src/log/log-connection.h | 15 | ||||
-rw-r--r-- | src/log/log-error-buffer.c | 122 | ||||
-rw-r--r-- | src/log/log-error-buffer.h | 24 | ||||
-rw-r--r-- | src/log/log-settings.c | 49 | ||||
-rw-r--r-- | src/log/main.c | 97 |
10 files changed, 1783 insertions, 0 deletions
diff --git a/src/log/Makefile.am b/src/log/Makefile.am new file mode 100644 index 0000000..9888fcd --- /dev/null +++ b/src/log/Makefile.am @@ -0,0 +1,26 @@ +pkglibexecdir = $(libexecdir)/dovecot + +pkglibexec_PROGRAMS = log + +AM_CPPFLAGS = \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-settings \ + -I$(top_srcdir)/src/lib-master \ + $(BINARY_CFLAGS) + +log_LDADD = $(LIBDOVECOT) \ + $(BINARY_LDFLAGS) + +log_DEPENDENCIES = $(LIBDOVECOT_DEPS) + +log_SOURCES = \ + doveadm-connection.c \ + log-connection.c \ + log-error-buffer.c \ + log-settings.c \ + main.c + +noinst_HEADERS = \ + doveadm-connection.h \ + log-connection.h \ + log-error-buffer.h diff --git a/src/log/Makefile.in b/src/log/Makefile.in new file mode 100644 index 0000000..33a2595 --- /dev/null +++ b/src/log/Makefile.in @@ -0,0 +1,825 @@ +# Makefile.in generated by automake 1.16.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2018 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 = log$(EXEEXT) +subdir = src/log +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_log_OBJECTS = doveadm-connection.$(OBJEXT) log-connection.$(OBJEXT) \ + log-error-buffer.$(OBJEXT) log-settings.$(OBJEXT) \ + main.$(OBJEXT) +log_OBJECTS = $(am_log_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 = +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)/log-connection.Po ./$(DEPDIR)/log-error-buffer.Po \ + ./$(DEPDIR)/log-settings.Po ./$(DEPDIR)/main.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 = $(log_SOURCES) +DIST_SOURCES = $(log_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-master \ + $(BINARY_CFLAGS) + +log_LDADD = $(LIBDOVECOT) \ + $(BINARY_LDFLAGS) + +log_DEPENDENCIES = $(LIBDOVECOT_DEPS) +log_SOURCES = \ + doveadm-connection.c \ + log-connection.c \ + log-error-buffer.c \ + log-settings.c \ + main.c + +noinst_HEADERS = \ + doveadm-connection.h \ + log-connection.h \ + log-error-buffer.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/log/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/log/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 + +log$(EXEEXT): $(log_OBJECTS) $(log_DEPENDENCIES) $(EXTRA_log_DEPENDENCIES) + @rm -f log$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(log_OBJECTS) $(log_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)/log-connection.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log-error-buffer.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log-settings.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.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)/doveadm-connection.Po + -rm -f ./$(DEPDIR)/log-connection.Po + -rm -f ./$(DEPDIR)/log-error-buffer.Po + -rm -f ./$(DEPDIR)/log-settings.Po + -rm -f ./$(DEPDIR)/main.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)/log-connection.Po + -rm -f ./$(DEPDIR)/log-error-buffer.Po + -rm -f ./$(DEPDIR)/log-settings.Po + -rm -f ./$(DEPDIR)/main.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/log/doveadm-connection.c b/src/log/doveadm-connection.c new file mode 100644 index 0000000..77872ac --- /dev/null +++ b/src/log/doveadm-connection.c @@ -0,0 +1,86 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "ostream.h" +#include "str.h" +#include "strescape.h" +#include "master-service.h" +#include "log-error-buffer.h" +#include "doveadm-connection.h" + +#include <unistd.h> + +struct doveadm_connection { + struct log_error_buffer *errorbuf; + + int fd; + struct ostream *output; +}; + +static void doveadm_connection_destroy(struct doveadm_connection **_conn); + +static int doveadm_connection_send_errors(struct doveadm_connection *conn) +{ + struct log_error_buffer_iter *iter; + const struct log_error *error; + string_t *str = t_str_new(256); + int ret = 0; + + iter = log_error_buffer_iter_init(conn->errorbuf); + while ((error = log_error_buffer_iter_next(iter)) != NULL) { + str_truncate(str, 0); + str_printfa(str, "%s\t%ld\t", + failure_log_type_names[error->type], + (long)error->timestamp); + str_append_tabescaped(str, error->prefix); + str_append_c(str, '\t'); + str_append_tabescaped(str, error->text); + str_append_c(str, '\n'); + if (o_stream_send(conn->output, + str_data(str), str_len(str)) < 0) { + ret = -1; + break; + } + } + log_error_buffer_iter_deinit(&iter); + return ret; +} + +static int doveadm_output(struct doveadm_connection *conn) +{ + if (o_stream_flush(conn->output) != 0) { + /* error / finished */ + doveadm_connection_destroy(&conn); + } + return 1; +} + +void doveadm_connection_create(struct log_error_buffer *errorbuf, int fd) +{ + struct doveadm_connection *conn; + + conn = i_new(struct doveadm_connection, 1); + conn->errorbuf = errorbuf; + conn->fd = fd; + conn->output = o_stream_create_fd(conn->fd, SIZE_MAX); + if (doveadm_connection_send_errors(conn) < 0) + doveadm_connection_destroy(&conn); + else { + o_stream_set_flush_callback(conn->output, doveadm_output, conn); + o_stream_set_flush_pending(conn->output, TRUE); + } +} + +static void doveadm_connection_destroy(struct doveadm_connection **_conn) +{ + struct doveadm_connection *conn = *_conn; + + *_conn = NULL; + + o_stream_destroy(&conn->output); + if (close(conn->fd) < 0) + i_error("close(doveadm connection) failed: %m"); + i_free(conn); + + master_service_client_connection_destroyed(master_service); +} diff --git a/src/log/doveadm-connection.h b/src/log/doveadm-connection.h new file mode 100644 index 0000000..c37eee4 --- /dev/null +++ b/src/log/doveadm-connection.h @@ -0,0 +1,6 @@ +#ifndef DOVEADM_CONNECTION_H +#define DOVEADM_CONNECTION_H + +void doveadm_connection_create(struct log_error_buffer *errorbuf, int fd); + +#endif diff --git a/src/log/log-connection.c b/src/log/log-connection.c new file mode 100644 index 0000000..82c9374 --- /dev/null +++ b/src/log/log-connection.c @@ -0,0 +1,533 @@ +/* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "array.h" +#include "ioloop.h" +#include "istream.h" +#include "llist.h" +#include "hash.h" +#include "time-util.h" +#include "process-title.h" +#include "master-interface.h" +#include "master-service.h" +#include "log-error-buffer.h" +#include "log-connection.h" + +#include <stdio.h> +#include <unistd.h> + +#define FATAL_QUEUE_TIMEOUT_MSECS 500 +#define MAX_MSECS_PER_CONNECTION 100 + +/* Log a warning after 1 secs when we've been all the time busy writing the + log connection. */ +#define LOG_WARN_PENDING_COUNT (1000 / MAX_MSECS_PER_CONNECTION) +/* If we keep being busy, log a warning every 60 seconds. */ +#define LOG_WARN_PENDING_INTERVAL (60 * LOG_WARN_PENDING_COUNT) + +struct log_client { + struct ip_addr ip; + char *prefix; + bool fatal_logged:1; +}; + +struct log_line_metadata { + bool continues; + enum log_type log_type; + pid_t pid; + char *log_prefix; +}; + +struct log_connection { + struct log_connection *prev, *next; + + struct log_error_buffer *errorbuf; + int fd; + int listen_fd; + struct io *io; + struct istream *input; + + struct log_line_metadata partial_line; + + char *default_prefix; + HASH_TABLE(void *, struct log_client *) clients; + + unsigned int pending_count; + + bool master:1; + bool handshaked:1; +}; + +static struct log_connection *log_connections = NULL; +static ARRAY(struct log_connection *) logs_by_fd; +static unsigned int global_pending_count; +static struct log_connection *last_pending_log; + +static void +log_connection_destroy(struct log_connection *log, bool shutting_down); + +static void log_refresh_proctitle(void) +{ + if (!verbose_proctitle) + return; + + if (global_pending_count == 0) + process_title_set(""); + else if (last_pending_log == NULL) { + process_title_set(t_strdup_printf( + "[%u services too fast]", global_pending_count)); + } else if (global_pending_count > 1) { + process_title_set(t_strdup_printf( + "[%u services too fast, last: %d/%d/%s]", + global_pending_count, + last_pending_log->fd, + last_pending_log->listen_fd, + last_pending_log->default_prefix)); + } else { + process_title_set(t_strdup_printf( + "[service too fast: %d/%d/%s]", + last_pending_log->fd, + last_pending_log->listen_fd, + last_pending_log->default_prefix)); + } +} + +static struct log_client *log_client_get(struct log_connection *log, pid_t pid) +{ + struct log_client *client; + + client = hash_table_lookup(log->clients, POINTER_CAST(pid)); + if (client == NULL) { + client = i_new(struct log_client, 1); + hash_table_insert(log->clients, POINTER_CAST(pid), client); + } + return client; +} + +static void log_client_free(struct log_connection *log, + struct log_client *client, pid_t pid) +{ + hash_table_remove(log->clients, POINTER_CAST(pid)); + + i_free(client->prefix); + i_free(client); +} + +static void log_parse_option(struct log_connection *log, + const struct failure_line *failure) +{ + struct log_client *client; + + client = log_client_get(log, failure->pid); + if (str_begins(failure->text, "ip=")) + (void)net_addr2ip(failure->text + 3, &client->ip); + else if (str_begins(failure->text, "prefix=")) { + i_free(client->prefix); + client->prefix = i_strdup(failure->text + 7); + } +} + +static void +client_log_ctx(struct log_connection *log, + const struct failure_context *ctx, + const struct timeval *log_time, + const char *prefix, const char *text) +{ + struct log_error err; + + switch (ctx->type) { + case LOG_TYPE_DEBUG: + case LOG_TYPE_INFO: + break; + case LOG_TYPE_WARNING: + case LOG_TYPE_ERROR: + case LOG_TYPE_FATAL: + case LOG_TYPE_PANIC: + i_zero(&err); + err.type = ctx->type; + err.timestamp = log_time->tv_sec; + err.prefix = ctx->log_prefix != NULL ? ctx->log_prefix : prefix; + err.text = text; + log_error_buffer_add(log->errorbuf, &err); + break; + case LOG_TYPE_OPTION: + case LOG_TYPE_COUNT: + i_unreached(); + } + /* log_prefix overrides the global prefix. Don't bother changing the + global prefix in that case. */ + if (ctx->log_prefix == NULL) + i_set_failure_prefix("%s", prefix); + i_log_type(ctx, "%s", text); + if (ctx->log_prefix == NULL) + i_set_failure_prefix("%s", global_log_prefix); +} + +static void +client_log_fatal(struct log_connection *log, struct log_client *client, + const char *line, const struct timeval *log_time, + const struct tm *tm) +{ + struct failure_context failure_ctx; + const char *prefix = log->default_prefix; + + i_zero(&failure_ctx); + failure_ctx.type = LOG_TYPE_FATAL; + failure_ctx.timestamp = tm; + failure_ctx.timestamp_usecs = log_time->tv_usec; + + if (client != NULL) { + if (client->prefix != NULL) + prefix = client->prefix; + else if (client->ip.family != 0) { + line = t_strdup_printf("%s [last ip=%s]", + line, net_ip2addr(&client->ip)); + } + } + client_log_ctx(log, &failure_ctx, log_time, prefix, + t_strconcat("master: ", line, NULL)); +} + +static void +log_parse_master_line(const char *line, const struct timeval *log_time, + const struct tm *tm) +{ + struct log_connection *const *logs, *log; + struct log_client *client; + const char *p, *p2, *cmd, *pidstr; + unsigned int count; + unsigned int service_fd; + pid_t pid; + + p = strchr(line, ' '); + if (p == NULL || (p2 = strchr(++p, ' ')) == NULL || + str_to_uint(t_strcut(line, ' '), &service_fd) < 0) { + i_error("Received invalid input from master: %s", line); + return; + } + pidstr = t_strcut(p, ' '); + if (str_to_pid(pidstr, &pid) < 0) { + i_error("Received invalid pid from master: %s", pidstr); + return; + } + cmd = p2 + 1; + + logs = array_get(&logs_by_fd, &count); + if (service_fd >= count || logs[service_fd] == NULL) { + if (strcmp(cmd, "BYE") == 0 && service_fd < count) { + /* master is probably shutting down and we already + noticed the log fd closing */ + return; + } + i_error("Received master input for invalid service_fd %u: %s", + service_fd, line); + return; + } + log = logs[service_fd]; + client = hash_table_lookup(log->clients, POINTER_CAST(pid)); + + if (strcmp(cmd, "BYE") == 0) { + if (client == NULL) { + /* we haven't seen anything important from this client. + it's not an error. */ + return; + } + log_client_free(log, client, pid); + } else if (str_begins(cmd, "FATAL ")) { + client_log_fatal(log, client, cmd + 6, log_time, tm); + } else if (str_begins(cmd, "DEFAULT-FATAL ")) { + /* If the client has logged a fatal/panic, don't log this + message. */ + if (client == NULL || !client->fatal_logged) + client_log_fatal(log, client, cmd + 14, log_time, tm); + } else { + i_error("Received unknown command from master: %s", cmd); + } +} + +static void log_partial_line_free(struct log_connection *log) +{ + if (!log->partial_line.continues) + return; + i_free(log->partial_line.log_prefix); + i_zero(&log->partial_line); +} + +static void +log_it(struct log_connection *log, const char *line, + const struct timeval *log_time, const struct tm *tm, bool partial_line) +{ + struct failure_line failure; + struct failure_context failure_ctx; + struct log_client *client = NULL; + const char *prefix = ""; + + if (log->master) { + if (partial_line) { + /* really not expected */ + i_error("Received partial line from master: %s", line); + } + log_parse_master_line(line, log_time, tm); + return; + } + + if (log->partial_line.continues && line[0] != '\001') { + /* The previous line didn't have LF, and it's now continued + here. We have the extra \001 check in here, because the + write was larger than PIPE_BUF and there's no guarantee + that the full write is sequential. The second line could + be an unrelated line, and the continuation could happen + sometimes after it. */ + i_zero(&failure); + failure.log_type = log->partial_line.log_type; + failure.pid = log->partial_line.pid; + failure.text = t_strconcat("<line continued> ", line, NULL); + if (log->partial_line.log_prefix != NULL) + prefix = t_strdup(log->partial_line.log_prefix); + if (!partial_line) + log_partial_line_free(log); + } else { + i_failure_parse_line(line, &failure); + if (partial_line) { + log->partial_line.continues = TRUE; + log->partial_line.log_type = failure.log_type; + log->partial_line.pid = failure.pid; + } else { + log_partial_line_free(log); + } + } + switch (failure.log_type) { + case LOG_TYPE_FATAL: + case LOG_TYPE_PANIC: + if (failure.pid != 0) { + client = log_client_get(log, failure.pid); + client->fatal_logged = TRUE; + } + break; + case LOG_TYPE_OPTION: + log_parse_option(log, &failure); + return; + default: + client = failure.pid == 0 ? NULL : + hash_table_lookup(log->clients, + POINTER_CAST(failure.pid)); + break; + } + i_assert(failure.log_type < LOG_TYPE_COUNT); + + i_zero(&failure_ctx); + failure_ctx.type = failure.log_type; + failure_ctx.timestamp = tm; + failure_ctx.timestamp_usecs = log_time->tv_usec; + if (failure.log_prefix_len != 0) { + failure_ctx.log_prefix = + t_strndup(failure.text, failure.log_prefix_len); + failure.text += failure.log_prefix_len; + if (partial_line && log->partial_line.log_prefix == NULL) { + log->partial_line.log_prefix = + i_strdup(failure_ctx.log_prefix); + } + } else if (failure.disable_log_prefix) { + failure_ctx.log_prefix = ""; + } else { + prefix = client != NULL && client->prefix != NULL ? + client->prefix : log->default_prefix; + } + client_log_ctx(log, &failure_ctx, log_time, prefix, failure.text); +} + +static int log_connection_handshake(struct log_connection *log) +{ + struct log_service_handshake handshake; + const unsigned char *data; + size_t size; + ssize_t ret; + + /* we're reading from a FIFO, so we're assuming that we're getting a + full handshake packet immediately. if not, treat it as an error + message that we want to log. */ + ret = i_stream_read(log->input); + if (ret == -1) { + i_error("read(log %s) failed: %s", log->default_prefix, + i_stream_get_error(log->input)); + return -1; + } + data = i_stream_get_data(log->input, &size); + if (size < sizeof(handshake)) { + /* this isn't a handshake */ + return 0; + } + + i_assert(size >= sizeof(handshake)); + memcpy(&handshake, data, sizeof(handshake)); + + if (handshake.log_magic != MASTER_LOG_MAGIC) { + /* this isn't a handshake */ + return 0; + } + + if (handshake.prefix_len > size - sizeof(handshake)) { + i_error("Missing prefix data in handshake"); + return -1; + } + i_free(log->default_prefix); + log->default_prefix = i_strndup(data + sizeof(handshake), + handshake.prefix_len); + i_stream_skip(log->input, sizeof(handshake) + handshake.prefix_len); + + if (strcmp(log->default_prefix, MASTER_LOG_PREFIX_NAME) == 0) { + if (log->listen_fd != MASTER_LISTEN_FD_FIRST) { + i_error("Received master prefix in handshake " + "from non-master fd %d", log->fd); + return -1; + } + log->master = TRUE; + } + log->handshaked = TRUE; + return 0; +} + +static void log_connection_input(struct log_connection *log) +{ + const char *line; + ssize_t ret; + struct timeval now, start_timeval; + struct tm tm; + bool too_much = FALSE; + + if (!log->handshaked) { + if (log_connection_handshake(log) < 0) { + log_connection_destroy(log, FALSE); + return; + } + /* come back here even if we read something else besides a + handshake. the first few lines could be coming from e.g. + libc before the proper handshake line is sent. */ + } + + io_loop_time_refresh(); + start_timeval = ioloop_timeval; + while ((ret = i_stream_read(log->input)) > 0 || ret == -2) { + /* get new timestamps for every read() */ + now = ioloop_timeval; + tm = *localtime(&now.tv_sec); + + if (ret != -2) { + while ((line = i_stream_next_line(log->input)) != NULL) T_BEGIN { + log_it(log, line, &now, &tm, FALSE); + } T_END; + } else T_BEGIN { + /* LF not found, but buffer is full. Just log what we + have for now. */ + size_t size; + const unsigned char *data = + i_stream_get_data(log->input, &size); + line = t_strndup(data, size); + log_it(log, line, &now, &tm, TRUE); + i_stream_skip(log->input, size); + } T_END; + io_loop_time_refresh(); + if (timeval_diff_msecs(&ioloop_timeval, &start_timeval) > MAX_MSECS_PER_CONNECTION) { + too_much = TRUE; + break; + } + } + + if (log->input->eof) { + if (log->input->stream_errno != 0) + i_error("read(log %s) failed: %m", log->default_prefix); + log_connection_destroy(log, FALSE); + } else { + i_assert(!log->input->closed); + if (!too_much) { + if (log->pending_count > 0) { + log->pending_count = 0; + i_assert(global_pending_count > 0); + global_pending_count--; + if (log == last_pending_log) + last_pending_log = NULL; + log_refresh_proctitle(); + } + return; + } + last_pending_log = log; + if (log->pending_count++ == 0) { + global_pending_count++; + log_refresh_proctitle(); + } + if (log->pending_count == LOG_WARN_PENDING_COUNT || + (log->pending_count % LOG_WARN_PENDING_INTERVAL) == 0) { + i_warning("Log connection fd %d listen_fd %d prefix '%s' is sending input faster than we can write", + log->fd, log->listen_fd, log->default_prefix); + } + } +} + +void log_connection_create(struct log_error_buffer *errorbuf, + int fd, int listen_fd) +{ + struct log_connection *log; + + log = i_new(struct log_connection, 1); + log->errorbuf = errorbuf; + log->fd = fd; + log->listen_fd = listen_fd; + log->io = io_add(fd, IO_READ, log_connection_input, log); + log->input = i_stream_create_fd(fd, PIPE_BUF); + log->default_prefix = i_strdup_printf("listen_fd(%d): ", listen_fd); + hash_table_create_direct(&log->clients, default_pool, 0); + array_idx_set(&logs_by_fd, listen_fd, &log); + + DLLIST_PREPEND(&log_connections, log); + log_connection_input(log); +} + +static void +log_connection_destroy(struct log_connection *log, bool shutting_down) +{ + struct hash_iterate_context *iter; + void *key; + struct log_client *client; + unsigned int client_count = 0; + + array_idx_clear(&logs_by_fd, log->listen_fd); + + DLLIST_REMOVE(&log_connections, log); + + iter = hash_table_iterate_init(log->clients); + while (hash_table_iterate(iter, log->clients, &key, &client)) { + i_free(client); + client_count++; + } + hash_table_iterate_deinit(&iter); + hash_table_destroy(&log->clients); + + if (client_count > 0 && shutting_down) { + i_warning("Shutting down logging for '%s' with %u clients", + log->default_prefix, client_count); + } + + i_stream_unref(&log->input); + io_remove(&log->io); + if (close(log->fd) < 0) + i_error("close(log connection fd) failed: %m"); + log_partial_line_free(log); + i_free(log->default_prefix); + i_free(log); + + master_service_client_connection_destroyed(master_service); +} + +void log_connections_init(void) +{ + i_array_init(&logs_by_fd, 64); +} + +void log_connections_deinit(void) +{ + /* normally we don't exit until all log connections are gone, + but we could get here when we're being killed by a signal */ + while (log_connections != NULL) + log_connection_destroy(log_connections, TRUE); + array_free(&logs_by_fd); +} diff --git a/src/log/log-connection.h b/src/log/log-connection.h new file mode 100644 index 0000000..2885399 --- /dev/null +++ b/src/log/log-connection.h @@ -0,0 +1,15 @@ +#ifndef LOG_CONNECTION_H +#define LOG_CONNECTION_H + +struct log_connection; + +extern bool verbose_proctitle; +extern char *global_log_prefix; + +void log_connection_create(struct log_error_buffer *errorbuf, + int fd, int listen_fd); + +void log_connections_init(void); +void log_connections_deinit(void); + +#endif diff --git a/src/log/log-error-buffer.c b/src/log/log-error-buffer.c new file mode 100644 index 0000000..608d1ad --- /dev/null +++ b/src/log/log-error-buffer.c @@ -0,0 +1,122 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "log-error-buffer.h" + +#define LOG_ERROR_BUFFER_MAX_LINES 1000 + +struct log_error_data { + struct log_error_data *next; + + enum log_type type; + time_t timestamp; + unsigned char prefix_text[FLEXIBLE_ARRAY_MEMBER]; +}; + +struct log_error_buffer { + struct log_error_data *head, *tail; + unsigned int count; +}; + +struct log_error_buffer_iter { + struct log_error_buffer *buf; + struct log_error_data *cur; + struct log_error error; +}; + +struct log_error_buffer *log_error_buffer_init(void) +{ + struct log_error_buffer *buf; + + buf = i_new(struct log_error_buffer, 1); + return buf; +} + +static void log_error_buffer_delete_head(struct log_error_buffer *buf) +{ + struct log_error_data *data; + + i_assert(buf->head != NULL); + + buf->count--; + data = buf->head; + buf->head = data->next; + if (buf->tail == data) { + /* last one */ + buf->tail = NULL; + } + i_free(data); +} + +void log_error_buffer_add(struct log_error_buffer *buf, + const struct log_error *error) +{ + size_t prefix_size = strlen(error->prefix)+1; + size_t text_size = strlen(error->text)+1; + struct log_error_data *data; + + if (buf->count == LOG_ERROR_BUFFER_MAX_LINES) + log_error_buffer_delete_head(buf); + + /* @UNSAFE */ + data = i_malloc(MALLOC_ADD(sizeof(*data), + MALLOC_ADD(prefix_size, text_size))); + data->type = error->type; + data->timestamp = error->timestamp; + memcpy(data->prefix_text, error->prefix, prefix_size); + memcpy(data->prefix_text + prefix_size, error->text, text_size); + + if (buf->tail != NULL) + buf->tail->next = data; + else + buf->head = data; + buf->tail = data; + buf->count++; +} + +void log_error_buffer_deinit(struct log_error_buffer **_buf) +{ + struct log_error_buffer *buf = *_buf; + + *_buf = NULL; + while (buf->count > 0) + log_error_buffer_delete_head(buf); + i_free(buf); +} + +struct log_error_buffer_iter * +log_error_buffer_iter_init(struct log_error_buffer *buf) +{ + struct log_error_buffer_iter *iter; + + iter = i_new(struct log_error_buffer_iter, 1); + iter->buf = buf; + iter->cur = buf->head; + return iter; +} + +struct log_error * +log_error_buffer_iter_next(struct log_error_buffer_iter *iter) +{ + struct log_error_data *data = iter->cur; + + if (data == NULL) + return NULL; + iter->cur = iter->cur->next; + + iter->error.type = data->type; + iter->error.timestamp = data->timestamp; + iter->error.prefix = (const void *)data->prefix_text; + iter->error.text = (const void *)(data->prefix_text + + strlen(iter->error.prefix) + 1); + return &iter->error; +} + +void log_error_buffer_iter_deinit(struct log_error_buffer_iter **_iter) +{ + struct log_error_buffer_iter *iter = *_iter; + + *_iter = NULL; + + i_free(iter); +} diff --git a/src/log/log-error-buffer.h b/src/log/log-error-buffer.h new file mode 100644 index 0000000..e863c35 --- /dev/null +++ b/src/log/log-error-buffer.h @@ -0,0 +1,24 @@ +#ifndef LOG_ERROR_BUFFER_H +#define LOG_ERROR_BUFFER_H + +struct log_error_buffer; + +struct log_error { + enum log_type type; + time_t timestamp; + const char *prefix; + const char *text; +}; + +struct log_error_buffer *log_error_buffer_init(void); +void log_error_buffer_add(struct log_error_buffer *buf, + const struct log_error *error); +void log_error_buffer_deinit(struct log_error_buffer **buf); + +struct log_error_buffer_iter * +log_error_buffer_iter_init(struct log_error_buffer *buf); +struct log_error * +log_error_buffer_iter_next(struct log_error_buffer_iter *iter); +void log_error_buffer_iter_deinit(struct log_error_buffer_iter **iter); + +#endif diff --git a/src/log/log-settings.c b/src/log/log-settings.c new file mode 100644 index 0000000..7c55544 --- /dev/null +++ b/src/log/log-settings.c @@ -0,0 +1,49 @@ +/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "buffer.h" +#include "settings-parser.h" +#include "service-settings.h" + +#include <stddef.h> + +/* <settings checks> */ +static struct file_listener_settings log_unix_listeners_array[] = { + { "log-errors", 0600, "", "" } +}; +static struct file_listener_settings *log_unix_listeners[] = { + &log_unix_listeners_array[0] +}; +static buffer_t log_unix_listeners_buf = { + { { log_unix_listeners, sizeof(log_unix_listeners) } } +}; +/* </settings checks> */ + +struct service_settings log_service_settings = { + .name = "log", + .protocol = "", + .type = "log", + .executable = "log", + .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 = { { &log_unix_listeners_buf, + sizeof(log_unix_listeners[0]) } }, + .fifo_listeners = ARRAY_INIT, + .inet_listeners = ARRAY_INIT, + + .process_limit_1 = TRUE +}; + diff --git a/src/log/main.c b/src/log/main.c new file mode 100644 index 0000000..a6ac950 --- /dev/null +++ b/src/log/main.c @@ -0,0 +1,97 @@ +/* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "lib-signals.h" +#include "hostpid.h" +#include "restrict-access.h" +#include "master-interface.h" +#include "master-service-private.h" +#include "master-service-settings.h" +#include "log-error-buffer.h" +#include "log-connection.h" +#include "doveadm-connection.h" + +#include <unistd.h> + +bool verbose_proctitle; +char *global_log_prefix; +static struct log_error_buffer *errorbuf; + +static void +sig_reopen_logs(const siginfo_t *si ATTR_UNUSED, void *context ATTR_UNUSED) +{ + master_service->log_initialized = FALSE; + master_service_init_log_with_prefix(master_service, global_log_prefix); +} + +static void main_init(void) +{ + lib_signals_set_handler(SIGUSR1, LIBSIG_FLAGS_SAFE, + sig_reopen_logs, NULL); + + errorbuf = log_error_buffer_init(); + log_connections_init(); +} + +static void main_deinit(void) +{ + log_connections_deinit(); + log_error_buffer_deinit(&errorbuf); + i_free(global_log_prefix); +} + +static void client_connected(struct master_service_connection *conn) +{ + if (conn->fifo) { + log_connection_create(errorbuf, conn->fd, conn->listen_fd); + /* kludge: normally FIFOs aren't counted as connections, + but here we want log process to stay open until all writers + have closed */ + conn->fifo = FALSE; + } else if (strcmp(conn->name, "log-errors") == 0) + doveadm_connection_create(errorbuf, conn->fd); + else { + i_error("Unknown listener name: %s", conn->name); + return; + } + + master_service_client_connection_accept(conn); +} + +int main(int argc, char *argv[]) +{ + const enum master_service_flags service_flags = + MASTER_SERVICE_FLAG_DONT_SEND_STATS; + const char *error; + + master_service = master_service_init("log", service_flags, + &argc, &argv, ""); + + /* use log prefix and log to stderr until we've configured the real + logging */ + global_log_prefix = i_strdup_printf("log(%s): ", my_pid); + i_set_failure_file("/dev/stderr", global_log_prefix); + + if (master_getopt(master_service) > 0) + return FATAL_DEFAULT; + + if (master_service_settings_read_simple(master_service, + NULL, &error) < 0) + i_fatal("Error reading configuration: %s", error); + master_service_init_log_with_prefix(master_service, global_log_prefix); + + verbose_proctitle = master_service_settings_get(master_service)->verbose_proctitle; + + restrict_access_by_env(RESTRICT_ACCESS_FLAG_ALLOW_ROOT, NULL); + restrict_access_allow_coredumps(TRUE); + + /* logging should never die if there are some clients */ + master_service_set_die_with_master(master_service, FALSE); + + main_init(); + master_service_init_finish(master_service); + master_service_run(master_service, client_connected); + main_deinit(); + master_service_deinit(&master_service); + return 0; +} |