Skip to content

Commit

Permalink
Merge pull request #719 from janowagner/resolve_tags
Browse files Browse the repository at this point in the history
Make several NVTI tags internally explicit.
  • Loading branch information
mattmundell authored Aug 28, 2019
2 parents b5246fc + 05d9e75 commit 6104903
Show file tree
Hide file tree
Showing 9 changed files with 382 additions and 69 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ include (CPack)

## Variables

set (GVMD_DATABASE_VERSION 218)
set (GVMD_DATABASE_VERSION 219)

set (GVMD_SCAP_DATABASE_VERSION 15)

Expand Down
65 changes: 57 additions & 8 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -10170,23 +10170,72 @@ results_xml_append_nvt (iterator_t *results, GString *buffer, int cert_loaded)
if (!cvss_base && !strcmp (oid, "0"))
cvss_base = "0.0";

/* Add the elements that are expected as part of the pipe-separated tag list
* via API although internally already explicitely stored. Once the API is
* extended to have these elements explicitely, they do not need to be
* added to this string anymore. */
/* Add the elements that are expected as part of the pipe-separated
* tag list via API although internally already explicitely stored.
* Once the API is extended to have these elements explicitely, they
* do not need to be added to this tag string anymore. */
if (result_iterator_nvt_summary (results))
{
if (tags->str)
g_string_append_printf (tags, "|summary=%s",
result_iterator_nvt_summary (results));
else
g_string_append_printf (tags, "summary=%s",
result_iterator_nvt_summary (results));
}
if (result_iterator_nvt_insight (results))
{
if (tags->str)
g_string_append_printf (tags, "|insight=%s",
result_iterator_nvt_insight (results));
else
g_string_append_printf (tags, "insight=%s",
result_iterator_nvt_insight (results));
}
if (result_iterator_nvt_affected (results))
{
if (tags->str)
g_string_append_printf (tags, "|affected=%s",
result_iterator_nvt_affected (results));
else
g_string_append_printf (tags, "affected=%s",
result_iterator_nvt_affected (results));
}
if (result_iterator_nvt_impact (results))
{
if (tags->str)
g_string_append_printf (tags, "|impact=%s",
result_iterator_nvt_impact (results));
else
g_string_append_printf (tags, "impact=%s",
result_iterator_nvt_impact (results));
}
if (result_iterator_nvt_solution (results))
{
if (tags->str)
g_string_append_printf (tags, "|solution=%s", result_iterator_nvt_solution (results));
g_string_append_printf (tags, "|solution=%s",
result_iterator_nvt_solution (results));
else
g_string_append_printf (tags, "solution=%s",
result_iterator_nvt_solution (results));
}
if (result_iterator_nvt_detection (results))
{
if (tags->str)
g_string_append_printf (tags, "|vuldetect=%s",
result_iterator_nvt_detection (results));
else
g_string_append_printf (tags, "solution=%s", result_iterator_nvt_solution (results));
g_string_append_printf (tags, "vuldetect=%s",
result_iterator_nvt_detection (results));
}
if (result_iterator_nvt_solution_type (results))
{
if (tags->str)
g_string_append_printf (tags, "|solution_type=%s", result_iterator_nvt_solution_type (results));
g_string_append_printf (tags, "|solution_type=%s",
result_iterator_nvt_solution_type (results));
else
g_string_append_printf (tags, "solution_type=%s", result_iterator_nvt_solution_type (results));
g_string_append_printf (tags, "solution_type=%s",
result_iterator_nvt_solution_type (results));
}

