summaryrefslogtreecommitdiff
path: root/contrib/wallet-unknown-hosts
diff options
context:
space:
mode:
authorRuss Allbery <eagle@eyrie.org>2014-07-11 22:36:11 -0700
committerRuss Allbery <rra@stanford.edu>2014-07-11 22:39:23 -0700
commit1329e6db944a6fce5578b249de08a8250a920877 (patch)
tree2dd24e191af3767a93a21db9cd6b183164dbe491 /contrib/wallet-unknown-hosts
parentbf513da9cc1bc6f125aded53685cf71083c5ae56 (diff)
Test for Perl strict and minimum version
Fix strictness issues across the whole code base, and ensure that all Perl scripts enable warnings. (Hopefully enabling warnings won't cause problems for the server.) Change-Id: I4dee49f7a6bcbeeee21d74bf61a1fd26514f832c Reviewed-on: https://gerrit.stanford.edu/1532 Reviewed-by: Russ Allbery <rra@stanford.edu> Tested-by: Russ Allbery <rra@stanford.edu>
Diffstat (limited to 'contrib/wallet-unknown-hosts')
-rwxr-xr-xcontrib/wallet-unknown-hosts36
1 files changed, 21 insertions, 15 deletions
diff --git a/contrib/wallet-unknown-hosts b/contrib/wallet-unknown-hosts
index 339983d..50b5a04 100755
--- a/contrib/wallet-unknown-hosts
+++ b/contrib/wallet-unknown-hosts
@@ -1,8 +1,21 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl
#
# Report host keytabs in wallet for unknown hosts.
##############################################################################
+# Modules and declarations
+##############################################################################
+
+require 5.006;
+
+use strict;
+use warnings;
+
+use DB_File ();
+use Wallet::Report ();
+use Wallet::Server ();
+
+##############################################################################
# Site configuration
##############################################################################
@@ -22,9 +35,10 @@ our $MIN = 3;
our $THRESHOLD = time - 30 * 24 * 60 * 60;
# Set up a Net::DNS resolver that will be used by local_check_keytab.
+my $DNS;
BEGIN {
use Net::DNS;
- our $DNS = Net::DNS::Resolver->new;
+ $DNS = Net::DNS::Resolver->new;
}
# Pre-filter. This is called for all host-based keytabs and is the place to
@@ -55,18 +69,6 @@ sub local_check_keytab {
}
##############################################################################
-# Modules and declarations
-##############################################################################
-
-require 5.006;
-
-use strict;
-
-use DB_File ();
-use Wallet::Report ();
-use Wallet::Server ();
-
-##############################################################################
# Utility functions
##############################################################################
@@ -97,6 +99,7 @@ sub check_host {
# Do a scan of all host-based keytabs in wallet and record those that are not
# found in DNS or which should not be used according to site configuration.
sub check {
+ my %history;
tie %history, 'DB_File', $HISTORY;
my @keytabs = list_keytabs;
for my $keytab (@keytabs) {
@@ -124,6 +127,7 @@ sub check {
# list (given as a threshold time in seconds since epoch).
sub report {
my ($min, $threshold) = @_;
+ my %history;
tie %history, 'DB_File', $HISTORY;
for my $keytab (sort keys %history) {
my ($count, $time) = split (',', $history{$keytab});
@@ -142,6 +146,7 @@ sub report {
sub purge {
my ($user, $min, $threshold) = @_;
my $wallet = Wallet::Server->new ($user, 'localhost');
+ my %history;
tie %history, 'DB_File', $HISTORY;
for my $keytab (sort keys %history) {
my ($count, $time) = split (',', $history{$keytab});
@@ -161,7 +166,7 @@ sub purge {
my $command = shift or die "Usage: $0 (check | report | purge)\n";
if ($command eq 'check') {
- check;
+ check ();
} elsif ($command eq 'report') {
my ($min, $threshold) = @_;
$min = $MIN unless defined ($min);
@@ -170,6 +175,7 @@ if ($command eq 'check') {
report ($min, $threshold);
} elsif ($command eq 'purge') {
my $user = $ENV{REMOTE_USER} or die "$0: REMOTE_USER must be set\n";
+ my ($min, $threshold) = @_;
$min = $MIN unless defined ($min);
die "$0: minimum count must be at least 1\n" if $min < 1;
$threshold = $THRESHOLD unless defined ($threshold);