Use printf %s so user send data cannot do any formatting.
authorRoy Marples <roy@marples.name>
Mon, 13 Jun 2011 10:34:00 +0000 (10:34 +0000)
committerRoy Marples <roy@marples.name>
Mon, 13 Jun 2011 10:34:00 +0000 (10:34 +0000)
Important for handling some IPv6 addresses.
Fixes #14.

dnsmasq.in
libc.in
named.in
pdns_recursor.in
pdnsd.in
resolvconf.in
unbound.in

index 167886628303c3b46fad54cd739c86442499805b..a120189ba99421252d06cfe21623d2d74a911cdf 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2007-2009 Roy Marples
+# Copyright (c) 2007-2011 Roy Marples
 # All rights reserved
 
 # dnsmasq subscriber for resolvconf
 . "@SYSCONFDIR@/resolvconf.conf" || exit 1
 [ -z "$dnsmasq_conf" -a -z "$dnsmasq_resolv" ] && exit 0
 [ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
+NL="
+"
 
 : ${dnsmasq_pid:=/var/run/dnsmasq.pid}
 [ -s "$dnsmasq_pid" ] || dnsmasq_pid=/var/run/dnsmasq/dnsmasq.pid
 : ${dnsmasq_service:=dnsmasq}
 : ${dnsmasq_restart:=@RESTARTCMD ${dnsmasq_service}@}
-newconf="# Generated by resolvconf\n"
+newconf="# Generated by resolvconf$NL"
 newresolv="$newconf"
 
 # Using dbus means that we never have to restart the daemon
@@ -56,14 +58,14 @@ if [ -s "$dbus_pid" -a -s "$dnsmasq_pid" ]; then
                        kill -0 $(cat "$dnsmasq_pid") 2>/dev/null
                then
                        dbus=true
-                       newconf="$newconf\n# Domain specific servers will"
-                       newconf="$newconf be sent over dbus\nenable-dbus\n"
+                       newconf="$newconf$NL# Domain specific servers will"
+                       newconf="$newconf be sent over dbus${NL}enable-dbus$NL"
                fi
        fi
 fi
 
 for n in $NAMESERVERS; do
-       newresolv="${newresolv}nameserver $n\n"
+       newresolv="${newresolv}nameserver $n$NL"
 done
 
 dbusdest=
@@ -75,16 +77,16 @@ for d in $DOMAINS; do
                        SIFS=${IFS-y} OIFS=$IFS
                        IFS=.
                        set -- ${ns%%,*}
-                       num="0x$(printf "%02x" $1 $2 $3 $4)"
+                       num="0x$(printf %02x $1 $2 $3 $4)"
                        if [ "$SIFS" = yi ]; then
                                unset IFS
                        else
                                IFS=$OIFS
                        fi
-                       dbusdest="$dbusdest uint32:$(printf "%u" $num)"
+                       dbusdest="$dbusdest uint32:$(printf %u $num)"
                        dbusdest="$dbusdest string:$dn"
                else
-                       newconf="${newconf}server=/$dn/${ns%%,*}\n"
+                       newconf="${newconf}server=/$dn/${ns%%,*}$NL"
                fi
                [ "$ns" = "${ns#*,}" ] && break
                ns="${ns#*,}"
@@ -94,22 +96,22 @@ done
 changed=false
 if [ -n "$dnsmasq_conf" ]; then
        if [ ! -f "$dnsmasq_conf" ] || \
-               [ "$(cat "$dnsmasq_conf")" != "$(printf "$newconf")" ]
+               [ "$(cat "$dnsmasq_conf")" != "$(printf %s "$newconf")" ]
        then
                changed=true
-               printf "$newconf" >"$dnsmasq_conf"
+               printf %s "$newconf" >"$dnsmasq_conf"
        fi
 fi
 if [ -n "$dnsmasq_resolv" ]; then
        if [ -f "$dnsmasq_resolv" ]; then
-               if [ "$(cat "$dnsmasq_resolv")" != "$(printf "$newresolv")" ]
+               if [ "$(cat "$dnsmasq_resolv")" != "$(printf %s "$newresolv")" ]
                then
                        changed=true
-                       printf "$newresolv" >"$dnsmasq_resolv"
+                       printf %s "$newresolv" >"$dnsmasq_resolv"
                fi
        else
                # dnsmasq polls this file so no need to set changed=true
-               printf "$newresolv" >"$dnsmasq_resolv"
+               printf %s "$newresolv" >"$dnsmasq_resolv"
        fi
 fi
 
diff --git a/libc.in b/libc.in
index c542d3b349c9ced080f77f8d0e10f37ed330c084..9c73f0fffad0ba338b9c55a7591351249288f508 100644 (file)
--- a/libc.in
+++ b/libc.in
@@ -30,6 +30,8 @@ SYSCONFDIR=@SYSCONFDIR@
 LIBEXECDIR=@LIBEXECDIR@
 VARDIR=@VARDIR@
 IFACEDIR="$VARDIR/interfaces"
+NL="
+"
 
 # sed may not be available, and this is faster on small files
 key_get_value()
@@ -109,7 +111,7 @@ case "${resolv_conf_passthrough:-NO}" in
                fi
        done
        [ -z "$newest" ] && exit 0
-       newconf="$(cat "$newest")\n"
+       newconf="$(cat "$newest")$NL"
        ;;
 *)
        [ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
@@ -118,13 +120,13 @@ case "${resolv_conf_passthrough:-NO}" in
        newns="$(uniqify $name_servers $NS $name_servers_append)"
 
        # Hold our new resolv.conf in a variable to save on temporary files
-       newconf="# Generated by resolvconf\n"
+       newconf="# Generated by resolvconf$NL"
        if [ -n "$resolv_conf_head" ]; then
-               newconf="$newconf$resolv_conf_head\n"
+               newconf="$newconf$resolv_conf_head$NL"
        fi
-       [ -n "$newsearch" ] && newconf="${newconf}search $newsearch\n"
+       [ -n "$newsearch" ] && newconf="${newconf}search $newsearch$NL"
        for n in $newns; do
-               newconf="${newconf}nameserver $n\n"
+               newconf="${newconf}nameserver $n$NL"
        done
 
        # Now get any configured options
@@ -135,22 +137,22 @@ case "${resolv_conf_passthrough:-NO}" in
                for opt in $(uniqify $opts); do
                        newconf="${newconf} $opt"
                done
-               newconf="$newconf\n"
+               newconf="$newconf$NL"
        fi
 
        if [ -n "$resolv_conf_tail" ]; then
-               newconf="$newconf$resolv_conf_tail\n"
+               newconf="$newconf$resolv_conf_tail$NL"
        fi
        ;;
 esac
 
 # Check if the file has actually changed or not
 if [ -e "$resolv_conf" ]; then
-       [ "$(cat "$resolv_conf")" = "$(printf "$newconf")" ] && exit 0
+       [ "$(cat "$resolv_conf")" = "$(printf %s "$newconf")" ] && exit 0
 fi
 
 # Create our resolv.conf now
-(umask 022; printf "$newconf" >"$resolv_conf")
+(umask 022; echo "$newconf" >"$resolv_conf")
 eval $libc_restart
 
 retval=0
index 6448961285076ce1c20276296e0f0300a7938b8f..c960866b99853b0764fd50915f8b24cc0f29b848 100644 (file)
--- a/named.in
+++ b/named.in
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2007-2009 Roy Marples
+# Copyright (c) 2007-2011 Roy Marples
 # All rights reserved
 
 # named subscriber for resolvconf
@@ -30,6 +30,8 @@
 . "@SYSCONFDIR@/resolvconf.conf" || exit 1
 [ -z "$named_zones" -a -z "$named_options" ] && exit 0
 [ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
+NL="
+"
 
 # Platform specific kludges
 if [ -z "$named_service" -a -z "$named_restart" -a \
@@ -42,31 +44,31 @@ then
 fi
 : ${named_service:=named}
 : ${named_restart:=@RESTARTCMD ${named_service}@}
-newoptions="# Generated by resolvconf\n"
+newoptions="# Generated by resolvconf$NL"
 newzones="$newoptions"
 
 forward=
 for n in $NAMESERVERS; do
        case "$forward" in
-       *"\n\t$n;"*);;
-       *) forward="$forward\n\t$n;";;
+       *"$NL   $n;"*);;
+       *) forward="$forward$NL $n;";;
        esac
 done
 if [ -n "$forward" ]; then