buffer_xml_append_printf (buffer,
Expand Down
64 changes: 57 additions & 7 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -7257,20 +7257,70 @@ get_nvti_xml (iterator_t *nvts, int details, int pref_count,
/* Add the elements that are expected as part of the pipe-separated tag list
* via API although internally already explicitely stored. Once the API is
* extended to have these elements explicitely, they do not need to be
* added to this string anymore. */
if (nvt_iterator_solution (nvts))
* added to this tag string anymore. */
if (nvt_iterator_summary (nvts) && nvt_iterator_summary (nvts)[0])
{
if (nvt_tags->str)
g_string_append_printf (nvt_tags, "|solution=%s", nvt_iterator_solution (nvts));
g_string_append_printf (nvt_tags, "|summary=%s",
nvt_iterator_summary (nvts));
else
g_string_append_printf (nvt_tags, "solution=%s", result_iterator_nvt_solution (nvts));
g_string_append_printf (nvt_tags, "summary=%s",
nvt_iterator_summary (nvts));
}
if (nvt_iterator_solution_type (nvts))
if (nvt_iterator_insight (nvts) && nvt_iterator_insight (nvts)[0])
{
if (nvt_tags->str)
g_string_append_printf (nvt_tags, "|solution_type=%s", nvt_iterator_solution_type (nvts));
g_string_append_printf (nvt_tags, "|insight=%s",
nvt_iterator_insight (nvts));
else
g_string_append_printf (nvt_tags, "solution_type=%s", nvt_iterator_solution_type (nvts));
g_string_append_printf (nvt_tags, "insight=%s",
nvt_iterator_insight (nvts));
}
if (nvt_iterator_affected (nvts) && nvt_iterator_affected (nvts)[0])
{
if (nvt_tags->str)
g_string_append_printf (nvt_tags, "|affected=%s",
nvt_iterator_affected (nvts));
else
g_string_append_printf (nvt_tags, "affected=%s",
nvt_iterator_affected (nvts));
}
if (nvt_iterator_impact (nvts) && nvt_iterator_impact (nvts)[0])
{
if (nvt_tags->str)
g_string_append_printf (nvt_tags, "|impact=%s",
nvt_iterator_impact (nvts));
else
g_string_append_printf (nvt_tags, "impact=%s",
nvt_iterator_impact (nvts));
}
if (nvt_iterator_solution (nvts) && nvt_iterator_solution (nvts)[0])
{
if (nvt_tags->str)
g_string_append_printf (nvt_tags, "|solution=%s",
nvt_iterator_solution (nvts));
else
g_string_append_printf (nvt_tags, "solution=%s",
nvt_iterator_solution (nvts));
}
if (nvt_iterator_solution_type (nvts)
&& nvt_iterator_solution_type (nvts)[0])
{
if (nvt_tags->str)
g_string_append_printf (nvt_tags, "|solution_type=%s",
nvt_iterator_solution_type (nvts));
else
g_string_append_printf (nvt_tags, "solution_type=%s",
nvt_iterator_solution_type (nvts));
}
if (nvt_iterator_detection (nvts) && nvt_iterator_detection (nvts)[0])
{
if (nvt_tags->str)
g_string_append_printf (nvt_tags, "|vuldetect=%s",
nvt_iterator_detection (nvts));
else
g_string_append_printf (nvt_tags, "vuldetect=%s",
nvt_iterator_detection (nvts));
}

refs_str = g_string_new ("");
Expand Down
30 changes: 30 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1444,12 +1444,27 @@ result_iterator_nvt_oid (iterator_t*);
const char*
result_iterator_nvt_name (iterator_t *);

const char*
result_iterator_nvt_summary (iterator_t *);

const char*
result_iterator_nvt_insight (iterator_t *);

const char*
result_iterator_nvt_affected (iterator_t *);

const char*
result_iterator_nvt_impact (iterator_t *);

const char*
result_iterator_nvt_solution (iterator_t *);

const char*
result_iterator_nvt_solution_type (iterator_t *);

const char*
result_iterator_nvt_detection (iterator_t *);

const char*
result_iterator_nvt_family (iterator_t *);

Expand Down Expand Up @@ -1990,6 +2005,18 @@ nvt_iterator_version (iterator_t*);
const char*
nvt_iterator_name (iterator_t*);

const char*
nvt_iterator_summary (iterator_t*);

const char*
nvt_iterator_insight (iterator_t*);

const char*
nvt_iterator_affected (iterator_t*);

const char*
nvt_iterator_impact (iterator_t*);

const char*
nvt_iterator_description (iterator_t*);

Expand All @@ -2005,6 +2032,9 @@ nvt_iterator_family (iterator_t*);
const char*
nvt_iterator_cvss_base (iterator_t*);

const char*
nvt_iterator_detection (iterator_t*);

const char*
nvt_iterator_qod (iterator_t*);

Expand Down
38 changes: 38 additions & 0 deletions src/manage_migrators.c
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,43 @@ migrate_217_to_218 ()
return 0;
}

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

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

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

/* Update the database. */

/* Extend table "nvts" with additional columns "summary",
* "insight", "affected", "detection" and "impact" */
sql ("ALTER TABLE IF EXISTS nvts ADD COLUMN summary text;");
sql ("ALTER TABLE IF EXISTS nvts ADD COLUMN insight text;");
sql ("ALTER TABLE IF EXISTS nvts ADD COLUMN affected text;");
sql ("ALTER TABLE IF EXISTS nvts ADD COLUMN detection text;");
sql ("ALTER TABLE IF EXISTS nvts ADD COLUMN impact text;");

/* Set the database version to 219. */

set_db_version (219);

sql_commit ();

return 0;
}

