Control: tags -1 + patch

I had a look at the C source of ldap2zone, and am not quite sure how
to add code there to ensure the emitted zone info is valid.  But
another idea is to use bind to check it, and revert the new zone file
if bind reject the new file.  Here is a untested draft patch doing that.

Would this be an OK approach?

It is done by backing up the original zone file before doing the
reload, and restoring the backup if the reload failed.  I introduced
three variables TEMPFILE, CURRENT and OLD to make the lines shorter
and easier to read.

--- ldap2zone-0.2.orig/ldap2bind
+++ ldap2zone-0.2/ldap2bind
@@ -78,15 +78,24 @@ EOF
 fi
 
 for domain in $ZONES; do
-       if $ldap2zone $domain $LDAP_URI $TTL > /tmp/$domain; then
-               lines=$(cat /tmp/$domain | wc -l)
-               [ $lines -gt 1 ] && mv /tmp/$domain 
$BIND_DATA/${PREFIX}${domain}
-       fi
+       TMPFILE=$TMPFILE
+       CURRENT=$BIND_DATA/${PREFIX}${domain}
+       OLD=$BIND_DATA/${PREFIX}${domain}.old-$$
+       if $ldap2zone $domain $LDAP_URI $TTL > $TMPFILE; then
+               lines=$(cat $TMPFILE | wc -l)
+               if [ $lines -gt 1 ] ; then
+                   mv $CURRENT $OLD
+                   mv $TMPFILE $CURRENT
+               fi
+        fi
 
        result=$($rndc reload $domain 2>&1)
        if [ $? -ne 0 ]; then
-                logger -t ldap2bind "Reloading the zone '$domain' failed: 
$result\n"
-       else
+                logger -t ldap2bind "Reloading the zone '$domain' failed: 
$result. Reverting.\n"
+                mv $CURRENT $CURRENT.broken
+                mv $OLD $CURRENT
+        else
+                rm $OLD
                 logger -t ldap2bind "Reloading the zone '$domain' was 
successful\n"
-       fi
+        fi
 done



-- 
Happy hacking
Petter Reinholdtsen


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to