1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit flag-o-matic pam systemd toolchain-funcs
9 MY_SRC="${PN}-${MY_PV}"
10 MY_URI="ftp://ftp.porcupine.org/mirrors/postfix-release/experimental"
13 DESCRIPTION="A fast and secure drop-in replacement for sendmail"
14 HOMEPAGE="http://www.postfix.org/"
15 SRC_URI="${MY_URI}/${MY_SRC}.tar.gz"
17 LICENSE="|| ( IBM EPL-2.0 )"
19 KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86"
20 IUSE="+berkdb cdb dovecot-sasl +eai hardened ldap ldap-bind libressl lmdb memcached mbox mysql nis pam postgres sasl selinux sqlite ssl"
22 DEPEND=">=dev-libs/libpcre-3.4
24 berkdb? ( >=sys-libs/db-3.2:* )
25 cdb? ( || ( >=dev-db/tinycdb-0.76 >=dev-db/cdb-0.75-r4 ) )
26 eai? ( dev-libs/icu:= )
27 ldap? ( net-nds/openldap )
28 ldap-bind? ( net-nds/openldap[sasl] )
29 lmdb? ( >=dev-db/lmdb-0.9.11 )
30 mysql? ( dev-db/mysql-connector-c:0= )
31 nis? ( net-libs/libnsl )
33 postgres? ( dev-db/postgresql:* )
34 sasl? ( >=dev-libs/cyrus-sasl-2 )
35 sqlite? ( dev-db/sqlite:3 )
37 !libressl? ( dev-libs/openssl:0= )
38 libressl? ( >=dev-libs/libressl-2.9.1:0= )
45 memcached? ( net-misc/memcached )
57 !<mail-mta/ssmtp-2.64-r2
58 !>=mail-mta/ssmtp-2.64-r2[mta]
60 selinux? ( sec-policy/selinux-postfix )"
62 REQUIRED_USE="ldap-bind? ( ldap sasl )"
64 S="${WORKDIR}/${MY_SRC}"
67 "${FILESDIR}/${PN}-libressl-certkey.patch"
68 "${FILESDIR}/${PN}-libressl-server.patch"
73 sed -i -e "/^#define ALIAS_DB_MAP/s|:/etc/aliases|:/etc/mail/aliases|" \
74 src/util/sys_defs.h || die "sed failed"
75 # change default paths to better comply with portage standard paths
76 sed -i -e "s:/usr/local/:/usr/:g" conf/master.cf || die "sed failed"
80 for name in CDB LDAP LMDB MYSQL PCRE PGSQL SDBM SQLITE
82 local AUXLIBS_${name}=""
85 # Make sure LDFLAGS get passed down to the executables.
86 local mycc="-DHAS_PCRE" mylibs="${LDFLAGS} -ldl"
87 AUXLIBS_PCRE="$(pcre-config --libs)"
89 use pam && mylibs="${mylibs} -lpam"
92 mycc="${mycc} -DHAS_LDAP"
93 AUXLIBS_LDAP="-lldap -llber"
97 mycc="${mycc} -DHAS_MYSQL $(mysql_config --include)"
98 AUXLIBS_MYSQL="$(mysql_config --libs)"
101 if use postgres; then
102 mycc="${mycc} -DHAS_PGSQL -I$(pg_config --includedir)"
103 AUXLIBS_PGSQL="-L$(pg_config --libdir) -lpq"
107 mycc="${mycc} -DHAS_SQLITE"
108 AUXLIBS_SQLITE="-lsqlite3 -lpthread"
112 mycc="${mycc} -DUSE_TLS"
113 mylibs="${mylibs} -lssl -lcrypto"
117 mycc="${mycc} -DHAS_LMDB"
118 AUXLIBS_LMDB="-llmdb -lpthread"
122 mycc="${mycc} -DNO_EAI"
125 # broken. and "in other words, not supported" by upstream.
126 # Use inet_protocols setting in main.cf
128 # mycc="${mycc} -DNO_IPV6"
132 if use dovecot-sasl; then
133 # Set dovecot as default.
134 mycc="${mycc} -DDEF_SASL_SERVER=\\\"dovecot\\\""
136 if use ldap-bind; then
137 mycc="${mycc} -DUSE_LDAP_SASL"
139 mycc="${mycc} -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl"
140 mylibs="${mylibs} -lsasl2"
141 elif use dovecot-sasl; then
142 mycc="${mycc} -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\\\"dovecot\\\""
146 mycc="${mycc} -DNO_NIS"
149 if ! use berkdb; then
150 mycc="${mycc} -DNO_DB"
152 # change default hash format from Berkeley DB to cdb
153 mycc="${mycc} -DDEF_DB_TYPE=\\\"cdb\\\""
158 mycc="${mycc} -DHAS_CDB -I/usr/include/cdb"
159 # Tinycdb is preferred.
160 if has_version dev-db/tinycdb ; then
161 einfo "Building with dev-db/tinycdb"
164 einfo "Building with dev-db/cdb"
165 CDB_PATH="/usr/$(get_libdir)"
166 for i in cdb.a alloc.a buffer.a unix.a byte.a ; do
167 AUXLIBS_CDB="${AUXLIBS_CDB} ${CDB_PATH}/${i}"
172 # Robin H. Johnson <robbat2@gentoo.org> 17/Nov/2006
173 # Fix because infra boxes hit 2Gb .db files that fail a 32-bit fstat signed check.
174 mycc="${mycc} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE"
177 # Workaround for bug #76512
178 if use hardened; then
179 [[ "$(gcc-version)" == "3.4" ]] && replace-flags -O? -Os
182 # Remove annoying C++ comment style warnings - bug #378099
183 append-flags -Wno-comment
185 sed -i -e "/^RANLIB/s/ranlib/$(tc-getRANLIB)/g" "${S}"/makedefs
186 sed -i -e "/^AR/s/ar/$(tc-getAR)/g" "${S}"/makedefs
188 emake makefiles shared=yes dynamicmaps=no pie=yes \
189 shlib_directory="/usr/$(get_libdir)/postfix/MAIL_VERSION" \
190 DEBUG="" CC="$(tc-getCC)" OPT="${CFLAGS}" CCARGS="${mycc}" AUXLIBS="${mylibs}" \
191 AUXLIBS_CDB="${AUXLIBS_CDB}" AUXLIBS_LDAP="${AUXLIBS_LDAP}" \
192 AUXLIBS_LMDB="${AUXLIBS_LMDB}" AUXLIBS_MYSQL="${AUXLIBS_MYSQL}" \
193 AUXLIBS_PCRE="${AUXLIBS_PCRE}" AUXLIBS_PGSQL="${AUXLIBS_PGSQL}" \
194 AUXLIBS_SQLITE="${AUXLIBS_SQLITE}"
198 LD_LIBRARY_PATH="${S}/lib" \
199 /bin/sh postfix-install \
201 install_root="${D}" \
202 config_directory="/etc/postfix" \
203 manpage_directory="/usr/share/man" \
204 command_directory="/usr/sbin" \
205 mailq_path="/usr/bin/mailq" \
206 newaliases_path="/usr/bin/newaliases" \
207 sendmail_path="/usr/sbin/sendmail" \
208 || die "postfix-install failed"
210 # Fix spool removal on upgrade
212 keepdir /var/spool/postfix
214 # Install rmail for UUCP, closes bug #19127
215 dobin auxiliary/rmail/rmail
217 # Provide another link for legacy FSH
218 dosym ../sbin/sendmail /usr/$(get_libdir)/sendmail
220 # Install qshape, posttls-finger and collate
221 dobin auxiliary/qshape/qshape.pl
222 doman man/man1/qshape.1
223 dobin bin/posttls-finger
224 doman man/man1/posttls-finger.1
225 dobin auxiliary/collate/collate.pl
226 newdoc auxiliary/collate/README README.collate
228 # Performance tuning tools and their manuals
229 dosbin bin/smtp-{source,sink} bin/qmqp-{source,sink}
230 doman man/man1/smtp-{source,sink}.1 man/man1/qmqp-{source,sink}.1
232 # Set proper permissions on required files/directories
233 keepdir /var/lib/postfix
234 fowners -R postfix:postfix /var/lib/postfix
235 fperms 0750 /var/lib/postfix
236 fowners root:postdrop /usr/sbin/post{drop,queue}
237 fperms 02755 /usr/sbin/post{drop,queue}
240 keepdir /etc/postfix/postfix-files.d
242 mypostconf="mail_spool_directory=/var/spool/mail"
244 mypostconf="home_mailbox=.maildir/"
246 LD_LIBRARY_PATH="${S}/lib" \
247 "${D}"/usr/sbin/postconf -c "${D}"/etc/postfix \
248 -e ${mypostconf} || die "postconf failed"
251 newins "${FILESDIR}"/smtp.pass saslpass
252 fperms 600 /etc/postfix/saslpass
254 newinitd "${FILESDIR}"/postfix.rc6.${RC_VER} postfix
255 # do not start mysql/postgres unnecessarily - bug #359913
256 use mysql || sed -i -e "s/mysql //" "${D}/etc/init.d/postfix"
257 use postgres || sed -i -e "s/postgresql //" "${D}/etc/init.d/postfix"
259 dodoc *README COMPATIBILITY HISTORY PORTING RELEASE_NOTES*
260 mv "${S}"/examples "${D}"/usr/share/doc/${PF}/
261 # postfix set-permissions expects uncompressed man files
262 docompress -x /usr/share/man
264 pamd_mimic_system smtp auth account
268 newins "${FILESDIR}"/smtp.sasl smtpd.conf
272 insinto /usr/include/postfix
275 if has_version mail-mta/postfix; then
276 # let the sysadmin decide when to change the compatibility_level
277 sed -i -e /^compatibility_level/"s/^/#/" "${D}"/etc/postfix/main.cf || die
280 systemd_dounit "${FILESDIR}/${PN}.service"
284 if has_version '<mail-mta/postfix-3.4'; then
286 elog "Postfix-3.4 introduces a new master.cf service 'postlog'"
287 elog "with type 'unix-dgram' that is used by the new postlogd(8) daemon."
288 elog "Before backing out to an older Postfix version, edit the master.cf"
289 elog "file and remove the postlog entry."
295 if [[ ! -e /etc/mail/aliases.db ]] ; then
297 ewarn "You must edit /etc/mail/aliases to suit your needs"
298 ewarn "and then run /usr/bin/newaliases. Postfix will not"
299 ewarn "work correctly without it."
303 # check and fix file permissions
304 "${EROOT}"/usr/sbin/postfix set-permissions
308 if "${EROOT}"/usr/sbin/postfix tls all-default-client; then
309 elog "To configure client side TLS settings:"
310 elog "${EROOT}"/usr/sbin/postfix tls enable-client
312 if "${EROOT}"/usr/sbin/postfix tls all-default-server; then
313 elog "To configure server side TLS settings:"
314 elog "${EROOT}"/usr/sbin/postfix tls enable-server