Allow pdnsd to add forward domains to it's configuration file.
authorRoy Marples <roy@marples.name>
Fri, 29 Oct 2010 15:47:49 +0000 (15:47 +0000)
committerRoy Marples <roy@marples.name>
Fri, 29 Oct 2010 15:47:49 +0000 (15:47 +0000)
pdnsd.in
resolvconf.conf.5.in

index d94d2fe625d57f85b2c9b0ff3a98a8214e03b720..72a20d3dac735c49ab5d1b3399162c11df65eb31 100644 (file)
--- a/pdnsd.in
+++ b/pdnsd.in
 [ -z "$pdnsd_resolv" ] && exit 0
 [ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
 
 [ -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"
 newresolv="# Generated by resolvconf\n"
+changed=false
 
 for n in $NAMESERVERS; do
        newresolv="${newresolv}nameserver $n\n"
 done
 
 
 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")" ]
 if [ -n "$pdnsd_resolv" ]; then
        if [ ! -f "$pdnsd_resolv" ] || \
                [ "$(cat "$pdnsd_resolv")" != "$(printf "$newresolv")" ]
index 432c92e74ecd1f391b779982353fadd32d1242b5..d742bcd42f03bdd1fb53c95e50051b09dc2fcdbc 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 October 28, 2010
+.Dd October 29, 2010
 .Dt RESOLVCONF.CONF 5 SMM
 .Os
 .Sh NAME
 .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;
 Example pdnsd.conf:
 .D1 global {
 .D1    server_ip = 127.0.0.1;
+.D1    status_ctl = on;
 .D1 }
 .D1 server {
 .D1    label="resolvconf";
 .D1 }
 .D1 server {
 .D1    label="resolvconf";