1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
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.
15 PYTHON_COMPAT=( python3_{6,7} )
17 inherit python-r1 eutils autotools toolchain-funcs flag-o-matic multilib db-use user systemd
20 MY_PV="${MY_PV/_rc/rc}"
23 SDB_LDAP_VER="1.1.0-fc14"
27 # SDB-LDAP: http://bind9-ldap.bayour.com/
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 )"
34 # http://ftp.disconnected-by-peer.at/pub/bind-sdb-ldap-${SDB_LDAP_VER}.patch.bz2
37 LICENSE="Apache-2.0 BSD BSD-2 GPL-2 HPND ISC MPL-2.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
44 # sdb-ldap - patch broken
45 # no PKCS11 currently as it requires OpenSSL to be patched, also see bug 409687
55 python? ( ${PYTHON_REQUIRED_USE} )"
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:= )
71 zlib? ( sys-libs/zlib )
72 dnstap? ( dev-libs/fstrm dev-libs/protobuf-c )
75 dev-python/ply[${PYTHON_USEDEP}]
77 # sdb-ldap? ( net-nds/openldap )
80 selinux? ( sec-policy/selinux-bind )
83 S="${WORKDIR}/${MY_P}"
85 # bug 479092, requires networking
89 "${FILESDIR}"/bind-9.14.8-mysql8-bool.patch
93 ebegin "Creating named group and user"
95 enewuser named 40 -1 /etc/bind named
102 export LDFLAGS="${LDFLAGS} -L${EPREFIX}/usr/$(get_libdir) -ldl"
104 # Adjusting PATHs in manpages
105 for i in bin/{named/named.8,check/named-checkconf.8,rndc/rndc.8} ; do
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"
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/
125 # should be installed by bind-tools
126 sed -i -r -e "s:(nsupdate|dig|delv) ::g" bin/Makefile.in || die
128 # Disable tests for now, bug 406399
129 sed -i '/^SUBDIRS/s:tests::' bin/Makefile.in lib/Makefile.in || die
133 rm -rf libtool.m4/ || die
139 --sysconfdir=/etc/bind
144 --with-openssl="${EPREFIX}"/usr
145 $(use_enable caps linux-caps)
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)
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)
162 $(use_with xml libxml2)
166 use geoip && myeconfargs+=( --with-geoip )
167 use geoip2 && myeconfargs+=( --with-geoip2 )
170 # gcc-specs-ssp && replace-flags -O[23s] -O
172 # To include db.h from proper path
173 use berkdb && append-flags "-I$(db_includedir)"
175 export BUILD_CC=$(tc-getBUILD_CC)
176 econf "${myeconfargs[@]}"
179 echo '#undef SO_BSDCOMPAT' >> config.h
188 dodoc doc/arm/Bv9ARM.pdf
193 # might a 'html' useflag make sense?
198 dodoc contrib/scripts/{nanny.pl,named-bootconf.sh}
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
207 newins "${FILESDIR}"/named.conf-r8 named.conf
209 # ftp://ftp.rs.internic.net/domain/named.cache:
211 newins "${FILESDIR}"/named.cache-r3 named.cache
213 insinto /var/bind/pri
214 newins "${FILESDIR}"/localhost.zone-r3 localhost.zone
216 newinitd "${FILESDIR}"/named.init-r13 named
217 newconfd "${FILESDIR}"/named.confd-r7 named
219 newenvd "${FILESDIR}"/10bind.env 10bind
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
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
238 find "${ED}" -type f -name '*.la' -delete || die
241 install_python_tools() {
242 dosbin bin/python/dnssec-{checkds,coverage}
244 python_foreach_impl install_python_tools
246 python_replicate_script "${ED}/usr/sbin/dnssec-checkds"
247 python_replicate_script "${ED}/usr/sbin/dnssec-coverage"
251 dosym named.cache /var/bind/root.cache
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}
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}
266 systemd_newunit "${FILESDIR}/named.service-r1" named.service
267 systemd_dotmpfilesd "${FILESDIR}"/named.conf
269 doexe "${FILESDIR}/generate-rndc-key.sh"
273 if [ ! -f '/etc/bind/rndc.key' ]; then
275 einfo "Using /dev/urandom for generating rndc.key"
276 /usr/sbin/rndc-confgen -r /dev/urandom -a
279 einfo "Using /dev/random for generating rndc.key"
280 /usr/sbin/rndc-confgen -a
283 chown root:named /etc/bind/rndc.key || die
284 chmod 0640 /etc/bind/rndc.key || die
288 einfo "You can edit /etc/conf.d/named to customize named settings"
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"
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}'\`"
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."
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})
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'."
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."
330 ewarn "${CHROOT} already exists... some things might become overridden"
331 ewarn "press CTRL+C if you don't want to continue"
335 echo; einfo "Setting up the chroot directory..."
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
344 ${CHROOT}/var/{bind,log/named} \
345 ${CHROOT}/run/named/ \
349 mknod ${CHROOT}/dev/null c 1 3 || die
350 chmod 0666 ${CHROOT}/dev/null || die
352 mknod ${CHROOT}/dev/zero c 1 5 || die
353 chmod 0666 ${CHROOT}/dev/zero || die
356 mknod ${CHROOT}/dev/urandom c 1 9 || die
357 chmod 0666 ${CHROOT}/dev/urandom || die
359 mknod ${CHROOT}/dev/random c 1 8 || die
360 chmod 0666 ${CHROOT}/dev/random || die
363 if [ "${CHROOT_NOMOUNT:-0}" -ne 0 ]; then
364 cp -a /etc/bind ${CHROOT}/etc/ || die
365 cp -a /var/bind ${CHROOT}/var/ || die
368 if [ "${CHROOT_GEOIP:-0}" -eq 1 ]; 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
376 elog "You may need to add the following line to your syslog-ng.conf:"
377 elog "source jail { unix-stream(\"${CHROOT}/dev/log\"); };"