ASR_BASE
Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/external/subpack/mail/sendmail/patches/010-enable-nonroot-install.patch b/external/subpack/mail/sendmail/patches/010-enable-nonroot-install.patch
new file mode 100644
index 0000000..6093b6d
--- /dev/null
+++ b/external/subpack/mail/sendmail/patches/010-enable-nonroot-install.patch
@@ -0,0 +1,15 @@
+--- a/cf/cf/Makefile
++++ b/cf/cf/Makefile
+@@ -80,10 +80,10 @@ install:
+ install-cf: install-sendmail-cf install-submit-cf
+
+ install-sendmail-cf: $(CF).cf
+- $(INSTALL) -c -o $(CFOWN) -g $(CFGRP) -m $(CFMODE) $(CF).cf ${DESTDIR}$(MAILDIR)/sendmail.cf
++ $(INSTALL) -c -m $(CFMODE) $(CF).cf ${DESTDIR}$(MAILDIR)/sendmail.cf
+
+ install-submit-cf: $(SUBMIT).cf
+- $(INSTALL) -c -o $(CFOWN) -g $(CFGRP) -m $(CFMODE) $(SUBMIT).cf ${DESTDIR}$(MAILDIR)/submit.cf
++ $(INSTALL) -c -m $(CFMODE) $(SUBMIT).cf ${DESTDIR}$(MAILDIR)/submit.cf
+
+ depend:
+
diff --git a/external/subpack/mail/sendmail/patches/011-libmilter-so-version.patch b/external/subpack/mail/sendmail/patches/011-libmilter-so-version.patch
new file mode 100644
index 0000000..3b4df03
--- /dev/null
+++ b/external/subpack/mail/sendmail/patches/011-libmilter-so-version.patch
@@ -0,0 +1,14 @@
+--- a/libmilter/Makefile.m4
++++ b/libmilter/Makefile.m4
+@@ -9,7 +9,10 @@ define(`confMT', `true')
+ SMSRCDIR=ifdef(`confSMSRCDIR', `confSMSRCDIR', `${SRCDIR}/sendmail')
+ PREPENDDEF(`confINCDIRS', `-I${SMSRCDIR} ')
+
+-bldPRODUCT_START(`library', `libmilter')
++# obtain libmilter version
++define(`confSOVER', `esyscmd(`gcc -I../include -o lm_getver lm_getver.c && ./lm_getver')')
++
++bldPRODUCT_START(`sharedlibrary', `libmilter')
+ define(`bldINSTALLABLE', `true')
+ define(`LIBMILTER_EXTRAS', `errstring.c strl.c')
+ APPENDDEF(`confENVDEF', `-DNOT_SENDMAIL -Dsm_snprintf=snprintf')
diff --git a/external/subpack/mail/sendmail/patches/100-misc-os-musl-fixes.patch b/external/subpack/mail/sendmail/patches/100-misc-os-musl-fixes.patch
new file mode 100644
index 0000000..db6e7b5
--- /dev/null
+++ b/external/subpack/mail/sendmail/patches/100-misc-os-musl-fixes.patch
@@ -0,0 +1,49 @@
+--- a/devtools/bin/Build
++++ b/devtools/bin/Build
+@@ -320,6 +320,16 @@ then
+ rel=`/usr/apollo/bin/bldt | grep Domain | awk '{ print $4 }' | sed -e 's/,//g'`
+ fi
+
++#
++# LEDE/OpenWrt build system
++#
++if [ -n "$STAGING_DIR" -a -n "$OPENWRT_BUILD" ]
++then
++ os="OpenWrt"
++ rel="any"
++ arch="any"
++fi
++
+ if [ ! "$arch" -a ! "$os" -a ! "$rel" ]
+ then
+ arch=`uname -m | sed -e 's/ //g' -e 's/\//-/g'`
+--- a/include/sm/conf.h
++++ b/include/sm/conf.h
+@@ -57,7 +57,7 @@
+ # endif
+
+ # ifndef HASRRESVPORT
+-# define HASRRESVPORT 1 /* has rrsevport(3) call */
++# define HASRRESVPORT 0 /* has rrsevport(3) call */
+ # endif
+
+ /**********************************************************************
+@@ -1484,7 +1484,9 @@ extern void *malloc();
+ # define SM_CONF_GETOPT 0 /* need a replacement for getopt(3) */
+ # define HASUNAME 1 /* use System V uname(2) system call */
+ # define HASUNSETENV 1 /* has unsetenv(3) call */
+-# define ERRLIST_PREDEFINED /* don't declare sys_errlist */
++# ifdef __GLIBC__
++# define ERRLIST_PREDEFINED /* don't declare sys_errlist */
++# endif
+ # define GIDSET_T gid_t /* from <linux/types.h> */
+ # ifndef HASGETUSERSHELL
+ # define HASGETUSERSHELL 0 /* getusershell(3) broken in Slackware 2.0 */
+@@ -1522,6 +1524,7 @@ extern void *malloc();
+ # if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
+ # define HASSTRERROR 1 /* has strerror(3) */
+ # endif
++# define HASSTRERROR 1 /* Patch for LEDE/OpenWRT: has strerror(3) */
+ # ifndef TZ_TYPE
+ # define TZ_TYPE TZ_NONE /* no standard for Linux */
+ # endif
diff --git a/external/subpack/mail/sendmail/patches/102-pthreads-stack-size.patch b/external/subpack/mail/sendmail/patches/102-pthreads-stack-size.patch
new file mode 100644
index 0000000..aec19bf
--- /dev/null
+++ b/external/subpack/mail/sendmail/patches/102-pthreads-stack-size.patch
@@ -0,0 +1,44 @@
+This patch increases the stack size for pthreads from 80 KB, the default
+stack size for musl libc, to 2 MB. The default stack size for glibc is 8 MB.
+
+OpenDKIM, an application that depends on libmilter, segfaults if the stack
+size for pthreads is left unchanged at the musl default value of 80 KB.
+Apparently, OpenDKIM allocates blocks of 64 KB multiple times, which causes
+libmilter and therefore OpenDKIM to crash:
+https://git.alpinelinux.org/cgit/aports/commit/?id=95724d1bd53ae87f72e6388cb7323dbd8f84be9d
+
+This patch follows the patch suggested by an Alpine Linux user in bug report
+above. Also, a bug report has been filed upstream:
+https://sourceforge.net/p/opendkim/bugs/258/
+
+
+--- a/libmilter/libmilter.h
++++ b/libmilter/libmilter.h
+@@ -127,10 +127,10 @@ struct smfi_str
+ # define MI_SOCK_READ(s, b, l) read(s, b, l)
+ # define MI_SOCK_READ_FAIL(x) ((x) < 0)
+ # define MI_SOCK_WRITE(s, b, l) write(s, b, l)
+-
+-# define thread_create(ptid,wr,arg) pthread_create(ptid, NULL, wr, arg)
+ # define sthread_get_id() pthread_self()
+
++extern int thread_create(pthread_t *ptid, void *(*wr) (void *), void *arg);
++
+ typedef pthread_mutex_t smutex_t;
+ # define smutex_init(mp) (pthread_mutex_init(mp, NULL) == 0)
+ # define smutex_destroy(mp) (pthread_mutex_destroy(mp) == 0)
+--- a/libmilter/main.c
++++ b/libmilter/main.c
+@@ -16,6 +16,12 @@ SM_RCSID("@(#)$Id: main.c,v 8.85 2013-11
+ #include <fcntl.h>
+ #include <sys/stat.h>
+
++int thread_create(pthread_t *ptid, void *(*wr) (void *), void *arg) {
++ pthread_attr_t attr;
++ pthread_attr_init(&attr);
++ pthread_attr_setstacksize(&attr,2*1024*1024);
++ return pthread_create(ptid, &attr, wr, arg);
++}
+
+ static smfiDesc_ptr smfi = NULL;
+
diff --git a/external/subpack/mail/sendmail/patches/103-create-install-dirs.patch b/external/subpack/mail/sendmail/patches/103-create-install-dirs.patch
new file mode 100644
index 0000000..fa99810
--- /dev/null
+++ b/external/subpack/mail/sendmail/patches/103-create-install-dirs.patch
@@ -0,0 +1,42 @@
+--- a/sendmail/Makefile.m4
++++ b/sendmail/Makefile.m4
+@@ -71,6 +71,7 @@ install-set-user-id: bldCURRENT_PRODUCT
+ ${INSTALL} -c -o ${S`'BINOWN} -g ${S`'BINGRP} -m ${S`'BINMODE} bldCURRENT_PRODUCT ${DESTDIR}${M`'BINDIR}
+ for i in ${sendmailTARGET_LINKS}; do \
+ rm -f $$i; \
++ mkdir -p $$(dirname $$i); \
+ ${LN} ${LNOPTS} ${M`'BINDIR}/sendmail $$i; \
+ done
+
+@@ -79,6 +80,7 @@ install-sm-mta: bldCURRENT_PRODUCT
+ ${INSTALL} -c -o ${M`'BINOWN} -g ${M`'BINGRP} -m ${M`'BINMODE} bldCURRENT_PRODUCT ${DESTDIR}${M`'BINDIR}/sm-mta
+ for i in confMTA_LINKS; do \
+ rm -f $$i; \
++ mkdir -p $$(dirname $$i); \
+ ${LN} ${LNOPTS} ${M`'BINDIR}/sm-mta $$i; \
+ done
+
+--- a/devtools/M4/UNIX/links.m4
++++ b/devtools/M4/UNIX/links.m4
+@@ -23,6 +23,7 @@ define(`bldMAKE_SOURCE_LINKS',
+ define(`bldMAKE_TARGET_LINKS',
+ ` for i in $2; do \
+ rm -f $$i; \
++ mkdir -p $$(dirname $$i); \
+ ln -s $1 $$i; \
+ done'
+ )dnl
+--- a/cf/cf/Makefile
++++ b/cf/cf/Makefile
+@@ -80,9 +80,11 @@ install:
+ install-cf: install-sendmail-cf install-submit-cf
+
+ install-sendmail-cf: $(CF).cf
++ mkdir -p ${DESTDIR}$(MAILDIR)
+ $(INSTALL) -c -m $(CFMODE) $(CF).cf ${DESTDIR}$(MAILDIR)/sendmail.cf
+
+ install-submit-cf: $(SUBMIT).cf
++ mkdir -p ${DESTDIR}$(MAILDIR)
+ $(INSTALL) -c -m $(CFMODE) $(SUBMIT).cf ${DESTDIR}$(MAILDIR)/submit.cf
+
+ depend:
diff --git a/external/subpack/mail/sendmail/patches/210-cdefs.patch b/external/subpack/mail/sendmail/patches/210-cdefs.patch
new file mode 100644
index 0000000..53a93c3
--- /dev/null
+++ b/external/subpack/mail/sendmail/patches/210-cdefs.patch
@@ -0,0 +1,10 @@
+--- a/include/sm/os/sm_os_linux.h
++++ b/include/sm/os/sm_os_linux.h
+@@ -33,7 +33,6 @@
+ # endif /* LINUX_VERSION_CODE */
+ #endif /* SM_CONF_SHM */
+
+-#define SM_CONF_SYS_CDEFS_H 1
+ #ifndef SM_CONF_SEM
+ # define SM_CONF_SEM 2
+ #endif /* SM_CONF_SEM */