declare( suffix, "database", "Filename of the SQLite3 database", "powerdns.sqlite" );
declare( suffix, "pragma-synchronous", "Set this to 0 for blazing speed", "" );
- string record_query = "SELECT content,ttl,prio,type,domain_id,disabled,name FROM records WHERE";
- string record_auth_query = "SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM records WHERE";
+ declare(suffix, "dnssec", "Enable DNSSEC processing","no");
+
+ string record_query = "SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM records WHERE";
declare(suffix, "basic-query", "Basic query", record_query+" disabled=0 and type='%s' and name='%s'");
declare(suffix, "id-query", "Basic with ID query", record_query+" disabled=0 and type='%s' and name='%s' and domain_id=%d");
declare(suffix, "wildcard-query", "Wildcard query", record_query+" disabled=0 and type='%s' and name like '%s'");
- declare(suffix, "wildcard-id-query", "Wildcard with ID query", record_query+" disabled=0 and type='%s' and name like '%s' and domain_id=%d");
+ declare(suffix, "wildcard-id-query", "Wildcard with ID query", record_query+" disabled=0 and type='%s' and name like '%s' and domain_id='%d'");
declare(suffix, "any-query", "Any query", record_query+" disabled=0 and name='%s'");
declare(suffix, "any-id-query", "Any with ID query", record_query+" disabled=0 and name='%s' and domain_id=%d");
declare(suffix, "wildcard-any-query", "Wildcard ANY query", record_query+" disabled=0 and name like '%s'");
- declare(suffix, "wildcard-any-id-query", "Wildcard ANY with ID query", record_query+" disabled=0 and name like '%s' and domain_id=%d");
+ declare(suffix, "wildcard-any-id-query", "Wildcard ANY with ID query", record_query+" disabled=0 and name like '%s' and domain_id='%d'");
- declare(suffix, "list-query", "AXFR query", record_query+" (disabled=0 OR %d) and domain_id=%d");
+ declare(suffix, "list-query", "AXFR query", record_query+" (disabled=0 OR %d) and domain_id='%d' order by name, type");
declare(suffix, "list-subzone-query", "Subzone listing", record_query+" disabled=0 and (name='%s' OR name like '%s') and domain_id=%d");
- declare(suffix,"remove-empty-non-terminals-from-zone-query", "remove all empty non-terminals from zone", "delete from records where domain_id='%d' and type is null");
- declare(suffix,"insert-empty-non-terminal-query", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,disabled) values ('%d','%s',null,0)");
- declare(suffix,"delete-empty-non-terminal-query", "delete empty non-terminal from zone", "delete from records where domain_id='%d' and name='%s' and type is null");
+ declare(suffix, "remove-empty-non-terminals-from-zone-query", "remove all empty non-terminals from zone", "delete from records where domain_id='%d' and type is null");
+ declare(suffix, "insert-empty-non-terminal-query", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,disabled,auth) values ('%d','%s',null,0,'1')");
+ declare(suffix, "delete-empty-non-terminal-query", "delete empty non-terminal from zone", "delete from records where domain_id='%d' and name='%s' and type is null");
- // and now with auth
- declare(suffix, "basic-query-auth", "Basic query", record_auth_query+" disabled=0 and type='%s' and name='%s'");
- declare(suffix, "id-query-auth", "Basic with ID query", record_auth_query+" disabled=0 and type='%s' and name='%s' and domain_id=%d");
- declare(suffix, "wildcard-query-auth", "Wildcard query", record_auth_query+" disabled=0 and type='%s' and name like '%s'");
- declare(suffix, "wildcard-id-query-auth", "Wildcard with ID query", record_auth_query+" disabled=0 and type='%s' and name like '%s' and domain_id='%d'");
+ declare( suffix, "master-zone-query", "Data", "select master from domains where name='%s' and type='SLAVE'");
- declare(suffix, "any-query-auth", "Any query", record_auth_query+" disabled=0 and name='%s'");
- declare(suffix, "any-id-query-auth", "Any with ID query", record_auth_query+" disabled=0 and name='%s' and domain_id=%d");
- declare(suffix, "wildcard-any-query-auth", "Wildcard ANY query", record_auth_query+" disabled=0 and name like '%s'");
- declare(suffix, "wildcard-any-id-query-auth", "Wildcard ANY with ID query", record_auth_query+" disabled=0 and name like '%s' and domain_id='%d'");
+ declare( suffix, "info-zone-query", "","select id,name,master,last_check,notified_serial,type from domains where name='%s'");
- declare(suffix, "list-query-auth", "AXFR query", record_auth_query+" (disabled=0 OR %d) and domain_id='%d' order by name, type");
- declare(suffix, "list-subzone-query-auth", "Subzone listing", record_auth_query+" disabled=0 and (name='%s' OR name like '%s') and domain_id=%d");
+ declare( suffix, "info-all-slaves-query", "","select id,name,master,last_check,type from domains where type='SLAVE'");
+ declare( suffix, "supermaster-query", "", "select account from supermasters where ip='%s' and nameserver='%s'");
+ declare( suffix, "supermaster-name-to-ips", "", "select ip from supermasters where nameserver='%s'");
+
+ declare( suffix, "insert-zone-query", "", "insert into domains (type,name) values('NATIVE','%s')");
+ declare( suffix, "insert-slave-query", "", "insert into domains (type,name,master,account) values('SLAVE','%s','%s','%s')");
+
+ declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values ('%s',%d,%d,'%s',%d,%d,'%s',%d)");
+ declare(suffix, "insert-record-order-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,ordername,auth) values ('%s',%d,%d,'%s',%d,%d,'%s','%s','%d')");
+ declare(suffix, "insert-ent-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,auth) values (null,'%d',0,'%s','%d')");
+ declare(suffix, "insert-ent-order-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,ordername,auth) values (null,'%d',0,'%s','%s','%d')");
- declare(suffix, "insert-empty-non-terminal-query-auth", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,disabled,auth) values ('%d','%s',null,0,'1')");
-
declare(suffix, "get-order-first-query", "DNSSEC Ordering Query, first", "select ordername, name from records where disabled=0 and domain_id=%d and ordername is not null order by 1 asc limit 1");
declare(suffix, "get-order-before-query", "DNSSEC Ordering Query, before", "select ordername, name from records where disabled=0 and ordername <= '%s' and domain_id=%d and ordername is not null order by 1 desc limit 1");
declare(suffix, "get-order-after-query", "DNSSEC Ordering Query, after", "select min(ordername) from records where disabled=0 and ordername > '%s' and domain_id=%d and ordername is not null");
declare(suffix, "get-order-last-query", "DNSSEC Ordering Query, last", "select ordername, name from records where disabled=0 and ordername != '' and domain_id=%d and ordername is not null order by 1 desc limit 1");
declare(suffix, "set-order-and-auth-query", "DNSSEC set ordering query", "update records set ordername='%s',auth=%d where name='%s' and domain_id='%d' and disabled=0");
+ declare(suffix, "set-auth-on-ds-record-query", "DNSSEC set auth on a DS record", "update records set auth=1 where domain_id='%d' and name='%s' and type='DS' and disabled=0");
declare(suffix, "nullify-ordername-and-update-auth-query", "DNSSEC nullify ordername and update auth query", "update records set ordername=NULL,auth=%d where domain_id='%d' and name='%s' and disabled=0");
declare(suffix, "nullify-ordername-and-auth-query", "DNSSEC nullify ordername and auth query", "update records set ordername=NULL,auth=0 where name='%s' and type='%s' and domain_id='%d' and disabled=0");
- declare(suffix, "set-auth-on-ds-record-query", "DNSSEC set auth on a DS record", "update records set auth=1 where domain_id='%d' and name='%s' and type='DS' and disabled=0");
-
- declare( suffix, "master-zone-query", "Data", "select master from domains where name='%s' and type='SLAVE'");
-
- declare( suffix, "info-zone-query", "","select id,name,master,last_check,notified_serial,type from domains where name='%s'");
-
- declare( suffix, "info-all-slaves-query", "","select id,name,master,last_check,type from domains where type='SLAVE'");
- declare( suffix, "supermaster-query", "", "select account from supermasters where ip='%s' and nameserver='%s'");
- declare( suffix, "supermaster-name-to-ips", "", "select ip from supermasters where nameserver='%s'");
- declare( suffix, "insert-zone-query", "", "insert into domains (type,name) values('NATIVE','%s')");
- declare( suffix, "insert-slave-query", "", "insert into domains (type,name,master,account) values('SLAVE','%s','%s','%s')");
-
- declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name) values ('%s',%d,%d,'%s',%d,%d,'%s')");
- declare(suffix, "insert-record-query-auth", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values ('%s',%d,%d,'%s',%d,%d,'%s',%d)");
- declare(suffix, "insert-record-order-query-auth", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,ordername,auth) values ('%s',%d,%d,'%s',%d,%d,'%s','%s',%d)");
- declare(suffix, "insert-ent-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name) values (null,'%d',0,'%s')");
- declare(suffix, "insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,auth) values (null,'%d',0,'%s','%d')");
- declare(suffix, "insert-ent-order-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,ordername,auth) values (null,'%d',0,'%s','%s','%d')");
declare( suffix, "update-master-query", "", "update domains set master='%s' where name='%s'");
declare( suffix, "update-kind-query", "", "update domains set type='%s' where name='%s'");
declare( suffix, "delete-zone-query", "", "delete from records where domain_id=%d");
declare( suffix, "delete-rrset-query", "", "delete from records where domain_id = %d and name='%s' and type='%s'");
declare( suffix, "delete-names-query", "", "delete from records where domain_id = %d and name='%s'");
- declare(suffix, "dnssec", "Assume DNSSEC Schema is in place","no");
declare(suffix,"add-domain-key-query","", "insert into cryptokeys (domain_id, flags, active, content) select id, %d, %d, '%s' from domains where name='%s'");
declare(suffix,"list-domain-keys-query","", "select cryptokeys.id, flags, active, content from domains, cryptokeys where cryptokeys.domain_id=domains.id and name='%s'");
declare(suffix, "delete-comment-rrset-query", "", "DELETE FROM comments WHERE domain_id=%d AND name='%s' AND type='%s'");
declare(suffix, "delete-comments-query", "", "DELETE FROM comments WHERE domain_id=%d");
}
-
+
//! Constructs a new gSQLite3Backend object.
DNSBackend *make( const string & suffix = "" )
{
--- /dev/null
+CREATE TABLE domains (
+ id INTEGER PRIMARY KEY,
+ name VARCHAR(255) NOT NULL COLLATE NOCASE,
+ master VARCHAR(128) DEFAULT NULL,
+ last_check INTEGER DEFAULT NULL,
+ type VARCHAR(6) NOT NULL,
+ notified_serial INTEGER DEFAULT NULL,
+ account VARCHAR(40) DEFAULT NULL
+);
+
+CREATE UNIQUE INDEX name_index ON domains(name);
+
+
+
+CREATE TABLE records (
+ id INTEGER PRIMARY KEY,
+ domain_id INTEGER DEFAULT NULL,
+ name VARCHAR(255) DEFAULT NULL,
+ type VARCHAR(10) DEFAULT NULL,
+ content VARCHAR(65535) DEFAULT NULL,
+ ttl INTEGER DEFAULT NULL,
+ prio INTEGER DEFAULT NULL,
+ change_date INTEGER DEFAULT NULL,
+ disabled BOOLEAN DEFAULT 0,
+ ordername VARCHAR(255),
+ auth BOOL DEFAULT 1
+);
+
+CREATE INDEX rec_name_index ON records(name);
+CREATE INDEX nametype_index ON records(name,type);
+CREATE INDEX domain_id ON records(domain_id);
+CREATE INDEX orderindex ON records(ordername);
+
+
+
+CREATE TABLE supermasters (
+ ip VARCHAR(64) NOT NULL,
+ nameserver VARCHAR(255) NOT NULL COLLATE NOCASE,
+ account VARCHAR(40) DEFAULT NULL
+);
+
+CREATE UNIQUE INDEX ip_nameserver_pk ON supermasters(ip, nameserver);
+
+
+
+CREATE TABLE comments (
+ id INTEGER PRIMARY KEY,
+ domain_id INTEGER NOT NULL,
+ name VARCHAR(255) NOT NULL,
+ type VARCHAR(10) NOT NULL,
+ modified_at INT NOT NULL,
+ account VARCHAR(40) DEFAULT NULL,
+ comment VARCHAR(65535) NOT NULL
+);
+
+CREATE INDEX comments_domain_id_index ON comments (domain_id);
+CREATE INDEX comments_nametype_index ON comments (name, type);
+CREATE INDEX comments_order_idx ON comments (domain_id, modified_at);
+
+
+
+CREATE TABLE domainmetadata (
+ id INTEGER PRIMARY KEY,
+ domain_id INT NOT NULL,
+ kind VARCHAR(16) COLLATE NOCASE,
+ content TEXT
+);
+
+CREATE INDEX domainmetaidindex ON domainmetadata(domain_id);
+
+
+
+CREATE TABLE cryptokeys (
+ id INTEGER PRIMARY KEY,
+ domain_id INT NOT NULL,
+ flags INT NOT NULL,
+ active BOOL,
+ content TEXT
+);
+
+CREATE INDEX domainidindex ON cryptokeys(domain_id);
+
+
+
+CREATE TABLE tsigkeys (
+ id INTEGER PRIMARY KEY,
+ name VARCHAR(255) COLLATE NOCASE,
+ algorithm VARCHAR(50) COLLATE NOCASE,
+ secret VARCHAR(255)
+);
+
+CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);