From 444601d7ac16ddb1190dda553b45ed0ad2add7e5 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 17 Sep 2021 14:15:48 +0200 Subject: [PATCH 1/6] Removed first OSP scanner specific code. Removed first OSP scanner specific code from gmp.c, gvmd.c, manage.c and manage_sql.c --- src/gmp.c | 3 +-- src/gvmd.c | 4 ---- src/manage.c | 14 +------------- src/manage_sql.c | 6 +----- 4 files changed, 3 insertions(+), 24 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index c1da7f7d8..399b655c1 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -15439,8 +15439,7 @@ handle_get_scanners (gmp_parser_t *gmp_parser, GError **error) cleanup_iterator (&tasks); SEND_TO_CLIENT_OR_FAIL (""); } - if ((scanner_iterator_type (&scanners) == SCANNER_TYPE_OSP - || scanner_iterator_type (&scanners) == SCANNER_TYPE_OPENVAS) + if ((scanner_iterator_type (&scanners) == SCANNER_TYPE_OPENVAS) && get_scanners_data->get.details) { char *s_name = NULL, *s_ver = NULL; diff --git a/src/gvmd.c b/src/gvmd.c index cba9a14e3..d3fb1ec76 100644 --- a/src/gvmd.c +++ b/src/gvmd.c @@ -2668,8 +2668,6 @@ gvmd (int argc, char** argv) if (!scanner_type || !strcasecmp (scanner_type, "OpenVAS")) type = SCANNER_TYPE_OPENVAS; - else if (!strcasecmp (scanner_type, "OSP")) - type = SCANNER_TYPE_OSP; else if (!strcasecmp (scanner_type, "OSP-Sensor")) type = SCANNER_TYPE_OSP_SENSOR; else @@ -2712,8 +2710,6 @@ gvmd (int argc, char** argv) if (strcasecmp (scanner_type, "OpenVAS") == 0) type = SCANNER_TYPE_OPENVAS; - else if (strcasecmp (scanner_type, "OSP") == 0) - type = SCANNER_TYPE_OSP; else if (!strcasecmp (scanner_type, "OSP-Sensor")) type = SCANNER_TYPE_OSP_SENSOR; else diff --git a/src/manage.c b/src/manage.c index acb694db4..328c71285 100644 --- a/src/manage.c +++ b/src/manage.c @@ -2755,17 +2755,7 @@ run_osp_scan_get_report (task_t task, int from, char **report_id) resume_report = 0; *report_id = NULL; - if (from == 1 - && scanner_type (task_scanner (task)) == SCANNER_TYPE_OSP) - { - g_warning ("%s: Scanner type does not support resuming scans", - __func__); - return -1; - } - - if (from - && scanner_type (task_scanner (task)) != SCANNER_TYPE_OSP - && task_last_resumable_report (task, &resume_report)) + if (from && task_last_resumable_report (task, &resume_report)) { g_warning ("%s: error getting report to resume", __func__); return -1; @@ -3630,7 +3620,6 @@ run_task (const char *task_id, char **report_id, int from) return run_cve_task (task); if (scanner_type (scanner) == SCANNER_TYPE_OPENVAS - || scanner_type (scanner) == SCANNER_TYPE_OSP || scanner_type (scanner) == SCANNER_TYPE_OSP_SENSOR) return run_osp_task (task, from, report_id); @@ -3783,7 +3772,6 @@ stop_task (const char *task_id) return 3; if (scanner_type (task_scanner (task)) == SCANNER_TYPE_OPENVAS - || scanner_type (task_scanner (task)) == SCANNER_TYPE_OSP || scanner_type (task_scanner (task)) == SCANNER_TYPE_OSP_SENSOR) return stop_osp_task (task); diff --git a/src/manage_sql.c b/src/manage_sql.c index 225f76dd6..6971d0f57 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -40216,8 +40216,7 @@ verify_scanner (const char *scanner_id, char **version) return 1; } g_free (get.id); - if (scanner_iterator_type (&scanner) == SCANNER_TYPE_OSP - || scanner_iterator_type (&scanner) == SCANNER_TYPE_OPENVAS + if (scanner_iterator_type (&scanner) == SCANNER_TYPE_OPENVAS || scanner_iterator_type (&scanner) == SCANNER_TYPE_OSP_SENSOR) { int ret = osp_get_version_from_iterator (&scanner, NULL, version, NULL, @@ -40275,9 +40274,6 @@ manage_get_scanners (GSList *log_config, const db_conn_info_t *database) switch (scanner_type) { - case SCANNER_TYPE_OSP: - scanner_type_str = "OSP"; - break; case SCANNER_TYPE_OPENVAS: scanner_type_str = "OpenVAS"; break; From 44c83fec74e94652c6c10bd4768e73e78005d39a Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 17 Sep 2021 14:30:22 +0200 Subject: [PATCH 2/6] Removed the function "create_config_from_scanner (..)". Removed the function "create_config_from_scanner (..)" from the files manage_sql_configs.c and manage_configs.h. Removed the corresponding code (the creation from scanner) from gmp_configs.c. --- src/gmp_configs.c | 64 +------------------------- src/manage_configs.h | 4 -- src/manage_sql_configs.c | 97 ---------------------------------------- 3 files changed, 1 insertion(+), 164 deletions(-) diff --git a/src/gmp_configs.c b/src/gmp_configs.c index db1131746..1ebea047d 100644 --- a/src/gmp_configs.c +++ b/src/gmp_configs.c @@ -398,7 +398,7 @@ parse_config_entity (entity_t config, const char **config_id, char **name, void create_config_run (gmp_parser_t *gmp_parser, GError **error) { - entity_t entity, get_configs_response, config, name, copy, scanner; + entity_t entity, get_configs_response, config, name, copy; entity = (entity_t) create_config_data.context->first->data; @@ -527,68 +527,6 @@ create_config_run (gmp_parser_t *gmp_parser, GError **error) return; } - /* Check for creation from scanner. */ - - scanner = entity_child (entity, "scanner"); - if (scanner && strlen (entity_text (scanner))) - { - char *uuid; - - uuid = NULL; - - switch (create_config_from_scanner - (entity_text (scanner), - text_or_null (entity_child (entity, "name")), - text_or_null (entity_child (entity, "comment")), - text_or_null (entity_child (entity, "usage_type")), - &uuid)) - { - case 0: - SENDF_TO_CLIENT_OR_FAIL (XML_OK_CREATED_ID - ("create_config"), uuid); - log_event ("config", "Scan config", uuid, "created"); - break; - case 1: - SENDF_TO_CLIENT_OR_FAIL - (XML_ERROR_SYNTAX ("create_config", - "Failed to find scanner")); - break; - case 2: - SENDF_TO_CLIENT_OR_FAIL - (XML_ERROR_SYNTAX ("create_config", - "Scanner not of type OSP")); - break; - case 3: - SENDF_TO_CLIENT_OR_FAIL - (XML_ERROR_SYNTAX ("create_config", - "Config name exists already")); - break; - case 4: - SENDF_TO_CLIENT_OR_FAIL - (XML_ERROR_SYNTAX ("create_config", - "Failed to get params from scanner" - " - the scanner may be offline or not" - " configured correctly")); - break; - case 99: - SEND_TO_CLIENT_OR_FAIL - (XML_ERROR_SYNTAX ("create_config", - "Permission denied")); - log_event_fail ("config", "Scan config", NULL, "created"); - break; - case -1: - default: - SEND_TO_CLIENT_OR_FAIL - (XML_INTERNAL_ERROR ("create_config")); - log_event_fail ("config", "Scan config", NULL, "created"); - break; - } - g_free (uuid); - - create_config_reset (); - return; - } - /* Try copy from an existing config. */ copy = entity_child (entity, "copy"); diff --git a/src/manage_configs.h b/src/manage_configs.h index 23f3a70f6..44798d4a4 100644 --- a/src/manage_configs.h +++ b/src/manage_configs.h @@ -47,10 +47,6 @@ int create_config (const char*, const char*, int, const char*, int, const array_t*, const array_t*, const char*, const char*, config_t*, char**); -int -create_config_from_scanner (const char*, const char *, const char *, - const char *, char **); - int copy_config (const char*, const char*, const char *, const char *, config_t*); diff --git a/src/manage_sql_configs.c b/src/manage_sql_configs.c index c1d5d1469..be142ebfe 100644 --- a/src/manage_sql_configs.c +++ b/src/manage_sql_configs.c @@ -2754,98 +2754,6 @@ configs_extra_where (const char *usage_type) return extra_where; } -/** - * @brief Create a config from an OSP scanner. - * - * @param[in] scanner_id UUID of scanner to create config from. - * @param[in] name Name for config. - * @param[in] comment Comment for config. - * @param[in] usage_type The usage type ("scan" or "policy") - * @param[out] uuid Config UUID, on success. - * - * @return 0 success, 1 couldn't find scanner, 2 scanner not of OSP type, - * 3 config name exists already, 4 couldn't get params from scanner, - * 99 permission denied, -1 error. - */ -int -create_config_from_scanner (const char *scanner_id, const char *name, - const char *comment, const char *usage_type, - char **uuid) -{ - scanner_t scanner; - config_t config; - GSList *params, *element; - char *quoted_name, *quoted_comment; - const char *actual_usage_type; - - assert (current_credentials.uuid); - assert (scanner_id); - sql_begin_immediate (); - - if (acl_user_may ("create_config") == 0) - { - sql_rollback (); - return 99; - } - if (find_scanner_with_permission (scanner_id, &scanner, "get_scanners")) - { - sql_rollback (); - return -1; - } - if (scanner == 0) - { - sql_rollback (); - return 1; - } - if (scanner_type (scanner) != SCANNER_TYPE_OSP) - { - sql_rollback (); - return 2; - } - if (resource_with_name_exists (name, "config", 0)) - { - sql_rollback (); - return 3; - } - - params = get_scanner_params (scanner); - if (!params) - { - sql_rollback (); - return 4; - } - quoted_name = sql_quote (name ?: ""); - quoted_comment = sql_quote (comment ?: ""); - if (usage_type && strcasecmp (usage_type, "policy") == 0) - actual_usage_type = "policy"; - else - actual_usage_type = "scan"; - - /* Create new OSP config. */ - sql ("INSERT INTO configs (uuid, name, owner, nvt_selector, comment," - " type, scanner, creation_time, modification_time, usage_type)" - " VALUES (make_uuid (), '%s'," - " (SELECT id FROM users WHERE users.uuid = '%s')," - " '', '%s', 1, %llu, m_now (), m_now (), '%s');", - quoted_name, current_credentials.uuid, quoted_comment, scanner, - actual_usage_type); - g_free (quoted_name); - g_free (quoted_comment); - config = sql_last_insert_id (); - *uuid = config_uuid (config); - - element = params; - while (element) - { - insert_osp_parameter (element->data, config); - osp_param_free (element->data); - element = element->next; - } - g_slist_free (params); - sql_commit (); - return 0; -} - /** * @brief Return the UUID of a config. * @@ -2978,8 +2886,6 @@ create_task_check_config_scanner (config_t config, scanner_t scanner) return 1; if (ctype == 0 && stype == SCANNER_TYPE_OSP_SENSOR) return 1; - if (ctype == 1 && stype == SCANNER_TYPE_OSP) - return 1; return 0; } @@ -3042,9 +2948,6 @@ modify_task_check_config_scanner (task_t task, const char *config_id, : (config ? 1 : 0); ctype = config_type (config); - /* OSP Scanner with OSP config. */ - if (stype == SCANNER_TYPE_OSP && ctype == 1) - return 0; /* OpenVAS Scanner with OpenVAS config. */ if ((stype == SCANNER_TYPE_OPENVAS) From bac0bd1577863bf8681a569b6d662adf5d6d3c50 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 17 Sep 2021 15:16:41 +0200 Subject: [PATCH 3/6] Removed the sync config functionality for osp scanners from gvmd. Removed the function sync_config (..) and all corresponding code from gmp.c, manage.h, manage_configs.h and manage_sql_configs.h. Amongst others also the functions handle_sync_config (..) and its corresponding code was removed. --- src/gmp.c | 114 ------------------ src/manage.h | 2 +- src/manage_configs.h | 3 - src/manage_sql_configs.c | 241 --------------------------------------- 4 files changed, 1 insertion(+), 359 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index 399b655c1..1132e8f32 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -3161,27 +3161,6 @@ stop_task_data_reset (stop_task_data_t *data) memset (data, 0, sizeof (stop_task_data_t)); } -/** - * @brief Command data for the sync_config command. - */ -typedef struct -{ - char *config_id; ///< Config UUID. -} sync_config_data_t; - -/** - * @brief Reset command data. - * - * @param[in] data Command data. - */ -static void -sync_config_data_reset (sync_config_data_t *data) -{ - g_free (data->config_id); - - memset (data, 0, sizeof (sync_config_data_t)); -} - /** * @brief Command data for the test_alert command. */ @@ -3382,7 +3361,6 @@ typedef union resume_task_data_t resume_task; ///< resume_task start_task_data_t start_task; ///< start_task stop_task_data_t stop_task; ///< stop_task - sync_config_data_t sync_config; ///< sync_config test_alert_data_t test_alert; ///< test_alert verify_report_format_data_t verify_report_format; ///< verify_report_format verify_scanner_data_t verify_scanner; ///< verify_scanner @@ -3952,12 +3930,6 @@ static start_task_data_t *start_task_data static stop_task_data_t *stop_task_data = (stop_task_data_t*) &(command_data.stop_task); -/** - * @brief Parser callback data for SYNC_CONFIG. - */ -static sync_config_data_t *sync_config_data - = (sync_config_data_t*) &(command_data.sync_config); - /** * @brief Parser callback data for TEST_ALERT. */ @@ -4534,7 +4506,6 @@ typedef enum CLIENT_RUN_WIZARD_PARAMS_PARAM_VALUE, CLIENT_START_TASK, CLIENT_STOP_TASK, - CLIENT_SYNC_CONFIG, CLIENT_TEST_ALERT, CLIENT_VERIFY_REPORT_FORMAT, CLIENT_VERIFY_SCANNER, @@ -5924,12 +5895,6 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context, &stop_task_data->task_id); set_client_state (CLIENT_STOP_TASK); } - else if (strcasecmp ("SYNC_CONFIG", element_name) == 0) - { - append_attribute (attribute_names, attribute_values, "config_id", - &sync_config_data->config_id); - set_client_state (CLIENT_SYNC_CONFIG); - } else if (strcasecmp ("TEST_ALERT", element_name) == 0) { append_attribute (attribute_names, attribute_values, @@ -17721,81 +17686,6 @@ handle_get_vulns (gmp_parser_t *gmp_parser, GError **error) set_client_state (CLIENT_AUTHENTIC); } -/** - * @brief Handle end of SYNC_CONFIG element. - * - * @param[in] gmp_parser GMP parser. - * @param[in] error Error parameter. - */ -static void -handle_sync_config (gmp_parser_t *gmp_parser, GError **error) -{ - assert (current_credentials.username); - if (!sync_config_data->config_id) - { - SEND_TO_CLIENT_OR_FAIL - (XML_ERROR_SYNTAX ("sync_config", - "SYNC_CONFIG requires a config_id attribute")); - sync_config_data_reset (sync_config_data); - set_client_state (CLIENT_AUTHENTIC); - return; - } - switch (sync_config (sync_config_data->config_id)) - { - case 0: - log_event ("config", "config", sync_config_data->config_id, - "synchronized"); - SEND_TO_CLIENT_OR_FAIL (XML_OK ("sync_config")); - break; - case 1: - if (send_find_error_to_client - ("sync_config", "config", sync_config_data->config_id, gmp_parser)) - { - error_send_to_client (error); - return; - } - log_event_fail ("config", "Config", sync_config_data->config_id, - "synchronized"); - break; - case 2: - SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX - ("sync_config", "Config not of type OSP")); - log_event_fail ("config", "Config", sync_config_data->config_id, - "synchronized"); - break; - case 3: - SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX - ("sync_config", "Config has no scanner")); - log_event_fail ("config", "Config", sync_config_data->config_id, - "synchronized"); - break; - case 4: - SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX - ("sync_config", - "Couldn't get parameters from scanner")); - log_event_fail ("config", "Config", sync_config_data->config_id, - "synchronized"); - break; - case 99: - SEND_TO_CLIENT_OR_FAIL - (XML_ERROR_SYNTAX ("sync_config", "Permission denied")); - log_event_fail ("config", "Config", sync_config_data->config_id, - "synchronized"); - break; - case -1: - SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("sync_config")); - log_event_fail ("config", "Config", sync_config_data->config_id, - "synchronized"); - break; - default: - abort (); - break; - } - - sync_config_data_reset (sync_config_data); - set_client_state (CLIENT_AUTHENTIC); -} - /** * @brief Handle end of CREATE_SCANNER element. * @@ -25544,10 +25434,6 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context, set_client_state (CLIENT_AUTHENTIC); break; - case CLIENT_SYNC_CONFIG: - handle_sync_config (gmp_parser, error); - break; - case CLIENT_VERIFY_REPORT_FORMAT: if (verify_report_format_data->report_format_id) { diff --git a/src/manage.h b/src/manage.h index 58edaaf26..9feea1faa 100644 --- a/src/manage.h +++ b/src/manage.h @@ -303,7 +303,7 @@ typedef enum typedef enum scanner_type { SCANNER_TYPE_NONE = 0, - SCANNER_TYPE_OSP = 1, + /* 1 was removed (SCANNER_TYPE_OSP). */ SCANNER_TYPE_OPENVAS = 2, SCANNER_TYPE_CVE = 3, /* 4 was removed (SCANNER_TYPE_GMP). */ diff --git a/src/manage_configs.h b/src/manage_configs.h index 44798d4a4..e3af570ac 100644 --- a/src/manage_configs.h +++ b/src/manage_configs.h @@ -53,9 +53,6 @@ copy_config (const char*, const char*, const char *, const char *, config_t*); int delete_config (const char*, int); -int -sync_config (const char *); - gboolean find_config_with_permission (const char*, config_t*, const char *); diff --git a/src/manage_sql_configs.c b/src/manage_sql_configs.c index be142ebfe..2a4359b88 100644 --- a/src/manage_sql_configs.c +++ b/src/manage_sql_configs.c @@ -2661,77 +2661,6 @@ create_config_no_acl (const char *config_id, const char *proposed_name, config, name); } -/** - * @brief Get list of OSP Scanner parameters. - * - * @param[in] scanner Scanner. - * - * @return List of scanner parameters, NULL if error. - */ -static GSList * -get_scanner_params (scanner_t scanner) -{ - GSList *list = NULL; - osp_connection_t *connection; - - connection = osp_scanner_connect (scanner); - if (!connection) - return NULL; - - osp_get_scanner_details (connection, NULL, &list); - osp_connection_close (connection); - return list; -} - -/** - * @brief Insert an OSP parameter into a config if not already present. - * - * @param[in] param OSP parameter to insert. - * @param[in] config Config to insert parameter into. - * - * @return 1 if added, 0 otherwise. - */ -static int -insert_osp_parameter (osp_param_t *param, config_t config) -{ - char *param_id, *param_name, *param_type, *param_def, *param_value = NULL; - int ret = 0; - - if (!param) - return ret; - param_id = sql_quote (osp_param_id (param)); - param_name = sql_quote (osp_param_name (param)); - param_type = sql_quote (osp_param_type_str (param)); - if (!strcmp (param_type, "selection")) - { - char **strarray = g_strsplit (osp_param_default (param), "|", 2); - - param_value = sql_quote (strarray[0] ?: ""); - param_def = sql_quote (strarray[1] ?: param_value); - g_strfreev (strarray); - } - else - param_def = sql_quote (osp_param_default (param)); - if (sql_int ("SELECT count(*) FROM config_preferences" - " WHERE config = %llu AND name = '%s' AND type = '%s'" - " AND default_value = '%s';", - config, param_id, param_type, param_def) == 0) - { - sql ("INSERT INTO config_preferences (config, name, type, value," - " default_value, hr_name)" - " VALUES (%llu, '%s', '%s', '%s', '%s', '%s')", - config , param_id, param_type, param_value ?: param_def, - param_def, param_name); - ret = 1; - } - g_free (param_name); - g_free (param_id); - g_free (param_type); - g_free (param_def); - g_free (param_value); - return ret; -} - /** * @brief Generate an extra WHERE clause for selecting configs * @@ -2787,33 +2716,6 @@ config_type (config_t config) return type; } -/** - * @brief Return the scanner associated with a config, if any. - * - * @param[in] config Config. - * - * @return Scanner ID if found, 0 otherwise. - */ -static scanner_t -config_scanner (config_t config) -{ - scanner_t scanner; - - switch (sql_int64 (&scanner, - "SELECT scanner FROM configs WHERE id = %llu;", config)) - { - case 0: - break; - case 1: /* Too few rows in result of query. */ - return 0; - case -1: - return 0; - default: /* Programming error. */ - assert (0); - } - return scanner; -} - /** * @brief Return whether a config is predefined. * @@ -3211,149 +3113,6 @@ delete_config (const char *config_id, int ultimate) return 0; } -/** - * @brief Update a config with a list of parameters. - * - * @param[in] config Config ID. - * @param[in] config_id Config UUID. - * @param[in] params List of new config parameters. - * - */ -static void -update_config_params (config_t config, const char *config_id, GSList *params) -{ - GSList *element; - iterator_t iterator; - - /* Remove parameters not used anymore. */ - init_iterator (&iterator, - "SELECT id, name, type, default_value, hr_name" - " FROM config_preferences" - " WHERE config = %llu;", config); - while (next (&iterator)) - { - int found = 0; - - element = params; - while (element) - { - const char *name, *type, *def; - - name = osp_param_id (element->data); - type = osp_param_type_str (element->data); - def = osp_param_default (element->data); - if (!strcmp (name, iterator_string (&iterator, 1)) - && !strcmp (type, iterator_string (&iterator, 2))) - { - const char *iter_def = iterator_string (&iterator, 3); - - if (!strcmp (type, "selection") - && !strcmp (strchr (def, '|') + 1, iter_def)) - found = 1; - else if (strcmp (type, "selection") && !strcmp (def, iter_def)) - found = 1; - if (found) - break; - } - element = element->next; - } - if (!found) - { - g_message ("Removing config preference %s from config '%s'", - iterator_string (&iterator, 1), config_id); - sql ("DELETE FROM config_preferences WHERE id = %llu;", - iterator_int64 (&iterator, 0)); - } - else if (strcmp (osp_param_name (element->data), - iterator_string (&iterator, 4))) - { - // Update hr_name (= OSP name) - gchar *quoted_name; - quoted_name = sql_quote (osp_param_name (element->data)); - g_message ("Updating name of config preference %s in config '%s'", - iterator_string (&iterator, 1), config_id); - sql ("UPDATE config_preferences SET hr_name='%s' WHERE id = %llu;", - quoted_name, - iterator_int64 (&iterator, 0)); - g_free (quoted_name); - } - } - cleanup_iterator (&iterator); - /* Insert new parameters. */ - element = params; - while (element) - { - if (insert_osp_parameter (element->data, config)) - g_message ("Adding config preference %s to config '%s'", - osp_param_id (element->data), config_id); - element = element->next; - } -} - -/** - * @brief Synchronize a config. - * - * @param[in] config_id UUID of config. - * - * @return 0 success, 1 failed to find config, 2 config not of OSP type, - * 3 config has no scanner, 4 couldn't get params from scanner, - * 99 permission denied, -1 error. - */ -int -sync_config (const char *config_id) -{ - config_t config = 0; - GSList *params; - scanner_t scanner; - - assert (config_id); - assert (current_credentials.uuid); - - sql_begin_immediate (); - - if (acl_user_may ("modify_config") == 0) - { - sql_rollback (); - return 99; - } - if (find_config_with_permission (config_id, &config, "modify_config")) - { - sql_rollback (); - return -1; - } - if (config == 0) - { - sql_rollback (); - return 1; - } - if (config_type (config) != SCANNER_TYPE_OSP) - { - sql_rollback (); - return 2; - } - scanner = config_scanner (config); - if (!scanner) - { - sql_rollback (); - return 3; - } - params = get_scanner_params (scanner); - if (!params) - { - sql_rollback (); - return 4; - } - update_config_params (config, config_id, params); - - sql_commit (); - while (params) - { - osp_param_free (params->data); - params = g_slist_remove_link (params, params); - } - return 0; -} - /** * @brief Count the number of scan configs. * From bdfd400659fb1861043ad8fbc0daed9ef14ede0c Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Mon, 20 Sep 2021 09:12:25 +0200 Subject: [PATCH 4/6] Removed the launch of an OSP task from gvmd. Removed the function launch_osp_task (..) with its included function get_osp_task_options (..) and its included function task_scanner_options (..) from the file manage.c. --- src/manage.c | 212 +-------------------------------------------------- 1 file changed, 3 insertions(+), 209 deletions(-) diff --git a/src/manage.c b/src/manage.c index 328c71285..fc0deda22 100644 --- a/src/manage.c +++ b/src/manage.c @@ -781,7 +781,8 @@ scanner_type_valid (scanner_type_t scanner_type) { if (scanner_type > SCANNER_TYPE_NONE && scanner_type < SCANNER_TYPE_MAX - && scanner_type != 4) + && scanner_type != 4 + && scanner_type != 1) return 1; return 0; } @@ -1579,115 +1580,6 @@ set_task_interrupted (task_t task, const gchar *message) /* OSP tasks. */ -/** - * @brief Give a task's OSP scan options in a hash table. - * - * @param[in] task The task. - * @param[in] target The target. - * - * @return Hash table with options names and their values. - */ -static GHashTable * -task_scanner_options (task_t task, target_t target) -{ - GHashTable *table; - config_t config; - iterator_t prefs; - char *allow_simultaneous_ips; - - config = task_config (task); - init_config_preference_iterator (&prefs, config); - table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - while (next (&prefs)) - { - char *name, *value = NULL; - const char *type; - - name = g_strdup (config_preference_iterator_name (&prefs)); - type = config_preference_iterator_type (&prefs); - - if (g_str_has_prefix (type, "credential_")) - { - credential_t credential = 0; - iterator_t iter; - const char *uuid = config_preference_iterator_value (&prefs); - - if (!strcmp (config_preference_iterator_value (&prefs), "0")) - credential = target_ssh_credential (target); - else if (find_resource ("credential", uuid, &credential)) - { - g_warning ("Error getting credential for osp parameter %s", name); - g_free (name); - continue; - } - if (credential == 0) - { - g_warning ("No credential for osp parameter %s", name); - g_free (name); - continue; - } - - init_credential_iterator_one (&iter, credential); - if (!next (&iter)) - { - g_warning ("No credential for credential_id %llu", credential); - g_free (name); - continue; - } - if (!strcmp (type, "credential_up") - && !strcmp (credential_iterator_type (&iter), "up")) - value = g_strdup_printf ("%s:%s", credential_iterator_login (&iter), - credential_iterator_password (&iter)); - else if (!strcmp (type, "credential_up")) - { - g_warning ("OSP Parameter %s requires credentials of type" - " username+password", name); - g_free (name); - continue; - } - else - abort (); - cleanup_iterator (&iter); - if (!value) - { - g_warning ("No adequate %s for parameter %s", type, name); - g_free (name); - continue; - } - } - else if (!strcmp (name, "definitions_file")) - { - char *fname; - - if (!config_preference_iterator_value (&prefs)) - continue; - fname = g_strdup_printf ("%s/%s", GVM_SCAP_DATA_DIR "/", - config_preference_iterator_value (&prefs)); - value = gvm_file_as_base64 (fname); - if (!value) - continue; - } - else - value = g_strdup (config_preference_iterator_value (&prefs)); - g_hash_table_insert (table, name, value); - } - cleanup_iterator (&prefs); - - // Target options sent as scanner preferences - allow_simultaneous_ips = target_allow_simultaneous_ips (target); - if (allow_simultaneous_ips) - { - g_hash_table_replace (table, - g_strdup ("allow_simultaneous_ips"), - g_strdup (strcmp (allow_simultaneous_ips, "0") - ? "yes" - : "no")); - } - free (allow_simultaneous_ips); - - return table; -} - /** * @brief Delete an OSP scan. * @@ -1979,96 +1871,6 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id) return rc; } -/** - * @brief Get an OSP Task's scan options. - * - * @param[in] task The task. - * @param[in] target The target. - * - * @return OSP Task options, NULL if failure. - */ -static GHashTable * -get_osp_task_options (task_t task, target_t target) -{ - char *ssh_port; - const char *user, *pass; - iterator_t iter; - credential_t cred; - GHashTable *options = task_scanner_options (task, target); - - if (!options) - return NULL; - - cred = target_ssh_credential (target); - if (cred) - { - ssh_port = target_ssh_port (target); - g_hash_table_insert (options, g_strdup ("port"), ssh_port); - - init_credential_iterator_one (&iter, cred); - if (!next (&iter)) - { - g_warning ("%s: LSC Credential not found.", __func__); - g_hash_table_destroy (options); - cleanup_iterator (&iter); - return NULL; - } - if (credential_iterator_private_key (&iter)) - { - g_warning ("%s: LSC Credential not a user/pass pair.", __func__); - g_hash_table_destroy (options); - cleanup_iterator (&iter); - return NULL; - } - user = credential_iterator_login (&iter); - pass = credential_iterator_password (&iter); - g_hash_table_insert (options, g_strdup ("username"), g_strdup (user)); - g_hash_table_insert (options, g_strdup ("password"), g_strdup (pass)); - cleanup_iterator (&iter); - } - return options; -} - -/** - * @brief Launch an OSP task. - * - * @param[in] task The task. - * @param[in] target The target. - * @param[out] scan_id The new scan uuid. - * @param[out] error Error return. - * - * @return 0 success, -1 if scanner is down. - */ -static int -launch_osp_task (task_t task, target_t target, const char *scan_id, - char **error) -{ - osp_connection_t *connection; - char *target_str, *ports_str; - GHashTable *options; - int ret; - - options = get_osp_task_options (task, target); - if (!options) - return -1; - connection = osp_scanner_connect (task_scanner (task)); - if (!connection) - { - g_hash_table_destroy (options); - return -1; - } - target_str = target_hosts (target); - ports_str = target_port_range (target); - ret = osp_start_scan (connection, target_str, ports_str, options, scan_id, - error); - - g_hash_table_destroy (options); - osp_connection_close (connection); - g_free (target_str); - g_free (ports_str); - return ret; -} - /** * @brief Get the SSH credential of a target as an osp_credential_t * @@ -2865,15 +2667,7 @@ fork_osp_scan_handler (task_t task, target_t target, int from, reinit_manage_process (); manage_session_init (current_credentials.uuid); - if (scanner_type (task_scanner (task)) == SCANNER_TYPE_OPENVAS - || scanner_type (task_scanner (task) == SCANNER_TYPE_OSP_SENSOR)) - { - rc = launch_osp_openvas_task (task, target, report_id, from, &error); - } - else - { - rc = launch_osp_task (task, target, report_id, &error); - } + rc = launch_osp_openvas_task (task, target, report_id, from, &error); if (rc) { From 1e89dff779b7839a46ab036bbf25d176b856ffa6 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Wed, 22 Sep 2021 11:03:31 +0200 Subject: [PATCH 5/6] Small change to manage_sql.c regarding the removal of OSP scanners Adjusted the function make_osp_result (..) according to the removal of OSP scanners. --- src/manage_sql.c | 50 ++++++++---------------------------------------- 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index 6971d0f57..f0dc6a7d2 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -314,9 +314,6 @@ setting_value_int (const char *, int *); static int setting_auto_cache_rebuild_int (); -static double -setting_default_severity_dbl (); - static int setting_dynamic_severity_int (); @@ -18990,10 +18987,6 @@ make_osp_result (task_t task, const char *host, const char *hostname, nvt_revision = sql_string ("SELECT iso_time (modification_time)" " FROM nvts WHERE oid='%s'", quoted_nvt); - else if (g_str_has_prefix (nvt, "CVE-")) - nvt_revision = sql_string ("SELECT iso_time (modification_time)" - " FROM scap.cves WHERE uuid='%s'", - quoted_nvt); } if (!severity || !strcmp (severity, "")) @@ -19002,30 +18995,14 @@ make_osp_result (task_t task, const char *host, const char *hostname, result_severity = g_strdup (G_STRINGIFY (SEVERITY_ERROR)); else { - if (nvt && g_str_has_prefix (nvt, "CVE-")) - { - result_severity = cve_cvss_base (nvt); - if (result_severity == NULL || strcmp (result_severity, "") == 0) - { - g_free (result_severity); - result_severity - = g_strdup_printf ("%0.1f", - setting_default_severity_dbl ()); - g_debug ("%s: OSP CVE result without severity for '%s'", - __func__, nvt); - } - } - else - { - /* - result_severity - = g_strdup_printf ("%0.1f", - setting_default_severity_dbl ()); - */ - g_warning ("%s: Non-CVE OSP result without severity for test %s", - __func__, nvt ? nvt : "(unknown)"); - return 0; - } + /* + result_severity + = g_strdup_printf ("%0.1f", + setting_default_severity_dbl ()); + */ + g_warning ("%s: Result without severity for test %s", + __func__, nvt ? nvt : "(unknown)"); + return 0; } } else @@ -49374,17 +49351,6 @@ setting_filter (const char *resource) current_credentials.uuid); } -/** - * @brief Return the Default Severity user setting as a double. - * - * @return The user's Default Severity. - */ -static double -setting_default_severity_dbl () -{ - return current_credentials.default_severity; -} - /** * @brief Return the Dynamic Severity user setting as an int. * From 7a13c9a4e6fe2985ed24444e8e46843617329e80 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Wed, 22 Sep 2021 13:14:40 +0200 Subject: [PATCH 6/6] Small adjustment of the documentation and CHANGELOG entry. Small adjustment of the documentation regarding the removal of OSP scanners and CHANGELOG entry. --- CHANGELOG.md | 1 + doc/gvmd.8 | 2 +- doc/gvmd.8.xml | 2 +- doc/gvmd.html | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0861a4af..02a792d1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Removed OVAL definitions from GMP and gvmd documentation [1551](https://github.com/greenbone/gvmd/pull/1551) - Removed the Business Process Map from gvmd [1627](https://github.com/greenbone/gvmd/pull/1627) - Removed ifaces element from users [#1676](https://github.com/greenbone/gvmd/pull/1676) +- Removed OSP scanners from gvmd [#1689](https://github.com/greenbone/gvmd/pull/1689) [#1691](https://github.com/greenbone/gvmd/pull/1691) [Unreleased]: https://github.com/greenbone/gvmd/compare/gvmd-21.04...master diff --git a/doc/gvmd.8 b/doc/gvmd.8 index 8d4889284..c919d8147 100644 --- a/doc/gvmd.8 +++ b/doc/gvmd.8 @@ -179,7 +179,7 @@ Scanner port for --create-scanner and --modify-scanner. \fB--scanner-type=\fISCANNER-TYPE\fB\f1 Scanner type for --create-scanner and --modify-scanner. -Either 'OpenVAS', 'OSP', 'GMP', 'OSP-Sensor' or a number as used in GMP. +Either 'OpenVAS', 'GMP', 'OSP-Sensor' or a number as used in GMP. .TP \fB--scanner-connection-retry=\fINUMBER\fB\f1 Number of auto retries if scanner connection is lost in a running task. diff --git a/doc/gvmd.8.xml b/doc/gvmd.8.xml index 0a8697934..4b905338e 100644 --- a/doc/gvmd.8.xml +++ b/doc/gvmd.8.xml @@ -401,7 +401,7 @@ along with this program. If not, see .

--scanner-type=SCANNER-TYPE

Scanner type for --create-scanner and --modify-scanner.

-

Either 'OpenVAS', 'OSP', 'GMP', 'OSP-Sensor' or a number +

Either 'OpenVAS', 'GMP', 'OSP-Sensor' or a number as used in GMP.

diff --git a/doc/gvmd.html b/doc/gvmd.html index 981f1e0d8..653158df8 100644 --- a/doc/gvmd.html +++ b/doc/gvmd.html @@ -362,7 +362,7 @@

Options

--scanner-type=SCANNER-TYPE

Scanner type for --create-scanner and --modify-scanner.

-

Either 'OpenVAS', 'OSP', 'GMP', 'OSP-Sensor' or a number +

Either 'OpenVAS', 'GMP', 'OSP-Sensor' or a number as used in GMP.