-       newoptions="${newoptions}forward first;\nforwarders {$forward\n};\n"
+       newoptions="${newoptions}forward first;${NL}forwarders {$forward${NL}};$NL"
 fi
 
 for d in $DOMAINS; do
-       newzones="${newzones}zone \"${d%%:*}\" {\n"
-       newzones="$newzones\ttype forward;\n"
-       newzones="$newzones\tforward first;\n\tforwarders {\n"
+       newzones="${newzones}zone \"${d%%:*}\" {$NL"
+       newzones="$newzones     type forward;$NL"
+       newzones="$newzones     forward first;$NL       forwarders {$NL"
        ns="${d#*:}"
        while [ -n "$ns" ]; do
-               newzones="$newzones\t\t${ns%%,*};\n"
+               newzones="$newzones             ${ns%%,*};$NL"
                [ "$ns" = "${ns#*,}" ] && break
                ns="${ns#*,}"
        done
-       newzones="$newzones\t};\n};\n"
+       newzones="$newzones     };$NL};$NL"
 done
 
 # No point in changing files or reloading bind if the end result has not
@@ -74,17 +76,17 @@ done
 changed=false
 if [ -n "$named_options" ]; then
        if [ ! -f "$named_options" ] || \
-               [ "$(cat "$named_options")" != "$(printf "$newoptions")" ]
+               [ "$(cat "$named_options")" != "$(printf %s "$newoptions")" ]
        then
