mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 22:15:23 +00:00
[#2299] Create subnet audit entry when network is deleted
Update subnets in shared-network BDEL trigger rather than relying on foreign key update action new files: src/share/database/scripts/mysql/upgrade_013_to_014.sh.in src/share/database/scripts/pgsql/upgrade_011_to_012.sh.in configure.ac added: src/share/database/scripts/mysql/upgrade_013_to_014.sh src/share/database/scripts/pgsql/upgrade_011_to_012.sh src/bin/admin/tests/mysql_tests.sh.in added 13 to 14 checks src/bin/admin/tests/pgsql_tests.sh.in added 11 to 12 checks src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc enabled disabled tests src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc GenericConfigBackendDHCPv4Test::getAllSharedNetworks4Test() - updated expected audit entry order src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc GenericConfigBackendDHCPv6Test::getAllSharedNetworks6Test() - updated expected audit entry order src/lib/mysql/mysql_constants.h Updated schema version to 14 src/lib/pgsql/pgsql_connection.h Updated schema version to 12 src/share/database/scripts/mysql/.gitignore src/share/database/scripts/mysql/Makefile.am added upgrade_013_to_014.sh src/share/database/scripts/mysql/dhcpdb_create.mysql subnet rows are now updated directly in shared-network BEFORE delete triggers (v4 and v6) src/share/database/scripts/pgsql/Makefile.am added upgrade_011_to_012.sh src/share/database/scripts/pgsql/dhcpdb_create.pgsql subnet rows are now updated directly in shared-network BEFORE delete triggers (v4 and v6)
This commit is contained in:
1
src/share/database/scripts/mysql/.gitignore
vendored
1
src/share/database/scripts/mysql/.gitignore
vendored
@@ -21,4 +21,5 @@
|
||||
/upgrade_010_to_011.sh
|
||||
/upgrade_011_to_012.sh
|
||||
/upgrade_012_to_013.sh
|
||||
/upgrade_013_to_014.sh
|
||||
/wipe_data.sh
|
||||
|
@@ -32,6 +32,7 @@ mysql_SCRIPTS += upgrade_009.6_to_010.0.sh
|
||||
mysql_SCRIPTS += upgrade_010_to_011.sh
|
||||
mysql_SCRIPTS += upgrade_011_to_012.sh
|
||||
mysql_SCRIPTS += upgrade_012_to_013.sh
|
||||
mysql_SCRIPTS += upgrade_013_to_014.sh
|
||||
mysql_SCRIPTS += wipe_data.sh
|
||||
|
||||
DISTCLEANFILES = ${mysql_SCRIPTS}
|
||||
|
@@ -4286,6 +4286,70 @@ UPDATE schema_version
|
||||
|
||||
-- This line concludes database upgrade to version 13.
|
||||
|
||||
-- Modify shared-network-name foreign key contraint on dhcp4_subnet to not perform
|
||||
-- the update when the network is deleted the cascaded update will not execute
|
||||
-- dhcp4_subnet update trigger leaving the updated subnets without audit_entries.
|
||||
ALTER TABLE dhcp4_subnet
|
||||
DROP FOREIGN KEY fk_dhcp4_subnet_shared_network;
|
||||
|
||||
ALTER TABLE dhcp4_subnet
|
||||
ADD CONSTRAINT fk_dhcp4_subnet_shared_network FOREIGN KEY (shared_network_name)
|
||||
REFERENCES dhcp4_shared_network (name)
|
||||
ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||
|
||||
-- Modify BEFORE delete trigger on dhcp4_shared_network to explicitly
|
||||
-- update dhcp4_subnets. This ensures there are audit entries for updated
|
||||
-- subnets.
|
||||
DROP TRIGGER dhcp4_shared_network_BDEL;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE TRIGGER dhcp4_shared_network_BDEL BEFORE DELETE ON dhcp4_shared_network
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
CALL createAuditEntryDHCP4('dhcp4_shared_network', OLD.id, "delete");
|
||||
-- In MySQL Foreign key constraint triggered updates will not cascade, so we explicitly
|
||||
-- update subnets first which should ensure they get audit entries.
|
||||
UPDATE dhcp4_subnet SET shared_network_name = NULL WHERE shared_network_name = OLD.name;
|
||||
DELETE FROM dhcp4_options WHERE shared_network_name = OLD.name;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
-- Modify shared-network-name foreign key contraint on dhcp6_subnet to not perform
|
||||
-- the update when the network is deleted the cascaded update will not execute
|
||||
-- dhcp6_subnet update trigger leaving the updated subnets without audit_entries.
|
||||
ALTER TABLE dhcp6_subnet
|
||||
DROP FOREIGN KEY fk_dhcp6_subnet_shared_network;
|
||||
|
||||
ALTER TABLE dhcp6_subnet
|
||||
ADD CONSTRAINT fk_dhcp6_subnet_shared_network FOREIGN KEY (shared_network_name)
|
||||
REFERENCES dhcp6_shared_network (name)
|
||||
ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||
|
||||
-- Modify BEFORE delete trigger on dhcp6_shared_network to explicitly
|
||||
-- update dhcp6_subnets. This ensures there are audit entries for updated
|
||||
-- subnets.
|
||||
DROP TRIGGER dhcp6_shared_network_BDEL;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE TRIGGER dhcp6_shared_network_BDEL BEFORE DELETE ON dhcp6_shared_network
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
CALL createAuditEntryDHCP6('dhcp6_shared_network', OLD.id, "delete");
|
||||
-- In MySQL Foreign key constraint triggered updates will not cascade, so we explicitly
|
||||
-- update subnets first which should ensure they get audit entries.
|
||||
UPDATE dhcp6_subnet SET shared_network_name = NULL WHERE shared_network_name = OLD.name;
|
||||
DELETE FROM dhcp6_options WHERE shared_network_name = OLD.name;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
-- Update the schema version number.
|
||||
UPDATE schema_version
|
||||
SET version = '14', minor = '0';
|
||||
|
||||
|
||||
|
||||
-- This line concludes database upgrade to version 14.
|
||||
|
||||
# Notes:
|
||||
#
|
||||
# Indexes
|
||||
|
116
src/share/database/scripts/mysql/upgrade_013_to_014.sh.in
Normal file
116
src/share/database/scripts/mysql/upgrade_013_to_014.sh.in
Normal file
@@ -0,0 +1,116 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
# SC1091: Not following: ... was not specified as input (see shellcheck -x).
|
||||
|
||||
# Exit with error if commands exit with non-zero and if undefined variables are
|
||||
# used.
|
||||
set -eu
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
# SC2034: ... appears unused. Verify use (or export if used externally).
|
||||
prefix="@prefix@"
|
||||
|
||||
# Include utilities. Use installed version if available and
|
||||
# use build version if it isn't.
|
||||
if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
|
||||
. "@datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh"
|
||||
else
|
||||
. "@abs_top_builddir@/src/bin/admin/admin-utils.sh"
|
||||
fi
|
||||
|
||||
# Check version.
|
||||
version=$(mysql_version "${@}")
|
||||
if test "${version}" != "13.0"; then
|
||||
printf 'This script upgrades 13.0 to 14.0. '
|
||||
printf 'Reported version is %s. Skipping upgrade.\n' "${version}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Get the schema name from database argument. We need this to
|
||||
# query information_schema for the right database.
|
||||
for arg in "${@}"
|
||||
do
|
||||
if ! printf '%s' "${arg}" | grep -Eq '^\-\-'
|
||||
then
|
||||
schema="$arg"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Make sure we have the schema.
|
||||
if [ -z "$schema" ]
|
||||
then
|
||||
printf "Could not find database schema name in cmd line args: %s\n" "${*}"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
mysql "$@" <<EOF
|
||||
-- Modify shared-network-name foreign key contraint on dhcp4_subnet to not perform
|
||||
-- the update when the network is deleted the cascaded update will not execute
|
||||
-- dhcp4_subnet update trigger leaving the updated subnets without audit_entries.
|
||||
ALTER TABLE dhcp4_subnet
|
||||
DROP FOREIGN KEY fk_dhcp4_subnet_shared_network;
|
||||
|
||||
ALTER TABLE dhcp4_subnet
|
||||
ADD CONSTRAINT fk_dhcp4_subnet_shared_network FOREIGN KEY (shared_network_name)
|
||||
REFERENCES dhcp4_shared_network (name)
|
||||
ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||
|
||||
-- Modify BEFORE delete trigger on dhcp4_shared_network to explicitly
|
||||
-- update dhcp4_subnets. This ensures there are audit entries for updated
|
||||
-- subnets.
|
||||
DROP TRIGGER dhcp4_shared_network_BDEL;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE TRIGGER dhcp4_shared_network_BDEL BEFORE DELETE ON dhcp4_shared_network
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
CALL createAuditEntryDHCP4('dhcp4_shared_network', OLD.id, "delete");
|
||||
-- In MySQL Foreign key constraint triggered updates will not cascade, so we explicitly
|
||||
-- update subnets first which should ensure they get audit entries.
|
||||
UPDATE dhcp4_subnet SET shared_network_name = NULL WHERE shared_network_name = OLD.name;
|
||||
DELETE FROM dhcp4_options WHERE shared_network_name = OLD.name;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
-- Modify shared-network-name foreign key contraint on dhcp6_subnet to not perform
|
||||
-- the update when the network is deleted the cascaded update will not execute
|
||||
-- dhcp6_subnet update trigger leaving the updated subnets without audit_entries.
|
||||
ALTER TABLE dhcp6_subnet
|
||||
DROP FOREIGN KEY fk_dhcp6_subnet_shared_network;
|
||||
|
||||
ALTER TABLE dhcp6_subnet
|
||||
ADD CONSTRAINT fk_dhcp6_subnet_shared_network FOREIGN KEY (shared_network_name)
|
||||
REFERENCES dhcp6_shared_network (name)
|
||||
ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||
|
||||
-- Modify BEFORE delete trigger on dhcp6_shared_network to explicitly
|
||||
-- update dhcp4_subnets. This ensures there are audit entries for updated
|
||||
-- subnets.
|
||||
DROP TRIGGER dhcp6_shared_network_BDEL;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE TRIGGER dhcp6_shared_network_BDEL BEFORE DELETE ON dhcp6_shared_network
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
CALL createAuditEntryDHCP6('dhcp6_shared_network', OLD.id, "delete");
|
||||
-- In MySQL Foreign key constraint triggered updates will not cascade, so we explicitly
|
||||
-- update subnets first which should ensure they get audit entries.
|
||||
UPDATE dhcp6_subnet SET shared_network_name = NULL WHERE shared_network_name = OLD.name;
|
||||
DELETE FROM dhcp6_options WHERE shared_network_name = OLD.name;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
-- Update the schema version number.
|
||||
UPDATE schema_version
|
||||
SET version = '14', minor = '0';
|
||||
|
||||
-- This line concludes database upgrade to version 14.
|
||||
EOF
|
Reference in New Issue
Block a user