zoneconf.in: Set up a temporary directory when signing.
[zoneconf] / zoneconf.in
index 22f170f..541c019 100755 (executable)
@@ -1013,7 +1013,6 @@ define-configuration-space zone ZONECFG {
   define-list sign-views {}
   define-list signzone-command \
       [list "$BINDPROGS/dnssec-signzone" \
-          "-g" \
           "-S" \
           "-K%h/key" \
           "-d%h/ds" \
@@ -1137,6 +1136,16 @@ proc output-file-name {view} {
   return [string map [list %v $view] $ZONECFG(conf-file)]
 }
 
+proc temporary-directory {} {
+  ## Create a temporary directory and set as the working directory.
+
+  global ZONECFG
+  set tmp [file join $ZONECFG(home-dir) "tmp"]
+  file mkdir $tmp
+  cd $tmp
+  return $tmp
+}
+
 proc compute-zone-properties {view config} {
   ## Derive interesting information from the zone configuration plist CONFIG,
   ## relative to the stated server VIEW.  Return a new plist.
@@ -1405,7 +1414,7 @@ provided by the named USER."
   isolate [list confspc-eval toplevel [list source $CONFFILE]]
 
   ## Make sure there's a temporary directory.
-  file mkdir [file join $ZONECFG(home-dir) "tmp"]
+  set tmpdir [temporary-directory]
 
   ## Keep track of cleanup jobs.
   set cleanup {}
@@ -1436,8 +1445,7 @@ provided by the named USER."
     ## Make a new temporary file to read the zone into.
     set pid [pid]
     for {set i 0} {$i < 1000} {incr i} {
-      set tmp [file join $ZONECFG(home-dir) "tmp" \
-                  "tmp.$pid.$i.$user.$name"]
+      set tmp [file join $tmpdir "tmp.$pid.$i.$user.$name"]
       if {![catch { set chan [open $tmp {WRONLY CREAT EXCL}] } msg]} {
        break
       } elseif {[string equal [lindex $errorCode 0] POSIX] && \
@@ -1503,6 +1511,10 @@ defcmd sign {} {
   ## Read the configuration.
   isolate [list confspc-eval toplevel [list source $CONFFILE]]
 
+  ## Sometimes `dnssec-signzone' tries to write temporary files to the
+  ## current directory.  Make sure this is sensible.
+  temporary-directory
+
   ## Grind through all of the zones.
   array unset seen
   foreach view $ZONECFG(all-views) {