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

Drop bid and xref from table nvts #582

Merged
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ include (CPack)

## Variables

set (GVMD_DATABASE_VERSION 209)
set (GVMD_DATABASE_VERSION 210)

set (GVMD_SCAP_DATABASE_VERSION 15)

Expand Down
42 changes: 42 additions & 0 deletions src/manage_migrators.c
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,47 @@ migrate_208_to_209 ()
return 0;
}

/**
* @brief Migrate the database from version 208 to version 209.
*
* @return 0 success, -1 error.
*/
int
migrate_209_to_210 ()
{
sql_begin_immediate ();

/* Ensure that the database is currently version 209. */

if (manage_db_version () != 209)
{
sql_rollback ();
return -1;
}

/* Do nothing when SQLite is used. During a later
* migration the columns will automatically be removed.
*/
if (! sql_is_sqlite3 ())
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
{

/* Update the database. */

/* Remove the fields "bid" and "xref" from table "nvts". */

sql ("ALTER TABLE IF EXISTS nvts DROP COLUMN bid CASCADE;");
sql ("ALTER TABLE IF EXISTS nvts DROP COLUMN xref CASCADE;");
}

/* Set the database version to 210. */

set_db_version (210);

sql_commit ();

return 0;
}

#undef UPDATE_DASHBOARD_SETTINGS

/**
Expand Down Expand Up @@ -1773,6 +1814,7 @@ static migrator_t database_migrators[] = {
{207, migrate_206_to_207},
{208, migrate_207_to_208},
{209, migrate_208_to_209},
{210, migrate_209_to_210},
/* End marker. */
{-1, NULL}};

Expand Down
4 changes: 1 addition & 3 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2014-2018 Greenbone Networks GmbH
/* Copyright (C) 2014-2019 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
Expand Down Expand Up @@ -2861,8 +2861,6 @@ create_tables ()
" name text,"
" comment text,"
" cve text,"
" bid text,"
" xref text,"
" tag text,"
" category text,"
" family text,"
Expand Down
26 changes: 20 additions & 6 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -15535,19 +15535,33 @@ update_nvti_cache ()
nvti_cache = nvtis_new ();

init_iterator (&nvts,
"SELECT oid, name, family, cvss_base, cve, bid, xref, tag"
" FROM nvts;");
"SELECT oid, name, family, cvss_base, tag FROM nvts;");
while (next (&nvts))
{
iterator_t refs;

nvti_t *nvti = nvti_new ();
nvti_set_oid (nvti, iterator_string (&nvts, 0));
nvti_set_name (nvti, iterator_string (&nvts, 1));
nvti_set_family (nvti, iterator_string (&nvts, 2));
nvti_set_cvss_base (nvti, iterator_string (&nvts, 3));
nvti_add_refs (nvti, "cve", iterator_string (&nvts, 4), "");
nvti_add_refs (nvti, "bid", iterator_string (&nvts, 5), "");
nvti_add_refs (nvti, NULL, iterator_string (&nvts, 6), "");
nvti_set_tag (nvti, iterator_string (&nvts, 7));
nvti_set_tag (nvti, iterator_string (&nvts, 4));

init_iterator (&refs,
"SELECT type, ref_id, ref_text"
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
" FROM vt_refs"
" WHERE vt_oid = '%s';",
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
iterator_string (&nvts, 0));

while (next (&refs))
{
nvti_add_vtref (nvti, vtref_new (iterator_string (&refs, 0),
iterator_string (&refs, 1),
iterator_string (&refs, 2)));
}

cleanup_iterator (&refs);

nvtis_add (nvti_cache, nvti);
}
cleanup_iterator (&nvts);
Expand Down
32 changes: 11 additions & 21 deletions src/manage_sql_nvts.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,18 @@ find_nvt (const char* oid, nvt_t* nvt)
static void
insert_nvt (const nvti_t *nvti)
{
gchar *qod_str, *qod_type, *cve, *bid, *xref;
gchar *quoted_name;
gchar *quoted_cve, *quoted_bid, *quoted_xref, *quoted_tag;
gchar *qod_str, *qod_type, *cve;
gchar *quoted_name, *quoted_cve, *quoted_tag;
gchar *quoted_cvss_base, *quoted_qod_type, *quoted_family, *value;
gchar *quoted_solution_type;
int creation_time, modification_time, qod;

cve = nvti_refs (nvti, "cve", "", 0);
bid = nvti_refs (nvti, "bid", "", 0);
xref = nvti_refs (nvti, NULL, "cve,bid", 1);

quoted_name = sql_quote (nvti_name (nvti) ? nvti_name (nvti) : "");
quoted_cve = sql_quote (cve ? cve : "");
quoted_bid = sql_quote (bid ? bid : "");
quoted_xref = sql_quote (xref ? xref : "");

g_free (cve);
g_free (bid);
g_free (xref);

if (nvti_tag (nvti))
{
Expand Down Expand Up @@ -331,13 +324,12 @@ insert_nvt (const nvti_t *nvti)
int i;

sql ("INSERT into nvts (oid, name,"
" cve, bid, xref, tag, category, family, cvss_base,"
" cve, tag, category, family, cvss_base,"
" creation_time, modification_time, uuid, solution_type,"
" qod, qod_type)"
" VALUES ('%s', '%s', '%s', '%s', '%s',"
" VALUES ('%s', '%s', '%s',"
" '%s', %i, '%s', '%s', %i, %i, '%s', '%s', %d, '%s');",
nvti_oid (nvti), quoted_name,
quoted_cve, quoted_bid, quoted_xref, quoted_tag,
nvti_oid (nvti), quoted_name, quoted_cve, quoted_tag,
nvti_category (nvti), quoted_family, quoted_cvss_base, creation_time,
modification_time, nvti_oid (nvti), quoted_solution_type,
qod, quoted_qod_type);
Expand All @@ -364,8 +356,6 @@ insert_nvt (const nvti_t *nvti)

g_free (quoted_name);
g_free (quoted_cve);
g_free (quoted_bid);
g_free (quoted_xref);
g_free (quoted_tag);
g_free (quoted_cvss_base);
g_free (quoted_family);
Expand Down Expand Up @@ -812,7 +802,7 @@ DEF_ACCESS (nvt_iterator_name, GET_ITERATOR_COLUMN_COUNT + 2);
* @return Tag, or NULL if iteration is complete. Freed by
* cleanup_iterator.
*/
DEF_ACCESS (nvt_iterator_tag, GET_ITERATOR_COLUMN_COUNT + 6);
DEF_ACCESS (nvt_iterator_tag, GET_ITERATOR_COLUMN_COUNT + 4);

