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

  1. #
  2. # SATAN data management routines.
  3. #
  4. require 'perl/targets.pl';
  5. require 'perl/todo.pl';
  6. require 'perl/facts.pl';
  7.  
  8. #
  9. # Reset and point path names to new or existing data directory.
  10. #
  11. sub init_satan_data {
  12.     local($directory);
  13.  
  14.     &clear_satan_data();
  15.     &find_satan_data();
  16. }
  17.  
  18. #
  19. # Point path names to new or existing data directory.
  20. #
  21. sub find_satan_data {
  22.     if ($satan_data =~ /\// ) {
  23.         $directory = $satan_data;
  24.     } else {
  25.         (-d "results") || mkdir("results",0700) 
  26.             || die "results: invalid directory: $!\n";
  27.         $directory = "results/$satan_data";
  28.     }
  29.     (-d "$directory") || mkdir("$directory",0700) 
  30.         || die "$satan_data: invalid directory: $!\n";
  31.  
  32.     $todo_file = "$directory/todo";
  33.     $facts_file = "$directory/facts";
  34.     $all_hosts_file = "$directory/all-hosts";
  35. }
  36.  
  37. #
  38. # Erase all in-core satan data structures.
  39. #
  40. sub clear_satan_data {
  41.     &clear_all_hosts();
  42.     &clear_facts();
  43.     &clear_todos();
  44. }
  45.  
  46. #
  47. # Forget non-inference stuff we know about these hosts. We must save/reload
  48. # the tables later, or memory will be polluted with stale inferences.
  49. #
  50. sub drop_satan_data {
  51.     local($hosts) = @_;
  52.     local($host);
  53.  
  54.     for $host (split(/\s+/, $hosts)) {
  55.         &drop_all_hosts($host);
  56.         &drop_old_todos($host);
  57.         &drop_old_facts($host);
  58.     }
  59. }
  60.  
  61. #
  62. # Read satan data from file. Existing in-core data is lost.
  63. #
  64. sub read_satan_data {
  65.  
  66.     &clear_satan_data();
  67.  
  68.     print "Reading $satan_data files...\n" if (-s $facts_file && $debug);
  69.  
  70.     &read_all_hosts($all_hosts_file) if -f $all_hosts_file;
  71.     &read_facts($facts_file) if -f $facts_file;
  72.     &read_todos($todo_file) if -f $todo_file;
  73.  
  74.     print "Done reading $satan_data files\n" if (-s $facts_file && $debug);
  75. }
  76.  
  77. #
  78. # Save satan data to file. Order may matter, in case we crash.
  79. #
  80. sub save_satan_data {
  81.     &save_facts("$facts_file.new");
  82.     rename("$facts_file.new", $facts_file)
  83.         || die "rename $facts_file.new -> $facts_file: $!\n";
  84.  
  85.     &save_todos("$todo_file.new");
  86.     rename("$todo_file.new", $todo_file)
  87.         || die "rename $todo_file.new -> $todo_file: $!\n";
  88.  
  89.     &save_all_hosts("$all_hosts_file.new");
  90.     rename("$all_hosts_file.new", $all_hosts_file)
  91.         || die "rename $all_hosts_file.new -> $all_hosts_file: $!\n";
  92. }
  93.  
  94. #
  95. # Merge data with in-core tables.
  96. #
  97. sub merge_satan_data {
  98.     &merge_all_hosts($all_hosts_file) if -f $all_hosts_file;
  99.     &merge_facts($facts_file) if -f $facts_file;
  100.     &merge_todos($todo_file) if -f $todo_file;
  101. }
  102.