From 122b61acf1ecbb89747b1bb5fd85d3562cdb0ef7 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Thu, 30 May 2019 11:24:52 +0200 Subject: [PATCH 01/28] Remove nvt_cache_mode from OTP scanner connection. --- src/gmpd.c | 8 ++++---- src/manage.c | 4 ++-- src/manage_sql.c | 4 ++-- src/scanner.c | 47 +++++------------------------------------------ src/scanner.h | 6 +++--- 5 files changed, 16 insertions(+), 53 deletions(-) diff --git a/src/gmpd.c b/src/gmpd.c index ec69a9206b..8f93f50506 100644 --- a/src/gmpd.c +++ b/src/gmpd.c @@ -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 * @@ -505,7 +505,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; @@ -828,7 +828,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; @@ -952,7 +952,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; diff --git a/src/manage.c b/src/manage.c index b1a69711ee..9a1f1eb4f7 100644 --- a/src/manage.c +++ b/src/manage.c @@ -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 ()) @@ -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; diff --git a/src/manage_sql.c b/src/manage_sql.c index 9eaa10ef44..1b7e8eee52 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -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 * @@ -49465,7 +49465,7 @@ verify_scanner (const char *scanner_id, char **version) cleanup_iterator (&scanner); if (openvas_scanner_connected ()) openvas_scanner_close (); - if (openvas_scanner_connect () || openvas_scanner_init (0) + if (openvas_scanner_connect () || openvas_scanner_init () || openvas_scanner_close ()) return 2; if (version) diff --git a/src/scanner.c b/src/scanner.c index 92b132524d..b97e12bc2e 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2018 Greenbone Networks GmbH +/* Copyright (C) 2014-2019 Greenbone Networks GmbH * * SPDX-License-Identifier: GPL-2.0-or-later * @@ -359,13 +359,11 @@ openvas_scanner_realloc () /** * @brief Write as much as possible from the to_scanner buffer to the scanner. * - * @param[in] nvt_cache_mode NVT cache mode. - * * @return 0 wrote everything, -1 error, -2 wrote as much as scanner accepted, * -3 did an initialisation step. */ int -openvas_scanner_write (int nvt_cache_mode) +openvas_scanner_write (void) { if (openvas_scanner_socket == -1) return -1; @@ -402,17 +400,6 @@ openvas_scanner_write (int nvt_cache_mode) scanner_init_offset = 0; return -1; } - if (nvt_cache_mode) - { - string = "CLIENT <|> NVT_INFO <|> CLIENT\n"; - scanner_init_offset = write_string_to_server - (string + scanner_init_offset); - if (scanner_init_offset == -1) - { - scanner_init_offset = 0; - return -1; - } - } break; } case SCANNER_INIT_SENT_VERSION: @@ -421,22 +408,6 @@ openvas_scanner_write (int nvt_cache_mode) case SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE: return 0; case SCANNER_INIT_GOT_FEED_VERSION: - if (nvt_cache_mode) - { - static char* const ack = "CLIENT <|> COMPLETE_LIST <|> CLIENT\n"; - scanner_init_offset = write_string_to_server - (ack + scanner_init_offset); - if (scanner_init_offset == 0) - set_scanner_init_state (nvt_cache_mode == -1 - ? SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE - : SCANNER_INIT_SENT_COMPLETE_LIST); - else if (scanner_init_offset == -1) - { - scanner_init_offset = 0; - return -1; - } - break; - } /* fallthrough */ case SCANNER_INIT_GOT_PLUGINS: { @@ -445,12 +416,7 @@ openvas_scanner_write (int nvt_cache_mode) (ack + scanner_init_offset); if (scanner_init_offset == 0) { - if (nvt_cache_mode == -1) - set_scanner_init_state (SCANNER_INIT_DONE_CACHE_MODE_UPDATE); - else if (nvt_cache_mode == -2) - set_scanner_init_state (SCANNER_INIT_DONE_CACHE_MODE); - else - set_scanner_init_state (SCANNER_INIT_DONE); + set_scanner_init_state (SCANNER_INIT_DONE); } else if (scanner_init_offset == -1) { @@ -798,20 +764,17 @@ openvas_scanner_connected () /** * @brief Initializes the already setup connection with the Scanner. * - * @param[in] cache_mode NVT Cache mode if true, which means sending NVT_INFO - * command to scanner in initial negotiation. - * * @return 0 success, -1 error. */ int -openvas_scanner_init (int cache_mode) +openvas_scanner_init (void) { int ret; if (openvas_scanner_socket == -1) return -1; from_scanner = g_malloc0 (from_scanner_size); - ret = openvas_scanner_write (cache_mode); + ret = openvas_scanner_write (); if (ret != -3) { openvas_scanner_free (); diff --git a/src/scanner.h b/src/scanner.h index 60b9ccd42f..aff1c14925 100644 --- a/src/scanner.h +++ b/src/scanner.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2018 Greenbone Networks GmbH +/* Copyright (C) 2014-2019 Greenbone Networks GmbH * * SPDX-License-Identifier: GPL-2.0-or-later * @@ -31,7 +31,7 @@ int openvas_scanner_read (); int -openvas_scanner_write (int); +openvas_scanner_write (void); int openvas_scanner_close (); @@ -70,7 +70,7 @@ int openvas_scanner_connected (); int -openvas_scanner_init (int); +openvas_scanner_init (void); int openvas_scanner_is_loading (); From 9747a8a02b57282b88e8fa88f408c57514d77e39 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Thu, 30 May 2019 11:26:07 +0200 Subject: [PATCH 02/28] Remove SCANNER_NVT_INFO status from OTP handling. --- src/otp.c | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/src/otp.c b/src/otp.c index 461919de02..5b7ce253fa 100644 --- a/src/otp.c +++ b/src/otp.c @@ -356,7 +356,6 @@ typedef enum SCANNER_LOG_HOSTNAME, SCANNER_LOG_NUMBER, SCANNER_LOG_OID, - SCANNER_NVT_INFO, SCANNER_PLUGIN_LIST_BUGTRAQ_ID, SCANNER_PLUGIN_LIST_CATEGORY, SCANNER_PLUGIN_LIST_CVE_ID, @@ -1289,38 +1288,6 @@ process_otp_scanner_input () } break; } - case SCANNER_NVT_INFO: - { - char *feed_version, *db_feed_version; - - feed_version = g_strdup (field); - g_debug (" scanner got nvti_info: %s", feed_version); - if (plugins_feed_version) - g_free (plugins_feed_version); - plugins_feed_version = feed_version; - db_feed_version = nvts_feed_version (); - if (db_feed_version - && (strcmp (plugins_feed_version, db_feed_version) == 0)) - /* NVTs are at this version already. */ - return 4; - g_info (" Updating NVT cache"); - set_scanner_state (SCANNER_DONE); - switch (parse_scanner_done (&messages)) - { - case 0: - if (scanner_init_state == SCANNER_INIT_DONE) - set_scanner_init_state (SCANNER_INIT_GOT_FEED_VERSION); - else if (acknowledge_feed_version_info ()) - goto return_error; - break; - case -1: goto return_error; - case -2: - /* Need more input. */ - if (sync_buffer ()) goto return_error; - goto return_need_more; - } - break; - } case SCANNER_PREFERENCE_NAME: { /* Use match[1] instead of field[1] for UTF-8 hack. */ @@ -1399,8 +1366,6 @@ process_otp_scanner_input () set_scanner_state (SCANNER_ALARM_HOST); else if (strcasecmp ("LOG", field) == 0) set_scanner_state (SCANNER_LOG_HOST); - else if (strcasecmp ("NVT_INFO", field) == 0) - set_scanner_state (SCANNER_NVT_INFO); else if (strcasecmp ("PLUGIN_LIST", field) == 0) { set_scanner_state (SCANNER_PLUGIN_LIST_OID); From 3a56214a274b316fee80be2345bbe454ad1039c6 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Thu, 30 May 2019 11:45:18 +0200 Subject: [PATCH 03/28] process_otp_scanner() will not return 4 anymore. --- src/gmpd.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/gmpd.c b/src/gmpd.c index 8f93f50506..e7e09de41d 100644 --- a/src/gmpd.c +++ b/src/gmpd.c @@ -974,12 +974,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. */ From a2af32abdda9479dfdd2b15a93054b911242cf5e Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Thu, 30 May 2019 12:12:11 +0200 Subject: [PATCH 04/28] Remove now unneeded SCANNER_INIT_GOT_FEED_VERSION. --- src/gmpd.c | 1 - src/otp.c | 3 --- src/otp.h | 3 +-- src/scanner.c | 2 -- 4 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/gmpd.c b/src/gmpd.c index e7e09de41d..7c021ca635 100644 --- a/src/gmpd.c +++ b/src/gmpd.c @@ -605,7 +605,6 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database, || scanner_init_state == SCANNER_INIT_DONE_CACHE_MODE_UPDATE) && 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)) openvas_scanner_fd_set (&writefds); diff --git a/src/otp.c b/src/otp.c index 5b7ce253fa..fbc3c61bae 100644 --- a/src/otp.c +++ b/src/otp.c @@ -842,9 +842,6 @@ process_otp_scanner_input () from_scanner_start += ver_len; set_scanner_init_state (SCANNER_INIT_DONE); return 0; - case SCANNER_INIT_GOT_FEED_VERSION: - /* Nothing to parse. */ - return 0; case SCANNER_INIT_GOT_PLUGINS: /* Nothing to parse. */ return 0; diff --git a/src/otp.h b/src/otp.h index a4d8f87337..cf2a4c507a 100644 --- a/src/otp.h +++ b/src/otp.h @@ -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 * @@ -45,7 +45,6 @@ typedef enum SCANNER_INIT_DONE, SCANNER_INIT_DONE_CACHE_MODE, /* Done, when in NVT cache rebuild. */ SCANNER_INIT_DONE_CACHE_MODE_UPDATE, /* Done, when in NVT cache update. */ - SCANNER_INIT_GOT_FEED_VERSION, SCANNER_INIT_GOT_PLUGINS, SCANNER_INIT_SENT_COMPLETE_LIST, SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE, diff --git a/src/scanner.c b/src/scanner.c index b97e12bc2e..2ab45eaf99 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -407,8 +407,6 @@ openvas_scanner_write (void) case SCANNER_INIT_SENT_COMPLETE_LIST: case SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE: return 0; - case SCANNER_INIT_GOT_FEED_VERSION: - /* fallthrough */ case SCANNER_INIT_GOT_PLUGINS: { static char* const ack = "\n"; From 1ed169f6256f48fe41ff5a5f86c36cd308a23b86 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Thu, 30 May 2019 12:28:00 +0200 Subject: [PATCH 05/28] Remove now unneeded SCANNER_INIT_SENT_COMPLETE_LIST. This also removes acknowledge_feed_version_info() which wasn't used anywhere. --- src/gmpd.c | 1 - src/manage.c | 14 -------------- src/manage.h | 3 --- src/otp.c | 3 --- src/otp.h | 1 - src/scanner.c | 1 - 6 files changed, 23 deletions(-) diff --git a/src/gmpd.c b/src/gmpd.c index 7c021ca635..fdca2fb3f1 100644 --- a/src/gmpd.c +++ b/src/gmpd.c @@ -591,7 +591,6 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database, && (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 ()) diff --git a/src/manage.c b/src/manage.c index 9a1f1eb4f7..3ff3981440 100644 --- a/src/manage.c +++ b/src/manage.c @@ -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. * diff --git a/src/manage.h b/src/manage.h index 070128889e..3e7a8232e6 100644 --- a/src/manage.h +++ b/src/manage.h @@ -2619,9 +2619,6 @@ override_iterator_new_severity (iterator_t *); int acknowledge_bye (); -int -acknowledge_feed_version_info (); - int manage_check_current_task (); diff --git a/src/otp.c b/src/otp.c index fbc3c61bae..195bd2db16 100644 --- a/src/otp.c +++ b/src/otp.c @@ -848,7 +848,6 @@ process_otp_scanner_input () case SCANNER_INIT_CONNECTED: /* Input from scanner before version string sent. */ return -1; - case SCANNER_INIT_SENT_COMPLETE_LIST: case SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE: case SCANNER_INIT_DONE: case SCANNER_INIT_DONE_CACHE_MODE: @@ -1213,8 +1212,6 @@ process_otp_scanner_input () { case 0: if (scanner_init_state - == SCANNER_INIT_SENT_COMPLETE_LIST - || scanner_init_state == SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE) { set_scanner_init_state (SCANNER_INIT_GOT_PLUGINS); diff --git a/src/otp.h b/src/otp.h index cf2a4c507a..f180cd282d 100644 --- a/src/otp.h +++ b/src/otp.h @@ -46,7 +46,6 @@ typedef enum SCANNER_INIT_DONE_CACHE_MODE, /* Done, when in NVT cache rebuild. */ SCANNER_INIT_DONE_CACHE_MODE_UPDATE, /* Done, when in NVT cache update. */ SCANNER_INIT_GOT_PLUGINS, - SCANNER_INIT_SENT_COMPLETE_LIST, SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE, SCANNER_INIT_SENT_VERSION, SCANNER_INIT_TOP diff --git a/src/scanner.c b/src/scanner.c index 2ab45eaf99..eb03140825 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -404,7 +404,6 @@ openvas_scanner_write (void) } case SCANNER_INIT_SENT_VERSION: return 0; - case SCANNER_INIT_SENT_COMPLETE_LIST: case SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE: return 0; case SCANNER_INIT_GOT_PLUGINS: From dd3317098e673a326143716924dc120412c4d5b5 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Thu, 30 May 2019 12:38:22 +0200 Subject: [PATCH 06/28] Remove no unneeded SCANNER...COMPLETE_LIST_UPDATE. --- src/gmpd.c | 1 - src/otp.c | 7 ------- src/otp.h | 1 - src/scanner.c | 2 -- 4 files changed, 11 deletions(-) diff --git a/src/gmpd.c b/src/gmpd.c index fdca2fb3f1..41709ca0f9 100644 --- a/src/gmpd.c +++ b/src/gmpd.c @@ -591,7 +591,6 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database, && (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_UPDATE || scanner_init_state == SCANNER_INIT_SENT_VERSION) && !openvas_scanner_full ()) openvas_scanner_fd_set (&readfds); diff --git a/src/otp.c b/src/otp.c index 195bd2db16..b222b25104 100644 --- a/src/otp.c +++ b/src/otp.c @@ -848,7 +848,6 @@ process_otp_scanner_input () case SCANNER_INIT_CONNECTED: /* Input from scanner before version string sent. */ return -1; - case SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE: case SCANNER_INIT_DONE: case SCANNER_INIT_DONE_CACHE_MODE: case SCANNER_INIT_DONE_CACHE_MODE_UPDATE: @@ -1211,12 +1210,6 @@ process_otp_scanner_input () switch (parse_scanner_done (&messages)) { case 0: - if (scanner_init_state - == SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE) - { - set_scanner_init_state (SCANNER_INIT_GOT_PLUGINS); - set_nvts_feed_version (plugins_feed_version); - } break; case -1: goto return_error; case -2: diff --git a/src/otp.h b/src/otp.h index f180cd282d..3b383c54ca 100644 --- a/src/otp.h +++ b/src/otp.h @@ -46,7 +46,6 @@ typedef enum SCANNER_INIT_DONE_CACHE_MODE, /* Done, when in NVT cache rebuild. */ SCANNER_INIT_DONE_CACHE_MODE_UPDATE, /* Done, when in NVT cache update. */ SCANNER_INIT_GOT_PLUGINS, - SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE, SCANNER_INIT_SENT_VERSION, SCANNER_INIT_TOP } scanner_init_state_t; diff --git a/src/scanner.c b/src/scanner.c index eb03140825..24945b9628 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -404,8 +404,6 @@ openvas_scanner_write (void) } case SCANNER_INIT_SENT_VERSION: return 0; - case SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE: - return 0; case SCANNER_INIT_GOT_PLUGINS: { static char* const ack = "\n"; From 19ed54999ee1c19ba2f879cabfe26391168521ec Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Thu, 30 May 2019 12:47:27 +0200 Subject: [PATCH 07/28] Remove now unneeded SCANNER_INIT_GOT_PLUGINS. --- src/gmpd.c | 3 +-- src/otp.c | 3 --- src/otp.h | 1 - src/scanner.c | 18 ------------------ 4 files changed, 1 insertion(+), 24 deletions(-) diff --git a/src/gmpd.c b/src/gmpd.c index 41709ca0f9..c656e43e31 100644 --- a/src/gmpd.c +++ b/src/gmpd.c @@ -602,8 +602,7 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database, || scanner_init_state == SCANNER_INIT_DONE_CACHE_MODE || scanner_init_state == SCANNER_INIT_DONE_CACHE_MODE_UPDATE) && to_server_buffer_space () > 0) - || scanner_init_state == SCANNER_INIT_CONNECTED - || 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 diff --git a/src/otp.c b/src/otp.c index b222b25104..c101e1a5aa 100644 --- a/src/otp.c +++ b/src/otp.c @@ -842,9 +842,6 @@ process_otp_scanner_input () from_scanner_start += ver_len; set_scanner_init_state (SCANNER_INIT_DONE); return 0; - case SCANNER_INIT_GOT_PLUGINS: - /* Nothing to parse. */ - return 0; case SCANNER_INIT_CONNECTED: /* Input from scanner before version string sent. */ return -1; diff --git a/src/otp.h b/src/otp.h index 3b383c54ca..b9a26b1db0 100644 --- a/src/otp.h +++ b/src/otp.h @@ -45,7 +45,6 @@ typedef enum SCANNER_INIT_DONE, SCANNER_INIT_DONE_CACHE_MODE, /* Done, when in NVT cache rebuild. */ SCANNER_INIT_DONE_CACHE_MODE_UPDATE, /* Done, when in NVT cache update. */ - SCANNER_INIT_GOT_PLUGINS, SCANNER_INIT_SENT_VERSION, SCANNER_INIT_TOP } scanner_init_state_t; diff --git a/src/scanner.c b/src/scanner.c index 24945b9628..3817370bac 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -404,24 +404,6 @@ openvas_scanner_write (void) } case SCANNER_INIT_SENT_VERSION: return 0; - case SCANNER_INIT_GOT_PLUGINS: - { - static char* const ack = "\n"; - scanner_init_offset = write_string_to_server - (ack + scanner_init_offset); - if (scanner_init_offset == 0) - { - set_scanner_init_state (SCANNER_INIT_DONE); - } - else if (scanner_init_offset == -1) - { - scanner_init_offset = 0; - return -1; - } - else - break; - } - /* fallthrough */ case SCANNER_INIT_DONE: case SCANNER_INIT_DONE_CACHE_MODE: case SCANNER_INIT_DONE_CACHE_MODE_UPDATE: From 6b361d92855ad16453db2f062ef7ec523dbe46cc Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Thu, 30 May 2019 12:51:34 +0200 Subject: [PATCH 08/28] Remove now unneeded SCANNER_INIT_DONE_CACHE_MODE --- src/gmpd.c | 2 -- src/otp.c | 4 +--- src/otp.h | 1 - src/scanner.c | 1 - 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/gmpd.c b/src/gmpd.c index c656e43e31..47614ff4b1 100644 --- a/src/gmpd.c +++ b/src/gmpd.c @@ -589,7 +589,6 @@ 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_VERSION) && !openvas_scanner_full ()) @@ -599,7 +598,6 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database, 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) && to_server_buffer_space () > 0) || scanner_init_state == SCANNER_INIT_CONNECTED)) diff --git a/src/otp.c b/src/otp.c index c101e1a5aa..cff9072a2e 100644 --- a/src/otp.c +++ b/src/otp.c @@ -846,7 +846,6 @@ process_otp_scanner_input () /* Input from scanner before version string sent. */ return -1; case SCANNER_INIT_DONE: - case SCANNER_INIT_DONE_CACHE_MODE: case SCANNER_INIT_DONE_CACHE_MODE_UPDATE: case SCANNER_INIT_TOP: if (scanner_state == SCANNER_TOP) @@ -1286,8 +1285,7 @@ process_otp_scanner_input () if (sync_buffer ()) goto return_error; goto return_need_more; } - if (scanner_init_state == SCANNER_INIT_DONE_CACHE_MODE - || scanner_init_state + if (scanner_init_state == SCANNER_INIT_DONE_CACHE_MODE_UPDATE) { manage_complete_nvt_cache_update diff --git a/src/otp.h b/src/otp.h index b9a26b1db0..d4b0810c83 100644 --- a/src/otp.h +++ b/src/otp.h @@ -43,7 +43,6 @@ typedef enum { SCANNER_INIT_CONNECTED, SCANNER_INIT_DONE, - SCANNER_INIT_DONE_CACHE_MODE, /* Done, when in NVT cache rebuild. */ SCANNER_INIT_DONE_CACHE_MODE_UPDATE, /* Done, when in NVT cache update. */ SCANNER_INIT_SENT_VERSION, SCANNER_INIT_TOP diff --git a/src/scanner.c b/src/scanner.c index 3817370bac..15bb3d9df3 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -405,7 +405,6 @@ openvas_scanner_write (void) case SCANNER_INIT_SENT_VERSION: return 0; case SCANNER_INIT_DONE: - case SCANNER_INIT_DONE_CACHE_MODE: case SCANNER_INIT_DONE_CACHE_MODE_UPDATE: while (1) switch (write_to_server_buffer ()) From b92023500ff84435d0de811f32354cd9062ce145 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Thu, 30 May 2019 12:58:26 +0200 Subject: [PATCH 09/28] Removed also SCANNER_INIT_DONE_CACHE_MODE_UPDATE --- src/gmpd.c | 4 +--- src/otp.c | 13 ------------- src/otp.h | 1 - src/scanner.c | 1 - 4 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/gmpd.c b/src/gmpd.c index 47614ff4b1..d7f4656489 100644 --- a/src/gmpd.c +++ b/src/gmpd.c @@ -589,7 +589,6 @@ 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_UPDATE || scanner_init_state == SCANNER_INIT_SENT_VERSION) && !openvas_scanner_full ()) openvas_scanner_fd_set (&readfds); @@ -597,8 +596,7 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database, /* 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_UPDATE) + || scanner_init_state == SCANNER_INIT_DONE) && to_server_buffer_space () > 0) || scanner_init_state == SCANNER_INIT_CONNECTED)) openvas_scanner_fd_set (&writefds); diff --git a/src/otp.c b/src/otp.c index cff9072a2e..0aa9a483c3 100644 --- a/src/otp.c +++ b/src/otp.c @@ -846,7 +846,6 @@ process_otp_scanner_input () /* Input from scanner before version string sent. */ return -1; case SCANNER_INIT_DONE: - case SCANNER_INIT_DONE_CACHE_MODE_UPDATE: case SCANNER_INIT_TOP: if (scanner_state == SCANNER_TOP) switch (parse_scanner_bad_login (&messages)) @@ -1285,18 +1284,6 @@ process_otp_scanner_input () if (sync_buffer ()) goto return_error; goto return_need_more; } - if (scanner_init_state - == SCANNER_INIT_DONE_CACHE_MODE_UPDATE) - { - manage_complete_nvt_cache_update - (scanner_plugins_list, - scanner_preferences_list); - set_scanner_init_state (SCANNER_INIT_DONE); - manage_nvt_preferences_enable (); - /* Return 1, as though the scanner sent BYE. */ - /** @todo Exit more formally with Scanner? */ - goto return_bye; - } break; } diff --git a/src/otp.h b/src/otp.h index d4b0810c83..9cbc092145 100644 --- a/src/otp.h +++ b/src/otp.h @@ -43,7 +43,6 @@ typedef enum { SCANNER_INIT_CONNECTED, SCANNER_INIT_DONE, - SCANNER_INIT_DONE_CACHE_MODE_UPDATE, /* Done, when in NVT cache update. */ SCANNER_INIT_SENT_VERSION, SCANNER_INIT_TOP } scanner_init_state_t; diff --git a/src/scanner.c b/src/scanner.c index 15bb3d9df3..5c1da435e0 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -405,7 +405,6 @@ openvas_scanner_write (void) case SCANNER_INIT_SENT_VERSION: return 0; case SCANNER_INIT_DONE: - case SCANNER_INIT_DONE_CACHE_MODE_UPDATE: while (1) switch (write_to_server_buffer ()) { From 45977ffd7e75e9a077c512ad94abb5e17c010efa Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Thu, 30 May 2019 20:08:03 +0200 Subject: [PATCH 10/28] Remove manage_complete_nvt_cache_update(). This function is not needed anymore. Subsequently also functions update_old_config_preferences(), insert_nvts_list() and insert_nvt_from_nvti(). The function make_nvt_from_nvti() is actually not needed also. But it might be used for chunked insertion of nvts and therefore it is kept and a dumy call added to make the compiler accept the presence. --- src/manage.h | 3 - src/manage_sql_nvts.c | 140 +++--------------------------------------- 2 files changed, 10 insertions(+), 133 deletions(-) diff --git a/src/manage.h b/src/manage.h index 3e7a8232e6..82797afa4f 100644 --- a/src/manage.h +++ b/src/manage.h @@ -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. */ diff --git a/src/manage_sql_nvts.c b/src/manage_sql_nvts.c index 836e6a0675..5b16d9b208 100644 --- a/src/manage_sql_nvts.c +++ b/src/manage_sql_nvts.c @@ -186,12 +186,12 @@ find_nvt (const char* oid, nvt_t* nvt) } /** - * @brief Counter for chunking in insert_nvts_list. + * @brief Counter for chunking in make_nvt_from_nvti. */ static int chunk_count = 0; /** - * @brief Size of chunk for insert_nvts_list. + * @brief Size of chunk for make_nvt_from_nvti. */ #define CHUNK_SIZE 100 @@ -371,13 +371,16 @@ insert_nvt (const nvti_t *nvti) } /** - * @brief Make an nvt from an nvti. + * @brief Insert nvtis into database in chunks. * * @param[in] nvti NVTI. */ static void make_nvt_from_nvti (const nvti_t *nvti) { + if (nvti == NULL) + return; + if (chunk_count == 0) { sql_begin_immediate (); @@ -946,21 +949,6 @@ family_count () " WHERE family != 'Credentials';"); } -/** - * @brief Insert an NVT from an nvti structure. - * - * @param[in] nvti nvti_t to insert in nvts table. - * @param[in] dummy Dummy arg for g_list_foreach. - */ -static void -insert_nvt_from_nvti (gpointer nvti, gpointer dummy) -{ - if (nvti == NULL) - return; - - make_nvt_from_nvti (nvti); -} - /** * @brief Insert a NVT preferences. * @@ -980,20 +968,6 @@ insert_nvt_preference (gpointer nvt_preference, gpointer dummy) manage_nvt_preference_add (preference->name, preference->value); } -/** - * @brief Inserts NVTs in DB from a list of nvti_t structures. - * - * @param[in] nvts_list List of nvts to be inserted. - */ -static void -insert_nvts_list (GList *nvts_list) -{ - chunk_count = 0; - g_list_foreach (nvts_list, insert_nvt_from_nvti, NULL); - if (chunk_count > 0) - sql_commit (); -} - /** * @brief Inserts NVT preferences in DB from a list of nvt_preference_t structures. * @@ -1104,104 +1078,6 @@ set_nvts_check_time () } } -/** - * @brief Update config preferences that don't have a preference ID. - */ -static void -update_old_config_preferences () -{ - iterator_t nvt_prefs; - - init_iterator (&nvt_prefs, "SELECT name FROM nvt_preferences;"); - while (next (&nvt_prefs)) - { - char **splits, *quoted_name, *quoted_pref_name; - const char *pref_name = iterator_string (&nvt_prefs, 0); - - if (!strstr (pref_name, ":")) - continue; - splits = g_strsplit (pref_name, ":", 4); - if (!splits || !splits[0] || !splits[1] || !splits[2] || !splits[3]) - { - g_warning ("%s: Erroneous NVT preference '%s'", __FUNCTION__, pref_name); - g_strfreev (splits); - continue; - } - quoted_pref_name = sql_quote (pref_name); - quoted_name = sql_quote (splits[3]); - sql ("UPDATE config_preferences SET name = '%s'" - " WHERE name = '%s:%s:%s';", - quoted_pref_name, splits[0], splits[2], quoted_name); - g_free (quoted_pref_name); - g_free (quoted_name); - g_strfreev (splits); - } - cleanup_iterator (&nvt_prefs); -} - -/** - * @brief Complete an update of the NVT cache. - * - * @param[in] nvts_list List of nvti_t to insert. - * @param[in] nvt_preferences_list List of preference_t to insert. - */ -void -manage_complete_nvt_cache_update (GList *nvts_list, GList *nvt_preferences_list) -{ - iterator_t configs; - int count; - - sql_begin_immediate (); - if (sql_is_sqlite3 ()) - { - sql ("DELETE FROM nvt_cves;"); - sql ("DELETE FROM nvts;"); - sql ("DELETE FROM nvt_preferences;"); - } - else - { - sql ("TRUNCATE nvts CASCADE;"); - sql ("TRUNCATE nvt_preferences;"); - } - sql_commit (); - - /* NVTs and preferences are buffered, insert them into DB. */ - insert_nvts_list (nvts_list); - sql_begin_immediate (); - insert_nvt_preferences_list (nvt_preferences_list); - sql_commit (); - - sql_begin_immediate (); - - /* Remove preferences from configs where the preference has vanished from - * the associated NVT. Update the ones that don't have a preference ID before - * that. */ - update_old_config_preferences (); - init_iterator (&configs, "SELECT id FROM configs;"); - while (next (&configs)) - sql ("DELETE FROM config_preferences" - " WHERE config = %llu" - " AND type = 'PLUGINS_PREFS'" - " AND name NOT IN (SELECT nvt_preferences.name FROM nvt_preferences);", - get_iterator_resource (&configs)); - cleanup_iterator (&configs); - - if (check_config_families ()) - g_warning ("%s: Error updating config families." - " One or more configs refer to an outdated family of an NVT.", - __FUNCTION__); - update_all_config_caches (); - - refresh_nvt_cves (); - - set_nvts_check_time (); - - sql_commit (); - - count = sql_int ("SELECT count (*) FROM nvts;"); - g_info ("Updating NVT cache... done (%i NVTs).", count); -} - /** * @brief Get tag field from VT. * @@ -1592,6 +1468,10 @@ update_nvts_from_vts (entity_t *get_vts_response, nvti_t *nvti = nvti_from_vt (vt); insert_nvt (nvti); +// TODO: perhaps use chunked inserts? The next line is simply +// to call the function so that compiler does not complain. + make_nvt_from_nvti (NULL); + if (update_preferences_from_vt (vt, nvti_oid (nvti), &preferences)) { sql_rollback (); From 9132d6f6d2db44c921ebe2194172524ab5b34e1e Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Thu, 30 May 2019 21:43:24 +0200 Subject: [PATCH 11/28] Drop unneeded SCANNER_PLUGIN_LIST_BUGTRAQ_ID. --- src/otp.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/otp.c b/src/otp.c index 0aa9a483c3..24b6243272 100644 --- a/src/otp.c +++ b/src/otp.c @@ -356,7 +356,6 @@ typedef enum SCANNER_LOG_HOSTNAME, SCANNER_LOG_NUMBER, SCANNER_LOG_OID, - SCANNER_PLUGIN_LIST_BUGTRAQ_ID, SCANNER_PLUGIN_LIST_CATEGORY, SCANNER_PLUGIN_LIST_CVE_ID, SCANNER_PLUGIN_LIST_FAMILY, @@ -1244,14 +1243,6 @@ process_otp_scanner_input () if (strcmp (field, "NOCVE")) nvti_add_refs (current_plugin, "cve", field, ""); - set_scanner_state (SCANNER_PLUGIN_LIST_BUGTRAQ_ID); - break; - } - case SCANNER_PLUGIN_LIST_BUGTRAQ_ID: - { - if (strcmp (field, "NOBID")) - nvti_add_refs (current_plugin, "bid", field, ""); - set_scanner_state (SCANNER_PLUGIN_LIST_XREFS); break; } From 26477d1d9c2ac326483790031bfc93104a9332ca Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Thu, 30 May 2019 21:48:28 +0200 Subject: [PATCH 12/28] Drop unneeded SCANNER_PLUGIN_LIST_CVE_ID. --- src/otp.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/otp.c b/src/otp.c index 24b6243272..309d56c1ea 100644 --- a/src/otp.c +++ b/src/otp.c @@ -357,7 +357,6 @@ typedef enum SCANNER_LOG_NUMBER, SCANNER_LOG_OID, SCANNER_PLUGIN_LIST_CATEGORY, - SCANNER_PLUGIN_LIST_CVE_ID, SCANNER_PLUGIN_LIST_FAMILY, SCANNER_PLUGIN_LIST_NAME, SCANNER_PLUGIN_LIST_OID, @@ -1235,14 +1234,6 @@ process_otp_scanner_input () case SCANNER_PLUGIN_LIST_FAMILY: { nvti_set_family (current_plugin, field); - set_scanner_state (SCANNER_PLUGIN_LIST_CVE_ID); - break; - } - case SCANNER_PLUGIN_LIST_CVE_ID: - { - if (strcmp (field, "NOCVE")) - nvti_add_refs (current_plugin, "cve", field, ""); - set_scanner_state (SCANNER_PLUGIN_LIST_XREFS); break; } From 0ba6654d606a197bd9d1a51041b3b21bebb39f67 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Thu, 30 May 2019 21:52:25 +0200 Subject: [PATCH 13/28] Drop unneeded SCANNER_PLUGIN_LIST_FAMILY. --- src/otp.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/otp.c b/src/otp.c index 309d56c1ea..2d851d1259 100644 --- a/src/otp.c +++ b/src/otp.c @@ -357,7 +357,6 @@ typedef enum SCANNER_LOG_NUMBER, SCANNER_LOG_OID, SCANNER_PLUGIN_LIST_CATEGORY, - SCANNER_PLUGIN_LIST_FAMILY, SCANNER_PLUGIN_LIST_NAME, SCANNER_PLUGIN_LIST_OID, SCANNER_PLUGIN_LIST_TAGS, @@ -1228,12 +1227,6 @@ process_otp_scanner_input () case SCANNER_PLUGIN_LIST_CATEGORY: { nvti_set_category (current_plugin, atoi (field)); - set_scanner_state (SCANNER_PLUGIN_LIST_FAMILY); - break; - } - case SCANNER_PLUGIN_LIST_FAMILY: - { - nvti_set_family (current_plugin, field); set_scanner_state (SCANNER_PLUGIN_LIST_XREFS); break; } From 2bbcd7f6c0558921dde6be88f113c785bdd4db59 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Thu, 30 May 2019 21:58:34 +0200 Subject: [PATCH 14/28] Remove uneeded SCANNER_PLUGIN_LIST_CATEGORY. --- src/otp.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/otp.c b/src/otp.c index 2d851d1259..f75ad7a685 100644 --- a/src/otp.c +++ b/src/otp.c @@ -356,7 +356,6 @@ typedef enum SCANNER_LOG_HOSTNAME, SCANNER_LOG_NUMBER, SCANNER_LOG_OID, - SCANNER_PLUGIN_LIST_CATEGORY, SCANNER_PLUGIN_LIST_NAME, SCANNER_PLUGIN_LIST_OID, SCANNER_PLUGIN_LIST_TAGS, @@ -1221,12 +1220,6 @@ process_otp_scanner_input () case SCANNER_PLUGIN_LIST_NAME: { nvti_set_name (current_plugin, field); - set_scanner_state (SCANNER_PLUGIN_LIST_CATEGORY); - break; - } - case SCANNER_PLUGIN_LIST_CATEGORY: - { - nvti_set_category (current_plugin, atoi (field)); set_scanner_state (SCANNER_PLUGIN_LIST_XREFS); break; } From cb144c973d5570e14de463b0948e849c17796c32 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Fri, 31 May 2019 10:16:39 +0200 Subject: [PATCH 15/28] Drop unneeded SCANNER_PLUGIN_LIST_NAME. --- src/otp.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/otp.c b/src/otp.c index f75ad7a685..4e1b88531b 100644 --- a/src/otp.c +++ b/src/otp.c @@ -356,7 +356,6 @@ typedef enum SCANNER_LOG_HOSTNAME, SCANNER_LOG_NUMBER, SCANNER_LOG_OID, - SCANNER_PLUGIN_LIST_NAME, SCANNER_PLUGIN_LIST_OID, SCANNER_PLUGIN_LIST_TAGS, SCANNER_PLUGIN_LIST_XREFS, @@ -1214,12 +1213,6 @@ process_otp_scanner_input () current_plugin = nvti_new (); if (current_plugin == NULL) abort (); nvti_set_oid (current_plugin, field); - set_scanner_state (SCANNER_PLUGIN_LIST_NAME); - break; - } - case SCANNER_PLUGIN_LIST_NAME: - { - nvti_set_name (current_plugin, field); set_scanner_state (SCANNER_PLUGIN_LIST_XREFS); break; } From 118e6707579471a53527da2747af885663df31b0 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Fri, 31 May 2019 10:21:31 +0200 Subject: [PATCH 16/28] Drop unneeded SCANNER_PLUGIN_LIST_XREFS. --- src/otp.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/otp.c b/src/otp.c index 4e1b88531b..538e5a806e 100644 --- a/src/otp.c +++ b/src/otp.c @@ -358,7 +358,6 @@ typedef enum SCANNER_LOG_OID, SCANNER_PLUGIN_LIST_OID, SCANNER_PLUGIN_LIST_TAGS, - SCANNER_PLUGIN_LIST_XREFS, SCANNER_PREFERENCE_NAME, SCANNER_PREFERENCE_VALUE, SCANNER_SERVER, @@ -1213,22 +1212,7 @@ process_otp_scanner_input () current_plugin = nvti_new (); if (current_plugin == NULL) abort (); nvti_set_oid (current_plugin, field); - set_scanner_state (SCANNER_PLUGIN_LIST_XREFS); - break; - } - case SCANNER_PLUGIN_LIST_XREFS: - { - if (strcmp (field, "NOXREF")) - nvti_add_refs (current_plugin, NULL, field, ""); - set_scanner_state (SCANNER_PLUGIN_LIST_TAGS); - switch (parse_scanner_plugin_list_tags (&messages)) - { - case -2: - /* Need more input. */ - if (sync_buffer ()) goto return_error; - goto return_need_more; - } break; } case SCANNER_PREFERENCE_NAME: From 7ceb3ef85be19278118674a1adb859b4bd895179 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Fri, 31 May 2019 10:26:14 +0200 Subject: [PATCH 17/28] Drop uneeded SCANNER_PLUGIN_LIST_TAGS. Subsequently, also used functions and a static global vairable are removed as they are unused now. --- src/otp.c | 72 +------------------------------------------------------ 1 file changed, 1 insertion(+), 71 deletions(-) diff --git a/src/otp.c b/src/otp.c index 538e5a806e..5060658c88 100644 --- a/src/otp.c +++ b/src/otp.c @@ -310,11 +310,6 @@ static char* current_scanner_preference = NULL; */ static nvti_t* current_plugin = NULL; -/** - * @brief The full plugins list, during reading of scanner plugin list. - */ -static GList* scanner_plugins_list = NULL; - /** * @brief The full preferences list, during reading of scanner plugin list. */ @@ -357,7 +352,6 @@ typedef enum SCANNER_LOG_NUMBER, SCANNER_LOG_OID, SCANNER_PLUGIN_LIST_OID, - SCANNER_PLUGIN_LIST_TAGS, SCANNER_PREFERENCE_NAME, SCANNER_PREFERENCE_VALUE, SCANNER_SERVER, @@ -586,62 +580,6 @@ parse_scanner_preference_value (char** messages) return -2; } -/** - * @brief Parse the tags of a plugin list. - * - * @param messages A pointer into the OTP input buffer. - * - * @return 0 success, -2 too few characters (need more input). - */ -static int -parse_scanner_plugin_list_tags (char** messages) -{ - char *value, *end, *match; - assert (current_plugin != NULL); - end = *messages + from_scanner_end - from_scanner_start; - while (*messages < end && ((*messages)[0] == ' ')) - { (*messages)++; from_scanner_start++; } - if ((match = memchr (*messages, - (int) '\n', - from_scanner_end - from_scanner_start))) - { - match[0] = '\0'; - value = g_strdup (*messages); - blank_control_chars (value); - if (value != NULL) - { - char* pos = value; - while (*pos) - { - if (*pos == ';') - *pos = '\n'; - pos++; - } - } - if (current_plugin) - { - gchar *tags, *cvss_base; - parse_tags (value, &tags, &cvss_base); - nvti_set_tag (current_plugin, tags); - nvti_set_cvss_base (current_plugin, cvss_base); - g_free (tags); - g_free (cvss_base); - - /* Add the plugin to scanner_plugins_list which will be bulk-inserted - * in DB later in manage_complete_nvt_cache_update. */ - scanner_plugins_list = g_list_prepend (scanner_plugins_list, - current_plugin); - current_plugin = NULL; - } - set_scanner_state (SCANNER_PLUGIN_LIST_OID); - from_scanner_start += match + 1 - *messages; - *messages = match + 1; - g_free (value); - return 0; - } - return -2; -} - /** * @brief Parse the field following "SERVER <|>". * @@ -856,14 +794,6 @@ process_otp_scanner_input () if (sync_buffer ()) return -1; return 0; } - else if (scanner_state == SCANNER_PLUGIN_LIST_TAGS) - switch (parse_scanner_plugin_list_tags (&messages)) - { - case -2: - /* Need more input. */ - if (sync_buffer ()) return -1; - return 0; - } else if (scanner_state == SCANNER_PREFERENCE_VALUE) { switch (parse_scanner_preference_value (&messages)) @@ -1212,7 +1142,7 @@ process_otp_scanner_input () current_plugin = nvti_new (); if (current_plugin == NULL) abort (); nvti_set_oid (current_plugin, field); - set_scanner_state (SCANNER_PLUGIN_LIST_TAGS); + set_scanner_state (SCANNER_PLUGIN_LIST_OID); break; } case SCANNER_PREFERENCE_NAME: From 4e50be69d6f815f97d603b8c9eacfc9aeb7f589a Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Fri, 31 May 2019 10:29:22 +0200 Subject: [PATCH 18/28] Drop uneeded SCANNER_PLUGIN_LIST_OID. And subsequently unused global variable. --- src/otp.c | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/src/otp.c b/src/otp.c index 5060658c88..80a3d24612 100644 --- a/src/otp.c +++ b/src/otp.c @@ -305,11 +305,6 @@ static char* current_scanner_preference = NULL; /* Scanner plugins. */ -/** - * @brief The current plugin, during reading of scanner plugin list. - */ -static nvti_t* current_plugin = NULL; - /** * @brief The full preferences list, during reading of scanner plugin list. */ @@ -351,7 +346,6 @@ typedef enum SCANNER_LOG_HOSTNAME, SCANNER_LOG_NUMBER, SCANNER_LOG_OID, - SCANNER_PLUGIN_LIST_OID, SCANNER_PREFERENCE_NAME, SCANNER_PREFERENCE_VALUE, SCANNER_SERVER, @@ -1120,31 +1114,6 @@ process_otp_scanner_input () } break; } - case SCANNER_PLUGIN_LIST_OID: - { - /* Use match[1] instead of field[1] for UTF-8 hack. */ - if (strlen (field) == 0 && match[1] == '|') - { - set_scanner_state (SCANNER_DONE); - switch (parse_scanner_done (&messages)) - { - case 0: - break; - case -1: goto return_error; - case -2: - /* Need more input. */ - if (sync_buffer ()) goto return_error; - goto return_need_more; - } - break; - } - assert (current_plugin == NULL); - current_plugin = nvti_new (); - if (current_plugin == NULL) abort (); - nvti_set_oid (current_plugin, field); - set_scanner_state (SCANNER_PLUGIN_LIST_OID); - break; - } case SCANNER_PREFERENCE_NAME: { /* Use match[1] instead of field[1] for UTF-8 hack. */ @@ -1212,7 +1181,6 @@ process_otp_scanner_input () set_scanner_state (SCANNER_LOG_HOST); else if (strcasecmp ("PLUGIN_LIST", field) == 0) { - set_scanner_state (SCANNER_PLUGIN_LIST_OID); } else if (strcasecmp ("PREFERENCES", field) == 0) { From 7db04ecbe2f68ec53ac79f374bb92b88b96f6407 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Fri, 31 May 2019 10:30:54 +0200 Subject: [PATCH 19/28] Remove handling of PLUGIN_LIST OTP response. --- src/otp.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/otp.c b/src/otp.c index 80a3d24612..ad826833d0 100644 --- a/src/otp.c +++ b/src/otp.c @@ -1179,9 +1179,6 @@ process_otp_scanner_input () set_scanner_state (SCANNER_ALARM_HOST); else if (strcasecmp ("LOG", field) == 0) set_scanner_state (SCANNER_LOG_HOST); - else if (strcasecmp ("PLUGIN_LIST", field) == 0) - { - } else if (strcasecmp ("PREFERENCES", field) == 0) { assert (current_scanner_preference == NULL); From b15692b0be199b52ae29ea4cfb61e4e572a6aac2 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Fri, 31 May 2019 22:48:23 +0200 Subject: [PATCH 20/28] Revert "void" in proto. This is to be consistent with other protos. --- src/scanner.c | 4 ++-- src/scanner.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/scanner.c b/src/scanner.c index 5c1da435e0..67f46d7e25 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -363,7 +363,7 @@ openvas_scanner_realloc () * -3 did an initialisation step. */ int -openvas_scanner_write (void) +openvas_scanner_write () { if (openvas_scanner_socket == -1) return -1; @@ -742,7 +742,7 @@ openvas_scanner_connected () * @return 0 success, -1 error. */ int -openvas_scanner_init (void) +openvas_scanner_init () { int ret; diff --git a/src/scanner.h b/src/scanner.h index aff1c14925..94fe39493d 100644 --- a/src/scanner.h +++ b/src/scanner.h @@ -31,7 +31,7 @@ int openvas_scanner_read (); int -openvas_scanner_write (void); +openvas_scanner_write (); int openvas_scanner_close (); @@ -70,7 +70,7 @@ int openvas_scanner_connected (); int -openvas_scanner_init (void); +openvas_scanner_init (); int openvas_scanner_is_loading (); From d6388f86bdc2e44d3e12184da464b9d15b105744 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Fri, 31 May 2019 22:51:42 +0200 Subject: [PATCH 21/28] Remove make_nvt_from_nvti(). Currently it is not really used, so remove it. If we really need it later, we can pull it from the repository. --- src/manage_sql_nvts.c | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/src/manage_sql_nvts.c b/src/manage_sql_nvts.c index 5b16d9b208..c0af88e279 100644 --- a/src/manage_sql_nvts.c +++ b/src/manage_sql_nvts.c @@ -185,16 +185,6 @@ find_nvt (const char* oid, nvt_t* nvt) return FALSE; } -/** - * @brief Counter for chunking in make_nvt_from_nvti. - */ -static int chunk_count = 0; - -/** - * @brief Size of chunk for make_nvt_from_nvti. - */ -#define CHUNK_SIZE 100 - /** * @brief Insert an NVT. * @@ -370,33 +360,6 @@ insert_nvt (const nvti_t *nvti) g_free (quoted_qod_type); } -/** - * @brief Insert nvtis into database in chunks. - * - * @param[in] nvti NVTI. - */ -static void -make_nvt_from_nvti (const nvti_t *nvti) -{ - if (nvti == NULL) - return; - - if (chunk_count == 0) - { - sql_begin_immediate (); - chunk_count++; - } - else if (chunk_count == CHUNK_SIZE) - chunk_count = 0; - else - chunk_count++; - - insert_nvt (nvti); - - if (chunk_count == 0) - sql_commit (); -} - /** * @brief Initialise an NVT iterator. * @@ -1468,9 +1431,6 @@ update_nvts_from_vts (entity_t *get_vts_response, nvti_t *nvti = nvti_from_vt (vt); insert_nvt (nvti); -// TODO: perhaps use chunked inserts? The next line is simply -// to call the function so that compiler does not complain. - make_nvt_from_nvti (NULL); if (update_preferences_from_vt (vt, nvti_oid (nvti), &preferences)) { From 8e51e503499e9a204cc660ec7ba8cb9292495dd7 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Fri, 31 May 2019 23:33:31 +0200 Subject: [PATCH 22/28] Drop update_nvt_cache(). This function handled OTP-based NVT update. Removed call of this function and also the function itself. --- src/gvmd.c | 86 ------------------------------------------------------ 1 file changed, 86 deletions(-) diff --git a/src/gvmd.c b/src/gvmd.c index a6c74ab4d0..48804a8af6 100644 --- a/src/gvmd.c +++ b/src/gvmd.c @@ -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. * @@ -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)); } } } From 5a8593634e2a15851c090e6d56a71300a53817c9 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Sat, 1 Jun 2019 00:09:53 +0200 Subject: [PATCH 23/28] Remove nvt_cache_mode param from init_gmpd(). It is only called with 0 anyway. --- src/gmpd.c | 4 ++-- src/gmpd.h | 2 +- src/gvmd.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gmpd.c b/src/gmpd.c index d7f4656489..c8cb5e3b42 100644 --- a/src/gmpd.c +++ b/src/gmpd.c @@ -105,12 +105,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, 0, database, max_ips_per_target, max_email_attachment_size, max_email_include_size, max_email_message_size, fork_connection, skip_db_check); diff --git a/src/gmpd.h b/src/gmpd.h index 7c6e2a9a8b..5c5345e117 100644 --- a/src/gmpd.h +++ b/src/gmpd.h @@ -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 diff --git a/src/gvmd.c b/src/gvmd.c index 48804a8af6..0346fd11c6 100644 --- a/src/gvmd.c +++ b/src/gvmd.c @@ -2542,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)) From dc2be3a169f3f6027fd32f97cf29615e2f035fdf Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Sat, 1 Jun 2019 00:24:57 +0200 Subject: [PATCH 24/28] Drop nvt_chache_mode from init_gmp(). It is called with "0" always anyway. --- src/gmp.c | 4 ++-- src/gmp.h | 4 ++-- src/gmpd.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index eb1fb7be8b..d1cbd1ed34 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -30124,7 +30124,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) @@ -30134,7 +30134,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, 0, database, max_ips_per_target, max_email_attachment_size, max_email_include_size, max_email_message_size, fork_connection, skip_db_check); diff --git a/src/gmp.h b/src/gmp.h index dbb313f2e4..f48b9bcf58 100644 --- a/src/gmp.h +++ b/src/gmp.h @@ -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 * @@ -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 diff --git a/src/gmpd.c b/src/gmpd.c index c8cb5e3b42..ac318abac4 100644 --- a/src/gmpd.c +++ b/src/gmpd.c @@ -110,7 +110,7 @@ init_gmpd (GSList *log_config, const gchar *database, 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, 0, 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); From 367a3fa14dcab316aae478071f098af4966dc78b Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Sat, 1 Jun 2019 00:31:07 +0200 Subject: [PATCH 25/28] Remove nvt_cache_mode from init_manage(). It is called with "0" always anyway. --- src/gmp.c | 2 +- src/manage.h | 2 +- src/manage_sql.c | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index d1cbd1ed34..87fe519cd1 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -30134,7 +30134,7 @@ init_gmp (GSList *log_config, const gchar *database, (GLogFunc) gvm_log_func, log_config); command_data_init (&command_data); - return init_manage (log_config, 0, 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); diff --git a/src/manage.h b/src/manage.h index 82797afa4f..2c5bf34781 100644 --- a/src/manage.h +++ b/src/manage.h @@ -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 diff --git a/src/manage_sql.c b/src/manage_sql.c index 1b7e8eee52..c34b0878d9 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -18217,7 +18217,6 @@ init_manage_internal (GSList *log_config, * problems. * * @param[in] log_config Log configuration. - * @param[in] nvt_cache_mode True when running in NVT caching mode. * @param[in] database Location of database. * @param[in] max_ips_per_target Max number of IPs per target. * @param[in] max_email_attachment_size Max size of email attachments. @@ -18232,14 +18231,14 @@ init_manage_internal (GSList *log_config, * to be initialised from server, -4 max_ips_per_target out of range. */ int -init_manage (GSList *log_config, int nvt_cache_mode, const gchar *database, +init_manage (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_manage_internal (log_config, - nvt_cache_mode, + 0, database, max_ips_per_target, max_email_attachment_size, From d2e7f84b4c644569941c274d87ab39c7265b3b19 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Sat, 1 Jun 2019 00:35:52 +0200 Subject: [PATCH 26/28] Drop nvt_cache_mode param from init_manage_internal It is called with "0" always anyway. --- src/manage_sql.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index c34b0878d9..904b6b7029 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -18070,7 +18070,6 @@ cleanup_tables () * Optionally also stop active tasks. * * @param[in] log_config Log configuration. - * @param[in] nvt_cache_mode True when running in NVT caching mode. * @param[in] database Location of database. * @param[in] max_ips_per_target Max number of IPs per target. * @param[in] max_email_attachment_size Max size of email attachments. @@ -18088,7 +18087,6 @@ cleanup_tables () */ static int init_manage_internal (GSList *log_config, - int nvt_cache_mode, const gchar *database, int max_ips_per_target, int max_email_attachment_size, @@ -18163,7 +18161,7 @@ init_manage_internal (GSList *log_config, /* Check that the versions of the databases are correct. */ - ret = check_db_versions (nvt_cache_mode); + ret = check_db_versions (0); if (ret) return ret; @@ -18190,7 +18188,7 @@ init_manage_internal (GSList *log_config, sql ("INSERT INTO meta (name, value) VALUES ('max_hosts', %i);", max_hosts); } - if (stop_tasks && (nvt_cache_mode == 0)) + if (stop_tasks) /* Stop any active tasks. */ stop_active_tasks (); @@ -18238,7 +18236,6 @@ init_manage (GSList *log_config, const gchar *database, int skip_db_check) { return init_manage_internal (log_config, - 0, database, max_ips_per_target, max_email_attachment_size, @@ -18269,7 +18266,6 @@ init_manage_helper (GSList *log_config, const gchar *database, int max_ips_per_target) { return init_manage_internal (log_config, - 0, /* Run daemon in NVT cache mode. */ database, max_ips_per_target, 0, /* Default max_email_attachment_size. */ From de2c1137bb983e5dfa99235efc896506395f408e Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Sat, 1 Jun 2019 00:40:03 +0200 Subject: [PATCH 27/28] Drop nvti_cache_mode from check_db_versions(). It is always "0", so remove the parameter and the conditional for non-"0" as it can never happen anymore. --- src/manage_sql.c | 65 ++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 44 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index 904b6b7029..27f9ec0e71 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -16686,19 +16686,20 @@ add_role_permission_resource (const gchar *role_id, const gchar *permission, * @return 0 success, -1 error, -2 database is wrong version. */ static int -check_db_versions (int nvt_cache_mode) +check_db_versions () { char *database_version; int scap_db_version, cert_db_version; + long long int count; database_version = sql_string ("SELECT value FROM %s.meta" " WHERE name = 'database_version';", sql_schema ()); - if (nvt_cache_mode) + + if (database_version) { - if (database_version - && strcmp (database_version, - G_STRINGIFY (GVMD_DATABASE_VERSION))) + if (strcmp (database_version, + G_STRINGIFY (GVMD_DATABASE_VERSION))) { g_message ("%s: database version of database: %s", __FUNCTION__, @@ -16711,47 +16712,23 @@ check_db_versions (int nvt_cache_mode) } g_free (database_version); - /* If database_version was NULL then meta was missing, so assume - * that the database is missing, which is OK. */ - } - else - { - long long int count; - - if (database_version) - { - if (strcmp (database_version, - G_STRINGIFY (GVMD_DATABASE_VERSION))) - { - g_message ("%s: database version of database: %s", - __FUNCTION__, - database_version); - g_message ("%s: database version supported by manager: %s", - __FUNCTION__, - G_STRINGIFY (GVMD_DATABASE_VERSION)); - g_free (database_version); - return -2; - } - g_free (database_version); - - /* Check that the database was initialised from the scanner. - * - * This can also fail after a migration, for example if the database - * was created before NVT preferences were cached in the database. - */ + /* Check that the database was initialised from the scanner. + * + * This can also fail after a migration, for example if the database + * was created before NVT preferences were cached in the database. + */ - if (sql_int64 (&count, - "SELECT count(*) FROM %s.meta" - " WHERE name = 'nvts_feed_version'" - " OR name = 'nvt_preferences_enabled';", - sql_schema ()) - || count < 2) - g_warning ("database must be initialised from scanner"); - } - else - /* Assume database is missing. */ + if (sql_int64 (&count, + "SELECT count(*) FROM %s.meta" + " WHERE name = 'nvts_feed_version'" + " OR name = 'nvt_preferences_enabled';", + sql_schema ()) + || count < 2) g_warning ("database must be initialised from scanner"); } + else + /* Assume database is missing. */ + g_warning ("database must be initialised from scanner"); /* Check SCAP database version. */ @@ -18161,7 +18138,7 @@ init_manage_internal (GSList *log_config, /* Check that the versions of the databases are correct. */ - ret = check_db_versions (0); + ret = check_db_versions (); if (ret) return ret; From 7c4b58b61a650f6fa2d98c558f9a99dfb8d5866c Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Sat, 1 Jun 2019 00:54:17 +0200 Subject: [PATCH 28/28] Fix doc strings. --- src/gmp.c | 1 - src/gmpd.c | 1 - src/manage_sql.c | 2 -- 3 files changed, 4 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index 87fe519cd1..a6f8482cae 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -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. diff --git a/src/gmpd.c b/src/gmpd.c index ac318abac4..3b52074f4a 100644 --- a/src/gmpd.c +++ b/src/gmpd.c @@ -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. diff --git a/src/manage_sql.c b/src/manage_sql.c index 27f9ec0e71..1e57517e4d 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -16681,8 +16681,6 @@ add_role_permission_resource (const gchar *role_id, const gchar *permission, /** * @brief Ensure that the databases are the right versions. * - * @param[in] nvt_cache_mode True when running in NVT caching mode. - * * @return 0 success, -1 error, -2 database is wrong version. */ static int