Changeset 1026

Show
Ignore:
Timestamp:
04/12/07 22:50:53 (2 years ago)
Author:
ahu
Message:

fix escaped dots! Plus close debian bug 406462, 'm' stands for minutes, not months. Plus improve bindbackend query-logging

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pdns/pdns/backends/bind/bindbackend2.cc

    r1018 r1026  
    323323void Bind2Backend::insert(shared_ptr<State> stage, int id, const string &qnameu, const QType &qtype, const string &content, int ttl=300, int prio=25) 
    324324{ 
    325   // XXXX WRONG WRONG WRONG REWRITE 
    326  
    327325  BB2DomainInfo bb2 = stage->id_zone_map[id]; 
    328326  Bind2DNSRecord bdr; 
     
    761759    d_handle.qname=qname.substr(0,qname.size()-domain.length()-1); // strip domain name 
    762760 
    763   d_handle.parent=this; 
    764761  d_handle.qtype=qtype; 
    765762  d_handle.domain=qname.substr(qname.size()-domain.length()); 
     
    777774  } 
    778775 
    779   d_handle.d_records = state->id_zone_map[iditer->second].d_records; // give it a copy 
     776  d_handle.d_records = state->id_zone_map[iditer->second].d_records; // give it a reference counted copy 
    780777   
    781778  if(d_handle.d_records->empty()) 
    782779    DLOG(L<<"Query with no results"<<endl); 
    783    
     780 
    784781  pair<vector<Bind2DNSRecord>::const_iterator, vector<Bind2DNSRecord>::const_iterator> range; 
    785782 
     
    796793    d_handle.d_iter=range.first; 
    797794    d_handle.d_end_iter=range.second; 
     795    d_handle.mustlog = mustlog; 
     796 
    798797  } 
    799798 
     
    803802Bind2Backend::handle::handle() 
    804803{ 
    805   //  d_records=0; 
    806   count=0; 
     804  mustlog=false; 
    807805} 
    808806 
     
    859857  r.priority=(d_iter)->priority; 
    860858  d_iter++; 
     859  if(mustlog) 
     860    L<<Logger::Warning<<"Returning: "<< r.qtype.getName()<<" "<<r.content<<endl; 
     861 
    861862 
    862863  return true; 
     
    876877  d_handle.d_qname_end=d_handle.d_records->end();   // iter now points to a vector of pointers to vector<BBResourceRecords> 
    877878 
    878   d_handle.parent=this; 
    879879  d_handle.id=id; 
    880880  d_handle.d_list=true; 
  • trunk/pdns/pdns/backends/bind/bindbackend2.hh

    r1018 r1026  
    139139    void reset() 
    140140    { 
    141       parent=0; 
    142141      d_records.reset(); 
    143142      qname.clear(); 
    144  
     143      mustlog=false; 
    145144    } 
    146145 
    147146    handle(); 
    148  
    149     Bind2Backend *parent; 
    150147 
    151148    shared_ptr<vector<Bind2DNSRecord> > d_records; 
     
    161158    string domain; 
    162159    QType qtype; 
     160    bool mustlog; 
     161 
    163162  private: 
    164     int count; 
    165      
    166163    bool get_normal(DNSResourceRecord &); 
    167164    bool get_list(DNSResourceRecord &); 
  • trunk/pdns/pdns/dnsparser.cc

    r996 r1026  
    406406    unsigned char labellen=content.at(frompos++); 
    407407 
    408     //    cerr<<"ret: '"<<ret<<"', Labellen: "<<(int)labellen<<endl; 
    409408    if(!labellen) { 
    410409      if(ret.empty()) 
     
    418417    } 
    419418    else { 
    420       // should check for . here and replace by \. 
    421       ret.append(&content.at(frompos), &content.at(frompos+labellen)); 
     419      // XXX FIXME THIS MIGHT BE VERY SLOW! 
     420      ret.reserve(ret.size() + labellen + 2); 
     421      for(string::size_type n = 0 ; n < labellen; ++n, frompos++) { 
     422        if(content.at(frompos)=='.') 
     423          ret.append(1, '\\'); 
     424        ret.append(1, content[frompos]); 
     425      } 
    422426      ret.append(1,'.'); 
    423       frompos+=labellen; 
    424427    } 
    425428  } 
  • trunk/pdns/pdns/dnswriter.cc

    r996 r1026  
    33#include "dnsparser.hh" 
    44#include <boost/tokenizer.hpp> 
     5#include <boost/algorithm/string.hpp> 
    56 
    67DNSPacketWriter::DNSPacketWriter(vector<uint8_t>& content, const string& qname, uint16_t  qtype, uint16_t qclass, uint8_t opcode) 
     
    144145} 
    145146 
     147typedef vector<pair<string::size_type, string::size_type> > parts_t; 
     148 
     149bool labeltokUnescape(parts_t& parts, const string& label) 
     150{ 
     151  string::size_type epos = label.size(), lpos(0), pos; 
     152  bool unescapedSomething = false; 
     153  const char* ptr=label.c_str(); 
     154 
     155  parts.clear(); 
     156 
     157  for(pos = 0 ; pos < epos; ++pos) { 
     158    if(ptr[pos]=='\\') { 
     159      pos++; 
     160      unescapedSomething = true; 
     161      continue; 
     162    } 
     163    if(ptr[pos]=='.') { 
     164      parts.push_back(make_pair(lpos, pos)); 
     165      lpos=pos+1; 
     166    } 
     167  } 
     168   
     169  if(lpos < pos) 
     170    parts.push_back(make_pair(lpos, pos)); 
     171  return unescapedSomething; 
     172} 
     173 
    146174// this is the absolute hottest function in the pdns recursor  
    147175void DNSPacketWriter::xfrLabel(const string& label, bool compress) 
    148176{ 
    149   typedef vector<pair<unsigned int, unsigned int> > parts_t; 
    150177  parts_t parts; 
    151   vstringtok(parts, label, "."); // XXX FIXME this should deal with escaped . 
     178  bool unescaped=labeltokUnescape(parts, label);  
    152179   
    153180  // d_stuff is amount of stuff that is yet to be written out - the dnsrecordheader for example 
    154181  unsigned int pos=d_content.size() + d_record.size() + d_stuff;  
    155   string chopped(label); 
    156  
     182  string chopped; 
    157183  for(parts_t::const_iterator i=parts.begin(); i!=parts.end(); ++i) { 
    158     //    cerr<<"chopped: '"<<chopped<<"'\n"
     184    chopped.assign(label.c_str() + i->first)
    159185    lmap_t::iterator li=d_labelmap.end(); 
    160186    // see if we've written out this domain before 
     
    170196      d_labelmap.push_back(make_pair(chopped, pos));                       //  if untrue, we need to count - also, don't store offsets > 16384, won't work 
    171197 
    172     d_record.push_back((char)(i->second - i->first)); 
    173     unsigned int len=d_record.size(); 
    174     d_record.resize(len + i->second - i->first); 
    175     memcpy(((&*d_record.begin()) + len), label.c_str() + i-> first, i->second - i->first); 
    176     //    cerr<<"Added: '"<<string(label.c_str() + i->first, i->second - i->first) <<"'\n"; 
    177     pos+=(i->second - i->first)+1; 
    178  
    179     if(i+1 != parts.end()) 
    180       chopOff(chopped);                   // www.powerdns.com. -> powerdns.com. -> com. -> . 
     198    if(unescaped) { 
     199      string part(label.c_str() + i -> first, i->second - i->first); 
     200      replace_all(part, "\\.", "."); 
     201      d_record.push_back(part.size()); 
     202      unsigned int len=d_record.size(); 
     203      d_record.resize(len + part.size()); 
     204 
     205      memcpy(((&*d_record.begin()) + len), part.c_str(), part.size()); 
     206      pos+=(part.size())+1;                       
     207    } 
     208    else { 
     209      d_record.push_back((char)(i->second - i->first)); 
     210      unsigned int len=d_record.size(); 
     211      d_record.resize(len + i->second - i->first); 
     212      memcpy(((&*d_record.begin()) + len), label.c_str() + i-> first, i->second - i->first); 
     213      pos+=(i->second - i->first)+1; 
     214    } 
     215 
    181216  } 
    182217  d_record.push_back(0); 
  • trunk/pdns/pdns/rcpgenerator.cc

    r996 r1026  
    11/* 
    22    PowerDNS Versatile Database Driven Nameserver 
    3     Copyright (C) 2005 PowerDNS.COM BV 
     3    Copyright (C) 2005 - 2007 PowerDNS.COM BV 
    44 
    55    This program is free software; you can redistribute it and/or modify 
     
    138138      break; 
    139139 
    140     if(strptr[d_pos]=='\\' && d_pos < d_end - 1)  
     140    if(strptr[d_pos]=='\\' && d_pos < d_end - 1 && strptr[d_pos+1]!='.')  // leave the \. escape around 
    141141      d_pos++; 
    142142 
  • trunk/pdns/pdns/resolver.cc

    r1016 r1026  
    188188  int res=select(d_sock+1,&rd,0,0,&timeout); 
    189189 
    190   if(!res) 
     190  if(!res) { 
    191191    throw ResolverException("Timeout waiting for answer"); 
     192  } 
    192193  if(res<0) 
    193194    throw ResolverException("Error waiting for answer: "+stringerror()); 
     
    205206  sendResolve(ip, domain, type); 
    206207  try { 
    207     struct sockaddr_in from
    208     return receiveResolve((sockaddr*)&from, sizeof(from)); 
     208    ComboAddress from(ip)
     209    return receiveResolve((sockaddr*)&from, from.getSocklen()); 
    209210  } 
    210211  catch(ResolverException &re) { 
  • trunk/pdns/pdns/zoneparser-tng.cc

    r1015 r1026  
    6666  if(!isdigit(lc)) 
    6767    switch(lc) { 
     68    case 'M': 
     69      val*=60; // minutes, not months! 
     70      break; 
    6871    case 'H': 
    6972      val*=3600; 
     
    7477    case 'W': 
    7578      val*=3600*24*7; 
    76       break; 
    77     case 'M': 
    78       val*=3600*24*7*4; 
    7979      break; 
    8080    case 'Y': // ? :-) 
     
    352352        rr.content+=soaparts[n]; 
    353353    } 
     354    break; 
    354355  default:; 
    355356  }