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;
}
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;
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());
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 = "") {
string d_soawhere;
string d_rrwhere;
string d_origin;
+ bool d_useminimalttl;
unsigned int d_minimum;
};
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)
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)
+);
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;
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;
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;
+ }
+ }
}
::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";
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;
--- /dev/null
+MYDNS backend does not support LOC record type.
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
--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
--- /dev/null
+MYDNS has only 128 chars of data.