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

Add --rebuild #998

Merged
merged 11 commits into from
Mar 5, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Automatically load predefined report formats from the feed [#968](https://github.com/greenbone/gvmd/pull/968) [#970](https://github.com/greenbone/gvmd/pull/970)
- Print UUIDs in --get-users when --verbose given [#991](https://github.com/greenbone/gvmd/pull/991)
- Add --get-roles [#992](https://github.com/greenbone/gvmd/pull/992)
- Add --rebuild [#998](https://github.com/greenbone/gvmd/pull/998)

### Changed
- Update SCAP and CERT feed info in sync scripts [#810](https://github.com/greenbone/gvmd/pull/810)
Expand Down
49 changes: 27 additions & 22 deletions src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,7 @@ gvmd (int argc, char** argv)
static gchar *scanner_name = NULL;
static gchar *rc_name = NULL;
static gchar *relay_mapper = NULL;
static gboolean rebuild = FALSE;
static gchar *role = NULL;
static gchar *disable = NULL;
static gchar *value = NULL;
Expand Down Expand Up @@ -1804,6 +1805,10 @@ gvmd (int argc, char** argv)
&manager_port_string_2,
"Use port number <number> for address 2.",
"<number>" },
{ "rebuild", 'm', 0, G_OPTION_ARG_NONE,
&rebuild,
"Remove NVT db, and rebuild it from the scanner.",
NULL },
{ "relay-mapper", '\0', 0, G_OPTION_ARG_FILENAME,
&relay_mapper,
"Executable for mapping scanner hosts to relays."
Expand Down Expand Up @@ -2234,6 +2239,22 @@ gvmd (int argc, char** argv)
return EXIT_SUCCESS;
}

if (rebuild)
{
int ret;

proctitle_set ("gvmd: --rebuild");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;

ret = manage_rebuild (log_config, database);
log_config_free ();
if (ret)
return EXIT_FAILURE;
return EXIT_SUCCESS;
}

if (create_scanner)
{
int ret;
Expand Down Expand Up @@ -2735,29 +2756,13 @@ gvmd (int argc, char** argv)
if (gvm_auth_init ())
exit (EXIT_FAILURE);

/* Try to get OSP VT update socket from default OpenVAS if it
* was not set with the --osp-vt-update option.
*/
if (get_osp_vt_update_socket () == NULL)
if (check_osp_vt_update_socket ())
{
char *default_socket = openvas_default_scanner_host ();
if (default_socket)
{
g_debug ("%s: Using OSP VT update socket from default OpenVAS"
" scanner: %s",
__func__,
default_socket);
set_osp_vt_update_socket (default_socket);
}
else
{
g_critical ("%s: No OSP VT update socket found."
" Use --osp-vt-update or change the 'OpenVAS Default'"
" scanner to use the main ospd-openvas socket.",
__func__);
return EXIT_FAILURE;
}
free (default_socket);
g_critical ("%s: No OSP VT update socket found."
" Use --osp-vt-update or change the 'OpenVAS Default'"
" scanner to use the main ospd-openvas socket.",
__func__);
exit (EXIT_FAILURE);
}

/* Enter the main forever-loop. */
Expand Down
3 changes: 3 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3680,6 +3680,9 @@ gvm_get_sync_script_feed_version (const gchar *, gchar **);
int
manage_update_nvts_osp (const gchar *);

int
manage_rebuild (GSList *, const gchar *);


/* Wizards. */

Expand Down
Loading