Commit 1597b506 authored by Côme Chilliet's avatar Côme Chilliet

Merge branch '5760-add-the-caa-record-creation-on-argonaut-ldap2zone' into '1.4-dev'

Resolve "add the CAA record creation on argonaut-ldap2zone"

See merge request argonaut/argonaut!145
parents 106cde98 4157cd9e
......@@ -32,11 +32,9 @@ use 5.008;
use Exporter 'import'; # gives you Exporter's import() method directly
our @EXPORT_OK = qw(&argonaut_ldap2zone); # symbols to export on request
use DNS::ZoneParse;
use Argonaut::Libraries::Common qw(:ldap :config);
my @record_types = ('a','aaaa','cname','mx','ns','ptr','txt','srv','hinfo','rp','loc');
my @record_types = ('a','aaaa','caa','cname','mx','ns','ptr','txt','srv','hinfo','rp','loc');
my $NAMEDCHECKCONF = 'named-checkconf';
......@@ -205,16 +203,10 @@ sub zoneparse
print "Found ".scalar($mesg->entries())." results\n" if $verbose;
my $zonefile = DNS::ZoneParse->new(\"", $zone);
my $records = {};
my $records = {};
my $soa_record = {};
foreach my $record (@record_types) {
eval { #try
$records->{$record} = $zonefile->$record();
};
if ($@) { # catch
print "This DNS::ZoneParse version does not support '$record' record\n" if $verbose;
};
$records->{$record} = [];
}
my $dn; # Dn of zone entry;
......@@ -230,7 +222,7 @@ sub zoneparse
if(!$ttl) {
$ttl = "";#$default_ttl;
}
while(my ($type,$list) = each %{$records}){
while (my ($type,$list) = each %{$records}) {
foreach my $value ($entry->get_value($type."Record")) {
if (defined $unicityTest{$type.$name.$value.$class.$ttl}) {
# Avoid putting twice the same record
......@@ -238,19 +230,13 @@ sub zoneparse
} else {
$unicityTest{$type.$name.$value.$class.$ttl} = 1;
}
if($type eq "txt") {
push @{$list},{ name => $name, class => $class,
text => $value, ttl => $ttl, ORIGIN => $zone };
} else {
push @{$list},{ name => $name, class => $class,
host => $value, ttl => $ttl, ORIGIN => $zone };
}
push @{$list},{ name => $name, class => $class,
value => $value, ttl => $ttl };
print "Added record $type $name $class $value $ttl\n" if $verbose;
}
}
my $soa = $entry->get_value("sOARecord");
if ($soa) {
my $soa_record = $zonefile->soa();
my (@soa_fields) = split(' ',$soa);
if ((not defined $soa_record->{'serial'}) or ($soa_fields[2] > $soa_record->{'serial'})) {
$soa_record->{'primary'} = $soa_fields[0];
......@@ -282,12 +268,63 @@ sub zoneparse
my $file_output = "$output_BIND_CACHE_DIR/db.$zone";
my $newzone;
open($newzone, q{>}, $file_output) or die "error while trying to open $file_output";
print $newzone $zonefile->output();
print $newzone computezonecontent($zone, $soa_record, $records);
close $newzone;
return $dn;
}
sub computezonecontent
{
my ($ORIGIN,$soa,$records) = @_;
my $zone_ttl = $soa->{ttl} ? "\$TTL $soa->{ttl}" : '';
my $output = '';
$output .= <<ZONEHEADER1;
;
; Database file for $ORIGIN zone.
; Zone version: $soa->{serial}
: Generated by Argonaut::Libraries::Ldap2zone
;
ZONEHEADER1
if ( $soa->{'ORIGIN'} ne $soa->{'origin'} ) {
$output .= "\n\$ORIGIN $soa->{'ORIGIN'}\n\n";
}
$output .= <<ZONEHEADER2;
$zone_ttl
$soa->{origin} $soa->{ttl} IN SOA $soa->{primary} $soa->{email} (
$soa->{serial} ; serial number
$soa->{refresh} ; refresh
$soa->{retry} ; retry
$soa->{expire} ; expire
$soa->{minimumTTL} ; minimum TTL
)
;
; Zone Records
;
ZONEHEADER2
if ( $ORIGIN ne $soa->{'ORIGIN'} ) {
$output .= "\n\;\n\; $ORIGIN records\n\;\n\n";
$output .= "\$ORIGIN $ORIGIN\n\n";
}
while (my ($type,$list) = each %{$records}) {
foreach my $o (@$list) {
$output .= sprintf(
"%-15s %-5s %-5s %-5s %s\n",
$o->{name}, $o->{ttl}, $o->{class}, uc($type), $o->{value}
);
}
}
return $output;
}
=item zonesearch
Search the zone in the LDAP
Params : ldap handle, ldap base, zone name, bind dir, TTL, verbose flag
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment