Skip to content

Commit

Permalink
Merge pull request #392 from mattmundell/nvt-rebuild-via-osp
Browse files Browse the repository at this point in the history
Add option to update NVTs via OSP
  • Loading branch information
mattmundell authored May 23, 2019
2 parents 25ff0d7 + 6aaca99 commit 46dd903
Show file tree
Hide file tree
Showing 5 changed files with 751 additions and 69 deletions.
34 changes: 31 additions & 3 deletions src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ static int update_in_progress = 0;
*/
GSList *log_config = NULL;

/**
* @brief File socket for OSP NVT update. NULL to update via OTP.
*/
static gchar *osp_update_socket = NULL;


/* Helpers. */

Expand Down Expand Up @@ -1173,6 +1178,21 @@ update_nvt_cache (int register_cleanup)
}
}

/**
* @brief Update the NVT Cache using OSP.
*
* @param[in] update_socket UNIX socket for contacting openvas-ospd.
*
* @return 0 success.
*/
static int
update_nvt_cache_osp (const gchar *update_socket)
{
proctitle_set ("gvmd: OSP: Updating NVT cache");

return manage_update_nvts_osp (update_socket);
}

/**
* @brief Update NVT cache in forked child, retrying if scanner loading.
*
Expand Down Expand Up @@ -1204,9 +1224,10 @@ update_nvt_cache_retry ()
else if (child_pid == 0)
{
/* Child: Try reload. */
int ret = update_nvt_cache (0);

exit (ret);
if (osp_update_socket)
exit (update_nvt_cache_osp (osp_update_socket));
else
exit (update_nvt_cache (0));
}
}
}
Expand Down Expand Up @@ -1705,6 +1726,7 @@ main (int argc, char** argv)
static gchar *listen_mode = NULL;
static gchar *new_password = NULL;
static gchar *optimize = NULL;
static gchar *osp_vt_update = NULL;
static gchar *password = NULL;
static gchar *manager_address_string = NULL;
static gchar *manager_address_string_2 = NULL;
Expand Down Expand Up @@ -1791,6 +1813,9 @@ main (int argc, char** argv)
G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE,
&decrypt_all_credentials, NULL, NULL },
{ "new-password", '\0', 0, G_OPTION_ARG_STRING, &new_password, "Modify user's password and exit.", "<password>" },
{ "osp-vt-update", '\0', 0, G_OPTION_ARG_STRING, &osp_vt_update,
"Unix socket for OSP NVT update. Default is to do an OTP update.",
"<scanner-socket>" },
{ "optimize", '\0', 0, G_OPTION_ARG_STRING, &optimize, "Run an optimization: vacuum, analyze, cleanup-config-prefs, cleanup-port-names, cleanup-result-severities, cleanup-schedule-times, rebuild-report-cache or update-report-cache.", "<name>" },
{ "password", '\0', 0, G_OPTION_ARG_STRING, &password, "Password, for --create-user.", "<password>" },
{ "port", 'p', 0, G_OPTION_ARG_STRING, &manager_port_string, "Use port number <number>.", "<number>" },
Expand Down Expand Up @@ -2076,6 +2101,9 @@ main (int argc, char** argv)
* These can run concurrently, so they set the shared lock gvm-helping, and
* release gvm-checking, via option_lock. */

if (osp_vt_update)
osp_update_socket = osp_vt_update;

if (backup_database)
{
/* Backup the database and then exit. */
Expand Down
13 changes: 13 additions & 0 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -8854,6 +8854,19 @@ gvm_migrate_secinfo (int feed_type)
return ret;
}

/**
* @brief Update NVT cache using OSP.
*
* @param[in] update_socket Socket to use to contact ospd-openvas scanner.
*
* @return 0 success, -1 error, 2 scanner still loading.
*/
int
manage_update_nvts_osp (const gchar *update_socket)
{
return manage_update_nvt_cache_osp (update_socket);
}


/* Wizards. */

Expand Down
3 changes: 3 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -4189,6 +4189,9 @@ gvm_get_sync_script_description (const gchar *, gchar **);
gboolean
gvm_get_sync_script_feed_version (const gchar *, gchar **);

int
manage_update_nvts_osp (const gchar *);


/* Wizards. */

Expand Down
Loading

0 comments on commit 46dd903

Please sign in to comment.