zone.lisp: Apply pathname templates to DKIM and SSHFP files.
[zone] / zone.lisp
index 8d35c09..f03b9dd 100644 (file)
--- a/zone.lisp
+++ b/zone.lisp
   records)
 
 (export '*zone-output-path*)
-(defvar *zone-output-path* *default-pathname-defaults*
-  "Pathname defaults to merge into output files.")
+(defvar *zone-output-path* nil
+  "Pathname defaults to merge into output files.
+
+   If this is nil then use the prevailing `*default-pathname-defaults*'.
+   This is not the same as capturing the `*default-pathname-defaults*' from
+   load time.")
 
 (export '*preferred-subnets*)
 (defvar *preferred-subnets* nil
   "Choose a file name for a given ZONE and TYPE."
   (merge-pathnames (make-pathname :name (string-downcase zone)
                                  :type (string-downcase type))
-                  *zone-output-path*))
+                  (or *zone-output-path* *default-pathname-defaults*)))
 
 (export 'zone-preferred-subnet-p)
 (defun zone-preferred-subnet-p (name)
   ":txt TEXT"
   (rec :data data))
 
+(export '*dkim-pathname-defaults*)
+(defvar *dkim-pathname-defaults*
+  (make-pathname :directory '(:relative "keys")
+                :type "dkim"))
+
 (defzoneparse :dkim (name data rec)
   ":dkim (KEYFILE {:TAG VALUE}*)"
   (destructuring-bind (file &rest plist) (listify data)
        (emit (with-output-to-string (out)
                (write-string "p=" out)
                (when file
-                 (with-open-file (in file :direction :input)
+                 (with-open-file
+                     (in (merge-pathnames file *dkim-pathname-defaults*))
                    (loop
                      (when (string= (read-line in)
                                     "-----BEGIN PUBLIC KEY-----")
       (setf (get sym prop) val)
       (export sym))))
 
+(export '*sshfp-pathname-defaults*)
+(defvar *sshfp-pathname-defaults*
+  (make-pathname :directory '(:relative "keys")
+                :type "sshfp"))
+
 (defzoneparse :sshfp (name data rec)
   ":sshfp { FILENAME | ((FPR :alg ALG :type HASH)*) }"
   (if (stringp data)
-      (with-open-file (in data)
+      (with-open-file (in (merge-pathnames data *sshfp-pathname-defaults*))
        (loop (let ((line (read-line in nil)))
                (unless line (return))
                (let ((words (str-split-words line)))
                 (fixnum what)
                 (symbol (or (get what prop)
                             (error "~S is not a known ~A" what prop))))))
-       (dolist (item (listify data)
-                (destructuring-bind (fpr &key (alg 'rsa) (type 'sha-1))
-                    (listify item)
-                  (rec :data (list (lookup alg 'sshfp-algorithm)
-                                   (lookup type 'sshfp-type)
-                                   fpr))))))))
+       (dolist (item (listify data))
+         (destructuring-bind (fpr &key (alg 'rsa) (type 'sha-1))
+             (listify item)
+           (rec :data (list (lookup alg 'sshfp-algorithm)
+                            (lookup type 'sshfp-type)
+                            fpr)))))))
 
 (defzoneparse :mx (name data rec :zname zname)
   ":mx ((HOST :prio INT :ip IPADDR)*)"