Class Dnsruby::Config
In: lib/Dnsruby/Config.rb
Parent: Object
ResolvError EncodeError OtherResolvError ServFail FormErr DecodeError NXRRSet YXDomain NotImp NXDomain VerifyError NotAuth YXRRSet NotZone Refused TsigError Message Update CodeMapper Types MetaTypes QTypes Nsec3HashAlgorithms Algorithms OpCode Classes ExtendedRCode RCode Modes Comparable Name RRSet Resolver SingleResolver StandardError TimeoutError ResolvTimeout DNS Dnssec Hosts SelectThread\n[lib/Dnsruby/select_thread.rb\nlib/Dnsruby/select_thread.rb.michael.rb] Recursor IPv6 IPv4 ZoneTransfer MessageDecoder MessageEncoder Question Header TheLog RR\n[lib/Dnsruby/resource/A.rb\nlib/Dnsruby/resource/AAAA.rb\nlib/Dnsruby/resource/AFSDB.rb\nlib/Dnsruby/resource/CERT.rb\nlib/Dnsruby/resource/DLV.rb\nlib/Dnsruby/resource/DNSKEY.rb\nlib/Dnsruby/resource/DS.rb\nlib/Dnsruby/resource/HINFO.rb\nlib/Dnsruby/resource/IN.rb\nlib/Dnsruby/resource/ISDN.rb\nlib/Dnsruby/resource/LOC.rb\nlib/Dnsruby/resource/MINFO.rb\nlib/Dnsruby/resource/MX.rb\nlib/Dnsruby/resource/NAPTR.rb\nlib/Dnsruby/resource/NSAP.rb\nlib/Dnsruby/resource/NSEC.rb\nlib/Dnsruby/resource/NSEC3.rb\nlib/Dnsruby/resource/NSEC3PARAM.rb\nlib/Dnsruby/resource/OPT.rb\nlib/Dnsruby/resource/PX.rb\nlib/Dnsruby/resource/RP.rb\nlib/Dnsruby/resource/RRSIG.rb\nlib/Dnsruby/resource/RT.rb\nlib/Dnsruby/resource/SOA.rb\nlib/Dnsruby/resource/SPF.rb\nlib/Dnsruby/resource/SRV.rb\nlib/Dnsruby/resource/TKEY.rb\nlib/Dnsruby/resource/TSIG.rb\nlib/Dnsruby/resource/TXT.rb\nlib/Dnsruby/resource/X25.rb\nlib/Dnsruby/resource/domain_name.rb\nlib/Dnsruby/resource/generic.rb\nlib/Dnsruby/resource/resource.rb] ValidatorThread PacketSender ResolverRuby Config KeyCache Cache SingleVerifier Resolv Iana lib/Dnsruby/DNS.rb lib/Dnsruby/dnssec.rb lib/Dnsruby/Hosts.rb lib/Dnsruby/select_thread.rb.michael.rb lib/Dnsruby/Recursor.rb lib/Dnsruby/update.rb lib/Dnsruby/ipv6.rb lib/Dnsruby/ipv4.rb lib/Dnsruby/code_mapper.rb lib/Dnsruby/zone_transfer.rb lib/Dnsruby/message.rb lib/Dnsruby/TheLog.rb lib/Dnsruby/resource/resource.rb lib/Dnsruby/validator_thread.rb lib/Dnsruby/PacketSender.rb lib/Dnsruby/Resolver.rb lib/Dnsruby/Config.rb lib/Dnsruby/key_cache.rb lib/Dnsruby/Cache.rb lib/Dnsruby/single_verifier.rb lib/Dnsruby/SingleResolver.rb lib/Dnsruby/name.rb lib/dnsruby.rb lib/Dnsruby/resource/TKEY.rb lib/Dnsruby/iana_ports.rb Dnsruby dot/m_56_0.png

Description

 The Config class determines the system configuration for DNS.
 In particular, it determines the nameserver to target queries to.

 It also specifies whether and how the search list and default
 domain should be applied to queries, according to the following
 algorithm :
  • If the name is absolute, then it is used as is.
  • If the name is not absolute, then :
       If apply_domain is true, and ndots is greater than the number
       of labels in the name, then the default domain is added to the name.
    
       If apply_search_list is true, then each member of the search list
       is appended to the name.
    
     The Config class has now been modified for lazy loading. Previously, the config
     was loaded when a Resolver was instantiated. Now, the config is only loaded if
     a query is performed (or a config parameter requested on) a Resolver which has
     not yet been configured.
    

Methods

Attributes

apply_domain  [RW]  Should the default domain be applied?
apply_search_list  [RW]  Should the search list be applied?

Public Class methods

Create a new Config with system default values

[Source]

    # File lib/Dnsruby/Config.rb, line 84
84:     def initialize()
85:       @mutex = Mutex.new
86:       @configured = false
87:       #      parse_config

88:     end

Reset the config to default values

[Source]

    # File lib/Dnsruby/Config.rb, line 90
