Skip to content

Commit

Permalink
Merge pull request #766 from timopollmeier/scanner-prefs-from-osp
Browse files Browse the repository at this point in the history
Get scanner preferences from OSP-OpenVAS scanner
  • Loading branch information
mattmundell authored Oct 1, 2019
2 parents 39541c1 + bf4b700 commit fbe3390
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Added
- Added TLS certificates as a new resource type [#585](https://github.com/greenbone/gvmd/pull/585) [#663](https://github.com/greenbone/gvmd/pull/663) [#673](https://github.com/greenbone/gvmd/pull/673) [#674](https://github.com/greenbone/gvmd/pull/674) [#689](https://github.com/greenbone/gvmd/pull/689) [#695](https://github.com/greenbone/gvmd/pull/695) [#703](https://github.com/greenbone/gvmd/pull/703) [#728](https://github.com/greenbone/gvmd/pull/728) [#732](https://github.com/greenbone/gvmd/pull/732) [#750](https://github.com/greenbone/gvmd/pull/750) [#752](https://github.com/greenbone/gvmd/pull/752)
- Update NVTs via OSP [#392](https://github.com/greenbone/gvmd/pull/392) [#609](https://github.com/greenbone/gvmd/pull/609) [#626](https://github.com/greenbone/gvmd/pull/626) [#753](https://github.com/greenbone/gvmd/pull/753)
- Update NVTs via OSP [#392](https://github.com/greenbone/gvmd/pull/392) [#609](https://github.com/greenbone/gvmd/pull/609) [#626](https://github.com/greenbone/gvmd/pull/626) [#753](https://github.com/greenbone/gvmd/pull/753) [#766](https://github.com/greenbone/gvmd/pull/766)
- Handle addition of ID to NVT preferences. [#413](https://github.com/greenbone/gvmd/pull/413) [#744](https://github.com/greenbone/gvmd/pull/744)
- Add setting 'OMP Slave Check Period' [#491](https://github.com/greenbone/gvmd/pull/491)
- Document switching between releases when using Postgres. [#563](https://github.com/greenbone/gvmd/pull/563)
Expand Down
60 changes: 60 additions & 0 deletions src/manage_sql_nvts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,7 @@ manage_update_nvt_cache_osp (const gchar *update_socket)
if ((db_feed_version == NULL)
|| strcmp (scanner_feed_version, db_feed_version))
{
GSList *scanner_prefs;
entity_t vts;
osp_get_vts_opts_t get_vts_opts;

Expand Down Expand Up @@ -1476,6 +1477,65 @@ manage_update_nvt_cache_osp (const gchar *update_socket)
update_nvts_from_vts (&vts, scanner_feed_version);
free_entity (vts);

/* Update scanner preferences */
connection = osp_connection_new (update_socket, 0, NULL, NULL, NULL);
if (!connection)
{
g_warning ("%s: failed to connect to %s (3)",
__FUNCTION__, update_socket);
return -1;
}

scanner_prefs = NULL;
if (osp_get_scanner_details (connection, NULL, &scanner_prefs))
{
g_warning ("%s: failed to get scanner preferences", __FUNCTION__);
osp_connection_close (connection);
return -1;
}
else
{
GString *prefs_sql;
GSList *point;
int first;

point = scanner_prefs;
first = 1;

osp_connection_close (connection);
prefs_sql = g_string_new ("INSERT INTO nvt_preferences (name, value)"
" VALUES");
while (point)
{
osp_param_t *param;
gchar *quoted_name, *quoted_value;

param = point->data;
quoted_name = sql_quote (osp_param_id (param));
quoted_value = sql_quote (osp_param_default (param));

g_string_append_printf (prefs_sql,
"%s ('%s', '%s')",
first ? "" : ",",
quoted_name,
quoted_value);
first = 0;
point = g_slist_next (point);
g_free (quoted_name);
g_free (quoted_value);
}
g_string_append (prefs_sql,
" ON CONFLICT (name)"
" DO UPDATE SET value = EXCLUDED.value;");

if (first == 0)
{
sql ("%s", prefs_sql->str);
}

g_string_free (prefs_sql, TRUE);
}

/* Tell the main process to update its NVTi cache. */
sql ("UPDATE %s.meta SET value = 1 WHERE name = 'update_nvti_cache';",
sql_schema ());
Expand Down

0 comments on commit fbe3390

Please sign in to comment.