Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/ROY]: src/external/bsd/openresolv/dist Import openresolv-3.6.1 with the ...



details:   https://anonhg.NetBSD.org/src/rev/81c79a043c93
branches:  ROY
changeset: 454314:81c79a043c93
user:      roy <roy%NetBSD.org@localhost>
date:      Tue Oct 28 22:37:59 2014 +0000

description:
Import openresolv-3.6.1 with the following changes:
  *  Don't update when nothing has been deleted
  *  Backup resolv.conf to resolv.conf.bak when it doesn't have an openresolv
     signature
     Restore it when the new resolv.conf only has the openresolv signature
  *  Document prepend_search and prepend_nameservers
  *  Implement append_search and append_nameservers
  *  Implement replace and replace_sub to allow for keyword/value/replacement

diffstat:

 external/bsd/openresolv/dist/libc.in              |  26 +++++++++-
 external/bsd/openresolv/dist/resolvconf.8.in      |   6 +-
 external/bsd/openresolv/dist/resolvconf.conf.5.in |  41 +++++++++++++++++-
 external/bsd/openresolv/dist/resolvconf.in        |  54 ++++++++++++++++++++++-
 4 files changed, 120 insertions(+), 7 deletions(-)

diffs (247 lines):

diff -r 7f7311b2ac58 -r 81c79a043c93 external/bsd/openresolv/dist/libc.in
--- a/external/bsd/openresolv/dist/libc.in      Mon Oct 20 09:09:53 2014 +0000
+++ b/external/bsd/openresolv/dist/libc.in      Tue Oct 28 22:37:59 2014 +0000
@@ -106,6 +106,9 @@
        resolv_conf_tail="$(cat "$SYSCONFDIR"/resolv.conf.tail)"
 fi
 
+backup=true
+signature="# Generated by resolvconf"
+ 
 uniqify()
 {
        local result=
@@ -121,6 +124,7 @@
 
 case "${resolv_conf_passthrough:-NO}" in
 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
+       backup=false
        newest=
        for conf in "$IFACEDIR"/*; do
                if [ -z "$newest" -o "$conf" -nt "$newest" ]; then
@@ -147,11 +151,11 @@
 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) ;;
 *)
        : ${domain:=$DOMAIN}
-       newsearch="$(uniqify $prepend_search $SEARCH)"
+       newsearch="$(uniqify $prepend_search $SEARCH $append_search)"
        NS="$LOCALNAMESERVERS $NAMESERVERS"
        newns=
        gotlocal=false
-       for n in $(uniqify $prepend_nameservers $NS); do
+       for n in $(uniqify $prepend_nameservers $NS $append_nameservers); do
                add=true
                islocal=false
                for l in $local_nameservers; do
@@ -169,7 +173,7 @@
        done
 
        # Hold our new resolv.conf in a variable to save on temporary files
-       newconf="# Generated by resolvconf$NL"
+       newconf="$signature$NL"
        if [ -n "$resolv_conf_head" ]; then
                newconf="$newconf$resolv_conf_head$NL"
        fi
@@ -207,6 +211,22 @@
        [ "$(cat "$resolv_conf")" = "$(printf %s "$newconf")" ] && exit 0
 fi
 
+# Change is good.
+# If the old file does not have our signature, back it up.
+# If the new file just has our signature, restore the backup.
+if $backup; then
+       if [ "$newconf" = "$signature$NL" ]; then
+               if [ -e "$resolv_conf.bak" ]; then
+                       newconf="$(cat "$resolv_conf.bak")"
+               fi
+       elif [ -e "$resolv_conf" ]; then
+               read line <"$resolv_conf"
+               if [ "$line" != "$signature" ]; then
+                       cp "$resolv_conf" "$resolv_conf.bak"
+               fi
+       fi
+fi
+
 # Create our resolv.conf now
 (umask 022; printf %s "$newconf" >"$resolv_conf")
 eval $libc_restart
diff -r 7f7311b2ac58 -r 81c79a043c93 external/bsd/openresolv/dist/resolvconf.8.in
--- a/external/bsd/openresolv/dist/resolvconf.8.in      Mon Oct 20 09:09:53 2014 +0000
+++ b/external/bsd/openresolv/dist/resolvconf.8.in      Tue Oct 28 22:37:59 2014 +0000
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd October 20, 2014
+.Dd October 26, 2014
 .Dt RESOLVCONF 8 SMM
 .Os
 .Sh NAME
@@ -81,7 +81,7 @@
 assumes it has a job to do.
 In some situations
 .Nm
-needs to act as a deterent to writing to
+needs to act as a deterrent to writing to
 .Pa /etc/resolv.conf .
 Where this file cannot be made immutable or you just need to toggle this
 behaviour,
@@ -220,6 +220,8 @@
 .El
 .Sh FILES
 .Bl -ohang
+.It Pa /etc/resolv.conf.bak
+Backup file of the original resolv.conf.
 .It Pa @SYSCONFDIR@/resolvconf.conf
 Configuration file for
 .Nm .
diff -r 7f7311b2ac58 -r 81c79a043c93 external/bsd/openresolv/dist/resolvconf.conf.5.in
--- a/external/bsd/openresolv/dist/resolvconf.conf.5.in Mon Oct 20 09:09:53 2014 +0000
+++ b/external/bsd/openresolv/dist/resolvconf.conf.5.in Tue Oct 28 22:37:59 2014 +0000
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd October 20, 2014
+.Dd October 28, 2014
 .Dt RESOLVCONF.CONF 5 SMM
 .Os
 .Sh NAME
@@ -48,6 +48,9 @@
 After updating this file, you may wish to run
 .Nm resolvconf -u
 to apply the new configuration.
+.Pp
+When a dynmically generated list is appended or prepended to, the whole
+is made unique where left-most wins.
 .Sh RESOLVCONF OPTIONS
 .Bl -tag -width indent
 .It Sy resolvconf
@@ -91,6 +94,34 @@
 This is equivalent to the
 .Nm resolvconf -p
 option.
+.It Sy replace
+Is a space separated list of replacement keywords. The syntax is this:
+.Va $keyword Ns / Ns Va $match Ns / Ns Va $replacement
+.Pp
+Example, given this resolv.conf:
+.D1 domain foo.org
+.D1 search foo.org dead.beef
+.D1 nameserver 1.2.3.4
+.D1 nameserver 2.3.4.5
+and this configuaration:
+.D1 replace="search/foo*/bar.com nameserver/1.2.3.4/5.6.7.8 nameserver/2.3.4.5/"
+you would get this resolv.conf instead:
+.D1 domain foo.org
+.D1 search bar.com
+.D1 nameserver 5.6.7.8
+.It Sy replace_sub
+Works the same way as
+.Sy replace
+except it works on each space separated value rather than the whole line,
+so it's useful for the replacing a single domain within the search directive.
+Using the same example resolv.conf and changing
+.Sy replace
+to
+.Sy replace_sub ,
+you would get this resolv.conf instead:
+.D1 domain foo.org
+.D1 search bar.com dead.beef
+.D1 nameserver 5.6.7.8
 .It Sy state_dir
 Override the default state directory of
 .Pa @VARDIR@ .
@@ -132,6 +163,14 @@
 Set this to NO to also list non-local nameservers.
 This will give you working DNS even if the local nameserver stops functioning
 at the expense of duplicated server queries.
+.It Sy append_nameservers
+Append name servers to the dynamically generated list.
+.It Sy prepend_nameservers
+Prepend name servers to the dynamically generated list.
+.It Sy append_search
+Append search domains to the dynamically generated list.
+.It Sy prepend_search
+Prepend search domains to the dynamically generated list.
 .El
 .Sh SUBSCRIBER OPTIONS
 openresolv ships with subscribers for the name servers
diff -r 7f7311b2ac58 -r 81c79a043c93 external/bsd/openresolv/dist/resolvconf.in
--- a/external/bsd/openresolv/dist/resolvconf.in        Mon Oct 20 09:09:53 2014 +0000
+++ b/external/bsd/openresolv/dist/resolvconf.in        Tue Oct 28 22:37:59 2014 +0000
@@ -354,6 +354,47 @@
        echo
 }
 
