Changeset 1360

Show
Ignore:
Timestamp:
05/30/09 22:18:11 (15 months ago)
Author:
ahu
Message:

add first stab at 'per-zone-axfr-acls'. Set that flag in the configuration table, and see  http://mailman.powerdns.com/pipermail/pdns-users/2006-March/003115.html
Also allows netmasks

Location:
trunk/pdns
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/modules/gmysqlbackend/gmysqlbackend.cc

    r477 r1360  
    7575    declare(suffix,"info-all-master-query","", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'"); 
    7676    declare(suffix,"delete-zone-query","", "delete from records where domain_id=%d"); 
    77  
    78  
     77    declare(suffix,"check-acl-query","", "select value from acls where acl_type='%s' and acl_key='%s'"); 
    7978  } 
    8079   
  • trunk/pdns/modules/goraclebackend/goraclebackend.cc

    r342 r1360  
    6969    declare(suffix,"info-all-master-query","", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'"); 
    7070    declare(suffix,"delete-zone-query","", "delete from records where domain_id=%d"); 
    71  
    72  
     71    declare(suffix,"check-acl-query","", "select value from acls where acl_type='%s' and acl_key='%s'"); 
    7372  } 
    7473   
  • trunk/pdns/modules/gpgsqlbackend/gpgsqlbackend.cc

    r340 r1360  
    7575    declare(suffix,"info-all-master-query","", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'"); 
    7676    declare(suffix,"delete-zone-query","", "delete from records where domain_id=%d"); 
     77    declare(suffix,"check-acl-query","", "select value from acls where acl_type='%s' and acl_key='%s'"); 
    7778 
    7879 
  • trunk/pdns/modules/gsqlite3backend/gsqlite3backend.cc

    r1342 r1360  
    7676    declare( suffix, "info-all-master-query", "", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'"); 
    7777    declare( suffix, "delete-zone-query", "", "delete from records where domain_id=%d"); 
     78    declare(suffix,"check-acl-query","", "select value from acls where acl_type='%s' and acl_key='%s'"); 
    7879  } 
    7980   
  • trunk/pdns/modules/gsqlitebackend/gsqlitebackend.cc

    r1342 r1360  
    7676    declare( suffix, "info-all-master-query", "", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'"); 
    7777    declare( suffix, "delete-zone-query", "", "delete from records where domain_id=%d"); 
     78    declare(suffix,"check-acl-query","", "select value from acls where acl_type='%s' and acl_key='%s'"); 
    7879  } 
    7980   
  • trunk/pdns/pdns/backends/gsql/gsqlbackend.cc

    r1271 r1360  
    122122  /* list all domains that need refreshing for which we are slave, and insert into SlaveDomain: 
    123123     id,name,master IP,serial */ 
    124   char output[1024]; 
    125   snprintf(output,sizeof(output)-1,d_InfoOfAllSlaveDomainsQuery.c_str()); 
    126  
    127   try { 
    128     d_db->doQuery(output,d_result); 
     124 
     125  try { 
     126    d_db->doQuery(d_InfoOfAllSlaveDomainsQuery,d_result); 
    129127  } 
    130128  catch (SSqlException &e) { 
     
    161159  /* list all domains that need notifications for which we are master, and insert into updatedDomains 
    162160     id,name,master IP,serial */ 
    163   char output[1024]; 
    164   snprintf(output, sizeof(output)-1, d_InfoOfAllMasterDomainsQuery.c_str()); 
    165  
    166   try { 
    167     d_db->doQuery(output,d_result); 
     161  try { 
     162    d_db->doQuery(d_InfoOfAllMasterDomainsQuery,d_result); 
    168163  } 
    169164  catch(SSqlException &e) { 
     
    240235  d_InfoOfAllMasterDomainsQuery=getArg("info-all-master-query"); 
    241236  d_DeleteZoneQuery=getArg("delete-zone-query"); 
     237  d_CheckACLQuery=getArg("check-acl-query"); 
    242238} 
    243239 
     
    343339  } 
    344340  return false; 
     341} 
     342 
     343 
     344bool GSQLBackend::checkACL(const string &acl_type, const string &key, const string &value) 
     345{ 
     346  string format; 
     347  char output[1024]; 
     348  format = d_CheckACLQuery; 
     349  snprintf(output, sizeof(output)-1, format.c_str(), sqlEscape(acl_type).c_str(), sqlEscape(key).c_str()); 
     350  try { 
     351    d_db->doQuery(output, d_result); 
     352  } 
     353  catch(SSqlException &e) { 
     354    throw AhuException("Database error trying to check ACL:"+acl_type+" with error: "+e.txtReason()); 
     355  } 
     356  if(!d_result.empty()) { 
     357    for (unsigned int i = 0; i < d_result.size(); i++) { 
     358      Netmask nm(d_result[i][0]); 
     359      if (nm.match(value)) { 
     360        return true; 
     361      } 
     362    } 
     363  }   
     364  return false; // default to false 
    345365} 
    346366 
  • trunk/pdns/pdns/backends/gsql/gsqlbackend.hh

    r1342 r1360  
    3535  bool superMasterBackend(const string &ip, const string &domain, const vector<DNSResourceRecord>&nsset, string *account, DNSBackend **db); 
    3636  void setFresh(uint32_t domain_id); 
     37  bool checkACL(const string &acl_type, const string &key, const string &value); 
    3738  void getUnfreshSlaveInfos(vector<DomainInfo> *domains); 
    3839  void getUpdatedMasters(vector<DomainInfo> *updatedDomains); 
     
    6768  string d_InfoOfAllMasterDomainsQuery; 
    6869  string d_DeleteZoneQuery;              
    69  
     70  string d_CheckACLQuery;    
    7071}; 
  • trunk/pdns/pdns/common_startup.cc

    r1346 r1360  
    120120  ::arg().set("max-tcp-connections","Maximum number of TCP connections")="10"; 
    121121  ::arg().setSwitch("no-shuffle","Set this to prevent random shuffling of answers - for regression testing")="off"; 
     122  ::arg().setSwitch("per-zone-axfr-acls","When set, backends that implement it perform per-zone AXFL ACL checks")="off"; 
    122123 
    123124  ::arg().setSwitch( "use-logfile", "Use a log file (Windows only)" )= "no"; 
  • trunk/pdns/pdns/dnsbackend.hh

    r1018 r1360  
    167167  } 
    168168 
     169  virtual bool checkACL(const string &acl_type, const string &key, const string &value) 
     170  { 
     171    return false; 
     172  } 
     173 
    169174protected: 
    170175  bool mustDo(const string &key); 
  • trunk/pdns/pdns/tcpreceiver.cc

    r1346 r1360  
    350350    return false; 
    351351 
    352   if( ::arg()["allow-axfr-ips"].empty() || d_ng.match( (ComboAddress *) &q->remote ) ) 
     352  if(!::arg().mustDo("per-zone-axfr-acls") && (::arg()["allow-axfr-ips"].empty() || d_ng.match( (ComboAddress *) &q->remote ))) 
    353353    return true; 
     354 
     355  if(::arg().mustDo("per-zone-axfr-acls")) { 
     356    SOAData sd; 
     357    sd.db=(DNSBackend *)-1; 
     358    if(s_P->getBackend()->getSOA(q->qdomain,sd)) { 
     359      DNSBackend *B=sd.db; 
     360      if (B->checkACL(string("allow-axfr"), q->qdomain, q->getRemote())) { 
     361        return true; 
     362      } 
     363    }   
     364  } 
    354365 
    355366  extern CommunicatorClass Communicator;