]> granicus.if.org Git - pdns/commitdiff
import Ruben d'Arco's mydns updates, including test suite setup\!
authorPeter van Dijk <peter.van.dijk@netherlabs.nl>
Wed, 12 Dec 2012 20:15:34 +0000 (20:15 +0000)
committerPeter van Dijk <peter.van.dijk@netherlabs.nl>
Wed, 12 Dec 2012 20:15:34 +0000 (20:15 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2988 d19b8d6e-7fed-0310-83ef-9ca221ded41b

modules/mydnsbackend/mydnsbackend.cc
modules/mydnsbackend/mydnsbackend.hh
modules/mydnsbackend/schema.sql
pdns/backends/bind/zone2sql.cc
regression-tests/basic-loc/skip.mydns [new file with mode: 0644]
regression-tests/double/skip.mydns [new file with mode: 0644]
regression-tests/ds-at-secure-delegation/skip.mydns [new file with mode: 0644]
regression-tests/start-test-stop
regression-tests/very-long-txt/skip.mydns [new file with mode: 0644]

index 18ee7bdf410bf661e42ccc464eefa879f04ca84e..3f409100a9cd21e344afbeddd8b1692baf05f6ca 100644 (file)
@@ -61,6 +61,7 @@ MyDNSBackend::MyDNSBackend(const string &suffix) {
         d_soatable=getArg("soa-table");
         d_rrwhere=(mustDo("rr-active")?"active = 1 and ":"")+getArg("rr-where");
         d_soawhere=(mustDo("soa-active")?"active = 1 and ":"")+getArg("soa-where");
+        d_useminimalttl=mustDo("use-minimal-ttl");
 
         L<<Logger::Warning<<backendName<<" Connection successful"<<endl;
 }
@@ -153,7 +154,7 @@ bool MyDNSBackend::getSOA(const string& name, SOAData& soadata, DNSPacket*) {
         soadata.expire = atol(rrow[6].c_str());
         soadata.default_ttl = atol(rrow[7].c_str());
         soadata.ttl = atol(rrow[8].c_str());
-        if (soadata.ttl < soadata.default_ttl) {
+        if (d_useminimalttl && soadata.ttl < soadata.default_ttl) {
                soadata.ttl = soadata.default_ttl;
         }
         soadata.db = this;
@@ -324,7 +325,7 @@ bool MyDNSBackend::get(DNSResourceRecord &rr) {
 
         rr.priority = atol(rrow[2].c_str());
         rr.ttl = atol(rrow[3].c_str());
-        if (rr.ttl < d_minimum)
+        if (d_useminimalttl && rr.ttl < d_minimum)
                rr.ttl = d_minimum;
         rr.domain_id=atol(rrow[4].c_str());
 
@@ -353,6 +354,7 @@ public:
                declare(suffix,"rr-where","Additional WHERE clause for RR","1 = 1");
                declare(suffix,"soa-active","Use the active column in the SOA table","yes");
                declare(suffix,"rr-active","Use the active column in the RR table","yes");
+               declare(suffix,"use-minimal-ttl","Setting this to 'yes' will make the backend behave like MyDNS on the TTL values. Setting it to 'no' will make it ignore the minimal-ttl of the zone.","yes");
         }
 
         MyDNSBackend *make(const string &suffix = "") {
index d45c327e37387a3be1dc74a72c0abb73495e35eb..c85675207651035b7a94cfc56f43f27d1f5bcdc1 100644 (file)
@@ -30,6 +30,7 @@ private:
         string d_soawhere;
         string d_rrwhere;
         string d_origin;
+        bool d_useminimalttl;
         unsigned int d_minimum;
 
 };
index 710e6ffb9f414285fda3bfa68b3c526075f00c6f..f503b35548df1351c7275d1635a9e712b252900c 100644 (file)
@@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS soa (
   minimum    INT UNSIGNED NOT NULL default '86400',
   ttl        INT UNSIGNED NOT NULL default '86400',
   UNIQUE KEY (origin)
-) TYPE=MyISAM;
+);
 
 --
 --  Table structure for table 'rr' (resource records)
@@ -36,6 +36,6 @@ CREATE TABLE IF NOT EXISTS rr (
   data       CHAR(128) NOT NULL,
   aux        INT UNSIGNED NOT NULL,
   ttl        INT UNSIGNED NOT NULL default '86400',
-  UNIQUE KEY rr (zone,name,type,data)
-) TYPE=MyISAM;
+  UNIQUE KEY rr (zone,name,type,data,aux)
+);
 
index c4108b26da846cd16ecb45a58a2d4e7666f00aad..28c85e7745c869dc2361d5af04becb73e532c5bd 100644 (file)
@@ -44,7 +44,7 @@
 StatBag S;
 static bool g_doDNSSEC;
 
-enum dbmode_t {MYSQL, ORACLE, POSTGRES, SQLITE};
+enum dbmode_t {MYSQL, ORACLE, POSTGRES, SQLITE, MYDNS};
 static dbmode_t g_mode;
 static bool g_intransaction;
 static int g_numRecords;
@@ -79,13 +79,13 @@ static void startNewTransaction()
     if(g_mode==POSTGRES || g_mode==ORACLE) {
       cout<<"COMMIT WORK;"<<endl;
     }
-    else if(g_mode == MYSQL || g_mode == SQLITE) {
+    else if(g_mode == MYSQL || g_mode == SQLITE || g_mode == MYDNS) {
       cout<<"COMMIT;"<<endl;
     }
   }
   g_intransaction=1;
   
-  if(g_mode == MYSQL)
+  if(g_mode == MYSQL || g_mode == MYDNS)
     cout<<"BEGIN;"<<endl;
   else
     cout<<"BEGIN TRANSACTION;"<<endl;
@@ -154,6 +154,33 @@ static void emitRecord(const string& zoneName, const string &qname, const string
       sqlstr(stripDot(content))<<", "<<ttl<<", "<<prio<< 
       " from Domains where name="<<toLower(sqlstr(zoneName))<<";\n";
   }
+  else if (g_mode == MYDNS) {
+    string zoneNameDot = zoneName + ".";
+    if (qtype == "A" || qtype == "AAAA" || qtype == "CNAME" || qtype == "HINFO" || qtype == "MX" || qtype == "NAPTR" || 
+        qtype == "NS" || qtype == "PTR" || qtype == "RP" || qtype == "SRV" || qtype == "TXT")
+    {
+      if ((qtype == "MX" || qtype == "NS" || qtype == "SRV" || qtype == "CNAME") && content[content.size()-1] != '.')
+        content.append(".");
+      cout<<"INSERT INTO rr(zone, name, type, data, aux, ttl) VALUES("<<
+      "(SELECT id FROM soa WHERE origin = "<< 
+      sqlstr(toLower(zoneNameDot))<<"), "<<
+      sqlstr(toLower(qname))<<", "<<
+      sqlstr(qtype)<<", "<<sqlstr(content)<<", "<<prio<<", "<<ttl<<");\n";
+    }
+    else if (qtype == "SOA") {
+      //pdns CONTENT = ns1.wtest.com. ahu.example.com. 2005092501 28800 7200 604800 86400 
+      vector<string> parts;
+      stringtok(parts, content);
+      cout<<"INSERT INTO soa(origin, ns, mbox, serial, refresh, retry, expire, minimum, ttl) VALUES("<<
+      sqlstr(toLower(zoneNameDot))<<", "<<sqlstr(parts[0])<<", "<<sqlstr(parts[1])<<", "<<atoi(parts[2].c_str())<<", "<<
+      atoi(parts[3].c_str())<<", "<<atoi(parts[4].c_str())<<", "<<atoi(parts[5].c_str())<<", "<<atoi(parts[6].c_str())<<", "<<ttl<<");\n";
+    }
+    else
+    {
+      cerr<<"Record type "<<qtype<<" is not supported."<<endl;
+    }
+  }
 }
 
 
