From c5c1378f59bd81bbc9638c1862e5c81ebf02d23d Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 14 Mar 2023 11:34:48 +0000 Subject: [PATCH] trust-dns: properly quote TXT records --- modules/services/trust-dns.nix | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/services/trust-dns.nix b/modules/services/trust-dns.nix index 8212ec65..3919951d 100644 --- a/modules/services/trust-dns.nix +++ b/modules/services/trust-dns.nix @@ -7,7 +7,20 @@ with lib; let cfg = config.sane.services.trust-dns; toml = pkgs.formats.toml { }; - fmtRecord = proto: rrtype: name: value: "${name}\t${proto}\t${rrtype}\t${value}"; + recordFormatters = { + # quote rules for zone files: + # - any character may be encoded by `\DDD`, where `DDD` represents its ascii value in base 8. + # - any non-digit `X` may be encoded by `\X`. + # - stated in: : 5.1 Format + # - visible in + # for us, we can just replace `\` => `\\ and `"` -> `\"` + TXT = value: "\"" + (lib.escape [ "\\" "\"" ] value) + "\""; + }; + fmtRecord = proto: rrtype: name: value: + let + formatter = recordFormatters."${rrtype}" or lib.id; + in + "${name}\t${proto}\t${rrtype}\t${formatter value}"; fmtRecordList = proto: rrtype: name: values: concatStringsSep "\n" (map (fmtRecord proto rrtype name) values)