dns_one 0.4.8 → 0.4.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dns_one/server.rb +16 -8
- data/lib/dns_one/util.rb +4 -0
- data/lib/dns_one/version.rb +1 -1
- data/lib/dns_one/zone_search.rb +27 -22
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc8be979621a0fc5e52dfbe6c57f73cb77aaec42
|
4
|
+
data.tar.gz: b4dc717ee6ecd5ab0b87367874b630869e942fb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e8048cc9ee4cfb43414b2bf89d7a7dea2f7457b1cd3b0d90baa8600bdc237c36bcd4809b0a7ca00f6788483143e2f8afcabd9c4661d47d6c11c35c7bc20b8f9
|
7
|
+
data.tar.gz: 186601a91301576e1d40b091f0af0529d17e1d01104ca7be3801f242b933ba9bb9d2684310c5866e23f6c35bd9d37854436fb1a9b33ba882d669f328d3662efc
|
data/lib/dns_one/server.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
|
2
2
|
module DnsOne; class Server # < RExec::Daemon::Base
|
3
3
|
|
4
|
-
|
4
|
+
DEFAULT_RUN_AS = "dnsone"
|
5
|
+
|
5
6
|
DNS_DAEMON_INTERFACES = [
|
6
7
|
[:udp, "0.0.0.0", 53],
|
7
8
|
[:tcp, "0.0.0.0", 53],
|
@@ -18,19 +19,26 @@ module DnsOne; class Server # < RExec::Daemon::Base
|
|
18
19
|
conf = @conf
|
19
20
|
RubyDNS::run_server(listen: dns_daemon_interfaces, logger: Log.logger) do
|
20
21
|
on(:start) do
|
21
|
-
if RExec.current_user == 'root'
|
22
|
-
|
22
|
+
if RExec.current_user == 'root'
|
23
|
+
run_as = conf[:run_as] || DEFAULT_RUN_AS
|
24
|
+
RExec.change_user run_as
|
23
25
|
end
|
24
26
|
Log.i "Running as #{RExec.current_user}"
|
25
27
|
end
|
26
28
|
|
27
29
|
match(/(.+)/) do |t| # transaction
|
28
30
|
domain_name = t.question.to_s
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
ip_address = t.options[:peer] rescue nil
|
32
|
+
|
33
|
+
records = ZoneSearch.instance.query domain_name, t.resource_class, ip_address
|
34
|
+
|
35
|
+
if records
|
36
|
+
if records.empty?
|
37
|
+
t.fail! :NoError
|
38
|
+
else
|
39
|
+
records.each do |rec|
|
40
|
+
t.respond! *[rec.val].flatten, {resource_class: rec.res_class, section: rec.section}
|
41
|
+
end
|
34
42
|
end
|
35
43
|
else
|
36
44
|
t.fail! :NXDomain
|
data/lib/dns_one/util.rb
CHANGED
data/lib/dns_one/version.rb
CHANGED
data/lib/dns_one/zone_search.rb
CHANGED
@@ -20,40 +20,45 @@ module DnsOne; class ZoneSearch
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def query dom_name, res_class
|
23
|
+
def query dom_name, res_class, ip_address
|
24
24
|
dom_name = dom_name.dup
|
25
|
+
res_class_short = Util.last_mod res_class # :A, :NS, found in conf.yml:record_sets items
|
26
|
+
Log.d "request #{ dom_name }/#{res_class_short} from #{ip_address}..."
|
25
27
|
|
26
|
-
|
28
|
+
records = []
|
27
29
|
|
28
30
|
rec_set_name = find_record_set dom_name
|
29
|
-
Log.d "
|
30
|
-
|
31
|
+
Log.d "domain #{ rec_set_name ? 'found' : 'not found' } for #{dom_name}/#{res_class_short}"
|
32
|
+
return unless rec_set_name
|
31
33
|
|
32
|
-
if rec_set_name == ''
|
33
|
-
|
34
|
-
end
|
34
|
+
# use first record set if rec_set_name == ''
|
35
|
+
rec_set_name = @conf[:record_sets].keys.first if rec_set_name == ''
|
35
36
|
|
36
37
|
rec_set = @conf[:record_sets][rec_set_name.to_sym]
|
37
|
-
Log.d "record set #{ rec_set ? 'found' : 'not found' } for #{dom_name}
|
38
|
-
|
38
|
+
Log.d "record set #{ rec_set ? 'found' : 'not found' } for #{dom_name}/#{res_class_short}"
|
39
|
+
return records unless rec_set
|
39
40
|
|
40
|
-
|
41
|
+
# TODO: move parsing logic to own class
|
41
42
|
|
42
|
-
|
43
|
-
if rec = rec_set[ res_class.to_s.split('::').last.to_sym ]
|
44
|
-
answer = rec
|
45
|
-
answer = [answer] unless answer.is_a? Array
|
46
|
-
end
|
47
|
-
end
|
43
|
+
recs = rec_set[res_class_short.to_sym]
|
48
44
|
|
49
|
-
|
45
|
+
# Loop over 1 or more
|
46
|
+
recs = [recs]
|
47
|
+
recs.flatten! unless res_class == IN::SOA
|
50
48
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
recs.compact.each do |val_raw|
|
50
|
+
val = if res_class == IN::NS
|
51
|
+
Name.create val_raw
|
52
|
+
elsif res_class == IN::SOA
|
53
|
+
[0, 1].each{|i| val_raw[i] = Name.create val_raw[i] }
|
54
|
+
val_raw
|
55
|
+
else
|
56
|
+
val_raw
|
57
|
+
end
|
58
|
+
records << OpenStruct.new(val: val, res_class: res_class, section: 'answer')
|
59
|
+
end
|
55
60
|
|
56
|
-
|
61
|
+
records
|
57
62
|
end
|
58
63
|
|
59
64
|
private
|