@@ -179,6 +206,7 @@ int main(int argc, char **argv)
    
     ::arg().setSwitch("gpgsql","Output in format suitable for default gpgsqlbackend")="no";
     ::arg().setSwitch("gmysql","Output in format suitable for default gmysqlbackend")="no";
+    ::arg().setSwitch("mydns","Output in format suitable for default mydnsbackend")="no";
     ::arg().setSwitch("oracle","Output in format suitable for the oraclebackend")="no";
     ::arg().setSwitch("gsqlite","Output in format suitable for default gsqlitebackend")="no";
     ::arg().setSwitch("verbose","Verbose comments on operation")="no";
@@ -221,6 +249,8 @@ int main(int argc, char **argv)
       if(!::arg().mustDo("transactions"))
         cout<<"set autocommit on;"<<endl;
     }
+    else if(::arg().mustDo("mydns"))
+      g_mode=MYDNS;
     else {
       cerr<<"Unknown SQL mode!\n\n";
       cerr<<"syntax:"<<endl<<endl;
diff --git a/regression-tests/basic-loc/skip.mydns b/regression-tests/basic-loc/skip.mydns
new file mode 100644 (file)
index 0000000..599e152
--- /dev/null
@@ -0,0 +1 @@
+MYDNS backend does not support LOC record type.
diff --git a/regression-tests/double/skip.mydns b/regression-tests/double/skip.mydns
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/regression-tests/ds-at-secure-delegation/skip.mydns b/regression-tests/ds-at-secure-delegation/skip.mydns
new file mode 100644 (file)
index 0000000..e69de29
index 9b5e2351bb0559b3eee8c62ef9b40e1d9828176c..7b6de4f04ed6cf2b1ed811e84b39a7289b35b87a 100755 (executable)
@@ -43,6 +43,7 @@ gpgsql-nodnssec gpgsql gpgsql-nsec3
 gsqlite3-nodnssec gsqlite3 gsqlite3-nsec3
 opendbx-sqlite3
 tinydns
+mydns
 remotebackend-pipe remotebackend-unix remotebackend-http 
 remotebackend-pipe-dnssec remotebackend-unix-dnssec remotebackend-http-dnssec
 #remotebackend-pipe-nsec3 remotebackend-unix-nsec3 remotebackend-http-nsec3
@@ -149,6 +150,39 @@ __EOF__
                                --gmysql-password="$GMYSQLPASSWD" &
                        skipreasons=nodnssec
                        ;;
+               mydns)
+                       [ -z "$MYDNSDB" ] && MYDNSDB=pdnstest
+                       [ -z "$MYDNSUSER" ] && MYDNSUSER=root
+                       [ -z "$MYDNSHOST" ] && MYDNSHOST=localhost
+                       [ -z "$MYDNSPASSWD" ] && MYDNSPASSWD=''
+
+                       mysqladmin --user="$MYDNSUSER" --password="$MYDNSPASSWD" --host="$MYDNSHOST" --force drop "$MYDNSDB" \
+                               || echo ignoring mysqladmin drop failure
+                       mysqladmin --user="$MYDNSUSER" --password="$MYDNSPASSWD" --host="$MYDNSHOST" create "$MYDNSDB"
+                       mysql --user="$MYDNSUSER" --password="$MYDNSPASSWD" --host="$MYDNSHOST" \
+                               "$MYDNSDB" < ../modules/mydnsbackend/schema.sql
+
+                       tosql mydns | grep -v 'double\.example\.com' | mysql --user="$MYDNSUSER" --password="$MYDNSPASSWD" --host="$MYDNSHOST" \
+                               "$MYDNSDB"
+
+                       cat > pdns-mydns.conf << __EOF__
+launch=mydns
+mydns-dbname=$MYDNSDB
+mydns-user=$MYDNSUSER
+mydns-host=$MYDNSHOST
+mydns-password=$MYDNSPASSWD
+__EOF__
+                       $RUNWRAPPER ../pdns/pdns_server --daemon=no --local-port=$port --socket-dir=./  \
+                               --no-shuffle --launch=mydns --loglevel=99999 --query-logging=yes \
+                               --master --send-root-referral \
+                               --cache-ttl=0 --no-config \
+                               --mydns-rr-active=no --mydns-soa-active=no --mydns-use-minimal-ttl=no \
+                               --mydns-dbname="$MYDNSDB" \
+                               --mydns-user="$MYDNSUSER" \
+                               --mydns-host="$MYDNSHOST" \
+                               --mydns-password="$MYDNSPASSWD" &
+                       skipreasons="nodnssec noent"
+                       ;;
 
                gmysql | gmysql-nsec3 | gmysql-nsec3-narrow)
                        [ -z "$GMYSQLDB" ] && GMYSQLDB=pdnstest
diff --git a/regression-tests/very-long-txt/skip.mydns b/regression-tests/very-long-txt/skip.mydns
new file mode 100644 (file)
index 0000000..919c014
--- /dev/null
@@ -0,0 +1 @@
+MYDNS has only 128 chars of data.