Skip to content

Commit

Permalink
Merge branch 'master' into add_vtref_table
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmundell authored Jun 4, 2019
2 parents b2e1098 + ee993fd commit d471b04
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 657 deletions.
5 changes: 2 additions & 3 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -30110,7 +30110,6 @@ extern buffer_size_t from_client_end;
* @brief Initialise GMP library.
*
* @param[in] log_config Logging configuration list.
* @param[in] nvt_cache_mode True when running in NVT caching mode.
* @param[in] database Location of manage database.
* @param[in] max_ips_per_target Max number of IPs per target.
* @param[in] max_email_attachment_size Max size of email attachments.
Expand All @@ -30124,7 +30123,7 @@ extern buffer_size_t from_client_end;
* -4 max_ips_per_target out of range.
*/
int
init_gmp (GSList *log_config, int nvt_cache_mode, const gchar *database,
init_gmp (GSList *log_config, const gchar *database,
int max_ips_per_target, int max_email_attachment_size,
int max_email_include_size, int max_email_message_size,
manage_connection_forker_t fork_connection, int skip_db_check)
Expand All @@ -30134,7 +30133,7 @@ init_gmp (GSList *log_config, int nvt_cache_mode, const gchar *database,
(GLogFunc) gvm_log_func,
log_config);
command_data_init (&command_data);
return init_manage (log_config, nvt_cache_mode, database, max_ips_per_target,
return init_manage (log_config, database, max_ips_per_target,
max_email_attachment_size, max_email_include_size,
max_email_message_size,
fork_connection, skip_db_check);
Expand Down
4 changes: 2 additions & 2 deletions src/gmp.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2009-2018 Greenbone Networks GmbH
/* Copyright (C) 2009-2019 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
Expand Down Expand Up @@ -49,7 +49,7 @@
#define TRUNCATE_TEXT_SUFFIX "[...]\n(text truncated)"

int
init_gmp (GSList *, int, const gchar *, int, int, int, int,
init_gmp (GSList *, const gchar *, int, int, int, int,
manage_connection_forker_t, int);

void
Expand Down
31 changes: 8 additions & 23 deletions src/gmpd.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2009-2018 Greenbone Networks GmbH
/* Copyright (C) 2009-2019 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
Expand Down Expand Up @@ -91,7 +91,6 @@ static int gmpd_nvt_cache_mode = 0;
* @brief Initialise the GMP library for the GMP daemon.
*
* @param[in] log_config Log configuration
* @param[in] nvt_cache_mode 0 operate normally, -1 just update NVT cache.
* @param[in] database Location of manage database.
* @param[in] max_ips_per_target Max number of IPs per target.
* @param[in] max_email_attachment_size Max size of email attachments.
Expand All @@ -105,12 +104,12 @@ static int gmpd_nvt_cache_mode = 0;
* -4 max_ips_per_target out of range.
*/
int
init_gmpd (GSList *log_config, int nvt_cache_mode, const gchar *database,
init_gmpd (GSList *log_config, const gchar *database,
int max_ips_per_target, int max_email_attachment_size,
int max_email_include_size, int max_email_message_size,
manage_connection_forker_t fork_connection, int skip_db_check)
{
return init_gmp (log_config, nvt_cache_mode, database, max_ips_per_target,
return init_gmp (log_config, database, max_ips_per_target,
max_email_attachment_size, max_email_include_size,
max_email_message_size,
fork_connection, skip_db_check);
Expand Down Expand Up @@ -505,7 +504,7 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
ret = manage_scanner_set_default ();
if (ret)
return ret;
if (openvas_scanner_connect () || openvas_scanner_init (1))
if (openvas_scanner_connect () || openvas_scanner_init ())
{
openvas_scanner_close ();
return -1;
Expand Down Expand Up @@ -589,24 +588,16 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
/* See whether we need to read from the scannner. */
if (openvas_scanner_connected ()
&& (scanner_init_state == SCANNER_INIT_DONE
|| scanner_init_state == SCANNER_INIT_DONE_CACHE_MODE
|| scanner_init_state == SCANNER_INIT_DONE_CACHE_MODE_UPDATE
|| scanner_init_state == SCANNER_INIT_SENT_COMPLETE_LIST
|| scanner_init_state == SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE
|| scanner_init_state == SCANNER_INIT_SENT_VERSION)
&& !openvas_scanner_full ())
openvas_scanner_fd_set (&readfds);

/* See whether we need to write to the scanner. */
if (openvas_scanner_connected ()
&& (((scanner_init_state == SCANNER_INIT_TOP
|| scanner_init_state == SCANNER_INIT_DONE
|| scanner_init_state == SCANNER_INIT_DONE_CACHE_MODE
|| scanner_init_state == SCANNER_INIT_DONE_CACHE_MODE_UPDATE)
|| scanner_init_state == SCANNER_INIT_DONE)
&& to_server_buffer_space () > 0)
|| scanner_init_state == SCANNER_INIT_CONNECTED
|| scanner_init_state == SCANNER_INIT_GOT_FEED_VERSION
|| scanner_init_state == SCANNER_INIT_GOT_PLUGINS))
|| scanner_init_state == SCANNER_INIT_CONNECTED))
openvas_scanner_fd_set (&writefds);

/* Select, then handle result. Due to GNUTLS internal buffering
Expand Down Expand Up @@ -828,7 +819,7 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
{
/* Write as much as possible to the scanner. */

switch (openvas_scanner_write (gmpd_nvt_cache_mode))
switch (openvas_scanner_write ())
{
case 0: /* Wrote everything in to_scanner. */
break;
Expand Down Expand Up @@ -952,7 +943,7 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
/* Received scanner BYE. Write out the rest of to_scanner (the
* BYE ACK).
*/
openvas_scanner_write (gmpd_nvt_cache_mode);
openvas_scanner_write ();
set_scanner_init_state (SCANNER_INIT_TOP);
if (client_active == 0)
return 0;
Expand All @@ -974,12 +965,6 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
return 1;
openvas_scanner_close ();
}
else if (ret == 4)
{
/* NVT update requested and NVTS are already at that version. */
assert (gmpd_nvt_cache_mode);
return 0;
}
else if (ret == -1)
{
/* Error. */
Expand Down
2 changes: 1 addition & 1 deletion src/gmpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#define FROM_BUFFER_SIZE 1048576

int
init_gmpd (GSList *, int, const gchar *, int, int, int, int,
init_gmpd (GSList *, const gchar *, int, int, int, int,
manage_connection_forker_t, int);

void
Expand Down
88 changes: 1 addition & 87 deletions src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,89 +1095,6 @@ handle_sigabrt_simple (int signal)
exit (EXIT_FAILURE);
}

/**
* @brief Updates the NVT Cache and exits or returns exit code.
*
* @param[in] register_cleanup Whether to register cleanup with atexit.
*
* @return If this function did not exit itself, returns exit code.
*/
static int
update_nvt_cache (int register_cleanup)
{
int ret;
gvm_connection_t connection;

/* Initialise GMP daemon. */

proctitle_set ("gvmd: Updating NVT cache");

switch (init_gmpd (log_config,
-1,
database,
manage_max_hosts (),
0, /* Max email attachment size. */
0, /* Max email include size. */
0, /* Max email message size. */
NULL,
1 /* Skip DB check (including table creation). */))
{
case 0:
break;
case -2:
g_critical ("%s: database is wrong version", __FUNCTION__);
log_config_free ();
exit (EXIT_FAILURE);
break;
case -1:
default:
g_critical ("%s: failed to initialise GMP daemon", __FUNCTION__);
log_config_free ();
exit (EXIT_FAILURE);
}

/* Register the `cleanup' function. */

if (register_cleanup && atexit (&cleanup))
{
g_critical ("%s: failed to register `atexit' cleanup function",
__FUNCTION__);
log_config_free ();
exit (EXIT_FAILURE);
}

/* Register the signal handlers. */

setup_signal_handler (SIGTERM, handle_termination_signal, 0);
setup_signal_handler (SIGABRT, handle_sigabrt, 1);
setup_signal_handler (SIGINT, handle_termination_signal, 0);
setup_signal_handler (SIGHUP, SIG_IGN, 0);
setup_signal_handler (SIGQUIT, handle_termination_signal, 0);
setup_signal_handler (SIGSEGV, handle_sigsegv, 1);
setup_signal_handler (SIGCHLD, SIG_IGN, 0);

/* Call the GMP client serving function with a special client socket
* value. This invokes a scanner-only manager loop which will
* request and cache the plugins, then exit. */

connection.socket = -1;
ret = serve_gmp (&connection, database, NULL);
openvas_scanner_close ();
switch (ret)
{
case 0:
return EXIT_SUCCESS;
case 1:
return 2;
case -2:
g_critical ("%s: scanner OpenVAS Default has no cert", __FUNCTION__);
return EXIT_FAILURE;
default:
case -1:
return EXIT_FAILURE;
}
}

/**
* @brief Update the NVT Cache using OSP.
*
Expand Down Expand Up @@ -1223,11 +1140,8 @@ update_nvt_cache_retry ()
}
else if (child_pid == 0)
{
/* Child: Try reload. */
if (osp_update_socket)
exit (update_nvt_cache_osp (osp_update_socket));
else
exit (update_nvt_cache (0));
}
}
}
Expand Down Expand Up @@ -2628,7 +2542,7 @@ main (int argc, char** argv)

/* Initialise GMP daemon. */

switch (init_gmpd (log_config, 0, database, max_ips_per_target,
switch (init_gmpd (log_config, database, max_ips_per_target,
max_email_attachment_size, max_email_include_size,
max_email_message_size,
fork_connection_for_event, 0))
Expand Down
18 changes: 2 additions & 16 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -5105,7 +5105,7 @@ run_otp_task (task_t task, scanner_t scanner, int from, char **report_id)
}

if (!openvas_scanner_connected ()
&& (openvas_scanner_connect () || openvas_scanner_init (0)))
&& (openvas_scanner_connect () || openvas_scanner_init ()))
return -5;

if (openvas_scanner_is_loading ())
Expand Down Expand Up @@ -5821,7 +5821,7 @@ stop_task_internal (task_t task)
return -5;
}
if (!openvas_scanner_connected ()
&& (openvas_scanner_connect () || openvas_scanner_init (0)))
&& (openvas_scanner_connect () || openvas_scanner_init ()))
return -5;
if (send_to_server ("CLIENT <|> STOP_WHOLE_TEST <|> CLIENT\n"))
return -1;
Expand Down Expand Up @@ -6064,20 +6064,6 @@ acknowledge_bye ()
return 0;
}