-               printf "$newoptions" >"$named_options"
+               printf %s "$newoptions" >"$named_options"
                changed=true
        fi
 fi
 if [ -n "$named_zones" ]; then
        if [ ! -f "$named_zones" ] || \
-               [ "$(cat "$named_zones")" != "$(printf "$newzones")" ]
+               [ "$(cat "$named_zones")" != "$(printf %s "$newzones")" ]
        then
-               printf "$newzones" >"$named_zones"
+               printf %s "$newzones" >"$named_zones"
                changed=true
        fi
 fi
index 93bed04d9fd9a04941649c7d6b1dde0087a35a84..e7aa40e1eca171a737e137608caeffa9a4bed10a 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2009 Roy Marples
+# Copyright (c) 2009-2011 Roy Marples
 # All rights reserved
 
 # PowerDNS Recursor subscriber for resolvconf
@@ -30,6 +30,8 @@
 . "@SYSCONFDIR@/resolvconf.conf" || exit 1
 [ -z "$pdns_zones" ] && exit 0
 [ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
+NL="
+"
 
 : ${pdns_service:=pdns_recursor}
 : ${pdns_restart:=@RESTARTCMD ${pdns_service}@}
@@ -42,7 +44,7 @@ newzones=
 #for n in $NAMESERVERS; do
 #      newzones="$newzones${newzones:+,}$n"
 #done
-#[ -n "$newzones" ] && newzones=".=$newzones\n"
+#[ -n "$newzones" ] && newzones=".=$newzones$NL"
 
 for d in $DOMAINS; do
        newns=
@@ -52,12 +54,12 @@ for d in $DOMAINS; do
                [ "$ns" = "${ns#*,}" ] && break
                ns="${ns#*,}"
        done
-       [ -n "$newns" ] && newzones="$newzones${d%%:*}=$newns\n"
+       [ -n "$newns" ] && newzones="$newzones${d%%:*}=$newns$NL"
 done
 
 if [ ! -f "$pdns_zones" ] || \
-       [ "$(cat "$pdns_zones")" != "$(printf "$newzones")" ]
+       [ "$(cat "$pdns_zones")" != "$(printf %s "$newzones")" ]
 then
-       printf "$newzones" >"$pdns_zones"
+       printf %s "$newzones" >"$pdns_zones"
        eval $pdns_restart
 fi
index ff3b9b23ab5a975c579b2a51474c10f6782c73a6..237939ca9b5dd8cb2efa01885660c25d7c2b9060 100644 (file)
--- a/pdnsd.in
+++ b/pdnsd.in
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2010 Roy Marples
+# Copyright (c) 2010-2011 Roy Marples
 # All rights reserved
 
 # pdnsd subscriber for resolvconf
@@ -131,7 +131,7 @@ if [ -n "$pdnsd_conf" ]; then
        remove_markers "$signature" "$signature_end" "$pdnsd_conf" > "$cf"
        if [ -n "$newconf" ]; then
                echo "$signature" >> "$cf"
-               printf "$newconf" >> "$cf"
+               printf %s "$newconf" >> "$cf"
                echo "$signature_end" >> "$cf"
        fi
        if change_file "$pdnsd_conf" "$cf"; then
@@ -141,10 +141,10 @@ fi
 
 if [ -n "$pdnsd_resolv" ]; then
        if [ ! -f "$pdnsd_resolv" ] || \
-               [ "$(cat "$pdnsd_resolv")" != "$(printf "$newresolv")" ]
+               [ "$(cat "$pdnsd_resolv")" != "$(printf %s "$newresolv")" ]
        then
                changed=true
-               printf "$newresolv" >"$pdnsd_resolv"
+               printf %s "$newresolv" >"$pdnsd_resolv"
        fi
 fi
 
index 3896c3425ec54ffaec0000a2442a4874cbd0ecf9..2b292dd341bddf1f520763634deec88ddd0beaf5 100644 (file)
@@ -368,17 +368,17 @@ fi
 
 if [ "$cmd" = a ]; then
        # Read resolv.conf from stdin
-       resolv="$(cat)\n"
+       resolv="$(cat)"
        # If what we are given matches what we have, then do nothing
        if [ -e "$IFACEDIR/$iface" ]; then
-               if [ "$(printf "$resolv")" = \
+               if [ "$(echo "$resolv")" = \
                        "$(cat "$IFACEDIR/$iface")" ]
                then
                        exit 0
                fi
                rm "$IFACEDIR/$iface"
        fi
-       printf "$resolv" >"$IFACEDIR/$iface" || exit $?
+       echo "$resolv" >"$IFACEDIR/$iface" || exit $?
        [ ! -d "$METRICDIR" ] && mkdir "$METRICDIR"
        rm -f "$METRICDIR/"*" $iface"
        if [ -n "$IF_METRIC" ]; then
index b5fb7ecf53401c617060fb7776f0d4602aef6e31..839a85944059e6bb5d62578159a7e046b678ac53 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2009 Roy Marples
+# Copyright (c) 2009-2011 Roy Marples
 # All rights reserved
 
 # unbound subscriber for resolvconf
 . "@SYSCONFDIR@/resolvconf.conf" || exit 1
 [ -z "$unbound_conf" ] && exit 0
 [ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
+NL="
+"
 
 : ${unbound_pid:=/var/run/unbound.pid}
 : ${unbound_service:=unbound}
 : ${unbound_restart:=@RESTARTCMD ${unbound_service}@}
-newconf="# Generated by resolvconf\n"
+newconf="# Generated by resolvconf$NL"
 
 for d in $DOMAINS; do
        dn="${d%%:*}"
        ns="${d#*:}"
-       newconf="${newconf}\nforward-zone:\n\tname: \"$dn\"\n"
+       newconf="$newconf${NL}forward-zone:$NL  name: \"$dn\"$NL"
        while [ -n "$ns" ]; do
-               newconf="${newconf}\tforward-addr: ${ns%%,*}\n"
+               newconf="$newconf       forward-addr: ${ns%%,*}$NL"
                [ "$ns" = "${ns#*,}" ] && break
                ns="${ns#*,}"
        done
 done
 
 if [ -n "$NAMESERVERS" ]; then
-       newconf="${newconf}\nforward-zone:\n\tname: \".\"\n"
+       newconf="$newconf${NL}forward-zone:$NL  name: \".\"$NL"
        for n in $NAMESERVERS; do
-               newconf="${newconf}\tforward-addr: $n\n"
+               newconf="$newconf       forward-addr: $n$NL"
        done
 fi
 
 if [ ! -f "$unbound_conf" ] || \
-       [ "$(cat "$unbound_conf")" != "$(printf "$newconf")" ]
+       [ "$(cat "$unbound_conf")" != "$(printf %s "$newconf")" ]
 then
-       printf "$newconf" >"$unbound_conf"
+       printf %s "$newconf" >"$unbound_conf"
        # If we can't sent a HUP then force a restart
        if [ -s "$unbound_pid" ]; then
                if ! kill -HUP $(cat "$unbound_pid") 2>/dev/null; then