]> eyrie.org Git - kerberos/krb5-strength.git/blobdiff - tools/krb5-strength-wordlist
Add dependabot configuration
[kerberos/krb5-strength.git] / tools / krb5-strength-wordlist
index f8e2a83327dbca4e99911c4ddde9b0e6f81e8a96..e9886e4986c6035e467427eee9a0ba2647070aaa 100755 (executable)
@@ -12,7 +12,8 @@
 # Declarations and configuration
 ##############################################################################
 
-require 5.006;
+require 5.010;
+use autodie;
 use strict;
 use warnings;
 
@@ -42,16 +43,16 @@ my $SQLITE_INSERT = q{
 # Utility functions
 ##############################################################################
 
-# print with error checking and an explicit file handle.
+# say with error checking and an explicit file handle.
 #
 # $fh   - Output file handle
 # @args - Remaining arguments to print
 #
 # Returns: undef
 #  Throws: Text exception on output failure
-sub print_fh {
+sub say_fh {
     my ($fh, @args) = @_;
-    print {$fh} @args or croak('print failed');
+    say {$fh} @args or croak("say failed: $!");
     return;
 }
 
@@ -72,17 +73,16 @@ sub write_cdb {
     my ($in_fh, $output, $filter) = @_;
 
     # Check that the output CDB file doesn't exist.
-    if (-f $output) {
+    if (-e $output) {
         die "$0: output file $output already exists\n";
     }
 
     # Create a temporary file to write the CDB input into.
     my $tmp = $output . '.data';
-    if (-f $tmp) {
+    if (-e $tmp) {
         die "$0: temporary output file $tmp already exists\n";
     }
-    open(my $tmp_fh, '>', $tmp)
-      or die "$0: cannot create output file $tmp: $!\n";
+    open(my $tmp_fh, '>', $tmp);
 
     # Walk through the input word list and write each word that passes the
     # filter to the output file handle as CDB data.
@@ -90,19 +90,19 @@ sub write_cdb {
         chomp($word);
         next if !$filter->($word);
         my $length = length($word);
-        print_fh($tmp_fh, "+$length,1:$word->1\n");
+        say_fh($tmp_fh, "+$length,1:$word->1");
     }
 
     # Add a trailing newline, required by the CDB data format, and close.
-    print_fh($tmp_fh, "\n");
-    close($tmp_fh) or die "$0: cannot write to temporary file $tmp: $!\n";
+    say_fh($tmp_fh, q{});
+    close($tmp_fh);
 
     # Run cdb to turn the result into a CDB database.  Ignore duplicate keys.
     system($CDB, '-c', '-u', $output, $tmp) == 0
       or die "$0: cdb -c failed\n";
 
     # Remove the temporary file and return.
-    unlink($tmp) or die "$0: cannot remove temporary file $tmp: $!\n";
+    unlink($tmp);
     return;
 }
 
@@ -122,7 +122,7 @@ sub write_sqlite {
     my ($in_fh, $output, $filter) = @_;
 
     # Check that the output SQLite file doesn't exist.
-    if (-f $output) {
+    if (-e $output) {
         die "$0: output file $output already exists\n";
     }
 
@@ -169,19 +169,18 @@ sub write_sqlite {
 #  Throws: Text exception on output failure
 sub write_wordlist {
     my ($in_fh, $output, $filter) = @_;
-    open(my $out_fh, '>', $output)
-      or die "$0: cannot create output file $output: $!\n";
+    open(my $out_fh, '>', $output);
 
     # Walk through the input word list and write each word that passes the
     # filter to the output file handle.
     while (defined(my $word = <$in_fh>)) {
         chomp($word);
         next if !$filter->($word);
-        print_fh($out_fh, "$word\n");
+        say_fh($out_fh, $word);
     }
 
     # All done.
-    close($out_fh) or die "$0: cannot write to output file $output: $!\n";
+    close($out_fh);
     return;
 }
 
@@ -206,8 +205,8 @@ sub build_filter {
     # Build a filter from our command-line parameters.  This is an anonymous
     # sub that returns true to keep a word and false otherwise.
     my $filter = sub {
-        my ($word)     = @_;
-        my $length     = length($word);
+        my ($word) = @_;
+        my $length = length($word);
         my $min_length = $config_ref->{'min-length'};
         my $max_length = $config_ref->{'max-length'};
 
@@ -248,13 +247,13 @@ local $0 = basename($0);
 # Parse the argument list.
 my %config;
 my @options = (
-    'ascii|a',      'cdb|c=s',    'max-length|L=i', 'min-length|l=i',
-    'manual|man|m', 'output|o=s', 'sqlite|s=s',     'exclude|x=s@',
+    'ascii|a', 'cdb|c=s', 'max-length|L=i', 'min-length|l=i',
+    'manual|man|m', 'output|o=s', 'sqlite|s=s', 'exclude|x=s@',
 );
 Getopt::Long::config('bundling', 'no_ignore_case');
 GetOptions(\%config, @options);
 if ($config{manual}) {
-    print_fh(\*STDOUT, "Feeding myself to perldoc, please wait...\n");
+    say_fh(\*STDOUT, 'Feeding myself to perldoc, please wait...');
     exec('perldoc', '-t', $fullpath);
 }
 if (@ARGV != 1) {
@@ -271,8 +270,7 @@ my $input = $ARGV[0];
 my $filter = build_filter(\%config);
 
 # Process the input file into either wordlist output or a CDB file.
-open(my $in_fh, '<', $input)
-  or die "$0: cannot open input file $input: $!\n";
+open(my $in_fh, '<', $input);
 if ($config{output}) {
     write_wordlist($in_fh, $config{output}, $filter);
 } elsif ($config{cdb}) {
@@ -280,7 +278,7 @@ if ($config{output}) {
 } elsif ($config{sqlite}) {
     write_sqlite($in_fh, $config{sqlite}, $filter);
 }
-close($in_fh) or die "$0: cannot read all of input file $input: $!\n";
+close($in_fh);
 
 # All done.
 exit(0);
@@ -428,7 +426,7 @@ Russ Allbery <eagle@eyrie.org>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2016, 2020 Russ Allbery <eagle@eyrie.org>
+Copyright 2016, 2020, 2023 Russ Allbery <eagle@eyrie.org>
 
 Copyright 2013-2014 The Board of Trustees of the Leland Stanford Junior
 University