Permalink
Browse files

don't import supermaster ips from other accounts

  • Loading branch information...
1 parent b5667bb commit dd930ede3644c18ba33096f15f74cf2bbb9d9e52 @mind04 mind04 committed with mind04 Sep 8, 2014
@@ -10,6 +10,7 @@ ALTER TABLE records MODIFY auth TINYINT(1) DEFAULT 1;
ALTER TABLE records MODIFY type VARCHAR(10);
ALTER TABLE supermasters MODIFY ip VARCHAR(64) NOT NULL;
ALTER TABLE supermasters ADD PRIMARY KEY(ip, nameserver);
+ALTER TABLE supermasters MODIFY account VARCHAR(40) NOT NULL;
ALTER TABLE domainmetadata MODIFY kind VARCHAR(32);
ALTER TABLE tsigkeys MODIFY algorithm VARCHAR(50);
ALTER TABLE domainmetadata ENGINE=InnoDB;
@@ -70,7 +70,7 @@ class gMySQLFactory : public BackendFactory
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,"supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver='%s' and account='%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')");
@@ -7,6 +7,7 @@ ALTER TABLE records ADD ordername VARCHAR(255) BINARY DEFAULT NULL;
ALTER TABLE records ADD auth TINYINT(1) DEFAULT 1;
ALTER TABLE records MODIFY type VARCHAR(10);
ALTER TABLE supermasters MODIFY ip VARCHAR(64) NOT NULL;
+ALTER TABLE supermasters MODIFY account VARCHAR(40) NOT NULL;
ALTER TABLE supermasters ADD PRIMARY KEY(ip, nameserver);
CREATE INDEX recordorder ON records (domain_id, ordername);
@@ -35,7 +35,7 @@ CREATE INDEX recordorder ON records (domain_id, ordername);
CREATE TABLE supermasters (
ip VARCHAR(64) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
- account VARCHAR(40) DEFAULT NULL,
+ account VARCHAR(40) NOT NULL,
PRIMARY KEY (ip, nameserver)
) Engine=InnoDB;
@@ -77,7 +77,7 @@ class gOracleFactory : public BackendFactory
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,"supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver='%s' and account='%s'");
declare(suffix,"insert-zone-query","", "insert into domains (id, type, name) values(domain_id_sequence.nextval, 'NATIVE','%s')");
declare(suffix,"insert-slave-query","", "insert into domains (id, type,name,master,account) values(domain_id_sequence.nextval, 'SLAVE','%s','%s','%s')");
@@ -37,7 +37,7 @@ CREATE INDEX records$recordorder ON records (domain_id, ordername);
CREATE TABLE supermasters (
ip VARCHAR2(64) NOT NULL,
nameserver VARCHAR2(255) NOT NULL,
- account VARCHAR2(40) DEFAULT NULL,
+ account VARCHAR2(40) NOT NULL,
PRIMARY KEY (ip, nameserver)
);
@@ -7,6 +7,7 @@ ALTER TABLE records ALTER COLUMN content TYPE VARCHAR(65535);
ALTER TABLE records ALTER COLUMN auth SET DEFAULT 't';
ALTER TABLE records ALTER COLUMN type TYPE VARCHAR(10);
ALTER TABLE supermasters ALTER COLUMN ip TYPE INET USING ip::INET;
+ALTER TABLE supermasters ALTER COLUMN account SET DEFAULT NOT NULL;
ALTER TABLE supermasters ADD CONSTRAINT supermasters_pkey PRIMARY KEY (ip, nameserver);
ALTER TABLE domainmetadata ALTER COLUMN kind TYPE VARCHAR(32);
ALTER TABLE tsigkeys ALTER COLUMN algorithm TYPE VARCHAR(50);
@@ -64,7 +64,7 @@ class gPgSQLFactory : public BackendFactory
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=E'%s'");
- declare(suffix,"supermaster-name-to-ips", "", "select ip from supermasters where nameserver=E'%s'");
+ declare(suffix,"supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver=E'%s' and account=E'%s'");
declare(suffix,"insert-zone-query","", "insert into domains (type,name) values('NATIVE',E'%s')");
declare(suffix,"insert-slave-query","", "insert into domains (type,name,master,account) values('SLAVE',E'%s',E'%s',E'%s')");
@@ -7,6 +7,7 @@ ALTER TABLE records ADD ordername VARCHAR(255);
ALTER TABLE records ADD auth BOOL DEFAULT 't';
ALTER TABLE records ALTER COLUMN type TYPE VARCHAR(10);
ALTER TABLE supermasters ALTER COLUMN ip TYPE INET USING ip::INET;
+ALTER TABLE supermasters ALTER COLUMN account SET DEFAULT NOT NULL;
ALTER TABLE supermasters ADD CONSTRAINT supermasters_pkey PRIMARY KEY (ip, nameserver);
CREATE INDEX recordorder ON records (domain_id, ordername text_pattern_ops);
@@ -39,7 +39,7 @@ CREATE INDEX recordorder ON records (domain_id, ordername text_pattern_ops);
CREATE TABLE supermasters (
ip INET NOT NULL,
nameserver VARCHAR(255) NOT NULL,
- account VARCHAR(40) DEFAULT NULL,
+ account VARCHAR(40) NOT NULL,
PRIMARY KEY(ip, nameserver)
);
@@ -62,12 +62,13 @@ BEGIN TRANSACTION;
);
INSERT INTO supermasters_backup SELECT ip,nameserver,account FROM supermasters;
+ UPDATE supermasters_backup SET account='' WHERE account IS NULL;
DROP TABLE supermasters;
CREATE TABLE supermasters (
ip VARCHAR(64) NOT NULL,
nameserver VARCHAR(255) NOT NULL COLLATE NOCASE,
- account VARCHAR(40) DEFAULT NULL
+ account VARCHAR(40) NOT NULL
);
CREATE UNIQUE INDEX ip_nameserver_pk ON supermasters(ip, nameserver);
@@ -80,7 +80,7 @@ class gSQLite3Factory : public BackendFactory
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, "supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver='%s' and account='%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')");
@@ -59,12 +59,13 @@ BEGIN TRANSACTION;
);
INSERT INTO supermasters_backup SELECT ip, nameserver, account FROM supermasters;
+ UPDATE supermasters_backup SET account='' WHERE account IS NULL;
DROP TABLE supermasters;
CREATE TABLE supermasters (
ip VARCHAR(64) NOT NULL,
nameserver VARCHAR(255) NOT NULL COLLATE NOCASE,
- account VARCHAR(40) DEFAULT NULL
+ account VARCHAR(40) NOT NULL
);
CREATE UNIQUE INDEX ip_nameserver_pk ON supermasters(ip, nameserver);
@@ -34,7 +34,7 @@ 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
+ account VARCHAR(40) NOT NULL
);
CREATE UNIQUE INDEX ip_nameserver_pk ON supermasters(ip, nameserver);
@@ -918,13 +918,14 @@ bool GSQLBackend::createSlaveDomain(const string &ip, const string &domain, cons
if (!nameserver.empty()) {
// figure out all IP addresses for the master
format = d_GetSuperMasterIPs;
- snprintf(output,sizeof(output)-1,format.c_str(),sqlEscape(nameserver).c_str());
+ snprintf(output,sizeof(output)-1,format.c_str(),sqlEscape(nameserver).c_str(),sqlEscape(account).c_str());
d_db->doQuery(output, d_result);
if (!d_result.empty()) {
// collect all IP addresses
vector<string> tmp;
BOOST_FOREACH(SSql::row_t& row, d_result) {
- tmp.push_back(row[0]);
+ if (account == row[1])
+ tmp.push_back(row[0]);
}
// set them as domain's masters, comma separated
masters = boost::join(tmp, ", ");

0 comments on commit dd930ed

Please sign in to comment.