summaryrefslogtreecommitdiffstats
path: root/src/imap-urlauth
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
commitf7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch)
treea3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/imap-urlauth
parentInitial commit. (diff)
downloaddovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz
dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/imap-urlauth/Makefile.am85
-rw-r--r--src/imap-urlauth/Makefile.in1014
-rw-r--r--src/imap-urlauth/imap-urlauth-client.c380
-rw-r--r--src/imap-urlauth/imap-urlauth-client.h49
-rw-r--r--src/imap-urlauth/imap-urlauth-common.h13
-rw-r--r--src/imap-urlauth/imap-urlauth-login-settings.c75
-rw-r--r--src/imap-urlauth/imap-urlauth-login-settings.h6
-rw-r--r--src/imap-urlauth/imap-urlauth-login.c199
-rw-r--r--src/imap-urlauth/imap-urlauth-settings.c94
-rw-r--r--src/imap-urlauth/imap-urlauth-settings.h24
-rw-r--r--src/imap-urlauth/imap-urlauth-worker-settings.c88
-rw-r--r--src/imap-urlauth/imap-urlauth-worker-settings.h18
-rw-r--r--src/imap-urlauth/imap-urlauth-worker.c1033
-rw-r--r--src/imap-urlauth/imap-urlauth.c288
14 files changed, 3366 insertions, 0 deletions
diff --git a/src/imap-urlauth/Makefile.am b/src/imap-urlauth/Makefile.am
new file mode 100644
index 0000000..c9a37e6
--- /dev/null
+++ b/src/imap-urlauth/Makefile.am
@@ -0,0 +1,85 @@
+pkglibexecdir = $(libexecdir)/dovecot
+
+# Refer to comment in imap-urlauth.c for info on what these binaries are for.
+pkglibexec_PROGRAMS = imap-urlauth-login imap-urlauth imap-urlauth-worker
+
+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 \
+ $(BINARY_CFLAGS)
+
+# imap-urlauth-login
+
+imap_urlauth_login_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ -I$(top_srcdir)/src/login-common
+
+imap_urlauth_login_LDADD = \
+ $(LIBDOVECOT_LOGIN) \
+ $(LIBDOVECOT) \
+ $(SSL_LIBS) \
+ $(BINARY_LDFLAGS)
+
+imap_urlauth_login_DEPENDENCIES = \
+ $(LIBDOVECOT_LOGIN_DEPS) \
+ $(LIBDOVECOT_DEPS)
+
+imap_urlauth_login_SOURCES = \
+ imap-urlauth-login.c \
+ imap-urlauth-login-settings.c
+
+# imap-urlauth
+
+imap_urlauth_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ -I$(top_srcdir)/src/lib-dict \
+ -DPKG_RUNDIR=\""$(rundir)"\"
+
+imap_urlauth_LDFLAGS = -export-dynamic
+
+imap_urlauth_LDADD = $(LIBDOVECOT) \
+ $(BINARY_LDFLAGS)
+
+imap_urlauth_DEPENDENCIES = $(LIBDOVECOT_DEPS)
+
+imap_urlauth_SOURCES = \
+ imap-urlauth.c \
+ imap-urlauth-client.c \
+ imap-urlauth-settings.c
+
+# imap-urlauth-worker
+
+imap_urlauth_worker_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ -I$(top_srcdir)/src/lib-dict \
+ -I$(top_srcdir)/src/imap \
+ -I$(top_srcdir)/src/lib-imap \
+ -I$(top_srcdir)/src/lib-imap-storage \
+ -I$(top_srcdir)/src/lib-imap-urlauth \
+ -I$(top_srcdir)/src/lib-mail \
+ -I$(top_srcdir)/src/lib-index \
+ -I$(top_srcdir)/src/lib-storage \
+ -I$(top_srcdir)/src/login-common
+
+imap_urlauth_worker_LDFLAGS = -export-dynamic \
+ $(BINARY_LDFLAGS)
+
+urlauth_libs = \
+ $(top_builddir)/src/lib-imap-urlauth/libimap-urlauth.la
+
+imap_urlauth_worker_LDADD = $(urlauth_libs) $(LIBDOVECOT_STORAGE) $(LIBDOVECOT)
+imap_urlauth_worker_DEPENDENCIES = $(urlauth_libs) $(LIBDOVECOT_STORAGE_DEPS) $(LIBDOVECOT_DEPS)
+
+imap_urlauth_worker_SOURCES = \
+ imap-urlauth-worker.c \
+ imap-urlauth-worker-settings.c
+
+noinst_HEADERS = \
+ imap-urlauth-client.h \
+ imap-urlauth-common.h \
+ imap-urlauth-settings.h \
+ imap-urlauth-login-settings.h \
+ imap-urlauth-worker-settings.h
+
diff --git a/src/imap-urlauth/Makefile.in b/src/imap-urlauth/Makefile.in
new file mode 100644
index 0000000..d4dcb4e
--- /dev/null
+++ b/src/imap-urlauth/Makefile.in
@@ -0,0 +1,1014 @@
+# 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 = imap-urlauth-login$(EXEEXT) \
+ imap-urlauth$(EXEEXT) imap-urlauth-worker$(EXEEXT)
+subdir = src/imap-urlauth
+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_imap_urlauth_OBJECTS = imap_urlauth-imap-urlauth.$(OBJEXT) \
+ imap_urlauth-imap-urlauth-client.$(OBJEXT) \
+ imap_urlauth-imap-urlauth-settings.$(OBJEXT)
+imap_urlauth_OBJECTS = $(am_imap_urlauth_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 =
+imap_urlauth_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(imap_urlauth_LDFLAGS) $(LDFLAGS) -o $@
+am_imap_urlauth_login_OBJECTS = \
+ imap_urlauth_login-imap-urlauth-login.$(OBJEXT) \
+ imap_urlauth_login-imap-urlauth-login-settings.$(OBJEXT)
+imap_urlauth_login_OBJECTS = $(am_imap_urlauth_login_OBJECTS)
+am_imap_urlauth_worker_OBJECTS = \
+ imap_urlauth_worker-imap-urlauth-worker.$(OBJEXT) \
+ imap_urlauth_worker-imap-urlauth-worker-settings.$(OBJEXT)
+imap_urlauth_worker_OBJECTS = $(am_imap_urlauth_worker_OBJECTS)
+imap_urlauth_worker_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+ $(AM_CFLAGS) $(CFLAGS) $(imap_urlauth_worker_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)/imap_urlauth-imap-urlauth-client.Po \
+ ./$(DEPDIR)/imap_urlauth-imap-urlauth-settings.Po \
+ ./$(DEPDIR)/imap_urlauth-imap-urlauth.Po \
+ ./$(DEPDIR)/imap_urlauth_login-imap-urlauth-login-settings.Po \
+ ./$(DEPDIR)/imap_urlauth_login-imap-urlauth-login.Po \
+ ./$(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker-settings.Po \
+ ./$(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker.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 = $(imap_urlauth_SOURCES) $(imap_urlauth_login_SOURCES) \
+ $(imap_urlauth_worker_SOURCES)
+DIST_SOURCES = $(imap_urlauth_SOURCES) $(imap_urlauth_login_SOURCES) \
+ $(imap_urlauth_worker_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 \
+ $(BINARY_CFLAGS)
+
+
+# imap-urlauth-login
+imap_urlauth_login_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ -I$(top_srcdir)/src/login-common
+
+imap_urlauth_login_LDADD = \
+ $(LIBDOVECOT_LOGIN) \
+ $(LIBDOVECOT) \
+ $(SSL_LIBS) \
+ $(BINARY_LDFLAGS)
+
+imap_urlauth_login_DEPENDENCIES = \
+ $(LIBDOVECOT_LOGIN_DEPS) \
+ $(LIBDOVECOT_DEPS)
+
+imap_urlauth_login_SOURCES = \
+ imap-urlauth-login.c \
+ imap-urlauth-login-settings.c
+
+
+# imap-urlauth
+imap_urlauth_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ -I$(top_srcdir)/src/lib-dict \
+ -DPKG_RUNDIR=\""$(rundir)"\"
+
+imap_urlauth_LDFLAGS = -export-dynamic
+imap_urlauth_LDADD = $(LIBDOVECOT) \
+ $(BINARY_LDFLAGS)
+
+imap_urlauth_DEPENDENCIES = $(LIBDOVECOT_DEPS)
+imap_urlauth_SOURCES = \
+ imap-urlauth.c \
+ imap-urlauth-client.c \
+ imap-urlauth-settings.c
+
+
+# imap-urlauth-worker
+imap_urlauth_worker_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ -I$(top_srcdir)/src/lib-dict \
+ -I$(top_srcdir)/src/imap \
+ -I$(top_srcdir)/src/lib-imap \
+ -I$(top_srcdir)/src/lib-imap-storage \
+ -I$(top_srcdir)/src/lib-imap-urlauth \
+ -I$(top_srcdir)/src/lib-mail \
+ -I$(top_srcdir)/src/lib-index \
+ -I$(top_srcdir)/src/lib-storage \
+ -I$(top_srcdir)/src/login-common
+
+imap_urlauth_worker_LDFLAGS = -export-dynamic \
+ $(BINARY_LDFLAGS)
+
+urlauth_libs = \
+ $(top_builddir)/src/lib-imap-urlauth/libimap-urlauth.la
+
+imap_urlauth_worker_LDADD = $(urlauth_libs) $(LIBDOVECOT_STORAGE) $(LIBDOVECOT)
+imap_urlauth_worker_DEPENDENCIES = $(urlauth_libs) $(LIBDOVECOT_STORAGE_DEPS) $(LIBDOVECOT_DEPS)
+imap_urlauth_worker_SOURCES = \
+ imap-urlauth-worker.c \
+ imap-urlauth-worker-settings.c
+
+noinst_HEADERS = \
+ imap-urlauth-client.h \
+ imap-urlauth-common.h \
+ imap-urlauth-settings.h \
+ imap-urlauth-login-settings.h \
+ imap-urlauth-worker-settings.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/imap-urlauth/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign src/imap-urlauth/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
+
+imap-urlauth$(EXEEXT): $(imap_urlauth_OBJECTS) $(imap_urlauth_DEPENDENCIES) $(EXTRA_imap_urlauth_DEPENDENCIES)
+ @rm -f imap-urlauth$(EXEEXT)
+ $(AM_V_CCLD)$(imap_urlauth_LINK) $(imap_urlauth_OBJECTS) $(imap_urlauth_LDADD) $(LIBS)
+
+imap-urlauth-login$(EXEEXT): $(imap_urlauth_login_OBJECTS) $(imap_urlauth_login_DEPENDENCIES) $(EXTRA_imap_urlauth_login_DEPENDENCIES)
+ @rm -f imap-urlauth-login$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(imap_urlauth_login_OBJECTS) $(imap_urlauth_login_LDADD) $(LIBS)
+
+imap-urlauth-worker$(EXEEXT): $(imap_urlauth_worker_OBJECTS) $(imap_urlauth_worker_DEPENDENCIES) $(EXTRA_imap_urlauth_worker_DEPENDENCIES)
+ @rm -f imap-urlauth-worker$(EXEEXT)
+ $(AM_V_CCLD)$(imap_urlauth_worker_LINK) $(imap_urlauth_worker_OBJECTS) $(imap_urlauth_worker_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imap_urlauth-imap-urlauth-client.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imap_urlauth-imap-urlauth-settings.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imap_urlauth-imap-urlauth.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imap_urlauth_login-imap-urlauth-login-settings.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imap_urlauth_login-imap-urlauth-login.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker-settings.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker.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 $@ $<
+
+imap_urlauth-imap-urlauth.o: imap-urlauth.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT imap_urlauth-imap-urlauth.o -MD -MP -MF $(DEPDIR)/imap_urlauth-imap-urlauth.Tpo -c -o imap_urlauth-imap-urlauth.o `test -f 'imap-urlauth.c' || echo '$(srcdir)/'`imap-urlauth.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/imap_urlauth-imap-urlauth.Tpo $(DEPDIR)/imap_urlauth-imap-urlauth.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='imap-urlauth.c' object='imap_urlauth-imap-urlauth.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o imap_urlauth-imap-urlauth.o `test -f 'imap-urlauth.c' || echo '$(srcdir)/'`imap-urlauth.c
+
+imap_urlauth-imap-urlauth.obj: imap-urlauth.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT imap_urlauth-imap-urlauth.obj -MD -MP -MF $(DEPDIR)/imap_urlauth-imap-urlauth.Tpo -c -o imap_urlauth-imap-urlauth.obj `if test -f 'imap-urlauth.c'; then $(CYGPATH_W) 'imap-urlauth.c'; else $(CYGPATH_W) '$(srcdir)/imap-urlauth.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/imap_urlauth-imap-urlauth.Tpo $(DEPDIR)/imap_urlauth-imap-urlauth.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='imap-urlauth.c' object='imap_urlauth-imap-urlauth.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o imap_urlauth-imap-urlauth.obj `if test -f 'imap-urlauth.c'; then $(CYGPATH_W) 'imap-urlauth.c'; else $(CYGPATH_W) '$(srcdir)/imap-urlauth.c'; fi`
+
+imap_urlauth-imap-urlauth-client.o: imap-urlauth-client.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT imap_urlauth-imap-urlauth-client.o -MD -MP -MF $(DEPDIR)/imap_urlauth-imap-urlauth-client.Tpo -c -o imap_urlauth-imap-urlauth-client.o `test -f 'imap-urlauth-client.c' || echo '$(srcdir)/'`imap-urlauth-client.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/imap_urlauth-imap-urlauth-client.Tpo $(DEPDIR)/imap_urlauth-imap-urlauth-client.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='imap-urlauth-client.c' object='imap_urlauth-imap-urlauth-client.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o imap_urlauth-imap-urlauth-client.o `test -f 'imap-urlauth-client.c' || echo '$(srcdir)/'`imap-urlauth-client.c
+
+imap_urlauth-imap-urlauth-client.obj: imap-urlauth-client.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT imap_urlauth-imap-urlauth-client.obj -MD -MP -MF $(DEPDIR)/imap_urlauth-imap-urlauth-client.Tpo -c -o imap_urlauth-imap-urlauth-client.obj `if test -f 'imap-urlauth-client.c'; then $(CYGPATH_W) 'imap-urlauth-client.c'; else $(CYGPATH_W) '$(srcdir)/imap-urlauth-client.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/imap_urlauth-imap-urlauth-client.Tpo $(DEPDIR)/imap_urlauth-imap-urlauth-client.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='imap-urlauth-client.c' object='imap_urlauth-imap-urlauth-client.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o imap_urlauth-imap-urlauth-client.obj `if test -f 'imap-urlauth-client.c'; then $(CYGPATH_W) 'imap-urlauth-client.c'; else $(CYGPATH_W) '$(srcdir)/imap-urlauth-client.c'; fi`
+
+imap_urlauth-imap-urlauth-settings.o: imap-urlauth-settings.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT imap_urlauth-imap-urlauth-settings.o -MD -MP -MF $(DEPDIR)/imap_urlauth-imap-urlauth-settings.Tpo -c -o imap_urlauth-imap-urlauth-settings.o `test -f 'imap-urlauth-settings.c' || echo '$(srcdir)/'`imap-urlauth-settings.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/imap_urlauth-imap-urlauth-settings.Tpo $(DEPDIR)/imap_urlauth-imap-urlauth-settings.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='imap-urlauth-settings.c' object='imap_urlauth-imap-urlauth-settings.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o imap_urlauth-imap-urlauth-settings.o `test -f 'imap-urlauth-settings.c' || echo '$(srcdir)/'`imap-urlauth-settings.c
+
+imap_urlauth-imap-urlauth-settings.obj: imap-urlauth-settings.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT imap_urlauth-imap-urlauth-settings.obj -MD -MP -MF $(DEPDIR)/imap_urlauth-imap-urlauth-settings.Tpo -c -o imap_urlauth-imap-urlauth-settings.obj `if test -f 'imap-urlauth-settings.c'; then $(CYGPATH_W) 'imap-urlauth-settings.c'; else $(CYGPATH_W) '$(srcdir)/imap-urlauth-settings.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/imap_urlauth-imap-urlauth-settings.Tpo $(DEPDIR)/imap_urlauth-imap-urlauth-settings.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='imap-urlauth-settings.c' object='imap_urlauth-imap-urlauth-settings.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o imap_urlauth-imap-urlauth-settings.obj `if test -f 'imap-urlauth-settings.c'; then $(CYGPATH_W) 'imap-urlauth-settings.c'; else $(CYGPATH_W) '$(srcdir)/imap-urlauth-settings.c'; fi`
+
+imap_urlauth_login-imap-urlauth-login.o: imap-urlauth-login.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_login_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT imap_urlauth_login-imap-urlauth-login.o -MD -MP -MF $(DEPDIR)/imap_urlauth_login-imap-urlauth-login.Tpo -c -o imap_urlauth_login-imap-urlauth-login.o `test -f 'imap-urlauth-login.c' || echo '$(srcdir)/'`imap-urlauth-login.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/imap_urlauth_login-imap-urlauth-login.Tpo $(DEPDIR)/imap_urlauth_login-imap-urlauth-login.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='imap-urlauth-login.c' object='imap_urlauth_login-imap-urlauth-login.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_login_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o imap_urlauth_login-imap-urlauth-login.o `test -f 'imap-urlauth-login.c' || echo '$(srcdir)/'`imap-urlauth-login.c
+
+imap_urlauth_login-imap-urlauth-login.obj: imap-urlauth-login.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_login_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT imap_urlauth_login-imap-urlauth-login.obj -MD -MP -MF $(DEPDIR)/imap_urlauth_login-imap-urlauth-login.Tpo -c -o imap_urlauth_login-imap-urlauth-login.obj `if test -f 'imap-urlauth-login.c'; then $(CYGPATH_W) 'imap-urlauth-login.c'; else $(CYGPATH_W) '$(srcdir)/imap-urlauth-login.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/imap_urlauth_login-imap-urlauth-login.Tpo $(DEPDIR)/imap_urlauth_login-imap-urlauth-login.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='imap-urlauth-login.c' object='imap_urlauth_login-imap-urlauth-login.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_login_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o imap_urlauth_login-imap-urlauth-login.obj `if test -f 'imap-urlauth-login.c'; then $(CYGPATH_W) 'imap-urlauth-login.c'; else $(CYGPATH_W) '$(srcdir)/imap-urlauth-login.c'; fi`
+
+imap_urlauth_login-imap-urlauth-login-settings.o: imap-urlauth-login-settings.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_login_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT imap_urlauth_login-imap-urlauth-login-settings.o -MD -MP -MF $(DEPDIR)/imap_urlauth_login-imap-urlauth-login-settings.Tpo -c -o imap_urlauth_login-imap-urlauth-login-settings.o `test -f 'imap-urlauth-login-settings.c' || echo '$(srcdir)/'`imap-urlauth-login-settings.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/imap_urlauth_login-imap-urlauth-login-settings.Tpo $(DEPDIR)/imap_urlauth_login-imap-urlauth-login-settings.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='imap-urlauth-login-settings.c' object='imap_urlauth_login-imap-urlauth-login-settings.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_login_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o imap_urlauth_login-imap-urlauth-login-settings.o `test -f 'imap-urlauth-login-settings.c' || echo '$(srcdir)/'`imap-urlauth-login-settings.c
+
+imap_urlauth_login-imap-urlauth-login-settings.obj: imap-urlauth-login-settings.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_login_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT imap_urlauth_login-imap-urlauth-login-settings.obj -MD -MP -MF $(DEPDIR)/imap_urlauth_login-imap-urlauth-login-settings.Tpo -c -o imap_urlauth_login-imap-urlauth-login-settings.obj `if test -f 'imap-urlauth-login-settings.c'; then $(CYGPATH_W) 'imap-urlauth-login-settings.c'; else $(CYGPATH_W) '$(srcdir)/imap-urlauth-login-settings.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/imap_urlauth_login-imap-urlauth-login-settings.Tpo $(DEPDIR)/imap_urlauth_login-imap-urlauth-login-settings.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='imap-urlauth-login-settings.c' object='imap_urlauth_login-imap-urlauth-login-settings.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_login_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o imap_urlauth_login-imap-urlauth-login-settings.obj `if test -f 'imap-urlauth-login-settings.c'; then $(CYGPATH_W) 'imap-urlauth-login-settings.c'; else $(CYGPATH_W) '$(srcdir)/imap-urlauth-login-settings.c'; fi`
+
+imap_urlauth_worker-imap-urlauth-worker.o: imap-urlauth-worker.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_worker_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT imap_urlauth_worker-imap-urlauth-worker.o -MD -MP -MF $(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker.Tpo -c -o imap_urlauth_worker-imap-urlauth-worker.o `test -f 'imap-urlauth-worker.c' || echo '$(srcdir)/'`imap-urlauth-worker.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker.Tpo $(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='imap-urlauth-worker.c' object='imap_urlauth_worker-imap-urlauth-worker.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_worker_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o imap_urlauth_worker-imap-urlauth-worker.o `test -f 'imap-urlauth-worker.c' || echo '$(srcdir)/'`imap-urlauth-worker.c
+
+imap_urlauth_worker-imap-urlauth-worker.obj: imap-urlauth-worker.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_worker_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT imap_urlauth_worker-imap-urlauth-worker.obj -MD -MP -MF $(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker.Tpo -c -o imap_urlauth_worker-imap-urlauth-worker.obj `if test -f 'imap-urlauth-worker.c'; then $(CYGPATH_W) 'imap-urlauth-worker.c'; else $(CYGPATH_W) '$(srcdir)/imap-urlauth-worker.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker.Tpo $(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='imap-urlauth-worker.c' object='imap_urlauth_worker-imap-urlauth-worker.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_worker_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o imap_urlauth_worker-imap-urlauth-worker.obj `if test -f 'imap-urlauth-worker.c'; then $(CYGPATH_W) 'imap-urlauth-worker.c'; else $(CYGPATH_W) '$(srcdir)/imap-urlauth-worker.c'; fi`
+
+imap_urlauth_worker-imap-urlauth-worker-settings.o: imap-urlauth-worker-settings.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_worker_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT imap_urlauth_worker-imap-urlauth-worker-settings.o -MD -MP -MF $(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker-settings.Tpo -c -o imap_urlauth_worker-imap-urlauth-worker-settings.o `test -f 'imap-urlauth-worker-settings.c' || echo '$(srcdir)/'`imap-urlauth-worker-settings.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker-settings.Tpo $(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker-settings.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='imap-urlauth-worker-settings.c' object='imap_urlauth_worker-imap-urlauth-worker-settings.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_worker_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o imap_urlauth_worker-imap-urlauth-worker-settings.o `test -f 'imap-urlauth-worker-settings.c' || echo '$(srcdir)/'`imap-urlauth-worker-settings.c
+
+imap_urlauth_worker-imap-urlauth-worker-settings.obj: imap-urlauth-worker-settings.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_worker_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT imap_urlauth_worker-imap-urlauth-worker-settings.obj -MD -MP -MF $(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker-settings.Tpo -c -o imap_urlauth_worker-imap-urlauth-worker-settings.obj `if test -f 'imap-urlauth-worker-settings.c'; then $(CYGPATH_W) 'imap-urlauth-worker-settings.c'; else $(CYGPATH_W) '$(srcdir)/imap-urlauth-worker-settings.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker-settings.Tpo $(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker-settings.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='imap-urlauth-worker-settings.c' object='imap_urlauth_worker-imap-urlauth-worker-settings.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(imap_urlauth_worker_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o imap_urlauth_worker-imap-urlauth-worker-settings.obj `if test -f 'imap-urlauth-worker-settings.c'; then $(CYGPATH_W) 'imap-urlauth-worker-settings.c'; else $(CYGPATH_W) '$(srcdir)/imap-urlauth-worker-settings.c'; fi`
+
+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)/imap_urlauth-imap-urlauth-client.Po
+ -rm -f ./$(DEPDIR)/imap_urlauth-imap-urlauth-settings.Po
+ -rm -f ./$(DEPDIR)/imap_urlauth-imap-urlauth.Po
+ -rm -f ./$(DEPDIR)/imap_urlauth_login-imap-urlauth-login-settings.Po
+ -rm -f ./$(DEPDIR)/imap_urlauth_login-imap-urlauth-login.Po
+ -rm -f ./$(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker-settings.Po
+ -rm -f ./$(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker.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)/imap_urlauth-imap-urlauth-client.Po
+ -rm -f ./$(DEPDIR)/imap_urlauth-imap-urlauth-settings.Po
+ -rm -f ./$(DEPDIR)/imap_urlauth-imap-urlauth.Po
+ -rm -f ./$(DEPDIR)/imap_urlauth_login-imap-urlauth-login-settings.Po
+ -rm -f ./$(DEPDIR)/imap_urlauth_login-imap-urlauth-login.Po
+ -rm -f ./$(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker-settings.Po
+ -rm -f ./$(DEPDIR)/imap_urlauth_worker-imap-urlauth-worker.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/imap-urlauth/imap-urlauth-client.c b/src/imap-urlauth/imap-urlauth-client.c
new file mode 100644
index 0000000..73f5b18
--- /dev/null
+++ b/src/imap-urlauth/imap-urlauth-client.c
@@ -0,0 +1,380 @@
+/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
+
+#include "imap-urlauth-common.h"
+#include "array.h"
+#include "ioloop.h"
+#include "net.h"
+#include "fdpass.h"
+#include "istream.h"
+#include "ostream.h"
+#include "str.h"
+#include "strescape.h"
+#include "eacces-error.h"
+#include "llist.h"
+#include "hostpid.h"
+#include "execv-const.h"
+#include "env-util.h"
+#include "var-expand.h"
+#include "restrict-access.h"
+#include "master-service.h"
+#include "master-interface.h"
+
+#include <unistd.h>
+#include <sys/wait.h>
+
+#define IMAP_URLAUTH_PROTOCOL_MAJOR_VERSION 1
+#define IMAP_URLAUTH_PROTOCOL_MINOR_VERSION 0
+
+#define IMAP_URLAUTH_WORKER_SOCKET "imap-urlauth-worker"
+
+/* max. length of input lines (URLs) */
+#define MAX_INBUF_SIZE 2048
+
+/* Disconnect client after idling this many milliseconds */
+#define CLIENT_IDLE_TIMEOUT_MSECS (10*60*1000)
+
+#define USER_EXECUTABLE "imap-urlauth-worker"
+
+#define IS_STANDALONE() \
+ (getenv(MASTER_IS_PARENT_ENV) == NULL)
+
+static struct event_category event_category_urlauth = {
+ .name = "imap-urlauth",
+};
+
+struct client *imap_urlauth_clients;
+unsigned int imap_urlauth_client_count;
+
+static int client_worker_connect(struct client *client);
+static void client_worker_disconnect(struct client *client);
+static void client_worker_input(struct client *client);
+
+int client_create(const char *service, const char *username,
+ int fd_in, int fd_out, const struct imap_urlauth_settings *set,
+ struct client **client_r)
+{
+ struct client *client;
+ const char *app;
+
+ /* always use nonblocking I/O */
+ net_set_nonblock(fd_in, TRUE);
+ net_set_nonblock(fd_out, TRUE);
+
+ client = i_new(struct client, 1);
+ client->fd_in = fd_in;
+ client->fd_out = fd_out;
+ client->fd_ctrl = -1;
+ client->set = set;
+
+ client->event = event_create(NULL);
+ event_set_forced_debug(client->event, set->mail_debug);
+ event_add_category(client->event, &event_category_urlauth);
+ event_set_append_log_prefix(client->event, t_strdup_printf(
+ "user %s: ", username));
+
+ if (client_worker_connect(client) < 0) {
+ event_unref(&client->event);
+ i_free(client);
+ return -1;
+ }
+
+ /* determine user's special privileges */
+ i_array_init(&client->access_apps, 4);
+ if (username != NULL) {
+ if (set->imap_urlauth_submit_user != NULL &&
+ strcmp(set->imap_urlauth_submit_user, username) == 0) {
+ e_debug(client->event, "User has URLAUTH submit access");
+ app = "submit+";
+ array_push_back(&client->access_apps, &app);
+ }
+ if (set->imap_urlauth_stream_user != NULL &&
+ strcmp(set->imap_urlauth_stream_user, username) == 0) {
+ e_debug(client->event, "User has URLAUTH stream access");
+ app = "stream";
+ array_push_back(&client->access_apps, &app);
+ }
+ }
+
+ client->username = i_strdup(username);
+ client->service = i_strdup(service);
+
+ client->output = o_stream_create_fd(fd_out, SIZE_MAX);
+
+ imap_urlauth_client_count++;
+ DLLIST_PREPEND(&imap_urlauth_clients, client);
+
+ imap_urlauth_refresh_proctitle();
+ *client_r = client;
+ return 0;
+}
+
+void client_send_line(struct client *client, const char *fmt, ...)
+{
+ va_list va;
+ ssize_t ret;
+
+ if (client->output->closed)
+ return;
+
+ va_start(va, fmt);
+
+ T_BEGIN {
+ string_t *str;
+
+ str = t_str_new(256);
+ str_vprintfa(str, fmt, va);
+ str_append(str, "\n");
+
+ ret = o_stream_send(client->output,
+ str_data(str), str_len(str));
+ i_assert(ret < 0 || (size_t)ret == str_len(str));
+ } T_END;
+
+ va_end(va);
+}
+
+static int client_worker_connect(struct client *client)
+{
+ static const char handshake[] = "VERSION\timap-urlauth-worker\t2\t0\n";
+ const char *socket_path;
+ ssize_t ret;
+ unsigned char data;
+
+ socket_path = t_strconcat(client->set->base_dir,
+ "/"IMAP_URLAUTH_WORKER_SOCKET, NULL);
+
+ e_debug(client->event, "Connecting to worker socket %s", socket_path);
+
+ client->fd_ctrl = net_connect_unix_with_retries(socket_path, 1000);
+ if (client->fd_ctrl < 0) {
+ if (errno == EACCES) {
+ e_error(client->event, "imap-urlauth-client: %s",
+ eacces_error_get("net_connect_unix",
+ socket_path));
+ } else {
+ e_error(client->event, "imap-urlauth-client: "
+ "net_connect_unix(%s) failed: %m",
+ socket_path);
+ }
+ return -1;
+ }
+
+ /* transfer one or two fds */
+ data = (client->fd_in == client->fd_out ? '0' : '1');
+ ret = fd_send(client->fd_ctrl, client->fd_in, &data, sizeof(data));
+ if (ret > 0 && client->fd_in != client->fd_out) {
+ data = '0';
+ ret = fd_send(client->fd_ctrl, client->fd_out,
+ &data, sizeof(data));
+ }
+
+ if (ret <= 0) {
+ if (ret < 0) {
+ e_error(client->event, "fd_send(%s, %d) failed: %m",
+ socket_path, client->fd_ctrl);
+ } else {
+ e_error(client->event, "fd_send(%s, %d) failed to send byte",
+ socket_path, client->fd_ctrl);
+ }
+ client_worker_disconnect(client);
+ return -1;
+ }
+
+ client->ctrl_output = o_stream_create_fd(client->fd_ctrl, SIZE_MAX);
+
+ /* send protocol version handshake */
+ if (o_stream_send_str(client->ctrl_output, handshake) < 0) {
+ e_error(client->event,
+ "Error sending handshake to imap-urlauth worker: %m");
+ client_worker_disconnect(client);
+ return -1;
+ }
+
+ client->ctrl_input =
+ i_stream_create_fd(client->fd_ctrl, MAX_INBUF_SIZE);
+ client->ctrl_io =
+ io_add(client->fd_ctrl, IO_READ, client_worker_input, client);
+ return 0;
+}
+
+void client_worker_disconnect(struct client *client)
+{
+ client->worker_state = IMAP_URLAUTH_WORKER_STATE_INACTIVE;
+
+ io_remove(&client->ctrl_io);
+ o_stream_destroy(&client->ctrl_output);
+ i_stream_destroy(&client->ctrl_input);
+ if (client->fd_ctrl >= 0) {
+ net_disconnect(client->fd_ctrl);
+ client->fd_ctrl = -1;
+ }
+}
+
+static int
+client_worker_input_line(struct client *client, const char *response)
+{
+ const char *const *apps;
+ unsigned int count, i;
+ bool restart;
+ string_t *str;
+ int ret;
+
+ switch (client->worker_state) {
+ case IMAP_URLAUTH_WORKER_STATE_INACTIVE:
+ if (strcasecmp(response, "OK") != 0) {
+ client_disconnect(client, "Worker handshake failed");
+ return -1;
+ }
+ client->worker_state = IMAP_URLAUTH_WORKER_STATE_CONNECTED;
+
+ str = t_str_new(256);
+ str_append(str, "ACCESS\t");
+ if (client->username != NULL)
+ str_append_tabescaped(str, client->username);
+ str_append(str, "\t");
+ str_append_tabescaped(str, client->service);
+ if (client->set->mail_debug)
+ str_append(str, "\tdebug");
+ if (array_count(&client->access_apps) > 0) {
+ str_append(str, "\tapps=");
+ apps = array_get(&client->access_apps, &count);
+ str_append(str, apps[0]);
+ for (i = 1; i < count; i++) {
+ str_append_c(str, ',');
+ str_append_tabescaped(str, apps[i]);
+ }
+ }
+ str_append(str, "\n");
+
+ ret = o_stream_send(client->ctrl_output,
+ str_data(str), str_len(str));
+ i_assert(ret < 0 || (size_t)ret == str_len(str));
+ if (ret < 0) {
+ client_disconnect(client,
+ "Failed to send ACCESS control command to worker");
+ return -1;
+ }
+ break;
+
+ case IMAP_URLAUTH_WORKER_STATE_CONNECTED:
+ if (strcasecmp(response, "OK") != 0) {
+ client_disconnect(client,
+ "Failed to negotiate access parameters");
+ return -1;
+ }
+ client->worker_state = IMAP_URLAUTH_WORKER_STATE_ACTIVE;
+ break;
+
+ case IMAP_URLAUTH_WORKER_STATE_ACTIVE:
+ restart = TRUE;
+ if (strcasecmp(response, "DISCONNECTED") == 0) {
+ /* worker detected client disconnect */
+ restart = FALSE;
+ } else if (strcasecmp(response, "FINISHED") != 0) {
+ /* unknown response */
+ client_disconnect(client,
+ "Worker finished with unknown response");
+ return -1;
+ }
+
+ e_debug(client->event, "Worker finished successfully");
+
+ if (restart) {
+ /* connect to new worker for accessing different user */
+ client_worker_disconnect(client);
+ if (client_worker_connect(client) < 0) {
+ client_disconnect(client,
+ "Failed to connect to new worker");
+ return -1;
+ }
+
+ /* indicate success of "END" command */
+ client_send_line(client, "OK");
+ } else {
+ client_disconnect(client, "Client disconnected");
+ }
+ return -1;
+ default:
+ i_unreached();
+ }
+ return 0;
+}
+
+void client_worker_input(struct client *client)
+{
+ struct istream *input = client->ctrl_input;
+ const char *line;
+
+ if (input->closed) {
+ /* disconnected */
+ client_disconnect(client, "Worker disconnected unexpectedly");
+ return;
+ }
+
+ switch (i_stream_read(input)) {
+ case -1:
+ /* disconnected */
+ client_disconnect(client, "Worker disconnected unexpectedly");
+ return;
+ case -2:
+ /* input buffer full */
+ client_disconnect(client, "Worker sent too large input");
+ return;
+ }
+
+ while ((line = i_stream_next_line(input)) != NULL) {
+ if (client_worker_input_line(client, line) < 0)
+ return;
+ }
+}
+
+void client_destroy(struct client *client, const char *reason)
+{
+ i_assert(reason != NULL || client->disconnected);
+
+ if (!client->disconnected)
+ e_info(client->event, "Disconnected: %s", reason);
+
+ imap_urlauth_client_count--;
+ DLLIST_REMOVE(&imap_urlauth_clients, client);
+
+ timeout_remove(&client->to_idle);
+
+ client_worker_disconnect(client);
+
+ o_stream_destroy(&client->output);
+
+ fd_close_maybe_stdio(&client->fd_in, &client->fd_out);
+
+ event_unref(&client->event);
+
+ i_free(client->username);
+ i_free(client->service);
+ array_free(&client->access_apps);
+ i_free(client);
+
+ master_service_client_connection_destroyed(master_service);
+ imap_urlauth_refresh_proctitle();
+}
+
+static void client_destroy_timeout(struct client *client)
+{
+ client_destroy(client, NULL);
+}
+
+void client_disconnect(struct client *client, const char *reason)
+{
+ if (client->disconnected)
+ return;
+
+ client->disconnected = TRUE;
+ e_info(client->event, "Disconnected: %s", reason);
+
+ client->to_idle = timeout_add(0, client_destroy_timeout, client);
+}
+
+void clients_destroy_all(void)
+{
+ while (imap_urlauth_clients != NULL)
+ client_destroy(imap_urlauth_clients, "Server shutting down.");
+}
diff --git a/src/imap-urlauth/imap-urlauth-client.h b/src/imap-urlauth/imap-urlauth-client.h
new file mode 100644
index 0000000..ada8407
--- /dev/null
+++ b/src/imap-urlauth/imap-urlauth-client.h
@@ -0,0 +1,49 @@
+#ifndef IMAP_URLAUTH_CLIENT_H
+#define IMAP_URLAUTH_CLIENT_H
+
+struct client;
+struct mail_storage;
+
+enum imap_urlauth_worker_state {
+ IMAP_URLAUTH_WORKER_STATE_INACTIVE = 0,
+ IMAP_URLAUTH_WORKER_STATE_CONNECTED,
+ IMAP_URLAUTH_WORKER_STATE_ACTIVE,
+};
+
+struct client {
+ struct client *prev, *next;
+
+ int fd_in, fd_out, fd_ctrl;
+ struct io *ctrl_io;
+ struct ostream *output, *ctrl_output;
+ struct istream *ctrl_input;
+ struct timeout *to_idle;
+ struct event *event;
+
+ char *username, *service;
+ ARRAY_TYPE(const_string) access_apps;
+
+ /* settings: */
+ const struct imap_urlauth_settings *set;
+
+ enum imap_urlauth_worker_state worker_state;
+
+ bool disconnected:1;
+};
+
+extern struct client *imap_urlauth_clients;
+extern unsigned int imap_urlauth_client_count;
+
+int client_create(const char *service, const char *username,
+ int fd_in, int fd_out, const struct imap_urlauth_settings *set,
+ struct client **client_r);
+void client_destroy(struct client *client, const char *reason);
+
+void client_send_line(struct client *client, const char *fmt, ...)
+ ATTR_FORMAT(2, 3);
+
+void client_disconnect(struct client *client, const char *reason);
+
+void clients_destroy_all(void);
+
+#endif
diff --git a/src/imap-urlauth/imap-urlauth-common.h b/src/imap-urlauth/imap-urlauth-common.h
new file mode 100644
index 0000000..ac6d06f
--- /dev/null
+++ b/src/imap-urlauth/imap-urlauth-common.h
@@ -0,0 +1,13 @@
+#ifndef IMAP_URLAUTH_COMMON_H
+#define IMAP_URLAUTH_COMMON_H
+
+#include "lib.h"
+#include "imap-urlauth-client.h"
+#include "imap-urlauth-settings.h"
+
+extern bool verbose_proctitle;
+extern struct mail_storage_service_ctx *storage_service;
+
+void imap_urlauth_refresh_proctitle(void);
+
+#endif
diff --git a/src/imap-urlauth/imap-urlauth-login-settings.c b/src/imap-urlauth/imap-urlauth-login-settings.c
new file mode 100644
index 0000000..3dc41f6
--- /dev/null
+++ b/src/imap-urlauth/imap-urlauth-login-settings.c
@@ -0,0 +1,75 @@
+/* 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 "login-settings.h"
+#include "imap-urlauth-login-settings.h"
+
+#include <stddef.h>
+
+/* <settings checks> */
+static struct file_listener_settings
+imap_urlauth_login_unix_listeners_array[] = {
+ { "imap-urlauth", 0666, "", "" }
+};
+static struct file_listener_settings *imap_urlauth_login_unix_listeners[] = {
+ &imap_urlauth_login_unix_listeners_array[0]
+};
+static buffer_t imap_urlauth_login_unix_listeners_buf = {
+ { { imap_urlauth_login_unix_listeners,
+ sizeof(imap_urlauth_login_unix_listeners) } }
+};
+/* </settings checks> */
+
+struct service_settings imap_urlauth_login_service_settings = {
+ .name = "imap-urlauth-login",
+ .protocol = "imap",
+ .type = "login",
+ .executable = "imap-urlauth-login",
+ .user = "$default_login_user",
+ .group = "",
+ .privileged_group = "",
+ .extra_groups = "",
+ .chroot = "token-login",
+
+ .drop_priv_before_exec = FALSE,
+
+ .process_min_avail = 0,
+ .process_limit = 0,
+ .client_limit = 0,
+ .service_count = 1,
+ .idle_kill = 0,
+ .vsz_limit = UOFF_T_MAX,
+
+ .unix_listeners = { { &imap_urlauth_login_unix_listeners_buf,
+ sizeof(imap_urlauth_login_unix_listeners[0]) } },
+ .fifo_listeners = ARRAY_INIT,
+ .inet_listeners = ARRAY_INIT
+};
+
+static const struct setting_define imap_urlauth_login_setting_defines[] = {
+ SETTING_DEFINE_LIST_END
+};
+
+static const struct setting_parser_info *imap_urlauth_login_setting_dependencies[] = {
+ &login_setting_parser_info,
+ NULL
+};
+
+const struct setting_parser_info imap_urlauth_login_setting_parser_info = {
+ .module_name = "imap-urlauth-login",
+ .defines = imap_urlauth_login_setting_defines,
+
+ .type_offset = SIZE_MAX,
+ .parent_offset = SIZE_MAX,
+
+ .dependencies = imap_urlauth_login_setting_dependencies
+};
+
+const struct setting_parser_info *imap_urlauth_login_setting_roots[] = {
+ &login_setting_parser_info,
+ &imap_urlauth_login_setting_parser_info,
+ NULL
+};
diff --git a/src/imap-urlauth/imap-urlauth-login-settings.h b/src/imap-urlauth/imap-urlauth-login-settings.h
new file mode 100644
index 0000000..775638a
--- /dev/null
+++ b/src/imap-urlauth/imap-urlauth-login-settings.h
@@ -0,0 +1,6 @@
+#ifndef IMAP_URLAUTH_LOGIN_SETTINGS_H
+#define IMAP_URLAUTH_LOGIN_SETTINGS_H
+
+extern const struct setting_parser_info *imap_urlauth_login_setting_roots[];
+
+#endif
diff --git a/src/imap-urlauth/imap-urlauth-login.c b/src/imap-urlauth/imap-urlauth-login.c
new file mode 100644
index 0000000..e917a5b
--- /dev/null
+++ b/src/imap-urlauth/imap-urlauth-login.c
@@ -0,0 +1,199 @@
+/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
+
+#include "login-common.h"
+#include "str.h"
+#include "strescape.h"
+#include "base64.h"
+#include "net.h"
+#include "ioloop.h"
+#include "istream.h"
+#include "ostream.h"
+#include "master-service.h"
+#include "auth-client.h"
+#include "client-common.h"
+#include "imap-urlauth-login-settings.h"
+
+#define IMAP_URLAUTH_PROTOCOL_MAJOR_VERSION 2
+#define IMAP_URLAUTH_PROTOCOL_MINOR_VERSION 0
+
+struct imap_urlauth_client {
+ struct client common;
+
+ const struct imap_urlauth_login_settings *set;
+
+ bool version_received:1;
+};
+
+static void
+imap_urlauth_client_auth_result(struct client *client,
+ enum client_auth_result result,
+ const struct client_auth_reply *reply ATTR_UNUSED,
+ const char *text ATTR_UNUSED)
+{
+ if (result != CLIENT_AUTH_RESULT_SUCCESS) {
+ /* failed or otherwise invalid status */
+ client_send_raw(client, "FAILED\n");
+ client_destroy(client, "Authentication failed");
+ } else {
+ /* authentication succeeded */
+ }
+}
+
+static void imap_urlauth_client_handle_input(struct client *client)
+{
+#define AUTH_ARG_COUNT 6
+ struct imap_urlauth_client *uauth_client =
+ (struct imap_urlauth_client *)client;
+ struct net_unix_cred cred;
+ const char *line;
+ const char *const *args;
+ pid_t pid;
+
+ if (!uauth_client->version_received) {
+ if ((line = i_stream_next_line(client->input)) == NULL)
+ return;
+
+ if (!version_string_verify(line, "imap-urlauth",
+ IMAP_URLAUTH_PROTOCOL_MAJOR_VERSION)) {
+ e_error(client->event,
+ "IMAP URLAUTH client not compatible with this server "
+ "(mixed old and new binaries?) %s", line);
+ client_destroy(client, "Version mismatch");
+ return;
+ }
+ uauth_client->version_received = TRUE;
+ }
+
+ if ((line = i_stream_next_line(client->input)) == NULL)
+ return;
+
+ /* read authentication info from input;
+ "AUTH"\t<service>\t<session-pid>\t<auth-username>\t<session_id>\t<token> */
+ args = t_strsplit_tabescaped(line);
+ if (str_array_length(args) < AUTH_ARG_COUNT ||
+ strcmp(args[0], "AUTH") != 0 || str_to_pid(args[2], &pid) < 0) {
+ e_error(client->event,
+ "IMAP URLAUTH client sent unexpected AUTH input: %s", line);
+ client_destroy(client, "Unexpected input");
+ return;
+ }
+
+ /* only imap and submission have direct access to urlauth service */
+ if (strcmp(args[1], "imap") != 0 && strcmp(args[1], "submission") != 0) {
+ e_error(client->event,
+ "IMAP URLAUTH accessed from inappropriate service: %s", args[1]);
+ client_destroy(client, "Unexpected input");
+ return;
+ }
+
+ /* verify session pid if possible */
+ if (net_getunixcred(client->fd, &cred) == 0 &&
+ cred.pid != (pid_t)-1 && pid != cred.pid) {
+ e_error(client->event,
+ "IMAP URLAUTH client sent invalid session pid %ld in AUTH request: "
+ "it did not match peer credentials (pid=%ld, uid=%ld)",
+ (long)pid, (long)cred.pid, (long)cred.uid);
+ client_destroy(client, "Invalid AUTH request");
+ return;
+ }
+
+ T_BEGIN {
+ string_t *auth_data = t_str_new(128);
+ string_t *init_resp;
+ unsigned int i;
+
+ str_append(auth_data, args[1]);
+ for (i = 2; i < AUTH_ARG_COUNT; i++) {
+ str_append_c(auth_data, '\0');
+ str_append(auth_data, args[i]);
+ }
+ init_resp = t_str_new(256);
+ base64_encode(str_data(auth_data),
+ str_len(auth_data), init_resp);
+
+ (void)client_auth_begin_private(client, "DOVECOT-TOKEN",
+ str_c(init_resp));
+ } T_END;
+}
+
+static void imap_urlauth_client_input(struct client *client)
+{
+ if (!client_read(client))
+ return;
+
+ client_ref(client);
+ o_stream_cork(client->output);
+ if (!auth_client_is_connected(auth_client)) {
+ /* we're not currently connected to auth process -
+ don't allow any commands */
+ timeout_remove(&client->to_auth_waiting);
+ client->input_blocked = TRUE;
+ } else {
+ imap_urlauth_client_handle_input(client);
+ }
+ o_stream_uncork(client->output);
+ client_unref(&client);
+}
+
+static struct client *imap_urlauth_client_alloc(pool_t pool)
+{
+ struct imap_urlauth_client *uauth_client;
+
+ uauth_client = p_new(pool, struct imap_urlauth_client, 1);
+ return &uauth_client->common;
+}
+
+static void imap_urlauth_client_create
+(struct client *client, void **other_sets)
+{
+ struct imap_urlauth_client *uauth_client =
+ (struct imap_urlauth_client *)client;
+
+ uauth_client->set = other_sets[0];
+ client->io = io_add_istream(client->input, client_input, client);
+}
+
+static void imap_urlauth_login_preinit(void)
+{
+ login_set_roots = imap_urlauth_login_setting_roots;
+}
+
+static void imap_urlauth_login_init(void)
+{
+}
+
+static void imap_urlauth_login_deinit(void)
+{
+ clients_destroy_all();
+}
+
+static struct client_vfuncs imap_urlauth_vfuncs = {
+ .alloc = imap_urlauth_client_alloc,
+ .create = imap_urlauth_client_create,
+ .input = imap_urlauth_client_input,
+ .auth_result = imap_urlauth_client_auth_result,
+ .send_raw_data = client_common_send_raw_data,
+ .free = client_common_default_free,
+};
+
+static struct login_binary imap_urlauth_login_binary = {
+ .protocol = "imap-urlauth",
+ .process_name = "imap-urlauth-login",
+ .default_login_socket = LOGIN_TOKEN_DEFAULT_SOCKET,
+
+ .event_category = {
+ .name = "imap",
+ },
+
+ .client_vfuncs = &imap_urlauth_vfuncs,
+ .preinit = imap_urlauth_login_preinit,
+ .init = imap_urlauth_login_init,
+ .deinit = imap_urlauth_login_deinit,
+
+ .anonymous_login_acceptable = TRUE,
+};
+
+int main(int argc, char *argv[])
+{
+ return login_binary_run(&imap_urlauth_login_binary, argc, argv);
+}
diff --git a/src/imap-urlauth/imap-urlauth-settings.c b/src/imap-urlauth/imap-urlauth-settings.c
new file mode 100644
index 0000000..73c3220
--- /dev/null
+++ b/src/imap-urlauth/imap-urlauth-settings.c
@@ -0,0 +1,94 @@
+/* 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 "imap-urlauth-settings.h"
+
+#include <stddef.h>
+#include <unistd.h>
+
+/* <settings checks> */
+static struct file_listener_settings imap_urlauth_unix_listeners_array[] = {
+ { "token-login/imap-urlauth", 0666, "", "" }
+};
+static struct file_listener_settings *imap_urlauth_unix_listeners[] = {
+ &imap_urlauth_unix_listeners_array[0]
+};
+static buffer_t imap_urlauth_unix_listeners_buf = {
+ { { imap_urlauth_unix_listeners, sizeof(imap_urlauth_unix_listeners) } }
+};
+/* </settings checks> */
+
+struct service_settings imap_urlauth_service_settings = {
+ .name = "imap-urlauth",
+ .protocol = "imap",
+ .type = "",
+ .executable = "imap-urlauth",
+ .user = "$default_internal_user",
+ .group = "",
+ .privileged_group = "",
+ .extra_groups = "",
+ .chroot = "",
+
+ .drop_priv_before_exec = FALSE,
+
+ .process_min_avail = 0,
+ .process_limit = 1024,
+ .client_limit = 1,
+ .service_count = 1,
+ .idle_kill = 0,
+ .vsz_limit = UOFF_T_MAX,
+
+ .unix_listeners = { { &imap_urlauth_unix_listeners_buf,
+ sizeof(imap_urlauth_unix_listeners[0]) } },
+ .fifo_listeners = ARRAY_INIT,
+ .inet_listeners = ARRAY_INIT
+};
+
+#undef DEF
+#define DEF(type, name) \
+ SETTING_DEFINE_STRUCT_##type(#name, name, struct imap_urlauth_settings)
+
+static const struct setting_define imap_urlauth_setting_defines[] = {
+ DEF(STR, base_dir),
+
+ DEF(BOOL, mail_debug),
+
+ DEF(BOOL, verbose_proctitle),
+
+ DEF(STR, imap_urlauth_logout_format),
+ DEF(STR, imap_urlauth_submit_user),
+ DEF(STR, imap_urlauth_stream_user),
+
+ SETTING_DEFINE_LIST_END
+};
+
+const struct imap_urlauth_settings imap_urlauth_default_settings = {
+ .base_dir = PKG_RUNDIR,
+ .mail_debug = FALSE,
+
+ .verbose_proctitle = FALSE,
+
+ .imap_urlauth_logout_format = "in=%i out=%o",
+ .imap_urlauth_submit_user = NULL,
+ .imap_urlauth_stream_user = NULL
+};
+
+static const struct setting_parser_info *imap_urlauth_setting_dependencies[] = {
+ NULL
+};
+
+const struct setting_parser_info imap_urlauth_setting_parser_info = {
+ .module_name = "imap-urlauth",
+ .defines = imap_urlauth_setting_defines,
+ .defaults = &imap_urlauth_default_settings,
+
+ .type_offset = SIZE_MAX,
+ .struct_size = sizeof(struct imap_urlauth_settings),
+
+ .parent_offset = SIZE_MAX,
+
+ .dependencies = imap_urlauth_setting_dependencies
+};
diff --git a/src/imap-urlauth/imap-urlauth-settings.h b/src/imap-urlauth/imap-urlauth-settings.h
new file mode 100644
index 0000000..c04080e
--- /dev/null
+++ b/src/imap-urlauth/imap-urlauth-settings.h
@@ -0,0 +1,24 @@
+#ifndef IMAP_URLAUTH_SETTINGS_H
+#define IMAP_URLAUTH_SETTINGS_H
+
+struct mail_user_settings;
+
+struct imap_urlauth_settings {
+ const char *base_dir;
+
+ bool mail_debug;
+
+ bool verbose_proctitle;
+
+ /* imap_urlauth: */
+ const char *imap_urlauth_logout_format;
+
+ const char *imap_urlauth_submit_user;
+ const char *imap_urlauth_stream_user;
+};
+
+extern const struct imap_urlauth_settings imap_urlauth_default_settings;
+
+extern const struct setting_parser_info imap_urlauth_setting_parser_info;
+
+#endif
diff --git a/src/imap-urlauth/imap-urlauth-worker-settings.c b/src/imap-urlauth/imap-urlauth-worker-settings.c
new file mode 100644
index 0000000..a459aed
--- /dev/null
+++ b/src/imap-urlauth/imap-urlauth-worker-settings.c
@@ -0,0 +1,88 @@
+/* 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 "mail-storage-settings.h"
+#include "imap-urlauth-worker-settings.h"
+
+#include <stddef.h>
+#include <unistd.h>
+
+/* <settings checks> */
+static struct file_listener_settings imap_urlauth_worker_unix_listeners_array[] = {
+ { "imap-urlauth-worker", 0600, "$default_internal_user", "" }
+};
+static struct file_listener_settings *imap_urlauth_worker_unix_listeners[] = {
+ &imap_urlauth_worker_unix_listeners_array[0]
+};
+static buffer_t imap_urlauth_worker_unix_listeners_buf = {
+ { { imap_urlauth_worker_unix_listeners,
+ sizeof(imap_urlauth_worker_unix_listeners) } }
+};
+/* </settings checks> */
+
+struct service_settings imap_urlauth_worker_service_settings = {
+ .name = "imap-urlauth-worker",
+ .protocol = "imap",
+ .type = "",
+ .executable = "imap-urlauth-worker",
+ .user = "",
+ .group = "",
+ .privileged_group = "",
+ .extra_groups = "$default_internal_group",
+ .chroot = "",
+
+ .drop_priv_before_exec = FALSE,
+
+ .process_min_avail = 0,
+ .process_limit = 1024,
+ .client_limit = 1,
+ .service_count = 1,
+ .idle_kill = 0,
+ .vsz_limit = UOFF_T_MAX,
+
+ .unix_listeners = { { &imap_urlauth_worker_unix_listeners_buf,
+ sizeof(imap_urlauth_worker_unix_listeners[0]) } },
+ .fifo_listeners = ARRAY_INIT,
+ .inet_listeners = ARRAY_INIT
+};
+
+#undef DEF
+#define DEF(type, name) \
+ SETTING_DEFINE_STRUCT_##type(#name, name, struct imap_urlauth_worker_settings)
+
+static const struct setting_define imap_urlauth_worker_setting_defines[] = {
+ DEF(BOOL, verbose_proctitle),
+
+ DEF(STR, imap_urlauth_host),
+ DEF(IN_PORT, imap_urlauth_port),
+
+ SETTING_DEFINE_LIST_END
+};
+
+const struct imap_urlauth_worker_settings imap_urlauth_worker_default_settings = {
+ .verbose_proctitle = FALSE,
+
+ .imap_urlauth_host = "",
+ .imap_urlauth_port = 143
+};
+
+static const struct setting_parser_info *imap_urlauth_worker_setting_dependencies[] = {
+ &mail_user_setting_parser_info,
+ NULL
+};
+
+const struct setting_parser_info imap_urlauth_worker_setting_parser_info = {
+ .module_name = "imap-urlauth-worker",
+ .defines = imap_urlauth_worker_setting_defines,
+ .defaults = &imap_urlauth_worker_default_settings,
+
+ .type_offset = SIZE_MAX,
+ .struct_size = sizeof(struct imap_urlauth_worker_settings),
+
+ .parent_offset = SIZE_MAX,
+
+ .dependencies = imap_urlauth_worker_setting_dependencies
+};
diff --git a/src/imap-urlauth/imap-urlauth-worker-settings.h b/src/imap-urlauth/imap-urlauth-worker-settings.h
new file mode 100644
index 0000000..28154e8
--- /dev/null
+++ b/src/imap-urlauth/imap-urlauth-worker-settings.h
@@ -0,0 +1,18 @@
+#ifndef IMAP_URLAUTH_SETTINGS_H
+#define IMAP_URLAUTH_SETTINGS_H
+
+struct mail_user_settings;
+
+struct imap_urlauth_worker_settings {
+ bool verbose_proctitle;
+
+ /* imap_urlauth: */
+ const char *imap_urlauth_host;
+ in_port_t imap_urlauth_port;
+};
+
+extern const struct imap_urlauth_worker_settings imap_urlauth_worker_default_settings;
+
+extern const struct setting_parser_info imap_urlauth_worker_setting_parser_info;
+
+#endif
diff --git a/src/imap-urlauth/imap-urlauth-worker.c b/src/imap-urlauth/imap-urlauth-worker.c
new file mode 100644
index 0000000..4dc413a
--- /dev/null
+++ b/src/imap-urlauth/imap-urlauth-worker.c
@@ -0,0 +1,1033 @@
+/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "array.h"
+#include "ioloop.h"
+#include "net.h"
+#include "fdpass.h"
+#include "istream.h"
+#include "ostream.h"
+#include "str.h"
+#include "str-sanitize.h"
+#include "strescape.h"
+#include "llist.h"
+#include "hostpid.h"
+#include "var-expand.h"
+#include "process-title.h"
+#include "randgen.h"
+#include "restrict-access.h"
+#include "settings-parser.h"
+#include "master-service.h"
+#include "master-interface.h"
+#include "mail-storage.h"
+#include "mail-storage-service.h"
+#include "mail-namespace.h"
+#include "imap-url.h"
+#include "imap-msgpart-url.h"
+#include "imap-urlauth.h"
+#include "imap-urlauth-fetch.h"
+#include "imap-urlauth-worker-settings.h"
+
+#include <unistd.h>
+#include <sysexits.h>
+
+#define MAX_CTRL_HANDSHAKE 255
+
+/* max. length of input lines (URLs) */
+#define MAX_INBUF_SIZE 2048
+
+/* Disconnect client after idling this many milliseconds */
+#define CLIENT_IDLE_TIMEOUT_MSECS (10*60*1000)
+
+#define IS_STANDALONE() \
+ (getenv(MASTER_IS_PARENT_ENV) == NULL)
+
+#define IMAP_URLAUTH_WORKER_PROTOCOL_MAJOR_VERSION 2
+#define IMAP_URLAUTH_WORKER_PROTOCOL_MINOR_VERSION 0
+
+struct client {
+ struct client *prev, *next;
+
+ int fd_in, fd_out, fd_ctrl;
+
+ struct io *io, *ctrl_io;
+ struct istream *input, *ctrl_input;
+ struct ostream *output, *ctrl_output;
+ struct timeout *to_idle;
+
+ char *access_user, *access_service;
+ ARRAY_TYPE(string) access_apps;
+
+ struct mail_storage_service_user *service_user;
+ struct mail_user *mail_user;
+
+ struct imap_urlauth_context *urlauth_ctx;
+
+ struct imap_msgpart_url *url;
+ struct istream *msg_part_input;
+ uoff_t msg_part_size;
+
+ /* settings: */
+ const struct imap_urlauth_worker_settings *set;
+ const struct mail_storage_settings *mail_set;
+
+ bool debug:1;
+ bool finished:1;
+ bool waiting_input:1;
+ bool version_received:1;
+ bool access_received:1;
+ bool access_anonymous:1;
+};
+
+static bool verbose_proctitle = FALSE;
+static struct mail_storage_service_ctx *storage_service;
+
+struct client *imap_urlauth_worker_clients;
+unsigned int imap_urlauth_worker_client_count;
+
+static void client_destroy(struct client *client);
+static void client_abort(struct client *client, const char *reason);
+static int client_run_url(struct client *client);
+static void client_input(struct client *client);
+static bool client_handle_input(struct client *client);
+static int client_output(struct client *client);
+
+static void client_ctrl_input(struct client *client);
+
+static void imap_urlauth_worker_refresh_proctitle(void)
+{
+ struct client *client = imap_urlauth_worker_clients;
+ string_t *title;
+
+ if (!verbose_proctitle)
+ return;
+
+ title = t_str_new(128);
+ str_append_c(title, '[');
+ switch (imap_urlauth_worker_client_count) {
+ case 0:
+ str_append(title, "idling");
+ break;
+ case 1:
+ if (client->mail_user == NULL)
+ str_append(title, client->access_user);
+ else {
+ str_append(title, client->access_user);
+ str_append(title, "->");
+ str_append(title, client->mail_user->username);
+ }
+ break;
+ default:
+ str_printfa(title, "%u connections",
+ imap_urlauth_worker_client_count);
+ break;
+ }
+ str_append_c(title, ']');
+ process_title_set(str_c(title));
+}
+
+static void client_idle_timeout(struct client *client)
+{
+ if (client->url != NULL) {
+ client_abort(client,
+ "Session closed for inactivity in reading our output");
+ } else {
+ client_destroy(client);
+ }
+}
+
+static struct client *client_create(int fd)
+{
+ struct client *client;
+
+ /* always use nonblocking I/O */
+ net_set_nonblock(fd, TRUE);
+
+ client = i_new(struct client, 1);
+ i_array_init(&client->access_apps, 16);
+ client->fd_in = -1;
+ client->fd_out = -1;
+ client->fd_ctrl = fd;
+ client->access_anonymous = TRUE; /* default until overridden */
+
+ client->ctrl_io = io_add(fd, IO_READ, client_ctrl_input, client);
+ client->to_idle = timeout_add(CLIENT_IDLE_TIMEOUT_MSECS,
+ client_idle_timeout, client);
+
+ imap_urlauth_worker_client_count++;
+ DLLIST_PREPEND(&imap_urlauth_worker_clients, client);
+
+ imap_urlauth_worker_refresh_proctitle();
+ return client;
+}
+
+static struct client *
+client_create_standalone(const char *access_user,
+ const char *const *access_applications,
+ int fd_in, int fd_out, bool debug)
+{
+ struct client *client;
+
+ /* always use nonblocking I/O */
+ net_set_nonblock(fd_in, TRUE);
+ net_set_nonblock(fd_out, TRUE);
+
+ client = i_new(struct client, 1);
+ i_array_init(&client->access_apps, 16);
+ client->fd_in = fd_in;
+ client->fd_out = fd_out;
+ client->fd_ctrl = -1;
+
+ if (access_user != NULL && *access_user != '\0')
+ client->access_user = i_strdup(access_user);
+ else {
+ client->access_user = i_strdup("anonymous");
+ client->access_anonymous = TRUE;
+ }
+ if (access_applications != NULL) {
+ const char *const *apps = access_applications;
+ for (; *apps != NULL; apps++) {
+ char *app = i_strdup(*apps);
+ array_push_back(&client->access_apps, &app);
+ }
+ }
+ client->debug = debug;
+
+ client->input = i_stream_create_fd(fd_in, MAX_INBUF_SIZE);
+ client->output = o_stream_create_fd(fd_out, SIZE_MAX);
+ client->io = io_add(fd_in, IO_READ, client_input, client);
+ client->to_idle = timeout_add(CLIENT_IDLE_TIMEOUT_MSECS,
+ client_idle_timeout, client);
+ o_stream_set_no_error_handling(client->output, TRUE);
+ o_stream_set_flush_callback(client->output, client_output, client);
+
+ imap_urlauth_worker_client_count++;
+ DLLIST_PREPEND(&imap_urlauth_worker_clients, client);
+
+ i_set_failure_prefix("imap-urlauth[%s](%s): ",
+ my_pid, client->access_user);
+ return client;
+}
+
+static void client_abort(struct client *client, const char *reason)
+{
+ i_error("%s", reason);
+ client_destroy(client);
+}
+
+static void client_destroy(struct client *client)
+{
+ char *app;
+
+ i_set_failure_prefix("imap-urlauth[%s](%s): ",
+ my_pid, client->access_user);
+
+ if (client->url != NULL) {
+ /* deinitialize url */
+ i_stream_close(client->input);
+ o_stream_close(client->output);
+ (void)client_run_url(client);
+ i_assert(client->url == NULL);
+ }
+
+ imap_urlauth_worker_client_count--;
+ DLLIST_REMOVE(&imap_urlauth_worker_clients, client);
+
+ if (client->urlauth_ctx != NULL)
+ imap_urlauth_deinit(&client->urlauth_ctx);
+
+ if (client->mail_user != NULL)
+ mail_user_deinit(&client->mail_user);
+
+ io_remove(&client->io);
+ io_remove(&client->ctrl_io);
+ timeout_remove(&client->to_idle);
+
+ i_stream_destroy(&client->input);
+ o_stream_destroy(&client->output);
+
+ i_stream_destroy(&client->ctrl_input);
+ o_stream_destroy(&client->ctrl_output);
+
+ fd_close_maybe_stdio(&client->fd_in, &client->fd_out);
+ if (client->fd_ctrl >= 0)
+ net_disconnect(client->fd_ctrl);
+
+ if (client->service_user != NULL)
+ mail_storage_service_user_unref(&client->service_user);
+ i_free(client->access_user);
+ i_free(client->access_service);
+ array_foreach_elem(&client->access_apps, app)
+ i_free(app);
+ array_free(&client->access_apps);
+ i_free(client);
+
+ imap_urlauth_worker_refresh_proctitle();
+ master_service_client_connection_destroyed(master_service);
+}
+
+static int client_run_url(struct client *client)
+{
+ const unsigned char *data;
+ size_t size;
+ ssize_t ret = 0;
+
+ while (i_stream_read_more(client->msg_part_input, &data, &size) > 0) {
+ if ((ret = o_stream_send(client->output, data, size)) < 0)
+ break;
+ i_stream_skip(client->msg_part_input, ret);
+
+ if (o_stream_get_buffer_used_size(client->output) >= 4096) {
+ if ((ret = o_stream_flush(client->output)) < 0)
+ break;
+ if (ret == 0)
+ return 0;
+ }
+ }
+
+ if (client->output->closed || ret < 0) {
+ imap_msgpart_url_free(&client->url);
+ return -1;
+ }
+
+ if (client->msg_part_input->eof) {
+ o_stream_nsend(client->output, "\n", 1);
+ imap_msgpart_url_free(&client->url);
+ return 1;
+ }
+ return 0;
+}
+
+static void clients_destroy_all(void)
+{
+ while (imap_urlauth_worker_clients != NULL)
+ client_destroy(imap_urlauth_worker_clients);
+}
+
+static void ATTR_FORMAT(2, 3)
+client_send_line(struct client *client, const char *fmt, ...)
+{
+ va_list va;
+
+ if (client->output->closed)
+ return;
+
+ va_start(va, fmt);
+
+ T_BEGIN {
+ string_t *str;
+
+ str = t_str_new(256);
+ str_vprintfa(str, fmt, va);
+ str_append(str, "\n");
+
+ o_stream_nsend(client->output, str_data(str), str_len(str));
+ } T_END;
+
+ va_end(va);
+}
+
+static int
+client_fetch_urlpart(struct client *client, const char *url,
+ enum imap_urlauth_fetch_flags url_flags,
+ const char **bpstruct_r, bool *binary_with_nuls_r,
+ const char **errormsg_r)
+{
+ const char *error;
+ struct imap_msgpart_open_result mpresult;
+ enum mail_error error_code;
+ int ret;
+
+ *bpstruct_r = NULL;
+ *errormsg_r = NULL;
+ *binary_with_nuls_r = FALSE;
+
+ ret = imap_urlauth_fetch(client->urlauth_ctx, url,
+ &client->url, &error_code, &error);
+ if (ret <= 0) {
+ if (ret < 0)
+ return -1;
+ error = t_strdup_printf("Failed to fetch URLAUTH \"%s\": %s",
+ url, error);
+ if (client->debug)
+ i_debug("%s", error);
+ /* don't leak info about existence/accessibility
+ of mailboxes */
+ if (error_code == MAIL_ERROR_PARAMS)
+ *errormsg_r = error;
+ return 0;
+ }
+
+ if ((url_flags & IMAP_URLAUTH_FETCH_FLAG_BINARY) != 0)
+ imap_msgpart_url_set_decode_to_binary(client->url);
+ if ((url_flags & IMAP_URLAUTH_FETCH_FLAG_BODYPARTSTRUCTURE) != 0) {
+ ret = imap_msgpart_url_get_bodypartstructure(client->url,
+ bpstruct_r, &error);
+ if (ret <= 0) {
+ *errormsg_r = t_strdup_printf(
+ "Failed to read URLAUTH \"%s\": %s", url, error);
+ if (client->debug)
+ i_debug("%s", *errormsg_r);
+ return ret;
+ }
+ }
+
+ /* if requested, read the message part the URL points to */
+ if ((url_flags & IMAP_URLAUTH_FETCH_FLAG_BODY) != 0 ||
+ (url_flags & IMAP_URLAUTH_FETCH_FLAG_BINARY) != 0) {
+ ret = imap_msgpart_url_read_part(client->url, &mpresult, &error);
+ if (ret <= 0) {
+ *errormsg_r = t_strdup_printf(
+ "Failed to read URLAUTH \"%s\": %s", url, error);
+ if (client->debug)
+ i_debug("%s", *errormsg_r);
+ return ret;
+ }
+ client->msg_part_size = mpresult.size;
+ client->msg_part_input = mpresult.input;
+ *binary_with_nuls_r = mpresult.binary_decoded_input_has_nuls;
+ }
+ return 1;
+}
+
+static int client_fetch_url(struct client *client, const char *url,
+ enum imap_urlauth_fetch_flags url_flags)
+{
+ string_t *response;
+ const char *bpstruct, *errormsg;
+ bool binary_with_nuls;
+ int ret;
+
+ i_assert(client->url == NULL);
+
+ client->msg_part_size = 0;
+ client->msg_part_input = NULL;
+
+ if (client->debug)
+ i_debug("Fetching URLAUTH %s", url);
+
+ /* fetch URL */
+ ret = client_fetch_urlpart(client, url, url_flags, &bpstruct,
+ &binary_with_nuls, &errormsg);
+ if (ret <= 0) {
+ /* fetch failed */
+ if (client->url != NULL)
+ imap_msgpart_url_free(&client->url);
+ /* don't send error details to anonymous users: just to be sure
+ that no information about the target user account is unduly
+ leaked. */
+ if (client->access_anonymous || errormsg == NULL)
+ client_send_line(client, "NO");
+ else {
+ client_send_line(client, "NO\terror=%s",
+ str_tabescape(errormsg));
+ }
+ if (ret < 0) {
+ /* fetch failed badly */
+ client_abort(client, "Session aborted: Fatal failure while fetching URL");
+ }
+ return 0;
+ }
+
+ response = t_str_new(256);
+ str_append(response, "OK");
+ if (binary_with_nuls)
+ str_append(response, "\thasnuls");
+ if (bpstruct != NULL) {
+ str_append(response, "\tbpstruct=");
+ str_append(response, str_tabescape(bpstruct));
+ if (client->debug) {
+ i_debug("Fetched URLAUTH yielded BODYPARTSTRUCTURE (%s)",
+ bpstruct);
+ }
+ }
+
+ /* return content */
+ o_stream_cork(client->output);
+ if (client->msg_part_size == 0 || client->msg_part_input == NULL) {
+ /* empty */
+ str_append(response, "\t0");
+ client_send_line(client, "%s", str_c(response));
+
+ imap_msgpart_url_free(&client->url);
+ client->url = NULL;
+ if (client->debug)
+ i_debug("Fetched URLAUTH yielded empty result");
+ } else {
+
+ /* actual content */
+ str_printfa(response, "\t%"PRIuUOFF_T, client->msg_part_size);
+ client_send_line(client, "%s", str_c(response));
+
+ if (client->debug) {
+ i_debug("Fetched URLAUTH yielded %"PRIuUOFF_T" bytes "
+ "of %smessage data", client->msg_part_size,
+ (binary_with_nuls ? "binary " : ""));
+ }
+ if (client_run_url(client) < 0) {
+ client_abort(client,
+ "Session aborted: Fatal failure while transferring URL");
+ return 0;
+ }
+ }
+
+ if (client->url != NULL) {
+ /* URL not finished */
+ o_stream_set_flush_pending(client->output, TRUE);
+ client->waiting_input = TRUE;
+ }
+ o_stream_uncork(client->output);
+ return client->url != NULL ? 0 : 1;
+}
+
+static int
+client_handle_command(struct client *client, const char *cmd,
+ const char *const *args, const char **error_r)
+{
+ int ret;
+
+ *error_r = NULL;
+
+ /* "URL"["\tbody"]["\tbinary"]["\tbpstruct"]"\t"<url>:
+ fetch URL (meta)data */
+ if (strcmp(cmd, "URL") == 0) {
+ enum imap_urlauth_fetch_flags url_flags = 0;
+ const char *url;
+
+ if (*args == NULL) {
+ *error_r = "URL: Missing URL parameter";
+ return -1;
+ }
+
+ url = *args;
+
+ args++;
+ while (*args != NULL) {
+ if (strcasecmp(*args, "body") == 0)
+ url_flags |= IMAP_URLAUTH_FETCH_FLAG_BODY;
+ else if (strcasecmp(*args, "binary") == 0)
+ url_flags |= IMAP_URLAUTH_FETCH_FLAG_BINARY;
+ else if (strcasecmp(*args, "bpstruct") == 0)
+ url_flags |= IMAP_URLAUTH_FETCH_FLAG_BODYPARTSTRUCTURE;
+
+ args++;
+ }
+
+ if (url_flags == 0)
+ url_flags = IMAP_URLAUTH_FETCH_FLAG_BODY;
+
+ T_BEGIN {
+ ret = client_fetch_url(client, url, url_flags);
+ } T_END;
+ return ret;
+ }
+
+ /* "END": unselect current user (closes worker) */
+ if (strcmp(cmd, "END") == 0) {
+ if (args[0] != NULL) {
+ *error_r = "END: Invalid number of parameters";
+ return -1;
+ }
+
+ client->finished = TRUE;
+ if (client->ctrl_output != NULL)
+ o_stream_nsend_str(client->ctrl_output, "FINISHED\n");
+ client_destroy(client);
+ return 0;
+ }
+
+ *error_r = t_strconcat("Unknown or inappropriate command: ", cmd, NULL);
+ return -1;
+}
+
+static int
+client_handle_user_command(struct client *client, const char *cmd,
+ const char *const *args, const char **error_r)
+{
+ struct mail_storage_service_input input;
+ struct imap_urlauth_worker_settings *set;
+ struct mail_storage_service_user *user;
+ struct imap_urlauth_config config;
+ struct mail_user *mail_user;
+ const char *error;
+ unsigned int count;
+ int ret;
+
+ /* "USER\t"<username> */
+ *error_r = NULL;
+
+ /* check command syntax */
+ if (strcmp(cmd, "USER") != 0) {
+ *error_r = t_strconcat("Unknown or inappropriate command: ",
+ cmd, NULL);
+ return -1;
+ }
+
+ if (args[0] == NULL || args[1] != NULL) {
+ *error_r = "USER: Invalid number of parameters";
+ return -1;
+ }
+
+ /* lookup user */
+ i_zero(&input);
+ input.module = "imap-urlauth-worker";
+ input.service = "imap-urlauth-worker";
+ input.username = args[0];
+
+ if (client->debug)
+ i_debug("Looking up user %s", input.username);
+
+ ret = mail_storage_service_lookup_next(storage_service, &input,
+ &user, &mail_user, &error);
+ if (ret < 0) {
+ i_error("Failed to lookup user %s: %s", input.username, error);
+ client_abort(client, "Session aborted: Failed to lookup user");
+ return 0;
+ } else if (ret == 0) {
+ if (client->debug)
+ i_debug("User %s doesn't exist", input.username);
+
+ client_send_line(client, "NO");
+ return 1;
+ }
+
+ client->debug = mail_user->mail_debug =
+ client->debug || mail_user->mail_debug;
+
+ /* drop privileges */
+ restrict_access_allow_coredumps(TRUE);
+
+ set = mail_storage_service_user_get_set(user)[1];
+ if (settings_var_expand(&imap_urlauth_worker_setting_parser_info, set,
+ mail_user->pool,
+ mail_user_var_expand_table(mail_user),
+ &error) <= 0) {
+ client_send_line(client, "NO");
+ client_abort(client, t_strdup_printf(
+ "Session aborted: Failed to expand settings: %s", error));
+ return 0;
+ }
+
+ if (set->verbose_proctitle) {
+ verbose_proctitle = TRUE;
+ imap_urlauth_worker_refresh_proctitle();
+ }
+
+ client->service_user = user;
+ client->mail_user = mail_user;
+ client->set = set;
+
+ if (client->debug) {
+ i_debug("Found user account `%s' on behalf of user `%s'",
+ mail_user->username, client->access_user);
+ }
+
+ /* initialize urlauth context */
+ if (*set->imap_urlauth_host == '\0') {
+ i_error("imap_urlauth_host setting is not configured for user %s",
+ mail_user->username);
+ client_send_line(client, "NO");
+ client_abort(client, "Session aborted: URLAUTH not configured");
+ return 0;
+ }
+
+ i_zero(&config);
+ config.url_host = set->imap_urlauth_host;
+ config.url_port = set->imap_urlauth_port;
+ config.access_user = client->access_user;
+ config.access_service = client->access_service;
+ config.access_anonymous = client->access_anonymous;
+ config.access_applications =
+ (const void *)array_get(&client->access_apps, &count);
+
+ client->urlauth_ctx = imap_urlauth_init(client->mail_user, &config);
+ if (client->debug) {
+ i_debug("Providing access to user account `%s' on behalf of user `%s' "
+ "using service `%s'", mail_user->username, client->access_user,
+ client->access_service);
+ }
+
+ i_set_failure_prefix("imap-urlauth[%s](%s->%s): ",
+ my_pid, client->access_user, mail_user->username);
+
+ client_send_line(client, "OK");
+ return 1;
+}
+
+static bool client_handle_input(struct client *client)
+{
+ const char *line, *cmd, *error;
+ int ret;
+
+ if (client->url != NULL) {
+ /* we're still processing a URL. wait until it's
+ finished. */
+ io_remove(&client->io);
+ client->io = NULL;
+ client->waiting_input = TRUE;
+ return TRUE;
+ }
+
+ if (client->io == NULL) {
+ client->io = io_add(client->fd_in, IO_READ,
+ client_input, client);
+ }
+ client->waiting_input = FALSE;
+ timeout_reset(client->to_idle);
+
+ switch (i_stream_read(client->input)) {
+ case -1:
+ /* disconnected */
+ if (client->ctrl_output != NULL)
+ o_stream_nsend_str(client->ctrl_output, "DISCONNECTED\n");
+ client_destroy(client);
+ return FALSE;
+ case -2:
+ /* line too long, kill it */
+ client_abort(client, "Session aborted: Input line too long");
+ return FALSE;
+ }
+
+ while ((line = i_stream_next_line(client->input)) != NULL) {
+ const char *const *args = t_strsplit_tabescaped(line);
+
+ if (args[0] == NULL)
+ continue;
+ cmd = args[0]; args++;
+
+ if (client->mail_user == NULL)
+ ret = client_handle_user_command(client, cmd, args, &error);
+ else
+ ret = client_handle_command(client, cmd, args, &error);
+
+ if (ret <= 0) {
+ if (ret == 0)
+ break;
+ i_error("Client input error: %s", error);
+ client_abort(client, "Session aborted: Unexpected input");
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+static void client_input(struct client *client)
+{
+ (void)client_handle_input(client);
+}
+
+static int client_output(struct client *client)
+{
+ if (o_stream_flush(client->output) < 0) {
+ if (client->ctrl_output != NULL)
+ o_stream_nsend_str(client->ctrl_output, "DISCONNECTED\n");
+ client_destroy(client);
+ return 1;
+ }
+ timeout_reset(client->to_idle);
+
+ if (client->url != NULL) {
+ if (client_run_url(client) < 0) {
+ client_destroy(client);
+ return 1;
+ }
+
+ if (client->url == NULL && client->waiting_input) {
+ if (!client_handle_input(client)) {
+ /* client got destroyed */
+ return 1;
+ }
+ }
+ }
+
+ if (client->url != NULL) {
+ /* url not finished yet */
+ return 0;
+ } else if (client->io == NULL) {
+ /* data still in output buffer, get back here to add IO */
+ return 0;
+ } else {
+ return 1;
+ }
+}
+
+static int
+client_ctrl_read_fds(struct client *client)
+{
+ unsigned char data = 0;
+ ssize_t ret = 1;
+
+ if (client->fd_in == -1) {
+ ret = fd_read(client->fd_ctrl, &data,
+ sizeof(data), &client->fd_in);
+ if (ret > 0 && data == '0')
+ client->fd_out = client->fd_in;
+ }
+ if (ret > 0 && client->fd_out == -1) {
+ ret = fd_read(client->fd_ctrl, &data,
+ sizeof(data), &client->fd_out);
+ }
+
+ if (ret == 0) {
+ /* unexpectedly disconnected */
+ client_destroy(client);
+ return 0;
+ } else if (ret < 0) {
+ if (errno == EAGAIN)
+ return 0;
+ i_error("fd_read() failed: %m");
+ return -1;
+ } else if (data != '0') {
+ i_error("fd_read() returned invalid byte 0x%2x", data);
+ return -1;
+ }
+
+ if (client->fd_in == -1 || client->fd_out == -1) {
+ i_error("Handshake is missing a file descriptor");
+ return -1;
+ }
+
+ client->ctrl_input =
+ i_stream_create_fd(client->fd_ctrl, MAX_INBUF_SIZE);
+ client->ctrl_output = o_stream_create_fd(client->fd_ctrl, SIZE_MAX);
+ o_stream_set_no_error_handling(client->ctrl_output, TRUE);
+ return 1;
+}
+
+static void client_ctrl_input(struct client *client)
+{
+ const char *const *args;
+ const char *line;
+ int ret;
+
+ timeout_reset(client->to_idle);
+
+ if (client->fd_in == -1 || client->fd_out == -1) {
+ if ((ret = client_ctrl_read_fds(client)) <= 0) {
+ if (ret < 0)
+ client_abort(client, "FD Transfer failed");
+ return;
+ }
+ }
+
+ switch (i_stream_read(client->ctrl_input)) {
+ case -1:
+ /* disconnected */
+ client_destroy(client);
+ return;
+ case -2:
+ /* line too long, kill it */
+ client_abort(client,
+ "Control session aborted: Input line too long");
+ return;
+ }
+
+ if (!client->version_received) {
+ if ((line = i_stream_next_line(client->ctrl_input)) == NULL)
+ return;
+
+ if (!version_string_verify(line, "imap-urlauth-worker",
+ IMAP_URLAUTH_WORKER_PROTOCOL_MAJOR_VERSION)) {
+ i_error("imap-urlauth-worker client not compatible with this server "
+ "(mixed old and new binaries?) %s", line);
+ client_abort(client, "Control session aborted: Version mismatch");
+ return;
+ }
+
+ client->version_received = TRUE;
+ if (o_stream_send_str(client->ctrl_output, "OK\n") < 0) {
+ client_destroy(client);
+ return;
+ }
+ }
+
+ if (client->access_received) {
+ client_abort(client, "Control session aborted: Unexpected input");
+ return;
+ }
+
+ if ((line = i_stream_next_line(client->ctrl_input)) == NULL)
+ return;
+
+ args = t_strsplit_tabescaped(line);
+ if (*args == NULL || strcmp(*args, "ACCESS") != 0) {
+ i_error("Invalid control command: %s", str_sanitize(line, 80));
+ client_abort(client, "Control session aborted: Invalid command");
+ return;
+ }
+ args++;
+ if (args[0] == NULL || args[1] == NULL) {
+ i_error("Invalid ACCESS command: %s", str_sanitize(line, 80));
+ client_abort(client, "Control session aborted: Invalid command");
+ return;
+ }
+
+ i_assert(client->access_user == NULL);
+ i_assert(client->access_service == NULL);
+ if (**args != '\0') {
+ client->access_user = i_strdup(*args);
+ client->access_anonymous = FALSE;
+ } else {
+ client->access_user = i_strdup("anonymous");
+ client->access_anonymous = TRUE;
+ }
+ args++;
+ client->access_service = i_strdup(*args);
+
+ i_set_failure_prefix("imap-urlauth[%s](%s): ",
+ my_pid, client->access_user);
+
+ args++;
+ while (*args != NULL) {
+ /* debug */
+ if (strcasecmp(*args, "debug") == 0) {
+ client->debug = TRUE;
+ /* apps=<access-application>[,<access-application,...] */
+ } else if (strncasecmp(*args, "apps=", 5) == 0 &&
+ (*args)[5] != '\0') {
+ const char *const *apps = t_strsplit(*args+5, ",");
+
+ while (*apps != NULL) {
+ char *app = i_strdup(*apps);
+
+ array_push_back(&client->access_apps, &app);
+ if (client->debug) {
+ i_debug("User %s has URLAUTH %s access",
+ client->access_user, app);
+ }
+ apps++;
+ }
+ } else {
+ i_error("Invalid ACCESS parameter: %s", str_sanitize(*args, 80));
+ client_abort(client, "Control session aborted: Invalid command");
+ return;
+ }
+ args++;
+ }
+
+ client->access_received = TRUE;
+
+ if (o_stream_send_str(client->ctrl_output, "OK\n") < 0) {
+ client_destroy(client);
+ return;
+ }
+
+ client->input = i_stream_create_fd(client->fd_in, MAX_INBUF_SIZE);
+ client->output = o_stream_create_fd(client->fd_out, SIZE_MAX);
+ client->io = io_add(client->fd_in, IO_READ, client_input, client);
+ o_stream_set_no_error_handling(client->output, TRUE);
+ o_stream_set_flush_callback(client->output, client_output, client);
+
+ if (client->debug) {
+ i_debug("Worker activated for access by user `%s' using service `%s'",
+ client->access_user, client->access_service);
+ }
+}
+
+static void imap_urlauth_worker_die(void)
+{
+ /* do nothing */
+}
+
+static void main_stdio_run(const char *access_user,
+ const char *const *access_applications)
+{
+ bool debug;
+
+ debug = getenv("DEBUG") != NULL;
+ access_user = access_user != NULL ? access_user : getenv("USER");
+ if (access_user == NULL && IS_STANDALONE())
+ access_user = getlogin();
+ if (access_user == NULL)
+ i_fatal("USER environment missing");
+
+ (void)client_create_standalone(access_user, access_applications,
+ STDIN_FILENO, STDOUT_FILENO, debug);
+}
+
+static void client_connected(struct master_service_connection *conn)
+{
+ master_service_client_connection_accept(conn);
+ (void)client_create(conn->fd);
+}
+
+int main(int argc, char *argv[])
+{
+ static const struct setting_parser_info *set_roots[] = {
+ &imap_urlauth_worker_setting_parser_info,
+ NULL
+ };
+ enum master_service_flags service_flags = 0;
+ enum mail_storage_service_flags storage_service_flags =
+ MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP |
+ MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT;
+ ARRAY_TYPE (const_string) access_apps;
+ const char *access_user = NULL;
+ int c;
+
+ if (IS_STANDALONE()) {
+ service_flags |= MASTER_SERVICE_FLAG_STANDALONE |
+ MASTER_SERVICE_FLAG_STD_CLIENT;
+ } else {
+ service_flags |= MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN;
+ }
+
+ master_service = master_service_init("imap-urlauth-worker", service_flags,
+ &argc, &argv, "a:");
+
+ t_array_init(&access_apps, 4);
+ while ((c = master_getopt(master_service)) > 0) {
+ switch (c) {
+ case 'a': {
+ const char *app = t_strdup(optarg);
+
+ array_push_back(&access_apps, &app);
+ break;
+ }
+ default:
+ return FATAL_DEFAULT;
+ }
+ }
+
+ if ( optind < argc ) {
+ access_user = argv[optind++];
+ }
+
+ if (optind != argc) {
+ i_fatal_status(EX_USAGE, "Unknown argument: %s", argv[optind]);
+ }
+
+ master_service_init_log_with_pid(master_service);
+ master_service_set_die_callback(master_service, imap_urlauth_worker_die);
+
+ storage_service =
+ mail_storage_service_init(master_service,
+ set_roots, storage_service_flags);
+ master_service_init_finish(master_service);
+
+ /* fake that we're running, so we know if client was destroyed
+ while handling its initial input */
+ io_loop_set_running(current_ioloop);
+
+ if (IS_STANDALONE()) {
+ T_BEGIN {
+ if (array_count(&access_apps) > 0) {
+ (void)array_append_space(&access_apps);
+ main_stdio_run(access_user,
+ array_front(&access_apps));
+ } else {
+ main_stdio_run(access_user, NULL);
+ }
+ } T_END;
+ } else {
+ io_loop_set_running(current_ioloop);
+ }
+
+ if (io_loop_is_running(current_ioloop))
+ master_service_run(master_service, client_connected);
+ clients_destroy_all();
+
+ mail_storage_service_deinit(&storage_service);
+ master_service_deinit(&master_service);
+ return 0;
+}
diff --git a/src/imap-urlauth/imap-urlauth.c b/src/imap-urlauth/imap-urlauth.c
new file mode 100644
index 0000000..e7cb7d2
--- /dev/null
+++ b/src/imap-urlauth/imap-urlauth.c
@@ -0,0 +1,288 @@
+/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
+
+/*
+The imap-urlauth service provides URLAUTH access between different accounts. If
+user A has an URLAUTH that references a mail from user B, it makes a connection
+to the imap-urlauth service to access user B's mail store to retrieve the
+mail.
+
+The authentication and authorization of the URLAUTH is performed within
+this service. Because access to the mailbox and the associated mailbox keys is
+necessary to retrieve the message and for verification of the URLAUTH, the
+urlauth services need root privileges. To mitigate security concerns, the
+retrieval and verification of the URLs is performed in a worker service that
+drops root privileges and acts as target user B.
+
+The imap-urlauth service thus consists of three separate stages:
+
+- imap-urlauth-login:
+ This is the login service which operates identical to imap-login and
+ pop3-login equivalents, except for the fact that only token authentication is
+ allowed. It verifies that the connecting client is an IMAP service acting on
+ behaf of an authenticated user.
+
+- imap-urlauth:
+ Once the client is authenticated, the connection gets passed to the
+ imap-urlauth service (as implemented here). The goal of this stage is
+ to prevent the need for re-authenticating to the imap-urlauth service when
+ the clients wants to switch to a different target user. It normally runs as
+ $default_internal_user and starts workers to perform the actual work. To start
+ a worker, the imap-urlauth service establishes a control connection to the
+ imap-urlauth-worker service. In the handshake phase of the control protocol,
+ the connection of the client is passed to the worker. Once the worker
+ finishes, a new worker is started and the client connection is transfered to
+ it, unless the client is disconnected.
+
+- imap-urlauth-worker:
+ The worker handles the URLAUTH requests from the client, so this is where the
+ mail store of the target user is accessed. The worker starts as root. In the
+ protocol interaction the client first indicates what the target user is.
+ The worker then performs a userdb lookup and drops privileges. The client can
+ then submit URLAUTH requests, which are limited to that user. Once the client
+ wants to access a different user, the worker terminates and the imap-urlauth
+ service starts a new worker for the next target user.
+*/
+
+#include "imap-urlauth-common.h"
+#include "lib-signals.h"
+#include "ioloop.h"
+#include "buffer.h"
+#include "array.h"
+#include "istream.h"
+#include "ostream.h"
+#include "path-util.h"
+#include "base64.h"
+#include "str.h"
+#include "process-title.h"
+#include "auth-master.h"
+#include "master-service.h"
+#include "master-service-settings.h"
+#include "master-login.h"
+#include "master-interface.h"
+#include "var-expand.h"
+
+#include <stdio.h>
+#include <unistd.h>
+
+#define IS_STANDALONE() \
+ (getenv(MASTER_IS_PARENT_ENV) == NULL)
+
+bool verbose_proctitle = FALSE;
+static struct master_login *master_login = NULL;
+
+static const struct imap_urlauth_settings *imap_urlauth_settings;
+
+void imap_urlauth_refresh_proctitle(void)
+{
+ struct client *client;
+ string_t *title = t_str_new(128);
+
+ if (!verbose_proctitle)
+ return;
+
+ str_append_c(title, '[');
+ switch (imap_urlauth_client_count) {
+ case 0:
+ str_append(title, "idling");
+ break;
+ case 1:
+ client = imap_urlauth_clients;
+ str_append(title, client->username);
+ break;
+ default:
+ str_printfa(title, "%u connections", imap_urlauth_client_count);
+ break;
+ }
+ str_append_c(title, ']');
+ process_title_set(str_c(title));
+}
+
+static void imap_urlauth_die(void)
+{
+ /* do nothing. imap_urlauth connections typically die pretty quick anyway. */
+}
+
+static int
+client_create_from_input(const char *service, const char *username,
+ int fd_in, int fd_out)
+{
+ struct client *client;
+
+ if (client_create(service, username, fd_in, fd_out,
+ imap_urlauth_settings, &client) < 0)
+ return -1;
+
+ if (!IS_STANDALONE())
+ client_send_line(client, "OK");
+ return 0;
+}
+
+static void main_stdio_run(const char *username)
+{
+ username = username != NULL ? username : getenv("USER");
+ if (username == NULL && IS_STANDALONE())
+ username = getlogin();
+ if (username == NULL)
+ i_fatal("USER environment missing");
+
+ (void)client_create_from_input("", username, STDIN_FILENO, STDOUT_FILENO);
+}
+
+static void
+login_client_connected(const struct master_login_client *client,
+ const char *username, const char *const *extra_fields)
+{
+ const char *msg = "NO\n";
+ struct auth_user_reply reply;
+ struct net_unix_cred cred;
+ const char *const *fields;
+ const char *service = NULL;
+ unsigned int count, i;
+
+ auth_user_fields_parse(extra_fields, pool_datastack_create(), &reply);
+
+ /* check peer credentials if possible */
+ if (reply.uid != (uid_t)-1 && net_getunixcred(client->fd, &cred) == 0 &&
+ reply.uid != cred.uid) {
+ i_error("Peer's credentials (uid=%ld) do not match "
+ "the user that logged in (uid=%ld).",
+ (long)cred.uid, (long)reply.uid);
+ if (write(client->fd, msg, strlen(msg)) < 0) {
+ /* ignored */
+ }
+ net_disconnect(client->fd);
+ return;
+ }
+
+ fields = array_get(&reply.extra_fields, &count);
+ for (i = 0; i < count; i++) {
+ if (str_begins(fields[i], "client_service=")) {
+ service = fields[i] + 15;
+ break;
+ }
+ }
+
+ if (service == NULL) {
+ i_error("Auth did not yield required client_service field (BUG).");
+ if (write(client->fd, msg, strlen(msg)) < 0) {
+ /* ignored */
+ }
+ net_disconnect(client->fd);
+ return;
+ }
+
+ if (reply.anonymous)
+ username = NULL;
+
+ if (client_create_from_input(service, username, client->fd, client->fd) < 0)
+ net_disconnect(client->fd);
+}
+
+static void login_client_failed(const struct master_login_client *client,
+ const char *errormsg ATTR_UNUSED)
+{
+ const char *msg = "NO\n";
+ if (write(client->fd, msg, strlen(msg)) < 0) {
+ /* ignored */
+ }
+}
+
+static void client_connected(struct master_service_connection *conn)
+{
+ /* when running standalone, we shouldn't even get here */
+ i_assert(master_login != NULL);
+
+ master_service_client_connection_accept(conn);
+ master_login_add(master_login, conn->fd);
+}
+
+int main(int argc, char *argv[])
+{
+ static const struct setting_parser_info *set_roots[] = {
+ &imap_urlauth_setting_parser_info,
+ NULL
+ };
+ struct master_login_settings login_set;
+ struct master_service_settings_input input;
+ struct master_service_settings_output output;
+ void **sets;
+ enum master_service_flags service_flags = 0;
+ const char *error = NULL, *username = NULL;
+ const char *auth_socket_path = "auth-master";
+ int c;
+
+ i_zero(&login_set);
+ login_set.postlogin_timeout_secs = MASTER_POSTLOGIN_TIMEOUT_DEFAULT;
+
+ if (IS_STANDALONE() && getuid() == 0 &&
+ net_getpeername(1, NULL, NULL) == 0) {
+ printf("NO imap_urlauth binary must not be started from "
+ "inetd, use imap-urlauth-login instead.\n");
+ return 1;
+ }
+
+ if (IS_STANDALONE()) {
+ service_flags |= MASTER_SERVICE_FLAG_STANDALONE |
+ MASTER_SERVICE_FLAG_STD_CLIENT;
+ } else {
+ service_flags |= MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN;
+ }
+
+ master_service = master_service_init("imap-urlauth", service_flags,
+ &argc, &argv, "a:");
+ while ((c = master_getopt(master_service)) > 0) {
+ switch (c) {
+ case 'a':
+ auth_socket_path = optarg;
+ break;
+ default:
+ return FATAL_DEFAULT;
+ }
+ }
+ master_service_init_log(master_service);
+
+ i_zero(&input);
+ input.roots = set_roots;
+ input.module = "imap-urlauth";
+ input.service = "imap-urlauth";
+ if (master_service_settings_read(master_service, &input, &output,
+ &error) < 0)
+ i_fatal("Error reading configuration: %s", error);
+
+ sets = master_service_settings_get_others(master_service);
+ imap_urlauth_settings = sets[0];
+
+ if (imap_urlauth_settings->verbose_proctitle)
+ verbose_proctitle = TRUE;
+
+ if (t_abspath(auth_socket_path, &login_set.auth_socket_path, &error) < 0) {
+ i_fatal("t_abspath(%s) failed: %s", auth_socket_path, error);
+ }
+ login_set.callback = login_client_connected;
+ login_set.failure_callback = login_client_failed;
+
+ master_service_init_finish(master_service);
+ master_service_set_die_callback(master_service, imap_urlauth_die);
+
+ /* fake that we're running, so we know if client was destroyed
+ while handling its initial input */
+ io_loop_set_running(current_ioloop);
+
+ if (IS_STANDALONE()) {
+ T_BEGIN {
+ main_stdio_run(username);
+ } T_END;
+ } else {
+ master_login = master_login_init(master_service, &login_set);
+ io_loop_set_running(current_ioloop);
+ }
+
+ if (io_loop_is_running(current_ioloop))
+ master_service_run(master_service, client_connected);
+ clients_destroy_all();
+
+ if (master_login != NULL)
+ master_login_deinit(&master_login);
+ master_service_deinit(&master_service);
+ return 0;
+}