Skip to content
Permalink
Browse files

dns-server: Add hard-coded network settings to address portindex issue

* Use default hard-coded example configuration settings
* Put network settings in `post-activate` block as recommended
* Use `awks`'s `$NF` to get default interfaces
* Resolves: https://trac.macports.org/ticket/58668
  • Loading branch information
essandess authored and pmetzger committed Jul 10, 2019
1 parent 9978324 commit e71ee76812fdb3680c25fd5d2f09f710486cecc1
Showing with 103 additions and 86 deletions.
  1. +103 −86 net/dns-server/Portfile
@@ -5,6 +5,7 @@ PortSystem 1.0
name dns-server
# use port:bind9's version as the version number
version 9.14.3
revision 1
categories net
platforms darwin freebsd sunos
supported_archs noarch
@@ -28,23 +29,6 @@ depends_run-append port:bind9

use_configure no

# Network configuration
set named_fullhost [exec /bin/hostname -f]
set named_host [exec /bin/sh -c "echo ${named_fullhost} | /usr/bin/sed -E -e 's|^(\[\[:alnum:\]_-\]+\\.)*((\[\[:alnum:\]_-\]+\\.)\[a-zA-Z0-9-\]{2,24})\\.?|\\1|' | /usr/bin/sed -E -e 's|^(\[\[:alnum:\]_-\]+)\\.?$|\\1|'"]
set named_domaintld [exec /bin/sh -c "echo ${named_fullhost} | /usr/bin/sed -E -e 's|^(\[\[:alnum:\]_-\]+\\.)*((\[\[:alnum:\]_-\]+\\.)\[a-zA-Z0-9-\]{2,24})\\.?|\\2|'"]
set named_domain [exec /bin/sh -c "echo ${named_domaintld} | /usr/bin/sed -E -e 's|^(\[\[:alnum:\]_-\]+)\\.\[a-zA-Z0-9-\]{2,24}\\.?|\\1|'"]
set named_tld [exec /bin/sh -c "echo ${named_domaintld} | /usr/bin/sed -E -e 's|^\[\[:alnum:\]_-\]+\\.(\[a-zA-Z0-9-\]{2,24})\\.?|\\1|'"]
if {${os.platform} eq "darwin" && ${os.major} >= 19} {
set host_lan_ip_address [exec /bin/sh -c "/sbin/ifconfig `/usr/sbin/netstat -nr | /usr/bin/awk '{ if (\$1 ~/default/) { print \$4} }' | /usr/bin/head -1` | /usr/bin/awk '{ if (\$1 ~/inet\$/) { print \$2} }'"]
} else {
set host_lan_ip_address [exec /bin/sh -c "/sbin/ifconfig `/usr/sbin/netstat -nr | /usr/bin/awk '{ if (\$1 ~/default/) { print \$6} }' | /usr/bin/head -1` | /usr/bin/awk '{ if (\$1 ~/inet\$/) { print \$2} }'"]
}
set lan_reverse_ip_subnet [exec /bin/sh -c "echo ${host_lan_ip_address} | /usr/bin/sed -E -e 's|(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\$|\\3.\\2.\\1|'"]
set host_lan_reverse_ip_address [exec /bin/sh -c "echo ${host_lan_ip_address} | /usr/bin/sed -E -e 's|(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\$|\\4.\\3.\\2.\\1|'"]
# aribitrary example for client IP address
set client_lan_ip_address [exec /bin/sh -c "echo ${host_lan_ip_address} | /usr/bin/sed -E -e 's|(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\$|\\1.\\2.\\3.201|'"]
set client_lan_reverse_ip_address [exec /bin/sh -c "echo ${client_lan_ip_address} | /usr/bin/sed -E -e 's|(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\$|\\4.\\3.\\2.\\1|'"]

build {}

