dnsruby 1.55 → 1.56.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +96 -0
  3. data/Rakefile +30 -29
  4. data/demo/axfr.rb +93 -93
  5. data/demo/check_soa.rb +99 -99
  6. data/demo/check_zone.rb +59 -59
  7. data/demo/digdlv.rb +43 -43
  8. data/demo/digroot.rb +34 -34
  9. data/demo/example_recurse.rb +14 -14
  10. data/demo/mresolv.rb +30 -30
  11. data/demo/mx.rb +31 -31
  12. data/demo/rubydig.rb +37 -37
  13. data/demo/to_resolve.txt +3088 -3088
  14. data/demo/trace_dns.rb +46 -46
  15. data/lib/dnsruby.rb +161 -526
  16. data/lib/dnsruby/DNS.rb +305 -0
  17. data/lib/{Dnsruby/Cache.rb → dnsruby/cache.rb} +152 -152
  18. data/lib/{Dnsruby → dnsruby}/code_mapper.rb +48 -52
  19. data/lib/dnsruby/code_mappers.rb +295 -0
  20. data/lib/{Dnsruby/Config.rb → dnsruby/config.rb} +454 -454
  21. data/lib/{Dnsruby → dnsruby}/dnssec.rb +91 -91
  22. data/lib/{Dnsruby/Hosts.rb → dnsruby/hosts.rb} +125 -125
  23. data/lib/{Dnsruby → dnsruby}/ipv4.rb +26 -26
  24. data/lib/{Dnsruby → dnsruby}/ipv6.rb +42 -42
  25. data/lib/{Dnsruby → dnsruby}/key_cache.rb +29 -29
  26. data/lib/dnsruby/message/decoder.rb +164 -0
  27. data/lib/dnsruby/message/encoder.rb +75 -0
  28. data/lib/dnsruby/message/header.rb +249 -0
  29. data/lib/dnsruby/message/message.rb +629 -0
  30. data/lib/dnsruby/message/question.rb +86 -0
  31. data/lib/dnsruby/message/section.rb +96 -0
  32. data/lib/{Dnsruby → dnsruby}/name.rb +141 -141
  33. data/lib/dnsruby/packet_sender.rb +661 -0
  34. data/lib/{Dnsruby/Recursor.rb → dnsruby/recursor.rb} +235 -233
  35. data/lib/dnsruby/resolv.rb +113 -0
  36. data/lib/dnsruby/resolver.rb +1192 -0
  37. data/lib/dnsruby/resource/A.rb +56 -0
  38. data/lib/dnsruby/resource/AAAA.rb +54 -0
  39. data/lib/{Dnsruby → dnsruby}/resource/AFSDB.rb +68 -68
  40. data/lib/{Dnsruby → dnsruby}/resource/CERT.rb +105 -105
  41. data/lib/{Dnsruby → dnsruby}/resource/DHCID.rb +54 -54
  42. data/lib/dnsruby/resource/DLV.rb +27 -0
  43. data/lib/{Dnsruby → dnsruby}/resource/DNSKEY.rb +372 -372
  44. data/lib/{Dnsruby → dnsruby}/resource/DS.rb +255 -255
  45. data/lib/{Dnsruby → dnsruby}/resource/HINFO.rb +71 -71
  46. data/lib/{Dnsruby → dnsruby}/resource/HIP.rb +29 -29
  47. data/lib/{Dnsruby → dnsruby}/resource/IN.rb +30 -30
  48. data/lib/{Dnsruby → dnsruby}/resource/IPSECKEY.rb +31 -31
  49. data/lib/{Dnsruby → dnsruby}/resource/ISDN.rb +62 -62
  50. data/lib/{Dnsruby → dnsruby}/resource/KX.rb +65 -65
  51. data/lib/{Dnsruby → dnsruby}/resource/LOC.rb +263 -263
  52. data/lib/{Dnsruby → dnsruby}/resource/MINFO.rb +69 -69
  53. data/lib/{Dnsruby → dnsruby}/resource/MX.rb +65 -65
  54. data/lib/{Dnsruby → dnsruby}/resource/NAPTR.rb +98 -98
  55. data/lib/{Dnsruby → dnsruby}/resource/NSAP.rb +171 -171
  56. data/lib/dnsruby/resource/NSEC.rb +275 -0
  57. data/lib/dnsruby/resource/NSEC3.rb +332 -0
  58. data/lib/dnsruby/resource/NSEC3PARAM.rb +135 -0
  59. data/lib/dnsruby/resource/OPT.rb +272 -0
  60. data/lib/{Dnsruby → dnsruby}/resource/PX.rb +70 -70
  61. data/lib/{Dnsruby → dnsruby}/resource/RP.rb +75 -75
  62. data/lib/dnsruby/resource/RR.rb +421 -0
  63. data/lib/dnsruby/resource/RRSIG.rb +275 -0
  64. data/lib/dnsruby/resource/RRSet.rb +190 -0
  65. data/lib/{Dnsruby → dnsruby}/resource/RT.rb +67 -67
  66. data/lib/{Dnsruby → dnsruby}/resource/SOA.rb +94 -94
  67. data/lib/dnsruby/resource/SPF.rb +29 -0
  68. data/lib/dnsruby/resource/SRV.rb +112 -0
  69. data/lib/{Dnsruby → dnsruby}/resource/SSHFP.rb +14 -14
  70. data/lib/dnsruby/resource/TKEY.rb +163 -0
  71. data/lib/dnsruby/resource/TSIG.rb +593 -0
  72. data/lib/{Dnsruby → dnsruby}/resource/TXT.rb +191 -191
  73. data/lib/dnsruby/resource/X25.rb +55 -0
  74. data/lib/{Dnsruby → dnsruby}/resource/domain_name.rb +25 -25
  75. data/lib/{Dnsruby → dnsruby}/resource/generic.rb +80 -80
  76. data/lib/dnsruby/resource/resource.rb +25 -0
  77. data/lib/{Dnsruby → dnsruby}/select_thread.rb +148 -148
  78. data/lib/{Dnsruby/SingleResolver.rb → dnsruby/single_resolver.rb} +60 -60
  79. data/lib/{Dnsruby → dnsruby}/single_verifier.rb +344 -344
  80. data/lib/dnsruby/the_log.rb +44 -0
  81. data/lib/dnsruby/update.rb +278 -0
  82. data/lib/dnsruby/validator_thread.rb +124 -0
  83. data/lib/dnsruby/version.rb +3 -0
  84. data/lib/{Dnsruby → dnsruby}/zone_reader.rb +93 -93
  85. data/lib/{Dnsruby → dnsruby}/zone_transfer.rb +377 -377
  86. data/test/spec_helper.rb +16 -0
  87. data/test/tc_axfr.rb +31 -34
  88. data/test/tc_cache.rb +32 -32
  89. data/test/tc_dlv.rb +28 -28
  90. data/test/tc_dns.rb +73 -76
  91. data/test/tc_dnskey.rb +31 -32
  92. data/test/tc_dnsruby.rb +50 -44
  93. data/test/tc_ds.rb +36 -36
  94. data/test/tc_escapedchars.rb +252 -255
  95. data/test/tc_hash.rb +17 -21
  96. data/test/tc_header.rb +48 -57
  97. data/test/tc_hip.rb +19 -22
  98. data/test/tc_ipseckey.rb +18 -21
  99. data/test/tc_keith.rb +300 -0
  100. data/test/tc_message.rb +87 -0
  101. data/test/tc_misc.rb +83 -87
  102. data/test/tc_name.rb +81 -84
  103. data/test/tc_naptr.rb +18 -21
  104. data/test/tc_nsec.rb +55 -55
  105. data/test/tc_nsec3.rb +23 -24
  106. data/test/tc_nsec3param.rb +20 -21
  107. data/test/tc_packet.rb +90 -93
  108. data/test/tc_packet_unique_push.rb +48 -51
  109. data/test/tc_question.rb +30 -33
  110. data/test/tc_queue.rb +16 -17
  111. data/test/tc_recur.rb +16 -17
  112. data/test/tc_res_config.rb +38 -41
  113. data/test/tc_res_env.rb +29 -32
  114. data/test/tc_res_file.rb +26 -29
  115. data/test/tc_res_opt.rb +62 -65
  116. data/test/tc_resolver.rb +287 -242
  117. data/test/tc_rr-opt.rb +70 -63
  118. data/test/tc_rr-txt.rb +68 -71
  119. data/test/tc_rr-unknown.rb +45 -48
  120. data/test/tc_rr.rb +76 -70
  121. data/test/tc_rrset.rb +21 -22
  122. data/test/tc_rrsig.rb +19 -20
  123. data/test/tc_single_resolver.rb +294 -297
  124. data/test/tc_soak.rb +199 -202
  125. data/test/tc_soak_base.rb +29 -34
  126. data/test/tc_sshfp.rb +20 -23
  127. data/test/tc_tcp.rb +32 -35
  128. data/test/tc_tkey.rb +41 -44
  129. data/test/tc_tsig.rb +81 -84
  130. data/test/tc_update.rb +108 -111
  131. data/test/tc_validator.rb +29 -29
  132. data/test/tc_verifier.rb +81 -82
  133. data/test/ts_dnsruby.rb +16 -15
  134. data/test/ts_offline.rb +62 -63
  135. data/test/ts_online.rb +115 -115
  136. metadata +155 -90
  137. data/README +0 -59
  138. data/lib/Dnsruby/DNS.rb +0 -305
  139. data/lib/Dnsruby/PacketSender.rb +0 -656
  140. data/lib/Dnsruby/Resolver.rb +0 -1189
  141. data/lib/Dnsruby/TheLog.rb +0 -44
  142. data/lib/Dnsruby/message.rb +0 -1230
  143. data/lib/Dnsruby/resource/A.rb +0 -56
  144. data/lib/Dnsruby/resource/AAAA.rb +0 -54
  145. data/lib/Dnsruby/resource/DLV.rb +0 -27
  146. data/lib/Dnsruby/resource/NSEC.rb +0 -298
  147. data/lib/Dnsruby/resource/NSEC3.rb +0 -340
  148. data/lib/Dnsruby/resource/NSEC3PARAM.rb +0 -135
  149. data/lib/Dnsruby/resource/OPT.rb +0 -213
  150. data/lib/Dnsruby/resource/RRSIG.rb +0 -275
  151. data/lib/Dnsruby/resource/SPF.rb +0 -29
  152. data/lib/Dnsruby/resource/SRV.rb +0 -112
  153. data/lib/Dnsruby/resource/TKEY.rb +0 -163
  154. data/lib/Dnsruby/resource/TSIG.rb +0 -593
  155. data/lib/Dnsruby/resource/X25.rb +0 -55
  156. data/lib/Dnsruby/resource/resource.rb +0 -678
  157. data/lib/Dnsruby/update.rb +0 -278
  158. data/lib/Dnsruby/validator_thread.rb +0 -124
