pNet-DNS 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. data/README +68 -0
  2. data/lib/Net/DNS.rb +879 -0
  3. data/lib/Net/DNS/Header.rb +303 -0
  4. data/lib/Net/DNS/Nameserver.rb +601 -0
  5. data/lib/Net/DNS/Packet.rb +851 -0
  6. data/lib/Net/DNS/Question.rb +117 -0
  7. data/lib/Net/DNS/RR.rb +630 -0
  8. data/lib/Net/DNS/RR/A.rb +103 -0
  9. data/lib/Net/DNS/RR/AAAA.rb +147 -0
  10. data/lib/Net/DNS/RR/AFSDB.rb +114 -0
  11. data/lib/Net/DNS/RR/CERT.rb +191 -0
  12. data/lib/Net/DNS/RR/CNAME.rb +89 -0
  13. data/lib/Net/DNS/RR/DNAME.rb +84 -0
  14. data/lib/Net/DNS/RR/EID.rb +70 -0
  15. data/lib/Net/DNS/RR/HINFO.rb +108 -0
  16. data/lib/Net/DNS/RR/ISDN.rb +118 -0
  17. data/lib/Net/DNS/RR/LOC.rb +341 -0
  18. data/lib/Net/DNS/RR/MB.rb +92 -0
  19. data/lib/Net/DNS/RR/MG.rb +96 -0
  20. data/lib/Net/DNS/RR/MINFO.rb +109 -0
  21. data/lib/Net/DNS/RR/MR.rb +92 -0
  22. data/lib/Net/DNS/RR/MX.rb +124 -0
  23. data/lib/Net/DNS/RR/NAPTR.rb +182 -0
  24. data/lib/Net/DNS/RR/NIMLOC.rb +70 -0
  25. data/lib/Net/DNS/RR/NS.rb +100 -0
  26. data/lib/Net/DNS/RR/NSAP.rb +273 -0
  27. data/lib/Net/DNS/RR/NULL.rb +68 -0
  28. data/lib/Net/DNS/RR/OPT.rb +251 -0
  29. data/lib/Net/DNS/RR/PTR.rb +93 -0
  30. data/lib/Net/DNS/RR/PX.rb +131 -0
  31. data/lib/Net/DNS/RR/RP.rb +108 -0
  32. data/lib/Net/DNS/RR/RT.rb +115 -0
  33. data/lib/Net/DNS/RR/SOA.rb +195 -0
  34. data/lib/Net/DNS/RR/SPF.rb +46 -0
  35. data/lib/Net/DNS/RR/SRV.rb +153 -0
  36. data/lib/Net/DNS/RR/SSHFP.rb +190 -0
  37. data/lib/Net/DNS/RR/TKEY.rb +219 -0
  38. data/lib/Net/DNS/RR/TSIG.rb +358 -0
  39. data/lib/Net/DNS/RR/TXT.rb +162 -0
  40. data/lib/Net/DNS/RR/UNKNOWN.rb +76 -0
  41. data/lib/Net/DNS/RR/X25.rb +90 -0
  42. data/lib/Net/DNS/Resolver.rb +2090 -0
  43. data/lib/Net/DNS/Resolver/Recurse.rb +478 -0
  44. data/lib/Net/DNS/Update.rb +189 -0
  45. data/test/custom.txt +4 -0
  46. data/test/resolv.conf +4 -0
  47. data/test/tc_escapedchars.rb +498 -0
  48. data/test/tc_header.rb +91 -0
  49. data/test/tc_inet6.rb +169 -0
  50. data/test/tc_misc.rb +137 -0
  51. data/test/tc_online.rb +236 -0
  52. data/test/tc_packet.rb +174 -0
  53. data/test/tc_packet_unique_push.rb +126 -0
  54. data/test/tc_question.rb +49 -0
  55. data/test/tc_recurse.rb +69 -0
  56. data/test/tc_res_env.rb +59 -0
  57. data/test/tc_res_file.rb +55 -0
  58. data/test/tc_res_opt.rb +135 -0
  59. data/test/tc_resolver.rb +102 -0
  60. data/test/tc_rr-opt.rb +40 -0
  61. data/test/tc_rr-rrsort.rb +116 -0
  62. data/test/tc_rr-txt.rb +138 -0
  63. data/test/tc_rr-unknown.rb +95 -0
  64. data/test/tc_rr.rb +246 -0
  65. data/test/tc_tcp.rb +34 -0
  66. data/test/tc_tkey.rb +115 -0
  67. data/test/tc_update.rb +226 -0
  68. data/test/ts_netdns.rb +17 -0
  69. data/test/ts_offline.rb +32 -0
  70. data/test/ts_online.rb +33 -0
  71. metadata +119 -0
