rubydns 0.6.7 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/.yardopts +1 -0
- data/README.md +98 -92
- data/lib/rubydns.rb +5 -47
- data/lib/rubydns/{extensions/string-1.9.3.rb → binary_string.rb} +2 -0
- data/lib/rubydns/extensions/logger.rb +1 -1
- data/lib/rubydns/extensions/resolv.rb +1 -5
- data/lib/rubydns/extensions/string.rb +1 -0
- data/lib/rubydns/handler.rb +7 -2
- data/lib/rubydns/message.rb +17 -4
- data/lib/rubydns/resolver.rb +3 -0
- data/lib/rubydns/server.rb +182 -93
- data/lib/rubydns/transaction.rb +110 -149
- data/lib/rubydns/version.rb +1 -1
- data/rubydns.gemspec +1 -1
- data/test/examples/dropping-dns.rb +2 -2
- data/test/examples/fortune-dns.rb +2 -2
- data/test/examples/soa-dns.rb +1 -1
- data/test/examples/wikipedia-dns.rb +2 -2
- data/test/test_daemon.rb +3 -3
- data/test/test_message.rb +41 -0
- data/test/test_passthrough.rb +5 -1
- data/test/test_rules.rb +3 -3
- data/test/test_slow_server.rb +8 -6
- data/test/test_truncation.rb +3 -3
- metadata +10 -9
- data/lib/rubydns/extensions/hexdump.rb +0 -38
- data/lib/rubydns/extensions/string-1.8.rb +0 -35
- data/lib/rubydns/extensions/string-1.9.2.rb +0 -29
data/lib/rubydns/version.rb
CHANGED
data/rubydns.gemspec
CHANGED
@@ -50,7 +50,7 @@ class DroppingDaemon < RExec::Daemon::Base
|
|
50
50
|
match(/(m?i?c?r?o?s?o?f?t)/) do |transaction, match_data|
|
51
51
|
if match_data[1].size > 7
|
52
52
|
logger.info "Dropping domain MICROSOFT..."
|
53
|
-
transaction.
|
53
|
+
transaction.fail!(:NXDomain)
|
54
54
|
else
|
55
55
|
# Pass the request to the otherwise handler
|
56
56
|
false
|
@@ -60,7 +60,7 @@ class DroppingDaemon < RExec::Daemon::Base
|
|
60
60
|
# Hmm....
|
61
61
|
match(/^(.+\.)?sco\./) do |transaction|
|
62
62
|
logger.info "Dropping domain SCO..."
|
63
|
-
transaction.
|
63
|
+
transaction.fail!(:NXDomain)
|
64
64
|
end
|
65
65
|
|
66
66
|
# Default DNS handler
|
@@ -79,7 +79,7 @@ class FortuneDNS < RExec::Daemon::Base
|
|
79
79
|
if fortune
|
80
80
|
transaction.respond!(*fortune.chunked)
|
81
81
|
else
|
82
|
-
transaction.
|
82
|
+
transaction.fail!(:NXDomain)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -100,7 +100,7 @@ class FortuneDNS < RExec::Daemon::Base
|
|
100
100
|
|
101
101
|
# Default DNS handler
|
102
102
|
otherwise do |transaction|
|
103
|
-
transaction.
|
103
|
+
transaction.fail!(:NXDomain)
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
data/test/examples/soa-dns.rb
CHANGED
@@ -103,13 +103,13 @@ class WikipediaDNS < RExec::Daemon::Base
|
|
103
103
|
end
|
104
104
|
|
105
105
|
http.errback do
|
106
|
-
transaction.
|
106
|
+
transaction.fail!(:ServFail)
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
110
|
# Default DNS handler
|
111
111
|
otherwise do |transaction|
|
112
|
-
transaction.
|
112
|
+
transaction.fail!(:NXDomain)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
data/test/test_daemon.rb
CHANGED
@@ -47,7 +47,7 @@ class BasicTestServer < RExec::Daemon::Base
|
|
47
47
|
|
48
48
|
# Default DNS handler
|
49
49
|
otherwise do |transaction|
|
50
|
-
transaction.
|
50
|
+
transaction.fail!(:NXDomain)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -68,7 +68,7 @@ class DaemonTest < Test::Unit::TestCase
|
|
68
68
|
assert_equal :running, RExec::Daemon::ProcessFile.status(BasicTestServer)
|
69
69
|
|
70
70
|
EventMachine.run do
|
71
|
-
resolver =
|
71
|
+
resolver = RubyDNS::Resolver.new(BasicTestServer::SERVER_PORTS)
|
72
72
|
|
73
73
|
resolver.query("test.local") do |response|
|
74
74
|
answer = response.answer.first
|
@@ -85,7 +85,7 @@ class DaemonTest < Test::Unit::TestCase
|
|
85
85
|
assert_equal :running, RExec::Daemon::ProcessFile.status(BasicTestServer)
|
86
86
|
|
87
87
|
EventMachine.run do
|
88
|
-
resolver =
|
88
|
+
resolver = RubyDNS::Resolver.new(BasicTestServer::SERVER_PORTS)
|
89
89
|
|
90
90
|
resolver.query("foobar") do |response|
|
91
91
|
answer = response.answer.first
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubydns'
|
2
|
+
|
3
|
+
class MessageTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
end
|
6
|
+
|
7
|
+
def teardown
|
8
|
+
end
|
9
|
+
|
10
|
+
def hex2bin(hexstring)
|
11
|
+
ret = "\x00" * (hexstring.length / 2)
|
12
|
+
ret.force_encoding("BINARY")
|
13
|
+
offset = 0
|
14
|
+
while offset < hexstring.length
|
15
|
+
hex_byte = hexstring[offset..(offset+1)]
|
16
|
+
ret.setbyte(offset/2, hex_byte.to_i(16))
|
17
|
+
offset += 2
|
18
|
+
end
|
19
|
+
ret
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_good_decode
|
23
|
+
data = hex2bin("1d008180000100080000000103777777057961686f6f03636f6d0000010001c00c000500010000012c000f0666642d667033037767310162c010c02b000500010000012c00090664732d667033c032c046000500010000003c00150e64732d616e792d6670332d6c666203776131c036c05b000500010000012c00120f64732d616e792d6670332d7265616cc06ac07c000100010000003c0004628afc1ec07c000100010000003c0004628bb495c07c000100010000003c0004628bb718c07c000100010000003c0004628afd6d0000291000000000000000")
|
24
|
+
|
25
|
+
decoded = RubyDNS.decode_message(data)
|
26
|
+
assert_equal(RubyDNS::Message, decoded.class)
|
27
|
+
assert_equal(0x1d00, decoded.id)
|
28
|
+
assert_equal(1, decoded.question.count)
|
29
|
+
assert_equal(8, decoded.answer.count)
|
30
|
+
assert_equal(0, decoded.authority.count)
|
31
|
+
assert_equal(1, decoded.additional.count)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_bad_AAAA_length
|
35
|
+
data = hex2bin("ea9e8180000100010000000108626169636169636e03636f6d00001c0001c00c001c00010000011e000432177b770000291000000000000000")
|
36
|
+
|
37
|
+
assert_raise(Resolv::DNS::DecodeError) do
|
38
|
+
RubyDNS.decode_message(data)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/test/test_passthrough.rb
CHANGED
@@ -49,19 +49,23 @@ class TestPassthroughServer < RExec::Daemon::Base
|
|
49
49
|
|
50
50
|
# Default DNS handler
|
51
51
|
otherwise do |transaction|
|
52
|
-
transaction.
|
52
|
+
transaction.fail!(:NXDomain)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
class PassthroughTest < Test::Unit::TestCase
|
59
|
+
# LOG_PATH = File.join(__dir__, "log/TestPassthroughServer.log")
|
60
|
+
|
59
61
|
def setup
|
62
|
+
# system("rm", LOG_PATH)
|
60
63
|
TestPassthroughServer.start
|
61
64
|
end
|
62
65
|
|
63
66
|
def teardown
|
64
67
|
TestPassthroughServer.stop
|
68
|
+
# system("cat", LOG_PATH)
|
65
69
|
end
|
66
70
|
|
67
71
|
def test_basic_dns
|
data/test/test_rules.rb
CHANGED
@@ -39,7 +39,7 @@ class RulesTest < Test::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_string_pattern
|
42
|
-
rule = RubyDNS::
|
42
|
+
rule = RubyDNS::RuleBasedServer::Rule.new(["foobar", IN::A], @true_callback)
|
43
43
|
|
44
44
|
assert rule.call(@server, "foobar", IN::A)
|
45
45
|
assert !rule.call(@server, "barfoo", IN::A)
|
@@ -47,7 +47,7 @@ class RulesTest < Test::Unit::TestCase
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_regexp_pattern
|
50
|
-
rule = RubyDNS::
|
50
|
+
rule = RubyDNS::RuleBasedServer::Rule.new([/foo/, IN::A], @true_callback)
|
51
51
|
|
52
52
|
assert rule.call(@server, "foobar", IN::A)
|
53
53
|
assert !rule.call(@server, "barbaz", IN::A)
|
@@ -64,7 +64,7 @@ class RulesTest < Test::Unit::TestCase
|
|
64
64
|
name.size == 6
|
65
65
|
end
|
66
66
|
|
67
|
-
rule = RubyDNS::
|
67
|
+
rule = RubyDNS::RuleBasedServer::Rule.new([callback], @true_callback)
|
68
68
|
|
69
69
|
assert rule.call(@server, "foobar", IN::A)
|
70
70
|
assert !rule.call(@server, "foobarbaz", IN::A)
|
data/test/test_slow_server.rb
CHANGED
@@ -38,16 +38,18 @@ class SlowServer < RExec::Daemon::Base
|
|
38
38
|
def self.run
|
39
39
|
RubyDNS::run_server(:listen => SERVER_PORTS) do
|
40
40
|
match(/\.*.com/, IN::A) do |transaction|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
defer do |fiber|
|
42
|
+
# No domain exists, after 2 seconds:
|
43
|
+
EventMachine::Timer.new(2) do
|
44
|
+
transaction.fail!(:NXDomain)
|
45
|
+
|
46
|
+
fiber.resume
|
47
|
+
end
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
49
51
|
otherwise do |transaction|
|
50
|
-
transaction.
|
52
|
+
transaction.fail!(:NXDomain)
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
data/test/test_truncation.rb
CHANGED
@@ -36,6 +36,8 @@ class TruncatedServer < RExec::Daemon::Base
|
|
36
36
|
IN = Resolv::DNS::Resource::IN
|
37
37
|
|
38
38
|
def self.run
|
39
|
+
# RubyDNS::log_bad_messages!("bad.log")
|
40
|
+
|
39
41
|
# Start the RubyDNS server
|
40
42
|
RubyDNS::run_server(:listen => SERVER_PORTS) do
|
41
43
|
match("truncation", IN::TXT) do |transaction|
|
@@ -45,7 +47,7 @@ class TruncatedServer < RExec::Daemon::Base
|
|
45
47
|
|
46
48
|
# Default DNS handler
|
47
49
|
otherwise do |transaction|
|
48
|
-
transaction.
|
50
|
+
transaction.fail!(:NXDomain)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
@@ -65,8 +67,6 @@ class TruncationTest < Test::Unit::TestCase
|
|
65
67
|
|
66
68
|
EventMachine::run do
|
67
69
|
resolver.query("truncation", IN::TXT) do |response|
|
68
|
-
|
69
|
-
|
70
70
|
text = response.answer.first
|
71
71
|
|
72
72
|
assert_equal "Hello World! " * 100, text[2].strings.join
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubydns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rexec
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.6.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.6.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: eventmachine
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -55,19 +55,17 @@ extra_rdoc_files: []
|
|
55
55
|
files:
|
56
56
|
- .gitignore
|
57
57
|
- .travis.yml
|
58
|
+
- .yardopts
|
58
59
|
- Gemfile
|
59
60
|
- README.md
|
60
61
|
- Rakefile
|
61
62
|
- bin/rd-dns-check
|
62
63
|
- bin/rd-resolve-test
|
63
64
|
- lib/rubydns.rb
|
65
|
+
- lib/rubydns/binary_string.rb
|
64
66
|
- lib/rubydns/chunked.rb
|
65
|
-
- lib/rubydns/extensions/hexdump.rb
|
66
67
|
- lib/rubydns/extensions/logger.rb
|
67
68
|
- lib/rubydns/extensions/resolv.rb
|
68
|
-
- lib/rubydns/extensions/string-1.8.rb
|
69
|
-
- lib/rubydns/extensions/string-1.9.2.rb
|
70
|
-
- lib/rubydns/extensions/string-1.9.3.rb
|
71
69
|
- lib/rubydns/extensions/string.rb
|
72
70
|
- lib/rubydns/handler.rb
|
73
71
|
- lib/rubydns/message.rb
|
@@ -88,6 +86,7 @@ files:
|
|
88
86
|
- test/hosts.txt
|
89
87
|
- test/test_daemon.rb
|
90
88
|
- test/test_domains.txt
|
89
|
+
- test/test_message.rb
|
91
90
|
- test/test_passthrough.rb
|
92
91
|
- test/test_resolver.rb
|
93
92
|
- test/test_rules.rb
|
@@ -114,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
113
|
version: '0'
|
115
114
|
requirements: []
|
116
115
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.0.
|
116
|
+
rubygems_version: 2.0.3
|
118
117
|
signing_key:
|
119
118
|
specification_version: 4
|
120
119
|
summary: An easy to use DNS server and resolver for Ruby.
|
@@ -130,9 +129,11 @@ test_files:
|
|
130
129
|
- test/hosts.txt
|
131
130
|
- test/test_daemon.rb
|
132
131
|
- test/test_domains.txt
|
132
|
+
- test/test_message.rb
|
133
133
|
- test/test_passthrough.rb
|
134
134
|
- test/test_resolver.rb
|
135
135
|
- test/test_rules.rb
|
136
136
|
- test/test_slow_server.rb
|
137
137
|
- test/test_system.rb
|
138
138
|
- test/test_truncation.rb
|
139
|
+
has_rdoc: yard
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'stringio'
|
22
|
-
|
23
|
-
class String
|
24
|
-
def hexdump
|
25
|
-
i = 1
|
26
|
-
out = StringIO.new
|
27
|
-
|
28
|
-
out.puts "Size: #{self.bytesize}"
|
29
|
-
while (self.length > 16*(i-1))
|
30
|
-
a = self.slice(16*(i-1)..(16*i)-1)
|
31
|
-
out.printf("%06x: %4.4x %4.4x %4.4x %4.4x %4.4x %4.4x %4.4x %4.4x ", (i-1)*16, *a.unpack("n16"))
|
32
|
-
out.printf("|%s|\n", a.tr("^\040-\176","."))
|
33
|
-
i += 1
|
34
|
-
end
|
35
|
-
|
36
|
-
return out.string
|
37
|
-
end
|
38
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'stringio'
|
22
|
-
|
23
|
-
class String
|
24
|
-
def bytesize
|
25
|
-
size
|
26
|
-
end
|
27
|
-
|
28
|
-
def byteslice(*args)
|
29
|
-
self[*args]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
module RubyDNS
|
34
|
-
BinaryStringIO = StringIO
|
35
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'stringio'
|
22
|
-
require 'rubydns/extensions/string-1.9.3'
|
23
|
-
|
24
|
-
class String
|
25
|
-
def byteslice(*args)
|
26
|
-
self.dup.force_encoding("BINARY").slice(*args)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|