System Integrity Tripwire to check a file or directory (optional whitespace, string beginning with /), then we should check that the file or directory exists. If not, we should comment out the line to prevent Tripwire from generating an error. Similarly, if we find a line in the policy file that looks like a commented out file (optional whitespace, #, optional whitespace, string beginning with /), then we should check if the file or directory exists. If it does, then we’ll remove the comment to reinstate the file. 6. We’ll write the script as a filter, so it reads configuration lines from STDIN and writes to STDOUT. Any lines that don’t look like either of the types of line we’re interested in are passed through unmodified. It would be nice to know how much work we’ve saved ourselves by counting up the number of lines that the script modifies. Here’s the script (hopefully your new knowledge of Perl will give you an idea of the structure that we’ve employed, even if the details are still a bit beyond you - they’ll come with practice): #! /usr/bin/perl -w # Filter for Tripwire policy file. Looks for lines that # start with optional whitespace and a filename, and # comments them out if the file does not exist. Also # looks for commented out lines containing filename and # removes comment if they do exist. $Additions = 0; $Removals = 0; # Read each line from stdin into the $line variable while ($line = ) { # Look for lines that match a pattern (the Perl # pattern matching characters are enclosed in []) # start with optional white space [ ^s* ] # then a ‘#’ [ # ] # then more optional white space [ s* ] # then a string starting with ‘/’ that doesn’t # contain white space [ /S+ ] # # The last part of the pattern is enclosed in () # so that if the pattern matches, we can access # this part through the $1 variable. # # This pattern matches a commented out entry/ if ( $line =~ /^s*#s*(/S+)/ ) { # Found commented out entry. If the file exists, # strip off the comment character. if ( -e $1 ) { $line =~ s/^s*#//; $Additions++; } # Now look for a line that’s like the above but # without the ‘#’ comment character. } elsif ( $line =~ /^s*(/S+)/ ) { # Found entry that starts with ” /”. If file # does not exist, then comment out entry. if ( ! -e $1 ) { $line = “# ” . $line; $Removals++; } } # Output the line (whether modified or not) 411
Note: If you are looking for reliable and quality webspace company to host and run your servlet application check professional servlet hosting services