@@ -0,0 +1,189 @@
1
+ # The contents of this file are subject to the Mozilla
2
+ # Public Licence Version 1.1 (the "Licence"); you may
3
+ # not use this file except in compliance with the
4
+ # Licence. You may obtain a copy of the Licence at
5
+ # http://www.mozilla.org/MPL
6
+ # Software distributed under the Licence is distributed
7
+ # on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
8
+ # either express or implied. See the Licence of the
9
+ # specific language governing rights and limitations
10
+ # under the Licence.
11
+ # The Original Code is pNet::DNS.
12
+ # The Initial Developer of the Original Code is
13
+ # Nominet UK (www.nominet.org.uk). Portions created by
14
+ # Nominet UK are Copyright (c) Nominet UK 2006.
15
+ # All rights reserved.
16
+ module Net
17
+ module DNS
18
+ #= NAME
19
+ #
20
+ #Net::DNS::Update - Create a DNS update packet
21
+ #
22
+ #= DESCRIPTION
23
+ #
24
+ #Net::DNS::Update is a subclass of Net::DNS::Packet,
25
+ #to be used for making DNS dynamic updates. Programmers
26
+ #should refer to RFC 2136 for the semantics of dynamic updates.
27
+ #
28
+ #WARNING: This code is still under development. Please use with
29
+ #caution on production nameservers.
30
+ #
31
+ #
32
+ #Future versions of Net::DNS may provide a simpler interface
33
+ #for making dynamic updates.
34
+ #
35
+ #
36
+ #
37
+ #= EXAMPLES
38
+ #
39
+ #The first example below shows a complete program; subsequent examples
40
+ #show only the creation of the update packet.
41
+ #
42
+ #== Add a new host
43
+ #
44
+ # require 'Net/DNS'
45
+ #
46
+ # # Create the update packet.
47
+ # update = Net::DNS::Update.new_from_values('example.com')
48
+ #
49
+ # # Prerequisite is that no A records exist for the name.
50
+ # update.push('pre', Net::DNS.nxrrset('foo.example.com. A'))
51
+ #
52
+ # # Add two A records for the name.
53
+ # update.push('update', Net::DNS.rr_add('foo.example.com. 86400 A 192.168.1.2'))
54
+ # update.push('update', Net::DNS.rr_add('foo.example.com. 86400 A 172.16.3.4'))
55
+ #
56
+ # # Send the update to the zone's primary master.
57
+ # res = Net::DNS::Resolver.new
58
+ # res.nameservers=('primary-master.example.com')
59
+ #
60
+ # reply = res.send(update)
61
+ #
62
+ # # Did it work?
63
+ # if (reply)
64
+ # if (reply.header.rcode == 'NOERROR')
65
+ # print "Update succeeded\n"
66
+ # else
67
+ # print 'Update failed: ', reply.header.rcode, "\n"
68
+ # end
69
+ # else
70
+ # print 'Update failed: ', res.errorstring, "\n"
71
+ # end
72
+ #
73
+ #== Add an MX record for a name that already exists
74
+ #
75
+ # update = Net::DNS::Update.new_from_values('example.com')
76
+ # update.push("pre", yxdomain('example.com'))
77
+ # update.push("update", Net::DNS.rr_add('example.com MX 10 mailhost.example.com'))
78
+ #
79
+ #== Add a TXT record for a name that doesn't exist
80
+ #
81
+ # update = Net::DNS::Update.new_from_values('example.com')
82
+ # update.push("pre", nxdomain('info.example.com'))
83
+ # update.push("update", Net::DNS.rr_add('info.example.com TXT "yabba dabba doo"'))
84
+ #
85
+ #== Delete all A records for a name
86
+ #
87
+ # update = Net::DNS::Update.new_from_values('example.com')
88
+ # update.push("pre", yxrrset('foo.example.com A'))
89
+ # update.push("update", Net::DNS.rr_del('foo.example.com A'))
90
+ #
91
+ #== Delete all RRs for a name
92
+ #
93
+ # update = Net::DNS::Update.new_from_values('example.com')
94
+ # update.push("pre", yxdomain('byebye.example.com'))
95
+ # $update->push("update", Net::DNS.rr_del('byebye.example.com'))
96
+ #
97
+ #== Perform a signed update
98
+ #
99
+ # key_name = 'tsig-key'
100
+ # key = 'awwLOtRfpGE+rRKF2+DEiw=='
101
+ #
102
+ # update = Net::DNS::Update.new_from_values('example.com')
103
+ # update.push('update', Net::DNS.rr_add('foo.example.com A 10.1.2.3'))
104
+ # update.push('update', Net::DNS.rr_add('bar.example.com A 10.4.5.6'))
105
+ # update.sign_tsig(key_name, key)
106
+ #
107
+ #== Another way to perform a signed update
108
+ #
109
+ # key_name = 'tsig-key'
110
+ # key = 'awwLOtRfpGE+rRKF2+DEiw=='
111
+ #
112
+ # update = Net::DNS::Update.new_from_values('example.com')
113
+ # update.push('update', Net::DNS.rr_add('foo.example.com A 10.1.2.3'))
114
+ # update.push('update', Net::DNS.rr_add('bar.example.com A 10.4.5.6'))
115
+ # update.push('additional', Net::DNS::RR.create("#{key_name} TSIG #{key}"))
116
+ #
117
+ #== Perform a signed update with a customized TSIG record
118
+ #
119
+ # key_name = 'tsig-key'
120
+ # key = 'awwLOtRfpGE+rRKF2+DEiw=='
121
+ #
122
+ # tsig = Net::DNS::RR.create("#{key_name} TSIG #{key}")
123
+ # tsig.fudge=(60)
124
+ #
125
+ # update = Net::DNS::Update.new_from_values('example.com')
126
+ # update.push('update', Net::DNS.rr_add('foo.example.com A 10.1.2.3'))
127
+ # update.push('update', Net::DNS.rr_add('bar.example.com A 10.4.5.6'))
128
+ # update.push('additional', tsig)
129
+ #
130
+ #= BUGS
131
+ #
132
+ #This code is still under development. Please use with caution on
133
+ #production nameservers.
134
+ #
135
+ #= COPYRIGHT
136
+ #
137
+ #Copyright (c) 1997-2002 Michael Fuhr.
138
+ #
139
+ #Portions Copyright (c) 2002-2004 Chris Reinhardt.
140
+ #
141
+ #Ruby version Copyright (c) 2006 AlexD (Nominet UK)
142
+ #
143
+ #All rights reserved. This program is free software; you may redistribute
144
+ #it and/or modify it under the same terms as Perl itself.
145
+ #
146
+ #= SEE ALSO
147
+ #
148
+ #Net::DNS, Net::DNS::Resolver, Net::DNS::Header,
149
+ #Net::DNS::Packet, Net::DNS::Question, Net::DNS::RR, RFC 2136,
150
+ #RFC 2845
151
+ #
152
+ class Update < Packet
153
+
154
+ #Returns a Net::DNS::Update object suitable for performing a DNS
155
+ #dynamic update. Specifically, it creates a packet with the header
156
+ #opcode set to UPDATE and the zone record type to SOA (per RFC 2136,
157
+ #Section 2.3).
158
+ #
159
+ #Programs must use the push method to add RRs to the prerequisite,
160
+ #update, and additional sections before performing the update.
161
+ #
162
+ #Arguments are the zone name and the class. If the zone is omitted,
163
+ #the default domain will be taken from the resolver configuration.
164
+ #If the class is omitted, it defaults to IN.
165
+ # packet = Net::DNS::Update.new_from_values
166
+ # packet = Net::DNS::Update.new('example.com')
167
+ # packet = Net::DNS::Update.new('example.com', 'HS')
168
+ #
169
+ def Update.new_from_values(zone=nil, klass=nil)
170
+
171
+ if (zone==nil)
172
+ res = Net::DNS::Resolver.new
173
+ zone = (res.searchlist)[0]
174
+ return unless zone
175
+ end
176
+
177
+ type = 'SOA'
178
+ klass ||= 'IN'
179
+
180
+ packet = Packet.new_from_values(zone, type, klass) || return
181
+
182
+ packet.header.opcode=('UPDATE')
183
+ packet.header.rd=(0)
184
+
185
+ return packet
186
+ end
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,4 @@
1
+ # $Id: custom.txt 264 2005-04-06 09:16:15Z olaf $
2
+ domain t2.net-dns.org
3
+ search alt.net-dns.org ext.net-dns.org
4
+ nameserver 10.0.1.42 10.0.2.42
@@ -0,0 +1,4 @@
1
+ # $Id: .resolv.conf 264 2005-04-06 09:16:15Z olaf $
2
+ domain t.net-dns.org
3
+ search net-dns.org lib.net-dns.org
4
+ nameserver 10.0.1.128 10.0.2.128
@@ -0,0 +1,498 @@
1
+ # The contents of this file are subject to the Mozilla
2
+ # Public Licence Version 1.1 (the "Licence"); you may
3
+ # not use this file except in compliance with the
4
+ # Licence. You may obtain a copy of the Licence at
5
+ # http://www.mozilla.org/MPL
6
+ # Software distributed under the Licence is distributed
7
+ # on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
8
+ # either express or implied. See the Licence of the
9
+ # specific language governing rights and limitations
10
+ # under the Licence.
11
+ # The Original Code is pNet::DNS.
12
+ # The Initial Developer of the Original Code is
13
+ # Nominet UK (www.nominet.org.uk). Portions created by
14
+ # Nominet UK are Copyright (c) Nominet UK 2006.
15
+ # All rights reserved.
16
+ require 'test/unit'
17
+ require 'Net/DNS'
18
+ class TestEscapedChars < Test::Unit::TestCase
19
+ def test_one
20
+ #
21
+ # We test al sorts of escaped non-ascii characters.
22
+ # This is all to be protocol conform... so to speak.
23
+
24
+ #
25
+ # The collection of tests is somewhat of a hodgepodge that tried to
26
+ # assess sensitivity to combinations of characters that the regular
27
+ # expressions and perl itself are sensitive to. (like \\\\\.\..)
28
+ # Development versions of the code tried to split a domain name in
29
+ # invidual labels by a regular expression. It made no sense to remove
30
+ # the more ackward tests as they have to pass anyway ...
31
+
32
+
33
+ # @todo Net::DNS still to have this functionality
34
+ #~ message="Using the "
35
+ #~ message+= if (Net::DNS::HAVE_XS) then " XS compiled " else " perl implemented " end
36
+ #~ message+="dn_expand function "
37
+ #~ diag (message)
38
+
39
+
40
+ #~ had_xs=Net::DNS::HAVE_XS
41
+
42
+
43
+ # Note that in perl the \\ in a presentation format can only be achieved
44
+ # through \\\\ .
45
+
46
+ # The hex codes are the names in wireformat:
47
+ # length octet. content octets, length octet, content , NULL octet
48
+
49
+
50
+
51
+ # Below are test combos, 1st and 2nd array elements are
52
+ # representations of the name. The output of the perl functions should
53
+ # yield the 2nd presentation (eg \037 gets presented as % )
54
+
55
+ # The 3rd element is a label count.
56
+ # The 4th element represents the number of octets per label
57
+ # The 5th element is a hexdump of the domain name in wireformat
58
+
59
+ # The optional 6th element is a boolean instructing to use the perl
60
+ # based dn_expand. This because the conversion between the native
61
+ # dn_expand output to a perl varialbe provides some problems.
62
+
63
+
64
+ testcombos=[
65
+ [
66
+ 'bla\255.foo.org',
67
+ 'bla\255.foo.org',
68
+ 3,
69
+ [4,3,3],
70
+ #Wire: 4 b l a 0xff 3 f o o 3 o r g 0
71
+ "04626c61ff03666f6f036f726700"
72
+ ],
73
+
74
+ [
75
+ 'bla.f\xa9oo.org',
76
+ 'bla.f\169oo.org',
77
+ 3,
78
+ [3,4,3] ,
79
+ #Wire: 3 b l a 4 f 0xa9 o o 3 o r g 0
80
+ "03626c610466a96f6f036f726700"
81
+ ], # Note hex to decimal
82
+ ['bla.fo\.o.org',
83
+ 'bla.fo\.o.org',
84
+ 3,
85
+ [3,4,3],
86
+ #Wire: 3 b l a 4 f o . o 3 o r g 0
87
+ "03626c6104666f2e6f036f726700"
88
+ ],
89
+
90
+ ['bla\0000.foo.org',
91
+ 'bla\0000.foo.org',
92
+ 3,
93
+ [5,3,3],
94
+ #Wire: 5 b l a 0x00 0 3 f o o 3 o r g 0
95
+ "05626c61003003666f6f036f726700" ,
96
+ ],
97
+
98
+ ['bla.fo\o.org',
99
+ 'bla.foo.org',
100
+ 3,
101
+ [3,3,3],
102
+ #Wire: 3 b l a 3 f o o 3 o r g 0 ignoring backslash on input
103
+ "03626c6103666f6f036f726700",
104
+ ],
105
+ #drops the \
106
+ ['bla(*.foo.org',
107
+ 'bla\(*.foo.org',
108
+ 3,
109
+ [5,3,3],
110
+
111
+ #Wire: 5 b l a ( * 3 f o o 3 o r g 0
112
+ "05626c61282a03666f6f036f726700"
113
+ ],
114
+
115
+ [' .bla.foo.org',
116
+ '\032.bla.foo.org',
117
+ 4,
118
+ [1,3,3,3],
119
+ "012003626c6103666f6f036f726700",
120
+ ],
121
+
122
+ ['\\\\a.foo',
123
+ '\\\\a.foo',
124
+ 2,
125
+ [2,3],
126
+ #Wire: 2 \ a 3 f o o 0
127
+ "025c6103666f6f00"
128
+ ],
129
+
130
+
131
+ ['\\\\.foo',
132
+ '\\\\.foo',
133
+ 2,
134
+ [1,3],
135
+ #Wire: 1 \ 3 f o o 0
136
+ "015c03666f6f00",
137
+ ],
138
+
139
+ ['a\\..foo',
140
+ 'a\\..foo',
141
+ 2,
142
+ [2,3],
143
+ #Wire: 2 a . 3 f o o 0
144
+ "02612e03666f6f00"
145
+ ],
146
+
147
+ ['a\\.foo.org',
148
+ 'a\\.foo.org',
149
+ 2, [5,3],
150
+ #Wire: 5 a . f o o 3 o r g 0
151
+ "05612e666f6f036f726700" ,
152
+ ],
153
+
154
+ ['\..foo.org',
155
+ '\..foo.org',
156
+ 3,
157
+ [1,3,3],
158
+
159
+ #Wire: 1 . 3 f o o 3 o r g 0
160
+ "012e03666f6f036f726700" ,
161
+ ],
162
+
163
+ [
164
+ '\046.\046',
165
+ '\..\.',
166
+ 2,
167
+ [1,1],
168
+ '012e012e00',
169
+ ],
170
+
171
+ [ # all non \w characters :-)
172
+ '\000\001\002\003\004\005\006\007\008\009\010\011\012\013\014\015\016\017\018\019\020\021\022\023\024\025\026\027\028\029\030\031\032.\033\034\035\036\037\038\039\040\041\042\043\044\045\046\047\048.\058\059\060\061\062\063\064\065.\091\092\093\094\095\096.\123\124\125\126\127\128\129',
173
+ '\000\001\002\003\004\005\006\007\008\009\010\011\012\013\014\015\016\017\018\019\020\021\022\023\024\025\026\027\028\029\030\031\032.!\"#\$%&\'\(\)*+,-\./0.:\<=>?\@A.[\\\\]^_`.{|}~\127\128\129',
174
+ 5,
175
+ [33,16,8,6,7],
176
+ "21000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20102122232425262728292a2b2c2d2e2f30083a3b3c3d3e3f4041065b5c5d5e5f60077b7c7d7e7f808100",
177
+ ],
178
+
179
+ ]
180
+
181
+
182
+ #foreach my $testinput (@testcombos){
183
+ testcombos.each do |testinput|
184
+ # test back and forth
185
+
186
+ labels=Net::DNS.name2labels( testinput[0])
187
+
188
+
189
+ # assert_equal(testinput[1], Net::DNS::labels2name(labels), "consistent name2labels labels2name for " + testinput[0])
190
+
191
+
192
+ # test number of labels
193
+ assert_equal(testinput[2],labels.length(),"consistent labelcount (#{testinput[2]})")
194
+ # test number of elements within label.
195
+ i=0
196
+ # Test length of each individual label
197
+ while i<testinput[2]
198
+ assert_equal(labels[i].length, testinput[3][i],
199
+ "labellength for label #{i} equals " + testinput[3][i].to_s)
200
+ i = i + 1
201
+ end
202
+
203
+ wire=Net::DNS::RR._name2wire(testinput[0])
204
+
205
+ wireinhex=wire.unpack("H*")[0]
206
+ assert_equal( wireinhex,testinput[4], "Wireinhex for " + testinput[0] )
207
+ # And now call DN_EXPAND
208
+
209
+ if (Net::DNS::HAVE_XS)
210
+
211
+ #SKIP: {
212
+ # skip "No dn_expand_xs available", 1 unless $had_xs
213
+ name,offset=dn_expand(wire,0)
214
+ assert_equal(name,testinput[1],"DN_EXPAND (xs) consistent")
215
+ end
216
+
217
+ # }
218
+
219
+ # @todo Net::DNS does not yet have this functionality
220
+ #~ Net::DNS::HAVE_XS=0
221
+ #~ name,offset=dn_expand(wire,0)
222
+ #~ assert_equal(name,testinput[1],"DN_EXPAND (pp) consistent")
223
+ #~ Net::DNS::HAVE_XS=had_xs
224
+ end
225
+
226
+ # PERL_DN_EXPAND: {
227
+ # if ($had_xs && !$Net::DNS::DN_EXPAND_ESCAPES ){
228
+ # diag ("\ndisabling XS based dns_expand for a moment.")
229
+ # $Net::DNS::HAVE_XS=0
230
+ # }
231
+
232
+ # QUESTION SECTION
233
+ #\\.eg.secret-wg.org. IN TXT
234
+ #
235
+ # ANSWER SECTION:
236
+ #\\.eg.secret-wg.org. 10 IN TXT "WildCard Match"
237
+ #
238
+ # AUTHORITY SECTION:
239
+ #eg.secret-wg.org. 600 IN NS ns.eg.secret-wg.org.
240
+ #
241
+ # ADDITIONAL SECTION:
242
+ #ns.eg.secret-wg.org. 600 IN A 10.0.53.208
243
+ #
244
+
245
+ uuencodedPacket=%w{
246
+ c8 d5 85 00 00 01 00 01 00 01 00 01 02 5c 5c 02
247
+ 65 67 09 73 65 63 72 65 74 2d 77 67 03 6f 72 67
248
+ 00 00 10 00 01 c0 0c 00 10 00 01 00 00 00 0a 00
249
+ 0f 0e 57 69 6c 64 43 61 72 64 20 4d 61 74 63 68
250
+ c0 0f 00 02 00 01 00 00 02 58 00 05 02 6e 73 c0
251
+ 0f c0 4c 00 01 00 01 00 00 02 58 00 04 0a 00 35
252
+ d0
253
+ }
254
+
255
+ # uuEncodedPacket =~ s/\s*//g
256
+ # uuEncodedPacket =uuEncodedPacket.gsub("\s*", "")
257
+ # packetdata = [uuEncodedPacket].pack('H*')
258
+
259
+ uuencodedPacket.map!{|e| e.hex}
260
+ packetdata = uuencodedPacket.pack('c*')
261
+ packetdata = packetdata.gsub("\s*", "")
262
+
263
+ packet = Net::DNS::Packet.new_from_binary(packetdata)
264
+ assert(packet, "nil packet returned from binary data")
265
+ assert_equal( (packet.answer)[0].name,'\\\\\\\\.eg.secret-wg.org',"Correctly dealt escaped backslash from wireformat \\\\.eg.secret-wg.org")
266
+ end
267
+
268
+ def test_esoteric_stuff
269
+ # Now testing for the real esotheric stuff.
270
+ # domain names can contain NULL and space characters (on the wire)
271
+ # these should be properly expanded
272
+
273
+ # This only works if the dn_expand_XS() is NOT used.
274
+
275
+ # The UUencoded packet contains a captured packet with this content:
276
+
277
+ # QUESTION SECTION:
278
+ #\000.n\032ll.eg.secret-wg.org. IN TXT
279
+
280
+ # ANSWER SECTION:
281
+ #\000.n ll.eg.secret-wg.org. 0 IN TXT "NULL byte ownername"
282
+ # ^ SPACE !!!
283
+ # AUTHORITY SECTION:
284
+ #eg.secret-wg.org. 600 IN NS ns.eg.secret-wg.org.
285
+
286
+ # ADDITIONAL SECTION:
287
+ #ns.eg.secret-wg.org. 600 IN A 10.0.53.208
288
+
289
+ uuencodedPacket =%w{
290
+ a6 58 85 00 00 01 00 01 00 01 00 01 01 00 04 6e
291
+ 20 6c 6c 02 65 67 09 73 65 63 72 65 74 2d 77 67
292
+ 03 6f 72 67 00 00 10 00 01 c0 0c 00 10 00 01 00
293
+ 00 00 00 00 14 13 4e 55 4c 4c 20 62 79 74 65 20
294
+ 6f 77 6e 65 72 6e 61 6d 65 c0 13 00 02 00 01 00
295
+ 00 02 58 00 05 02 6e 73 c0 13 c0 55 00 01 00 01
296
+ 00 00 02 58 00 04 0a 00 35 d0
297
+ }
298
+
299
+ uuencodedPacket.map!{|e| e.hex}
300
+ packetdata = uuencodedPacket.pack('c*')
301
+ packetdata = packetdata.gsub("\s*", "")
302
+ packet = Net::DNS::Packet.new_from_binary(packetdata)
303
+ assert_equal( '\000.n\\032ll.eg.secret-wg.org',(packet.answer)[0].name,"Correctly dealt with NULL bytes in domain names")
304
+
305
+
306
+ #slightly modified \\ .eg.secret-wg.org instead of \\\\.eg.secret-wg.org
307
+ # That is escaped backslash space
308
+ uuencodedPacket=%w{
309
+ c8 d5 85 00 00 01 00 01 00 01 00 01 02 5c 20 02
310
+ 65 67 09 73 65 63 72 65 74 2d 77 67 03 6f 72 67
311
+ 00 00 10 00 01 c0 0c 00 10 00 01 00 00 00 0a 00
312
+ 0f 0e 57 69 6c 64 43 61 72 64 20 4d 61 74 63 68
313
+ c0 0f 00 02 00 01 00 00 02 58 00 05 02 6e 73 c0
314
+ 0f c0 4c 00 01 00 01 00 00 02 58 00 04 0a 00 35
315
+ d0
316
+ }
317
+
318
+ uuencodedPacket.map!{|e| e.hex}
319
+ packetdata = uuencodedPacket.pack('c*')
320
+ packetdata.gsub!("\s*", "")
321
+ packet = Net::DNS::Packet.new_from_binary(packetdata)
322
+
323
+
324
+ assert_equal( '\\\\\\032.eg.secret-wg.org',(packet.answer)[0].name,"Correctly dealt escaped backslash from wireformat \\e.eg.secret-wg.org")
325
+ # @todo Replace when Net::DNS does this!
326
+ # if ( had_xs && !Net::DNS::HAVE_XS )
327
+ # puts("\nContinuing to use the XS based dn_expand()\n")
328
+ # Net::DNS::HAVE_XS=1
329
+ # end
330
+
331
+
332
+
333
+ #slightly modified \\e.eg.secret-wg.org instead of \\\\.eg.secret-wg.org
334
+ uuencodedPacket=%w{
335
+ c8 d5 85 00 00 01 00 01 00 01 00 01 02 5c 65 02
336
+ 65 67 09 73 65 63 72 65 74 2d 77 67 03 6f 72 67
337
+ 00 00 10 00 01 c0 0c 00 10 00 01 00 00 00 0a 00
338
+ 0f 0e 57 69 6c 64 43 61 72 64 20 4d 61 74 63 68
339
+ c0 0f 00 02 00 01 00 00 02 58 00 05 02 6e 73 c0
340
+ 0f c0 4c 00 01 00 01 00 00 02 58 00 04 0a 00 35
341
+ d0
342
+ }
343
+
344
+ # uuEncodedPacket =~ s/\s*//g
345
+ # packetdata = uuEncodedPacket.pack('H*')
346
+ # packetdata = packetdata.gsub("\s*", "")
347
+ uuencodedPacket.map!{|e| e.hex}
348
+ packetdata = uuencodedPacket.pack('c*')
349
+ packet = Net::DNS::Packet.new_from_binary(packetdata)
350
+
351
+
352
+ assert_equal( (packet.answer)[0].name,'\\\\e.eg.secret-wg.org',"Correctly dealt escaped backslash from wireformat \\e.eg.secret-wg.org")
353
+
354
+
355
+ #slightly modified \\\..eg.secret-wg.org instead of \\e.eg.secret-wg.org
356
+ uuencodedPacket=%w{
357
+ c8 d5 85 00 00 01 00 01 00 01 00 01 02 5c 65 02
358
+ 65 67 09 73 65 63 72 65 74 2d 77 67 03 6f 72 67
359
+ 00 00 10 00 01 c0 0c 00 10 00 01 00 00 00 0a 00
360
+ 0f 0e 57 69 6c 64 43 61 72 64 20 4d 61 74 63 68
361
+ c0 0f 00 02 00 01 00 00 02 58 00 05 02 6e 73 c0
362
+ 0f c0 4c 00 01 00 01 00 00 02 58 00 04 0a 00 35
363
+ d0
364
+ }
365
+
366
+ ## uuEncodedPacket =~ s/\s*//g
367
+ # packetdata = uuEncodedPacket.pack('H*')
368
+ # packetdata = packetdata.gsub("\s*", "")
369
+ uuencodedPacket.map!{|e| e.hex}
370
+ packetdata = uuencodedPacket.pack('c*')
371
+ packet = Net::DNS::Packet.new_from_binary(packetdata)
372
+ assert_equal( (packet.answer)[0].name,'\\\\e.eg.secret-wg.org',"Correctly dealt escaped backslash from wireformat \\\..eg.secret-wg.org")
373
+
374
+ testrr=Net::DNS::RR.create(
375
+ :name => '\\e.eg.secret-wg.org',
376
+ :type => 'TXT',
377
+ :txtdata => '"WildCard Match"',
378
+ :ttl => 10,
379
+ :class => "IN"
380
+ )
381
+
382
+
383
+
384
+ klass = "IN"
385
+ ttl = 43200
386
+ name = 'def0au&lt.example.com'
387
+
388
+
389
+
390
+ rrs = [
391
+ { #[0]
392
+ :name => '\..bla\..example.com',
393
+ :type => 'A',
394
+ :address => '10.0.0.1',
395
+ }, { #[2]
396
+ :name => name,
397
+ :type => 'AFSDB',
398
+ :subtype => 1,
399
+ :hostname =>'afsdb-hostname.example.com',
400
+ },
401
+ { #[3]
402
+ :name => '\\.funny.example.com',
403
+ :type => 'CNAME',
404
+ :cname => 'cname-cn\244ame.example.com',
405
+ },
406
+ { #[4]
407
+ :name => name,
408
+ :type => 'DNAME',
409
+ :dname => 'dn\222ame.example.com',
410
+ },
411
+ { #[9]
412
+ :name => name,
413
+ :type => 'MINFO',
414
+ :rmailbx => 'minfo\.rmailbx.example.com',
415
+ :emailbx => 'minfo\007emailbx.example.com',
416
+ },
417
+
418
+ { #[13]
419
+ :name => name,
420
+ :type => 'NS',
421
+ :nsdname => '\001ns-nsdname.example.com',
422
+ },
423
+
424
+ { #[19]
425
+ :name => name,
426
+ :type => 'SOA',
427
+ :mname => 'soa-mn\001ame.example.com',
428
+ :rname => 'soa\.rname.example.com',
429
+ :serial => 12345,
430
+ :refresh => 7200,
431
+ :retry => 3600,
432
+ :expire => 2592000,
433
+ :minimum => 86400,
434
+ },
435
+
436
+ ]
437
+
438
+ #------------------------------------------------------------------------------
439
+ # Create the packet.
440
+ #------------------------------------------------------------------------------
441
+ packet = nil
442
+ packet = Net::DNS::Packet.new_from_values(name)
443
+ assert(packet, 'Packet created')
444
+
445
+ # foreach my $data (@rrs) {
446
+ rrs.each do |data|
447
+
448
+ data.update({:ttl => ttl,})
449
+
450
+ packet.push(:answer, Net::DNS::RR.create(data))
451
+ end
452
+
453
+
454
+ #------------------------------------------------------------------------------
455
+ # Re-create the packet from data.
456
+ #------------------------------------------------------------------------------
457
+
458
+ data = packet.data
459
+ assert(data, 'Packet has data after pushes')
460
+
461
+ packet = nil
462
+ packet = Net::DNS::Packet.new_from_binary(data)
463
+
464
+ assert(packet, 'Packet reconstructed from data')
465
+
466
+ answer = packet.answer
467
+
468
+ # assert(answer && answer == rrs, 'Packet returned correct answer section')
469
+ rrs.each do |rr|
470
+ record = nil
471
+ answer.each do |ansrec|
472
+ if (ansrec.type == rr[:type])
473
+ record = ansrec
474
+ break
475
+ end
476
+ end
477
+ assert(record!=nil, "can't find answer record for #{rr}")
478
+ rr.keys.each do |key|
479
+ assert_equal(record.send(key.to_s), rr[key], "value not right for key #{key} for rr #{rr}")
480
+ end
481
+ end
482
+
483
+
484
+ while (answer.size>0 and rrs.size>0)
485
+ data = rrs.shift
486
+ rr = answer.shift
487
+ type = data[:type]
488
+ # foreach my $meth (keys %{$data}) {
489
+ (data.keys.each do |meth|
490
+ assert_equal(rr.send(meth), data[meth], "#{type} - #meth() correct")
491
+ end)
492
+
493
+ rr2 = Net::DNS::RR.new_from_string(rr.inspect)
494
+ assert_equal(rr2.inspect, rr.inspect, "#{type} - Parsing from string works")
495
+ end
496
+
497
+ end
498
+ end