diff --git a/CHANGELOG.md b/CHANGELOG.md index 00d11d479..099f9fa26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Init comment for MODIFY_PERMISSION, in case it's empty [#919](https://github.com/greenbone/gvmd/pull/919) - Fix Verinice ISM report format and update version [#963](https://github.com/greenbone/gvmd/pull/963) - Use right format specifier for merge_ovaldef version [#1053](https://github.com/greenbone/gvmd/pull/1053) +- Fix deletion of OVAL definition data [#1077](https://github.com/greenbone/gvmd/pull/1077) ### Removed diff --git a/src/manage_pg.c b/src/manage_pg.c index 95a491e87..00a609df0 100644 --- a/src/manage_pg.c +++ b/src/manage_pg.c @@ -3601,6 +3601,9 @@ manage_db_init (const gchar *name) sql ("CREATE OR REPLACE FUNCTION scap_delete_oval ()" " RETURNS TRIGGER AS $$" " BEGIN" + " DELETE FROM affected_ovaldefs" + " WHERE id IN (SELECT id FROM ovaldefs" + " WHERE ovaldefs.xml_file = old.xml_file);" " DELETE FROM ovaldefs WHERE ovaldefs.xml_file = old.xml_file;" " RETURN old;" " END;" diff --git a/src/manage_sql_secinfo.c b/src/manage_sql_secinfo.c index e3eccef52..578a7d76c 100644 --- a/src/manage_sql_secinfo.c +++ b/src/manage_sql_secinfo.c @@ -4494,9 +4494,9 @@ rebuild_scap (const char *type) || strcasecmp (type, "ovaldef") == 0) { g_debug ("%s: rebuilding ovaldefs", __FUNCTION__); - sql ("DELETE FROM ovalfiles"); sql ("DELETE FROM affected_ovaldefs"); sql ("DELETE FROM ovaldefs"); + sql ("DELETE FROM ovalfiles"); ret = update_scap (lockfile, TRUE, /* ignore_last_scap_update */ diff --git a/src/manage_sqlite3.c b/src/manage_sqlite3.c index 0214dc355..870aa02bf 100644 --- a/src/manage_sqlite3.c +++ b/src/manage_sqlite3.c @@ -4437,6 +4437,9 @@ manage_db_init (const gchar *name) sql ("CREATE TRIGGER scap.ovalfiles_delete AFTER DELETE" " ON ovalfiles" " BEGIN" + " DELETE FROM affected_ovaldefs" + " WHERE id IN (SELECT id FROM ovaldefs" + " WHERE ovaldefs.xml_file = old.xml_file);" " DELETE FROM ovaldefs WHERE ovaldefs.xml_file = old.xml_file;" " END;");