data/demo/trace_dns.rb CHANGED
@@ -1,46 +1,46 @@
1
- #--
2
- #Copyright 2007 Nominet UK
3
- #
4
- #Licensed under the Apache License, Version 2.0 (the "License");
5
- #you may not use this file except in compliance with the License.
6
- #You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- #Unless required by applicable law or agreed to in writing, software
11
- #distributed under the License is distributed on an "AS IS" BASIS,
12
- #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- #See the License for the specific language governing permissions and
14
- #limitations under the License.
15
- #++
16
-
17
- require 'dnsruby'
18
- include Dnsruby
19
-
20
- # e.g. ruby trace_dns.rb example.com
21
-
22
- # Load DLV key
23
- dlv_key = RR.create("dlv.isc.org. IN DNSKEY 257 3 5 BEAAAAPHMu/5onzrEE7z1egmhg/WPO0+juoZrW3euWEn4MxDCE1+lLy2 brhQv5rN32RKtMzX6Mj70jdzeND4XknW58dnJNPCxn8+jAGl2FZLK8t+ 1uq4W+nnA3qO2+DL+k6BD4mewMLbIYFwe0PG73Te9fZ2kJb56dhgMde5 ymX4BI/oQ+cAK50/xvJv00Frf8kw6ucMTwFlgPe+jnGxPPEmHAte/URk Y62ZfkLoBAADLHQ9IrS2tryAe7mbBZVcOwIeU/Rw/mRx/vwwMCTgNboM QKtUdvNXDrYJDSHZws3xiRXF1Rf+al9UmZfSav/4NWLKjHzpT59k/VSt TDN0YUuWrBNh")
24
- Dnssec.add_dlv_key(dlv_key)
25
-
26
- res = Dnsruby::Recursor.new
27
- #TheLog.level = Logger::DEBUG
28
-
29
-
30
- res.recursion_callback=(Proc.new { |packet|
31
-
32
- packet.additional.each { |a| print a.to_s + "\n" }
33
-
34
- print(";; Received #{packet.answersize} bytes from #{packet.answerfrom}. Security Level = #{packet.security_level.string}\n\n")
35
- })
36
-
37
- type = ARGV[1]
38
- if (type == nil)
39
- type = Types.A
40
- end
41
- begin
42
- ret = res.query(ARGV[0], type)
43
- print "\nRESPONSE : #{ret}\n"
44
- rescue NXDomain
45
- print "Domain doesn't exist\n"
46
- end
1
+ # --
2
+ # Copyright 2007 Nominet UK
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ++
16
+
17
+ require 'dnsruby'
18
+ include Dnsruby
19
+
20
+ # e.g. ruby trace_dns.rb example.com
21
+
22
+ # Load DLV key
23
+ dlv_key = RR.create("dlv.isc.org. IN DNSKEY 257 3 5 BEAAAAPHMu/5onzrEE7z1egmhg/WPO0+juoZrW3euWEn4MxDCE1+lLy2 brhQv5rN32RKtMzX6Mj70jdzeND4XknW58dnJNPCxn8+jAGl2FZLK8t+ 1uq4W+nnA3qO2+DL+k6BD4mewMLbIYFwe0PG73Te9fZ2kJb56dhgMde5 ymX4BI/oQ+cAK50/xvJv00Frf8kw6ucMTwFlgPe+jnGxPPEmHAte/URk Y62ZfkLoBAADLHQ9IrS2tryAe7mbBZVcOwIeU/Rw/mRx/vwwMCTgNboM QKtUdvNXDrYJDSHZws3xiRXF1Rf+al9UmZfSav/4NWLKjHzpT59k/VSt TDN0YUuWrBNh")
24
+ Dnssec.add_dlv_key(dlv_key)
25
+
26
+ res = Dnsruby::Recursor.new
27
+ # TheLog.level = Logger::DEBUG
28
+
29
+
30
+ res.recursion_callback=(Proc.new { |packet|
31
+
32
+ packet.additional.each { |a| print a.to_s + "\n" }
33
+
34
+ print(";; Received #{packet.answersize} bytes from #{packet.answerfrom}. Security Level = #{packet.security_level.string}\n\n")
35
+ })
36
+
37
+ type = ARGV[1]
38
+ if (type == nil)
39
+ type = Types.A
40
+ end
41
+ begin
42
+ ret = res.query(ARGV[0], type)
43
+ print "\nRESPONSE : #{ret}\n"
44
+ rescue NXDomain
45
+ print "Domain doesn't exist\n"
46
+ end
data/lib/dnsruby.rb CHANGED
@@ -1,600 +1,235 @@
1
- #--
2
- #Copyright 2007 Nominet UK
3
- #
4
- #Licensed under the Apache License, Version 2.0 (the "License");
5
- #you may not use this file except in compliance with the License.
6
- #You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- #Unless required by applicable law or agreed to in writing, software
11
- #distributed under the License is distributed on an "AS IS" BASIS,
12
- #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- #See the License for the specific language governing permissions and
14
- #limitations under the License.
15
- #++
16
- require 'Dnsruby/code_mapper'
17
- require 'Dnsruby/ipv4'
18
- require 'Dnsruby/ipv6'
1
+ # --
2
+ # Copyright 2007 Nominet UK
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ++
16
+ require 'dnsruby/code_mappers'
17
+ require 'dnsruby/message/message'
18
+ require 'dnsruby/ipv4'
19
+ require 'dnsruby/ipv6'
19
20
  require 'timeout'
