cb68569b7c8438c0ed30e5ec7b555a383f872203
[gentoo.git] / mail-mta / exim / exim-4.93.0.4-r1.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="7"
5
6 inherit db-use toolchain-funcs multilib pam systemd
7
8 IUSE="arc +dane dcc +dkim dlfunc dmarc +dnsdb doc dovecot-sasl dsn elibc_glibc exiscan-acl gnutls idn ipv6 ldap libressl lmtp maildir mbx mysql nis pam perl pkcs11 postgres +prdr proxy radius redis sasl selinux spf sqlite srs +ssl syslog tcpd +tpda X"
9 REQUIRED_USE="
10         arc? ( dkim spf )
11         dane? ( ssl !gnutls )
12         dmarc? ( dkim spf )
13         dkim? ( ssl !gnutls )
14         gnutls? ( ssl )
15         pkcs11? ( ssl )
16         spf? ( exiscan-acl )
17         srs? ( exiscan-acl )
18 "
19 # NOTE on USE="gnutls dane", gnutls[dane] is masked in base, unmasked
20 # for x86 and amd64 only, due to this, repoman won't allow depending on
21 # gnutls[dane] for all else.  Because we cannot express USE=dane when
22 # USE=gnutls is in effect only in package.use.mask, the only option we
23 # have left is to a) ignore the dependency (but that results in bug
24 # #661164) or b) mask the usage of USE=dane with USE=gnutls.  Both are
25 # incorrect, but b) is the only "correct" view from repoman.
26
27 SDIR=$([[ ${PV} == *_rc* ]]   && echo /test
28        [[ ${PV} == *.*.*.* ]] && echo /fixes)
29 COMM_URI="https://downloads.exim.org/exim4${SDIR}"
30
31 DESCRIPTION="A highly configurable, drop-in replacement for sendmail"
32 SRC_URI="${COMM_URI}/${P//rc/RC}.tar.xz
33         mirror://gentoo/system_filter.exim.gz
34         doc? ( ${COMM_URI}/${PN}-pdf-${PV//rc/RC}.tar.xz )"
35 HOMEPAGE="https://www.exim.org/"
36
37 SLOT="0"
38 LICENSE="GPL-2"
39 KEYWORDS="~alpha amd64 arm ~arm64 ~hppa ~ia64 ppc ppc64 sparc x86 ~x86-solaris"
40
41 COMMON_DEPEND=">=sys-apps/sed-4.0.5
42         ( >=sys-libs/db-3.2:= <sys-libs/db-6:= )
43         dev-libs/libpcre
44         idn? ( net-dns/libidn:= net-dns/libidn2:= )
45         perl? ( dev-lang/perl:= )
46         pam? ( sys-libs/pam )
47         tcpd? ( sys-apps/tcp-wrappers )
48         ssl? (
49                 gnutls? (
50                         net-libs/gnutls:0=[pkcs11?]
51                         dev-libs/libtasn1
52                 )
53                 !gnutls? (
54                         !libressl? ( dev-libs/openssl:0= )
55                         libressl? ( dev-libs/libressl:= )
56                 )
57         )
58         ldap? ( >=net-nds/openldap-2.0.7 )
59         nis? (
60                 elibc_glibc? (
61                         net-libs/libtirpc
62                         >=net-libs/libnsl-1:=
63                 )
64         )
65         mysql? ( dev-db/mysql-connector-c:= )
66         postgres? ( dev-db/postgresql:= )
67         sasl? ( >=dev-libs/cyrus-sasl-2.1.26-r2 )
68         redis? ( dev-libs/hiredis )
69         spf? ( >=mail-filter/libspf2-1.2.5-r1 )
70         dmarc? ( mail-filter/opendmarc )
71         srs? ( mail-filter/libsrs_alt )
72         X? (
73                 x11-libs/libX11
74                 x11-libs/libXmu
75                 x11-libs/libXt
76                 x11-libs/libXaw
77         )
78         sqlite? ( dev-db/sqlite )
79         radius? ( net-dialup/freeradius-client )
80         virtual/libiconv
81         elibc_glibc? ( net-libs/libnsl )
82         "
83         # added X check for #57206
84 BDEPEND="virtual/pkgconfig"
85 DEPEND="${COMMON_DEPEND}"
86 RDEPEND="${COMMON_DEPEND}
87         !mail-mta/courier
88         !mail-mta/esmtp
89         !mail-mta/mini-qmail
90         !<mail-mta/msmtp-1.4.19-r1
91         !>=mail-mta/msmtp-1.4.19-r1[mta]
92         !mail-mta/netqmail
93         !mail-mta/nullmailer
94         !mail-mta/postfix
95         !mail-mta/qmail-ldap
96         !mail-mta/sendmail
97         !mail-mta/opensmtpd
98         !<mail-mta/ssmtp-2.64-r2
99         !>=mail-mta/ssmtp-2.64-r2[mta]
100         !net-mail/mailwrapper
101         >=net-mail/mailbase-0.00-r5
102         virtual/logger
103         dcc? ( mail-filter/dcc )
104         selinux? ( sec-policy/selinux-exim )
105         "
106
107 S=${WORKDIR}/${P//rc/RC}
108
109 src_prepare() {
110         # Legacy patches which need a respin for -p1
111         eapply -p0 "${FILESDIR}"/exim-4.14-tail.patch
112         eapply -p0 "${FILESDIR}"/exim-4.74-radius-db-ENV-clash.patch # 287426
113         eapply     "${FILESDIR}"/exim-4.93-as-needed-ldflags.patch # 352265, 391279
114         eapply -p0 "${FILESDIR}"/exim-4.76-crosscompile.patch # 266591
115         eapply     "${FILESDIR}"/exim-4.69-r1.27021.patch
116         eapply     "${FILESDIR}"/exim-4.93-localscan_dlopen.patch
117         eapply -p2 "${FILESDIR}"/exim-4.93-radius.patch # 720364
118         eapply     "${FILESDIR}"/exim-4.93-CVE-2020-12783.patch # 722484
119
120         if use maildir ; then
121                 eapply "${FILESDIR}"/exim-4.20-maildir.patch
122         else
123                 eapply -p0 "${FILESDIR}"/exim-4.80-spool-mail-group.patch # 438606
124         fi
125
126         eapply_user
127
128         # user Exim believes it should be
129         MAILUSER=mail
130         MAILGROUP=mail
131         if use prefix && [[ ${EUID} != 0 ]] ; then
132                 MAILUSER=$(id -un)
133                 MAILGROUP=$(id -gn)
134         fi
135 }
136
137 src_configure() {
138         # general config and paths
139
140         local aliases="${EPREFIX}/etc/mail/aliases"
141         sed -i \
142                 -e "/SYSTEM_ALIASES_FILE/s'SYSTEM_ALIASES_FILE'${aliases}'" \
143                 src/configure.default || die
144
145         sed -i -e 's/^buildname=.*/buildname=exim-gentoo/' Makefile || die
146
147         if use elibc_musl; then
148                 sed -i -e 's/^LIBS = -lnsl/LIBS =/g' OS/Makefile-Linux || die
149         fi
150
151         local conffile="${EPREFIX}/etc/exim/exim.conf"
152         sed -e "48i\CFLAGS=${CFLAGS}" \
153                 -e "s:BIN_DIRECTORY=/usr/exim/bin:BIN_DIRECTORY=${EPREFIX}/usr/sbin:" \
154                 -e "s;EXIM_USER=;EXIM_USER=ref:${MAILUSER};" \
155                 -e "s:CONFIGURE_FILE=.*$:CONFIGURE_FILE=${conffile}:" \
156                 -e "s:ZCAT_COMMAND=.*$:ZCAT_COMMAND=${EPREFIX}/bin/zcat:" \
157                 -e "s:COMPRESS_COMMAND=.*$:COMPRESS_COMMAND=${EPREFIX}/bin/gzip:" \
158                 src/EDITME > Local/Makefile || die
159
160         # work on Local/Makefile from now on
161         cd Local
162
163         cat >> Makefile <<- EOC
164                 INFO_DIRECTORY=${EPREFIX}/usr/share/info
165                 PID_FILE_PATH=${EPREFIX}/run/exim.pid
166                 SPOOL_DIRECTORY=${EPREFIX}/var/spool/exim
167                 HAVE_ICONV=yes
168         EOC
169
170         # if we use libiconv, now is the time to tell so
171         if use !elibc_glibc && use !elibc_musl ; then
172                 cat >> Makefile <<- EOC
173                         EXTRALIBS_EXIM=-liconv
174                 EOC
175         fi
176
177         # support for IPv6
178         if use ipv6; then
179                 cat >> Makefile <<- EOC
180                         HAVE_IPV6=YES
181                 EOC
182         fi
183
184         # support i18n/IDNA
185         if use idn; then
186                 cat >> Makefile <<- EOC
187                         SUPPORT_I18N=yes
188                         SUPPORT_I18N_2008=yes
189                         EXTRALIBS_EXIM += -lidn -lidn2
190                 EOC
191         fi
192
193         #
194         # mail storage formats
195         #
196
197         # mailstore is Exim's traditional storage format
198         cat >> Makefile <<- EOC
199                 SUPPORT_MAILSTORE=yes
200         EOC
201
202         # mbox
203         if use mbx; then
204                 cat >> Makefile <<- EOC
205                         SUPPORT_MBX=yes
206                 EOC
207         fi
208
209         # maildir
210         if use maildir; then
211                 cat >> Makefile <<- EOC
212                         SUPPORT_MAILDIR=yes
213                 EOC
214         fi
215
216         #
217         # lookup methods
218
219         # use the "native" interfaces to the DBM and CDB libraries, support
220         # passwd and directory lookups by default
221         local DB_VERS="5.3 5.1 4.8 4.7 4.6 4.5 4.4 4.3 4.2 3.2"
222         cat >> Makefile <<- EOC
223                 USE_DB=yes
224                 LOOKUP_CDB=yes
225                 LOOKUP_PASSWD=yes
226                 LOOKUP_DSEARCH=yes
227                 # keep include in CFLAGS because exim.h -> dbstuff.h -> db.h
228                 CFLAGS += -I$(db_includedir ${DB_VERS})
229                 DBMLIB = -l$(db_libname ${DB_VERS})
230         EOC
231
232         if ! use dnsdb; then
233                 # DNSDB lookup is enabled by default
234                 sed -i -e 's:^LOOKUP_DNSDB=yes:# LOOKUP_DNSDB=yes:' Makefile || die
235         fi
236
237         if use ldap; then
238                 cat >> Makefile <<- EOC
239                         LOOKUP_LDAP=yes
240                         LDAP_LIB_TYPE=OPENLDAP2
241                         LOOKUP_INCLUDE += -I"${EPREFIX}"/usr/include/ldap
242                         LOOKUP_LIBS += -lldap -llber
243                 EOC
244         fi
245
246         if use mysql; then
247                 cat >> Makefile <<- EOC
248                         LOOKUP_MYSQL=yes
249                         LOOKUP_INCLUDE += $(mysql_config --include)
250                         LOOKUP_LIBS += $(mysql_config --libs)
251                 EOC
252         fi
253
254         if use nis; then
255                 cat >> Makefile <<- EOC
256                         LOOKUP_NIS=yes
257                         LOOKUP_NISPLUS=yes
258                 EOC
259                 if use elibc_glibc ; then
260                         cat >> Makefile <<- EOC
261                                 LOOKUP_INCLUDE += -I"${EPREFIX}"/usr/include/tirpc
262                                 LOOKUP_LIBS += -lnsl
263                         EOC
264                 fi
265         fi
266
267         if use postgres; then
268                 cat >> Makefile <<- EOC
269                         LOOKUP_PGSQL=yes
270                         LOOKUP_INCLUDE += -I$(pg_config --includedir)
271                         LOOKUP_LIBS += -L$(pg_config --libdir) -lpq
272                 EOC
273         fi
274
275         if use sqlite; then
276                 cat >> Makefile <<- EOC
277                         LOOKUP_SQLITE=yes
278                         LOOKUP_SQLITE_PC=sqlite3
279                 EOC
280         fi
281
282         if use redis; then
283                 cat >> Makefile <<- EOC
284                         LOOKUP_REDIS=yes
285                         LOOKUP_LIBS += -lhiredis
286                 EOC
287         fi
288
289         # Exim monitor, enabled by default, controlled via X USE-flag,
290         # disable if not requested, bug #46778
291         if use X; then
292                 cp ../exim_monitor/EDITME eximon.conf || die
293                 cat >> Makefile <<- EOC
294                         EXIM_MONITOR=eximon.bin
295                 EOC
296         fi
297
298         #
299         # features
300         #
301
302         # content scanning support
303         if use exiscan-acl; then
304                 cat >> Makefile <<- EOC
305                         WITH_CONTENT_SCAN=yes
306                 EOC
307         fi
308
309         # DomainKeys Identified Mail, RFC4871
310         if ! use dkim; then
311                 # DKIM is enabled by default
312                 cat >> Makefile <<- EOC
313                         DISABLE_DKIM=yes
314                 EOC
315         fi
316
317         # Per-Recipient-Data-Response
318         if ! use prdr; then
319                 # PRDR is enabled by default
320                 cat >> Makefile <<- EOC
321                         DISABLE_PRDR=yes
322                 EOC
323         fi
324
325         # Transport post-delivery actions
326         if use !tpda && use !dane; then
327                 # EVENT is enabled by default
328                 cat >> Makefile <<- EOC
329                         DISABLE_EVENT=yes
330                 EOC
331         fi
332
333         # log to syslog
334         if use syslog; then
335                 local eximlog="${EPREFIX}/var/log/exim/exim_%s.log"
336                 sed -i \
337                         -e "s:LOG_FILE_PATH=${eximlog}:LOG_FILE_PATH=syslog:" \
338                         Makefile || die
339                 cat >> Makefile <<- EOC
340                         LOG_FILE_PATH=syslog
341                 EOC
342         else
343                 cat >> Makefile <<- EOC
344                         LOG_FILE_PATH=${EPREFIX}/var/log/exim/exim_%s.log
345                 EOC
346         fi
347
348         # starttls support (ssl)
349         if use ssl; then
350                 if use gnutls; then
351                         echo "USE_GNUTLS=yes" >> Makefile
352                         echo "USE_GNUTLS_PC=gnutls $(use dane && echo gnutls-dane)" \
353                                 >> Makefile
354                         use pkcs11 || echo "AVOID_GNUTLS_PKCS11=yes" >> Makefile
355                 else
356                         echo "USE_OPENSSL=yes" >> Makefile
357                         echo "USE_OPENSSL_PC=openssl" >> Makefile
358                 fi
359         else
360                 echo "DISABLE_TLS=yes" >> Makefile
361         fi
362
363         # TCP wrappers
364         if use tcpd; then
365                 cat >> Makefile <<- EOC
366                         USE_TCP_WRAPPERS=yes
367                         EXTRALIBS_EXIM += -lwrap
368                 EOC
369         fi
370
371         # Light Mail Transport Protocol
372         if use lmtp; then
373                 cat >> Makefile <<- EOC
374                         TRANSPORT_LMTP=yes
375                 EOC
376         fi
377
378         # embedded Perl
379         if use perl; then
380                 cat >> Makefile <<- EOC
381                         EXIM_PERL=perl.o
382                 EOC
383         fi
384
385         # dlfunc
386         if use dlfunc; then
387                 cat >> Makefile <<- EOC
388                         EXPAND_DLFUNC=yes
389                         HAVE_LOCAL_SCAN=yes
390                         DLOPEN_LOCAL_SCAN=yes
391                 EOC
392         fi
393
394         # Proxy Protocol
395         if use proxy; then
396                 cat >> Makefile <<- EOC
397                         SUPPORT_PROXY=yes
398                 EOC
399         fi
400
401         # DANE
402         if use !dane; then
403                 # DANE is enabled by default
404                 sed -i -e 's:^SUPPORT_DANE=yes:# SUPPORT_DANE=yes:' Makefile || die
405         fi
406
407         # DMARC
408         if use dmarc; then
409                 cat >> Makefile <<- EOC
410                         SUPPORT_DMARC=yes
411                         EXTRALIBS_EXIM += -lopendmarc
412                 EOC
413         fi
414
415         # Sender Policy Framework
416         if use spf; then
417                 cat >> Makefile <<- EOC
418                         SUPPORT_SPF=yes
419                         EXTRALIBS_EXIM += -lspf2
420                 EOC
421         fi
422
423         #
424         # experimental features
425         #
426
427         # Authenticated Receive Chain
428         if use arc; then
429                 echo "EXPERIMENTAL_ARC=yes">> Makefile
430         fi
431
432         # Distributed Checksum Clearinghouse
433         if use dcc; then
434                 echo "EXPERIMENTAL_DCC=yes">> Makefile
435         fi
436
437         # Sender Rewriting Scheme
438         if use srs; then
439                 cat >> Makefile <<- EOC
440                         EXPERIMENTAL_SRS=yes
441                         EXTRALIBS_EXIM += -lsrs_alt
442                 EOC
443         fi
444
445         # Delivery Sender Notifications extra information in fail message
446         if use dsn; then
447                 cat >> Makefile <<- EOC
448                         EXPERIMENTAL_DSN_INFO=yes
449                 EOC
450         fi
451
452         #
453         # authentication (SMTP AUTH)
454         #
455
456         # standard bits
457         cat >> Makefile <<- EOC
458                 AUTH_SPA=yes
459                 AUTH_CRAM_MD5=yes
460                 AUTH_PLAINTEXT=yes
461         EOC
462
463         # Cyrus SASL
464         if use sasl; then
465                 cat >> Makefile <<- EOC
466                         CYRUS_SASLAUTHD_SOCKET=${EPREFIX}/run/saslauthd/mux
467                         AUTH_CYRUS_SASL=yes
468                         AUTH_LIBS += -lsasl2
469                 EOC
470         fi
471
472         # Dovecot
473         if use dovecot-sasl; then
474                 cat >> Makefile <<- EOC
475                         AUTH_DOVECOT=yes
476                 EOC
477         fi
478
479         # Pluggable Authentication Modules
480         if use pam; then
481                 cat >> Makefile <<- EOC
482                         SUPPORT_PAM=yes
483                         AUTH_LIBS += -lpam
484                 EOC
485         fi
486
487         # Radius
488         if use radius; then
489                 cat >> Makefile <<- EOC
490                         RADIUS_CONFIG_FILE=${EPREFIX}/etc/radiusclient/radiusclient.conf
491                         RADIUS_LIB_TYPE=RADIUSCLIENTNEW
492                         AUTH_LIBS += -lfreeradius-client
493                 EOC
494         fi
495 }
496
497 src_compile() {
498         emake CC="$(tc-getCC)" HOSTCC="$(tc-getBUILD_CC)" \
499                 AR="$(tc-getAR) cq" RANLIB="$(tc-getRANLIB)" FULLECHO=''
500 }
501
502 src_install() {
503         cd "${S}"/build-exim-gentoo || die
504         dosbin exim
505         if use X; then
506                 dosbin eximon.bin
507                 dosbin eximon
508         fi
509         fperms 4755 /usr/sbin/exim
510
511         dosym exim /usr/sbin/sendmail
512         dosym exim /usr/sbin/rsmtp
513         dosym exim /usr/sbin/rmail
514         dosym ../sbin/exim /usr/bin/mailq
515         dosym ../sbin/exim /usr/bin/newaliases
516         dosym ../sbin/sendmail /usr/lib/sendmail
517
518         for i in exicyclog exim_dbmbuild exim_dumpdb exim_fixdb exim_lock \
519                 exim_tidydb exinext exiwhat exigrep eximstats exiqsumm exiqgrep \
520                 convert4r3 convert4r4 exipick
521         do
522                 dosbin $i
523         done
524
525         dodoc -r "${S}"/doc/.
526         doman "${S}"/doc/exim.8
527         use dsn && dodoc "${S}"/README.DSN
528         use doc && dodoc "${WORKDIR}"/${PN}-pdf-${PV//rc/RC}/doc/*.pdf
529
530         # conf files
531         insinto /etc/exim
532         newins "${S}"/src/configure.default exim.conf.dist
533         if use exiscan-acl; then
534                 newins "${S}"/src/configure.default exim.conf.exiscan-acl
535         fi
536         doins "${WORKDIR}"/system_filter.exim
537         doins "${FILESDIR}"/auth_conf.sub
538
539         pamd_mimic system-auth exim auth account
540
541         # headers, #436406
542         if use dlfunc ; then
543                 # fixup includes so they actually can be found when including
544                 sed -i \
545                         -e '/#include "\(config\|store\|mytypes\).h"/s:"\(.\+\)":<exim/\1>:' \
546                         local_scan.h || die
547                 insinto /usr/include/exim
548                 doins {config,local_scan}.h ../src/{mytypes,store}.h
549         fi
550
551         insinto /etc/logrotate.d
552         newins "${FILESDIR}/exim.logrotate" exim
553
554         newinitd "${FILESDIR}"/exim.rc10 exim
555         newconfd "${FILESDIR}"/exim.confd exim
556
557         systemd_dounit \
558                 "${FILESDIR}"/{exim.service,exim.socket,exim-submission.socket}
559         systemd_newunit \
560                 "${FILESDIR}"/exim_at.service 'exim@.service'
561         systemd_newunit \
562                 "${FILESDIR}"/exim-submission_at.service 'exim-submission@.service'
563
564         diropts -m 0750 -o ${MAILUSER} -g ${MAILGROUP}
565         keepdir /var/log/${PN}
566 }
567
568 pkg_postinst() {
569         if [[ ! -f ${EROOT}/etc/exim/exim.conf ]] ; then
570                 einfo "${EROOT}/etc/exim/system_filter.exim is a sample system_filter."
571                 einfo "${EROOT}/etc/exim/auth_conf.sub contains the configuration sub"
572                 einfo "for using smtp auth."
573                 einfo "Please create ${EROOT}/etc/exim/exim.conf from"
574                 einfo "  ${EROOT}/etc/exim/exim.conf.dist."
575         fi
576         if use dmarc ; then
577                 einfo "DMARC support requires ${EROOT}/etc/exim/opendmarc.tlds"
578                 einfo "you can populate this file with the contents downloaded from"
579                 einfo "  https://publicsuffix.org/list/public_suffix_list.dat"
580         fi
581         if use dcc ; then
582                 einfo "DCC support is experimental, you can find some limited"
583                 einfo "documentation at the bottom of this prerelease message:"
584                 einfo "  http://article.gmane.org/gmane.mail.exim.devel/3579"
585         fi
586         use srs && einfo "SRS support is experimental"
587         use dsn && einfo "extra information in fail DSN message is experimental"
588         elog "The obsolete acl condition 'demime' is removed, the replacements"
589         elog "are the ACLs acl_smtp_mime and acl_not_smtp_mime"
590 }