summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Basin2021-12-06 20:54:33 +0300
committerIlya Basin2021-12-06 20:54:33 +0300
commit0e518548497f5e61c438d68d0c48b15adf4b2bc1 (patch)
treec7b4efc9e48b8f5a6818bdb0fb75f00e429d24f3
downloadaur-0e518548497f5e61c438d68d0c48b15adf4b2bc1.tar.gz
root
-rw-r--r--.SRCINFO49
-rw-r--r--02-exeext.patch22
-rw-r--r--03-fix-plugins.patch22
-rw-r--r--04-manpage-paths.patch51
-rw-r--r--14-MinGW-w64-add-LIBSASL_API-to-function-definitions.patch154
-rw-r--r--15-MinGW-w64-define-LIBSASL_EXPORTS_eq_1-for-sasldb.patch33
-rw-r--r--16-MinGW-w64-define-WIN32_LEAN_AND_MEAN-avoiding-handle_t-redef.patch13
-rw-r--r--19-paths-relocation.patch147
-rw-r--r--20-mingw-tchar.patch32
-rw-r--r--21-fix-getopt-guard.patch18
-rw-r--r--22-autoconf-prevent-full-path-resolution.patch56
-rw-r--r--PKGBUILD174
-rw-r--r--pathtools.c578
-rw-r--r--pathtools.h57
-rw-r--r--with-sqlite3-makemd5.patch10
15 files changed, 1416 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..6d42ac8f730a
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,49 @@
+pkgbase = mingw-w64-cyrus-sasl
+ pkgdesc = Cyrus Simple Authentication Service Layer (SASL) library (mingw-w64)
+ pkgver = 2.1.27
+ pkgrel = 1
+ url = https://www.cyrusimap.org/sasl/
+ arch = any
+ license = custom
+ depends = mingw-w64-gdbm
+ depends = mingw-w64-openssl
+ depends = mingw-w64-sqlite3
+ provides = mingw-w64-libsasl
+ conflicts = mingw-w64-libsasl
+ options = emptydirs
+ options = !strip
+ options = !buildflags
+ options = !makeflags
+ source = https://github.com/cyrusimap/cyrus-sasl/releases/download/cyrus-sasl-2.1.27/cyrus-sasl-2.1.27.tar.gz
+ source = https://github.com/cyrusimap/cyrus-sasl/releases/download/cyrus-sasl-2.1.27/cyrus-sasl-2.1.27.tar.gz.sig
+ source = pathtools.c
+ source = pathtools.h
+ source = 02-exeext.patch
+ source = 03-fix-plugins.patch
+ source = 04-manpage-paths.patch
+ source = 14-MinGW-w64-add-LIBSASL_API-to-function-definitions.patch
+ source = 15-MinGW-w64-define-LIBSASL_EXPORTS_eq_1-for-sasldb.patch
+ source = 16-MinGW-w64-define-WIN32_LEAN_AND_MEAN-avoiding-handle_t-redef.patch
+ source = 19-paths-relocation.patch
+ source = 20-mingw-tchar.patch
+ source = 21-fix-getopt-guard.patch
+ source = with-sqlite3-makemd5.patch
+ source = 22-autoconf-prevent-full-path-resolution.patch
+ validpgpkeys = 829F339F8C296FE80F409D93E3D7C118C7B9F46A
+ sha256sums = 26866b1549b00ffd020f188a43c258017fa1c382b3ddadd8201536f72efb05d5
+ sha256sums = SKIP
+ sha256sums = 6f1016e6647b6340fdceefaf24ff391f4c0ea3c785ddf70c9794ca2356797888
+ sha256sums = 6ce4dcf4ef6c4bce48dbcb6f1b5226baf79f74ac76719fb0c06419a0aadb37a3
+ sha256sums = 0d0220f721b07f821e14f00c04250c2243620301200f825e7f0532b581d63a7d
+ sha256sums = 62fca7407d288e021fac6fed47d8a94ef2775c257ddcb79071428fe7719485f5
+ sha256sums = b8bedacab5fc992eb2afd259ce2e898291d2bec685030108be3f51e6ce30977c
+ sha256sums = 795196a9db0c8155d59c08dcbb0df15dfe7bb4eb47b30df511649573ac59b39f
+ sha256sums = 148c2062d22011f731ad93fb603cde9c519e73322c89add0408772c434c6bf17
+ sha256sums = e101e1bd3ee03650e89e05c18d5f699d2f69aecc4f7aac4b11db2d1755783c5c
+ sha256sums = f10b41804eeb4c77cb3b061c95c5c71d5624faa17925e5e04e683f4bd6c2bee7
+ sha256sums = 57b1b40017fa2a3fb189deedc01959673ed96cc01e088fd85ae0d59e1e13f25f
+ sha256sums = f51412367d893cb4c2e4ee2ec76a6a641abaaf6d3086af93a9b579a8d0ce26c5
+ sha256sums = SKIP
+ sha256sums = 8cca4435b2d8bc5c04490bd16092bc9c5fcf3eb5c113778674b8393342302c65
+
+pkgname = mingw-w64-cyrus-sasl
diff --git a/02-exeext.patch b/02-exeext.patch
new file mode 100644
index 000000000000..dbec288b06a5
--- /dev/null
+++ b/02-exeext.patch
@@ -0,0 +1,22 @@
+
+
+From: David Rothenberger <daveroth@acm.org>
+
+
+---
+ m4/sasldb.m4 | 2 +-
+ 1 files changed, 1 insertions(+), 1 deletions(-)
+
+diff --git a/m4/sasldb.m4 b/m4/sasldb.m4
+index b28b087..85e769a 100644
+--- a/m4/sasldb.m4
++++ b/m4/sasldb.m4
+@@ -111,7 +111,7 @@ AC_MSG_RESULT($dblib)
+ SASL_DB_BACKEND="db_${dblib}.lo"
+ SASL_DB_BACKEND_STATIC="db_${dblib}.o allockey.o"
+ SASL_DB_BACKEND_STATIC_SRCS="\$(top_srcdir)/sasldb/db_${dblib}.c \$(top_srcdir)/sasldb/allockey.c"
+-SASL_DB_UTILS="saslpasswd2 sasldblistusers2"
++SASL_DB_UTILS='saslpasswd2$(EXEEXT) sasldblistusers2$(EXEEXT)'
+ SASL_DB_MANS="saslpasswd2.8 sasldblistusers2.8"
+
+ case "$dblib" in
diff --git a/03-fix-plugins.patch b/03-fix-plugins.patch
new file mode 100644
index 000000000000..416699136cc0
--- /dev/null
+++ b/03-fix-plugins.patch
@@ -0,0 +1,22 @@
+
+
+From: David Rothenberger <daveroth@acm.org>
+
+
+---
+ common/plugin_common.h | 2 +-
+ 1 files changed, 1 insertions(+), 1 deletions(-)
+
+diff --git a/common/plugin_common.h b/common/plugin_common.h
+index 0f75897..3e844c7 100644
+--- a/common/plugin_common.h
++++ b/common/plugin_common.h
+@@ -63,7 +63,7 @@
+ #include <saslutil.h>
+ #include <saslplug.h>
+
+-#ifdef WIN32
++#if defined(WIN32) || defined(__CYGWIN__)
+ #define PLUG_API __declspec(dllexport)
+ #else
+ #define PLUG_API extern
diff --git a/04-manpage-paths.patch b/04-manpage-paths.patch
new file mode 100644
index 000000000000..92949d16b748
--- /dev/null
+++ b/04-manpage-paths.patch
@@ -0,0 +1,51 @@
+
+
+From: David Rothenberger <daveroth@acm.org>
+
+
+---
+ saslauthd/LDAP_SASLAUTHD | 2 +-
+ saslauthd/saslauthd.8 | 10 +++++-----
+ 2 files changed, 6 insertions(+), 6 deletions(-)
+
+diff --git a/saslauthd/LDAP_SASLAUTHD b/saslauthd/LDAP_SASLAUTHD
+index 86f24e5..eb321ec 100644
+--- a/saslauthd/LDAP_SASLAUTHD
++++ b/saslauthd/LDAP_SASLAUTHD
+@@ -36,7 +36,7 @@ make install
+ 2. START SASLAUTHD WITH LDAP
+ ----------------------------
+
+-Create /usr/local/etc/saslauthd.conf and add the following (modify to fit your
++Create /etc/saslauthd.conf and add the following (modify to fit your
+ environment):
+ ldap_servers: ldap://10.1.1.15/ ldap://10.1.1.25/
+ ldap_bind_dn: cn=operator,ou=Profile,o=foo.com
+diff --git a/saslauthd/saslauthd.8 b/saslauthd/saslauthd.8
+index 843edb0..07b5358 100644
+--- a/saslauthd/saslauthd.8
++++ b/saslauthd/saslauthd.8
+@@ -169,10 +169,10 @@
+ ldap (All platforms that support OpenLDAP 2.0 or higher)
+
+ Authenticate against an ldap server. The ldap configuration
+- parameters are read from /usr/local/etc/saslauthd.conf. The
+- location of this file can be changed with the -O parameter.
+- See the LDAP_SASLAUTHD file included with the distribution for
+- the list of available parameters.
++ parameters are read from /etc/saslauthd.conf. The location
++ of this file can be changed with the -O parameter. See the
++ LDAP_SASLAUTHD file included with the distribution for the
++ list of available parameters.
+
+ sia (Digital UNIX)
+
+@@ -194,7 +194,7 @@
+ FILES
+ /var/run/saslauthd/mux The default communications socket.
+
+- /usr/local/etc/saslauthd.conf
++ /etc/saslauthd.conf
+ The default configuration file for ldap support.
+
+ SEE ALSO
diff --git a/14-MinGW-w64-add-LIBSASL_API-to-function-definitions.patch b/14-MinGW-w64-add-LIBSASL_API-to-function-definitions.patch
new file mode 100644
index 000000000000..d7dbf10abf26
--- /dev/null
+++ b/14-MinGW-w64-add-LIBSASL_API-to-function-definitions.patch
@@ -0,0 +1,154 @@
+diff -urN a/sasldb/db_berkeley.c b/sasldb/db_berkeley.c
+--- a/sasldb/db_berkeley.c 2014-08-12 22:40:34.277570400 +0100
++++ b/sasldb/db_berkeley.c 2014-08-12 22:40:35.109618000 +0100
+@@ -358,7 +358,7 @@
+ return result;
+ }
+
+-int _sasl_check_db(const sasl_utils_t *utils,
++LIBSASL_API int _sasl_check_db(const sasl_utils_t *utils,
+ sasl_conn_t *conn)
+ {
+ const char *path = SASL_DB_PATH;
+@@ -412,7 +412,7 @@
+ DBC *cursor;
+ } berkleyhandle_t;
+
+-sasldb_handle _sasldb_getkeyhandle(const sasl_utils_t *utils,
++LIBSASL_API sasldb_handle _sasldb_getkeyhandle(const sasl_utils_t *utils,
+ sasl_conn_t *conn)
+ {
+ int ret;
+@@ -447,7 +447,7 @@
+ return (sasldb_handle)handle;
+ }
+
+-int _sasldb_getnextkey(const sasl_utils_t *utils __attribute__((unused)),
++LIBSASL_API int _sasldb_getnextkey(const sasl_utils_t *utils __attribute__((unused)),
+ sasldb_handle handle, char *out,
+ const size_t max_out, size_t *out_len)
+ {
+@@ -501,7 +501,7 @@
+ }
+
+
+-int _sasldb_releasekeyhandle(const sasl_utils_t *utils,
++LIBSASL_API int _sasldb_releasekeyhandle(const sasl_utils_t *utils,
+ sasldb_handle handle)
+ {
+ berkleyhandle_t *dbh = (berkleyhandle_t *)handle;
+diff -urN a/sasldb/db_gdbm.c b/sasldb/db_gdbm.c
+--- a/sasldb/db_gdbm.c 2014-08-12 22:40:34.276570300 +0100
++++ b/sasldb/db_gdbm.c 2014-08-12 22:40:35.111618100 +0100
+@@ -221,7 +221,7 @@
+ return result;
+ }
+
+-int _sasl_check_db(const sasl_utils_t *utils,
++LIBSASL_API int _sasl_check_db(const sasl_utils_t *utils,
+ sasl_conn_t *conn)
+ {
+ const char *path = SASL_DB_PATH;
+@@ -270,7 +270,7 @@
+ int first;
+ } handle_t;
+
+-sasldb_handle _sasldb_getkeyhandle(const sasl_utils_t *utils,
++LIBSASL_API sasldb_handle _sasldb_getkeyhandle(const sasl_utils_t *utils,
+ sasl_conn_t *conn)
+ {
+ const char *path = SASL_DB_PATH;
+@@ -316,7 +316,7 @@
+ return (sasldb_handle)handle;
+ }
+
+-int _sasldb_getnextkey(const sasl_utils_t *utils __attribute__((unused)),
++LIBSASL_API int _sasldb_getnextkey(const sasl_utils_t *utils __attribute__((unused)),
+ sasldb_handle handle, char *out,
+ const size_t max_out, size_t *out_len)
+ {
+@@ -346,7 +346,7 @@
+ return SASL_CONTINUE;
+ }
+
+-int _sasldb_releasekeyhandle(const sasl_utils_t *utils,
++LIBSASL_API int _sasldb_releasekeyhandle(const sasl_utils_t *utils,
+ sasldb_handle handle)
+ {
+ handle_t *dbh = (handle_t *)handle;
+diff -urN a/sasldb/db_ndbm.c b/sasldb/db_ndbm.c
+--- a/sasldb/db_ndbm.c 2014-08-12 22:40:34.276570300 +0100
++++ b/sasldb/db_ndbm.c 2014-08-12 22:40:35.112618100 +0100
+@@ -231,7 +231,7 @@
+ #define SUFLEN 5
+ #endif
+
+-int _sasl_check_db(const sasl_utils_t *utils,
++LIBSASL_API int _sasl_check_db(const sasl_utils_t *utils,
+ sasl_conn_t *conn)
+ {
+ const char *path = SASL_DB_PATH;
+@@ -304,7 +304,7 @@
+ int first;
+ } handle_t;
+
+-sasldb_handle _sasldb_getkeyhandle(const sasl_utils_t *utils,
++LIBSASL_API sasldb_handle _sasldb_getkeyhandle(const sasl_utils_t *utils,
+ sasl_conn_t *conn)
+ {
+ const char *path = SASL_DB_PATH;
+@@ -350,7 +350,7 @@
+ return (sasldb_handle)handle;
+ }
+
+-int _sasldb_getnextkey(const sasl_utils_t *utils __attribute__((unused)),
++LIBSASL_API int _sasldb_getnextkey(const sasl_utils_t *utils __attribute__((unused)),
+ sasldb_handle handle, char *out,
+ const size_t max_out, size_t *out_len)
+ {
+@@ -380,7 +380,7 @@
+ return SASL_CONTINUE;
+ }
+
+-int _sasldb_releasekeyhandle(const sasl_utils_t *utils,
++LIBSASL_API int _sasldb_releasekeyhandle(const sasl_utils_t *utils,
+ sasldb_handle handle)
+ {
+ handle_t *dbh = (handle_t *)handle;
+diff -urN a/sasldb/db_none.c b/sasldb/db_none.c
+--- a/sasldb/db_none.c 2014-08-12 22:40:34.276570300 +0100
++++ b/sasldb/db_none.c 2014-08-12 22:40:35.114618300 +0100
+@@ -73,21 +73,21 @@
+ return SASL_FAIL;
+ }
+
+-int _sasl_check_db(const sasl_utils_t *utils,
++LIBSASL_API int _sasl_check_db(const sasl_utils_t *utils,
+ sasl_conn_t *conn)
+ {
+ if(conn) utils->seterror(conn, 0, "No Database Driver");
+ return SASL_FAIL;
+ }
+
+-sasldb_handle _sasldb_getkeyhandle(const sasl_utils_t *utils,
++LIBSASL_API sasldb_handle _sasldb_getkeyhandle(const sasl_utils_t *utils,
+ sasl_conn_t *conn)
+ {
+ if(conn) utils->seterror(conn, 0, "No Database Driver");
+ return NULL;
+ }
+
+-int _sasldb_getnextkey(const sasl_utils_t *utils __attribute__((unused)),
++LIBSASL_API int _sasldb_getnextkey(const sasl_utils_t *utils __attribute__((unused)),
+ sasldb_handle handle __attribute__((unused)),
+ char *out __attribute__((unused)),
+ const size_t max_out __attribute__((unused)),
+@@ -96,7 +96,7 @@
+ return SASL_FAIL;
+ }
+
+-int _sasldb_releasekeyhandle(const sasl_utils_t *utils __attribute__((unused)),
++LIBSASL_API int _sasldb_releasekeyhandle(const sasl_utils_t *utils __attribute__((unused)),
+ sasldb_handle handle __attribute__((unused)))
+ {
+ return SASL_FAIL;
diff --git a/15-MinGW-w64-define-LIBSASL_EXPORTS_eq_1-for-sasldb.patch b/15-MinGW-w64-define-LIBSASL_EXPORTS_eq_1-for-sasldb.patch
new file mode 100644
index 000000000000..9274f70ba2a6
--- /dev/null
+++ b/15-MinGW-w64-define-LIBSASL_EXPORTS_eq_1-for-sasldb.patch
@@ -0,0 +1,33 @@
+--- cyrus-sasl-2.1.27/plugins/Makefile.am.orig 2018-01-31 10:41:15.840628900 +0300
++++ cyrus-sasl-2.1.27/plugins/Makefile.am 2018-01-31 10:41:35.009709100 +0300
+@@ -49,7 +49,7 @@
+ # CURRENT:REVISION:AGE
+ plugin_version = 3:0:0
+
+-AM_CPPFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/lib -I$(top_srcdir)/sasldb -I$(top_srcdir)/common -I$(top_builddir)/include
++AM_CPPFLAGS=-DLIBSASL_EXPORTS=1 -I$(top_srcdir)/include -I$(top_srcdir)/lib -I$(top_srcdir)/sasldb -I$(top_srcdir)/common -I$(top_builddir)/include
+ AM_LDFLAGS = -module -export-dynamic -rpath $(plugindir) -version-info $(plugin_version) -no-undefined
+
+ if BUILD_LIBOBJ
+--- cyrus-sasl-2.1.27/sasldb/Makefile.am.orig 2018-01-31 10:41:57.392403300 +0300
++++ cyrus-sasl-2.1.27/sasldb/Makefile.am 2018-01-31 10:42:05.300229200 +0300
+@@ -44,7 +44,7 @@
+ # Note that this doesn't necessaraly follow the libsasl2 verison info
+ sasl_version = 1:25:0
+
+-AM_CPPFLAGS=-fPIC -I$(top_srcdir)/include -I$(top_builddir)/include @SASL_DB_INC@
++AM_CPPFLAGS=-DLIBSASL_EXPORTS=1 -fPIC -I$(top_srcdir)/include -I$(top_builddir)/include @SASL_DB_INC@
+
+ extra_common_sources = db_none.c db_lmdb.c db_ndbm.c db_gdbm.c db_berkeley.c
+
+--- cyrus-sasl-2.1.27/utils/Makefile.am.orig 2018-01-31 10:42:21.006694100 +0300
++++ cyrus-sasl-2.1.27/utils/Makefile.am 2018-01-31 10:42:52.234410200 +0300
+@@ -89,7 +89,7 @@
+ libsfsasl2_la_LIBADD = sfsasl.lo
+ libsfsasl2_la_LDFLAGS = -version-info 1:0:0 -export-dynamic -rpath $(libdir)
+
+-AM_CPPFLAGS=-I$(top_srcdir)/include -I$(top_builddir)/include @SASL_DB_INC@ -DPLUGINDIR='"${plugindir}"'
++AM_CPPFLAGS=-DLIBSASL_EXPORTS=1 -I$(top_srcdir)/include -I$(top_builddir)/include @SASL_DB_INC@ -DPLUGINDIR='"${plugindir}"'
+
+ EXTRA_DIST = saslpasswd2.8 sasldblistusers2.8 pluginviewer.8 sfsasl.h sfsasl.c smtptest.c testsuite.c pluginviewer.c NTMakefile
+
diff --git a/16-MinGW-w64-define-WIN32_LEAN_AND_MEAN-avoiding-handle_t-redef.patch b/16-MinGW-w64-define-WIN32_LEAN_AND_MEAN-avoiding-handle_t-redef.patch
new file mode 100644
index 000000000000..6a083fe2ee92
--- /dev/null
+++ b/16-MinGW-w64-define-WIN32_LEAN_AND_MEAN-avoiding-handle_t-redef.patch
@@ -0,0 +1,13 @@
+diff -urN a/configure.ac b/configure.ac
+--- a/configure.ac 2014-08-12 22:40:36.914721200 +0100
++++ b/configure.ac 2014-08-12 22:40:37.473753200 +0100
+@@ -1117,6 +1117,9 @@
+ darwin*)
+ AC_ARG_ENABLE(macos-framework, [ --disable-macos-framework disable building and installing replacement SASL2 Framework for MacOS X-provided SASL Framework [[no]]],building_for_macosx=no,building_for_macosx=yes)
+ ;;
++ mingw*)
++AC_DEFINE(WIN32_LEAN_AND_MEAN, 1, [Define to 1, avoids handle_t redefinition.])
++ ;;
+ esac
+ AM_CONDITIONAL(MACOSX, test "$building_for_macosx" = yes)
+ AM_CONDITIONAL(WINDOWS, test "$host_os" = "mingw32")
diff --git a/19-paths-relocation.patch b/19-paths-relocation.patch
new file mode 100644
index 000000000000..207e2880b6e1
--- /dev/null
+++ b/19-paths-relocation.patch
@@ -0,0 +1,147 @@
+diff -Naur cyrus-sasl-2.1.26-orig/m4/varexpand.m4 cyrus-sasl-2.1.26/m4/varexpand.m4
+--- cyrus-sasl-2.1.26-orig/m4/varexpand.m4 1970-01-01 03:00:00.000000000 +0300
++++ cyrus-sasl-2.1.26/m4/varexpand.m4 2014-12-16 00:22:11.487600000 +0300
+@@ -0,0 +1,8 @@
++AC_DEFUN([FULL_EXPAND_VARIABLE], [
++ $1=$2
++ $1=`(
++ test "x$prefix" = xNONE && prefix="$ac_default_prefix"
++ test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
++ eval echo \""[$]$1"\"
++ )`
++])
+diff -Naur cyrus-sasl-2.1.26-orig/configure.ac cyrus-sasl-2.1.26/configure.ac
+--- cyrus-sasl-2.1.26-orig/configure.ac 2014-12-15 23:10:23.125400000 +0300
++++ cyrus-sasl-2.1.26/configure.ac 2014-12-16 00:23:05.167200000 +0300
+@@ -1102,6 +1102,8 @@
+ configdir=$withval,
+ configdir='${plugindir}:${sysconfdir}/sasl2')
+ AC_SUBST(configdir)
++FULL_EXPAND_VARIABLE(sasl_bindir, "$bindir")
++AC_DEFINE_UNQUOTED(BINDIR, "$sasl_bindir", [Runtime executables location])
+
+ dnl look for rc4 libraries. we accept the CMU one or one from openSSL
+ AC_ARG_WITH(rc4, [ --with-rc4 use internal rc4 routines [[yes]] ],
+diff -Naur cyrus-sasl-2.1.26-orig/include/sasl.h cyrus-sasl-2.1.26/include/sasl.h
+--- cyrus-sasl-2.1.26-orig/include/sasl.h 2014-12-15 23:10:22.454600000 +0300
++++ cyrus-sasl-2.1.26/include/sasl.h 2014-12-15 23:43:10.374600000 +0300
+@@ -669,6 +669,8 @@
+ #define SASL_PATH_TYPE_PLUGIN 0
+ #define SASL_PATH_TYPE_CONFIG 1
+
++LIBSASL_API char * sasl_path_relocation(const char *from, const char *to);
++LIBSASL_API char * sasl_pathlist_relocation(const char *from_path, const char *to_path_list);
+ /* a simpler way to set plugin path or configuration file path
+ * without the need to set sasl_getpath_t callback.
+ *
+diff -Naur cyrus-sasl-2.1.26-orig/lib/common.c cyrus-sasl-2.1.26/lib/common.c
+--- cyrus-sasl-2.1.26-orig/lib/common.c 2014-12-15 23:10:22.953800000 +0300
++++ cyrus-sasl-2.1.26/lib/common.c 2014-12-15 23:46:29.514400000 +0300
+@@ -59,6 +59,7 @@
+ #include <saslutil.h>
+ #include <saslplug.h>
+ #include "saslint.h"
++#include "pathtools.h"
+
+ #ifdef HAVE_UNISTD_H
+ #include <unistd.h>
+@@ -64,6 +64,45 @@
+ #include <unistd.h>
+ #endif
+
++char *
++sasl_path_relocation(const char *from, const char *to)
++{
++#if defined(__MINGW32__)
++ char exe_path[PATH_MAX];
++ get_executable_path (NULL, &exe_path[0], sizeof(exe_path)/sizeof(exe_path[0]));
++ if (strrchr (exe_path, '/') != NULL)
++ {
++ strrchr (exe_path, '/')[1] = '\0';
++ }
++ char * rel_to_datadir = get_relative_path (from, to);
++ strcat (exe_path, rel_to_datadir);
++ simplify_path (&exe_path[0]);
++ return malloc_copy_string(exe_path);
++#else
++ return malloc_copy_string(to);
++#endif
++}
++
++char *
++sasl_pathlist_relocation(const char *from_path, const char *to_path_list)
++{
++#if defined(__MINGW32__)
++ static char stored_path[PATH_MAX];
++ static int stored = 0;
++ if (stored == 0)
++ {
++ char const * relocated = get_relocated_path_list(from_path, to_path_list);
++ strncpy (stored_path, relocated, PATH_MAX);
++ stored_path[PATH_MAX-1] = '\0';
++ free ((void *)relocated);
++ stored = 1;
++ }
++ return stored_path;
++#else
++ return (to_path_list);
++#endif
++}
++
+ static const char *implementation_string = "Cyrus SASL";
+
+ #define VSTR0(maj, min, step) #maj "." #min "." #step
+@@ -1585,9 +1625,13 @@
+
+ #if defined(WIN32)
+ /* NB: On Windows platforms this value is always allocated */
++# ifdef __MINGW32__
++ default_plugin_path = sasl_path_relocation(BINDIR, PLUGINDIR);
++# else
+ default_plugin_path = _sasl_get_default_win_path(context,
+ SASL_PLUGIN_PATH_ATTR,
+ PLUGINDIR);
++# endif
+ #else
+ /* NB: On Unix platforms this value is never allocated */
+ path = _sasl_get_default_unix_path(context,
+@@ -1640,9 +1684,13 @@
+
+ #if defined(WIN32)
+ /* NB: On Windows platforms this value is always allocated */
++# ifdef __MINGW32__
++ default_conf_path = sasl_pathlist_relocation(BINDIR, CONFIGDIR);
++# else
+ default_conf_path = _sasl_get_default_win_path(context,
+ SASL_CONF_PATH_ATTR,
+ CONFIGDIR);
++# endif
+ #else
+ /* NB: On Unix platforms this value is never allocated */
+ path = _sasl_get_default_unix_path(context,
+diff -Naur cyrus-sasl-2.1.26-orig/lib/Makefile.am cyrus-sasl-2.1.26/lib/Makefile.am
+--- cyrus-sasl-2.1.26-orig/lib/Makefile.am 2014-12-15 23:10:23.094200000 +0300
++++ cyrus-sasl-2.1.26/lib/Makefile.am 2014-12-15 23:24:10.600800000 +0300
+@@ -62,8 +62,8 @@
+ DLOPEN_C = dlopen.c
+ endif
+
+-common_headers = saslint.h
+-common_sources = auxprop.c canonusr.c checkpw.c client.c common.c config.c external.c md5.c saslutil.c server.c seterror.c $(DLOPEN_C)
++common_headers = saslint.h pathtools.h
++common_sources = auxprop.c canonusr.c checkpw.c client.c common.c config.c external.c md5.c pathtools.c saslutil.c server.c seterror.c $(DLOPEN_C)
+
+ LTLIBOBJS = @LTLIBOBJS@
+ LIB_DOOR= @LIB_DOOR@
+diff -Naur cyrus-sasl-2.1.26-orig/utils/pluginviewer.c cyrus-sasl-2.1.26/utils/pluginviewer.c
+--- cyrus-sasl-2.1.26-orig/utils/pluginviewer.c 2014-12-15 23:10:22.407800000 +0300
++++ cyrus-sasl-2.1.26/utils/pluginviewer.c 2014-12-15 23:45:36.037600000 +0300
+@@ -197,7 +197,7 @@
+ if (searchpath) {
+ *path = searchpath;
+ } else {
+- *path = PLUGINDIR;
++ *path = sasl_path_relocation(BINDIR, PLUGINDIR);
+ }
+
+ return SASL_OK;
diff --git a/20-mingw-tchar.patch b/20-mingw-tchar.patch
new file mode 100644
index 000000000000..9a46ccab68d6
--- /dev/null
+++ b/20-mingw-tchar.patch
@@ -0,0 +1,32 @@
+--- cyrus-sasl-2.1.27.orig/configure.ac 2021-05-04 00:43:26.301737400 +0530
++++ cyrus-sasl-2.1.27/configure.ac 2021-05-04 00:44:14.503209900 +0530
+@@ -1121,6 +1121,8 @@
+ ;;
+ mingw*)
+ AC_DEFINE(WIN32_LEAN_AND_MEAN, 1, [Define to 1, avoids handle_t redefinition.])
++AC_DEFINE(_UNICODE, [], [Enable unicode environment.])
++AC_DEFINE(UNICODE, [], [Enable unicode environment.])
+ ;;
+ esac
+ AM_CONDITIONAL(MACOSX, test "$building_for_macosx" = yes)
+@@ -1452,6 +1454,7 @@
+ # endif
+ #else /* WIN32 */
+ # include <winsock2.h>
++# include <tchar.h>
+ #endif /* WIN32 */
+ #include <string.h>
+
+@@ -1524,9 +1527,9 @@
+ #endif
+
+ #ifdef WIN32
+-#define SASL_ROOT_KEY "SOFTWARE\\Carnegie Mellon\\Project Cyrus\\SASL Library"
+-#define SASL_PLUGIN_PATH_ATTR "SearchPath"
+-#define SASL_CONF_PATH_ATTR "ConfFile"
++#define SASL_ROOT_KEY _T("SOFTWARE\\Carnegie Mellon\\Project Cyrus\\SASL Library")
++#define SASL_PLUGIN_PATH_ATTR _T("SearchPath")
++#define SASL_CONF_PATH_ATTR _T("ConfFile")
+
+ #include <windows.h>
+ inline static unsigned int sleep(unsigned int seconds) {
diff --git a/21-fix-getopt-guard.patch b/21-fix-getopt-guard.patch
new file mode 100644
index 000000000000..ff7fc3d5bb31
--- /dev/null
+++ b/21-fix-getopt-guard.patch
@@ -0,0 +1,18 @@
+--- cyrus-sasl-2.1.27/lib/saslutil.c.orig 2020-01-21 13:02:37.317323500 +0300
++++ cyrus-sasl-2.1.27/lib/saslutil.c 2020-01-21 13:03:14.353045400 +0300
+@@ -775,6 +775,7 @@
+ return (int)*pArgString; /* return the letter that matched */
+ }
+ }
++#endif /* WIN32 && !__MINGW64_VERSION_MAJOR */
+
+ #ifndef PASSWORD_MAX
+ # define PASSWORD_MAX 255
+@@ -798,7 +799,3 @@
+ fprintf(stderr, "\n"); (void) fflush(stderr);
+ return(pbuf);
+ }
+-
+-
+-
+-#endif /* WIN32 */
diff --git a/22-autoconf-prevent-full-path-resolution.patch b/22-autoconf-prevent-full-path-resolution.patch
new file mode 100644
index 000000000000..cef3d1c0bcc1
--- /dev/null
+++ b/22-autoconf-prevent-full-path-resolution.patch
@@ -0,0 +1,56 @@
+diff --unified -r cyrus-sasl-2.1.27.orig/configure.ac cyrus-sasl-2.1.27/configure.ac
+--- cyrus-sasl-2.1.27.orig/configure.ac 2018-10-09 20:28:04.000000000 +0530
++++ cyrus-sasl-2.1.27/configure.ac 2021-05-03 23:19:32.289742100 +0530
+@@ -1095,13 +1095,16 @@
+ be found [[LIBDIR/sasl2]] ],
+ plugindir=$withval,
+ plugindir='${libdir}/sasl2')
++AC_DEFINE_UNQUOTED(PLUGINDIR, "$plugindir", [Runtime plugin location])
+ AC_SUBST(plugindir)
+
+ AC_ARG_WITH(configdir, [ --with-configdir=DIR set the directory where config files will
+ be found [PLUGINDIR:SYSCONFDIR/sasl2] ],
+ configdir=$withval,
+ configdir='${plugindir}:${sysconfdir}/sasl2')
++AC_DEFINE_UNQUOTED(CONFIGDIR, "$configdir", [Runtime config file location])
+ AC_SUBST(configdir)
++
+ FULL_EXPAND_VARIABLE(sasl_bindir, "$bindir")
+ AC_DEFINE_UNQUOTED(BINDIR, "$sasl_bindir", [Runtime executables location])
+
+diff --unified -r cyrus-sasl-2.1.27.orig/lib/Makefile.am cyrus-sasl-2.1.27/lib/Makefile.am
+--- cyrus-sasl-2.1.27.orig/lib/Makefile.am 2018-10-05 20:10:16.000000000 +0530
++++ cyrus-sasl-2.1.27/lib/Makefile.am 2021-05-03 23:20:45.644604600 +0530
+@@ -46,7 +46,7 @@
+ sasl_version = 3:0:0
+
+ AM_CPPFLAGS=-DLIBSASL_EXPORTS=1 -I$(top_srcdir)/include -I$(top_srcdir)/plugins \
+- -I$(top_builddir)/include -I$(top_srcdir)/sasldb -I$(top_srcdir)/common -DCONFIGDIR='"${configdir}"' -DPLUGINDIR='"${plugindir}"'
++ -I$(top_builddir)/include -I$(top_srcdir)/sasldb -I$(top_srcdir)/common
+ PLUGIN_COMMON_OBJS = $(top_builddir)/common/libplugin_common.la
+
+ EXTRA_DIST = windlopen.c dlopen.c staticopen.h NTMakefile
+diff --unified -r cyrus-sasl-2.1.27.orig/sample/Makefile.am cyrus-sasl-2.1.27/sample/Makefile.am
+--- cyrus-sasl-2.1.27.orig/sample/Makefile.am 2018-10-05 20:10:16.000000000 +0530
++++ cyrus-sasl-2.1.27/sample/Makefile.am 2021-05-03 23:21:06.965457200 +0530
+@@ -42,7 +42,7 @@
+ #
+ ################################################################
+
+-AM_CPPFLAGS=-I$(top_srcdir)/include -DPLUGINDIR='"${plugindir}"'
++AM_CPPFLAGS=-I$(top_srcdir)/include
+
+ noinst_PROGRAMS = client server http_digest_client
+ EXTRA_PROGRAMS = sample-client sample-server
+diff --unified -r cyrus-sasl-2.1.27.orig/utils/Makefile.am cyrus-sasl-2.1.27/utils/Makefile.am
+--- cyrus-sasl-2.1.27.orig/utils/Makefile.am 2018-10-05 20:10:16.000000000 +0530
++++ cyrus-sasl-2.1.27/utils/Makefile.am 2021-05-03 23:21:35.991353300 +0530
+@@ -89,7 +89,7 @@
+ libsfsasl2_la_LIBADD = sfsasl.lo
+ libsfsasl2_la_LDFLAGS = -version-info 1:0:0 -export-dynamic -rpath $(libdir)
+
+-AM_CPPFLAGS=-DLIBSASL_EXPORTS=1 -I$(top_srcdir)/include -I$(top_builddir)/include @SASL_DB_INC@ -DPLUGINDIR='"${plugindir}"'
++AM_CPPFLAGS=-DLIBSASL_EXPORTS=1 -I$(top_srcdir)/include -I$(top_builddir)/include @SASL_DB_INC@
+
+ EXTRA_DIST = saslpasswd2.8 sasldblistusers2.8 pluginviewer.8 sfsasl.h sfsasl.c smtptest.c testsuite.c pluginviewer.c NTMakefile
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..77f84e286548
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,174 @@
+# Maintainer: Ilya Basin <basinilya at gmail dot com>
+# https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-cyrus-sasl
+
+# Contributor: Alexey Pavlov <alexpux@gmail.com>
+# Contributor: Ray Donnelly <mingw.android@gmail.com>
+# Contributor: Renato Silva <br.renatosilva@gmail.com>
+
+# There's an ugliness issue in cyrus-sasl's build system.
+# It builds libsasl2.dll with some compat objects, somehow
+# gotten from saslauthd/Makefile.am?! but these files -
+# getaddrinfo.c, getnameinfo.c (and one that doesn't ever
+# get built, snprintf.c) depend on ws2_32 on Windows.
+# The plugins need these objects too, so they are LN_S'ed
+# as COMPAT_OBJS and that's added to plugins/Makefile.am:
+# lib{plain,anonymous,kerberos4...}_la_{DEPENDENCIES,LIBADD}
+# .. problem with doing it this way is that the ws2_32
+# (encoded into LIB_SOCKET) dependency needs to be specified
+# repeatedly for each one ..
+# Instead these compat objects should be linked into a
+# convenience libtool library (.a compiled with -fPIC) that
+# carries the ws2_32 dependency with it, and this libtool
+# library should be added as a dependency to each of the
+# plugins. I've not fixed this because I've not got enough
+# libtool experience to do it yet so instead 12-MinGW-w64..patch
+# adds LIB_SOCKET all over the place in plugins/Makefile.am
+
+provides=(mingw-w64-libsasl)
+conflicts=(mingw-w64-libsasl)
+
+_architectures='i686-w64-mingw32 x86_64-w64-mingw32'
+MINGW_PACKAGE_PREFIX=mingw-w64
+_adapt_msys2() {
+ MINGW_CHOST=${_arch:?}
+ MINGW_PREFIX=/usr/${_arch:?}
+ CARCH=${_arch%%-*}
+}
+
+_realname=cyrus-sasl
+pkgbase=mingw-w64-${_realname}
+pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
+pkgver=2.1.27
+pkgrel=1
+pkgdesc="Cyrus Simple Authentication Service Layer (SASL) library (mingw-w64)"
+arch=('any')
+mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
+url="https://www.cyrusimap.org/sasl/"
+license=('custom')
+depends=("${MINGW_PACKAGE_PREFIX}-gdbm"
+ "${MINGW_PACKAGE_PREFIX}-openssl"
+ "${MINGW_PACKAGE_PREFIX}-sqlite3")
+options=('emptydirs' !strip !buildflags !makeflags)
+source=(https://github.com/cyrusimap/${_realname}/releases/download/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.gz{,.sig}
+ pathtools.c
+ pathtools.h
+ 02-exeext.patch
+ 03-fix-plugins.patch
+ 04-manpage-paths.patch
+ 14-MinGW-w64-add-LIBSASL_API-to-function-definitions.patch
+ 15-MinGW-w64-define-LIBSASL_EXPORTS_eq_1-for-sasldb.patch
+ 16-MinGW-w64-define-WIN32_LEAN_AND_MEAN-avoiding-handle_t-redef.patch
+ 19-paths-relocation.patch
+ 20-mingw-tchar.patch
+ 21-fix-getopt-guard.patch
+ with-sqlite3-makemd5.patch
+ 22-autoconf-prevent-full-path-resolution.patch)
+sha256sums=('26866b1549b00ffd020f188a43c258017fa1c382b3ddadd8201536f72efb05d5'
+ 'SKIP'
+ '6f1016e6647b6340fdceefaf24ff391f4c0ea3c785ddf70c9794ca2356797888'
+ '6ce4dcf4ef6c4bce48dbcb6f1b5226baf79f74ac76719fb0c06419a0aadb37a3'
+ '0d0220f721b07f821e14f00c04250c2243620301200f825e7f0532b581d63a7d'
+ '62fca7407d288e021fac6fed47d8a94ef2775c257ddcb79071428fe7719485f5'
+ 'b8bedacab5fc992eb2afd259ce2e898291d2bec685030108be3f51e6ce30977c'
+ '795196a9db0c8155d59c08dcbb0df15dfe7bb4eb47b30df511649573ac59b39f'
+ '148c2062d22011f731ad93fb603cde9c519e73322c89add0408772c434c6bf17'
+ 'e101e1bd3ee03650e89e05c18d5f699d2f69aecc4f7aac4b11db2d1755783c5c'
+ 'f10b41804eeb4c77cb3b061c95c5c71d5624faa17925e5e04e683f4bd6c2bee7'
+ '57b1b40017fa2a3fb189deedc01959673ed96cc01e088fd85ae0d59e1e13f25f'
+ 'f51412367d893cb4c2e4ee2ec76a6a641abaaf6d3086af93a9b579a8d0ce26c5'
+ SKIP
+ '8cca4435b2d8bc5c04490bd16092bc9c5fcf3eb5c113778674b8393342302c65')
+validpgpkeys=('829F339F8C296FE80F409D93E3D7C118C7B9F46A') # Partha Susarla <mail@spartha.org>
+
+prepare() {
+ test ! -d "${startdir}/../mingw-w64-pathtools" || {
+ cmp "${startdir}/../mingw-w64-pathtools/pathtools.c" "${srcdir}/pathtools.c" &&
+ cmp "${startdir}/../mingw-w64-pathtools/pathtools.h" "${srcdir}/pathtools.h"
+ } || exit 1
+
+ cd "${srcdir}/${_realname}-${pkgver}"
+ cp -fHv "${srcdir}"/pathtools.[ch] lib/
+
+ patch -p1 -i ${srcdir}/02-exeext.patch
+ patch -p1 -i ${srcdir}/03-fix-plugins.patch
+ patch -p1 -i ${srcdir}/04-manpage-paths.patch
+ patch -p1 -i ${srcdir}/14-MinGW-w64-add-LIBSASL_API-to-function-definitions.patch
+ patch -p1 -i ${srcdir}/15-MinGW-w64-define-LIBSASL_EXPORTS_eq_1-for-sasldb.patch
+ patch -p1 -i ${srcdir}/16-MinGW-w64-define-WIN32_LEAN_AND_MEAN-avoiding-handle_t-redef.patch
+ patch -p1 -i ${srcdir}/19-paths-relocation.patch
+ patch -p1 -i ${srcdir}/20-mingw-tchar.patch
+ patch -p1 -i ${srcdir}/21-fix-getopt-guard.patch
+
+ patch -p1 -i ${srcdir}/with-sqlite3-makemd5.patch
+
+ # Partially revert upstream b017b437bef7b329097945172b8516d434754d41 commit.
+ patch -p1 -i ${srcdir}/22-autoconf-prevent-full-path-resolution.patch
+
+ # For clang
+ sed -i "s/-fPIC //g" common/Makefile.am sasldb/Makefile.am
+
+ autoreconf -fiv
+ cp -f ${srcdir}/${_realname}-${pkgver}/win32/include/md5global.h ${srcdir}/${_realname}-${pkgver}/include/md5global.h
+}
+
+build() {
+
+ for _arch in ${_architectures}; do
+ _adapt_msys2
+ pushd .
+
+ [[ -d ${srcdir}/build-${CARCH} ]] && rm -rf ${srcdir}/build-${CARCH}
+ mkdir -p "${srcdir}/build-${CARCH}"
+ cd "${srcdir}/build-${CARCH}"
+
+ # Useful ref:
+ # https://fedorapeople.org/cgit/elmarco/public_git/mingw32-cyrus-sasl.git/tree/mingw32-cyrus-sasl.spec
+ # --oldincludedir=${MINGW_PREFIX}/include is so that /usr/include isn't added by default.
+ # --enable-sql seems to have problems with <mysql.h> not existing, I thought it would be a part of sqlite.
+ # --enable-sql
+ # --without-saslauthd because it needs sockaddr_un.
+
+ # We disable OpenSSL (--without-openssl --without-des) so that applications
+ # with licenses incompatible with OpenSSL (such as GPL applications) do not
+ # end up linked with OpenSSL if they use and redistribute Cyrus SASL outside
+ # MSYS2. See these links:
+ #
+ # * https://www.openssl.org/support/faq.html#LEGAL2
+ # * https://en.wikipedia.org/wiki/OpenSSL#Licensing
+
+ ${_arch}-configure \
+ --with-configdir=${MINGW_PREFIX}/etc/sasl2:${MINGW_PREFIX}/etc/sasl:${MINGW_PREFIX}/lib/sasl2 \
+ --with-plugindir=${MINGW_PREFIX}/lib/sasl2 \
+ --disable-static --enable-shared \
+ --with-sqlite3=${MINGW_PREFIX} \
+ --disable-ldapdb \
+ --oldincludedir=${MINGW_PREFIX}/include \
+ --without-saslauthd \
+ --without-pwcheck \
+ --without-des \
+ --without-authdaemond \
+ --with-dblib=gdbm \
+ --disable-sample \
+ ../${_realname}-${pkgver}
+
+ make
+
+ popd
+ done
+}
+
+package() {
+ for _arch in ${_architectures}; do
+ _adapt_msys2
+ pushd .
+
+ local _plugindir=${MINGW_PREFIX}/lib/sasl2
+
+ cd "${srcdir}/build-${CARCH}"
+ make DESTDIR="${pkgdir}" install sasldir=${_plugindir}
+
+ install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
+
+ popd
+ done
+}
diff --git a/pathtools.c b/pathtools.c
new file mode 100644
index 000000000000..cecc85aa0ccf
--- /dev/null
+++ b/pathtools.c
@@ -0,0 +1,578 @@
+/*
+ .Some useful path tools.
+ .ASCII only for now.
+ .Written by Ray Donnelly in 2014.
+ .Licensed under CC0 (and anything.
+ .else you need to license it under).
+ .No warranties whatsoever.
+ .email: <mingw.android@gmail.com>.
+ */
+
+#if defined(__APPLE__)
+#include <stdlib.h>
+#else
+#include <malloc.h>
+#endif
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#if defined(__linux__) || defined(__CYGWIN__) || defined(__MSYS__)
+#include <alloca.h>
+#endif
+#include <unistd.h>
+
+/* If you don't define this, then get_executable_path()
+ can only use argv[0] which will often not work well */
+#define IMPLEMENT_SYS_GET_EXECUTABLE_PATH
+
+#if defined(IMPLEMENT_SYS_GET_EXECUTABLE_PATH)
+#if defined(__linux__) || defined(__CYGWIN__) || defined(__MSYS__)
+/* Nothing needed, unistd.h is enough. */
+#elif defined(__APPLE__)
+#include <mach-o/dyld.h>
+#elif defined(_WIN32)
+#define WIN32_MEAN_AND_LEAN
+#include <windows.h>
+#include <psapi.h>
+#endif
+#endif /* defined(IMPLEMENT_SYS_GET_EXECUTABLE_PATH) */
+
+#include "pathtools.h"
+
+char *
+malloc_copy_string(char const * original)
+{
+ char * result = (char *) malloc (sizeof (char*) * strlen (original)+1);
+ if (result != NULL)
+ {
+ strcpy (result, original);
+ }
+ return result;
+}
+
+void
+sanitise_path(char * path)
+{
+ size_t path_size = strlen (path);
+
+ /* Replace any '\' with '/' */
+ char * path_p = path;
+ while ((path_p = strchr (path_p, '\\')) != NULL)
+ {
+ *path_p = '/';
+ }
+ /* Replace any '//' with '/' */
+ path_p = path + !!*path; /* skip first character, if any, to handle UNC paths correctly */
+ while ((path_p = strstr (path_p, "//")) != NULL)
+ {
+ memmove (path_p, path_p + 1, path_size--);
+ }
+ return;
+}
+
+char *
+get_relative_path(char const * from_in, char const * to_in)
+{
+ size_t from_size = (from_in == NULL) ? 0 : strlen (from_in);
+ size_t to_size = (to_in == NULL) ? 0 : strlen (to_in);
+ size_t max_size = (from_size + to_size) * 2 + 4;
+ char * scratch_space = (char *) alloca (from_size + 1 + to_size + 1 + max_size + max_size);
+ char * from;
+ char * to;
+ char * common_part;
+ char * result;
+ size_t count;
+
+ /* No to, return "./" */
+ if (to_in == NULL)
+ {
+ return malloc_copy_string ("./");
+ }
+
+ /* If alloca failed or no from was given return a copy of to */
+ if ( from_in == NULL
+ || scratch_space == NULL )
+ {
+ return malloc_copy_string (to_in);
+ }
+
+ from = scratch_space;
+ strcpy (from, from_in);
+ to = from + from_size + 1;
+ strcpy (to, to_in);
+ common_part = to + to_size + 1;
+ result = common_part + max_size;
+ simplify_path (from);
+ simplify_path (to);
+
+ result[0] = '\0';
+
+ size_t match_size_dirsep = 0; /* The match size up to the last /. Always wind back to this - 1 */
+ size_t match_size = 0; /* The running (and final) match size. */
+ size_t largest_size = (from_size > to_size) ? from_size : to_size;
+ int to_final_is_slash = (to[to_size-1] == '/') ? 1 : 0;
+ char from_c;
+ char to_c;
+ for (match_size = 0; match_size < largest_size; ++match_size)
+ {
+ /* To simplify the logic, always pretend the strings end with '/' */
+ from_c = (match_size < from_size) ? from[match_size] : '/';
+ to_c = (match_size < to_size) ? to[match_size] : '/';
+
+ if (from_c != to_c)
+ {
+ if (from_c != '\0' || to_c != '\0')
+ {
+ match_size = match_size_dirsep;
+ }
+ break;
+ }
+ else if (from_c == '/')
+ {
+ match_size_dirsep = match_size;
+ }
+ }
+ strncpy (common_part, from, match_size);
+ common_part[match_size] = '\0';
+ from += match_size;
+ to += match_size;
+ size_t ndotdots = 0;
+ char const* from_last = from + strlen(from) - 1;
+ while ((from = strchr (from, '/')) && from != from_last)
+ {
+ ++ndotdots;
+ ++from;
+ }
+ for (count = 0; count < ndotdots; ++count)
+ {
+ strcat(result, "../");
+ }
+ if (strlen(to) > 0)
+ {
+ strcat(result, to+1);
+ }
+ /* Make sure that if to ends with '/' result does the same, and
+ vice-versa. */
+ size_t size_result = strlen(result);
+ if ((to_final_is_slash == 1)
+ && (!size_result || result[size_result-1] != '/'))
+ {
+ strcat (result, "/");
+ }
+ else if (!to_final_is_slash
+ && size_result && result[size_result-1] == '/')
+ {
+ result[size_result-1] = '\0';
+ }
+
+ return malloc_copy_string (result);
+}
+
+void
+simplify_path(char * path)
+{
+ ssize_t n_toks = 1; /* in-case we need an empty initial token. */
+ ssize_t i, j;
+ size_t tok_size;
+ size_t in_size = strlen (path);
+ int it_ended_with_a_slash = (path[in_size - 1] == '/') ? 1 : 0;
+ char * result = path;
+ if (path[0] == '/' && path[1] == '/') {
+ /* preserve UNC path */
+ path++;
+ in_size--;
+ result++;
+ }
+ sanitise_path(result);
+ char * result_p = result;
+
+ do
+ {
+ ++n_toks;
+ ++result_p;
+ } while ((result_p = strchr (result_p, '/')) != NULL);
+
+ result_p = result;
+ char const ** toks = (char const **) alloca (sizeof (char const*) * n_toks);
+ n_toks = 0;
+ do
+ {
+ if (result_p > result)
+ {
+ *result_p++ = '\0';
+ }
+ else if (*result_p == '/')
+ {
+ /* A leading / creates an empty initial token. */
+ toks[n_toks++] = result_p;
+ *result_p++ = '\0';
+ }
+ toks[n_toks++] = result_p;
+ } while ((result_p = strchr (result_p, '/')) != NULL);
+
+ /* Remove all non-leading '.' and any '..' we can match
+ with an earlier forward path (i.e. neither '.' nor '..') */
+ for (i = 1; i < n_toks; ++i)
+ {
+ int removals[2] = { -1, -1 };
+ if ( strcmp (toks[i], "." ) == 0)
+ {
+ removals[0] = i;
+ }
+ else if ( strcmp (toks[i], ".." ) == 0)
+ {
+ /* Search backwards for a forward path to collapse.
+ If none are found then the .. also stays. */
+ for (j = i - 1; j > -1; --j)
+ {
+ if ( strcmp (toks[j], "." )
+ && strcmp (toks[j], ".." ) )
+ {
+ removals[0] = j;
+ removals[1] = i;
+ break;
+ }
+ }
+ }
+ for (j = 0; j < 2; ++j)
+ {
+ if (removals[j] >= 0) /* Can become -2 */
+ {
+ --n_toks;
+ memmove (&toks[removals[j]], &toks[removals[j]+1], (n_toks - removals[j])*sizeof (char*));
+ --i;
+ if (!j)
+ {
+ --removals[1];
+ }
+ }
+ }
+ }
+ result_p = result;
+ for (i = 0; i < n_toks; ++i)
+ {
+ tok_size = strlen(toks[i]);
+ memmove (result_p, toks[i], tok_size);
+ result_p += tok_size;
+ if ((!i || tok_size) && ((i < n_toks - 1) || it_ended_with_a_slash == 1))
+ {
+ *result_p = '/';
+ ++result_p;
+ }
+ }
+ *result_p = '\0';
+}
+
+/* Returns actual_to by calculating the relative path from -> to and
+ applying that to actual_from. An assumption that actual_from is a
+ dir is made, and it may or may not end with a '/' */
+char const *
+get_relocated_path (char const * from, char const * to, char const * actual_from)
+{
+ char const * relative_from_to = get_relative_path (from, to);
+ char * actual_to = (char *) malloc (strlen(actual_from) + 2 + strlen(relative_from_to));
+ return actual_to;
+}
+
+int
+get_executable_path(char const * argv0, char * result, ssize_t max_size)
+{
+ char * system_result = (char *) alloca (max_size);
+ ssize_t system_result_size = -1;
+ ssize_t result_size = -1;
+
+ if (system_result != NULL)
+ {
+#if defined(IMPLEMENT_SYS_GET_EXECUTABLE_PATH)
+#if defined(__linux__) || defined(__CYGWIN__) || defined(__MSYS__)
+ system_result_size = readlink("/proc/self/exe", system_result, max_size);
+#elif defined(__APPLE__)
+ uint32_t bufsize = (uint32_t)max_size;
+ if (_NSGetExecutablePath(system_result, &bufsize) == 0)
+ {
+ system_result_size = (ssize_t)bufsize;
+ }
+#elif defined(_WIN32)
+ unsigned long bufsize = (unsigned long)max_size;
+ system_result_size = GetModuleFileNameA(NULL, system_result, bufsize);
+ if (system_result_size == 0 || system_result_size == (ssize_t)bufsize)
+ {
+ /* Error, possibly not enough space. */
+ system_result_size = -1;
+ }
+ else
+ {
+ /* Early conversion to unix slashes instead of more changes
+ everywhere else .. */
+ char * winslash;
+ system_result[system_result_size] = '\0';
+ while ((winslash = strchr (system_result, '\\')) != NULL)
+ {
+ *winslash = '/';
+ }
+ }
+#else
+#warning "Don't know how to get executable path on this system"
+#endif
+#endif /* defined(IMPLEMENT_SYS_GET_EXECUTABLE_PATH) */
+ }
+ /* Use argv0 as a default in-case of failure */
+ if (system_result_size != -1)
+ {
+ strncpy (result, system_result, system_result_size);
+ result[system_result_size] = '\0';
+ }
+ else
+ {
+ if (argv0 != NULL)
+ {
+ strncpy (result, argv0, max_size);
+ result[max_size-1] = '\0';
+ }
+ else
+ {
+ result[0] = '\0';
+ }
+ }
+ result_size = strlen (result);
+ return result_size;
+}
+
+#if defined(_WIN32)
+int
+get_dll_path(char * result, unsigned long max_size)
+{
+ HMODULE handle;
+ char * p;
+ int ret;
+
+ if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
+ GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ (LPCSTR) &get_dll_path, &handle))
+ {
+ return -1;
+ }
+
+ ret = GetModuleFileNameA(handle, result, max_size);
+ if (ret == 0 || ret == (int)max_size)
+ {
+ return -1;
+ }
+
+ /* Early conversion to unix slashes instead of more changes
+ everywhere else .. */
+ result[ret] = '\0';
+ p = result - 1;
+ while ((p = strchr (p + 1, '\\')) != NULL)
+ {
+ *p = '/';
+ }
+
+ return ret;
+}
+#endif
+
+char const *
+strip_n_prefix_folders(char const * path, size_t n)
+{
+ if (path == NULL)
+ {
+ return NULL;
+ }
+
+ if (path[0] != '/')
+ {
+ return path;
+ }
+
+ char const * last = path;
+ while (n-- && path != NULL)
+ {
+ last = path;
+ path = strchr (path + 1, '/');
+ }
+ return (path == NULL) ? last : path;
+}
+
+void
+strip_n_suffix_folders(char * path, size_t n)
+{
+ if (path == NULL)
+ {
+ return;
+ }
+ while (n--)
+ {
+ if (strrchr (path + 1, '/'))
+ {
+ *strrchr (path + 1, '/') = '\0';
+ }
+ else
+ {
+ return;
+ }
+ }
+ return;
+}
+
+size_t
+split_path_list(char const * path_list, char split_char, char *** arr)
+{
+ size_t path_count;
+ size_t path_list_size;
+ char const * path_list_p;
+
+ path_list_p = path_list;
+ if (path_list == NULL || path_list[0] == '\0')
+ {
+ return 0;
+ }
+ path_list_size = strlen (path_list);
+
+ path_count = 0;
+ do
+ {
+ ++path_count;
+ ++path_list_p;
+ }
+ while ((path_list_p = strchr (path_list_p, split_char)) != NULL);
+
+ /* allocate everything in one go. */
+ char * all_memory = (char *) malloc (sizeof (char *) * path_count + strlen(path_list) + 1);
+ if (all_memory == NULL)
+ return 0;
+ *arr = (char **)all_memory;
+ all_memory += sizeof (char *) * path_count;
+
+ path_count = 0;
+ path_list_p = path_list;
+ char const * next_path_list_p = 0;
+ do
+ {
+ next_path_list_p = strchr (path_list_p, split_char);
+ if (next_path_list_p != NULL)
+ {
+ ++next_path_list_p;
+ }
+ size_t this_size = (next_path_list_p != NULL)
+ ? next_path_list_p - path_list_p - 1
+ : &path_list[path_list_size] - path_list_p;
+ memcpy (all_memory, path_list_p, this_size);
+ all_memory[this_size] = '\0';
+ (*arr)[path_count++] = all_memory;
+ all_memory += this_size + 1;
+ } while ((path_list_p = next_path_list_p) != NULL);
+
+ return path_count;
+}
+
+char *
+get_relocated_path_list(char const * from, char const * to_path_list)
+{
+ char exe_path[MAX_PATH];
+ char * temp;
+ get_executable_path (NULL, &exe_path[0], sizeof (exe_path) / sizeof (exe_path[0]));
+ if ((temp = strrchr (exe_path, '/')) != NULL)
+ {
+ temp[1] = '\0';
+ }
+
+ char **arr = NULL;
+ /* Ask Alexey why he added this. Are we not 100% sure
+ that we're dealing with unix paths here? */
+ char split_char = ':';
+ if (strchr (to_path_list, ';'))
+ {
+ split_char = ';';
+ }
+ size_t count = split_path_list (to_path_list, split_char, &arr);
+ int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */
+ size_t exe_path_size = strlen (exe_path);
+ size_t i;
+ /* Space required is:
+ count * (exe_path_size + strlen (rel_to_datadir))
+ rel_to_datadir upper bound is:
+ (count * strlen (from)) + (3 * num_slashes (from))
+ + strlen(arr[i]) + 1.
+ .. pathalogically num_slashes (from) is strlen (from)
+ (from = ////////) */
+ size_t space_required = (count * (exe_path_size + 4 * strlen (from))) + count - 1;
+ for (i = 0; i < count; ++i)
+ {
+ space_required += strlen (arr[i]);
+ }
+ char * scratch = (char *) alloca (space_required);
+ if (scratch == NULL)
+ return NULL;
+ for (i = 0; i < count; ++i)
+ {
+ char * rel_to_datadir = get_relative_path (from, arr[i]);
+ scratch[0] = '\0';
+ arr[i] = scratch;
+ strcat (scratch, exe_path);
+ strcat (scratch, rel_to_datadir);
+ simplify_path (arr[i]);
+ size_t arr_i_size = strlen (arr[i]);
+ result_size += arr_i_size;
+ scratch = arr[i] + arr_i_size + 1;
+ }
+ char * result = (char *) malloc (result_size);
+ if (result == NULL)
+ {
+ return NULL;
+ }
+ result[0] = '\0';
+ for (i = 0; i < count; ++i)
+ {
+ strcat (result, arr[i]);
+ if (i != count-1)
+ {
+#if defined(_WIN32)
+ strcat (result, ";");
+#else
+ strcat (result, ":");
+#endif
+ }
+ }
+ free ((void*)arr);
+ return result;
+}
+
+char *
+single_path_relocation(const char *from, const char *to)
+{
+#if defined(__MINGW32__)
+ char exe_path[PATH_MAX];
+ get_executable_path (NULL, &exe_path[0], sizeof(exe_path)/sizeof(exe_path[0]));
+ if (strrchr (exe_path, '/') != NULL)
+ {
+ strrchr (exe_path, '/')[1] = '\0';
+ }
+ char * rel_to_datadir = get_relative_path (from, to);
+ strcat (exe_path, rel_to_datadir);
+ simplify_path (&exe_path[0]);
+ return malloc_copy_string(exe_path);
+#else
+ return malloc_copy_string(to);
+#endif
+}
+
+char *
+pathlist_relocation(const char *from_path, const char *to_path_list)
+{
+#if defined(__MINGW32__)
+ static char stored_path[PATH_MAX];
+ static int stored = 0;
+ if (stored == 0)
+ {
+ char const * relocated = get_relocated_path_list(from_path, to_path_list);
+ strncpy (stored_path, relocated, PATH_MAX);
+ stored_path[PATH_MAX-1] = '\0';
+ free ((void *)relocated);
+ stored = 1;
+ }
+ return stored_path;
+#else
+ return (to_path_list);
+#endif
+}
diff --git a/pathtools.h b/pathtools.h
new file mode 100644
index 000000000000..b01fab00673e
--- /dev/null
+++ b/pathtools.h
@@ -0,0 +1,57 @@
+/*
+ .Some useful path tools.
+ .ASCII only for now.
+ .Written by Ray Donnelly in 2014.
+ .Licensed under CC0 (and anything.
+ .else you need to license it under).
+ .No warranties whatsoever.
+ .email: <mingw.android@gmail.com>.
+ */
+
+#ifndef PATHTOOLS_H
+#define PATHTOOLS_H
+
+#include <unistd.h>
+#if defined(__APPLE__)
+#include <stdlib.h>
+#else
+#include <malloc.h>
+#endif
+#include <stdio.h>
+
+char * malloc_copy_string(char const * original);
+
+/* In-place replaces any '\' with '/' and any '//' with '/' */
+void sanitise_path(char * path);
+
+/* Uses a host OS specific function to determine the path of the executable,
+ if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */
+int get_executable_path(char const * argv0, char * result, ssize_t max_size);
+
+#if defined(_WIN32)
+int get_dll_path(char * result, unsigned long max_size);
+#endif
+
+/* Where possible, in-place removes occourances of '.' and 'path/..' */
+void simplify_path(char * path);
+
+/* Allocates (via malloc) and returns the path to get from from to to. */
+char * get_relative_path(char const * from, char const * to);
+
+size_t split_path_list(char const * path_list, char split_char, char *** arr);
+
+/* Advances path along by the amount that removes n prefix folders. */
+char const *
+strip_n_prefix_folders(char const * path, size_t n);
+
+/* NULL terminates path to remove n suffix folders. */
+void
+strip_n_suffix_folders(char * path, size_t n);
+
+char const * get_relocated_path (char const * from, char const * to, char const * actual_from);
+char * get_relocated_path_list(char const * from, char const * to_path_list);
+
+char * single_path_relocation(const char *from, const char *to);
+char * pathlist_relocation(const char *from_path, const char *to_path_list);
+
+#endif /* PATHTOOLS_H */
diff --git a/with-sqlite3-makemd5.patch b/with-sqlite3-makemd5.patch
new file mode 100644
index 000000000000..df1757f3b968
--- /dev/null
+++ b/with-sqlite3-makemd5.patch
@@ -0,0 +1,10 @@
+--- cyrus-sasl-2.1.27/include/Makefile.am.old 2021-12-06 20:28:13.897877877 +0300
++++ cyrus-sasl-2.1.27/include/Makefile.am 2021-12-06 20:29:17.361859040 +0300
+@@ -53,6 +53,7 @@
+
+ makemd5$(BUILD_EXEEXT) $(makemd5_OBJECTS): CC=$(CC_FOR_BUILD)
+ makemd5$(BUILD_EXEEXT) $(makemd5_OBJECTS): CFLAGS=$(CFLAGS_FOR_BUILD)
++makemd5$(BUILD_EXEEXT) $(makemd5_OBJECTS): CPPFLAGS=$(CPPFLAGS_FOR_BUILD)
+ makemd5$(BUILD_EXEEXT): LDFLAGS=$(LDFLAGS_FOR_BUILD)
+
+ md5global.h: makemd5$(BUILD_EXEEXT) Makefile