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

Get scanner preferences from OSP-OpenVAS scanner #766

Merged
merged 5 commits into from
Oct 1, 2019
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 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)"
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
" 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