Add domain_blacklist and name_server_blacklist variables.
authorRoy Marples <roy@marples.name>
Wed, 22 Feb 2012 13:42:52 +0000 (13:42 +0000)
committerRoy Marples <roy@marples.name>
Wed, 22 Feb 2012 13:42:52 +0000 (13:42 +0000)
We default name_server_blacklist to 0.0.0.0 and allow pattern matching
on both lists.
Fixes #16.

resolvconf.conf.5.in
resolvconf.in

index b06d8654fe318fc7fe8e8dff7bd5a1c46d32732e..cfb81dc33ee75255c399fe0fc4fcb756e4553769 100644 (file)
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd August 11, 2011
+.Dd February 22, 2012
 .Dt RESOLVCONF.CONF 5 SMM
 .Os
 .Sh NAME
 .Dt RESOLVCONF.CONF 5 SMM
 .Os
 .Sh NAME
@@ -60,12 +60,20 @@ If unset, defaults to the following:-
 Prepend search domains to the dynamically generated list.
 .It Sy search_domains_append
 Append search domains to the dynamically generated list.
 Prepend search domains to the dynamically generated list.
 .It Sy search_domains_append
 Append search domains to the dynamically generated list.
+.It Sy domain_blacklist
+A list of domains to be removed from consideration.
+To remove a domain, you can use foo.*
+To remove a sub domain, you can use *.bar
 .It Sy name_servers
 Prepend name servers to the dynamically generated list.
 You should set this to 127.0.0.1 if you use a local name server other than
 libc.
 .It Sy name_servers_append
 Append name servers to the dynamically generated list.
 .It Sy name_servers
 Prepend name servers to the dynamically generated list.
 You should set this to 127.0.0.1 if you use a local name server other than
 libc.
 .It Sy name_servers_append
 Append name servers to the dynamically generated list.
+.It Sy name_server_blacklist
+A list of name servers to be removed from consideration.
+The default is 0.0.0.0 as some faulty routers send it via DHCP.
+To remove a block, you can use 192.168.*
 .It Sy private_interfaces
 These interfaces name servers will only be queried for the domains listed
 in their resolv.conf.
 .It Sy private_interfaces
 These interfaces name servers will only be queried for the domains listed
 in their resolv.conf.
index 567e7986c20c0d444d03cd49a0b6a6eca56e1c1b..dba656cb5d21c21638cb5a7d35714f7719d2a522 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
 #!/bin/sh
-# Copyright (c) 2007-2011 Roy Marples
+# Copyright (c) 2007-2012 Roy Marples
 # All rights reserved
 
 # Redistribution and use in source and binary forms, with or without
 # All rights reserved
 
 # Redistribution and use in source and binary forms, with or without
@@ -45,6 +45,7 @@ PRIVATEDIR="$VARDIR/private"
 
 : ${dynamic_order:=tap[0-9]* tun[0-9]* vpn vpn[0-9]* ppp[0-9]* ippp[0-9]*}
 : ${interface_order:=lo lo[0-9]*}
 
 : ${dynamic_order:=tap[0-9]* tun[0-9]* vpn vpn[0-9]* ppp[0-9]* ippp[0-9]*}
 : ${interface_order:=lo lo[0-9]*}
+: ${name_server_blacklist:=0.0.0.0}
 
 error_exit()
 {
 
 error_exit()
 {
@@ -289,18 +290,43 @@ list_resolv()
        return $retval
 }
 
        return $retval
 }
 
+list_remove() {
+       local list= e= l= result= found= retval=0
+
+       [ -z "$2" ] && return 0
+       eval list=\"\$$1\"
+       shift
+
+       for e; do
+               found=false
+               for l in $list; do
+                       case "$e" in
+                       $l) found=true;;
+                       esac
+                       $found && break
+               done
+               if $found; then
+                       retval=$(($retval + 1))
+               else
+                       result="$result $e"
+               fi
+       done
+       echo "${result# *}"
+       return $retval
+}
+
 make_vars()
 {
 make_vars()
 {
+       local newdomains= d= dn= newns= ns=
        eval "$(list_resolv -l "$@" | parse_resolv)"
 
        # Ensure that we only list each domain once
        eval "$(list_resolv -l "$@" | parse_resolv)"
 
        # Ensure that we only list each domain once
-       newdomains=
        for d in $DOMAINS; do
                dn="${d%%:*}"
        for d in $DOMAINS; do
                dn="${d%%:*}"
+               list_remove domain_blacklist "$dn" >/dev/null || continue
                case " $newdomains" in
                *" ${dn}:"*) continue;;
                esac
                case " $newdomains" in
                *" ${dn}:"*) continue;;
                esac
-               newdomains="$newdomains${newdomains:+ }$dn:"
                newns=
                for nd in $DOMAINS; do
                        if [ "$dn" = "${nd%%:*}" ]; then
                newns=
                for nd in $DOMAINS; do
                        if [ "$dn" = "${nd%%:*}" ]; then
@@ -308,19 +334,30 @@ make_vars()
                                while [ -n "$ns" ]; do
                                        case ",$newns," in
                                        *,${ns%%,*},*) ;;
                                while [ -n "$ns" ]; do
                                        case ",$newns," in
                                        *,${ns%%,*},*) ;;
-                                       *) newns="$newns${newns:+,}${ns%%,*}";;
+                                       *) list_remove name_server_blacklist \
+                                               "$ns" >/dev/null \
+                                       && newns="$newns${newns:+,}${ns%%,*}";;
                                        esac
                                        [ "$ns" = "${ns#*,}" ] && break
                                        ns="${ns#*,}"
                                done
                        fi
                done
                                        esac
                                        [ "$ns" = "${ns#*,}" ] && break
                                        ns="${ns#*,}"
                                done
                        fi
                done
-               newdomains="$newdomains$newns"
+               if [ -n "$newns" ]; then
+                       newdomains="$newdomains${newdomains:+ }$dn:$newns"
+               fi
        done
        done
+       DOMAIN="$(list_remove domain_blacklist $DOMAIN)"
+       SEARCH="$(uniqify $SEARCH)"
+       SEARCH="$(list_remove domain_blacklist $SEARCH)"
+       NAMESERVERS="$(uniqify $NAMESERVERS)"
+       NAMESERVERS="$(list_remove name_server_blacklist $NAMESERVERS)"
+       LOCALNAMESERVERS="$(uniqify $LOCALNAMESERVERS)"
+       LOCALNAMESERVERS="$(list_remove name_server_blacklist $LOCALNAMESERVERS)"
        echo "DOMAIN='$DOMAIN'"
        echo "DOMAIN='$DOMAIN'"
-       echo "SEARCH='$(uniqify $SEARCH)'"
-       echo "NAMESERVERS='$(uniqify $NAMESERVERS)'"
-       echo "LOCALNAMESERVERS='$(uniqify $LOCALNAMESERVERS)'"
+       echo "SEARCH='$SEARCH'"
+       echo "NAMESERVERS='$NAMESERVERS'"
+       echo "LOCALNAMESERVERS='$LOCALNAMESERVERS'"
        echo "DOMAINS='$newdomains'"
 }
 
        echo "DOMAINS='$newdomains'"
 }