projects
/
zonemaker.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a683afa
)
support splitting TXT records into bind-sized chunks
author
Ralf Jung
<post@ralfj.de>
Sat, 5 Mar 2016 17:44:51 +0000
(18:44 +0100)
committer
Ralf Jung
<post@ralfj.de>
Sat, 5 Mar 2016 17:44:51 +0000
(18:44 +0100)
zone.py
patch
|
blob
|
history
diff --git
a/zone.py
b/zone.py
index 7d692c175ca52865d3f6a7f58a601ec8bf56e8d4..a74ee1858361619774a8f12ba8748b279ed18d64 100644
(file)
--- a/
zone.py
+++ b/
zone.py
@@
-110,6
+110,11
@@
def concatenate(root, path):
return path
return path+"."+root
return path
return path+"."+root
+def escape_TXT(text):
+ for c in ('\\', '\"'):
+ text = text.replace(c, '\\'+c)
+ return text
+
## Enums
class Protocol:
## Enums
class Protocol:
@@
-182,13
+187,17
@@
class TXT:
for c in ('\n', '\r', '\t'):
if c in text:
raise Exception("TXT record {0} contains invalid character")
for c in ('\n', '\r', '\t'):
if c in text:
raise Exception("TXT record {0} contains invalid character")
- # escape text
- for c in ('\\', '\"'):
- text = text.replace(c, '\\'+c)
self._text = text
def generate_rr(self):
self._text = text
def generate_rr(self):
- return RR('@', 'TXT', '"{0}"'.format(self._text))
+ text = escape_TXT(self._text)
+ # split into chunks of max. 255 characters; be careful not to split right after a backslash
+ chunks = re.findall(r'.{0,254}[^\\]', text)
+ assert sum(len(c) for c in chunks) == len (text)
+ chunksep = '"\n' + ' '*20 + '"'
+ chunked = '( "' + chunksep.join(chunks) + '" )'
+ # generate the chunks
+ return RR('@', 'TXT', chunked)
class DKIM(TXT): # helper class to treat DKIM more antively
class DKIM(TXT): # helper class to treat DKIM more antively