Changeset 888


Ignore:
Timestamp:
06/20/25 15:31:19 (10 days ago)
Author:
Kris Deugau
Message:

/trunk

Commit tweak to CNAME validator and tinydns export to support RPZ zones,
in production for a couple of months now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r887 r888  
    778778    return ('FAIL', $errstr) if ! _check_hostname_form(${$args{host}}, ${$args{rectype}}, $args{defrec}, $args{revrec});
    779779  } else {
    780     # CNAME target check - IP addresses not allowed.  Must be a more or less well-formed hostname.
    781     return ('FAIL', "CNAME records cannot point directly to an IP address")
    782       if ${$args{val}} =~ /^(?:[\d.]+|[0-9a-fA-F:]+)$/;
    783 
    784     # Make sure target is a well-formed hostname
    785     return ('FAIL', $errstr) if ! _check_hostname_form(${$args{val}}, ${$args{rectype}}, $args{defrec}, $args{revrec});
    786 
    787     # Forcibly append the domain name if the hostname being added does not end with the current domain name
    788     my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : $self->domainName($args{id}));
    789     ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/i;
    790 
    791     # CNAMEs can not be used for parent nodes;  just leaf nodes with no other record types
    792     # Enforce this for the zone name
    793     return ('FAIL', "The bare zone name may not be a CNAME") if ${$args{host}} eq $pname || ${$args{host}} =~ /^\@/;
     780    # a bit expensive to put this here, but we need some kind of cheap flag for an RPZ zone with different rules
     781    my $zname = $self->domainName($args{id});
     782    if ($zname =~ /\.rpz$/) {
     783      # RPZ domains consist almost entirely of CNAME records, and have special rules for their syntax
     784      # From the Unbound doc:  https://unbound.docs.nlnetlabs.nl/en/latest/topics/filtering/rpz.html
     785      # Supposedly other overrides are also valid
     786      return ('FAIL', "Unsupported RPZ override ${$args{val}}")
     787        unless ${$args{val}} =~ /^(?:\.|\*\.|rpz-passthru\.|rpz-drop\.|rpz-tcp-only\.)$/;
     788      # Append the RPZ name
     789      my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : $self->domainName($args{id}));
     790      ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/i;
     791    } else {
     792      # CNAME target check - IP addresses not allowed.  Must be a more or less well-formed hostname.
     793      return ('FAIL', "CNAME records cannot point directly to an IP address")
     794        if ${$args{val}} =~ /^(?:[\d.]+|[0-9a-fA-F:]+)$/;
     795
     796      # Make sure target is a well-formed hostname
     797      return ('FAIL', $errstr) if ! _check_hostname_form(${$args{val}}, ${$args{rectype}}, $args{defrec}, $args{revrec});
     798
     799      # Forcibly append the domain name if the hostname being added does not end with the current domain name
     800      my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : $zname);
     801      ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/i;
     802
     803      # CNAMEs can not be used for parent nodes;  just leaf nodes with no other record types
     804      # Enforce this for the zone name
     805      return ('FAIL', "The bare zone name may not be a CNAME") if ${$args{host}} eq $pname || ${$args{host}} =~ /^\@/;
    794806
    795807##enhance:  Look up the passed value to see if it exists.  Ooo, fancy.
    796     return ('FAIL', $errstr) if ! _check_hostname_form(${$args{val}}, ${$args{rectype}}, $args{defrec}, $args{revrec});
    797   }
     808      return ('FAIL', $errstr) if ! _check_hostname_form(${$args{val}}, ${$args{rectype}}, $args{defrec}, $args{revrec});
     809    } # $zname !~ .rpz
     810  } # revzone eq 'n'
    798811
    799812  return ('OK','OK');
     
    69626975  elsif ($typemap{$type} eq 'CNAME') {
    69636976    ($host,$val) = __revswap($host,$val) if $revrec eq 'y';
     6977    if ($zone =~ /\.rpz$/) {
     6978      $val = '..' if $val eq '.';
     6979    }
    69646980    print $datafile "C$host:$val:$ttl:$stamp:$loc\n" or die $!;
    69656981  } # CNAME
Note: See TracChangeset for help on using the changeset viewer.