]> granicus.if.org Git - pdns/commitdiff
sad
authorBert Hubert <bert.hubert@netherlabs.nl>
Sat, 11 Oct 2003 19:57:19 +0000 (19:57 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Sat, 11 Oct 2003 19:57:19 +0000 (19:57 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@194 d19b8d6e-7fed-0310-83ef-9ca221ded41b

16 files changed:
ChangeLog
modules/gmysqlbackend/smysql.cc
modules/gmysqlbackend/smysql.hh
modules/gpgsqlbackend/spgsql.cc
modules/gpgsqlbackend/spgsql.hh
modules/gsqlitebackend/ssqlite.hh
modules/ldapbackend/ldapbackend.cc
pdns/backends/gsql/gsqlbackend.cc
pdns/backends/gsql/ssql.hh
pdns/common_startup.cc
pdns/dynlistener.cc
pdns/misc.cc
pdns/misc.hh
pdns/packethandler.cc
pdns/resolver.cc
pdns/syncres.hh

index 358ef6a288727dfd4685e2b4187fe1b7ac453a4e..e9f50486e5db89384826ca29500e5a3f063d65e3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,7 +17,10 @@ changes since 2.9.11:
        - pdns_recursor has gained an init.d script
        - sqlite support from 
        - bindbackend2 gains supermaster support (Mark Bergsma), untested
-       
+       - slave communicator more robust against misconfiguration (empty
+         master field) 
+       - postgresql backend gains error checking support
+
 changes since 2.9.10:
        - pdns_recursor now cleans its cache
        - pdns_recursor writes its pid to disk now (FreeBSD port maintainer)
index 4892479c516988e2fc2b6ac798f9ce166118ccb9..09af13b91cc2a809b61f9d834d8b35e3a2a6ff55 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright 2001 Netherlabs BV, bert.hubert@netherlabs.nl. See LICENSE 
    for more information.
-   $Id: smysql.cc,v 1.3 2003/09/28 17:37:43 ahu Exp $  */
+   $Id: smysql.cc,v 1.4 2003/10/11 19:57:19 ahu Exp $  */
 #include "smysql.hh"
 #include <string>
 #include <iostream>
@@ -41,6 +41,11 @@ SSqlException SMySQL::sPerrorException(const string &reason)
   return SSqlException(reason+string(": ")+mysql_error(&d_db));
 }
 
+int SMySQL::doCommand(const string &query)
+{
+  return doQuery(query);
+}
+
 int SMySQL::doQuery(const string &query)
 {
   if(d_rres)
index 30c4ad7758dde5235bf1aad312142a24562efe30..ac0831c63b98b679091c40ebff603da6143e0c5d 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright 2001 Netherlabs BV, bert.hubert@netherlabs.nl. See LICENSE 
    for more information.
-   $Id: smysql.hh,v 1.3 2002/12/19 16:28:31 ahu Exp $  */
+   $Id: smysql.hh,v 1.4 2003/10/11 19:57:19 ahu Exp $  */
 #ifndef SMYSQL_HH
 #define SMYSQL_HH
 
@@ -19,6 +19,7 @@ public:
   SSqlException sPerrorException(const string &reason);
   int doQuery(const string &query, result_t &result);
   int doQuery(const string &query);
+  int doCommand(const string &query);
   bool getRow(row_t &row);
   string escape(const string &str);    
   void setLog(bool state);
index a6d982b9b7cc3f251cb9414cbfd0bb335d4e3404..5cade0611c3eb57c92770e34264c25870991f239 100644 (file)
@@ -1,6 +1,6 @@
-/* Copyright 200w Netherlabs BV, bert.hubert@netherlabs.nl. See LICENSE 
+/* Copyright 2003 Netherlabs BV, bert.hubert@netherlabs.nl. See LICENSE 
    for more information.
-   $Id: spgsql.cc,v 1.2 2002/12/17 10:39:53 ahu Exp $  */
+   $Id: spgsql.cc,v 1.3 2003/10/11 19:57:19 ahu Exp $  */
 #include <string>
 #include "spgsql.hh"
 
@@ -28,10 +28,10 @@ SPgSQL::SPgSQL(const string &database, const string &host, const string &msocket
     connectstr+=" password="+password;
 
   d_db=new PgDatabase(connectstr.c_str());
-  
+  //  L<<Logger::Error<<"Connectstr: "<<connectstr<<endl;
   // Check to see that the backend connection was successfully made
   if (d_db->ConnectionBad() ) {
-    throw sPerrorException("Unable to connect to database");
+    throw sPerrorException("Unable to connect to database, connect string: "+connectstr);
   }
 
 }
@@ -51,14 +51,29 @@ SSqlException SPgSQL::sPerrorException(const string &reason)
   return SSqlException(reason+string(": ")+d_db->ErrorMessage());
 }
 
+int SPgSQL::doCommand(const string &query)
+{
+  if(s_dolog)
+    L<<Logger::Warning<<"Command: "<<query<<endl;
+
+  if(!d_db->ExecCommandOk(query.c_str())) { 
+    throw sPerrorException("PostgreSQL failed to execute command");
+  }
+
+  d_count=0;
+  return 0;
+}
+
+
 int SPgSQL::doQuery(const string &query)
 {
   if(s_dolog)
     L<<Logger::Warning<<"Query: "<<query<<endl;
 
-  if(!d_db->Exec(query.c_str())) {
+  if(!d_db->ExecTuplesOk(query.c_str())) { // was Exec, without TuplesOk
     throw sPerrorException("PostgreSQL failed to execute command");
   }
+
   d_count=0;
   return 0;
 }
@@ -83,7 +98,7 @@ int SPgSQL::doQuery(const string &query, result_t &result)
 bool SPgSQL::getRow(row_t &row)
 {
   row.clear();
+  
   if(d_count>=d_db->Tuples())
     return false;
   
index be28077c61b281bb7a1423eb187f702a243d436a..a6b5e85caeea0b106955493cb0dbc24161476d6f 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright 2001 Netherlabs BV, bert.hubert@netherlabs.nl. See LICENSE 
    for more information.
-   $Id: spgsql.hh,v 1.3 2003/01/06 16:13:59 ahu Exp $  */
+   $Id: spgsql.hh,v 1.4 2003/10/11 19:57:19 ahu Exp $  */
 #ifndef SPGSQL_HH
 #define SPGSQL_HH
 using namespace std;
@@ -20,6 +20,7 @@ public:
   SSqlException sPerrorException(const string &reason);
   int doQuery(const string &query, result_t &result);
   int doQuery(const string &query);
+  int doCommand(const string &query);
   bool getRow(row_t &row);
   string escape(const string &str);    
   void setLog(bool state);
index 5cc7fe09691ad294befc34b66dbc47f25a376573..30c6678890067ccc8f7eef2d1066f34b53a24bff 100644 (file)
@@ -27,11 +27,18 @@ public:
   //! Destructor.
   ~SSQLite( void );
   
-  //! Performs a query.
+  //! Performs a query and puts answers in result
   int doQuery( const std::string & query, result_t & result );
   
-  //! Performs a query.
+  //! Performs a query, caller can retrieve answers with getRow
   int doQuery( const std::string & query );
+
+  //! Performs a command that does not return rows
+  int doCommand( const std::string & query )
+  {
+    return doQuery(query);
+  }
+
   
   //! Returns a row from a result set.
   bool getRow( row_t & row );
index fe2a41f804fdd6f83ed21a2da8ec6708f312c034..23b0731307df4a8e03332bfccae5429b66a68773 100644 (file)
 
 
 
-static int Toupper(int c)
-{
-  return toupper(c);
-}
-
-
 LdapBackend::LdapBackend( const string &suffix )
 {
-       m_msgid = 0;
-       m_qname = "";
+       unsigned int i;
        setArgPrefix( "ldap" + suffix );
+       string hosts = getArg( "host" );
 
-
-       m_default_ttl = (u_int32_t) strtol( getArg( "default-ttl" ).c_str(), NULL, 10 );
+       m_msgid = 0;
+       m_qname = "";
+       m_default_ttl = arg().asNum( "default-ttl" );
 
        try
        {
-               L << Logger::Info << backendname << " LDAP Server = " << getArg( "host" ) << ":" << getArg( "port" ) << endl;
-               m_pldap = new PowerLDAP( getArg( "host" ), (u_int16_t) atoi( getArg( "port" ).c_str() ) );
+               for( i = 0; i < hosts.length(); i++ )
+               {
+                       if( hosts[i] == ',' ) { hosts[i] = ' '; }
+               }
+
+               L << Logger::Info << backendname << " LDAP servers = " << hosts << endl;
+
+               m_pldap = new PowerLDAP( hosts.c_str(), atoi( getArg( "port" ).c_str() ) );
                m_pldap->simpleBind( getArg( "binddn" ), getArg( "secret" ) );
        }
        catch( LDAPException &e )
@@ -70,8 +71,6 @@ bool LdapBackend::list( const string &target, int domain_id )
 
        try
        {
-               L << Logger::Notice << backendname << " AXFR request for " << target << endl;
-
                // search for DN of SOA record which is SOA for target zone
 
                filter = "(&(associatedDomain=" + target + ")(SOARecord=*))";
@@ -83,7 +82,7 @@ bool LdapBackend::list( const string &target, int domain_id )
                        return false;
                }
 
-               if( m_result.empty() || m_result.find( "dn" ) == m_result.end() || m_result["dn"].empty() )
+               if( m_result.empty() || !m_result.count( "dn" ) || m_result["dn"].empty() )
                {
                        L << Logger::Error << backendname << " No SOA record for " << target << endl;
                        return false;
@@ -94,15 +93,22 @@ bool LdapBackend::list( const string &target, int domain_id )
 
                // list all records one level below but not entries containing SOA records (these are seperate zones)
 
+               DLOG( L << Logger::Debug << backendname << " List = target: " << target << ", basedn: = " << dn << endl );
+
                m_qname = "";
                m_adomain = m_adomains.end();   // skip loops in get() first time
                filter = "(&(associatedDomain=*" + target + ")(!(SOARecord=*)))";
                m_msgid = m_pldap->search( dn, LDAP_SCOPE_ONELEVEL, filter, (const char**) attrany );
        }
+       catch( LDAPTimeout &lt )
+       {
+               L << Logger::Error << backendname << " Unable to get zone " + target + " from LDAP directory: " << lt.what() << endl;
+               return false;
+       }
        catch( LDAPException &le )
        {
                L << Logger::Error << backendname << " Unable to get zone " + target + " from LDAP directory: " << le.what() << endl;
-               return false;
+               throw( AhuException( "LDAP server unreachable" ) );   // try to reconnect to another server
        }
        catch( exception &e )
        {
@@ -132,12 +138,12 @@ void LdapBackend::lookup( const QType &qtype, const string &qname, DNSPacket *dn
        {
                m_qtype = qtype;
                m_qname = qname;
-               qesc = m_pldap->escape( qname );
+               qesc = toLower( m_pldap->escape( qname ) );
 
                if( mustDo( "disable-ptrrecord" ) )  // PTRRecords will be derived from ARecords
                {
-                       len = qesc.length();
                        stringtok( parts, qesc, "." );
+                       len = qesc.length();
 
                         if( parts.size() == 6 && len > 13 && qesc.substr( len - 13, 13 ) == ".in-addr.arpa" )   // IPv4 reverse lookups
                        {
@@ -175,15 +181,21 @@ void LdapBackend::lookup( const QType &qtype, const string &qname, DNSPacket *dn
                        }
                }
 
+               DLOG( L << Logger::Debug << backendname << " Search = basedn: " << getArg( "basedn" ) << ", filter: " << filter << ", qtype: " << qtype.getName() << endl );
+
                m_adomain = m_adomains.end();   // skip loops in get() first time
-               L << Logger::Info << backendname << " Search = basedn: " << getArg( "basedn" ) << ", filter: " << filter << ", qtype: " << qtype.getName() << endl;
                m_msgid = m_pldap->search( getArg("basedn"), LDAP_SCOPE_SUBTREE, filter, (const char**) attributes );
        }
-       catch( LDAPException &le )
+       catch( LDAPTimeout &lt )
        {
-               L << Logger::Warning << backendname << " Unable to search LDAP directory: " << le.what() << endl;
+               L << Logger::Error << backendname << " Unable to search LDAP directory: " << lt.what() << endl;
                return;
        }
+       catch( LDAPException &le )
+       {
+               L << Logger::Error << backendname << " Unable to search LDAP directory: " << le.what() << endl;
+               throw( AhuException( "LDAP server unreachable" ) );   // try to reconnect to another server
+       }
        catch( exception &e )
        {
                L << Logger::Error << backendname << " Caught STL exception: " << e.what() << endl;
@@ -214,8 +226,7 @@ bool LdapBackend::get( DNSResourceRecord &rr )
                                {
                                        attrname = m_attribute->first;
                                        qstr = attrname.substr( 0, attrname.length() - 6 );   // extract qtype string from ldap attribute name
-                                       transform( qstr.begin(), qstr.end(), qstr.begin(), &Toupper );
-                                       qt = QType( const_cast<char*>(qstr.c_str()) );
+                                       qt = QType( const_cast<char*>(toUpper( qstr ).c_str()) );
 
                                        while( m_value != m_attribute->second.end() )
                                        {
@@ -244,7 +255,7 @@ bool LdapBackend::get( DNSResourceRecord &rr )
                                                rr.content = content;
                                                m_value++;
 
-                                               L << Logger::Info << backendname << " Record = qname: " << rr.qname << ", qtype: " << (rr.qtype).getName() << ", priority: " << rr.priority << ", content: " << rr.content << endl;
+                                               DLOG( L << Logger::Debug << backendname << " Record = qname: " << rr.qname << ", qtype: " << (rr.qtype).getName() << ", priority: " << rr.priority << ", content: " << rr.content << endl );
                                                return true;
                                        }
 
@@ -260,9 +271,14 @@ bool LdapBackend::get( DNSResourceRecord &rr )
                while( m_pldap->getSearchEntry( m_msgid, m_result, false ) && prepareEntry() );
 
        }
+       catch( LDAPTimeout &lt )
+       {
+               L << Logger::Error << backendname << " Search failed: " << lt.what() << endl;
+       }
        catch( LDAPException &le )
        {
-               L << Logger::Warning << backendname << " Search failed: " << le.what() << endl;
+               L << Logger::Error << backendname << " Search failed: " << le.what() << endl;
+               throw( AhuException( "LDAP server unreachable" ) );   // try to reconnect to another server
        }
        catch( exception &e )
        {
@@ -301,7 +317,7 @@ inline bool LdapBackend::prepareEntry()
        m_adomains.clear();
        m_ttl = m_default_ttl;
 
-       if( m_result.find( "dNSTTL" ) != m_result.end() && !m_result["dNSTTL"].empty() )
+       if( m_result.count( "dNSTTL" ) && !m_result["dNSTTL"].empty() )
        {
                m_ttl = (u_int32_t) strtol( m_result["dNSTTL"][0].c_str(), NULL, 10 );
                m_result.erase( "dNSTTL" );
@@ -310,7 +326,7 @@ inline bool LdapBackend::prepareEntry()
        if( !m_qname.empty() )   // request was a normal lookup()
        {
                m_adomains.push_back( m_qname );
-               if( m_result.find( "associatedDomain" ) != m_result.end() )
+               if( m_result.count( "associatedDomain" ) )
                {
                        m_result["PTRRecord"] = m_result["associatedDomain"];
                        m_result.erase( "associatedDomain" );
@@ -318,7 +334,7 @@ inline bool LdapBackend::prepareEntry()
        }
        else   // request was a list() for AXFR
        {
-               if( m_result.find( "associatedDomain" ) != m_result.end() )
+               if( m_result.count( "associatedDomain" ) )
                {
                        m_adomains = m_result["associatedDomain"];
                        m_result.erase( "associatedDomain" );
@@ -342,13 +358,13 @@ public:
 
        void declareArguments( const string &suffix="" )
        {
-               declare( suffix, "host", "your ldap server","localhost" );
-               declare( suffix, "port", "ldap server port","389" );
+               declare( suffix, "host", "one or more ldap server","localhost:389" );
+               declare( suffix, "port", "ldap server port (depricated, use ldap-host)","389" );
                declare( suffix, "basedn", "search root in ldap tree (must be set)","" );
                declare( suffix, "binddn", "user dn for non anonymous binds","" );
                declare( suffix, "secret", "user password for non anonymous binds", "" );
                declare( suffix, "disable-ptrrecord", "disable necessity for seperate PTR records", "no" );
-               declare( suffix, "default-ttl", "default ttl if DNSTTL is not set", "86400" );
+               declare( suffix, "default-ttl", "default ttl if DNSTTL is not set (depricated, use default-ttl)", "3600" );
        }
 
 
@@ -369,7 +385,7 @@ public:
        Loader()
        {
                BackendMakers().report( new LdapFactory );
-               L << Logger::Notice << backendname << " This is the ldap module version "VERSION" ("__DATE__", "__TIME__") reporting" << endl;
+               L << Logger::Info << backendname << " This is the ldap module version "VERSION" ("__DATE__", "__TIME__") reporting" << endl;
   }
 };
 
index d6a1346d2e4b8a3918c8c0b5fb370aaeb349957b..43253ef04ae880574a4fcdf77e82677d0cc77210 100644 (file)
@@ -1,4 +1,4 @@
-// $Id: gsqlbackend.cc,v 1.9 2003/08/22 13:33:31 ahu Exp $ 
+// $Id: gsqlbackend.cc,v 1.10 2003/10/11 19:57:19 ahu Exp $ 
 #include <string>
 #include <map>
 
@@ -13,8 +13,6 @@ using namespace std;
 #include "pdns/logger.hh"
 #include "pdns/arguments.hh"
 
-
-
 #include <sstream>
 
 void GSQLBackend::setNotified(u_int32_t domain_id, u_int32_t serial)
@@ -40,7 +38,7 @@ void GSQLBackend::setFresh(u_int32_t domain_id)
           domain_id);
 
   try {
-    d_db->doQuery(output);
+    d_db->doCommand(output);
   }
   catch (SSqlException &e) {
     throw AhuException("GSQLBackend unable to refresh domain_id "+itoa(domain_id)+": "+e.txtReason());
@@ -348,7 +346,7 @@ bool GSQLBackend::createSlaveDomain(const string &ip, const string &domain, cons
   format = d_InsertSlaveZoneQuery;
   snprintf(output,sizeof(output)-1,format.c_str(),sqlEscape(domain).c_str(),sqlEscape(ip).c_str(),sqlEscape(account).c_str());
   try {
-    d_db->doQuery(output);
+    d_db->doCommand(output);
   }
   catch(SSqlException &e) {
     throw AhuException("Database error trying to insert new slave '"+domain+"': "+ e.txtReason());
@@ -388,7 +386,7 @@ bool GSQLBackend::feedRecord(const DNSResourceRecord &r)
           sqlEscape(r.qtype.getName()).c_str(),
           r.domain_id, toLower(sqlEscape(r.qname)).c_str()); 
   try {
-    d_db->doQuery(output);
+    d_db->doCommand(output);
   }
   catch (SSqlException &e) {
     throw AhuException(e.txtReason());
@@ -401,8 +399,8 @@ bool GSQLBackend::startTransaction(const string &domain, int domain_id)
   char output[1024];
   snprintf(output,sizeof(output)-1,d_DeleteZoneQuery.c_str(),domain_id);
   try {
-    d_db->doQuery("begin");
-    d_db->doQuery(output);
+    d_db->doCommand("begin");
+    d_db->doCommand(output);
   }
   catch (SSqlException &e) {
     throw AhuException("Database failed to start transaction: "+e.txtReason());
@@ -414,7 +412,7 @@ bool GSQLBackend::startTransaction(const string &domain, int domain_id)
 bool GSQLBackend::commitTransaction()
 {
   try {
-    d_db->doQuery("commit");
+    d_db->doCommand("commit");
   }
   catch (SSqlException &e) {
     throw AhuException("Database failed to commit transaction: "+e.txtReason());
@@ -425,7 +423,7 @@ bool GSQLBackend::commitTransaction()
 bool GSQLBackend::abortTransaction()
 {
   try {
-    d_db->doQuery("rollback");
+    d_db->doCommand("rollback");
   }
   catch(SSqlException &e) {
     throw AhuException("MySQL failed to abort transaction: "+string(e.txtReason()));
index 45dafe862c442e231b00984ff5b472c6e0300014..a65708b84fd8ff3b67f9609d7e964d4e0937e6d2 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright 2001 Netherlabs BV, bert.hubert@netherlabs.nl. See LICENSE 
    for more information.
-   $Id: ssql.hh,v 1.1 2002/12/16 20:34:29 ahu Exp $  */
+   $Id: ssql.hh,v 1.2 2003/10/11 19:57:19 ahu Exp $  */
 #ifndef SSQL_HH
 #define SSQL_HH
 
@@ -33,6 +33,7 @@ public:
   virtual SSqlException sPerrorException(const string &reason)=0;
   virtual int doQuery(const string &query, result_t &result)=0;
   virtual int doQuery(const string &query)=0;
+  virtual int doCommand(const string &query)=0;
   virtual bool getRow(row_t &row)=0;
   virtual string escape(const string &name)=0;
   virtual void setLog(bool state){}
index bf9a340bbd74d340a9d5b2c6c117fe5158c941cf..52e0e0066c0ad7bc250bdc42228ec4bfa9b16b0a 100644 (file)
@@ -100,6 +100,7 @@ void declareArguments()
   arg().set("negquery-cache-ttl","Seconds to store packets in the PacketCache")="60";
   arg().set("query-cache-ttl","Seconds to store packets in the PacketCache")="20";
   arg().set("soa-minimum-ttl","Default SOA mininum ttl")="3600";
+  arg().set("default-ttl","Seconds a result is valid if not set otherwise")="3600";
   arg().set("max-tcp-connections","Maximum number of TCP connections")="10";
 
   arg().setSwitch( "use-logfile", "Use a log file" )= "no";
index da1107195f33d68e7c303f920b6876d3bc9482d5..74ec8eb6d570b5788682d58441fa33d4e2fa1d56 100644 (file)
@@ -16,7 +16,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
-// $Id: dynlistener.cc,v 1.6 2003/09/16 21:02:35 ahu Exp $ 
+// $Id: dynlistener.cc,v 1.7 2003/10/11 19:57:19 ahu Exp $ 
 /* (C) Copyright 2002 PowerDNS.COM BV */
 #include <cstring>
 #include <string>
@@ -206,7 +206,7 @@ void DynListener::theListener()
        sendLine("Empty line");
        continue;
       }
-      upperCase(parts[0]);
+      parts[0] = toUpper( parts[0] );
       if(!d_funcdb[parts[0]]) {
        if(d_restfunc) 
          sendLine((*d_restfunc)(parts,d_ppid));
index e287014677999a813cdf28d1c78905c7565ea42d..fc8b00e2e06f55442238a8a2e18d9b1bc83c0bca 100644 (file)
@@ -27,6 +27,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include "ahuexception.hh"
 #include <sys/types.h>
 
 #ifndef WIN32
@@ -138,8 +139,11 @@ int sendData(const char *buffer, int replen, int outsock)
 
 void parseService(const string &descr, ServiceTuple &st)
 {
+
   vector<string>parts;
   stringtok(parts,descr,":");
+  if(parts.empty())
+    throw AhuException("Unable to parse '"+descr+"' as a service");
   st.host=parts[0];
   if(parts.size()>1)
     st.port=atoi(parts[1].c_str());
@@ -201,12 +205,6 @@ time_t DTime::time()
   return d_set.tv_sec;
 }
 
-// Make s uppercase:
-void upperCase(string& s) {
-  for(unsigned int i = 0; i < s.length(); i++)
-    s[i] = toupper(s[i]);
-}
-
 
 void chomp(string &line, const string &delim)
 {
index 1971c63d6481eda297d3b2386c8dd17e0273f5b6..775080a1a1f3952ebef0a97b782656568bd58bd9 100644 (file)
@@ -76,7 +76,6 @@ inline u_int32_t getLong(unsigned char *p)
   return (p[0]<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
 }
 
-void upperCase(string& s);
 
 struct ServiceTuple
 {
@@ -162,4 +161,15 @@ inline string toLower(const string &upper)
 }
 
 
+// Make s uppercase:
+inline string toUpper( const string& s )
+{
+       string r(s);
+       for( unsigned int i = 0; i < s.length(); i++ ) {
+               r[i] = toupper( r[i] );
+       }
+       return r;
+}
+
+
 #endif
index e9c37145bc1a531b4cb6e2a51320b04f26370cb4..284e6c256a8efbba8e97ea0f0cb7dbc8e0091c00 100644 (file)
@@ -154,7 +154,7 @@ int PacketHandler::doDNSCheckRequest(DNSPacket *p, DNSPacket *r, string &target)
   DNSResourceRecord rr;
 
   if (p->qclass == 3 && p->qtype.getName() == "HINFO") {
-    rr.content = "PowerDNS $Id: packethandler.cc,v 1.17 2003/09/16 21:02:35 ahu Exp $";
+    rr.content = "PowerDNS $Id: packethandler.cc,v 1.18 2003/10/11 19:57:19 ahu Exp $";
     rr.ttl = 5;
     rr.qname=target;
     rr.qtype=13; // hinfo
@@ -170,7 +170,7 @@ int PacketHandler::doVersionRequest(DNSPacket *p, DNSPacket *r, string &target)
 {
   DNSResourceRecord rr;
   if(p->qtype.getCode()==QType::TXT && target=="version.bind") {// TXT
-    rr.content="Served by POWERDNS "VERSION" $Id: packethandler.cc,v 1.17 2003/09/16 21:02:35 ahu Exp $";
+    rr.content="Served by POWERDNS "VERSION" $Id: packethandler.cc,v 1.18 2003/10/11 19:57:19 ahu Exp $";
     rr.ttl=5;
     rr.qname=target;
     rr.qtype=QType::TXT; // TXT
@@ -186,7 +186,6 @@ bool PacketHandler::getAuth(DNSPacket *p, SOAData *sd, const string &target, int
 {
   string subdomain(target);
   do {
-    cout<<"Trying: '"<<subdomain<<"'"<<endl;
     if( B.getSOA( subdomain, *sd ) ) {
       sd->qname = subdomain;
       *zoneId = sd->domain_id;
index 9bea73072cd1fd3137ab75c34431ac18491a18b9..1af320674bbf96213557d675f1d8a17d41e48e0b 100644 (file)
@@ -150,7 +150,6 @@ int Resolver::notify(int sock, const string &domain, const string &ip, u_int16_t
 
 void Resolver::sendResolve(const string &ip, const char *domain, int type)
 {
-
   DNSPacket p;
 
   p.setQuestion(Opcode::Query,domain,type);
@@ -164,7 +163,13 @@ void Resolver::sendResolve(const string &ip, const char *domain, int type)
   struct in_addr inp;
   ServiceTuple st;
   st.port=53;
-  parseService(ip, st);
+  try {
+    parseService(ip, st);
+  }
+  catch(AhuException &ae) {
+    throw ResolverException("Sending a dns question to '"+ip+"': "+ae.reason);
+  }
+
   Utility::inet_aton(st.host.c_str(),&inp);
   toaddr.sin_addr.s_addr=inp.s_addr;
 
index e70a923c08b6f7a5037167d6855191a5a872227a..db465f63da8ba9f532500de67079d93bb2ef1320 100644 (file)
@@ -42,7 +42,7 @@ public:
   void throttle(const Thing& t, unsigned int ttl=0, unsigned int tries=0) 
   {
     entry e;
-    e.ttd=time(0)+ (ttl ? ttl : d_ttl) ; 
+    e.ttd=time(0)+ (ttl ?: d_ttl) ; 
     e.T=t; 
     e.count=tries ? tries : d_limit;
     d_dq.push_front(e);