#! /usr/bin/perl
# Tripwire policy customization helper script.
# (w) Michael Schwendt <mschwendt@yahoo.com>
$policyfile = "/etc/tripwire/twpol.txt";

die if $#ARGV < 0;
$reportfile = "$ARGV[0]";
open (REPORT,"$reportfile") or die "open: $reportfile: $!";
$stat = 0;
while (<REPORT>)  {
    if ( !$stat && /^\#\#\# Warning: File system error\./) {
        ++$stat;
    }
    elsif ( $stat==1 && /^\#\#\# Filename: (.*)/ ) {
        ++$stat;
        $filename = $1;
    }
    elsif ( $stat==2 && /^\#\#\# No such file or directory/ ) {
        $stat = 0;
        system("perl -pi -e 's|^[ \t]*$filename|#     $filename|' $policyfile");
    }
    else {
        $stat = 0;
    }
}
exit 0;