/**
* @brief Acknowledge scanner PLUGINS_FEED_VERSION message,
* @brief requesting all plugin info.
*
* @return 0 on success, -1 if out of space in scanner output buffer.
*/
int
acknowledge_feed_version_info ()
{
if (send_to_server ("CLIENT <|> COMPLETE_LIST <|> CLIENT\n"))
return -1;
return 0;
}

/**
* @brief Handle state changes to current task made by other processes.
*
Expand Down
8 changes: 1 addition & 7 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ typedef int (*manage_connection_forker_t) (gvm_connection_t * conn,
const gchar* uuid);

int
init_manage (GSList*, int, const gchar *, int, int, int, int,
init_manage (GSList*, const gchar *, int, int, int, int,
manage_connection_forker_t, int);

int
Expand Down Expand Up @@ -2006,9 +2006,6 @@ nvt_default_timeout (const char *);
int
family_nvt_count (const char *);

void
manage_complete_nvt_cache_update (GList *, GList *);


/* NVT selectors. */

Expand Down Expand Up @@ -2619,9 +2616,6 @@ override_iterator_new_severity (iterator_t *);
int
acknowledge_bye ();

int
acknowledge_feed_version_info ();

int
manage_check_current_task ();

Expand Down
Loading

0 comments on commit d471b04

Please sign in to comment.