This class reads a zone file, and transforms it to a form suitable to be sorted by the OS sort command. For purposes of sorting, each RR should be prepended by the reversed domain name, followed by a separator (each label of the name is preserved
- the labels are simply written in reverse order)
This allows the auditor to operate on a zone file which is essentially in canonical order.
# File ../../auditor/lib/kasp_auditor/preparser.rb, line 50 def initialize(config, log) @config = config @line_num = 0 @log = log origin = config.name soa_minimum = config.soa ? config.soa.minimum : nil soa_ttl = config.soa ? config.soa.ttl : nil @zone_reader = Dnsruby::ZoneReader.new(origin, soa_minimum, soa_ttl) end
Take an input zone file ("zonefile") and output a new file ("zonefile.sorted") The output file has each (expanded) line prepended by the labels of the owner name for the RR in reversed order. The type is also prepended to the line - this allows RRSets to be ordered with the RRSIG and NSEC records last.
# File ../../auditor/lib/kasp_auditor/preparser.rb, line 65 def normalise_zone_and_add_prepended_names(infile, outfile) # Need to replace any existing files infile = (infile.to_s+"").untaint outfile = (outfile.to_s+"").untaint if File.exist?(outfile) File.delete(outfile) end @line_num = 0 begin File.open(outfile, File::CREAT|File::RDWR) { |f| begin IO.foreach(infile) { |line| ret = process_line(line) next if !ret if (ret) new_line, type, last_name = ret # Append the domain name and the RR Type here - e.g. "$NS" line_to_write = prepare(last_name) + NAME_SEPARATOR + type.to_s + SORT_SEPARATOR + new_line f.write(line_to_write) end } rescue Exception => e KASPAuditor.exit("ERROR - Can't open zone file : #{infile.inspect} : #{e}", 1, @log) end } rescue Exception => e KASPAuditor.exit("ERROR - Can't open temporary output file : #{outfile.inspect} : #{e}", 1, @log) end end
Take a domain name, and return the form to be prepended to the RR.
# File ../../auditor/lib/kasp_auditor/preparser.rb, line 108 def prepare(domain) # Check if the name contains any escape characters ("\") - If not, then just reverse elements. # If it does contain escape characters, then parse it as a proper name. labels = domain.split(".") if (domain.index("\\")) name = Name.create(domain) labels = name.labels end # Simply reverse each label return labels.reverse!.join(LABEL_SEPARATOR).downcase end
Generated with the Darkfish Rdoc Generator 2.