Class | Dnsruby::Config |
In: |
lib/Dnsruby/Config.rb
|
Parent: | Object |
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 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.
Reset the config to default values
# File lib/Dnsruby/Config.rb, line 90 90: def Config.reset 91: c = Config.new 92: @configured = false 93: # c.parse_config 94: end
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.
# 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
Set the default domain
# 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
# 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
# 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
# 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
# File lib/Dnsruby/Config.rb, line 60 60: def ndots 61: if (!@configured) 62: parse_config 63: end 64: return @ndots 65: end
Set the default search path
# 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 :
e.g. /etc/resolv.conf
nameserver (String) domain (String) search (String) ndots (Fixnum)
This method should not normally be called by client code.
# File lib/Dnsruby/Config.rb, line 79 79: def set_config_info(config_info) 80: parse_config(config_info) 81: end
# 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