From 45c641b0b8958b626196fd63cd3efcffa28457d9 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 29 Oct 2010 15:47:49 +0000 Subject: [PATCH] Allow pdnsd to add forward domains to it's configuration file. --- pdnsd.in | 82 ++++++++++++++++++++++++++++++++++++++++++++++++-- resolvconf.conf.5.in | 3 +- 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/pdnsd.in b/pdnsd.in index d94d2fe..72a20d3 100644 --- a/pdnsd.in +++ b/pdnsd.in @@ -31,16 +31,92 @@ [ -z "$pdnsd_resolv" ] && exit 0 [ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)" -: ${pdnsd_restart:=pdnsd-ctl config} +: ${pdnsd_restart:=pdnsd-ctl config $pdnsd_conf} +signature="# Generated by resolvconf" +signature_end="# End of resolvconf" + +# We normally use sed to remove markers from a configuration file +# but sed may not always be available at the time. +remove_markers() +{ + local m1="$1" m2="$2" x= line= in_marker=0 + + shift; shift + if type sed >/dev/null 2>&1; then + sed "/^$m1/,/^$m2/d" $@ + else + for x; do + while read line; do + case "$line" in + "$m1"*) in_marker=1;; + "$m2"*) in_marker=0;; + *) [ $in_marker = 0 ] && echo "$line";; + esac + done < "$x" + done + fi +} + +# Compare two files +# If different, replace first with second otherwise remove second +change_file() +{ + if [ -e "$1" ]; then + if type cmp >/dev/null 2>&1; then + cmp -s "$1" "$2" + elif type diff >/dev/null 2>&1; then + diff -q "$1" "$2" >/dev/null + else + # Hopefully we're only working on small text files ... + [ "$(cat "$1")" = "$(cat "$2")" ] + fi + if [ $? -eq 0 ]; then + rm -f "$2" + return 1 + fi + fi + cat "$2" > "$1" + rm -f "$2" + return 0 +} + newresolv="# Generated by resolvconf\n" +changed=false for n in $NAMESERVERS; do newresolv="${newresolv}nameserver $n\n" done -# pdnsd does now support domain forwarding +if [ -n "$pdnsd_conf" ]; then + cf="$pdnsd_conf.new" + newconf= + for d in $DOMAINS; do + newconf="${newconf}server {\n" + newconf="${newconf}\tinclude=\"${d%%:*}\";\n" + newconf="${newconf}\tpolicy=excluded;\n" + newconf="${newconf}\tip=" + ns="${d#*:}" + while [ -n "$ns" ]; do + newconf="${newconf}${ns%%,*}" + [ "$ns" = "${ns#*,}" ] && break + ns="${ns#*,}" + newconf="${newconf}," + done + newconf="${newconf};\n}\n" + done + + rm -f "$cf" + remove_markers "$signature" "$signature_end" "$pdnsd_conf" > "$cf" + if [ -n "$newconf" ]; then + echo "$signature" >> "$cf" + printf "$newconf" >> "$cf" + echo "$signature_end" >> "$cf" + fi + if change_file "$pdnsd_conf" "$cf"; then + changed=true + fi +fi -changed=false if [ -n "$pdnsd_resolv" ]; then if [ ! -f "$pdnsd_resolv" ] || \ [ "$(cat "$pdnsd_resolv")" != "$(printf "$newresolv")" ] diff --git a/resolvconf.conf.5.in b/resolvconf.conf.5.in index 432c92e..d742bcd 100644 --- a/resolvconf.conf.5.in +++ b/resolvconf.conf.5.in @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd October 28, 2010 +.Dd October 29, 2010 .Dt RESOLVCONF.CONF 5 SMM .Os .Sh NAME @@ -144,6 +144,7 @@ Example resolvconf.conf for pdnsd: Example pdnsd.conf: .D1 global { .D1 server_ip = 127.0.0.1; +.D1 status_ctl = on; .D1 } .D1 server { .D1 label="resolvconf"; -- 1.7.1