home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SATAN11.ZIP / PERL / INFER_TO.PL < prev    next >
Text File  |  1995-04-11  |  3KB  |  98 lines

  1. #
  2. # Usage: &infer_todo()
  3. # Applies rules in $infer_todo_files to the global $target..$text
  4. # variables (and to all other globals that are available) and
  5. # generates new probes for the data collection engine.
  6. # Standalone usage: perl infer_todo.pl [satan_record_files...]
  7. #
  8. # version 1, Tue Mar 21 20:25:31 1995, last mod by wietse
  9. #
  10.  
  11. $infer_todo_files = "rules/todo";
  12.  
  13. sub build_infer_todo{
  14.     local($files) = @_;
  15.     local($cond, $todo, $func, $host, $tool, $args, $args1, $args2);
  16.  
  17.     $code = "sub infer_todo {\n";
  18.     $code .= "    local(\$junk);\n";
  19.  
  20.     foreach $file (split(/\s+/, $files)) {
  21.     open(RULES, $file) || die "cannot open $file: $!";
  22.     while (<RULES>) {
  23.         chop;
  24.         while (/\\$/) {
  25.         chop;
  26.         $_ .= <RULES>;
  27.         chop;
  28.         }
  29.         s/#.*$//;
  30.         next if /^\s*$/;
  31.         s/@/\\@/g;
  32.         ($cond, $todo) = split(/\t+/, $_, 2);
  33.         ($host, $tool, $args) = split(/\s+/, $todo, 3);
  34.         $host ne "" || die "no host in $file: cond=$cond, todo=$todo\n";
  35.         $tool ne "" || die "no tool in $file: cond=$cond, todo=$todo\n";
  36.         if ($args =~ /\*\s*(.+)/) {
  37.         $func = "add_todo_ignore_args";
  38.         $args = $1;
  39.         } else {
  40.         $func = "add_todo";
  41.         }
  42.         $code .= "\tif ($cond) {\n\t\t&$func($host,$tool";
  43.         ($args ne "") && ($code .= ",$args");
  44.         $code .= ");\n\t}\n";
  45.     }
  46.     close(RULES);
  47.     }
  48.     $code .= "\n}\n";
  49.     return $code;
  50. }
  51.  
  52. #
  53. # Some scaffolding for stand-alone operation
  54. #
  55. if ($running_under_satan) {
  56.     eval &build_infer_todo($infer_todo_files);
  57.     die "error in $infer_todo_files: $@" if $@;
  58. } else {
  59.     $running_under_satan = -1;
  60.  
  61.     require 'perl/misc.pl';
  62.     require 'perl/fix_hostname.pl';
  63.  
  64.     warn "infer_todo.pl running in test mode";
  65.  
  66.     eval "sub add_todo { local(\$target,\$tool,\$args) = \@_;
  67.     print \"add_todo: \$target \$tool \$args\\n\"; }\n";
  68.  
  69.     eval "sub add_todo_ignore_args { local(\$target,\$tool,\$args) = \@_;
  70.     print \"add_todo_ignore_args: \$target \$tool \$args\\n\"; }\n";
  71.  
  72.     #
  73.     # Build satan rules and include them into the running code.
  74.     #
  75.     $code = &build_infer_todo($infer_todo_files);
  76.     print "Code generated from $infer_todo_files:\n\n";
  77.     print $code;
  78.     eval $code;
  79.     die "error in $infer_todo_files: $@" if $@;
  80.  
  81.     #
  82.     # Apply rules.
  83.     #
  84.     print "\nApplying rules to all SATAN records...\n";
  85.     while (<>) {
  86.     chop;
  87.     if (&satan_split($_)) {
  88.         warn "Ill-formed record: $_\n";
  89.     } else {
  90.         &infer_todo();
  91.     }
  92.     }
  93. }
  94.  
  95. 1;
  96.