Class Dnsruby::Config
In: lib/Dnsruby/Config.rb
Parent: Object
Message Update ResolvError EncodeError OtherResolvError ServFail FormErr DecodeError NXRRSet YXDomain NotImp NXDomain VerifyError NotAuth YXRRSet NotZone Refused TsigError CodeMapper Types MetaTypes QTypes Nsec3HashAlgorithms Algorithms OpCode Classes ExtendedRCode Modes RCode Comparable Name RRSet TsigNotSignedResponseError Resolver SingleResolver StandardError TimeoutError ResolvTimeout DNS Dnssec Hosts 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/DHCID.rb\nlib/Dnsruby/resource/DLV.rb\nlib/Dnsruby/resource/DNSKEY.rb\nlib/Dnsruby/resource/DS.rb\nlib/Dnsruby/resource/HINFO.rb\nlib/Dnsruby/resource/HIP.rb\nlib/Dnsruby/resource/IN.rb\nlib/Dnsruby/resource/IPSECKEY.rb\nlib/Dnsruby/resource/ISDN.rb\nlib/Dnsruby/resource/KX.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/SSHFP.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] Recursor IPv6 IPv4 ZoneTransfer MessageDecoder MessageEncoder Question Header TheLog ValidatorThread PacketSender ResolverRuby Config KeyCache Cache SingleVerifier SelectThread Resolv ZoneReader lib/Dnsruby/DNS.rb lib/Dnsruby/dnssec.rb lib/Dnsruby/Hosts.rb lib/Dnsruby/resource/PX.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/select_thread.rb lib/Dnsruby/name.rb lib/dnsruby.rb lib/Dnsruby/resource/TKEY.rb lib/Dnsruby/zone_reader.rb Dnsruby dot/m_61_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 399
399:     def domain
400:       if (!@configured)
401:         parse_config
402:       end
403:       if (@domain==nil)
404:         return nil
405:       end
406:       return Name.create(@domain).to_s
407:     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 417
417:     def get_ready
418:       if (!@configured)
419:         parse_config
420:       end
421:     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 387
387:     def search
388:       if (!@configured)
389:         parse_config
390:       end
391:       search = []
392:       @search.each do |s|
393:         search.push(Name.new(s).to_s)
394:       end
395:       return search
396:     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 344
344:     def to_s
345:       if (!@configured)
346:         parse_config
347:       end
348:       ret = "Config - nameservers : "
349:       @nameserver.each {|n| ret += n.to_s + ", "}
350:       domain_string="empty"
351:       if (@domain!=nil)
352:         domain_string=@domain.to_s
353:       end
354:       ret += " domain : #{domain_string}, search : "
355:       search.each {|s| ret += s + ", " }
356:       ret += " ndots : #{@ndots}"
357:       return ret
358:     end

[Validate]