1a057167b9ee411dc1ebaf8e595d145bc0fbb183
[gentoo.git] / net-dns / bind / bind-9.14.11.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 # Re dlz/mysql and threads, needs to be verified..
5 # MySQL uses thread local storage in its C api. Thus MySQL
6 # requires that each thread of an application execute a MySQL
7 # thread initialization to setup the thread local storage.
8 # This is impossible to do safely while staying within the DLZ
9 # driver API. This is a limitation caused by MySQL, and not the DLZ API.
10 # Because of this BIND MUST only run with a single thread when
11 # using the MySQL driver.
12
13 EAPI=7
14
15 PYTHON_COMPAT=( python3_{6,7} )
16
17 inherit python-r1 eutils autotools toolchain-funcs flag-o-matic multilib db-use user systemd
18
19 MY_PV="${PV/_p/-P}"
20 MY_PV="${MY_PV/_rc/rc}"
21 MY_P="${PN}-${MY_PV}"
22
23 SDB_LDAP_VER="1.1.0-fc14"
24
25 RRL_PV="${MY_PV}"
26
27 # SDB-LDAP: http://bind9-ldap.bayour.com/
28
29 DESCRIPTION="Berkeley Internet Name Domain - Name Server"
30 HOMEPAGE="https://www.isc.org/software/bind"
31 SRC_URI="https://downloads.isc.org/isc/bind9/${PV}/${P}.tar.gz
32         doc? ( mirror://gentoo/dyndns-samples.tbz2 )"
33 #       sdb-ldap? (
34 #               http://ftp.disconnected-by-peer.at/pub/bind-sdb-ldap-${SDB_LDAP_VER}.patch.bz2
35 #       )"
36
37 LICENSE="Apache-2.0 BSD BSD-2 GPL-2 HPND ISC MPL-2.0"
38 SLOT="0"
39 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
40 # -berkdb by default re bug 602682
41 IUSE="-berkdb +caps dlz dnstap doc dnsrps fixed-rrset geoip geoip2 gssapi
42 json ldap libressl lmdb mysql odbc postgres python selinux static-libs
43 urandom xml +zlib"
44 # sdb-ldap - patch broken
45 # no PKCS11 currently as it requires OpenSSL to be patched, also see bug 409687
46
47 REQUIRED_USE="
48         ?? ( geoip geoip2 )
49         postgres? ( dlz )
50         berkdb? ( dlz )
51         mysql? ( dlz )
52         odbc? ( dlz )
53         ldap? ( dlz )
54         dnsrps? ( dlz )
55         python? ( ${PYTHON_REQUIRED_USE} )"
56 # sdb-ldap? ( dlz )
57
58 DEPEND="!libressl? ( dev-libs/openssl:=[-bindist] )
59         libressl? ( dev-libs/libressl:= )
60         mysql? ( dev-db/mysql-connector-c:0= )
61         odbc? ( >=dev-db/unixODBC-2.2.6 )
62         ldap? ( net-nds/openldap )
63         postgres? ( dev-db/postgresql:= )
64         caps? ( >=sys-libs/libcap-2.1.0 )
65         xml? ( dev-libs/libxml2 )
66         geoip? ( >=dev-libs/geoip-1.4.6 )
67         geoip2? ( dev-libs/libmaxminddb )
68         gssapi? ( virtual/krb5 )
69         json? ( dev-libs/json-c:= )
70         lmdb? ( dev-db/lmdb )
71         zlib? ( sys-libs/zlib )
72         dnstap? ( dev-libs/fstrm dev-libs/protobuf-c )
73         python? (
74                 ${PYTHON_DEPS}
75                 dev-python/ply[${PYTHON_USEDEP}]
76         )"
77 #       sdb-ldap? ( net-nds/openldap )
78
79 RDEPEND="${DEPEND}
80         selinux? ( sec-policy/selinux-bind )
81         sys-process/psmisc"
82
83 S="${WORKDIR}/${MY_P}"
84
85 # bug 479092, requires networking
86 RESTRICT="test"
87
88 PATCHES=(
89         "${FILESDIR}"/bind-9.14.8-mysql8-bool.patch
90 )
91
92 pkg_setup() {
93         ebegin "Creating named group and user"
94         enewgroup named 40
95         enewuser named 40 -1 /etc/bind named
96         eend ${?}
97 }
98
99 src_prepare() {
100         default
101
102         export LDFLAGS="${LDFLAGS} -L${EPREFIX}/usr/$(get_libdir) -ldl"
103
104         # Adjusting PATHs in manpages
105         for i in bin/{named/named.8,check/named-checkconf.8,rndc/rndc.8} ; do
106                 sed -i \
107                         -e 's:/etc/named.conf:/etc/bind/named.conf:g' \
108                         -e 's:/etc/rndc.conf:/etc/bind/rndc.conf:g' \
109                         -e 's:/etc/rndc.key:/etc/bind/rndc.key:g' \
110                         "${i}" || die "sed failed, ${i} doesn't exist"
111         done
112
113 #       if use dlz; then
114 #               # sdb-ldap patch as per  bug #160567
115 #               # Upstream URL: http://bind9-ldap.bayour.com/
116 #               # New patch take from bug 302735
117 #               if use sdb-ldap; then
118 #                       epatch "${WORKDIR}"/${PN}-sdb-ldap-${SDB_LDAP_VER}.patch
119 #                       cp -fp contrib/sdb/ldap/ldapdb.[ch] bin/named/
120 #                       cp -fp contrib/sdb/ldap/{ldap2zone.1,ldap2zone.c} bin/tools/
121 #                       cp -fp contrib/sdb/ldap/{zone2ldap.1,zone2ldap.c} bin/tools/
122 #               fi
123 #       fi
124
125         # should be installed by bind-tools
126         sed -i -r -e "s:(nsupdate|dig|delv) ::g" bin/Makefile.in || die
127
128         # Disable tests for now, bug 406399
129         sed -i '/^SUBDIRS/s:tests::' bin/Makefile.in lib/Makefile.in || die
130
131         # bug #220361
132         rm aclocal.m4 || die
133         rm -rf libtool.m4/ || die
134         eautoreconf
135 }
136
137 src_configure() {
138         local myeconfargs=(
139                 --sysconfdir=/etc/bind
140                 --localstatedir=/var
141                 --with-libtool
142                 --enable-full-report
143                 --without-readline
144                 --with-openssl="${EPREFIX}"/usr
145                 $(use_enable caps linux-caps)
146                 $(use_enable dnsrps)
147                 $(use_enable dnstap)
148                 $(use_enable fixed-rrset)
149                 # $(use_enable static-libs static)
150                 $(use_with berkdb dlz-bdb)
151                 $(use_with dlz dlopen)
152                 $(use_with dlz dlz-filesystem)
153                 $(use_with dlz dlz-stub)
154                 $(use_with gssapi)
155                 $(use_with json libjson)
156                 $(use_with ldap dlz-ldap)
157                 $(use_with mysql dlz-mysql)
158                 $(use_with odbc dlz-odbc)
159                 $(use_with postgres dlz-postgres)
160                 $(use_with lmdb)
161                 $(use_with python)
162                 $(use_with xml libxml2)
163                 $(use_with zlib)
164         )
165
166         use geoip && myeconfargs+=( --with-geoip )
167         use geoip2 && myeconfargs+=( --with-geoip2 )
168
169         # bug #158664
170 #       gcc-specs-ssp && replace-flags -O[23s] -O
171
172         # To include db.h from proper path
173         use berkdb && append-flags "-I$(db_includedir)"
174
175         export BUILD_CC=$(tc-getBUILD_CC)
176         econf "${myeconfargs[@]}"
177
178         # bug #151839
179         echo '#undef SO_BSDCOMPAT' >> config.h
180 }
181
182 src_install() {
183         default
184
185         dodoc CHANGES README
186
187         if use doc; then
188                 dodoc doc/arm/Bv9ARM.pdf
189
190                 docinto misc
191                 dodoc -r doc/misc/
192
193                 # might a 'html' useflag make sense?
194                 docinto html
195                 dodoc -r doc/arm/
196
197                 docinto contrib
198                 dodoc contrib/scripts/{nanny.pl,named-bootconf.sh}
199
200                 # some handy-dandy dynamic dns examples
201                 pushd "${ED}"/usr/share/doc/${PF} 1>/dev/null || die
202                 tar xf "${DISTDIR}"/dyndns-samples.tbz2 || die
203                 popd 1>/dev/null || die
204         fi
205
206         insinto /etc/bind
207         newins "${FILESDIR}"/named.conf-r8 named.conf
208
209         # ftp://ftp.rs.internic.net/domain/named.cache:
210         insinto /var/bind
211         newins "${FILESDIR}"/named.cache-r3 named.cache
212
213         insinto /var/bind/pri
214         newins "${FILESDIR}"/localhost.zone-r3 localhost.zone
215
216         newinitd "${FILESDIR}"/named.init-r13 named
217         newconfd "${FILESDIR}"/named.confd-r7 named
218
219         newenvd "${FILESDIR}"/10bind.env 10bind
220
221         # Let's get rid of those tools and their manpages since they're provided by bind-tools
222         rm -f "${ED}"/usr/share/man/man1/{dig,host,nslookup}.1* || die
223         rm -f "${ED}"/usr/share/man/man8/nsupdate.8* || die
224         rm -f "${ED}"/usr/bin/{dig,host,nslookup,nsupdate} || die
225         rm -f "${ED}"/usr/sbin/{dig,host,nslookup,nsupdate} || die
226         for tool in dsfromkey importkey keyfromlabel keygen \
227         revoke settime signzone verify; do
228                 rm -f "${ED}"/usr/{,s}bin/dnssec-"${tool}" || die
229                 rm -f "${ED}"/usr/share/man/man8/dnssec-"${tool}".8* || die
230         done
231
232         # bug 405251, library archives aren't properly handled by --enable/disable-static
233         if ! use static-libs; then
234                 find "${ED}" -type f -name '*.a' -delete || die
235         fi
236
237         # bug 405251
238         find "${ED}" -type f -name '*.la' -delete || die
239
240         if use python; then
241                 install_python_tools() {
242                         dosbin bin/python/dnssec-{checkds,coverage}
243                 }
244                 python_foreach_impl install_python_tools
245
246                 python_replicate_script "${ED}/usr/sbin/dnssec-checkds"
247                 python_replicate_script "${ED}/usr/sbin/dnssec-coverage"
248         fi
249
250         # bug 450406
251         dosym named.cache /var/bind/root.cache
252
253         dosym ../../var/bind/pri /etc/bind/pri
254         dosym ../../var/bind/sec /etc/bind/sec
255         dosym ../../var/bind/dyn /etc/bind/dyn
256         keepdir /var/bind/{pri,sec,dyn}
257
258         dodir /var/log/named
259
260         fowners root:named /{etc,var}/bind /var/log/named /var/bind/{sec,pri,dyn}
261         fowners root:named /var/bind/named.cache /var/bind/pri/localhost.zone /etc/bind/{bind.keys,named.conf}
262         fperms 0640 /var/bind/named.cache /var/bind/pri/localhost.zone /etc/bind/{bind.keys,named.conf}
263         fperms 0750 /etc/bind /var/bind/pri
264         fperms 0770 /var/log/named /var/bind/{,sec,dyn}
265
266         systemd_newunit "${FILESDIR}/named.service-r1" named.service
267         systemd_dotmpfilesd "${FILESDIR}"/named.conf
268         exeinto /usr/libexec
269         doexe "${FILESDIR}/generate-rndc-key.sh"
270 }
271
272 pkg_postinst() {
273         if [ ! -f '/etc/bind/rndc.key' ]; then
274                 if use urandom; then
275                         einfo "Using /dev/urandom for generating rndc.key"
276                         /usr/sbin/rndc-confgen -r /dev/urandom -a
277                         echo
278                 else
279                         einfo "Using /dev/random for generating rndc.key"
280                         /usr/sbin/rndc-confgen -a
281                         echo
282                 fi
283                 chown root:named /etc/bind/rndc.key || die
284                 chmod 0640 /etc/bind/rndc.key || die
285         fi
286
287         einfo
288         einfo "You can edit /etc/conf.d/named to customize named settings"
289         einfo
290         use mysql || use postgres || use ldap && {
291                 elog "If your named depends on MySQL/PostgreSQL or LDAP,"
292                 elog "uncomment the specified rc_named_* lines in your"
293                 elog "/etc/conf.d/named config to ensure they'll start before bind"
294                 einfo
295         }
296         einfo "If you'd like to run bind in a chroot AND this is a new"
297         einfo "install OR your bind doesn't already run in a chroot:"
298         einfo "1) Uncomment and set the CHROOT variable in /etc/conf.d/named."
299         einfo "2) Run \`emerge --config '=${CATEGORY}/${PF}'\`"
300         einfo
301
302         CHROOT=$(source /etc/conf.d/named 2>/dev/null; echo ${CHROOT})
303         if [[ -n ${CHROOT} ]]; then
304                 elog "NOTE: As of net-dns/bind-9.4.3_p5-r1 the chroot part of the init-script got some major changes!"
305                 elog "To enable the old behaviour (without using mount) uncomment the"
306                 elog "CHROOT_NOMOUNT option in your /etc/conf.d/named config."
307                 elog "If you decide to use the new/default method, ensure to make backup"
308                 elog "first and merge your existing configs/zones to /etc/bind and"
309                 elog "/var/bind because bind will now mount the needed directories into"
310                 elog "the chroot dir."
311         fi
312 }
313
314 pkg_config() {
315         CHROOT=$(source /etc/conf.d/named; echo ${CHROOT})
316         CHROOT_NOMOUNT=$(source /etc/conf.d/named; echo ${CHROOT_NOMOUNT})
317         CHROOT_GEOIP=$(source /etc/conf.d/named; echo ${CHROOT_GEOIP})
318
319         if [[ -z "${CHROOT}" ]]; then
320                 eerror "This config script is designed to automate setting up"
321                 eerror "a chrooted bind/named. To do so, please first uncomment"
322                 eerror "and set the CHROOT variable in '/etc/conf.d/named'."
323                 die "Unset CHROOT"
324         fi
325         if [[ -d "${CHROOT}" ]]; then
326                 ewarn "NOTE: As of net-dns/bind-9.4.3_p5-r1 the chroot part of the init-script got some major changes!"
327                 ewarn "To enable the old behaviour (without using mount) uncomment the"
328                 ewarn "CHROOT_NOMOUNT option in your /etc/conf.d/named config."
329                 ewarn
330                 ewarn "${CHROOT} already exists... some things might become overridden"
331                 ewarn "press CTRL+C if you don't want to continue"
332                 sleep 10
333         fi
334
335         echo; einfo "Setting up the chroot directory..."
336
337         mkdir -m 0750 -p ${CHROOT} || die
338         mkdir -m 0755 -p ${CHROOT}/{dev,etc,var/log,run} || die
339         mkdir -m 0750 -p ${CHROOT}/etc/bind || die
340         mkdir -m 0770 -p ${CHROOT}/var/{bind,log/named} ${CHROOT}/run/named/ || die
341
342         chown root:named \
343                 ${CHROOT} \
344                 ${CHROOT}/var/{bind,log/named} \
345                 ${CHROOT}/run/named/ \
346                 ${CHROOT}/etc/bind \
347                 || die
348
349         mknod ${CHROOT}/dev/null c 1 3 || die
350         chmod 0666 ${CHROOT}/dev/null || die
351
352         mknod ${CHROOT}/dev/zero c 1 5 || die
353         chmod 0666 ${CHROOT}/dev/zero || die
354
355         if use urandom; then
356                 mknod ${CHROOT}/dev/urandom c 1 9 || die
357                 chmod 0666 ${CHROOT}/dev/urandom || die
358         else
359                 mknod ${CHROOT}/dev/random c 1 8 || die
360                 chmod 0666 ${CHROOT}/dev/random || die
361         fi
362
363         if [ "${CHROOT_NOMOUNT:-0}" -ne 0 ]; then
364                 cp -a /etc/bind ${CHROOT}/etc/ || die
365                 cp -a /var/bind ${CHROOT}/var/ || die
366         fi
367
368         if [ "${CHROOT_GEOIP:-0}" -eq 1 ]; then
369                 if use geoip; then
370                         mkdir -m 0755 -p ${CHROOT}/usr/share/GeoIP || die
371                 elif use geoip2; then
372                         mkdir -m 0755 -p ${CHROOT}/usr/share/GeoIP2 || die
373                 fi
374         fi
375
376         elog "You may need to add the following line to your syslog-ng.conf:"
377         elog "source jail { unix-stream(\"${CHROOT}/dev/log\"); };"
378 }