diff --git a/contrib/twpolmake.pl b/contrib/twpolmake.pl new file mode 100755 index 0000000..d397d9c --- /dev/null +++ b/contrib/twpolmake.pl @@ -0,0 +1,56 @@ +#!/usr/bin/perl +# Tripwire Policy File customize tool +# ---------------------------------------------------------------- +# Copyright (C) 2003 Hiroaki Izumi +# 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. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# ---------------------------------------------------------------- +# Usage: +# perl twpolmake.pl {Pol file} +# ---------------------------------------------------------------- +# +$POLFILE=$ARGV[0]; + +open(POL,"$POLFILE") or die "open error: $POLFILE" ; +my($myhost,$thost) ; +my($sharp,$tpath,$cond) ; +my($INRULE) = 0 ; + +while () { + chomp; + if (($thost) = /^HOSTNAME\s*=\s*(.*)\s*;/) { + $myhost = `hostname` ; chomp($myhost) ; + if ($thost ne $myhost) { + $_="HOSTNAME=\"$myhost\";" ; + } + } + elsif ( /^{/ ) { + $INRULE=1 ; + } + elsif ( /^}/ ) { + $INRULE=0 ; + } + elsif ($INRULE == 1 and ($sharp,$tpath,$cond) = /^(\s*\#?\s*)(\/\S+)\b(\s+->\s+.+)$/) { + $ret = ($sharp =~ s/\#//g) ; + if ($tpath eq '/sbin/e2fsadm' ) { + $cond =~ s/;\s+(tune2fs.*)$/; \#$1/ ; + } + if (! -s $tpath) { + $_ = "$sharp#$tpath$cond" if ($ret == 0) ; + } + else { + $_ = "$sharp$tpath$cond" ; + } + } + print "$_\n" ; +} +close(POL) ;