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
|
#!/usr/bin/perl
#
# Copyright 2007-2012 SPARTA, Inc. All rights reserved. See the COPYING
# file distributed with this software for details.
#
#
# dtconf
#
# This script displays the contents of a DNSSEC-Tools configuration file.
#
use strict;
use Getopt::Long qw(:config no_ignore_case_always);
use Net::DNS::SEC::Tools::conf;
use Net::DNS::SEC::Tools::defaults;
#
# Version information.
#
my $NAME = "dtconf";
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 =
(
"key=s", # Just give this key's value.
"Version", # Display the version number.
"help", # Give a usage message and exit.
);
my $key; # Key to display.
my %dtconf; # Config file contents.
#######################################################################
main();
exit(0);
#-----------------------------------------------------------------------------
# Routine: main()
#
# Purpose: Staging area.
#
sub main()
{
my $conffile; # The config file to check.
#
# Get our options.
#
doopts();
#
# Get the config filename to check.
#
$conffile = getfile();
#
# Read the config file.
#
%dtconf = parseconfig($conffile);
if(%dtconf == 0)
{
err("config file \"$conffile\" not parsed\n");
exit(-1);
}
confout();
}
#-----------------------------------------------------------------------------
# Routine: doopts()
#
# Purpose: This routine deals with the command's options.
#
sub doopts
{
#
# Check our options.
#
GetOptions(\%options,@opts) || usage();
$key = $options{'key'};
#
# Show the version number if requested
#
version() if(defined($options{'Version'}));
usage() if(defined($options{'help'}));
}
#-----------------------------------------------------------------------------
# Routine: getfile()
#
# Purpose: This routine gets the configuration file to display.
# If a file wasn't specified on the command line, we'll
# use the default DNSSEC-Tools config file.
#
sub getfile
{
my $conffile; # Configuration filename.
#
# Get the name to use.
#
if($ARGV[0] ne "")
{
$conffile = $ARGV[0];
}
else
{
$conffile = getconffile();
}
#
# Ensure the file exists.
#
if(! -e $conffile)
{
print STDERR "$conffile does not exist\n";
exit(1);
}
#
# Ensure the file is a file.
#
if(! -f $conffile)
{
print STDERR "$conffile is not a regular file\n";
exit(1);
}
#
# Return the file name to the caller.
#
return($conffile);
}
#-----------------------------------------------------------------------------
# Routine: confout()
#
# Purpose: This routine displays the contents of the file.
#
sub confout
{
if($key)
{
if(defined($dtconf{$key}))
{
print "$key $dtconf{$key}\n";
}
else
{
print "$key (undefined)\n";
}
}
else
{
my $maxlen = 0; # Maximum key length.
#
# Calculate the start of the second column.
#
foreach my $k (sort(keys(%dtconf)))
{
$maxlen = length($k) if(length($k) > $maxlen);
}
$maxlen += 8;
foreach my $k (sort(keys(%dtconf)))
{
my $len; # Length of key.
my $spaces; # Number of spaces.
$len = length($k);
$spaces = $maxlen - $len;
print "$k" . (' ' x $spaces) . "$dtconf{$k}\n";
}
}
}
#----------------------------------------------------------------------
# Routine: version()
#
# Purpose: Print the version number(s) and exit.
#
sub version
{
print STDERR "$VERS\n";
print STDERR "$DTVERS\n";
exit(0);
}
#-----------------------------------------------------------------------------
# Routine: usage()
#
sub usage
{
print STDERR "usage: conf [options] <config file>\n";
print STDERR "\toptions:\n";
print STDERR "\t\t-key <key>\n";
print STDERR "\t\t-Version\n";
print STDERR "\t\t-help\n";
exit(0);
}
1;
###############################################################################
=pod
=head1 NAME
dtconf - Display the contents of a DNSSEC-Tools configuration file
=head1 SYNOPSIS
dtconf [options] [config_file]
=head1 DESCRIPTION
B<dtconf> displays the key/value pairs of a DNSSEC-Tools configuration file.
If a configuration file isn't specified, the system configuration file will
be displayed.
Without the B<-key> option, B<dtconf> displays all the key/value pairs in the
configuration file. Comments are never displayed. If the B<-key> option is
given, then only that key/value pair is displayed. If the key isn't defined,
then the value will be "(undefined)."
=head1 OPTIONS
=over 4
=item B<-key>
The value of the specified key will be printed. If the key is not defined,
then the value will be given as "(undefined)".
=item B<-Version>
Displays the version information for B<dtconf> and the DNSSEC-Tools package.
=item B<-help>
Display a usage message.
=back
=head1 COPYRIGHT
Copyright 2007-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<dtinitconf(8)>,
B<dtconfchk(8)>
B<Net::DNS::SEC::Tools::conf.pm(3)>
B<dnssec-tools.conf(5)>
=cut
|