digcomp.pl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/perl
  2. #
  3. # Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC")
  4. # Copyright (C) 2000, 2001 Internet Software Consortium.
  5. #
  6. # Permission to use, copy, modify, and/or distribute this software for any
  7. # purpose with or without fee is hereby granted, provided that the above
  8. # copyright notice and this permission notice appear in all copies.
  9. #
  10. # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  11. # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  12. # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  13. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  14. # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  15. # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. # PERFORMANCE OF THIS SOFTWARE.
  17. # Compare two files, each with the output from dig, for differences.
  18. # Ignore "unimportant" differences, like ordering of NS lines, TTL's,
  19. # etc...
  20. # This is a bare copy of the script used in BIND 9's system test. It was
  21. # old and may need cleanups, or we may want to rewrite it in python.
  22. $file1 = $ARGV[0];
  23. $file2 = $ARGV[1];
  24. $count = 0;
  25. $firstname = "";
  26. $status = 0;
  27. $rcode1 = "none";
  28. $rcode2 = "none";
  29. open(FILE1, $file1) || die("open: $file1: $!\n");
  30. while (<FILE1>) {
  31. chomp;
  32. if (/^;.+status:\s+(\S+).+$/) {
  33. $rcode1 = $1;
  34. }
  35. next if (/^;/);
  36. if (/^(\S+)\s+\S+\s+(\S+)\s+(\S+)\s+(.+)$/) {
  37. $name = $1;
  38. $class = $2;
  39. $type = $3;
  40. $value = $4;
  41. if ($type eq "SOA") {
  42. $firstname = $name if ($firstname eq "");
  43. if ($name eq $firstname) {
  44. $name = "$name$count";
  45. $count++;
  46. }
  47. }
  48. if ($entry{"$name ; $class.$type ; $value"} ne "") {
  49. $line = $entry{"$name ; $class.$type ; $value"};
  50. print("Duplicate entry in $file1:\n> $_\n< $line\n");
  51. } else {
  52. $entry{"$name ; $class.$type ; $value"} = $_;
  53. }
  54. }
  55. }
  56. close(FILE1);
  57. $printed = 0;
  58. open(FILE2, $file2) || die("open: $file2: $!\n");
  59. while (<FILE2>) {
  60. chomp;
  61. if (/^;.+status:\s+(\S+).+$/) {
  62. $rcode2 = $1;
  63. }
  64. next if (/^;/);
  65. if (/^(\S+)\s+\S+\s+(\S+)\s+(\S+)\s+(.+)$/) {
  66. $name = $1;
  67. $class = $2;
  68. $type = $3;
  69. $value = $4;
  70. if (($name eq $firstname) && ($type eq "SOA")) {
  71. $count--;
  72. $name = "$name$count";
  73. }
  74. if ($entry{"$name ; $class.$type ; $value"} ne "") {
  75. $entry{"$name ; $class.$type ; $value"} = "";
  76. } else {
  77. print("Only in $file2 (missing from $file1):\n")
  78. if ($printed == 0);
  79. print("> $_\n");
  80. $printed++;
  81. $status = 1;
  82. }
  83. }
  84. }
  85. close(FILE2);
  86. $printed = 0;
  87. foreach $key (keys(%entry)) {
  88. if ($entry{$key} ne "") {
  89. print("Only in $file1 (missing from $file2):\n")
  90. if ($printed == 0);
  91. print("< $entry{$key}\n");
  92. $status = 1;
  93. $printed++;
  94. }
  95. }
  96. if ($rcode1 ne $rcode2) {
  97. print("< status: $rcode1\n");
  98. print("> status: $rcode2\n");
  99. $status = 1;
  100. }
  101. exit($status);