Makefile | 4 +- dnsmasq.in | 8 ++-- libc.in | 9 +++-- named.in | 32 +++++++--------- resolvconf.8.in | 2 +- resolvconf.conf | 18 +++++++-- resolvconf.conf.5.in | 2 +- resolvconf.in | 102 +++++++-------------------------------------------- 8 files changed, 57 insertions(+), 120 deletions(-) diff --git a/Makefile b/Makefile index 73fbb9a..2a24ba2 100644 --- a/Makefile +++ b/Makefile @@ -72,9 +72,9 @@ proginstall: ${TARGET} ${INSTALL} -m ${DOCMODE} resolvconf.conf ${DESTDIR}${SYSCONFDIR} ${INSTALL} -d ${DESTDIR}${LIBEXECDIR} ${INSTALL} -m ${DOCMODE} ${SUBSCRIBERS} ${DESTDIR}${LIBEXECDIR} - ${INSTALL} -d ${DESTDIR}${LIBEXECDIR}/libc.d + ${INSTALL} -d ${DESTDIR}${SYSCONFDIR}/hooks/resolv.conf.d ${INSTALL} -m ${DOCMODE} ${LIBC_SUBSCRIBERS} \ - ${DESTDIR}${LIBEXECDIR}/libc.d + ${DESTDIR}${SYSCONFDIR}/hooks/resolv.conf.d maninstall: ${INSTALL} -d ${DESTDIR}${MANDIR}/man8 diff --git a/dnsmasq.in b/dnsmasq.in index 8014eed..c0c03c8 100644 --- a/dnsmasq.in +++ b/dnsmasq.in @@ -28,11 +28,13 @@ [ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0 . "@SYSCONFDIR@/resolvconf.conf" || exit 1 -[ -z "${dnsmasq_conf}${dnsmasq_resolv}" ] && exit 0 +[ -z "$dnsmasq_conf" -o -z "$dnsmasq_resolv" ] && exit 0 [ -z "$RESOLVCONF" ] && eval "$(@SBINDIR@/resolvconf -v)" NL=" " +DBUS_SEND="${DBUS_SEND:-/usr/bin/dbus-send}" + : ${dnsmasq_pid:=/var/run/dnsmasq.pid} [ -s "$dnsmasq_pid" ] || dnsmasq_pid=/var/run/dnsmasq/dnsmasq.pid [ -s "$dnsmasq_pid" ] || unset dnsmasq_pid @@ -47,7 +49,7 @@ newresolv="$newconf" # Check for DBus support in the binary dbus=false dbus_ex=false -dbus_introspect=$(dbus-send --print-reply --system \ +dbus_introspect=$($DBUS_SEND --print-reply --system \ --dest=uk.org.thekelleys.dnsmasq \ /uk/org/thekelleys/dnsmasq \ org.freedesktop.DBus.Introspectable.Introspect \ @@ -203,7 +205,7 @@ if $dbus; then else method=SetServers fi - dbus-send --system --dest=uk.org.thekelleys.dnsmasq \ + $DBUS_SEND --system --dest=uk.org.thekelleys.dnsmasq \ /uk/org/thekelleys/dnsmasq uk.org.thekelleys.$method \ $dbusdest dbus-send --system --dest=uk.org.thekelleys.dnsmasq \ diff --git a/libc.in b/libc.in index 2b291b7..ef21de1 100644 --- a/libc.in +++ b/libc.in @@ -174,7 +174,7 @@ case "${resolv_conf_passthrough:-NO}" in # Hold our new resolv.conf in a variable to save on temporary files newconf="$signature$NL" if [ -n "$resolv_conf_head" ]; then - newconf="$newconf$resolv_conf_head$NL" + newconf="$newconf$(printf "$resolv_conf_head")$NL" fi [ -n "$domain" ] && newconf="${newconf}domain $domain$NL" @@ -200,7 +200,7 @@ case "${resolv_conf_passthrough:-NO}" in fi if [ -n "$resolv_conf_tail" ]; then - newconf="$newconf$resolv_conf_tail$NL" + newconf="$newconf$(printf "$resolv_conf_tail")$NL" fi ;; esac @@ -239,7 +239,10 @@ fi retval=0 # Notify users of the resolver -for script in "$LIBEXECDIR"/libc.d/*; do +for script in "$SYSCONFDIR"/hooks/resolv.conf.d/*; do + # Don't run *.rpm* and *~ scripts. + [ "${script%.rpm*}" = "$script" -a "${script%\~}" = "$script" ] || continue + if [ -f "$script" ]; then if [ -x "$script" ]; then "$script" "$@" diff --git a/named.in b/named.in index 3301896..143b20c 100644 --- a/named.in +++ b/named.in @@ -28,29 +28,22 @@ [ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0 . "@SYSCONFDIR@/resolvconf.conf" || exit 1 -[ -z "${named_zones}${named_options}" ] && exit 0 +[ -n "$named_zones" -a -n "$named_options" -a \ + -d "${named_zones%/*}" -a -d "${named_options%/*}" ] || exit 0 [ -z "$RESOLVCONF" ] && eval "$(@SBINDIR@/resolvconf -v)" NL=" " -# Platform specific kludges -if [ -z "${named_service}${named_restart}" ] && - [ -d "$RCDIR" ] && ! [ -x "$RCDIR"/named ] -then - if [ -x "$RCDIR"/bind9 ]; then - # Debian and derivatives - named_service=bind9 - elif [ -x "$RCDIR"/rc.bind ]; then - # Slackware - named_service=rc.bind - fi -fi -: ${named_service:=named} +: ${named_service:=bind} -: ${named_pid:=/var/run/$named_service.pid} -[ -s "$named_pid" ] || named_pid=/var/run/$named_service/$named_service.pid -[ -s "$named_pid" ] || unset named_pid +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$NL" newzones="$newoptions" @@ -66,7 +59,9 @@ if [ -n "$forward" ]; then fi for d in $DOMAINS; do - newzones="${newzones}zone \"${d%%:*}\" {$NL" + zone="${d%%:*}" + [ -n "${ownzones## *$zone* }" ] || continue + newzones="${newzones}zone \"$zone\" {$NL" newzones="$newzones type forward;$NL" newzones="$newzones forward first;$NL forwarders {$NL" ns="${d#*:}" @@ -116,3 +111,4 @@ if $changed; then @SBINDIR@/resolvconf -r ${named_service} fi fi +exit 0 diff --git a/resolvconf.8.in b/resolvconf.8.in index 39020e9..8f63b45 100644 --- a/resolvconf.8.in +++ b/resolvconf.8.in @@ -302,7 +302,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 4f5f2e6..c75ea6e 100644 --- a/resolvconf.conf +++ b/resolvconf.conf @@ -1,7 +1,19 @@ # 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 + +# These interfaces will always be processed first. +interface_order='lo lo[0-9]* lo.*' + +# These interfaces will be processed next, unless they have a metric. +dynamic_order='tap[0-9]* tun[0-9]* vpn vpn[0-9]* wg[0-9]* ppp[0-9]* ippp[0-9]*' + +#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.d/60-resolvconf +dnsmasq_resolv=/etc/resolv.conf.dnsmasq diff --git a/resolvconf.conf.5.in b/resolvconf.conf.5.in index b36e867..8044676 100644 --- a/resolvconf.conf.5.in +++ b/resolvconf.conf.5.in @@ -69,7 +69,7 @@ If set, these interfaces will not be processed. These interfaces will always be processed first. If unset, defaults to the following:- .Bd -compact -literal -offset indent -lo lo[0-9]* +lo lo[0-9]* lo.* .Ed .It Sy dynamic_order These interfaces will be processed next, unless they have a metric. diff --git a/resolvconf.in b/resolvconf.in index 198096b..dddba5c 100644 --- a/resolvconf.in +++ b/resolvconf.in @@ -45,7 +45,7 @@ unset interface_order state_dir local_nameservers="127.* 0.0.0.0 255.255.255.255 ::1" dynamic_order="tap[0-9]* tun[0-9]* vpn vpn[0-9]* wg[0-9]* ppp[0-9]* ippp[0-9]*" -interface_order="lo lo[0-9]*" +interface_order="lo lo[0-9]* lo.*" name_server_blacklist="0.0.0.0" # Support original resolvconf configuration layout @@ -298,95 +298,15 @@ detect_init() { [ -n "$RESTARTCMD" ] && return 0 - # Detect the running init system. - # As systemd and OpenRC can be installed on top of legacy init - # systems we try to detect them first. - status="@STATUSARG@" - : ${status:=status} - if [ -x /bin/systemctl ] && [ -S /run/systemd/private ]; then - RESTARTCMD=' - if /bin/systemctl --quiet is-active $1.service - then - /bin/systemctl restart $1.service - fi' - elif [ -x /usr/bin/systemctl ] && [ -S /run/systemd/private ]; then - RESTARTCMD=' - if /usr/bin/systemctl --quiet is-active $1.service - then - /usr/bin/systemctl restart $1.service - fi' - elif [ -x /sbin/rc-service ] && - { [ -s /libexec/rc/init.d/softlevel ] || - [ -s /run/openrc/softlevel ]; } - then - RESTARTCMD='/sbin/rc-service -i $1 -- -Ds restart' - elif [ -x /usr/sbin/invoke-rc.d ]; then - RCDIR=/etc/init.d - RESTARTCMD=' - if /usr/sbin/invoke-rc.d --quiet $1 status >/dev/null 2>&1 - then - /usr/sbin/invoke-rc.d $1 restart - fi' - elif [ -x /sbin/service ]; then - # Old RedHat - RCDIR=/etc/init.d - RESTARTCMD=' - if /sbin/service $1; then - /sbin/service $1 restart - fi' - elif [ -x /usr/sbin/service ]; then - # Could be FreeBSD - RESTARTCMD=" - if /usr/sbin/service \$1 $status >/dev/null 2>&1 - then - /usr/sbin/service \$1 restart - fi" - elif [ -x /bin/sv ]; then - RESTARTCMD='/bin/sv status $1 >/dev/null 2>&1 && - /bin/sv try-restart $1' - elif [ -x /usr/bin/sv ]; then - RESTARTCMD='/usr/bin/sv status $1 >/dev/null 2>&1 && - /usr/bin/sv try-restart $1' - elif [ -e /etc/arch-release ] && [ -d /etc/rc.d ]; then - RCDIR=/etc/rc.d - RESTARTCMD=' - if [ -e /var/run/daemons/$1 ] - then - /etc/rc.d/$1 restart - fi' - elif [ -e /etc/slackware-version ] && [ -d /etc/rc.d ]; then - RESTARTCMD=' - if /etc/rc.d/rc.$1 status >/dev/null 2>&1 - then - /etc/rc.d/rc.$1 restart - fi' - elif [ -e /etc/rc.d/rc.subr ] && [ -d /etc/rc.d ]; then - # OpenBSD - RESTARTCMD=' - if /etc/rc.d/$1 check >/dev/null 2>&1 - then - /etc/rc.d/$1 restart - fi' + local SYSTEMCTL=systemctl + local SERVICE=service + + if sd_booted; then + RESTARTCMD="$SYSTEMCTL --quiet is-active \"\$1\".service && $SYSTEMCTL restart \"\$1\".service ||:" else - for x in /etc/init.d/rc.d /etc/rc.d /etc/init.d; do - [ -d $x ] || continue - RESTARTCMD=" - if $x/\$1 $status >/dev/null 2>&1 - then - $x/\$1 restart - fi" - break - done + RESTARTCMD="$SERVICE \"\$1\" status 1>/dev/null 2>&1 && $SERVICE \"\$1\" restart ||:" fi - if [ -z "$RESTARTCMD" ]; then - if [ "$_NOINIT_WARNED" != true ]; then - warn "could not detect a useable init system" - _NOINIT_WARNED=true - fi - return 1 - fi - _NOINIT_WARNED= return 0 } @@ -915,7 +835,7 @@ a) # Set metric and private before creating the interface resolv.conf file # to ensure that it will have the correct flags [ ! -d "$METRICDIR" ] && mkdir "$METRICDIR" - oldmetric="$METRICDIR/"*" $iface" + oldmetric="$(echo "$METRICDIR/"*" $iface")" newmetric= if [ -n "$IF_METRIC" ]; then # Pad metric to 6 characters, so 5 is less than 10 @@ -1059,11 +979,12 @@ esac # Try and detect a suitable init system for our scripts detect_init -export RESTARTCMD RCDIR _NOINIT_WARNED +export RESTARTCMD RCDIR eval "$(make_vars)" export RESOLVCONF DOMAINS SEARCH NAMESERVERS LOCALNAMESERVERS : ${list_resolv:=list_resolv -l} +export PATH="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin" retval=0 # Run scripts in the same directory resolvconf is run from @@ -1071,6 +992,9 @@ retval=0 cd "$_PWD" for script in "$LIBEXECDIR"/*; do if [ -f "$script" ]; then + # Don't run *.rpm* and *~ scripts. + [ "${script%.rpm*}" = "$script" -a "${script%\~}" = "$script" ] || continue + eval script_enabled="\$${script##*/}" case "${script_enabled:-YES}" in [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) ;;