From: Mukund Sivaraman Date: Sun, 30 Sep 2012 19:15:45 +0000 (+0530) Subject: [1899] Add a unique constraint to nsec3 table X-Git-Tag: trac2351_base~3^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f284e18628afb282c1f5c9feec74b36abd9352be;p=thirdparty%2Fkea.git [1899] Add a unique constraint to nsec3 table This is to check that only one NSEC3 RR exists per owner name in a zone. The code to fix #1899 would depend on this assertion. --- diff --git a/src/bin/dbutil/dbutil.py.in b/src/bin/dbutil/dbutil.py.in index 4b76a5680e..f91c2768b7 100755 --- a/src/bin/dbutil/dbutil.py.in +++ b/src/bin/dbutil/dbutil.py.in @@ -193,10 +193,19 @@ UPGRADES = [ "ALTER TABLE schema_version " + "ADD COLUMN minor INTEGER NOT NULL DEFAULT 0" ] + }, + + {'from': (2, 0), 'to': (2, 1), + 'statements': [ + # Enforce that only one NSEC3 RR exists for an owner name in + # the zone. + "CREATE UNIQUE INDEX nsec3_by_zoneid_and_owner ON nsec3 " + + "(zone_id, owner)" + ] } # To extend this, leave the above statements in place and add another -# dictionary to the list. The "from" version should be (2, 0), the "to" +# dictionary to the list. The "from" version should be (2, 1), the "to" # version whatever the version the update is to, and the SQL statements are # the statements required to perform the upgrade. This way, the upgrade # program will be able to upgrade both a V1.0 and a V2.0 database. diff --git a/src/bin/dbutil/tests/dbutil_test.sh.in b/src/bin/dbutil/tests/dbutil_test.sh.in index f82eeb031d..35314e818e 100755 --- a/src/bin/dbutil/tests/dbutil_test.sh.in +++ b/src/bin/dbutil/tests/dbutil_test.sh.in @@ -165,7 +165,7 @@ upgrade_ok_test() { if [ $? -eq 0 ] then # Compare schema with the reference - get_schema $testdata/v2_0.sqlite3 + get_schema $testdata/v2_1.sqlite3 expected_schema=$db_schema get_schema $tempfile actual_schema=$db_schema @@ -177,7 +177,7 @@ upgrade_ok_test() { fi # Check the version is set correctly - check_version $tempfile "V2.0" + check_version $tempfile "V2.1" # Check that a backup was made check_backup $1 $2 @@ -449,7 +449,7 @@ copy_file $testdata/old_v1.sqlite3 $tempfile Yes . passzero $? -check_version $tempfile "V2.0" +check_version $tempfile "V2.1" rm -f $tempfile $backupfile echo "13.4 Interactive prompt - no" diff --git a/src/bin/dbutil/tests/testdata/Makefile.am b/src/bin/dbutil/tests/testdata/Makefile.am index 0d850a70f0..f4873f4b4e 100644 --- a/src/bin/dbutil/tests/testdata/Makefile.am +++ b/src/bin/dbutil/tests/testdata/Makefile.am @@ -10,3 +10,4 @@ EXTRA_DIST += old_v1.sqlite3 EXTRA_DIST += README EXTRA_DIST += too_many_version.sqlite3 EXTRA_DIST += v2_0.sqlite3 +EXTRA_DIST += v2_1.sqlite3 diff --git a/src/bin/dbutil/tests/testdata/v2_1.sqlite3 b/src/bin/dbutil/tests/testdata/v2_1.sqlite3 new file mode 100644 index 0000000000..9eea287452 Binary files /dev/null and b/src/bin/dbutil/tests/testdata/v2_1.sqlite3 differ diff --git a/src/lib/datasrc/sqlite3_accessor.cc b/src/lib/datasrc/sqlite3_accessor.cc index 24d7b3f72a..7a0ac9cc1f 100644 --- a/src/lib/datasrc/sqlite3_accessor.cc +++ b/src/lib/datasrc/sqlite3_accessor.cc @@ -42,7 +42,7 @@ namespace { // program may not be taking advantage of features (possibly performance // improvements) added to the database. const int SQLITE_SCHEMA_MAJOR_VERSION = 2; -const int SQLITE_SCHEMA_MINOR_VERSION = 0; +const int SQLITE_SCHEMA_MINOR_VERSION = 1; } namespace isc { @@ -325,7 +325,7 @@ public: const char* const SCHEMA_LIST[] = { "CREATE TABLE schema_version (version INTEGER NOT NULL, " "minor INTEGER NOT NULL DEFAULT 0)", - "INSERT INTO schema_version VALUES (2, 0)", + "INSERT INTO schema_version VALUES (2, 1)", "CREATE TABLE zones (id INTEGER PRIMARY KEY, " "name TEXT NOT NULL COLLATE NOCASE, " "rdclass TEXT NOT NULL COLLATE NOCASE DEFAULT 'IN', " @@ -351,6 +351,8 @@ const char* const SCHEMA_LIST[] = { "ttl INTEGER NOT NULL, rdtype TEXT NOT NULL COLLATE NOCASE, " "rdata TEXT NOT NULL)", "CREATE INDEX nsec3_byhash ON nsec3 (hash)", + // Enforce that only one NSEC3 RR exists for an owner name in the zone. + "CREATE UNIQUE INDEX nsec3_by_zoneid_and_owner ON nsec3 (zone_id, owner)", "CREATE TABLE diffs (id INTEGER PRIMARY KEY, " "zone_id INTEGER NOT NULL, " "version INTEGER NOT NULL, " diff --git a/src/lib/python/isc/datasrc/sqlite3_ds.py b/src/lib/python/isc/datasrc/sqlite3_ds.py index f9b47c0832..ef1245a303 100644 --- a/src/lib/python/isc/datasrc/sqlite3_ds.py +++ b/src/lib/python/isc/datasrc/sqlite3_ds.py @@ -25,7 +25,7 @@ RR_RDATA_INDEX = 7 # Current major and minor versions of schema SCHEMA_MAJOR_VERSION = 2 -SCHEMA_MINOR_VERSION = 0 +SCHEMA_MINOR_VERSION = 1 class Sqlite3DSError(Exception): """ Define exceptions.""" @@ -81,6 +81,9 @@ def create(cur): rdtype TEXT NOT NULL COLLATE NOCASE, rdata TEXT NOT NULL)""") cur.execute("CREATE INDEX nsec3_byhash ON nsec3 (hash)") + # Enforce that only one NSEC3 RR exists for an owner name in the zone. + cur.execute("""CREATE UNIQUE INDEX nsec3_by_zoneid_and_owner ON nsec3 + (zone_id, owner)"""); cur.execute("""CREATE TABLE diffs (id INTEGER PRIMARY KEY, zone_id INTEGER NOT NULL, version INTEGER NOT NULL,