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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f528114ee7c5a3f7d408fc8145be9aca563faaa8
4
- data.tar.gz: 46f90187b9565856cbef718c8401f813c1a90081
3
+ metadata.gz: bc8be979621a0fc5e52dfbe6c57f73cb77aaec42
4
+ data.tar.gz: b4dc717ee6ecd5ab0b87367874b630869e942fb5
5
5
  SHA512:
6
- metadata.gz: a95763e1b6bb77707524d45c8aa7c890ba81e1cdf061a1fba7969004eda42f4b7b8dee8bc573af1a65fca2314f1ef6e05994f7328838d62e044278d2250e0382
7
- data.tar.gz: 1760effc82e9636e220b58f9c2fd041d7a80808b351859c2d7edd40edaa00d218eb8ea18a9eaa5284944181f8b3f616b5a5d32dd52df99606df28764b9ca7c1f
6
+ metadata.gz: 5e8048cc9ee4cfb43414b2bf89d7a7dea2f7457b1cd3b0d90baa8600bdc237c36bcd4809b0a7ca00f6788483143e2f8afcabd9c4661d47d6c11c35c7bc20b8f9
7
+ data.tar.gz: 186601a91301576e1d40b091f0af0529d17e1d01104ca7be3801f242b933ba9bb9d2684310c5866e23f6c35bd9d37854436fb1a9b33ba882d669f328d3662efc
@@ -1,7 +1,8 @@
1
1
 
2
2
  module DnsOne; class Server # < RExec::Daemon::Base
3
3
 
4
- DNS_DAEMON_RUN_AS = "dnsserver"
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' and conf[:run_as]
22
- RExec.change_user conf[:run_as]
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
- answer, other_records = ZoneSearch.instance.query domain_name, t.resource_class
30
- if answer or other_records
31
- t.respond! *answer if answer
32
- other_records.each do |rec|
33
- t.add rec.obj, {section: rec.section}
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
@@ -26,4 +26,8 @@ module DnsOne; class Util; class << self
26
26
  stat.uid == 0 && stat.gid == 0
27
27
  end
28
28
 
29
+ def last_mod constant
30
+ constant.to_s.split('::').last
31
+ end
32
+
29
33
  end; end; end
@@ -1,3 +1,3 @@
1
1
  module DnsOne
2
- VERSION = "0.4.8"
2
+ VERSION = "0.4.10"
3
3
  end
@@ -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
- Log.d "searching #{ dom_name }..."
28
+ records = []
27
29
 
28
30
  rec_set_name = find_record_set dom_name
29
- Log.d "record set name #{ rec_set_name ? 'found' : 'not found' } for #{dom_name} #{res_class}"
30
- rec_set_name or return
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
- rec_set_name = @conf[:ecord_sets].keys.first.to_s
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} #{res_class}"
38
- rec_set or return
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
- answer = nil
41
+ # TODO: move parsing logic to own class
41
42
 
42
- unless res_class == IN::NS
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
- other_records = []
45
+ # Loop over 1 or more
46
+ recs = [recs]
47
+ recs.flatten! unless res_class == IN::SOA
50
48
 
51
- # NS
52
- ns_list = rec_set[:NS].map{|ns| IN::NS.new(Name.create ns)}
53
- ns_section = res_class == IN::NS ? :answer : :authority
54
- other_records << OpenStruct.new(obj: ns_list, section: ns_section)
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
- [answer, other_records]
61
+ records
57
62
  end
58
63
 
59
64
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns_one
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lobato