dnstraverse 0.1.11 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -127,10 +127,12 @@ module DNSTraverse
127
127
  @cacheable_good, @cacheable_bad = msg_cacheable(@message, @bailiwick)
128
128
  @endname = msg_follow_cnames(@message, :qname => @qname, :qtype => @qtype,
129
129
  :bailiwick => @bailiwick)
130
- return process_restart unless inside_bailiwick?(@endname)
130
+ return process_cname_loop if @endname.nil?
131
+ ## return process_restart unless inside_bailiwick?(@endname)
131
132
  return process_error if @message.rcode != NOERROR
132
133
  @answers = msg_answers?(@message, :qname => @endname, :qtype => qtype)
133
134
  return process_answered if @answers
135
+ return process_restart if @endname != @qname
134
136
  return process_nodata if @auth_soa.size > 0 or @auth_ns.size == 0
135
137
  return process_referral unless @auth_ns.empty?
136
138
  return process_restart
@@ -141,6 +143,10 @@ module DNSTraverse
141
143
  @exception_message = @message.to_s
142
144
  end
143
145
 
146
+ def process_cname_loop
147
+ @status = :cname_loop
148
+ end
149
+
144
150
  def process_restart
145
151
  @status = :restart
146
152
  end
@@ -181,17 +187,19 @@ module DNSTraverse
181
187
 
182
188
  def to_s
183
189
  case @status
184
- when :error
190
+ when :error
185
191
  return "Error: #{@error_message}"
186
- when :exception
192
+ when :exception
187
193
  return "Exception: #{@exception_message}"
188
- when :nodata
194
+ when :cname_loop
195
+ return "CNANE loop"
196
+ when :nodata
189
197
  return "No data"
190
- when :answered
198
+ when :answered
191
199
  return "Answered (#{@answers.size} entries)"
192
- when :referral
200
+ when :referral
193
201
  return "Referral to #{@authoritynames.join(',')}"
194
- when :restart
202
+ when :restart
195
203
  return "Query re-start with #{@endname}"
196
204
  end
197
205
  end
@@ -144,23 +144,31 @@ module DNSTraverse
144
144
  return ns, soa, other
145
145
  end
146
146
 
147
+ # follow any CNAMEs in the message and return the final name
148
+ # return nil if there is a loop
147
149
  def msg_follow_cnames(msg, args)
148
150
  name = args[:qname]
149
151
  type = args[:qtype]
150
152
  bw = args[:bailiwick].to_s
151
153
  bwend = ".#{args[:bailiwick]}"
154
+ seen = {}
152
155
  while true do
156
+ seen[name] = true
153
157
  return name if msg_answers?(msg, :qname => name, :qtype => type)
154
158
  if not ans = msg_answers?(msg, :qname => name, :qtype => 'CNAME') then
155
159
  return name
156
160
  end
157
161
  target = ans[0].domainname.to_s
158
162
  Log.debug { "CNAME encountered from #{name} to #{target}"}
159
- if bw and (target.casecmp(bw) != 0 and name !~ /#{bwend}$/i) then
163
+ if name !~ /#{bwend}$/i then
160
164
  # target outside of bailiwick, don't follow any more CNAMEs.
161
165
  return target
162
166
  end
163
167
  name = target
168
+ if seen[name] then
169
+ Log.debug { "CNAME loop detected" }
170
+ return nil
171
+ end
164
172
  end
165
173
  end
166
174
 
@@ -506,7 +506,9 @@ module DNSTraverse
506
506
  puts "Lame referral from #{referral.parent.server} " +
507
507
  "(#{referral.parent_ip}) to #{where}"
508
508
  when :loop
509
- puts "Loop encountered at #{response.server} "
509
+ puts "Loop encountered at #{response.server}"
510
+ when :cname_loop
511
+ puts "CNAME loop encountered at #{response.server}"
510
512
  when :error
511
513
  puts "#{response.error_message} at #{where}"
512
514
  when :nodata
@@ -95,6 +95,8 @@ module DNSTraverse
95
95
  o << "#{prefix}#{txt_prob sinfo[:prob]} found no glue"
96
96
  when :loop
97
97
  o << "#{prefix}#{txt_prob sinfo[:prob]} resulted in a loop"
98
+ when :cname_loop
99
+ o << "#{prefix}#{txt_prob sinfo[:prob]} resulted in a CNAME loop"
98
100
  else
99
101
  o << "#{prefix}#{txt_prob sinfo[:prob]} #{type}"
100
102
  end
@@ -2,7 +2,7 @@ module DNSTraverse
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 11
5
+ PATCH = 13
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnstraverse
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 11
10
- version: 0.1.11
9
+ - 13
10
+ version: 0.1.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Ponder
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-27 00:00:00 +01:00
18
+ date: 2011-12-17 00:00:00 +00:00
19
19
  default_executable: dnstraverse
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency