Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.1 KiB

  1. #!/usr/bin/perl
  2. # $RCSfile: scanner,v $$Revision: 4.1 $$Date: 92/08/07 17:20:44 $
  3. # This runs all the scan_* routines on all the machines in /etc/ghosts.
  4. # We run this every morning at about 6 am:
  5. # !/bin/sh
  6. # cd /usr/adm/private
  7. # decrypt scanner | perl >scan.out 2>&1
  8. # mail admin <scan.out
  9. # Note that the scan_* files should be encrypted with the key "-inquire", and
  10. # scanner should be encrypted somehow so that people can't find that key.
  11. # I leave it up to you to figure out how to unencrypt it before executing.
  12. $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/ucb:.';
  13. $| = 1; # command buffering on stdout
  14. print "Subject: bizarre happenings\n\n";
  15. (chdir '/usr/adm/private') || die "Can't cd to /usr/adm/private: $!\n";
  16. if ($#ARGV >= 0) {
  17. @scanlist = @ARGV;
  18. } else {
  19. @scanlist = split(/[ \t\n]+/,`echo scan_*`);
  20. }
  21. scan: while ($scan = shift(@scanlist)) {
  22. print "\n********** $scan **********\n";
  23. $showhost++;
  24. $systype = 'all';
  25. open(ghosts, '/etc/ghosts') || die 'No /etc/ghosts file';
  26. $one_of_these = ":$systype:";
  27. if ($systype =~ s/\+/[+]/g) {
  28. $one_of_these =~ s/\+/:/g;
  29. }
  30. line: while (<ghosts>) {
  31. s/[ \t]*\n//;
  32. if (!$_ || /^#/) {
  33. next line;
  34. }
  35. if (/^([a-zA-Z_0-9]+)=(.+)/) {
  36. $name = $1; $repl = $2;
  37. $repl =~ s/\+/:/g;
  38. $one_of_these =~ s/:$name:/:$repl:/;
  39. next line;
  40. }
  41. @gh = split;
  42. $host = $gh[0];
  43. if ($showhost) { $showhost = "$host:\t"; }
  44. class: while ($class = pop(gh)) {
  45. if (index($one_of_these,":$class:") >=0) {
  46. $iter = 0;
  47. `exec crypt -inquire <$scan >.x 2>/dev/null`;
  48. unless (open(scan,'.x')) {
  49. print "Can't run $scan: $!\n";
  50. next scan;
  51. }
  52. $cmd = <scan>;
  53. unless ($cmd =~ s/#!(.*)\n/$1/) {
  54. $cmd = '/usr/bin/perl';
  55. }
  56. close(scan);
  57. if (open(PIPE,"exec rsh $host '$cmd' <.x|")) {
  58. sleep(5);
  59. unlink '.x';
  60. while (<PIPE>) {
  61. last if $iter++ > 1000; # must be looping
  62. next if /^[0-9.]+u [0-9.]+s/;
  63. print $showhost,$_;
  64. }
  65. close(PIPE);
  66. } else {
  67. print "(Can't execute rsh: $!)\n";
  68. }
  69. last class;
  70. }
  71. }
  72. }
  73. }