diff --git a/CHANGELOG.md b/CHANGELOG.md index ae45dc718..e3a0066cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Replace deprecated sys_siglist with strsignal [#1280](https://github.com/greenbone/gvmd/pull/1280) - Copy instead of moving when migrating predefined report formats [#1286](https://github.com/greenbone/gvmd/pull/1286) - Skip DB check in helpers when main process is running [#1291](https://github.com/greenbone/gvmd/pull/1291) +- Recreate vulns after sync [#1292](https://github.com/greenbone/gvmd/pull/1292) - For radio prefs in GMP exclude value and include default [#1296](https://github.com/greenbone/gvmd/pull/1296) ### Removed diff --git a/src/manage_pg.c b/src/manage_pg.c index 9359fad71..651754dd5 100644 --- a/src/manage_pg.c +++ b/src/manage_pg.c @@ -1712,6 +1712,45 @@ manage_create_result_indexes () " (SELECT nvt FROM results" \ " WHERE (results.severity != " G_STRINGIFY (SEVERITY_ERROR) "))" +/** + * @brief Create or replace the vulns view. + */ +void +create_view_vulns () +{ + if (sql_int ("SELECT EXISTS (SELECT * FROM information_schema.tables" + " WHERE table_catalog = '%s'" + " AND table_schema = 'scap'" + " AND table_name = 'ovaldefs')" + " ::integer;", + sql_database ())) + sql ("CREATE OR REPLACE VIEW vulns AS" + " SELECT id, uuid, name, creation_time, modification_time," + " cast (cvss_base AS double precision) AS severity, qod," + " 'nvt' AS type" + " FROM nvts" + VULNS_RESULTS_WHERE + " UNION SELECT id, uuid, name, creation_time, modification_time," + " cvss AS severity, " G_STRINGIFY (QOD_DEFAULT) " AS qod," + " 'cve' AS type" + " FROM cves" + VULNS_RESULTS_WHERE + " UNION SELECT id, uuid, name, creation_time, modification_time," + " max_cvss AS severity, " G_STRINGIFY (QOD_DEFAULT) " AS qod," + " 'ovaldef' AS type" + " FROM ovaldefs" + VULNS_RESULTS_WHERE); + else + sql ("CREATE OR REPLACE VIEW vulns AS" + " SELECT id, uuid, name, creation_time, modification_time," + " cast (cvss_base AS double precision) AS severity, qod," + " 'nvt' AS type" + " FROM nvts" + VULNS_RESULTS_WHERE); +} + +#undef VULNS_RESULTS_WHERE + /** * @brief Create all tables. */ @@ -2862,37 +2901,7 @@ create_tables () " JOIN tls_certificate_origins AS origins" " ON sources.origin = origins.id;"); - if (sql_int ("SELECT EXISTS (SELECT * FROM information_schema.tables" - " WHERE table_catalog = '%s'" - " AND table_schema = 'scap'" - " AND table_name = 'ovaldefs')" - " ::integer;", - sql_database ())) - sql ("CREATE OR REPLACE VIEW vulns AS" - " SELECT id, uuid, name, creation_time, modification_time," - " cast (cvss_base AS double precision) AS severity, qod," - " 'nvt' AS type" - " FROM nvts" - VULNS_RESULTS_WHERE - " UNION SELECT id, uuid, name, creation_time, modification_time," - " cvss AS severity, " G_STRINGIFY (QOD_DEFAULT) " AS qod," - " 'cve' AS type" - " FROM cves" - VULNS_RESULTS_WHERE - " UNION SELECT id, uuid, name, creation_time, modification_time," - " max_cvss AS severity, " G_STRINGIFY (QOD_DEFAULT) " AS qod," - " 'ovaldef' AS type" - " FROM ovaldefs" - VULNS_RESULTS_WHERE); - else - sql ("CREATE OR REPLACE VIEW vulns AS" - " SELECT id, uuid, name, creation_time, modification_time," - " cast (cvss_base AS double precision) AS severity, qod," - " 'nvt' AS type" - " FROM nvts" - VULNS_RESULTS_WHERE); - -#undef VULNS_RESULTS_WHERE + create_view_vulns (); /* Create indexes. */ diff --git a/src/manage_sql.h b/src/manage_sql.h index b979b4b39..66e3346ee 100644 --- a/src/manage_sql.h +++ b/src/manage_sql.h @@ -481,4 +481,7 @@ void add_role_permission_resource (const gchar *, const gchar *, const gchar *, const gchar *); +void +create_view_vulns (); + #endif /* not _GVMD_MANAGE_SQL_H */ diff --git a/src/manage_sql_secinfo.c b/src/manage_sql_secinfo.c index eea7f4838..f1a9205f9 100644 --- a/src/manage_sql_secinfo.c +++ b/src/manage_sql_secinfo.c @@ -4711,6 +4711,9 @@ update_scap_end () sql ("ALTER SCHEMA scap RENAME TO scap3;"); sql ("ALTER SCHEMA scap2 RENAME TO scap;"); sql ("DROP SCHEMA scap3 CASCADE;"); + /* View 'vulns' contains references into the SCAP schema, so it is + * removed by the CASCADE. */ + create_view_vulns (); } else sql ("ALTER SCHEMA scap2 RENAME TO scap;");