20
- require 'Dnsruby/TheLog'
21
- #= Dnsruby library
22
- #Dnsruby is a thread-aware DNS stub resolver library written in Ruby.
23
- #
24
- #It is based on resolv.rb, the standard Ruby DNS implementation,
25
- #but gives a complete DNS implementation, including DNSSEC.
26
- #
27
- #The Resolv class can be used to resolve addresses using /etc/hosts and /etc/resolv.conf,
28
- #or the DNS class can be used to make DNS queries. These interfaces will attempt to apply
29
- #the default domain and searchlist when resolving names.
30
- #
31
- #The Resolver and SingleResolver interfaces allow finer control of individual messages.
32
- #The Resolver class sends queries to multiple resolvers using various retry mechanisms.
33
- #The SingleResolver class is used by Resolver to send individual Messages to individual
34
- #resolvers.
35
- #
36
- #Resolver queries return Dnsruby::Message objects. Message objects have five
37
- #sections:
38
- #
39
- #* The header section, a Dnsruby::Header object.
40
- #
41
- #* The question section, a list of Dnsruby::Question objects.
42
- #
43
- #* The answer section, a list of Dnsruby::Resource objects.
44
- #
45
- #* The authority section, a list of Dnsruby::Resource objects.
46
- #
47
- #* The additional section, a list of Dnsruby::Resource objects.
48
- #
49
- #
50
- #== example
21
+ require 'dnsruby/the_log'
22
+ require 'dnsruby/version'
23
+ require 'dnsruby/cache'
24
+ require 'dnsruby/DNS'
25
+ require 'dnsruby/hosts'
26
+ require 'dnsruby/update'
27
+ require 'dnsruby/zone_transfer'
28
+ require 'dnsruby/dnssec'
29
+ require 'dnsruby/zone_reader'
30
+
31
+
32
+ # = Dnsruby library
33
+ # Dnsruby is a thread-aware DNS stub resolver library written in Ruby.
34
+ #
35
+ # It is based on resolv.rb, the standard Ruby DNS implementation,
36
+ # but gives a complete DNS implementation, including DNSSEC.
37
+ #
38
+ # The Resolv class can be used to resolve addresses using /etc/hosts and /etc/resolv.conf,
39
+ # or the DNS class can be used to make DNS queries. These interfaces will attempt to apply
40
+ # the default domain and searchlist when resolving names.
41
+ #
42
+ # The Resolver and SingleResolver interfaces allow finer control of individual messages.
43
+ # The Resolver class sends queries to multiple resolvers using various retry mechanisms.
44
+ # The SingleResolver class is used by Resolver to send individual Messages to individual
45
+ # resolvers.
46
+ #
47
+ # Resolver queries return Dnsruby::Message objects. Message objects have five
48
+ # sections:
49
+ #
50
+ # * The header section, a Dnsruby::Header object.
51
+ #
52
+ # * The question section, a list of Dnsruby::Question objects.
53
+ #
54
+ # * The answer section, a list of Dnsruby::Resource objects.
55
+ #
56
+ # * The authority section, a list of Dnsruby::Resource objects.
57
+ #
58
+ # * The additional section, a list of Dnsruby::Resource objects.
59
+ #
60
+ #
61
+ # == example
51
62
  # res = Dnsruby::Resolver.new # System default
