/usr/bin/proclint is in procmail-lib 1:2009.1202-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | #!/usr/bin/perl
#
# proclint [-[no]list] [-[no]includerc] [-procmailrc] rcfiles ...
#
# Copyright
#
# Copyright (C) 2006-2010 Jari Aalto <jari.aalto@cante.net>
# Copyright (C) 1995-2010 Alan Stebbens <aks@sgi.com>
#
# License
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details at
# Visit <http://www.gnu.org/copyleft/gpl.html>.
#
# Description by Alan Stebbens
#
# By default, -noincluderc and -nolist are set.
#
# Because debugging procmailrc scripts is difficult
# I try to encode checks into this script.
#
# If -list given, list all lines of the recipe, numbered, and
# with levels and a type flag character.
#
# Current errors caught:
#
# '{' and '}' nesting errors.
# Missing '*' on conditions
# Lines which aren't recipes or assignments
# Unterminated recipes
my($DIR,$PROG) = $0 =~ m,^(.*/)?([^/]+)$,;
$DIR =~ s,/$,, || chomp($DIR = qx(pwd));
my $FH_TEMPLATE = 'fh00';
my $ERROR = 0;
$| = 1;
sub Usage (;$)
{
my $code = shift || 0;
print <<"EOF"; exit $code;
usage: $PROG [options] <rcfiles ...>
Check procmail rc files for proper syntax, recipe nesting, etc.
Options (default are marked with '*'):
-h, --help This message
-i, --includerc Scan and possibly list files included with INCLUDERC
-I, --noinclude* Do not scan INCLUDERC references
-l, --list List lines in the procmail recipe files.
-L, --nolist* Do not list lines, except for errors.
-p, --procmailrc Check \$HOME/.procmailrc
The output consists of: 'LINE-NUMBER:FLAG:DEPTH: text'.
FLAG is one of:
'R' recipe
'C' condition
'A' action (redirect, '!', or pipe, '|')
'F' folder
'=' assignment
'+' continuation
'E' *line may be erroneous*
DEPTH indicates the depth of the recipe nesting and is shown only
when greater than zero.
EOF
}
sub Untab ($)
{
local $_ = shift;
while (($x = index($_,"\t")) >= $[)
{
substr($_,$x,1) = " " x (((($x / 8) + 1) * 8) - $x)
}
$_;
}
sub Eval
{
my $val = shift;
while( ( $val =~ /\$(\w+)/ ) )
{
if( defined( $Assigns{$1} ) )
{
$val = $` . $Assigns{$1} . $';
}
elsif( defined( $ENV{$1} ) )
{
$val = $` . $ENV{$1} . $';
}
else
{
$val = $` . $'; # omit the variable -- it's empty
}
}
$val;
}
sub Scan ($; $$);
sub Scan ($; $$)
{
my $file = shift;
my $fileLevel = shift || 0;
my $mainLevel = shift || 0;
return if $Scanned{$file};
$Scanned{$file}++;
my($type, $count, $conditions, $var, $val);
my($includefile, $depth);
my($level) = $mainLevel;
local $_;
unless ($quiet)
{
print "\n" if $listlines;
print (" " x $fileLevel);
print "Scanning file $file:";
}
local($FH) = $FH_TEMPLATE++;
open( $FH , $file ) or do
{
print "Can't open $file: $!\n";
$ERROR = 1;
return;
};
print "\n" unless $quiet;
my $recipe = '';
my $errs = '';
my $continuation = '';
my $line = '';
while( <$FH> )
{
chomp;
$_ = Untab $_ if /\t/;
if( $continuation )
{
$line .= "\n".$_;
$_ = $line;
$line = '';
$continuation = '';
}
if( /\\$/ )
{ # continuation?
$continuation = 1;
chop; # remove the trailing slash
$line = $_; # make the continuation
next;
}
$type = ' ';
if( /^\s*\#/ or /^\s*$/ )
{ # ignore comments or blank lines
$type = ' ';
$_ = ' ' unless length;
}
elsif( ! $recipe or /^\s*:/) # are we looking for a recipe?
{
# This is a state driven scanner
# State Parse Next What
# 0 : 1 Start recipe parse
# 1 * 1 Parse condition
# 1 ! 0 Parse redirect
# 1 | 0 Parse pipe
# 1 { 0 Increment recipe level, parse sub-recipe
# 1 <other> 0 Parse filename path
if( /^\s*:\s*(\S.*)?/ ) # recipe start?
{
$flags = $1; # get flags
$count = $flags =~ /^(\d+)/ ? $1 :
$flags =~ /[eEaA]/ ? 0 : 1;
$recipe = $.; # we're in a recipe
$conditions = 0;
$type = 'R'; # set the type
} elsif( /^\s*}/ ) # end of a nested recipe?
{
$level--;
$type = 'R';
if ($level < 0)
{
$errs .= "Too many close brackets!\n";
$level = 0;
}
}
elsif( /^\s*(\w+)\s*=\s*(\S.*)?/ ) # an assignment?
{
$type = '='; # assignment
($var,$val) = ($1,$2);
if( $includerc )
{
$Assigns{$var} = $val;
if( $var eq 'INCLUDERC' )
{
$newfile = Eval $val;
if( $newfile && -f $newfile )
{
$includefile = $newfile;
}
elsif ( $newfile )
{
$errs .= "Included file \"$newfile\" does not exist.\n";
}
}
}
}
elsif( /^\s*(\w+)\s*$/ ) # an un-assignment?
{
$type = '='; # unassignment
}
else
{
$errs .= "Bad recipe line: \"$_\"\n";
$type = 'E';
}
}
else
{
if( /^\s*\*/ ) # a condition?
{
$conditions++;
$type = 'C'; # condition
$count--;
}
elsif ( /^\s*!/ && $count <= 0) # a redirection?
{
$recipe = ''; # an action, we're out of the recipe
$type = 'A'; # Action
}
elsif ( /^\s*\|/ ) # a pipe?
{
$recipe = ''; # another action
$type = 'A'; # Action
}
elsif ( /^\s*{/ ) # a subrecipe
{
$level++; # increment the level
$recipe = ''; # and we're out of the recipe
$type = 'A'; # Action
$level-- if /\s+}/; # decrement count if one-liner
}
elsif ( --$count >= 0 && !/^\s*[\|{]/) # more conditions?
{
$conditions++;
$type = 'C'; # assume condition
}
else # default is path
{
$type = 'F'; # folder
# make reasonable mistake guess
if ( /^\s*[\#*(){}|!?]|^\s*\w+ \w+/ )
{
$errs .= "Possibly bad folder name?\n";
}
$recipe = '';
}
}
Print:
if ( $listlines or $errs )
{
@lines = split /\n/;
$depth = $level > 0 ? sprintf("<%d>",$level) : " ";
while ($_ = shift(@lines))
{
print (" " x $fileLevel);
$_ .= "\\" if @lines;
printf "%3d:%1s%s %s\n",$.,$type,$depth,$_;
$type = '+';
}
}
if( $errs )
{
print $errs;
$ERROR = 1;
$errs = '';
}
if ($includefile)
{
Scan( $includefile, $fileLevel + 1, $level );
unless ($quiet)
{
print "\n" if $listlines;
print (" " x $fileLevel);
print "Back to file $file:\n";
}
$includefile = '';
}
}
if ($recipe)
{
print "$file: EOF: recipe at line $recipe never terminated.\n";
$ERROR = 1;
}
if ($level > $mainLevel)
{
print "$file: EOF: Unterminated nested recipies.\n";
$ERROR = 1;
}
close $FH;
}
sub Main ()
{
unless ($#ARGV >= $[)
{
Usage 1;
}
while( $_ = shift @ARGV )
{
if ( /^(-h|--help)/ )
{
Usage;
}
elsif ( /^(-l|--list)/ )
{
$listlines++;
}
elsif ( /^(-L|--nolist)/ )
{
$listlines = '';
}
elsif ( /^(-i|--includerc)/ )
{
$includerc++;
}
elsif ( /^(-I|--noincluderc)/ )
{
$includerc = '';
}
elsif ( /^(-p|--procmailrc)/ )
{
$HOME = $ENV{'HOME'} || (getpwuid($>))[7];
push(@ARGV,"$HOME/.procmailrc");
}
elsif ( /^-/ )
{
print "Unknown option: '$_'\n";
next;
}
else
{
Scan $_;
}
}
return $ERROR;
}
Main();
# End of file
|