ASR_BASE
Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/external/subpack/mail/dovecot/Config.in b/external/subpack/mail/dovecot/Config.in
new file mode 100644
index 0000000..0f48b9f
--- /dev/null
+++ b/external/subpack/mail/dovecot/Config.in
@@ -0,0 +1,40 @@
+menu "Select dovecot build options"
+ depends on PACKAGE_dovecot
+
+config DOVECOT_GSSAPI
+ bool "GSSAPI support"
+ default n
+ help
+ Implements GSSAPI support in dovecot.
+
+config DOVECOT_LDAP
+ bool "LDAP support"
+ default n
+ help
+ Implements LDAP support in dovecot.
+
+config DOVECOT_MYSQL
+ bool "MYSQL support"
+ default n
+ help
+ Implements MYSQL support in dovecot.
+
+config DOVECOT_PGSQL
+ bool "PostgreSQL support"
+ default n
+ help
+ Implements PostgreSQL support in dovecot.
+
+config DOVECOT_SQLITE
+ bool "SQLite support"
+ default n
+ help
+ Implements SQLite DB support in dovecot.
+
+config DOVECOT_ICU
+bool "Enable i18n features"
+ default n
+ help
+ Enable ICU (International Components for Unicode) support.
+
+endmenu
diff --git a/external/subpack/mail/dovecot/Makefile b/external/subpack/mail/dovecot/Makefile
new file mode 100644
index 0000000..cd69c1a
--- /dev/null
+++ b/external/subpack/mail/dovecot/Makefile
@@ -0,0 +1,136 @@
+#
+# Copyright (C) 2006-2018 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=dovecot
+PKG_VERSION:=2.3.13
+PKG_RELEASE:=$(AUTORELEASE)
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://dovecot.org/releases/2.3
+PKG_HASH:=a3f875b80ec11a452480690108660030978c94fa8e796ad6d943a874b496f1c4
+
+PKG_MAINTAINER:=Lucian Cristian <lucian.cristian@gmail.com>
+PKG_LICENSE:=LGPL-2.1-only MIT BSD-3-Clause
+PKG_LICENSE_FILES:=COPYING COPYING.LGPL COPYING.MIT
+PKG_CPE_ID:=cpe:/a:dovecot:dovecot
+
+PKG_CONFIG_DEPENDS:= \
+ CONFIG_DOVECOT_GSSAPI \
+ CONFIG_DOVECOT_LDAP \
+ CONFIG_DOVECOT_MYSQL \
+ CONFIG_DOVECOT_PGSQL \
+ CONFIG_DOVECOT_SQLITE \
+ CONFIG_DOVECOT_ICU
+
+PKG_FIXUP:=autoreconf
+PKG_INSTALL:=1
+PKG_BUILD_PARALLEL:=1
+
+include $(INCLUDE_DIR)/package.mk
+# iconv is needed when compiling with MySQL support. iconv will also be used by
+# dovecot itself.
+include $(INCLUDE_DIR)/nls.mk
+
+define Package/dovecot
+ SECTION:=mail
+ CATEGORY:=Mail
+ TITLE:=An IMAP and POP3 daemon
+ URL:=https://www.dovecot.org/
+ DEPENDS:=+DOVECOT_GSSAPI:krb5-libs +DOVECOT_LDAP:libopenldap +DOVECOT_MYSQL:libmysqlclient +DOVECOT_PGSQL:libpq +DOVECOT_SQLITE:libsqlite3 +libopenssl +librt +zlib +libbz2 +libcap +DOVECOT_ICU:icu $(ICONV_DEPENDS)
+ USERID:=dovecot=59:dovecot=59 dovenull=60:dovenull=60
+ ABI_VERSION:=$(PKG_VERSION)
+endef
+
+define Package/dovecot/description
+ Dovecot is a program which provides POP3 and IMAP services.
+endef
+
+define Package/dovecot/config
+ source "$(SOURCE)/Config.in"
+endef
+
+define Package/dovecot/conffiles
+/etc/dovecot/
+endef
+
+define Package/dovecot-utils
+ SECTION:=mail
+ CATEGORY:=Mail
+ DEPENDS:=+dovecot
+ TITLE:=doveadm and dsync utilities for Dovecot
+endef
+
+CONFIGURE_ARGS += \
+ --libexecdir=/usr/libexec \
+ --without-libunwind \
+ --without-pam \
+ --with-notify=dnotify \
+ --without-lzma \
+ --without-lz4 \
+ --without-sodium \
+ --without-zstd \
+ $(if $(CONFIG_DOVECOT_GSSAPI),--with-gssapi=yes,--with-gssapi=no) \
+ $(if $(CONFIG_DOVECOT_LDAP),--with-ldap=yes,--with-ldap=no) \
+ $(if $(CONFIG_DOVECOT_MYSQL),--with-mysql=yes,--with-mysql=no) \
+ $(if $(CONFIG_DOVECOT_PGSQL),--with-pgsql=yes,--with-pgsql=no) \
+ $(if $(CONFIG_DOVECOT_SQLITE),--with-sqlite=yes,--with-sqlite=no) \
+ $(if $(CONFIG_DOVECOT_ICU),--with-icu=yes,--with-icu=no)
+
+CONFIGURE_VARS += \
+ RPCGEN= \
+ i_cv_signed_size_t=no \
+ i_cv_signed_time_t=no \
+ i_cv_gmtime_max_time_t=32 \
+ i_cv_mmap_plays_with_write=yes \
+ i_cv_fd_passing=yes \
+ i_cv_c99_vsnprintf=yes \
+ lib_cv_va_copy=yes \
+ lib_cv_va_copy=yes \
+ lib_cv___va_copy=yes \
+ lib_cv_va_val_copy=yes \
+ ac_cv_prog_KRB5CONFIG="krb5-config"
+
+define Build/InstallDev
+ $(INSTALL_DIR) $(1)/usr/include $(1)/usr/lib
+ $(CP) $(PKG_INSTALL_DIR)/usr/include/dovecot $(1)/usr/include/
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/dovecot $(1)/usr/lib/
+ $(call libtool_remove_files,$(1))
+endef
+
+
+define Package/dovecot/install
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_BIN) ./files/dovecot.init $(1)/etc/init.d/dovecot
+
+ $(INSTALL_DIR) $(1)/etc/dovecot
+ $(CP) $(PKG_INSTALL_DIR)/usr/share/doc/dovecot/example-config/* $(1)/etc/dovecot/
+
+ $(INSTALL_DIR) $(1)/usr/lib/dovecot
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/dovecot/* $(1)/usr/lib/dovecot/
+ rm $(1)/usr/lib/dovecot/dovecot-config
+ find $(1)/usr/lib/dovecot/ -name "*.a" -o -name "*.la" | $(XARGS) rm -f
+
+ $(INSTALL_DIR) $(1)/usr/libexec/dovecot
+ $(CP) $(PKG_INSTALL_DIR)/usr/libexec/dovecot/* $(1)/usr/libexec/dovecot/
+
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/doveconf $(1)/usr/bin/
+
+ $(INSTALL_DIR) $(1)/usr/sbin
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/* $(1)/usr/sbin/
+endef
+
+define Package/dovecot-utils/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/doveadm $(1)/usr/bin/
+ $(CP) $(PKG_INSTALL_DIR)/usr/bin/dsync $(1)/usr/bin/
+endef
+
+$(eval $(call BuildPackage,dovecot))
+$(eval $(call BuildPackage,dovecot-utils))
diff --git a/external/subpack/mail/dovecot/files/dovecot.init b/external/subpack/mail/dovecot/files/dovecot.init
new file mode 100644
index 0000000..1f83184
--- /dev/null
+++ b/external/subpack/mail/dovecot/files/dovecot.init
@@ -0,0 +1,16 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2006-2013 OpenWrt.org
+
+START=75
+STOP=75
+
+USE_PROCD=1
+
+start_service() {
+ mkdir -p -m 0755 /var/lib/dovecot
+ mkdir -p -m 0755 /var/run/dovecot
+ chmod 0750 /var/lib/dovecot
+ procd_open_instance
+ procd_set_param command /usr/sbin/dovecot -F
+ procd_close_instance
+}
diff --git a/external/subpack/mail/dovecot/patches/001-configure_in.patch b/external/subpack/mail/dovecot/patches/001-configure_in.patch
new file mode 100644
index 0000000..b01d5b6
--- /dev/null
+++ b/external/subpack/mail/dovecot/patches/001-configure_in.patch
@@ -0,0 +1,91 @@
+--- a/m4/fd_passing.m4
++++ b/m4/fd_passing.m4
+@@ -8,7 +8,7 @@ AC_DEFUN([DOVECOT_FD_PASSING], [
+ CFLAGS="$CFLAGS -DBUGGY_CMSG_MACROS"
+ fi
+
+- AC_TRY_RUN([
++ AC_TRY_LINK([
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <sys/wait.h>
+@@ -16,7 +16,7 @@ AC_DEFUN([DOVECOT_FD_PASSING], [
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include "fdpass.h"
+-
++ ], [
+ static
+ int nopen(void)
+ {
+--- a/m4/glibc.m4
++++ b/m4/glibc.m4
+@@ -17,7 +17,7 @@ AC_DEFUN([DOVECOT_GLIBC], [
+ dnl * Old glibcs have broken posix_fallocate(). Make sure not to use it.
+ dnl * It may also be broken in AIX.
+ AC_CACHE_CHECK([whether posix_fallocate() works],i_cv_posix_fallocate_works,[
+- AC_TRY_RUN([
++ AC_TRY_LINK([
+ #define _XOPEN_SOURCE 600
+ #include <stdio.h>
+ #include <stdlib.h>
+@@ -26,6 +26,7 @@ AC_DEFUN([DOVECOT_GLIBC], [
+ #if defined(__GLIBC__) && (__GLIBC__ < 2 || __GLIBC_MINOR__ < 7)
+ possibly broken posix_fallocate
+ #endif
++ ], [
+ int main() {
+ int fd = creat("conftest.temp", 0600);
+ int ret;
+--- a/m4/ioloop.m4
++++ b/m4/ioloop.m4
+@@ -4,9 +4,9 @@ AC_DEFUN([DOVECOT_IOLOOP], [
+
+ if test "$ioloop" = "best" || test "$ioloop" = "epoll"; then
+ AC_CACHE_CHECK([whether we can use epoll],i_cv_epoll_works,[
+- AC_TRY_RUN([
++ AC_TRY_LINK([
+ #include <sys/epoll.h>
+-
++ ], [
+ int main()
+ {
+ return epoll_create(5) < 1;
+--- a/m4/mmap_write.m4
++++ b/m4/mmap_write.m4
+@@ -1,7 +1,7 @@
+ dnl * If mmap() plays nicely with write()
+ AC_DEFUN([DOVECOT_MMAP_WRITE], [
+ AC_CACHE_CHECK([whether shared mmaps get updated by write()s],i_cv_mmap_plays_with_write,[
+- AC_TRY_RUN([
++ AC_TRY_LINK([
+ #include <stdio.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+@@ -9,6 +9,7 @@ AC_DEFUN([DOVECOT_MMAP_WRITE], [
+ #include <fcntl.h>
+ #include <sys/mman.h>
+ #include <string.h>
++ ], [
+ int main() {
+ /* return 0 if we're signed */
+ int f = open("conftest.mmap", O_RDWR|O_CREAT|O_TRUNC, 0600);
+--- a/m4/want_gssapi.m4
++++ b/m4/want_gssapi.m4
+@@ -55,7 +55,7 @@ AC_DEFUN([DOVECOT_WANT_GSSAPI], [
+
+ # does the kerberos library support SPNEGO?
+ AC_CACHE_CHECK([whether GSSAPI supports SPNEGO],i_cv_gssapi_spnego,[
+- AC_TRY_RUN([
++ AC_TRY_LINK([
+ #ifdef HAVE_GSSAPI_H
+ # include <gssapi.h>
+ #else
+@@ -63,6 +63,7 @@ AC_DEFUN([DOVECOT_WANT_GSSAPI], [
+ #endif
+ #include <krb5.h>
+ #include <string.h>
++ ], [
+ int main(void) {
+ OM_uint32 minor_status;
+ gss_OID_set mech_set;
diff --git a/external/subpack/mail/dovecot/patches/050-fix-dovecot-config-for-cross-compile.patch b/external/subpack/mail/dovecot/patches/050-fix-dovecot-config-for-cross-compile.patch
new file mode 100644
index 0000000..2fd49d9
--- /dev/null
+++ b/external/subpack/mail/dovecot/patches/050-fix-dovecot-config-for-cross-compile.patch
@@ -0,0 +1,56 @@
+pigeonhole: Fix managesieve-login needs libdovecot-login
+
+When trying to use managesieve my MUA complained sieve wasn't supported.
+On investigation dovecot logs the following could be seen:
+
+ Aug 16 00:28:44 managesieve-login: Fatal: master:
+ service(managesieve-login): child 1430 returned error 127
+ Aug 16 00:31:32 managesieve-login: Error: Error loading shared
+ library libdovecot-login.so.0: No such file or directory
+ (needed by /usr/lib/dovecot/managesieve-login)
+ Aug 16 00:31:32 managesieve-login: Error: Error loading
+ shared library libdovecot.so.0: No such file or directory
+ (needed by /usr/lib/dovecot/managesieve-login)
+ Aug 16 00:31:32 managesieve-login: Error: Error relocating
+ /usr/lib/dovecot/managesieve-login: net_ip2addr: symbol not found
+
+The issue (verified with readelf on non-working build and build with my fix)
+is that there is no RPATH information in the pigeonhole binaries (like
+managesieve-login).
+
+The dovecot-config that is 'installed' in the staging dir
+assumes that plugins will be built on the same host as the installed files.
+The 'installed' dovecot-config (partial) looks like:
+
+LIBDOVECOT='-L/usr/lib/dovecot -ldovecot'
+LIBDOVECOT_LOGIN='-ldovecot-login -L/home/user/Build/openwrt/openwrt-ath79/staging_dir/target-mips_24kc_musl/usr/lib -lssl -lcrypto'
+LIBDOVECOT_SQL=-ldovecot-sql
+LIBDOVECOT_COMPRESS=-ldovecot-compression
+LIBDOVECOT_LDA=-ldovecot-lda
+LIBDOVECOT_STORAGE='-ldovecot-storage '
+LIBDOVECOT_DSYNC=-ldovecot-dsync
+LIBDOVECOT_LIBFTS=-ldovecot-fts
+
+This patch modifed dovecot-config that gets installed on the assumption
+that users of libdovecot will also be cross-compiled (a safe bet).
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -73,7 +73,7 @@ install-exec-hook:
+ grep -v '^LIBDOVECOT_.*_INCLUDE' dovecot-config | \
+ grep -v '^LIBDOVECOT.*_DEPS' | sed \
+ -e "s|^\(DOVECOT_INSTALLED\)=.*$$|\1=yes|" \
+- -e "s|^\(LIBDOVECOT\)=.*$$|\1='-L$(pkglibdir) -ldovecot'|" \
++ -e "s|^\(LIBDOVECOT\)=.*$$|\1='-L$(STAGING_DIR)$(pkglibdir) -ldovecot'|" \
+ -e "s|^\(LIBDOVECOT_LOGIN\)=.*$$|\1='-ldovecot-login $(SSL_LIBS)'|" \
+ -e "s|^\(LIBDOVECOT_SQL\)=.*$$|\1=-ldovecot-sql|" \
+ -e "s|^\(LIBDOVECOT_COMPRESS\)=.*$$|\1=-ldovecot-compression|" \
+@@ -81,7 +81,8 @@ install-exec-hook:
+ -e "s|^\(LIBDOVECOT_LDA\)=.*$$|\1=-ldovecot-lda|" \
+ -e "s|^\(LIBDOVECOT_LIBFTS\)=.*$$|\1=-ldovecot-fts|" \
+ -e "s|^\(LIBDOVECOT_STORAGE\)=.*$$|\1='-ldovecot-storage $(LINKED_STORAGE_LDADD)'|" \
+- -e "s|^\(LIBDOVECOT_INCLUDE\)=.*$$|\1=-I$(pkgincludedir)|" \
++ -e "s|^\(LIBDOVECOT_INCLUDE\)=.*$$|\1=-I$(STAGING_DIR)$(pkgincludedir)|" \
++ -e "s|^\(DOVECOT_BINARY_LDFLAGS=\".*\)\"$$|\1 -Wl,-rpath -Wl,$(pkglibdir)\"|" \
+ > $(DESTDIR)$(pkglibdir)/dovecot-config
+
+ uninstall-hook:
diff --git a/external/subpack/mail/dovecot/patches/100-openssl-deprecated.patch b/external/subpack/mail/dovecot/patches/100-openssl-deprecated.patch
new file mode 100644
index 0000000..621a9f2
--- /dev/null
+++ b/external/subpack/mail/dovecot/patches/100-openssl-deprecated.patch
@@ -0,0 +1,43 @@
+--- a/src/lib-ssl-iostream/dovecot-openssl-common.c
++++ b/src/lib-ssl-iostream/dovecot-openssl-common.c
+@@ -63,9 +63,11 @@ void dovecot_openssl_common_global_ref(v
+ /*i_warning("CRYPTO_set_mem_functions() was called too late");*/
+ }
+
++#if OPENSSL_VERSION_NUMBER < 0x10100000L
+ SSL_library_init();
+ SSL_load_error_strings();
+ OpenSSL_add_all_algorithms();
++#endif
+ }
+
+ bool dovecot_openssl_common_global_unref(void)
+@@ -79,6 +81,7 @@ bool dovecot_openssl_common_global_unref
+ ENGINE_finish(dovecot_openssl_engine);
+ dovecot_openssl_engine = NULL;
+ }
++#if OPENSSL_VERSION_NUMBER < 0x10100000L
+ /* OBJ_cleanup() is called automatically by EVP_cleanup() in
+ newer versions. Doesn't hurt to call it anyway. */
+ OBJ_cleanup();
+@@ -101,6 +104,7 @@ bool dovecot_openssl_common_global_unref
+ #ifdef HAVE_OPENSSL_CLEANUP
+ OPENSSL_cleanup();
+ #endif
++#endif
+ return FALSE;
+ }
+
+--- a/src/lib-ssl-iostream/iostream-openssl-context.c
++++ b/src/lib-ssl-iostream/iostream-openssl-context.c
+@@ -558,8 +558,10 @@ ssl_proxy_ctx_set_crypto_params(SSL_CTX
+ int nid;
+ const char *curve_name;
+ #endif
++#if OPENSSL_VERSION_NUMBER < 0x10100000L
+ if (SSL_CTX_need_tmp_RSA(ssl_ctx) != 0)
+ SSL_CTX_set_tmp_rsa_callback(ssl_ctx, ssl_gen_rsa_key);
++#endif
+ if (set->dh == NULL || *set->dh == '\0')
+ SSL_CTX_set_tmp_dh_callback(ssl_ctx, ssl_tmp_dh_callback);
+ #ifdef HAVE_ECDH
diff --git a/external/subpack/mail/dovecot/patches/110-openssl-engine.patch b/external/subpack/mail/dovecot/patches/110-openssl-engine.patch
new file mode 100644
index 0000000..6d16c58
--- /dev/null
+++ b/external/subpack/mail/dovecot/patches/110-openssl-engine.patch
@@ -0,0 +1,87 @@
+--- a/src/lib-dcrypt/dcrypt-openssl.c
++++ b/src/lib-dcrypt/dcrypt-openssl.c
+@@ -20,10 +20,12 @@
+ #include <openssl/bio.h>
+ #include <openssl/pem.h>
+ #include <openssl/x509.h>
+-#include <openssl/engine.h>
+ #include <openssl/hmac.h>
+ #include <openssl/objects.h>
+ #include <openssl/bn.h>
++#ifndef OPENSSL_NO_ENGINE
++#include <openssl/engine.h>
++#endif
+ #include "dcrypt.h"
+ #include "dcrypt-private.h"
+
+@@ -236,11 +238,13 @@ dcrypt_openssl_padding_mode(enum dcrypt_
+ static bool dcrypt_openssl_initialize(const struct dcrypt_settings *set,
+ const char **error_r)
+ {
++#ifndef OPENSSL_NO_ENGINE
+ if (set->crypto_device != NULL && set->crypto_device[0] != '\0') {
+ if (dovecot_openssl_common_global_set_engine(
+ set->crypto_device, error_r) <= 0)
+ return FALSE;
+ }
++#endif
+ return TRUE;
+ }
+
+--- a/src/lib-ssl-iostream/dovecot-openssl-common.c
++++ b/src/lib-ssl-iostream/dovecot-openssl-common.c
+@@ -5,11 +5,14 @@
+ #include "dovecot-openssl-common.h"
+
+ #include <openssl/ssl.h>
+-#include <openssl/engine.h>
+ #include <openssl/rand.h>
++#ifndef OPENSSL_NO_ENGINE
++#include <openssl/engine.h>
+
+-static int openssl_init_refcount = 0;
+ static ENGINE *dovecot_openssl_engine;
++#endif
++
++static int openssl_init_refcount = 0;
+
+ #ifdef HAVE_SSL_NEW_MEM_FUNCS
+ static void *dovecot_openssl_malloc(size_t size, const char *u0 ATTR_UNUSED, int u1 ATTR_UNUSED)
+@@ -77,10 +80,12 @@ bool dovecot_openssl_common_global_unref
+ if (--openssl_init_refcount > 0)
+ return TRUE;
+
++#ifndef OPENSSL_NO_ENGINE
+ if (dovecot_openssl_engine != NULL) {
+ ENGINE_finish(dovecot_openssl_engine);
+ dovecot_openssl_engine = NULL;
+ }
++#endif
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
+ /* OBJ_cleanup() is called automatically by EVP_cleanup() in
+ newer versions. Doesn't hurt to call it anyway. */
+@@ -88,7 +93,9 @@ bool dovecot_openssl_common_global_unref
+ #ifdef HAVE_SSL_COMP_FREE_COMPRESSION_METHODS
+ SSL_COMP_free_compression_methods();
+ #endif
++#ifndef OPENSSL_NO_ENGINE
+ ENGINE_cleanup();
++#endif
+ EVP_cleanup();
+ CRYPTO_cleanup_all_ex_data();
+ #ifdef HAVE_OPENSSL_AUTO_THREAD_DEINIT
+@@ -111,6 +118,7 @@ bool dovecot_openssl_common_global_unref
+ int dovecot_openssl_common_global_set_engine(const char *engine,
+ const char **error_r)
+ {
++#ifndef OPENSSL_NO_ENGINE
+ if (dovecot_openssl_engine != NULL)
+ return 1;
+
+@@ -132,5 +140,6 @@ int dovecot_openssl_common_global_set_en
+ dovecot_openssl_engine = NULL;
+ return -1;
+ }
++#endif
+ return 1;
+ }