90:     def Config.reset
91:       c = Config.new
92:       @configured = false
93:       #      c.parse_config

94:     end

Public Instance methods

Add a nameserver to the list of nameservers.

Can take either a single String or an array of Strings. The new nameservers are added at a higher priority.

[Source]

     # File lib/Dnsruby/Config.rb, line 217
217:     def add_nameserver(ns)
218:       @configured = true
219:       if (ns.kind_of?String) 
220:         ns=[ns]
221:       end
222:       check_ns(ns)
223:       ns.reverse_each do |n|
224:         if (!@nameserver.include?(n))
225:           self.nameserver=[n]+@nameserver
226:         end
227:       end
228:     end

Return the default domain

[Source]

     # File lib/Dnsruby/Config.rb, line 371
371:     def domain
372:       if (!@configured)
373:         parse_config
374:       end
375:       if (@domain==nil)
376:         return nil
377:       end
378:       return Name.create(@domain).to_s
379:     end

Set the default domain

[Source]

     # File lib/Dnsruby/Config.rb, line 141
141:     def domain=(dom)
142:       #      @configured = true

143:       if (dom)
144:         if !dom.kind_of?(String)
145:           raise ArgumentError.new("invalid domain config: #{@domain.inspect}")
146:         end
147:         @domain = Name::split(dom)
148:       else
149:         @domain=nil
150:       end
151:     end

[Source]

     # File lib/Dnsruby/Config.rb, line 389
389:     def get_ready
390:       if (!@configured)
391:         parse_config
392:       end
393:     end

The list of nameservers to query

[Source]

    # File lib/Dnsruby/Config.rb, line 49
49:     def nameserver
50:       if (!@configured)
51:         parse_config
52:       end
53:       return @nameserver
54:     end

Set the config to point to a single nameserver

[Source]

     # File lib/Dnsruby/Config.rb, line 231
231:     def nameserver=(ns)
232:       @configured = true
233:       check_ns(ns)
234:       #      @nameserver = ['0.0.0.0'] if (@nameserver.class != Array || @nameserver.empty?)

235:       # Now go through and ensure that all ns point to IP addresses, not domain names

236:       @nameserver=ns
237:       Dnsruby.log.debug{'Nameservers = #{@nameserver.join(", ")}'}
238:     end

The minimum number of labels in the query name (if it is not absolute) before it is considered complete

[Source]

    # File lib/Dnsruby/Config.rb, line 60
60:     def ndots
61:       if (!@configured)
62:         parse_config
63:       end
64:       return @ndots
65:     end

Set ndots

[Source]

     # File lib/Dnsruby/Config.rb, line 154
154:     def ndots=(nd)
155:       @configured = true
156:       @ndots=nd
157:       if !@ndots.kind_of?(Integer)
158:         raise ArgumentError.new("invalid ndots config: #{@ndots.inspect}")
159:       end
160:     end

Return the search path

[Source]

     # File lib/Dnsruby/Config.rb, line 359
359:     def search
360:       if (!@configured)
361:         parse_config
362:       end
363:       search = []
364:       @search.each do |s|
365:         search.push(Name.new(s).to_s)
366:       end
367:       return search
368:     end

Set the default search path

[Source]

     # File lib/Dnsruby/Config.rb, line 163
163:     def search=(s)
164:       @configured = true
165:       @search=s
166:       if @search
167:         if @search.class == Array
168:           @search = @search.map {|arg| Name::split(arg) }
169:         else
170:           raise ArgumentError.new("invalid search config: search must be an array!")
171:         end
172:       else
173:         hostname = Socket.gethostname
174:         if /\./ =~ hostname
175:           @search = [Name.split($')]
176:         else
177:           @search = [[]]
178:         end
179:       end
180:       
181:       if !@search.kind_of?(Array) ||
182:           #              !@search.all? {|ls| ls.all? {|l| Label::Str === l } }

183:         !@search.all? {|ls| ls.all? {|l| Name::Label === l } }
184:         raise ArgumentError.new("invalid search config: #{@search.inspect}")
185:       end
186:     end

Set the config. Parameter can be :

  • A String containing the name of the config file to load
         e.g. /etc/resolv.conf
    
  • A hash with the following elements :
         nameserver (String)
         domain (String)
         search (String)
         ndots (Fixnum)
    

This method should not normally be called by client code.

[Source]

    # File lib/Dnsruby/Config.rb, line 79
79:     def set_config_info(config_info)
80:       parse_config(config_info)
81:     end

[Source]

     # File lib/Dnsruby/Config.rb, line 316
316:     def to_s
317:       if (!@configured)
318:         parse_config
319:       end
320:       ret = "Config - nameservers : "
321:       @nameserver.each {|n| ret += n.to_s + ", "}
322:       domain_string="empty"
323:       if (@domain!=nil)
324:         domain_string=@domain.to_s
325:       end
326:       ret += " domain : #{domain_string}, search : "
327:       search.each {|s| ret += s + ", " }
328:       ret += " ndots : #{@ndots}"
329:       return ret
330:     end

[Validate]