52
63
  # ret = res.query("example.com")
53
64
  # print "#{ret.anwer.length} answer records returned, #{ret.answer.rrsets.length} RRSets returned in aswer section\n"
54
- #
65
+ #
55
66
  # p Dnsruby::Resolv.getaddress("www.ruby-lang.org")
56
67
  # p Dnsruby::Resolv.getname("210.251.121.214")
57
- #
68
+ #
58
69
  # Dnsruby::DNS.open {|dns|
59
70
  # p dns.getresources("www.ruby-lang.org", Dnsruby::Types.A).collect {|r| r.address}
60
71
  # p dns.getresources("ruby-lang.org", 'MX').collect {|r| [r.exchange.to_s, r.preference]}
61
72
  # }
62
- #
63
- #== exceptions
64
- #
65
- #* ResolvError < StandardError
66
- #
67
- #* ResolvTimeout < TimeoutError
68
- #
69
- #* NXDomain < ResolvError
70
- #
71
- #* FormErr < ResolvError
72
- #
73
- #* ServFail < ResolvError
74
- #
75
- #* NotImp < ResolvError
76
- #
77
- #* Refused < ResolvError
78
- #
79
- #* NotZone < ResolvError
80
- #
81
- #* YXDomain < ResolvError
82
- #
83
- #* YXRRSet < ResolvError
84
- #
85
- #* NXRRSet < ResolvError
86
- #
87
- #* NotAuth < ResolvError
88
- #
89
- #* OtherResolvError < ResolvError
90
- #
91
- #== I/O
92
- #Dnsruby implements a pure Ruby event loop to perform I/O.
93
- #Support for EventMachine has been deprecated.
94
- #
95
- #== DNSSEC
96
- #Dnsruby supports DNSSEC and NSEC(3).
97
- #DNSSEC support is on by default - but no trust anchors are configured by default.
98
- #See Dnsruby::Dnssec for more details.
99
- #
100
- #== Bugs
101
- #* NIS is not supported.
102
- #* /etc/nsswitch.conf is not supported.
103
- #* NSEC3 validation still TBD
73
+ #
74
+ # == exceptions
75
+ #
76
+ # * ResolvError < StandardError
77
+ #
78
+ # * ResolvTimeout < TimeoutError
79
+ #
80
+ # * NXDomain < ResolvError
81
+ #
82
+ # * FormErr < ResolvError
83
+ #
84
+ # * ServFail < ResolvError
85
+ #
86
+ # * NotImp < ResolvError
87
+ #
88
+ # * Refused < ResolvError
89
+ #
90
+ # * NotZone < ResolvError
91
+ #
92
+ # * YXDomain < ResolvError
93
+ #
94
+ # * YXRRSet < ResolvError
95
+ #
96
+ # * NXRRSet < ResolvError
97
+ #
98
+ # * NotAuth < ResolvError
99
+ #
100
+ # * OtherResolvError < ResolvError
101
+ #
102
+ # == I/O
103
+ # Dnsruby implements a pure Ruby event loop to perform I/O.
104
+ # Support for EventMachine has been deprecated.
105
+ #
106
+ # == DNSSEC
107
+ # Dnsruby supports DNSSEC and NSEC(3).
108
+ # DNSSEC support is on by default - but no trust anchors are configured by default.
109
+ # See Dnsruby::Dnssec for more details.
110
+ #
111
+ # == Codes
112
+ # Dnsruby makes extensive use of several different types of codes. These are implemented
113
+ # in the form of subclasses of CodeMapper and are located in lib/code_mappers.rb. They are:
114
+ #
115
+ # * OpCode - e.g. Query, Status, Notify
116
+ # * RCode - e.g. NOERROR, NXDOMAIN
117
+ # * ExtendedRCode - currently only BADVERS
118
+ # * Classes - IN, CH, HS, NONE, ANY
119
+ # * Types - RR types, e.g. A, NS, SOA
120
+ # * QTypes - IXFR, AXFR, MAILB, MAILA, ANY
121
+ # * MetaTypes - TKEY, TSIG, OPT
122
+ # * Algorithms - e.g. RSAMD5, DH, DSA
123
+ # * Nsec3HashAlgorithms - currently only SHA-1
124
+
125
+ # == Bugs
126
+ # * NIS is not supported.
127
+ # * /etc/nsswitch.conf is not supported.
128
+ # * NSEC3 validation still TBD
104
129
  module Dnsruby
105
130
 
106
- # @TODO@ Remember to update version in dnsruby.gemspec!
107
- VERSION = 1.55
108
131
  def Dnsruby.version
109
132
  return VERSION
110
133
  end
111
-
134
+
112
135
  @@logger = Logger.new(STDOUT)
113
136
  @@logger.level = Logger::FATAL
114
- #Get the log for Dnsruby
115
- #Use this to set the log level
116
- #e.g. Dnsruby.log.level = Logger::INFO
137
+ # Get the log for Dnsruby
138
+ # Use this to set the log level
139
+ # e.g. Dnsruby.log.level = Logger::INFO
117
140
  def Dnsruby.log
118
141
  @@logger
119
142
  end
120
-
121
- class OpCode < CodeMapper
122
- Query = 0 # RFC 1035
123
- IQuery = 1 # RFC 1035
124
- Status = 2 # RFC 1035
125
- Notify = 4 # RFC 1996
126
- Update = 5 # RFC 2136
127
-
128
- update()
129
- end
130
-
131
- class RCode < CodeMapper
132
- NOERROR = 0 # RFC 1035
133
- FORMERR = 1 # RFC 1035
134
- SERVFAIL = 2 # RFC 1035
135
- NXDOMAIN = 3 # RFC 1035
136
- NOTIMP = 4 # RFC 1035
137
- REFUSED = 5 # RFC 1035
138
- YXDOMAIN = 6 # RFC 2136
139
- YXRRSET = 7 # RFC 2136
140
- NXRRSET = 8 # RFC 2136
141
- NOTAUTH = 9 # RFC 2136
142
- NOTZONE = 10 # RFC 2136
143
-
144
- # BADVERS = 16 # an EDNS ExtendedRCode
145
- BADSIG = 16
146
- BADKEY = 17
147
- BADTIME = 18
148
- BADMODE = 19
149
- BADNAME = 20
150
- BADALG = 21
151
-
152
- update()
153
- end
154
143
 
