]> www.infradead.org Git - users/dwmw2/vpnc-scripts.git/commitdiff
rewrite resolv.conf parsing
authorCorey Hickey <bugfood-ml@fatooh.org>
Sun, 28 Aug 2016 05:45:14 +0000 (22:45 -0700)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Sun, 28 Aug 2016 06:27:51 +0000 (07:27 +0100)
This patch simplifies parsing and changes behavior in two ways:

1. Domains for searching are now parsed from "search" and "domain"
lines. Only a "search" line is outputted, since "search" supports
multiple domains and is mutually exclusive with "domain". The motivation
for this is to make vpnc-script behave sanely when there are existing
resolv.conf files with only "domain" or with both "domain" and "search".

2. All original "nameserver" lines are discarded and replaced rather
than only the number of nameservers from $INTERNAL_IP4_DNS. The
rationale here is that vpnc-script should be consistent and either
retain all original nameservers or overwrite all of them. Retaining them
is problematic because there is a limit of three, and overwriting is
closer to the original behavior.

The Darwin changes are untested, but are a simple search/replace and
thus should work fine.

Signed-off-by: Corey Hickey <bugfood-ml@fatooh.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
vpnc-script

index c3aafa426c26f2152c695310385f8365ccb1051f..9c413e0f2ef40762bdab4f925ed11f13e6278148 100755 (executable)
@@ -369,49 +369,31 @@ modify_resolvconf_generic() {
 # and will be overwritten by vpnc
 # as long as the above mark is intact"
 
-       # If multiple domains are listed, prefer the first for "domain".
-       DOMAIN="${CISCO_DEF_DOMAIN%% *}"
-       # Remember the original value of CISCO_DEF_DOMAIN we need it later
-       CISCO_DEF_DOMAIN_ORIG="$CISCO_DEF_DOMAIN"
-       # Don't step on INTERNAL_IP4_DNS value, use a temporary variable
-       INTERNAL_IP4_DNS_TEMP="$INTERNAL_IP4_DNS"
+       DOMAINS="$CISCO_DEF_DOMAIN"
+
        exec 6< "$RESOLV_CONF_BACKUP"
        while read LINE <&6 ; do
                case "$LINE" in
-                       nameserver*)
-                               if [ -n "$INTERNAL_IP4_DNS_TEMP" ]; then
-                                       read ONE_NAMESERVER INTERNAL_IP4_DNS_TEMP <<-EOF
-       $INTERNAL_IP4_DNS_TEMP
-EOF
-                                       LINE="nameserver $ONE_NAMESERVER"
-                               else
-                                       LINE=""
-                               fi
-                               ;;
-                       search*)
-                               if [ -n "$CISCO_DEF_DOMAIN" ]; then
-                                       LINE="$LINE $CISCO_DEF_DOMAIN"
-                                       CISCO_DEF_DOMAIN=""
-                               fi
-                               ;;
-                       domain*)
-                               if [ -n "$DOMAIN" ]; then
-                                       LINE="domain $DOMAIN"
-                               fi
-                               ;;
+                       # omit; we will overwrite these
+                       nameserver*) ;;
+                       # extract listed domains and prepend to list
+                       domain* | search*) DOMAINS="${LINE#* } $DOMAINS" ;;
+                       # retain other lines
+                       *) NEW_RESOLVCONF="$NEW_RESOLVCONF
+$LINE" ;;
                esac
-               NEW_RESOLVCONF="$NEW_RESOLVCONF
-$LINE"
        done
        exec 6<&-
 
-       for i in $INTERNAL_IP4_DNS_TEMP ; do
+       for i in $INTERNAL_IP4_DNS ; do
                NEW_RESOLVCONF="$NEW_RESOLVCONF
 nameserver $i"
        done
-       if [ -n "$CISCO_DEF_DOMAIN" ]; then
+       # note that "search" is mutually exclusive with "domain";
+       # "search" allows multiple domains to be listed, so use that
+       if [ -n "$DOMAINS" ]; then
                NEW_RESOLVCONF="$NEW_RESOLVCONF
-search $CISCO_DEF_DOMAIN"
+search $DOMAINS"
        fi
        echo "$NEW_RESOLVCONF" > /etc/resolv.conf
 
@@ -453,7 +435,7 @@ search $CISCO_DEF_DOMAIN"
                                # DNS matching when available.  When multiple DNS matching
                                # is present, anything reading the /etc/resolv.conf file
                                # directly will probably not work as intended.
-                               #if [ -z "$CISCO_DEF_DOMAIN_ORIG" ]; then
+                               #if [ -z "$CISCO_DEF_DOMAIN" ]; then
                                        # Cannot use multiple DNS matching without a domain
                                        OVERRIDE_PRIMARY='d.add OverridePrimary # 1'
                                #fi
@@ -471,13 +453,13 @@ search $CISCO_DEF_DOMAIN"
                                        set State:/Network/Service/$TUNDEV/IPv4
                                        close
                                EOF
-                               if [ -n "$CISCO_DEF_DOMAIN_ORIG" ]; then
+                               if [ -n "$CISCO_DEF_DOMAIN" ]; then
                                        scutil >/dev/null 2>&1 <<-EOF
                                                open
                                                get State:/Network/Service/$TUNDEV/DNS
-                                               d.add DomainName $CISCO_DEF_DOMAIN_ORIG
-                                               d.add SearchDomains * $CISCO_DEF_DOMAIN_ORIG
-                                               d.add SupplementalMatchDomains * $CISCO_DEF_DOMAIN_ORIG
+                                               d.add DomainName $CISCO_DEF_DOMAIN
+                                               d.add SearchDomains * $CISCO_DEF_DOMAIN
+                                               d.add SupplementalMatchDomains * $CISCO_DEF_DOMAIN
                                                set State:/Network/Service/$TUNDEV/DNS
                                                close
                                        EOF