Changeset 532 for trunk/DNSDB.pm
- Timestamp:
- 09/26/13 16:50:54 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r531 r532 1231 1231 #major patterns: 1232 1232 #dashed IP, forward and reverse 1233 #underscoreed IP, forward and reverse 1233 1234 #dotted IP, forward and reverse (even if forward is... dumb) 1234 # -> %r for reverse, %i for forward, leading - or . to indicate separator, defaults to -1235 # -> %r for reverse, %i for forward, leading -, _, or . to indicate separator, defaults to - 1235 1236 # %r or %-r => %4d-%3d-%2d-%1d 1237 # %_r => %4d_%3d_%2d_%1d 1236 1238 # %.r => %4d.%3d.%2d.%1d 1237 1239 # %i or %-i => %1d-%2d-%3d-%4d 1240 # %_i => %1d_%2d_%3d_%4d 1238 1241 # %.i => %1d.%2d.%3d.%4d 1239 1242 $$tmpl =~ s/\%r/\%4d-\%3d-\%2d-\%1d/g; 1240 $$tmpl =~ s/\%([-. ])r/\%4d$1\%3d$1\%2d$1\%1d/g;1243 $$tmpl =~ s/\%([-._])r/\%4d$1\%3d$1\%2d$1\%1d/g; 1241 1244 $$tmpl =~ s/\%i/\%1d-\%2d-\%3d-\%4d/g; 1242 $$tmpl =~ s/\%([-. ])i/\%1d$1\%2d$1\%3d$1\%4d/g;1245 $$tmpl =~ s/\%([-._])i/\%1d$1\%2d$1\%3d$1\%4d/g; 1243 1246 1244 1247 #hex-coded IP … … 1260 1263 $$tmpl =~ s/\%([1234])0/$ippad[$1-1]/g; 1261 1264 } # _template4_expand() 1265 1266 # Broad syntactic check on the hostname. Checks for valid characters, correctly-expandable template patterns. 1267 # Takes the hostname, type, and live/default and forward/reverse flags 1268 # Returns true/false, sets errstr on failures 1269 sub _check_hostname_form { 1270 my ($hname,$rectype,$defrec,$revrec) = @_; 1271 1272 if ($hname =~ /\%/ && ($rectype == 65282 || $rectype == 65283) ) { 1273 my $tmphost = $hname; 1274 # we don't actually need to test with the real IP passed; that saves a bit of fiddling. 1275 _template4_expand(\$tmphost, '10.10.10.10'); 1276 if ($tmphost =~ /\%/) { 1277 $errstr = "Invalid template $hname"; 1278 return; 1279 } 1280 } elsif ($revrec eq 'y') { 1281 # Reverse zones don't support @ in hostnames 1282 # Also skip failure on revzone TXT records; the hostname contains the TXT content in that case. 1283 if ($rectype != $reverse_typemap{TXT} && lc($hname) !~ /^[0-9a-z_.-]+$/) { 1284 $errstr = "Hostnames may not contain anything other than (0-9 a-z . _)"; 1285 return; 1286 } 1287 } else { 1288 if (lc($hname) !~ /^(?:[0-9a-z_.-]+|@)$/) { 1289 # Don't mention @, because it would be far too wordy to explain the nuance of @ 1290 $errstr = "Hostnames may not contain anything other than (0-9 a-z . _)"; 1291 return; 1292 } 1293 } 1294 return 1; 1295 } # _check_hostname_form() 1262 1296 1263 1297 … … 3670 3704 return ('FAIL', "TTL must be numeric") unless $ttl =~ /^\d+$/; 3671 3705 3672 # Quick check on hostname parts. Note the regex is more forgiving than the error message; 3673 # domain names technically are case-insensitive, and we use printf-like % codes for a couple 3674 # of types. Other things may also be added to validate default records of several flavours. 3675 return ('FAIL', "Hostnames may not contain anything other than (0-9 a-z . _)") 3676 if $defrec eq 'n' && ($revrec eq 'y' ? $$rectype != $reverse_typemap{TXT} : 1) && 3677 $$host !~ /^(?:[0-9a-z_%.-]+|@)$/i; 3706 # Quick check on hostname parts. There are enough variations to justify a sub now. 3707 return ('FAIL', $errstr) if ! _check_hostname_form($$host, $$rectype, $defrec, $revrec); 3678 3708 3679 3709 # Collect these even if we're only doing a simple A record so we can call *any* validation sub … … 3807 3837 return ('FAIL', "TTL must be numeric") unless $ttl =~ /^\d+$/; 3808 3838 3809 # Quick check on hostname parts. Note the regex is more forgiving than the error message; 3810 # domain names technically are case-insensitive, and we use printf-like % codes for a couple 3811 # of types. Other things may also be added to validate default records of several flavours. 3812 return ('FAIL', "Hostnames may not contain anything other than (0-9 a-z - . _)") 3813 if $defrec eq 'n' && ($revrec eq 'y' ? $$rectype != $reverse_typemap{TXT} : 1) && 3814 $$host !~ /^(?:[0-9a-z_%.-]+|@)$/i; 3839 # Quick check on hostname parts. There are enough variations to justify a sub now. 3840 return ('FAIL', $errstr) if ! _check_hostname_form($$host, $$rectype, $defrec, $revrec); 3815 3841 3816 3842 # only MX and SRV will use these
Note:
See TracChangeset
for help on using the changeset viewer.