/**
* @brief Get the category from an NVT iterator.
Expand All @@ -826,7 +816,7 @@ nvt_iterator_category (iterator_t* iterator)
{
int ret;
if (iterator->done) return -1;
ret = iterator_int (iterator, GET_ITERATOR_COLUMN_COUNT + 7);
ret = iterator_int (iterator, GET_ITERATOR_COLUMN_COUNT + 5);
return ret;
}

Expand All @@ -838,7 +828,7 @@ nvt_iterator_category (iterator_t* iterator)
* @return Family, or NULL if iteration is complete. Freed by
* cleanup_iterator.
*/
DEF_ACCESS (nvt_iterator_family, GET_ITERATOR_COLUMN_COUNT + 8);
DEF_ACCESS (nvt_iterator_family, GET_ITERATOR_COLUMN_COUNT + 6);

/**
* @brief Get the cvss_base from an NVT iterator.
Expand All @@ -848,7 +838,7 @@ DEF_ACCESS (nvt_iterator_family, GET_ITERATOR_COLUMN_COUNT + 8);
* @return Cvss_base, or NULL if iteration is complete. Freed by
* cleanup_iterator.
*/
DEF_ACCESS (nvt_iterator_cvss_base, GET_ITERATOR_COLUMN_COUNT + 9);
DEF_ACCESS (nvt_iterator_cvss_base, GET_ITERATOR_COLUMN_COUNT + 7);

/**
* @brief Get the qod from an NVT iterator.
Expand All @@ -858,7 +848,7 @@ DEF_ACCESS (nvt_iterator_cvss_base, GET_ITERATOR_COLUMN_COUNT + 9);
* @return QoD, or NULL if iteration is complete. Freed by
* cleanup_iterator.
*/
DEF_ACCESS (nvt_iterator_qod, GET_ITERATOR_COLUMN_COUNT + 12);
DEF_ACCESS (nvt_iterator_qod, GET_ITERATOR_COLUMN_COUNT + 10);

/**
* @brief Get the qod_type from an NVT iterator.
Expand All @@ -868,7 +858,7 @@ DEF_ACCESS (nvt_iterator_qod, GET_ITERATOR_COLUMN_COUNT + 12);
* @return QoD type, or NULL if iteration is complete. Freed by
* cleanup_iterator.
*/
DEF_ACCESS (nvt_iterator_qod_type, GET_ITERATOR_COLUMN_COUNT + 13);
DEF_ACCESS (nvt_iterator_qod_type, GET_ITERATOR_COLUMN_COUNT + 11);

/**
* @brief Get the default timeout of an NVT.
Expand Down
8 changes: 2 additions & 6 deletions src/manage_sql_nvts.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2010-2018 Greenbone Networks GmbH
/* Copyright (C) 2010-2019 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
Expand Down Expand Up @@ -29,7 +29,7 @@
* @brief Filter columns for NVT info iterator.
*/
#define NVT_INFO_ITERATOR_FILTER_COLUMNS \
{ GET_ITERATOR_FILTER_COLUMNS, "version", "cve", "bid", "xref", \
{ GET_ITERATOR_FILTER_COLUMNS, "version", "cve", \
"family", "cvss_base", "severity", "cvss", "script_tags", "qod", \
"qod_type", "solution_type", NULL }

Expand All @@ -45,8 +45,6 @@
{ "modification_time", "version", KEYWORD_TYPE_INTEGER }, \
{ "name", NULL, KEYWORD_TYPE_STRING }, \
{ "cve", NULL, KEYWORD_TYPE_STRING }, \
{ "bid", NULL, KEYWORD_TYPE_STRING }, \
{ "xref", NULL, KEYWORD_TYPE_STRING }, \
{ "tag", NULL, KEYWORD_TYPE_STRING }, \
{ "category", NULL, KEYWORD_TYPE_STRING }, \
{ "family", NULL, KEYWORD_TYPE_STRING }, \
Expand All @@ -72,8 +70,6 @@
{ "modification_time", "version", KEYWORD_TYPE_INTEGER }, \
{ "nvts.name", NULL, KEYWORD_TYPE_STRING }, \
{ "cve", NULL, KEYWORD_TYPE_STRING }, \
{ "bid", NULL, KEYWORD_TYPE_STRING }, \
{ "xref", NULL, KEYWORD_TYPE_STRING }, \
{ "tag", NULL, KEYWORD_TYPE_STRING }, \
{ "category", NULL, KEYWORD_TYPE_STRING }, \
{ "nvts.family", NULL, KEYWORD_TYPE_STRING }, \
Expand Down