diff --git a/src/gmp.c b/src/gmp.c index eb1fb7be8b..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. @@ -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) @@ -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); 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 ec69a9206b..3b52074f4a 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 * @@ -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. @@ -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); @@ -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; @@ -589,10 +588,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_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); @@ -600,13 +595,9 @@ 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 - || 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 @@ -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; @@ -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; @@ -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. */ 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 a6c74ab4d0..0346fd11c6 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)); } } } @@ -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)) diff --git a/src/manage.c b/src/manage.c index b1a69711ee..3ff3981440 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; @@ -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..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 @@ -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. */ @@ -2619,9 +2616,6 @@ override_iterator_new_severity (iterator_t *); int acknowledge_bye (); -int -acknowledge_feed_version_info (); - int manage_check_current_task (); diff --git a/src/manage_sql.c b/src/manage_sql.c index 9eaa10ef44..1e57517e4d 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 * @@ -16681,24 +16681,23 @@ 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 -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 +16710,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. */ @@ -18070,7 +18045,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 +18062,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 +18136,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 (); if (ret) return ret; @@ -18190,7 +18163,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 (); @@ -18217,7 +18190,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 +18204,13 @@ 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, database, max_ips_per_target, max_email_attachment_size, @@ -18270,7 +18241,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. */ @@ -49465,7 +49435,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/manage_sql_nvts.c b/src/manage_sql_nvts.c index 8feb1354de..4e1d597682 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 insert_nvts_list. - */ -static int chunk_count = 0; - -/** - * @brief Size of chunk for insert_nvts_list. - */ -#define CHUNK_SIZE 100 - /** * @brief Insert an NVT. * @@ -393,30 +383,6 @@ insert_nvt (const nvti_t *nvti) g_free (quoted_qod_type); } -/** - * @brief Make an nvt from an nvti. - * - * @param[in] nvti NVTI. - */ -static void -make_nvt_from_nvti (const nvti_t *nvti) -{ - 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. * @@ -969,21 +935,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. * @@ -1003,20 +954,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. * @@ -1127,104 +1064,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. * @@ -1615,6 +1454,7 @@ update_nvts_from_vts (entity_t *get_vts_response, nvti_t *nvti = nvti_from_vt (vt); insert_nvt (nvti); + if (update_preferences_from_vt (vt, nvti_oid (nvti), &preferences)) { sql_rollback (); diff --git a/src/otp.c b/src/otp.c index 461919de02..ad826833d0 100644 --- a/src/otp.c +++ b/src/otp.c @@ -305,16 +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 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. */ @@ -356,15 +346,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, - SCANNER_PLUGIN_LIST_FAMILY, - SCANNER_PLUGIN_LIST_NAME, - SCANNER_PLUGIN_LIST_OID, - SCANNER_PLUGIN_LIST_TAGS, - SCANNER_PLUGIN_LIST_XREFS, SCANNER_PREFERENCE_NAME, SCANNER_PREFERENCE_VALUE, SCANNER_SERVER, @@ -593,62 +574,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 <|>". * @@ -843,20 +768,10 @@ 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; 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: - case SCANNER_INIT_DONE_CACHE_MODE_UPDATE: case SCANNER_INIT_TOP: if (scanner_state == SCANNER_TOP) switch (parse_scanner_bad_login (&messages)) @@ -873,14 +788,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)) @@ -1207,120 +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: - 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); - set_nvts_feed_version (plugins_feed_version); - } - 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_NAME); - break; - } - 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_FAMILY); - break; - } - 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_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; - } - 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_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. */ @@ -1335,19 +1128,6 @@ 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 - == 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; } @@ -1399,12 +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 ("NVT_INFO", field) == 0) - set_scanner_state (SCANNER_NVT_INFO); - else if (strcasecmp ("PLUGIN_LIST", field) == 0) - { - set_scanner_state (SCANNER_PLUGIN_LIST_OID); - } else if (strcasecmp ("PREFERENCES", field) == 0) { assert (current_scanner_preference == NULL); diff --git a/src/otp.h b/src/otp.h index a4d8f87337..9cbc092145 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 * @@ -43,12 +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_GOT_FEED_VERSION, - SCANNER_INIT_GOT_PLUGINS, - SCANNER_INIT_SENT_COMPLETE_LIST, - 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 92b132524d..67f46d7e25 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 () { if (openvas_scanner_socket == -1) return -1; @@ -402,68 +400,11 @@ 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: return 0; - case SCANNER_INIT_SENT_COMPLETE_LIST: - 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: - { - static char* const ack = "\n"; - scanner_init_offset = write_string_to_server - (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); - } - 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: while (1) switch (write_to_server_buffer ()) { @@ -798,20 +739,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 () { 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..94fe39493d 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 (); int openvas_scanner_close (); @@ -70,7 +70,7 @@ int openvas_scanner_connected (); int -openvas_scanner_init (int); +openvas_scanner_init (); int openvas_scanner_is_loading ();