- Timestamp:
- 02/09/12 14:43:08 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r229 r230 242 242 sub _validate_1 { 243 243 my $dbh = shift; 244 my $defrec = shift; 245 my $revrec = shift; 246 my $id = shift; # parent (group_id for defrecs, rdns_id for reverse records, 247 # domain_id for domain records) 248 249 # These next two should be references, so we can pass them back altered. Yes, we really want to do that. 250 my $host = shift; 251 my $val = shift; 252 my $addr = shift; 253 254 return ('FAIL', 'Reverse zones cannot contain A records') if $revrec eq 'y'; 244 245 my %args = @_; 246 247 return ('FAIL', 'Reverse zones cannot contain A records') if $args{revrec} eq 'y'; 255 248 256 249 # Coerce all hostnames to end in ".DOMAIN" for group/default records, 257 250 # or the intended parent domain for live records. 258 my $pname = ($ defrec eq 'y' ? 'DOMAIN' : domainName($dbh,$id));259 $ $host =~ s/\.*$/\.$pname/ if $$host!~ /$pname$/;251 my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id})); 252 ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/; 260 253 261 254 # Check IP is well-formed, and that it's a v4 address 262 255 return ('FAIL',"A record must be a valid IPv4 address") 263 unless $a ddr && !$addr->{isv6};256 unless $args{addr} && !$args{addr}->{isv6}; 264 257 # coerce IP/value to normalized form for storage 265 $ $val = $addr->addr;258 ${$args{val}} = $args{addr}->addr; 266 259 267 260 return ('OK','OK'); … … 270 263 # NS record 271 264 sub _validate_2 { 265 my $dbh = shift; 266 267 my %args = @_; 268 269 # Coerce the hostname to "DOMAIN" for forward default records, "ZONE" for reverse default records, 270 # or the intended parent zone for live records. 271 ##fixme: allow for delegating <subdomain>.DOMAIN? 272 if ($args{revrec} eq 'y') { 273 my $pname = ($args{defrec} eq 'y' ? 'ZONE' : revName($dbh,$args{id})); 274 ${$args{host}} = $pname if ${$args{host}} ne $pname; 275 } else { 276 my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id})); 277 ${$args{host}} = $pname if ${$args{host}} ne $pname; 278 } 279 280 # Let this lie for now. Needs more magic. 281 # # Check IP is well-formed, and that it's a v4 address 282 # return ('FAIL',"A record must be a valid IPv4 address") 283 # unless $addr && !$addr->{isv6}; 284 # # coerce IP/value to normalized form for storage 285 # $$val = $addr->addr; 286 272 287 return ('OK','OK'); 273 288 } # done NS record … … 275 290 # CNAME record 276 291 sub _validate_5 { 292 my $dbh = shift; 293 294 my %args = @_; 295 296 # Not really true, but these are only useful for delegating smaller-than-/24 IP blocks. 297 # This is fundamentally a messy operation and should really just be taken care of by the 298 # export process, not manual maintenance of the necessary records. 299 return ('FAIL', 'Reverse zones cannot contain CNAME records') if $args{revrec} eq 'y'; 300 301 # Coerce all hostnames to end in ".DOMAIN" for group/default records, 302 # or the intended parent domain for live records. 303 my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id})); 304 ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/; 305 277 306 return ('OK','OK'); 278 307 } # done CNAME record … … 280 309 # SOA record 281 310 sub _validate_6 { 311 # Smart monkeys won't stick their fingers in here; we have 312 # separate dedicated routines to deal with SOA records. 282 313 return ('OK','OK'); 283 314 } # done SOA record … … 290 321 # MX record 291 322 sub _validate_15 { 323 my $dbh = shift; 324 325 my %args = @_; 326 327 # Not absolutely true but WTF use is an MX record for a reverse zone? 328 return ('FAIL', 'Reverse zones cannot contain MX records') if $args{revrec} eq 'y'; 329 330 return ('FAIL', "Distance is required for MX records") unless defined(${$args{dist}}); 331 ${$args{dist}} =~ s/\s*//g; 332 return ('FAIL',"Distance is required, and must be numeric") unless ${$args{dist}} =~ /^\d+$/; 333 334 ${$args{fields}} = "distance,"; 335 push @{$args{vallist}}, ${$args{dist}}; 336 337 # Coerce all hostnames to end in ".DOMAIN" for group/default records, 338 # or the intended parent domain for live records. 339 my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id})); 340 ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/; 341 292 342 return ('OK','OK'); 293 343 } # done MX record … … 306 356 sub _validate_28 { 307 357 my $dbh = shift; 308 my $defrec = shift; 309 my $revrec = shift; 310 my $id = shift; # parent (group_id for defrecs, rdns_id for reverse records, 311 # domain_id for domain records) 312 313 # These next two should be references, so we can pass them back altered. Yes, we really want to do that. 314 my $host = shift; 315 my $val = shift; 316 my $addr = shift; 317 318 return ('FAIL', 'Reverse zones cannot contain AAAA records') if $revrec eq 'y'; 358 359 my %args = @_; 360 361 return ('FAIL', 'Reverse zones cannot contain AAAA records') if $args{revrec} eq 'y'; 319 362 320 363 # Coerce all hostnames to end in ".DOMAIN" for group/default records, 321 364 # or the intended parent domain for live records. 322 my $pname = ($ defrec eq 'y' ? 'DOMAIN' : domainName($dbh,$id));323 $ $host =~ s/\.*$/\.$pname/ if $$host!~ /$pname$/;365 my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id})); 366 ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/; 324 367 325 368 # Check IP is well-formed, and that it's a v6 address 326 369 return ('FAIL',"AAAA record must be a valid IPv6 address") 327 unless $a ddr && $addr->{isv6};370 unless $args{addr} && $args{addr}->{isv6}; 328 371 # coerce IP/value to normalized form for storage 329 $ $val = $addr->addr;372 ${$args{val}} = $args{addr}->addr; 330 373 331 374 return ('OK','OK');
Note:
See TracChangeset
for help on using the changeset viewer.