dnsmasq.in | 31 ++++++++++++++++--------------- libc.in | 13 +++---------- named.in | 20 +++++++++++++++++--- pdns_recursor.in | 2 +- resolvconf.8.in | 2 +- resolvconf.conf | 11 ++++++++++- resolvconf.conf.5.in | 2 +- resolvconf.in | 22 ++++++++++++---------- 8 files changed, 61 insertions(+), 42 deletions(-) diff --git a/dnsmasq.in b/dnsmasq.in index 16220a2..ea572f8 100644 --- a/dnsmasq.in +++ b/dnsmasq.in @@ -29,8 +29,12 @@ [ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0 . "@SYSCONFDIR@/resolvconf.conf" || exit 1 [ -z "$dnsmasq_conf" -o -z "$dnsmasq_resolv" ] && exit 0 +[ -f "$dnsmasq_conf" -a -f "$dnsmasq_resolv" ] || exit 0 [ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)" +DNSMASQ="${DNSMASQ:-/usr/sbin/dnsmasq}" +DBUS_SEND="${DBUS_SEND:-/usr/bin/dbus-send}" + : ${dnsmasq_pid:=/var/run/dnsmasq.pid} : ${dnsmasq_restart:=@RESTARTCMD dnsmasq@} newconf="# Generated by resolvconf\n" @@ -42,16 +46,14 @@ newresolv="$newconf" # so we need to validate a few things first. # Check for DBus support in the binary dbus=false -: ${dbus_pid:=/var/run/dbus/dbus.pid} -[ -s "$dbus_pid" ] || dbus_pid=/var/run/dbus.pid -[ -s "$dbus_pid" ] || dbus_pid=/var/run/dbus/pid -if [ -s "$dbus_pid" -a -s "$dnsmasq_pid" ]; then - if dnsmasq --version 2>/dev/null | \ +: ${dbus_pid:=/var/run/messagebus.pid} +if [ -x "$DNSMASQ" -a -x "$DBUS_SEND" -a -s "$dbus_pid" -a -s "$dnsmasq_pid" ]; then + if "$DNSMASQ" --version 2>/dev/null | \ grep -q "^Compile time options.*[[:space:]]DBus[[:space:]]" then # Sanity - check that dnsmasq and dbus are running - if kill -0 $(cat "$dbus_pid") 2>/dev/null && \ - kill -0 $(cat "$dnsmasq_pid") 2>/dev/null + if kill -0 "$(cat "$dbus_pid")" 2>/dev/null && \ + kill -0 "$(cat "$dnsmasq_pid")" 2>/dev/null then dbus=true newconf="$newconf\n# Domain specific servers will" @@ -69,15 +71,15 @@ for d in $DOMAINS; do dn="${d%%:*}" ns="${d#*:}" while [ -n "$ns" ]; do - if $dbus; then - SIFS=${IFS-y} OIFS=$IFS + if "$dbus"; then + SIFS="${IFS-y}" OIFS="$IFS" IFS=. set -- ${ns%%,*} num="0x$(printf "%02x" $1 $2 $3 $4)" if [ "$SIFS" = yi ]; then unset IFS else - IFS=$OIFS + IFS="$OIFS" fi dbusdest="$dbusdest uint32:$(printf "%u" $num)" dbusdest="$dbusdest string:$dn" @@ -106,13 +108,12 @@ else printf "$newresolv" >"$dnsmasq_resolv" fi -if $changed; then - eval $dnsmasq_restart +if "$changed"; then + eval "$dnsmasq_restart" fi -if $dbus; then - $restart || kill -HUP $(cat "$dnsmasq_pid") +if "$dbus"; then # Send even if empty so old servers are cleared - dbus-send --system --dest=uk.org.thekelleys.dnsmasq \ + "$DBUS_SEND" --system --dest=uk.org.thekelleys.dnsmasq \ /uk/org/thekelleys/dnsmasq uk.org.thekelleys.SetServers \ $dbusdest fi diff --git a/libc.in b/libc.in index 946e094..b68651d 100644 --- a/libc.in +++ b/libc.in @@ -77,7 +77,6 @@ elif [ -d "$SYSCONFDIR"/resolvconf ]; then fi fi : ${resolv_conf:=/etc/resolv.conf} -: ${libc_restart:=@RESTARTCMD nscd@} : ${list_resolv:=@PREFIX@/sbin/resolvconf -l} uniqify() @@ -107,7 +106,7 @@ case "${resolv_conf_passthrough:-NO}" in *) [ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)" newsearch="$(uniqify $search_domains $SEARCH)" - newns="$(uniqify $name_servers $NAMESERVERS)" + newns="$(uniqify $name_servers $LIBC_NAMESERVERS)" # Hold our new resolv.conf in a variable to save on temporary files newconf="# Generated by resolvconf\n" @@ -145,12 +144,6 @@ fi (umask 022; printf "$newconf" >"$resolv_conf") eval $libc_restart -retval=0 # Notify users of the resolver -for script in "$LIBEXECDIR"/libc.d/*; do - if [ -f "$script" -a -x "$script" ]; then - "$script" "$@" - retval=$(($retval + $?)) - fi -done -exit $retval +run-parts /etc/hooks/resolv.conf.d "$@" + diff --git a/named.in b/named.in index da0dc68..67f719c 100644 --- a/named.in +++ b/named.in @@ -28,10 +28,21 @@ [ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0 . "@SYSCONFDIR@/resolvconf.conf" || exit 1 -[ -z "$named_zones" -o -z "$named_options" ] && exit 0 +[ -n "$named_zones" -a -n "$named_options" -a \ + -d "${named_zones%/*}" -a -d "${named_options%/*}" ] || exit 0 [ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)" -: ${named_restart:=@RESTARTCMD named@} +: ${named_restart:=@RESTARTCMD bind@} + +list_own_zones() +{ + find "${named_zones%/*}" \ + -type f \( -name '*.conf' -a \! -name "${named_zones##*/}" \) \ + -exec sed -n 's/zone[[:space:]]\+"\([^"]\+\)\".*/\1/p' '{}' \+ |grep -v 'in-addr\.arpa$'|tr '\n' ' ' +} + +ownzones=" $(list_own_zones) " + newoptions="# Generated by resolvconf\n" newzones="$newoptions" @@ -47,7 +58,9 @@ if [ -n "$forward" ]; then fi for d in $DOMAINS; do - newzones="${newzones}zone \"${d%%:*}\" {\n" + zone="${d%%:*}" + [ -n "${ownzones## *$zone* }" ] || continue + newzones="${newzones}zone \"$zone\" {\n" newzones="$newzones\ttype forward;\n" newzones="$newzones\tforward first;\n\tforwarders {\n" ns="${d#*:}" @@ -78,3 +91,4 @@ fi if $changed; then eval $named_restart fi +exit 0 diff --git a/pdns_recursor.in b/pdns_recursor.in index 7e7c663..e44425a 100644 --- a/pdns_recursor.in +++ b/pdns_recursor.in @@ -31,7 +31,7 @@ [ -z "$pdns_zones" ] && exit 0 [ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)" -: ${pdns_restart:=@RESTARTCMD pdns_recursor@} +: ${pdns_restart:=@RESTARTCMD powerdns@} newzones= diff --git a/resolvconf.8.in b/resolvconf.8.in index 8097636..44cea2a 100644 --- a/resolvconf.8.in +++ b/resolvconf.8.in @@ -179,7 +179,7 @@ Configuration file for Directory of subscribers which are run every time .Nm adds, deletes or updates. -.It Pa @LIBEXECDIR@/libc.d +.It Pa /etc/hooks/resolv.conf.d Directory of subscribers which are run after the libc subscriber is run. .It Pa @VARDIR@ State directory for diff --git a/resolvconf.conf b/resolvconf.conf index 607f6af..9d27817 100644 --- a/resolvconf.conf +++ b/resolvconf.conf @@ -1,7 +1,16 @@ # Configuration for resolvconf(8) # See resolvconf.conf(5) for details +resolv_conf_head='# Do not edit manually, use\n# /etc/net/ifaces//resolv.conf instead.' resolv_conf=/etc/resolv.conf # If you run a local name server, you should uncomment the below line and # configure your subscribers configuration files below. -#name_servers=127.0.0.1 \ No newline at end of file +#name_servers=127.0.0.1 + +#Configuration files for named subscriber. +named_zones=/var/lib/bind/etc/resolvconf-zones.conf +named_options=/var/lib/bind/etc/resolvconf-options.conf + +#Configuration files for dnsmasq subscriber. +dnsmasq_conf=/etc/dnsmasq.conf.resolvconf +dnsmasq_resolv=/etc/resolv.conf.dnsmasq diff --git a/resolvconf.conf.5.in b/resolvconf.conf.5.in index 18ce8b4..33b8796 100644 --- a/resolvconf.conf.5.in +++ b/resolvconf.conf.5.in @@ -41,7 +41,7 @@ to apply the new configuration. .It Sy interface_order These interfaces will always be processed first. If unset, defaults to the following:- -.D1 lo lo[0-9]* +.D1 lo lo[0-9]* lo.* .It Sy dynamic_order These interfaces will be processed next, unless they have a metric. If unset, defaults to the following:- diff --git a/resolvconf.in b/resolvconf.in index 13bd847..589d09d 100644 --- a/resolvconf.in +++ b/resolvconf.in @@ -43,7 +43,7 @@ elif [ -d "$SYSCONFDIR/resolvconf" ]; then fi fi : ${dynamic_order:=tap[0-9]* tun[0-9]* vpn vpn[0-9]* ppp[0-9]* ippp[0-9]*} -: ${interface_order:=lo lo[0-9]*} +: ${interface_order:=lo lo[0-9]* lo.*} error_exit() { @@ -98,12 +98,13 @@ echo_resolv() # for domain name servers, search name servers and global nameservers parse_resolv() { - local line= ns= ds= search= d= n= newns= + local line= ns= libc_ns= ds= search= d= n= newns= local new=true iface= private=false echo "DOMAINS=" echo "SEARCH=" echo "NAMESERVERS=" + echo "LIBC_NAMESERVERS=" while read line; do case "$line" in @@ -127,9 +128,13 @@ parse_resolv() ;; "nameserver "*) case "${line#* }" in - 127.*|0.0.0.0|255.255.255.255) continue;; + 0.0.0.0|255.255.255.255) continue;; + 127.*) + libc_ns="$libc_ns${line#* } " + continue;; esac ns="$ns${line#* } " + libc_ns="$libc_ns${line#* } " ;; "domain "*|"search "*) search="${line#* }" @@ -150,8 +155,10 @@ parse_resolv() echo "SEARCH=\"\$SEARCH $search\"" if ! $private; then echo "NAMESERVERS=\"\$NAMESERVERS $ns\"" + echo "LIBC_NAMESERVERS=\"\$LIBC_NAMESERVERS $libc_ns\"" fi ns= + libc_ns= search= new=true ;; @@ -255,6 +262,7 @@ make_vars() echo "DOMAINS='$newdomains'" echo "SEARCH='$(uniqify $SEARCH)'" echo "NAMESERVERS='$(uniqify $NAMESERVERS)'" + echo "LIBC_NAMESERVERS='$(uniqify $LIBC_NAMESERVERS)'" } force=false @@ -382,10 +390,4 @@ fi eval "$(make_vars)" : ${list_resolv:=list_resolv -l} -retval=0 -for script in "$LIBEXECDIR"/*; do - [ -f "$script" ] || continue - ( . "$script" "$cmd" "$iface" ) - retval=$(($retval + $?)) -done -exit $retval +run-parts "$LIBEXECDIR" "$cmd" "$iface"