destroot {
@@ -54,19 +38,11 @@ destroot {
${destroot}${prefix}/var/named \
${destroot}${prefix}/var/log/named

# Install and configure the conf file
# Install the conf file template
xinstall -o root -m 644 ${filespath}/named.conf \
${destroot}${prefix}/etc/named.conf.macports
reinplace "s|@PREFIX@|${prefix}|g" \
${destroot}${prefix}/etc/named.conf.macports
reinplace "s|@LAN_REVERSE_IP_SUBNET@|${lan_reverse_ip_subnet}|g" \
${destroot}${prefix}/etc/named.conf.macports
reinplace "s|@domain@|${named_domain}|g" \
${destroot}${prefix}/etc/named.conf.macports
reinplace "s|@tld@|${named_tld}|g" \
${destroot}${prefix}/etc/named.conf.macports

# Install and configure the db files
# Install the db file templates
foreach f "\
db.@LAN_REVERSE_IP_SUBNET@.in-addr.arpa \
db.@domain@.@tld@ \
@@ -77,62 +53,70 @@ destroot {
" {
xinstall -o named -g named -m 644 ${filespath}/${f} \
${destroot}${prefix}/var/named/${f}.macports
reinplace "s|@PREFIX@|${prefix}|g" \
${destroot}${prefix}/var/named/${f}.macports
reinplace "s|@host@|${named_host}|g" \
${destroot}${prefix}/var/named/${f}.macports
reinplace "s|@domain@|${named_domain}|g" \
${destroot}${prefix}/var/named/${f}.macports
reinplace "s|@tld@|${named_tld}|g" \
${destroot}${prefix}/var/named/${f}.macports
# case sensitive for Kerberos REALMs
reinplace "s|@HOST@|[string toupper ${named_host}]|g" \
${destroot}${prefix}/var/named/${f}.macports
reinplace "s|@DOMAIN@|[string toupper ${named_domain}]|g" \
${destroot}${prefix}/var/named/${f}.macports
reinplace "s|@TLD@|[string toupper ${named_tld}]|g" \
${destroot}${prefix}/var/named/${f}.macports
reinplace "s|@HOST_LAN_IP_ADDRESS@|${host_lan_ip_address}|g" \
${destroot}${prefix}/var/named/${f}.macports
reinplace "s|@LAN_REVERSE_IP_SUBNET@|${lan_reverse_ip_subnet}|g" \
${destroot}${prefix}/var/named/${f}.macports
reinplace "s|@HOST_LAN_REVERSE_IP_ADDRESS@|${host_lan_reverse_ip_address}|g" \
${destroot}${prefix}/var/named/${f}.macports
reinplace "s|@CLIENT_LAN_IP_ADDRESS@|${client_lan_ip_address}|g" \
${destroot}${prefix}/var/named/${f}.macports
reinplace "s|@CLIENT_LAN_REVERSE_IP_ADDRESS@|${client_lan_reverse_ip_address}|g" \
${destroot}${prefix}/var/named/${f}.macports
}
move ${destroot}${prefix}/var/named/db.@LAN_REVERSE_IP_SUBNET@.in-addr.arpa.macports \
${destroot}${prefix}/var/named/db.${lan_reverse_ip_subnet}.in-addr.arpa.macports
move ${destroot}${prefix}/var/named/db.@domain@.@tld@.macports \
${destroot}${prefix}/var/named/db.${named_domain}.${named_tld}.macports
move ${destroot}${prefix}/var/named/db.@domain@.private.macports \
${destroot}${prefix}/var/named/db.${named_domain}.private.macports

ui_msg "Configuring DNS Server with:
Host ${named_host}
Domain ${named_domain}
TLD ${named_tld}
Host IP Address ${host_lan_ip_address}
Reverse IP Subnet ${lan_reverse_ip_subnet}
This configuration can be changed in the directory\:
${prefix}/var/named
See `man named` for details.
"
}

destroot.keepdirs ${destroot}${prefix}/var/log/named

# Network configuration
# hard-coded examples
set named_fullhost host.domain.tld
set named_host host
set named_domaintld domain.tld
set named_domain domain
set named_tld tld
set host_lan_ip_address 10.0.1.2
set lan_reverse_ip_subnet 1.0.10
set host_lan_reverse_ip_address 2.1.0.10
# aribitrary example for client IP address
set client_lan_ip_address 10.0.1.3
set client_lan_reverse_ip_address 3.1.0.10

post-activate {
# use network settings for installed example configuration
set named_fullhost [exec /bin/hostname -f]
set named_host [exec /bin/sh -c "echo ${named_fullhost} | /usr/bin/sed -E -e 's|^(\[\[:alnum:\]_-\]+\\.)*((\[\[:alnum:\]_-\]+\\.)\[a-zA-Z0-9-\]{2,24})\\.?|\\1|' | /usr/bin/sed -E -e 's|^(\[\[:alnum:\]_-\]+)\\.?$|\\1|'"]
set named_domaintld [exec /bin/sh -c "echo ${named_fullhost} | /usr/bin/sed -E -e 's|^(\[\[:alnum:\]_-\]+\\.)*((\[\[:alnum:\]_-\]+\\.)\[a-zA-Z0-9-\]{2,24})\\.?|\\2|'"]
set named_domain [exec /bin/sh -c "echo ${named_domaintld} | /usr/bin/sed -E -e 's|^(\[\[:alnum:\]_-\]+)\\.\[a-zA-Z0-9-\]{2,24}\\.?|\\1|'"]
set named_tld [exec /bin/sh -c "echo ${named_domaintld} | /usr/bin/sed -E -e 's|^\[\[:alnum:\]_-\]+\\.(\[a-zA-Z0-9-\]{2,24})\\.?|\\1|'"]
set host_lan_ip_address [exec /bin/sh -c "/sbin/ifconfig `/usr/sbin/netstat -nr | /usr/bin/awk '{ if (\$1 ~/default/) { print \$NF} }' | /usr/bin/head -1` | /usr/bin/awk '{ if (\$1 ~/inet\$/) { print \$2} }'"]
set lan_reverse_ip_subnet [exec /bin/sh -c "echo ${host_lan_ip_address} | /usr/bin/sed -E -e 's|(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\$|\\3.\\2.\\1|'"]
set host_lan_reverse_ip_address [exec /bin/sh -c "echo ${host_lan_ip_address} | /usr/bin/sed -E -e 's|(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\$|\\4.\\3.\\2.\\1|'"]
# aribitrary example for client IP address
set client_lan_ip_address [exec /bin/sh -c "echo ${host_lan_ip_address} | /usr/bin/sed -E -e 's|(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\$|\\1.\\2.\\3.201|'"]
set client_lan_reverse_ip_address [exec /bin/sh -c "echo ${client_lan_ip_address} | /usr/bin/sed -E -e 's|(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\\.(\[\[:digit:\]\]{1,3})\$|\\4.\\3.\\2.\\1|'"]

# copy to actual config files if they don't already exist
if ![file exists ${prefix}/etc/named.conf] {
# Configure the conf file
xinstall -o root -g named -m 644 ${prefix}/etc/named.conf.macports \
${prefix}/etc/named.conf
reinplace "s|@PREFIX@|${prefix}|g" \
${prefix}/etc/named.conf
reinplace "s|@LAN_REVERSE_IP_SUBNET@|${lan_reverse_ip_subnet}|g" \
${prefix}/etc/named.conf
reinplace "s|@domain@|${named_domain}|g" \
${prefix}/etc/named.conf
reinplace "s|@tld@|${named_tld}|g" \
${prefix}/etc/named.conf
}
# Configure the db file templates
foreach f "\
db.@LAN_REVERSE_IP_SUBNET@.in-addr.arpa \
db.@domain@.@tld@ \
db.@domain@.private \
localhost.zone \
named.ca \
named.local \
" {
set f_renamed $f
set f_renamed [ strsed $f_renamed "s|@domain@|${named_domain}|" ]
set f_renamed [ strsed $f_renamed "s|@tld@|${named_tld}|" ]
set f_renamed [ strsed $f_renamed "s|@LAN_REVERSE_IP_SUBNET@|${lan_reverse_ip_subnet}|" ]
if ![file exists ${prefix}/var/named/${f_renamed}] {
xinstall -m 0644 -W ${prefix}/var/named \
${f}.macports ${f_renamed}
}
}
foreach f "\
db.${lan_reverse_ip_subnet}.in-addr.arpa \
@@ -142,46 +126,79 @@ post-activate {
named.ca \
named.local \
" {
if ![file exists ${prefix}/var/named/${f}] {
xinstall -o named -g named -m 644 ${prefix}/var/named/${f}.macports \
${prefix}/var/named/${f}
}
reinplace "s|@PREFIX@|${prefix}|g" \
${prefix}/var/named/${f}
reinplace "s|@host@|${named_host}|g" \
${prefix}/var/named/${f}
reinplace "s|@domain@|${named_domain}|g" \
${prefix}/var/named/${f}
reinplace "s|@tld@|${named_tld}|g" \
${prefix}/var/named/${f}
# case sensitive for Kerberos REALMs
reinplace "s|@HOST@|[string toupper ${named_host}]|g" \
${prefix}/var/named/${f}
reinplace "s|@DOMAIN@|[string toupper ${named_domain}]|g" \
${prefix}/var/named/${f}
reinplace "s|@TLD@|[string toupper ${named_tld}]|g" \
${prefix}/var/named/${f}
reinplace "s|@HOST_LAN_IP_ADDRESS@|${host_lan_ip_address}|g" \
${prefix}/var/named/${f}
reinplace "s|@LAN_REVERSE_IP_SUBNET@|${lan_reverse_ip_subnet}|g" \
${prefix}/var/named/${f}
reinplace "s|@HOST_LAN_REVERSE_IP_ADDRESS@|${host_lan_reverse_ip_address}|g" \
${prefix}/var/named/${f}
reinplace "s|@CLIENT_LAN_IP_ADDRESS@|${client_lan_ip_address}|g" \
${prefix}/var/named/${f}
reinplace "s|@CLIENT_LAN_REVERSE_IP_ADDRESS@|${client_lan_reverse_ip_address}|g" \
${prefix}/var/named/${f}
}
if ![file exists ${prefix}/var/named/rndc.key] {
system "${prefix}/sbin/rndc-confgen -A hmac-sha512 -a -c ${prefix}/var/named/rndc.key -u named"
}
}


