Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recreate vulns after sync #1292

Merged
merged 4 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 40 additions & 31 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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. */

Expand Down
3 changes: 3 additions & 0 deletions src/manage_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
3 changes: 3 additions & 0 deletions src/manage_sql_secinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;");
Expand Down