# HG changeset patch # User Matthias Förste # Date 1309444497 -7200 # Node ID 1ed33114d87fa1e655932b19be4728d8a5e53ab8 # Parent 44183c6b78b6681628491b97efdedfc34d1e4f18# Parent c33217cb59896a6a8dbed92c5bb10a1546dc5715 merged in perltidy diff -r 44183c6b78b6 -r 1ed33114d87f .hgtags --- a/.hgtags Thu Jun 30 16:15:59 2011 +0200 +++ b/.hgtags Thu Jun 30 16:34:57 2011 +0200 @@ -3,3 +3,4 @@ 0e1e5027e9c09113c3c9f540a4bcd9ad0b815ea2 v0.1.1 0000000000000000000000000000000000000000 v0.1.1 5bdc20e4d5f039a0b2029234bc7a1edcb75ba1d1 0.1.1 +3db36388076614efb4bcfeb3c13b565967f50f85 0.1.2 diff -r 44183c6b78b6 -r 1ed33114d87f Build.PL --- a/Build.PL Thu Jun 30 16:15:59 2011 +0200 +++ b/Build.PL Thu Jun 30 16:34:57 2011 +0200 @@ -31,18 +31,19 @@ create_license => 1, license => "gpl", requires => { - perl => "5.10.0", - "Net::LibIDN" => "0", - "Template" => "0", - "Net::DNS" => "0", - "Net::DNS::SEC" => "0", + perl => "5.10.0", + "Net::LibIDN" => "0", + "Template" => "0", + "Net::DNS" => "0", + "Net::DNS::SEC" => "0", }, script_files => [glob "bin/*"], # avoid .swp files - sbin_files => { map { /\.(bak|orig)$/ ? () : ( $_ => $_ ) } glob("sbin/*") }, + sbin_files => { map { /\.(bak|orig)$/ ? () : ($_ => $_) } glob("sbin/*") }, nagios_files => { 'dnsnagios/check_dnssec' => 'sbin/check_dnssec' }, ); $build->add_build_element('sbin'); $build->add_build_element('nagios'); -$build->install_path('sbin' => $build->original_prefix($build->installdirs) . '/sbin'); +$build->install_path( + 'sbin' => $build->original_prefix($build->installdirs) . '/sbin'); $build->create_build_script; diff -r 44183c6b78b6 -r 1ed33114d87f lib/DNStools/UpdateSerial.pm --- a/lib/DNStools/UpdateSerial.pm Thu Jun 30 16:15:59 2011 +0200 +++ b/lib/DNStools/UpdateSerial.pm Thu Jun 30 16:34:57 2011 +0200 @@ -32,22 +32,22 @@ use POSIX qw(strftime); use if $ENV{DEBUG} => "Smart::Comments"; - BEGIN { our ($VERSION, @ISA, @EXPORT); use Exporter; # set the version for version checking - $VERSION = 1.00; + $VERSION = 1.00; + # if using RCS/CVS, this may be preferred $VERSION = sprintf "%d.%03d", q$Revision: 1.1 $ =~ /(\d+)/g; - @ISA = qw(Exporter); - @EXPORT = qw(&uniq &zones &changed_zones &update_index - &signature_expired &need_rollover &done_rollover &begin_rollover - &end_rollover &unlink_unused_keys &include_keys &sign &update_serial - &mk_zone_conf &file_entry &server_reload &dnssec_enabled %config); + @ISA = qw(Exporter); + @EXPORT = qw(&uniq &zones &changed_zones &update_index + &signature_expired &need_rollover &done_rollover &begin_rollover + &end_rollover &unlink_unused_keys &include_keys &sign &update_serial + &mk_zone_conf &file_entry &server_reload &dnssec_enabled %config); } our %config; @@ -111,8 +111,9 @@ next; } - my $stamp_mtime = (stat _)[9]; - my $zone_file_mtime = (stat "$_/$zone")[9] or die "Can't stat '$_/$zone': $!"; + my $stamp_mtime = (stat _)[9]; + my $zone_file_mtime = (stat "$_/$zone")[9] + or die "Can't stat '$_/$zone': $!"; # stamp age 'wins' if mtimes are equal because update_serial will both # modify the zonefile and update the stamp which both is likely to @@ -182,7 +183,8 @@ sub update_serial($) { my $zone = shift; -# say "XXX: $zone: updating serial number"; + + # say "XXX: $zone: updating serial number"; my $file = "$config{master_dir}/$zone/$zone"; my $in = IO::File->new($file) or die "Can't open $file: $!\n"; @@ -203,9 +205,9 @@ or die "Can't rename tmp to $file: $!\n"; my $perms = (stat $file)[2] & 07777 | 040 - or die "Can't stat '$file': $!"; + or die "Can't stat '$file': $!"; chmod $perms, $file - or die "Can't 'chmod $perms, $file': $!"; + or die "Can't 'chmod $perms, $file': $!"; $serial =~ s/\s*//g; say " * $zone: serial incremented to $serial"; @@ -213,7 +215,8 @@ open(my $stamp, ">", dirname($file) . "/.stamp"); say " * $zone: stamp aktualisiert"; -# say " XXX $zone: stamp '$s' aktualisiert"; + + # say " XXX $zone: stamp '$s' aktualisiert"; } sub new_serial($) { @@ -274,9 +277,9 @@ } my $perms = (stat _)[2] & 07777 | 040 - or die "Can't stat '$izf': $!"; + or die "Can't stat '$izf': $!"; chmod $perms, $izf - or die "Can't 'chmod $perms, $izf': $!"; + or die "Can't 'chmod $perms, $izf': $!"; say "** index-zone aktualisiert"; return $indexzone; @@ -296,16 +299,18 @@ my $cf = "$cd/$z"; my $de = dnssec_enabled $z, "$md/$config{indexzone}/$config{indexzone}"; my $suf = $de ? '.signed' : ''; - # TODO: assuming that paths in $md and in zone config snippets match somehow + + # TODO: assuming that paths in $md and in zone config snippets match somehow my $zr = qr{\Q$z/$z$suf\E$}; my $zf = "$md/$z/$z$suf"; my ($files, $changed) = (0, 0); my $czf; open C, "+<$cf" or die "Cant't open '$cf': $!"; - my @lines = ; # TODO: deal with race condition? + my @lines = ; # TODO: deal with race condition? my @oldlines; - my ($mode, $uid, $gid, $atime, $mtime) = (stat C)[2, 4, 5, 8, 9] or die "Can't stat: $!"; + my ($mode, $uid, $gid, $atime, $mtime) = (stat C)[2, 4, 5, 8, 9] + or die "Can't stat: $!"; $mode &= 07777; for (@lines) { next unless /^\s*file\s+"([^"]*)"\s*;\s*$/; @@ -318,20 +323,24 @@ } } - die "Multiple file statements found in '$cf' (maybe inside multiline comments)" if $files > 1; + die +"Multiple file statements found in '$cf' (maybe inside multiline comments)" + if $files > 1; next unless $changed; - # file statement in config snippet doesnt match, so we make a backup first and write a new config +# file statement in config snippet doesnt match, so we make a backup first and write a new config my $cb = "$cf.bak"; open B, ">$cb" or die "Can't open '$cb': $!"; print B @oldlines; close B; chown $uid, $gid, $cb or die "Can't 'chown $uid, $gid, $cb': $!"; chmod $mode, $cb or die "Can't 'chmod $mode, $cb': $!"; - utime $atime, $mtime, $cb or die "Can't 'utime $atime, $mtime, $cb': $!"; + utime $atime, $mtime, $cb + or die "Can't 'utime $atime, $mtime, $cb': $!"; truncate C, 0 or die "Can't truncate C, 0: $!"; seek C, 0, 0 or die "Can't seek C, 0, 0: $!"; + # write back @lines we modified earlier print C @lines; close C; @@ -368,12 +377,12 @@ sub done_rollover() { - # funktion ueberprueft ob ein keyrollover fertig ist - # die bedingung dafuer ist das: - # - eine datei .index.zsk vorhanden ist - # - die letzte änderung an der datei .index.zsk länger her ist als die abl_zeit - # - die datei .index.zsk ueber mehr als eine zeile gross ist - # (also mehr als einen Schlüssel enthält) +# funktion ueberprueft ob ein keyrollover fertig ist +# die bedingung dafuer ist das: +# - eine datei .index.zsk vorhanden ist +# - die letzte änderung an der datei .index.zsk länger her ist als die abl_zeit +# - die datei .index.zsk ueber mehr als eine zeile gross ist +# (also mehr als einen Schlüssel enthält) my @r; my $now = time; @@ -537,7 +546,8 @@ open I, "<$if" or die "Can't open index zone file '<$if': $!"; while () { -# say "XXX: match: $_" if /$re/; + + # say "XXX: match: $_" if /$re/; $r = $1 eq 'on' and last if /$re/; } close I; diff -r 44183c6b78b6 -r 1ed33114d87f sbin/dnssec-keytool --- a/sbin/dnssec-keytool Thu Jun 30 16:15:59 2011 +0200 +++ b/sbin/dnssec-keytool Thu Jun 30 16:34:57 2011 +0200 @@ -39,10 +39,11 @@ "h|help" => sub { pod2usage(-exit => 0, -verbose => 1) }, "m|man" => sub { pod2usage( - -exit => 0, - # "system('perldoc -V &>/dev/null')" appears shorter, but may not - # do what you expect ( it still returns 0 on debian squeeze with - # dash as system shell even if cannot find the command in $PATH) + -exit => 0, + + # "system('perldoc -V &>/dev/null')" appears shorter, but may not + # do what you expect ( it still returns 0 on debian squeeze with + # dash as system shell even if cannot find the command in $PATH) -noperldoc => system('perldoc -V >/dev/null 2>&1'), -verbose => 2 ); @@ -65,18 +66,19 @@ } given ($cmd) { - when ("zsk") { exit create_zsk(@zones) }; - when ("ksk") { exit create_ksk(@zones) }; + when ("zsk") { exit create_zsk(@zones) }; + when ("ksk") { exit create_ksk(@zones) }; + #when ("check") { exit check_zone(@zones) }; - when ("rm") { exit rm_keys(@zones) }; - default { die "not implemented\n" }; + when ("rm") { exit rm_keys(@zones) }; + default { die "not implemented\n" }; }; } sub rm_keys (@) { - my @zones = @_; + my @zones = @_; my $master_dir = "$cf{master_dir}"; for my $zone (@zones) { @@ -84,12 +86,11 @@ my $dir = "$master_dir/$zone"; my $ep = 0; - my @files = map "$dir/$_", ("$zone.signed", - ".keycounter", - ".index.ksk", - ".index.zsk", - "dsset-$zone.", - "keyset-$zone."); + my @files = map "$dir/$_", + ( + "$zone.signed", ".keycounter", ".index.ksk", ".index.zsk", + "dsset-$zone.", "keyset-$zone." + ); push @files, glob "$dir/K$zone*"; for my $f (@files) { @@ -104,7 +105,8 @@ open my $old, "$dir/$zone" or die "Can't open '$dir/$zone': $!\n"; my @old = <$old>; close $old; - my @new = grep { not /^\s*\$include\s+("?)K\Q$zone\E.*\.key\1\s*$/i } @old; + my @new = + grep { not /^\s*\$include\s+("?)K\Q$zone\E.*\.key\1\s*$/i } @old; return if @new ~~ @old; my $new = File::Temp->new(UNLINK => 0) @@ -127,9 +129,7 @@ ksk => { cmd => 'cd %s && dnssec-keygen -a RSASHA1 -b 2048 -f KSK -n ZONE %s' }, - zsk => { - cmd => 'cd %s && dnssec-keygen -a RSASHA1 -b 512 -n ZONE %s' - } + zsk => { cmd => 'cd %s && dnssec-keygen -a RSASHA1 -b 512 -n ZONE %s' } }; @@ -142,17 +142,20 @@ my $cmd = sprintf $args->{$type}->{cmd}, $dir, $zone; chomp($keyname = qx/$cmd/); - die "Key generation failed! (output was: '$keyname')" unless $keyname =~ /^K\Q$zone\E\.?\+\d{3}\+\d{5}$/; + die "Key generation failed! (output was: '$keyname')" + unless $keyname =~ /^K\Q$zone\E\.?\+\d{3}\+\d{5}$/; - open $idx, '+>>', "$dir/.index.$type" or die "Can't open $dir/.index.$type: $!\n"; - seek $idx, 0 ,0 or die "Cant' seek: $!"; - chomp (@index = <$idx>); + open $idx, '+>>', "$dir/.index.$type" + or die "Can't open $dir/.index.$type: $!\n"; + seek $idx, 0, 0 or die "Cant' seek: $!"; + chomp(@index = <$idx>); push @index, $keyname; + # TODO: this should be part of the key removal procedure, no? # shift @index if @index > 2; - seek $idx, 0 ,0 or die "Cant' seek: $!"; + seek $idx, 0, 0 or die "Cant' seek: $!"; truncate $idx, 0 or die "Can't truncate: $!"; print $idx join "\n" => @index, ''; close $idx; @@ -162,7 +165,8 @@ key_to_zonefile($keyname); if (lc $type eq 'zsk') { - open my $kc, '>', "$dir/.keycounter" or die "Can't open $dir/.keycounter: $!\n"; + open my $kc, '>', "$dir/.keycounter" + or die "Can't open $dir/.keycounter: $!\n"; print $kc "0\n"; close $kc; } @@ -273,7 +277,7 @@ my (@lines, $tmp); open OLD, '<', $zf or die "Can't open $zf: $!\n"; - chomp (@lines = ); + chomp(@lines = ); close OLD; return if grep /^\s*\$include\s+("?)\Q$keyname\E\.key\1\s*$/i, @lines; diff -r 44183c6b78b6 -r 1ed33114d87f sbin/update-serial --- a/sbin/update-serial Thu Jun 30 16:15:59 2011 +0200 +++ b/sbin/update-serial Thu Jun 30 16:34:57 2011 +0200 @@ -45,19 +45,20 @@ "h|help" => sub { pod2usage(-exit => 0, -verbose => 1) }, "m|man" => sub { pod2usage( - -exit => 0, - -verbose => 2, - # "system('perldoc -V &>/dev/null')" appears shorter, but may not - # do what you expect ( it still returns 0 on debian squeeze with - # dash as system shell even if cannot find the command in $PATH) + -exit => 0, + -verbose => 2, + + # "system('perldoc -V &>/dev/null')" appears shorter, but may not + # do what you expect ( it still returns 0 on debian squeeze with + # dash as system shell even if cannot find the command in $PATH) -noperldoc => system('perldoc -V >/dev/null 2>&1') ); } ) or pod2usage; # merge the config and the defined options from commandline - my @configs = ( "dnstools.conf", "$ENV{HOME}/.dnstools.conf", - "/etc/dnstools.conf"); + my @configs = + ("dnstools.conf", "$ENV{HOME}/.dnstools.conf", "/etc/dnstools.conf"); unshift @configs, $ENV{DNSTOOLS_CONF} if defined $ENV{DNSTOOLS_CONF}; %config = get_config @configs, \%opt; @@ -72,9 +73,13 @@ push @candidates, end_rollover(@done_rollover); foreach my $zone (uniq(@candidates)) { -# say "XXX: candidate $zone"; + + # say "XXX: candidate $zone"; update_serial($zone); - sign($zone) if dnssec_enabled($zone, "$config{master_dir}/$config{indexzone}/$config{indexzone}"); + sign($zone) + if dnssec_enabled($zone, + "$config{master_dir}/$config{indexzone}/$config{indexzone}"); + # say "XXX: $zone should be signed" if dnssec_enabled($zone, "$config{master_dir}/$config{indexzone}/$config{indexzone}"); } diff -r 44183c6b78b6 -r 1ed33114d87f sbin/zone-ls --- a/sbin/zone-ls Thu Jun 30 16:15:59 2011 +0200 +++ b/sbin/zone-ls Thu Jun 30 16:34:57 2011 +0200 @@ -21,11 +21,12 @@ "h|help" => sub { pod2usage(-exit => 0, -verbose => 1) }, "m|man" => sub { pod2usage( - -exit => 0, - -verbose => 2, - # "system('perldoc -V &>/dev/null')" appears shorter, but may not - # do what you expect ( it still returns 0 on debian squeeze with - # dash as system shell even if cannot find the command in $PATH) + -exit => 0, + -verbose => 2, + + # "system('perldoc -V &>/dev/null')" appears shorter, but may not + # do what you expect ( it still returns 0 on debian squeeze with + # dash as system shell even if cannot find the command in $PATH) -noperldoc => system('perldoc -V >/dev/null 2>&1') ); }, diff -r 44183c6b78b6 -r 1ed33114d87f sbin/zone-mk --- a/sbin/zone-mk Thu Jun 30 16:15:59 2011 +0200 +++ b/sbin/zone-mk Thu Jun 30 16:34:57 2011 +0200 @@ -26,10 +26,11 @@ "h|help" => sub { pod2usage(-verbose => 1, -exit => 0) }, "m|man" => sub { pod2usage( - -verbose => 2, - # "system('perldoc -V &>/dev/null')" appears shorter, but may not - # do what you expect ( it still returns 0 on debian squeeze with - # dash as system shell even if cannot find the command in $PATH) + -verbose => 2, + + # "system('perldoc -V &>/dev/null')" appears shorter, but may not + # do what you expect ( it still returns 0 on debian squeeze with + # dash as system shell even if cannot find the command in $PATH) -noperldoc => system('perldoc -V >/dev/null 2>&1'), -exit => 0 ); @@ -48,7 +49,7 @@ # in die entsprechenden verzeichnisse. for my $utf8zone (@ARGV) { - my $zone = idn_to_ascii($utf8zone, $CHARSET); + my $zone = idn_to_ascii($utf8zone, $CHARSET); my $zonefile = "$cf{master_dir}/$zone/$zone"; my $configfile = "$cf{zone_conf_dir}/$zone"; my $now = time; @@ -68,8 +69,8 @@ say "zone $utf8zone ($zone) for $customer."; my %vars = ( - zone => $zone, - utf8zone => $utf8zone, + zone => $zone, + utf8zone => $utf8zone, now => $now, zonefile => abs_path($zonefile), customer => $customer, diff -r 44183c6b78b6 -r 1ed33114d87f sbin/zone-rm --- a/sbin/zone-rm Thu Jun 30 16:15:59 2011 +0200 +++ b/sbin/zone-rm Thu Jun 30 16:34:57 2011 +0200 @@ -22,11 +22,12 @@ "h|help" => sub { pod2usage(-exit => 0, -verbose => 1) }, "m|man" => sub { pod2usage( - -exit => 0, - -verbose => 2, - # "system('perldoc -V &>/dev/null')" appears shorter, but may not - # do what you expect ( it still returns 0 on debian squeeze with - # dash as system shell even if cannot find the command in $PATH) + -exit => 0, + -verbose => 2, + + # "system('perldoc -V &>/dev/null')" appears shorter, but may not + # do what you expect ( it still returns 0 on debian squeeze with + # dash as system shell even if cannot find the command in $PATH) -noperldoc => system('perldoc -V >/dev/null 2>&1') ); }, diff -r 44183c6b78b6 -r 1ed33114d87f t/00-config.t --- a/t/00-config.t Thu Jun 30 16:15:59 2011 +0200 +++ b/t/00-config.t Thu Jun 30 16:34:57 2011 +0200 @@ -10,12 +10,12 @@ use_ok "DNStools::Config" => qw(get_config); } -can_ok("DNStools::Config" => "get_config"); +can_ok( "DNStools::Config" => "get_config" ); -eval { get_config("xxx|xxx", "yyy|yyy") }; -ok($@, "dies on missing config"); +eval { get_config( "xxx|xxx", "yyy|yyy" ) }; +ok( $@, "dies on missing config" ); -my ($tmp, %cf); +my ( $tmp, %cf ); # prepare some simple sample config my $c = <filename); -ok(%cf, "got config"); -is($cf{abc} => "xyz", "simple value"); -is($cf{other} => "valuewithspace", "spaced value"); +%cf = get_config( "xxx|xxx", $tmp->filename ); +ok( %cf, "got config" ); +is( $cf{abc} => "xyz", "simple value" ); +is( $cf{other} => "valuewithspace", "spaced value" ); # it should find the file specified in $ENV{DNSTOOLS_CONF} $ENV{DNSTOOLS_CONF} = $tmp->filename; -%cf = (); -%cf = get_config(); -ok(%cf, "got config from \$DNSTOOLS_CONF"); -is($cf{abc} => "xyz", "simple value"); -is($cf{other} => "valuewithspace", "spaced value"); +%cf = (); +%cf = get_config(); +ok( %cf, "got config from \$DNSTOOLS_CONF" ); +is( $cf{abc} => "xyz", "simple value" ); +is( $cf{other} => "valuewithspace", "spaced value" ); diff -r 44183c6b78b6 -r 1ed33114d87f t/00-perl-c.t --- a/t/00-perl-c.t Thu Jun 30 16:15:59 2011 +0200 +++ b/t/00-perl-c.t Thu Jun 30 16:34:57 2011 +0200 @@ -6,10 +6,13 @@ use File::Find; plan skip_all => "no blib directories in \@INC" - if not /blib/ ~~ @INC; + if not /blib/ ~~ @INC; -find(sub{ - -f -x or return; - system("perl -Mblib -c $_ &>/dev/null"); - is($? => 0, "syntax $File::Find::name"); -}, "blib/"); +find( + sub { + -f -x or return; + system("perl -Mblib -c $_ &>/dev/null"); + is( $? => 0, "syntax $File::Find::name" ); + }, + "blib/" +); diff -r 44183c6b78b6 -r 1ed33114d87f t/01-zone-mk.t --- a/t/01-zone-mk.t Thu Jun 30 16:15:59 2011 +0200 +++ b/t/01-zone-mk.t Thu Jun 30 16:34:57 2011 +0200 @@ -14,30 +14,30 @@ my $CMD = "perl -Mblib blib/sbin/zone-mk"; system("$CMD -h >/dev/null 2>&1"); -is($? => 0, "exit on help"); +is( $? => 0, "exit on help" ); system("$CMD -m >/dev/null 2>&1"); -is($? => 0, "exit on man"); +is( $? => 0, "exit on man" ); system("$CMD >/dev/null 2>&1"); -ok($? > 0, "error on missing args"); +ok( $? > 0, "error on missing args" ); - -$_ = File::Temp::tempdir CLEANUP => 1 or die "Can't make temporary directory" for my ($master_dir, $config_dir); +$_ = File::Temp::tempdir CLEANUP => 1 + or die "Can't make temporary directory" + for my ( $master_dir, $config_dir ); my $tmp = Aux::make_config { - master_dir => $master_dir, + master_dir => $master_dir, zone_conf_dir => $config_dir, - hostmaster => 'hostmaster@schlittermann.de', - template_dir => './templates' + hostmaster => 'hostmaster@schlittermann.de', + template_dir => './templates' }; $ENV{DNSTOOLS_CONF} = $tmp->filename; system("$CMD xxx müller.de >/dev/null 2>&1"); -is($? => 0, "created zone"); +is( $? => 0, "created zone" ); -my $domain = idn_to_ascii("müller.de", "UTF-8"); -ok(-s "$master_dir/$domain/$domain", "zone file $domain"); -ok(-s "$config_dir/$domain", "config file $domain"); - +my $domain = idn_to_ascii( "müller.de", "UTF-8" ); +ok( -s "$master_dir/$domain/$domain", "zone file $domain" ); +ok( -s "$config_dir/$domain", "config file $domain" ); # older versions of Test::More (debian lenny fex) don't know done_testing -if (defined &done_testing) { &done_testing; } +if ( defined &done_testing ) { &done_testing; } diff -r 44183c6b78b6 -r 1ed33114d87f t/lib/Aux.pm --- a/t/lib/Aux.pm Thu Jun 30 16:15:59 2011 +0200 +++ b/t/lib/Aux.pm Thu Jun 30 16:34:57 2011 +0200 @@ -6,21 +6,25 @@ use File::Temp; use base "Exporter"; -our $VERSION = 0.0; +our $VERSION = 0.0; our @EXPORT_OK = qw(make_config); -sub make_config { +sub make_config($) { my ($c) = @_; my $f = File::Temp->new or die "Config file creation failed\n"; - if (ref $c eq 'HASH') { + if ( ref $c eq 'HASH' ) { map { print $f "$_ = $c->{$_}\n" } keys %{$c}; - } elsif (defined $c) { + } + elsif ( defined $c ) { + # assuming just a string print $f $c; - } else { + } + else { + # make a default configuration $_ = File::Temp::tempdir CLEANUP => 1 or die "Can't make temporary directory" for my ($bd, $md, $cd);