notes "
DNS Server is configured with\:
ui_msg "Configuring DNS Server with:
Host ${named_host}
Domain ${named_domain}
TLD ${named_tld}
Host IP Address ${host_lan_ip_address}
Reverse IP Subnet ${lan_reverse_ip_subnet}
This configuration can be changed in the directory\:
This configuration can be changed in the directory:
${prefix}/var/named
See `man named` for details.
"
}


notes "
The DNS server's initial configuration uses installation-time network
settings to provide a basic, working DNS server.
Users must reconfigure the installation for their own network
specifics by editing the files:
${prefix}/etc/named.conf
${prefix}/var/named/db.*
Refer to the *.macports template files and `man named` for details.
Post Installation\:
Post Installation:
1. Edit files in the directory ${prefix}/var/named to specify correct DNS
and reverse DNS entries. Example: These two commands should point to
each other\:
each other:
host ${named_host} ${host_lan_ip_address}
host ${host_lan_ip_address} ${host_lan_ip_address}
A rndc.key fil is automatically created with the command\:
A rndc.key fil is automatically created with the command:
rndc-confgen -A hmac-sha512 -a -c ${prefix}/var/named/rndc.key -u named
2. It is necessary to launch named with\:
2. It is necessary to launch named with:
sudo port load bind9

0 comments on commit e71ee76

Please sign in to comment.
You can’t perform that action at this time.