155
- class ExtendedRCode < CodeMapper
156
- BADVERS = 16
157
- update()
158
- end
159
-
160
- class Classes < CodeMapper
161
- IN = 1 # RFC 1035
162
- CH = 3 # RFC 1035
163
- # CHAOS = 3 # RFC 1035
164
- HS = 4 # RFC 1035
165
- # HESIOD = 4 # RFC 1035
166
- NONE = 254 # RFC 2136
167
- ANY = 255 # RFC 1035
168
- update()
169
-
170
- def unknown_string(arg)
171
- if (arg=~/^CLASS/i)
172
- Classes.add_pair(arg, arg.gsub('CLASS', '').to_i)
173
- set_string(arg)
174
- else
175
- raise ArgumentError.new("String #{arg} not a member of #{self.class}")
176
- end
177
- end
178
-
179
- def unknown_code(arg)
180
- Classes.add_pair('CLASS' + arg.to_s, arg)
181
- set_code(arg)
182
- end
183
-
184
- # classesbyval and classesbyname functions are wrappers around the
185
- # similarly named hashes. They are used for 'unknown' DNS RR classess
186
- # (RFC3597)
187
- # See typesbyval and typesbyname, these beasts have the same functionality
188
- def Classes.classesbyname(name) #:nodoc: all
189
- name.upcase!;
190
- if to_code(name)
191
- return to_code(name)
192
- end
193
-
194
- if ((name =~/^\s*CLASS(\d+)\s*$/o) == nil)
195
- raise ArgumentError, "classesbyval() argument is not CLASS### (#{name})"
196
- end
197
-
198
- val = $1.to_i
199
- if val > 0xffff
200
- raise ArgumentError, 'classesbyval() argument larger than ' + 0xffff
201
- end
202
-
203
- return val;
204
- end
205
-
206
-
207
-
208
- def Classes.classesbyval(val) #:nodoc: all
209
- if (val.class == String)
210
- if ((val =~ /^\s*0*([0-9]+)\s*$/) == nil)
211
- raise ArgumentError, "classesbybal() argument is not numeric (#{val})" # unless val.gsub!("^\s*0*([0-9]+)\s*$", "$1")
212
- # val =~ s/^\s*0*([0-9]+)\s*$/$1/o;#
213
- end
214
- val = $1.to_i
215
- end
216
-
217
- return to_string(val) if to_string(val)
218
-
219
- raise ArgumentError, 'classesbyval() argument larger than ' + 0xffff if val > 0xffff;
220
-
221
- return "CLASS#{val}";
222
- end
223
- end
224
-
225
- # The RR types explicitly supported by Dnsruby.
226
- #
227
- # New RR types should be added to this set
228
- class Types < CodeMapper
229
- SIGZERO = 0 # RFC2931 consider this a pseudo type
230
- A = 1 # RFC 1035, Section 3.4.1
231
- NS = 2 # RFC 1035, Section 3.3.11
232
- MD = 3 # RFC 1035, Section 3.3.4 (obsolete)
233
- MF = 4 # RFC 1035, Section 3.3.5 (obsolete)
234
- CNAME = 5 # RFC 1035, Section 3.3.1
235
- SOA = 6 # RFC 1035, Section 3.3.13
236
- MB = 7 # RFC 1035, Section 3.3.3
237
- MG = 8 # RFC 1035, Section 3.3.6
238
- MR = 9 # RFC 1035, Section 3.3.8
239
- NULL = 10 # RFC 1035, Section 3.3.10
240
- WKS = 11 # RFC 1035, Section 3.4.2 (deprecated)
241
- PTR = 12 # RFC 1035, Section 3.3.12
242
- HINFO = 13 # RFC 1035, Section 3.3.2
243
- MINFO = 14 # RFC 1035, Section 3.3.7
244
- MX = 15 # RFC 1035, Section 3.3.9
245
- TXT = 16 # RFC 1035, Section 3.3.14
246
- RP = 17 # RFC 1183, Section 2.2
247
- AFSDB = 18 # RFC 1183, Section 1
248
- X25 = 19 # RFC 1183, Section 3.1
249
- ISDN = 20 # RFC 1183, Section 3.2
250
- RT = 21 # RFC 1183, Section 3.3
251
- NSAP = 22 # RFC 1706, Section 5
252
- NSAP_PTR = 23 # RFC 1348 (obsolete)
253
- SIG = 24 # RFC 2535, Section 4.1
254
- KEY = 25 # RFC 2535, Section 3.1
255
- PX = 26 # RFC 2163,
256
- GPOS = 27 # RFC 1712 (obsolete)
257
- AAAA = 28 # RFC 1886, Section 2.1
258
- LOC = 29 # RFC 1876
259
- NXT = 30 # RFC 2535, Section 5.2 obsoleted by RFC3755
260
- EID = 31 # draft-ietf-nimrod-dns-xx.txt
261
- NIMLOC = 32 # draft-ietf-nimrod-dns-xx.txt
262
- SRV = 33 # RFC 2052
263
- ATMA = 34 # ???
264
- NAPTR = 35 # RFC 2168
265
- KX = 36 # RFC 2230
266
- CERT = 37 # RFC 2538
267
- DNAME = 39 # RFC 2672
268
- OPT = 41 # RFC 2671
269
- # APL = 42 # RFC 3123
270
- DS = 43 # RFC 4034
271
- SSHFP = 44 # RFC 4255
272
- IPSECKEY = 45 # RFC 4025
273
- RRSIG = 46 # RFC 4034
274
- NSEC = 47 # RFC 4034
275
- DNSKEY = 48 # RFC 4034
276
- DHCID = 49 # RFC 4701
277
- NSEC3 = 50 # RFC still pending at time of writing
278
- NSEC3PARAM= 51 # RFC still pending at time of writing
279
- HIP = 55 # RFC 5205
280
- SPF = 99 # RFC 4408
281
- UINFO = 100 # non-standard
282
- UID = 101 # non-standard
283
- GID = 102 # non-standard
284
- UNSPEC = 103 # non-standard
285
- TKEY = 249 # RFC 2930
286
- TSIG = 250 # RFC 2931
287
- IXFR = 251 # RFC 1995
288
- AXFR = 252 # RFC 1035
289
- MAILB = 253 # RFC 1035 (MB, MG, MR)
290
- MAILA = 254 # RFC 1035 (obsolete - see MX)
291
- ANY = 255 # RFC 1035
292
- DLV = 32769 # RFC 4431 (informational)
293
- update()
294
-
295
- def unknown_string(arg) #:nodoc: all
296
- if (arg=~/^TYPE/i)
297
- Types.add_pair(arg, arg.gsub('TYPE', '').to_i)
298
- set_string(arg)
299
- else
300
- raise ArgumentError.new("String #{arg} not a member of #{self.class}")
301
- end
302
- end
303
-
304
- def unknown_code(arg) #:nodoc: all
305
- Types.add_pair('TYPE' + arg.to_s, arg)
306
- set_code(arg)
307
- end
308
-
309
- #--
310
- # typesbyval and typesbyname functions are wrappers around the similarly named
311
- # hashes. They are used for 'unknown' DNS RR types (RFC3597)
312
- # typesbyname returns they TYPEcode as a function of the TYPE
313
- # mnemonic. If the TYPE mapping is not specified the generic mnemonic
314
- # TYPE### is returned.
315
- def Types.typesbyname(name) #:nodoc: all
316
- name.upcase!
317
-
318
- if to_code(name)
319
- return to_code(name)
320
- end
321
-
322
-
323
- if ((name =~/^\s*TYPE(\d+)\s*$/o)==nil)
324
- raise ArgumentError, "Net::DNS::typesbyname() argument (#{name}) is not TYPE###"
325
- end
326
-
327
- val = $1.to_i
328
- if val > 0xffff
329
- raise ArgumentError, 'Net::DNS::typesbyname() argument larger than ' + 0xffff
330
- end
331
-
332
- return val;
333
- end
334
-
335
-
336
- # typesbyval returns they TYPE mnemonic as a function of the TYPE
337
- # code. If the TYPE mapping is not specified the generic mnemonic
338
- # TYPE### is returned.
339
- def Types.typesbyval(val) #:nodoc: all
340
- if (!defined?val)
341
- raise ArgumentError, "Net::DNS::typesbyval() argument is not defined"
342
- end
343
-
344
- if val.class == String
345
- # if val.gsub!("^\s*0*(\d+)\s*$", "$1")
346
- if ((val =~ /^\s*0*(\d+)\s*$", "$1/o) == nil)
347
- raise ArgumentError, "Net::DNS::typesbyval() argument (#{val}) is not numeric"
348
- # val =~s/^\s*0*(\d+)\s*$/$1/o;
349
- end
350
-
351
- val = $1.to_i
352
- end
353
-
354
-
355
- if to_string(val)
356
- return to_string(val)
357
- end
358
-
359
- raise ArgumentError, 'Net::DNS::typesbyval() argument larger than ' + 0xffff if
360
- val > 0xffff;
361
-
362
- return "TYPE#{val}";
363
- end
364
- end
365
-
366
- class QTypes < CodeMapper
367
- IXFR = 251 # incremental transfer [RFC1995]
368
- AXFR = 252 # transfer of an entire zone [RFC1035]
369
- MAILB = 253 # mailbox-related RRs (MB, MG or MR) [RFC1035]
370
- MAILA = 254 # mail agent RRs (Obsolete - see MX) [RFC1035]
371
- ANY = 255 # all records [RFC1035]
372
- update()
373
- end
374
-
375
- class MetaTypes < CodeMapper
376
- TKEY = 249 # Transaction Key [RFC2930]
377
- TSIG = 250 # Transaction Signature [RFC2845]
378
- OPT = 41 # RFC 2671
379
- end
380
-
381
- # http://www.iana.org/assignments/dns-sec-alg-numbers/
382
- class Algorithms < CodeMapper
383
- RESERVED = 0
384
- RSAMD5 = 1
385
- DH = 2
386
- DSA = 3
387
- RSASHA1 = 5
388
- RSASHA256 = 8
389
- RSASHA512 = 10
390
- ECDSAP256SHA256 = 13
391
- ECDSAP384SHA384 = 14
392
- INDIRECT = 252
393
- PRIVATEDNS = 253
394
- PRIVATEOID = 254
395
- update()
396
- # Referred to as Algorithms.DSA_NSEC3_SHA1
397
- add_pair("DSA-NSEC3-SHA1", 6)
398
- # Referred to as Algorithms.RSASHA1_NSEC3_SHA1
399
- add_pair("RSASHA1-NSEC3-SHA1", 7)
400
- # Referred to as Algorithms.ECC_GOST
401
- add_pair("ECC-GOST",12)
402
- end
403
144
 
