strict/warn

This commit is contained in:
Joe Cooper
2016-06-03 00:36:15 -07:00
parent adfd154341
commit fb4595b38d

View File

@@ -1,28 +1,34 @@
#!/usr/local/bin/perl
# Actually setup rndc
use strict;
use warnings;
our (%access, %text, %config);
require './bind8-lib.pl';
$access{'defaults'} || &error($text{'rndc_ecannot'});
&error_setup($text{'rndc_err'});
$cfile = &make_chroot($config{'named_conf'});
my $cfile = &make_chroot($config{'named_conf'});
# Generate the RNDC config
my ($out, $err);
&execute_command($config{'rndcconf_cmd'}, undef, \$out, \$err);
if ($?) {
&error("<pre>$err</pre>");
}
&open_lock_tempfile(CONF, ">$config{'rndc_conf'}");
&print_tempfile(CONF, $out);
&close_tempfile(CONF);
my $CONF;
&open_lock_tempfile($CONF, ">$config{'rndc_conf'}");
&print_tempfile($CONF, $out);
&close_tempfile($CONF);
&set_ownership_permissions(0, 0, 0600, $config{'rndc_conf'});
$rconf = [ &read_config_file($config{'rndc_conf'}) ];
my $rconf = [ &read_config_file($config{'rndc_conf'}) ];
# Get the new key
$rkey = &find("key", $rconf);
my $rkey = &find("key", $rconf);
$rkey || &error($text{'rndc_ekey'});
$secret = &find_value("secret", $rkey->{'members'});
my $secret = &find_value("secret", $rkey->{'members'});
$secret || &error($text{'rndc_esecret'});
$options = &find("options", $rconf);
my $options = &find("options", $rconf);
my $port;
if ($options) {
$port = &find_value("default-port", $options->{'members'});
}
@@ -30,10 +36,10 @@ $port ||= 953;
# Add the key to named.conf
&lock_file($cfile);
$parent = &get_config_parent();
$conf = &get_config();
@keys = &find("key", $conf);
($key) = grep { $_->{'values'}->[0] eq "rndc-key" } @keys;
my $parent = &get_config_parent();
my $conf = &get_config();
my @keys = &find("key", $conf);
my ($key) = grep { $_->{'values'}->[0] eq "rndc-key" } @keys;
if (!$key) {
# Need to create key
$key = { 'name' => 'key',
@@ -49,13 +55,13 @@ if (!$key) {
&save_directive($parent, 'key', \@keys, 0);
# Make sure there is a control for the inet port
$controls = &find("controls", $conf);
my $controls = &find("controls", $conf);
if (!$controls) {
# Need to add controls section
$controls = { 'name' => 'controls', 'type' => 1 };
&save_directive($parent, 'controls', [ $controls ]);
}
$inet = &find("inet", $controls->{'members'});
my $inet = &find("inet", $controls->{'members'});
if (!$inet) {
# Need to add inet entry
$inet = { 'name' => 'inet',
@@ -70,7 +76,7 @@ if (!$inet) {
}
else {
# Just make sure it is valid
%keys = map { $_->{'name'}, 1 } @{$inet->{'members'}->{'keys'}};
my %keys = map { $_->{'name'}, 1 } @{$inet->{'members'}->{'keys'}};
if (!$keys{'rndc-key'}) {
push(@{$inet->{'members'}->{'keys'}},
{ 'name' => "rndc-key" });
@@ -81,7 +87,7 @@ else {
&flush_file_lines();
# MacOS specific fix - remove include for /etc/rndc.key , which we don't need
$lref = &read_file_lines($cfile);
my $lref = &read_file_lines($cfile);
for(my $i=0; $i<@$lref; $i++) {
if ($lref->[$i] =~ /^include\s+"\/etc\/rndc.key"/i) {
splice(@$lref, $i, 1);