+replace()
+{
+       local r= k= f= v= val= sub=
+
+       while read -r keyword value; do
+               for r in $replace; do
+                       k="${r%%/*}"
+                       r="${r#*/}"
+                       f="${r%%/*}"
+                       r="${r#*/}"
+                       v="${r%%/*}"
+                       case "$keyword" in
+                       $k)
+                               case "$value" in
+                               $f) value="$v";;
+                               esac
+                               ;;
+                       esac
+               done
+               val=
+               for sub in $value; do
+                       for r in $replace_sub; do
+                               k="${r%%/*}"
+                               r="${r#*/}"
+                               f="${r%%/*}"
+                               r="${r#*/}"
+                               v="${r%%/*}"
+                               case "$keyword" in
+                               $k)
+                                       case "$sub" in
+                                       $f) sub="$v";;
+                                       esac
+                                       ;;
+                               esac
+                       done
+                       val="$val${val:+ }$sub"
+               done
+               printf "%s %s\n" "$keyword" "$val"
+       done
+}
+
 make_vars()
 {
        local newdomains= d= dn= newns= ns=
@@ -369,7 +410,7 @@
                eval "$(echo_prepend | parse_resolv)"
        fi
        if [ -z "$VFLAG" ]; then
-               eval "$(list_resolv -l "$@" | parse_resolv)"
+               eval "$(list_resolv -l "$@" | replace | parse_resolv)"
        fi
        if [ -n "$name_servers_append" -o -n "$search_domains_append" ]; then
                eval "$(echo_append | parse_resolv)"
@@ -510,6 +551,17 @@
 if [ ! -d "$IFACEDIR" ]; then
        mkdir -m 0755 -p "$IFACEDIR" || \
                error_exit "Failed to create needed directory $IFACEDIR"
+       if [ "$cmd" = d ]; then
+               # Provide the same error messages as below
+               if ! ${force}; then
+                       cd "$IFACEDIR"
+                       for i in $args; do
+                               warn "No resolv.conf for interface $i"
+                       done
+               fi
+               ${force}
+               exit $?
+       fi
 else
        # Delete any existing information about the interface
        if [ "$cmd" = d ]; then



Home | Main Index | Thread Index | Old Index