1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
|
#!/usr/bin/perl
#
# Copyright 2010-2012 SPARTA, Inc. All rights reserved. See the COPYING
# file distributed with this software for details.
#
# DNSSEC-Tools: dtupdkrf
#
# This script updates an existing DNSSEC-Tools keyrec file to the
# format. The command is used in this way:
#
# dtupdkrf <krf-file>
#
use strict;
use Getopt::Long qw(:config no_ignore_case_always);
use Net::DNS::SEC::Tools::keyrec;
#
# Version information.
#
my $NAME = "dtupdkrf";
my $VERS = "$NAME version: 1.13.0";
my $DTVERS = "DNSSEC-Tools Version: 1.13";
########################################################################
#
# Data required for command line options.
#
my %options = (); # Filled option array.
my @opts =
(
"count", # Give a count of keyrecs in file.
"verbose", # Give verbose output.
"quiet", # Don't give much output.
"help", # Display help and exit.
"Version", # Display versions and exit.
);
my $count = 0; # Keyrec-count flag.
my $verbose = 0; # Verbose-output flag.
my $quiet = 0; # No-output flag.
#------------------------------------------------------------------------
my $ret; # Count of errors found.
$ret = main();
exit($ret);
#------------------------------------------------------------------------
# Routine: main()
#
# Purpose: Do Everything.
#
sub main
{
my $mod; # Module name.
my $errcnt = 0; # Error count.
#
# Check options.
#
opts();
foreach my $krf (@ARGV)
{
$errcnt += checkkrf($krf);
}
return($errcnt);
}
#------------------------------------------------------------------------
# Routine: opts()
#
# Purpose: Parse the command line and perform option verification.
#
sub opts
{
#
# Parse the options.
#
GetOptions(\%options,@opts) || usage();
#
# Handle a few immediate flags.
#
version() if(defined($options{'Version'}));
usage(1) if(defined($options{'help'}));
#
# Set our option variables based on the parsed options.
#
$count = $options{'count'};
$verbose = $options{'verbose'};
$quiet = $options{'quiet'};
#
# Ensure that exclusive options actually are.
#
if($verbose && $quiet)
{
print STDERR "-verbose and -quiet are mutually exclusive\n";
exit(0);
}
}
#------------------------------------------------------------------------
# Routine: checkkrf()
#
# Purpose:
#
sub checkkrf
{
my $krffile = shift; # Name of keyrec file to check.
my $cnt; # Number of keyrecs in file.
#
# Ensure that the file looks like it might be a keyrec file.
#
if(keyrec_filestat($krffile) != 0)
{
my @errs = (
"dummy message",
"no keyrec file given",
"$krffile: keyrec file does not exist",
"$krffile: keyrec file is not a regular file",
"$krffile: keyrec file is not readable",
"$krffile: keyrec file is empty"
);
$ret = keyrec_filestat($krffile);
print STDERR "$errs[$ret]\n";
exit(1);
}
#
# Read the contents of the keyrec file.
#
$cnt = keyrec_read($krffile);
if($cnt < 0)
{
print STDERR "$krffile: unable to read keyrec file\n";
exit(1);
}
vprint("$cnt keyrecs in $krffile\n") if($count);
#
# Check the keyrec format.
#
$cnt = keyrec_fmtchk($krffile);
if($cnt == 0)
{
vprint("$krffile is in current format\n");
}
else
{
qprint("$krffile is in old format; $cnt changes made\n");
}
#
# Close the keyrec file.
#
keyrec_close();
return($cnt);
}
#-----------------------------------------------------------------------------
# Routine: qprint()
#
# Purpose: Print a line of text iff the -quiet option wasn't given.
#
sub qprint
{
my $line = shift;
print $line if(!$quiet);
}
#-----------------------------------------------------------------------------
# Routine: vprint()
#
# Purpose: Print a line of text iff the -quiet option wasn't given and
# the -verbose option was.
#
sub vprint
{
my $line = shift;
qprint($line) if($verbose);
}
#----------------------------------------------------------------------
#
# Routine: version()
#
sub version
{
print STDERR "$VERS\n";
print STDERR "$DTVERS\n";
exit(0);
}
#------------------------------------------------------------------------
# Routine: usage()
#
sub usage
{
print "usage: dtupdkrf [options] <keyrec files>\n";
print "\tcount display count of keyrecs in keyrec file\n";
print "\tverbose give verbose output\n";
print "\tquiet check keyrec file without printing results\n";
print "\tVersion display version and exit\n";
print "\thelp display help and exit\n";
exit(0);
}
1;
##############################################################################
#
=pod
=head1 NAME
dtupdkrf - Ensures that a keyrec file is in the current format
=head1 SYNOPSIS
dtupdkrf [options] <keyrec files>
=head1 DESCRIPTION
B<dtupdkrf> ensures that a I<keyrec> file is in the current format. If the
I<keyrec> file has an old format, it is converted to the current format.
The format of I<keyrec> files does not change very often. Therefore,
B<dtupdkrf> should be run when installing new versions of the DNSSEC-Tools
software. It does not have to be run very often otherwise.
The number of error fixed in the given I<keyrec> files will be given as
B<dtupdkrf>'s exit code.
B<WARNING: dtupdkrf should NOT be run on keyrec files that are in active use
by other DNSSEC-Tools programs. You MUST stop rollerd, zonesigner, or any
other DNSSEC-Tools programs BEFORE running dtupdkrf on active files.>
=head1 OPTIONS
B<dtupdkrf> supports several types of options. These options are detailed
below.
=over 4
=item B<-count>
Display the count of I<keyrec>s in each I<keyrec> file.
=item B<-quiet>
Display no information.
B<-quiet> and B<-verbose> are mutually exclusive.
=item B<-verbose>
Display verbose information.
B<-verbose> and B<-quiet> are mutually exclusive.
=item B<-Version>
Display B<dtupdkrf>' version information and exit.
=item B<-help>
Display a usage message and exit.
=back
=head1 COPYRIGHT
Copyright 2010-2012 SPARTA, Inc. All rights reserved.
See the COPYING file included with the DNSSEC-Tools package for details.
=head1 AUTHOR
Wayne Morrison, tewok@tislabs.com
=head1 SEE ALSO
B<keyrec(5)>
=cut
|