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

  1. #
  2. # miscellaneous perl functions that don't belong anywhere else
  3. #
  4.  
  5. #
  6. # Symbolic offsets for SATAN record fields.
  7. #
  8.  
  9. $TARGET_FIELD = 0;
  10. $SERVICE_FIELD = 1;
  11. $STATUS_FIELD = 2;
  12. $SEVERITY_FIELD = 3;
  13. $TRUSTEE_FIELD = 4;
  14. $TRUSTED_FIELD = 5;
  15. $SERVICE_OUTPUT_FIELD = 6;
  16. $TEXT_FIELD = 7;
  17. $SATAN_FIELDS = 8;
  18.  
  19. # strip leading directory and optional suffix information.
  20. sub basename {
  21.     local($path, $suffix) = @_;
  22.  
  23.     $path =~ s:.*/::;
  24.     if ($suffix) {
  25.     $path =~ s/$suffix$//;
  26.     }
  27.     return $path;
  28. }
  29.  
  30. # print to string 
  31.  
  32. sub satan_string{
  33.  
  34.     return "$target|$service|$status|$severity|$trustee|$trusted|$service_output|$text";
  35. }
  36.  
  37. # print the output for the brain/optimizer
  38. sub satan_print {
  39.  
  40.     print "$target|$service|$status|$severity|$trustee|$trusted|$service_output|$text\n";
  41.  
  42. }
  43.  
  44. # format the output for the brain/optimizer
  45. sub satan_text {
  46.  
  47.     return "$target|$service|$status|$severity|$trustee|$trusted|$service_output|$text";
  48.  
  49. }
  50.  
  51. # breakup record into its constituent fields
  52. sub satan_split {
  53.     local ($line) = @_;
  54.  
  55.     return ((($target,$service,$status,$severity,$trustee,$trusted,$service_output,$text) = split(/\|/, $line)) != $SATAN_FIELDS);
  56. }
  57.  
  58. # count the number of elements in an associative array.
  59. sub sizeof {
  60.     local(*which) = @_;
  61.     local(@keywords);
  62.  
  63.     @keywords = keys %which;
  64.     return($#keywords + 1);
  65. }
  66.  
  67. #
  68. # ensure that all paths in paths.pl file actually exist and are executable
  69. sub check_paths {
  70. local($caps, $command, $path, $null);
  71.  
  72. die "Can't open paths.pl\n" unless open(PATHS, "paths.pl");
  73.  
  74. while (<PATHS>) {
  75.     ($caps, $command) = split(/=/, $_);
  76.     ($null, $path, $null) = split(/\"/, $command);
  77.     die "$path is *not* executable - necessary for SATAN to run\n"
  78.         unless -x $path;
  79.     }
  80.  
  81. close(PATHS);
  82. }
  83.  
  84. 1;
  85.