1 # Copyright 1999-2018 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
5 inherit eutils multilib ssl-cert toolchain-funcs flag-o-matic pam user versionator systemd
8 MY_SRC="${PN}-${MY_PV}"
9 MY_URI="ftp://ftp.porcupine.org/mirrors/postfix-release/official"
11 VDA_P="${PN}-vda-v13-${VDA_PV}"
14 DESCRIPTION="A fast and secure drop-in replacement for sendmail"
15 HOMEPAGE="http://www.postfix.org/"
16 SRC_URI="${MY_URI}/${MY_SRC}.tar.gz
17 vda? ( http://vda.sourceforge.net/VDA/${VDA_P}.patch ) "
22 IUSE="+berkdb cdb doc dovecot-sasl hardened ldap ldap-bind memcached mbox mysql nis pam postgres sasl selinux sqlite ssl vda"
24 DEPEND=">=dev-libs/libpcre-3.4
26 berkdb? ( >=sys-libs/db-3.2:* )
27 cdb? ( || ( >=dev-db/tinycdb-0.76 >=dev-db/cdb-0.75-r1 ) )
28 ldap? ( net-nds/openldap )
29 ldap-bind? ( net-nds/openldap[sasl] )
30 mysql? ( virtual/mysql )
32 postgres? ( dev-db/postgresql:* )
33 sasl? ( >=dev-libs/cyrus-sasl-2 )
34 sqlite? ( dev-db/sqlite:3 )
35 ssl? ( dev-libs/openssl:0= )"
38 dovecot-sasl? ( net-mail/dovecot )
39 memcached? ( net-misc/memcached )
41 selinux? ( sec-policy/selinux-postfix )
52 !<mail-mta/ssmtp-2.64-r2
53 !>=mail-mta/ssmtp-2.64-r2[mta]
54 !net-mail/fastforward"
56 REQUIRED_USE="ldap-bind? ( ldap sasl )"
58 S="${WORKDIR}/${MY_SRC}"
61 # Add postfix, postdrop user/group (bug #77565)
63 enewgroup postdrop 208
64 enewuser postfix 207 -1 /var/spool/postfix postfix,mail
68 epatch "${FILESDIR}/${PN}-2.11.1-db6.patch"
70 epatch "${DISTDIR}"/${VDA_P}.patch
73 sed -i -e "/^#define ALIAS_DB_MAP/s|:/etc/aliases|:/etc/mail/aliases|" \
74 src/util/sys_defs.h || die "sed failed"
76 # change default paths to better comply with portage standard paths
77 sed -i -e "s:/usr/local/:/usr/:g" conf/master.cf || die "sed failed"
81 # Make sure LDFLAGS get passed down to the executables.
82 local mycc="-DHAS_PCRE" mylibs="${LDFLAGS} -lpcre -lcrypt -lpthread"
84 use pam && mylibs="${mylibs} -lpam"
87 mycc="${mycc} -DHAS_LDAP"
88 mylibs="${mylibs} -lldap -llber"
92 mycc="${mycc} -DHAS_MYSQL $(mysql_config --include)"
93 mylibs="${mylibs} $(mysql_config --libs)"
97 mycc="${mycc} -DHAS_PGSQL -I$(pg_config --includedir)"
98 mylibs="${mylibs} -lpq -L$(pg_config --libdir)"
102 mycc="${mycc} -DHAS_SQLITE"
103 mylibs="${mylibs} -lsqlite3"
107 mycc="${mycc} -DUSE_TLS"
108 mylibs="${mylibs} -lssl -lcrypto"
111 # broken. and "in other words, not supported" by upstream.
112 # Use inet_protocols setting in main.cf
114 # mycc="${mycc} -DNO_IPV6"
118 if use dovecot-sasl; then
119 # Set dovecot as default.
120 mycc="${mycc} -DDEF_SASL_SERVER=\\\"dovecot\\\""
122 if use ldap-bind; then
123 mycc="${mycc} -DUSE_LDAP_SASL"
125 mycc="${mycc} -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl"
126 mylibs="${mylibs} -lsasl2"
127 elif use dovecot-sasl; then
128 mycc="${mycc} -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\\\"dovecot\\\""
132 sed -i -e "s|#define HAS_NIS|//#define HAS_NIS|g" \
133 src/util/sys_defs.h || die "sed failed"
136 if ! use berkdb; then
137 mycc="${mycc} -DNO_DB"
139 # change default hash format from Berkeley DB to cdb
140 sed -i -e "s/hash/cdb/" src/util/sys_defs.h || die
145 mycc="${mycc} -DHAS_CDB -I/usr/include/cdb"
147 # Tinycdb is preferred.
148 if has_version dev-db/tinycdb ; then
149 einfo "Building with dev-db/tinycdb"
152 einfo "Building with dev-db/cdb"
153 CDB_PATH="/usr/$(get_libdir)"
154 for i in cdb.a alloc.a buffer.a unix.a byte.a ; do
155 CDB_LIBS="${CDB_LIBS} ${CDB_PATH}/${i}"
158 mylibs="${mylibs} ${CDB_LIBS}"
161 # Robin H. Johnson <robbat2@gentoo.org> 17/Nov/2006
162 # Fix because infra boxes hit 2Gb .db files that fail a 32-bit fstat signed check.
163 mycc="${mycc} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE"
166 # Workaround for bug #76512
167 if use hardened; then
168 [[ "$(gcc-version)" == "3.4" ]] && replace-flags -O? -Os
171 # Remove annoying C++ comment style warnings - bug #378099
172 append-flags -Wno-comment
174 sed -i -e "/^RANLIB/s/ranlib/$(tc-getRANLIB)/g" "${S}"/makedefs
175 sed -i -e "/^AR/s/ar/$(tc-getAR)/g" "${S}"/makedefs
176 emake DEBUG="" CC="$(tc-getCC)" OPT="${CFLAGS}" CCARGS="${mycc}" AUXLIBS="${mylibs}" makefiles
181 use doc && myconf="readme_directory=\"/usr/share/doc/${PF}/readme\" \
182 html_directory=\"/usr/share/doc/${PF}/html\""
184 /bin/sh postfix-install \
186 install_root="${D}" \
187 config_directory="/etc/postfix" \
188 manpage_directory="/usr/share/man" \
189 command_directory="/usr/sbin" \
190 mailq_path="/usr/bin/mailq" \
191 newaliases_path="/usr/bin/newaliases" \
192 sendmail_path="/usr/sbin/sendmail" \
194 || die "postfix-install failed"
196 # Fix spool removal on upgrade
198 keepdir /var/spool/postfix
200 # Install rmail for UUCP, closes bug #19127
201 dobin auxiliary/rmail/rmail
203 # Provide another link for legacy FSH
204 dosym /usr/sbin/sendmail /usr/$(get_libdir)/sendmail
206 # Install qshape tool
207 dobin auxiliary/qshape/qshape.pl
208 doman man/man1/qshape.1
210 # Performance tuning tools and their manuals
211 dosbin bin/smtp-{source,sink} bin/qmqp-{source,sink}
212 doman man/man1/smtp-{source,sink}.1 man/man1/qmqp-{source,sink}.1
214 # Set proper permissions on required files/directories
215 dodir /var/lib/postfix
216 keepdir /var/lib/postfix
217 fowners -R postfix:postfix /var/lib/postfix
218 fperms 0750 /var/lib/postfix
219 fowners root:postdrop /usr/sbin/post{drop,queue}
220 fperms 02711 /usr/sbin/post{drop,queue}
224 mypostconf="mail_spool_directory=/var/spool/mail"
226 mypostconf="home_mailbox=.maildir/"
228 "${D}"/usr/sbin/postconf -c "${D}"/etc/postfix \
229 -e ${mypostconf} || die "postconf failed"
232 newins "${FILESDIR}"/smtp.pass saslpass
233 fperms 600 /etc/postfix/saslpass
235 newinitd "${FILESDIR}"/postfix.rc6.${RC_VER} postfix
236 # do not start mysql/postgres unnecessarily - bug #359913
237 use mysql || sed -i -e "s/mysql //" "${D}/etc/init.d/postfix"
238 use postgres || sed -i -e "s/postgresql //" "${D}/etc/init.d/postfix"
240 dodoc *README COMPATIBILITY HISTORY PORTING RELEASE_NOTES*
241 mv "${D}"/etc/postfix/{*.default,makedefs.out} "${D}"/usr/share/doc/${PF}/
242 use doc && mv "${S}"/examples "${D}"/usr/share/doc/${PF}/
244 pamd_mimic_system smtp auth account
248 newins "${FILESDIR}"/smtp.sasl smtpd.conf
252 insinto /usr/include/postfix
255 # Remove unnecessary files
256 rm -f "${D}"/etc/postfix/{*LICENSE,access,aliases,canonical,generic}
257 rm -f "${D}"/etc/postfix/{header_checks,relocated,transport,virtual}
259 systemd_dounit "${FILESDIR}/${PN}.service"
264 # default for inet_protocols changed from ipv4 to all in postfix-2.9.
265 # check inet_protocols setting in main.cf and modify if necessary to prevent
266 # performance loss with useless DNS lookups and useless connection attempts.
267 [[ -d ${ROOT}/etc/postfix ]] && {
268 if [[ "$(${D}/usr/sbin/postconf -dh inet_protocols)" != "ipv4" ]]; then
269 if [[ ! -n "$(${D}/usr/sbin/postconf -c ${ROOT}/etc/postfix -n inet_protocols)" ]];
271 ewarn "\nCOMPATIBILITY: adding inet_protocols=ipv4 to main.cf."
272 ewarn "That will keep the same behaviour as previous postfix versions."
273 ewarn "Specify inet_protocols explicitly if you want to enable IPv6.\n"
275 # delete inet_protocols setting. there is already one in /etc/postfix
276 sed -i -e /inet_protocols/d "${D}"/etc/postfix/main.cf || die
283 # Do not install server.{key,pem) SSL certificates if they already exist
284 if use ssl && [[ ! -f "${ROOT}"/etc/ssl/postfix/server.key \
285 && ! -f "${ROOT}"/etc/ssl/postfix/server.pem ]] ; then
286 SSL_ORGANIZATION="${SSL_ORGANIZATION:-Postfix SMTP Server}"
287 install_cert /etc/ssl/postfix/server
288 chown postfix:mail "${ROOT}"/etc/ssl/postfix/server.{key,pem}
291 if [[ ! -e /etc/mail/aliases.db ]] ; then
293 ewarn "You must edit /etc/mail/aliases to suit your needs"
294 ewarn "and then run /usr/bin/newaliases. Postfix will not"
295 ewarn "work correctly without it."