#undef UPDATE_DASHBOARD_SETTINGS

/**
Expand All @@ -1348,6 +1385,7 @@ static migrator_t database_migrators[] = {
{216, migrate_215_to_216},
{217, migrate_216_to_217},
{218, migrate_217_to_218},
{219, migrate_218_to_219},
/* End marker. */
{-1, NULL}};

Expand Down
5 changes: 5 additions & 0 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2920,6 +2920,10 @@ create_tables ()
" oid text UNIQUE NOT NULL,"
" name text,"
" comment text,"
" summary text,"
" insight text,"
" affected text,"
" impact text,"
" cve text,"
" tag text,"
" category text,"
Expand All @@ -2929,6 +2933,7 @@ create_tables ()
" modification_time integer,"
" solution text,"
" solution_type text,"
" detection text,"
" qod integer,"
" qod_type text);");

Expand Down
90 changes: 90 additions & 0 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -24272,6 +24272,78 @@ result_iterator_nvt_name (iterator_t *iterator)
return NULL;
}

/**
* @brief Get the NVT summary from a result iterator.
*
* @param[in] iterator Iterator.
*
* @return The summary of the NVT that produced the result, or NULL on error.
*/
const char*
result_iterator_nvt_summary (iterator_t *iterator)
{
nvti_t *nvti;
if (iterator->done) return NULL;
nvti = lookup_nvti (result_iterator_nvt_oid (iterator));
if (nvti)
return nvti_summary (nvti);
return NULL;
}

/**
* @brief Get the NVT insight from a result iterator.
*
* @param[in] iterator Iterator.
*
* @return The insight of the NVT that produced the result, or NULL on error.
*/
const char*
result_iterator_nvt_insight (iterator_t *iterator)
{
nvti_t *nvti;
if (iterator->done) return NULL;
nvti = lookup_nvti (result_iterator_nvt_oid (iterator));
if (nvti)
return nvti_insight (nvti);
return NULL;
}

/**
* @brief Get the NVT affected from a result iterator.
*
* @param[in] iterator Iterator.
*
* @return The affected of the NVT that produced the result, or NULL on error.
*/
const char*
result_iterator_nvt_affected (iterator_t *iterator)
{
nvti_t *nvti;
if (iterator->done) return NULL;
nvti = lookup_nvti (result_iterator_nvt_oid (iterator));
if (nvti)
return nvti_affected (nvti);
return NULL;
}

/**
* @brief Get the NVT affected from a result iterator.
*
* @param[in] iterator Iterator.
*
* @return Impact text of the NVT that produced the result, or NULL on error.
*/
const char*
result_iterator_nvt_impact (iterator_t *iterator)
{
nvti_t *nvti;
if (iterator->done) return NULL;
nvti = lookup_nvti (result_iterator_nvt_oid (iterator));
if (nvti)
return nvti_impact (nvti);
return NULL;
}

/**
* @brief Get the NVT solution from a result iterator.
*
Expand Down Expand Up @@ -24309,6 +24381,24 @@ result_iterator_nvt_solution_type (iterator_t *iterator)
return NULL;
}

/**
* @brief Get the NVT detection from a result iterator.
*
* @param[in] iterator Iterator.
*
* @return The detection of the NVT that produced the result, or NULL on error.
*/
const char*
result_iterator_nvt_detection (iterator_t *iterator)
{
nvti_t *nvti;
if (iterator->done) return NULL;
nvti = lookup_nvti (result_iterator_nvt_oid (iterator));
if (nvti)
return nvti_detection (nvti);
return NULL;
}

/**
* @brief Get the NVT family from a result iterator.
*
Expand Down
Loading

0 comments on commit 6104903

Please sign in to comment.