404
- # http://www.iana.org/assignments/dnssec-nsec3-parameters/dnssec-nsec3-parameters.xhtml
405
- class Nsec3HashAlgorithms < CodeMapper
406
- RESERVED = 0
407
- update()
408
- add_pair("SHA-1", 1)
409
- end
145
+ # Logs (error level) and raises an error.
146
+ def log_and_raise(object, error_class = RuntimeError)
147
+ if object.is_a?(Exception)
148
+ error = object
149
+ Dnsruby.log.error(error.inspect)
150
+ raise error
151
+ else
152
+ message = object.to_s
153
+ Dnsruby.log.error(message)
154
+ raise error_class.new(message)
155
+ end
156
+ end; module_function :log_and_raise
410
157
 
411
- #An error raised while querying for a resource
158
+ # An error raised while querying for a resource
412
159
  class ResolvError < StandardError
413
160
  end
414
-
415
- #A timeout error raised while querying for a resource
161
+
162
+ # A timeout error raised while querying for a resource
416
163
  class ResolvTimeout < TimeoutError
417
164
  end
418
-
419
- #The requested domain does not exist
165
+
166
+ # The requested domain does not exist
420
167
  class NXDomain < ResolvError
421
168
  end
422
-
423
- #A format error in a received DNS message
169
+
170
+ # A format error in a received DNS message
424
171
  class FormErr < ResolvError
425
172
  end
426
-
427
- #Indicates a failure in the remote resolver
173
+
174
+ # Indicates a failure in the remote resolver
428
175
  class ServFail < ResolvError
429
176
  end
430
-
431
- #The requested operation is not implemented in the remote resolver
177
+
178
+ # The requested operation is not implemented in the remote resolver
432
179
  class NotImp < ResolvError
433
180
  end
434
-
435
- #The requested operation was refused by the remote resolver
181
+
182
+ # The requested operation was refused by the remote resolver
436
183
  class Refused < ResolvError
437
184
  end
438
185
 
439
- #The update RR is outside the zone (in dynamic update)
186
+ # The update RR is outside the zone (in dynamic update)
440
187
  class NotZone < ResolvError
441
188
  end
442
189
 
443
- #Some name that ought to exist, does not exist (in dynamic update)
190
+ # Some name that ought to exist, does not exist (in dynamic update)
444
191
  class YXDomain < ResolvError
445
192
  end
446
193
 
447
- #Some RRSet that ought to exist, does not exist (in dynamic update)
194
+ # Some RRSet that ought to exist, does not exist (in dynamic update)
448
195
  class YXRRSet < ResolvError
449
196
  end
450
197
 
451
- #Some RRSet that ought not to exist, does exist (in dynamic update)
198
+ # Some RRSet that ought not to exist, does exist (in dynamic update)
452
199
  class NXRRSet < ResolvError
453
200
  end
454
201
 
455
- #The nameserver is not responsible for the zone (in dynamic update)
202
+ # The nameserver is not responsible for the zone (in dynamic update)
456
203
  class NotAuth < ResolvError
457
204
  end
458
205
 
459
-
460
- #Another kind of resolver error has occurred
206
+
207
+ # Another kind of resolver error has occurred
461
208
  class OtherResolvError < ResolvError
462
209
  end
463
210
 
464
- #An error occurred processing the TSIG
211
+ # An error occurred processing the TSIG
465
212
  class TsigError < OtherResolvError
466
213
  end
467
-
468
- # Sent a signed packet, got an unsigned response
214
+
215
+ # Sent a signed packet, got an unsigned response
469
216
  class TsigNotSignedResponseError < TsigError
470
217
  end
471
218
 
472
- #Indicates an error in decoding an incoming DNS message
219
+ # Indicates an error in decoding an incoming DNS message
473
220
  class DecodeError < ResolvError
474
221
  attr_accessor :partial_message
475
222
  end
476
223
 
477
- #Indicates an error encoding a DNS message for transmission
224
+ # Indicates an error encoding a DNS message for transmission
478
225
  class EncodeError < ResolvError
479
226
  end
480
227
 
481
- #Indicates an error verifying
228
+ # Indicates an error verifying
482
229
  class VerifyError < ResolvError
483
230
  end
484
231
 
485
- #Indicates a zone transfer has failed due to SOA serial mismatch
232
+ # Indicates a zone transfer has failed due to SOA serial mismatch
486
233
  class ZoneSerialError < ResolvError
487
234
  end
488
-
489
- #The Resolv class can be used to resolve addresses using /etc/hosts and /etc/resolv.conf,
490
- #
491
- #The DNS class may be used to perform more queries. If greater control over the sending
492
- #of packets is required, then the Resolver or SingleResolver classes may be used.
493
- class Resolv
494
-
495
- #Looks up the first IP address for +name+
496
- def self.getaddress(name)
497
- DefaultResolver.getaddress(name)
498
- end
499
-
500
- #Looks up all IP addresses for +name+
501
- def self.getaddresses(name)
502
- DefaultResolver.getaddresses(name)
503
- end
504
-
505
- #Iterates over all IP addresses for +name+
506
- def self.each_address(name, &block)
507
- DefaultResolver.each_address(name, &block)
508
- end
509
-
510
- #Looks up the first hostname of +address+
511
- def self.getname(address)
512
- DefaultResolver.getname(address)
513
- end
514
-
515
- #Looks up all hostnames of +address+
516
- def self.getnames(address)
517
- DefaultResolver.getnames(address)
518
- end
519
-
520
- #Iterates over all hostnames of +address+
521
- def self.each_name(address, &proc)
522
- DefaultResolver.each_name(address, &proc)
523
- end
524
-
525
- #Creates a new Resolv using +resolvers+
526
- def initialize(resolvers=[Hosts.new, DNS.new])
527
- @resolvers = resolvers
528
- end
529
-
530
- #Looks up the first IP address for +name+
531
- def getaddress(name)
532
- each_address(name) {|address| return address}
533
- raise ResolvError.new("no address for #{name}")
534
- end
535
-
536
- #Looks up all IP addresses for +name+
537
- def getaddresses(name)
538
- ret = []
539
- each_address(name) {|address| ret << address}
540
- return ret
541
- end
542
-
543
- #Iterates over all IP addresses for +name+
544
- def each_address(name)
545
- if AddressRegex =~ name
546
- yield name
547
- return
548
- end
549
- yielded = false
550
- @resolvers.each {|r|
551
- r.each_address(name) {|address|
552
- yield address.to_s
553
- yielded = true
554
- }
555
- return if yielded
556
- }
557
- end
558
-
559
- #Looks up the first hostname of +address+
560
- def getname(address)
561
- each_name(address) {|name| return name}
562
- raise ResolvError.new("no name for #{address}")
563
- end
564
-
565
- #Looks up all hostnames of +address+
566
- def getnames(address)
567
- ret = []
568
- each_name(address) {|name| ret << name}
569
- return ret
570
- end
571
-
572
- #Iterates over all hostnames of +address+
573
- def each_name(address)
574
- yielded = false
575
- @resolvers.each {|r|
576
- r.each_name(address) {|name|
577
- yield name.to_s
578
- yielded = true
579
- }
580
- return if yielded
581
- }
582
- end
583
-
584
-
585
- require 'Dnsruby/Cache'
586
- require 'Dnsruby/DNS'
587
- require 'Dnsruby/Hosts'
588
- require 'Dnsruby/message'
589
- require 'Dnsruby/update'
590
- require 'Dnsruby/zone_transfer'
591
- require 'Dnsruby/dnssec'
592
- require 'Dnsruby/zone_reader'
593
-
594
- #Default Resolver to use for Dnsruby class methods
595
- DefaultResolver = self.new
596
-
597
- #Address RegExp to use for matching IP addresses
598
- AddressRegex = /(?:#{IPv4::Regex})|(?:#{IPv6::Regex})/
599
- end
600
235
  end