From 52f3c3a19b72148507ea46b516d040f152ec61e1 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Thu, 30 Sep 2021 11:10:48 +0200 Subject: [PATCH 1/8] Removed the field config_type from gvmd. Since the field config_type was only used for OSP scanners the field and the corresponding code is removed from the gvmd sources. Further the field hr_name was rebuilt for NVT preferences. --- src/gmp.c | 71 ++---------------- src/gmp_configs.c | 2 +- src/manage_configs.c | 1 - src/manage_configs.h | 5 +- src/manage_preferences.c | 3 +- src/manage_preferences.h | 3 +- src/manage_sql_configs.c | 158 ++++++++++++--------------------------- src/manage_sql_configs.h | 2 +- 8 files changed, 59 insertions(+), 186 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index 0691dc0c6..9c7be2fc9 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -8508,6 +8508,7 @@ buffer_config_preference_xml (GString *buffer, iterator_t *prefs, "" "%s" "%s" + "%s" "%s" "%s", oid ? oid : "", @@ -11546,7 +11547,7 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error) SEND_GET_START ("config"); while (1) { - int config_nvts_growing, config_families_growing, config_type; + int config_nvts_growing, config_families_growing; const char *selector, *usage_type; config_t config; @@ -11565,7 +11566,6 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error) selector = config_iterator_nvt_selector (&configs); config = get_iterator_resource (&configs); config_nvts_growing = config_iterator_nvts_growing (&configs); - config_type = config_iterator_type (&configs); usage_type = config_iterator_usage_type (&configs); config_families_growing = config_iterator_families_growing (&configs); @@ -11578,19 +11578,17 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error) "" "%i%i" "" - "%i" + "0" "%s" "%i", config_iterator_family_count (&configs), config_families_growing, config_iterator_nvt_count (&configs), config_nvts_growing, - config_type, usage_type, config_iterator_predefined (&configs)); - if (config_type == 0 && (get_configs_data->families - || get_configs_data->get.details)) + if (get_configs_data->families || get_configs_data->get.details) { iterator_t families; int max_nvt_count = 0, known_nvt_count = 0; @@ -11656,62 +11654,7 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error) known_nvt_count); } - if (config_type > 0) - { - iterator_t prefs; - scanner_t scanner; - char *s_uuid, *s_name; - - assert (config); - scanner = config_iterator_scanner (&configs); - - if (config_iterator_scanner_trash (&configs)) - { - s_uuid = trash_scanner_uuid (scanner); - s_name = trash_scanner_name (scanner); - } - else - { - s_uuid = scanner_uuid (scanner); - s_name = scanner_name (scanner); - } - - SENDF_TO_CLIENT_OR_FAIL ("" - "%s" - "%d" - "", - s_uuid, s_name, - config_iterator_scanner_trash (&configs)); - - g_free (s_uuid); - g_free (s_name); - SEND_TO_CLIENT_OR_FAIL (""); - - init_config_preference_iterator (&prefs, config); - while (next (&prefs)) - { - const char *name, *value, *type, *def; - - name = config_preference_iterator_name (&prefs); - value = config_preference_iterator_value (&prefs); - def = config_preference_iterator_default (&prefs); - type = config_preference_iterator_type (&prefs); - SENDF_TO_CLIENT_OR_FAIL - ("" - "" - "" - "%s" - "osp_%s" - "%s" - "%s" - "", - name, type, value ?: "", def); - } - cleanup_iterator (&prefs); - SEND_TO_CLIENT_OR_FAIL (""); - } - else if (get_configs_data->preferences - || get_configs_data->get.details) + if (get_configs_data->preferences || get_configs_data->get.details) { iterator_t prefs; @@ -11758,7 +11701,7 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error) SEND_TO_CLIENT_OR_FAIL (""); } - if (config_type == 0 && get_configs_data->get.details) + if (get_configs_data->get.details) { iterator_t selectors; @@ -17181,7 +17124,6 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error) "%s" "" "%s" - "%i" "%i" "%s" "" @@ -17211,7 +17153,6 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error) task_iterator_usage_type (&tasks), config_uuid ?: "", config_name_escaped ?: "", - config_type (task_config (index)), task_config_in_trash (index), config_available ? "" : "", task_target_uuid ?: "", diff --git a/src/gmp_configs.c b/src/gmp_configs.c index fb34e7387..d9f8b30cd 100644 --- a/src/gmp_configs.c +++ b/src/gmp_configs.c @@ -363,6 +363,7 @@ parse_config_entity (entity_t config, const char **config_id, char **name, preference_nvt_oid, import_alts, text_or_null (entity_child (preference, "default")), + NULL, 0 /* do not free strings */); } @@ -443,7 +444,6 @@ create_config_run (gmp_parser_t *gmp_parser, GError **error) all_selector, import_nvt_selectors, import_preferences, - type, usage_type_text, &new_config, &created_name)) diff --git a/src/manage_configs.c b/src/manage_configs.c index 2d4ccaf63..baf9bc53b 100644 --- a/src/manage_configs.c +++ b/src/manage_configs.c @@ -238,7 +238,6 @@ create_config_from_file (const gchar *path) all_selector, nvt_selectors, preferences, - type, usage_type, &new_config, &created_name)) diff --git a/src/manage_configs.h b/src/manage_configs.h index 2f976096c..b34aa2097 100644 --- a/src/manage_configs.h +++ b/src/manage_configs.h @@ -45,7 +45,7 @@ typedef struct int create_config (const char*, const char*, int, const char*, int, const array_t*, - const array_t*, const char*, const char*, config_t*, char**); + const array_t*, const char*, config_t*, char**); int copy_config (const char*, const char*, const char *, const char *, config_t*); @@ -59,9 +59,6 @@ find_config_with_permission (const char*, config_t*, const char *); char * config_uuid (config_t); -int -config_type (config_t); - char * config_nvt_timeout (config_t, const char *); diff --git a/src/manage_preferences.c b/src/manage_preferences.c index 8fe8f0deb..9d37831d5 100644 --- a/src/manage_preferences.c +++ b/src/manage_preferences.c @@ -43,7 +43,7 @@ gpointer preference_new (char *id, char *name, char *type, char *value, char *nvt_name, char *nvt_oid, array_t *alts, char* default_value, - int free_strings) + char *hr_name, int free_strings) { preference_t *preference; @@ -56,6 +56,7 @@ preference_new (char *id, char *name, char *type, char *value, char *nvt_name, preference->nvt_oid = nvt_oid; preference->alts = alts; preference->default_value = default_value; + preference->hr_name = hr_name; preference->free_strings = free_strings; return preference; diff --git a/src/manage_preferences.h b/src/manage_preferences.h index 15b412ebb..a8fb24633 100644 --- a/src/manage_preferences.h +++ b/src/manage_preferences.h @@ -39,12 +39,13 @@ typedef struct char *nvt_oid; ///< OID of NVT preference affects. array_t *alts; ///< Array of gchar's. Alternate values for radio type. char *default_value; ///< Default value of preference. + char *hr_name; ///< Extended, more human-readable name. int free_strings; ///< Whether string fields are freed by preference_free. } preference_t; gpointer preference_new (char *, char *, char *, char *, char *, - char *, array_t *, char*, int); + char *, array_t *, char*, char *, int); void preference_free (preference_t *); diff --git a/src/manage_sql_configs.c b/src/manage_sql_configs.c index 140d1e022..85c44de8b 100644 --- a/src/manage_sql_configs.c +++ b/src/manage_sql_configs.c @@ -970,10 +970,6 @@ manage_set_config_families (config_t config, return 1; } - if (config_type (config) > 0) - { - return 0; - } constraining = config_families_growing (config); if (constraining + grow_families == 1) @@ -2184,11 +2180,11 @@ get_nvt_preference_by_id (const char *nvt_oid, const char *value) { preference_t *new_pref; - char *full_name, *id, *name, *type, *nvt_name, *default_value; + char *full_name, *id, *name, *type, *nvt_name, *default_value, *hr_name; array_t *alts; gchar *quoted_oid, *quoted_id; - full_name = name = type = nvt_name = default_value = NULL; + full_name = name = type = nvt_name = default_value = hr_name = NULL; /* Check parameters */ if (nvt_oid == NULL) @@ -2279,6 +2275,7 @@ get_nvt_preference_by_id (const char *nvt_oid, strdup (nvt_oid), alts, default_value, + hr_name, 1); return new_pref; @@ -2289,14 +2286,12 @@ get_nvt_preference_by_id (const char *nvt_oid, * * @param[in] config Config. * @param[in] preferences Preferences. - * @param[in] config_type Config type. * * @return 0 success, -1 error, -4 input error. */ static int config_insert_preferences (config_t config, - const array_t* preferences /* preference_t. */, - const char* config_type) + const array_t* preferences /* preference_t. */) { int index = 0; const preference_t *preference; @@ -2318,8 +2313,7 @@ config_insert_preferences (config_t config, /* Special Timeout preference. */ - if (preference->nvt_oid == NULL - && (config_type == NULL || strcmp (config_type, "0") == 0)) + if (preference->nvt_oid == NULL) return -4; quoted_nvt_oid = sql_quote (preference->nvt_oid); @@ -2342,8 +2336,7 @@ config_insert_preferences (config_t config, /* Presume NVT or OSP preference. */ - if (preference->nvt_oid == NULL - && (config_type == NULL || strcmp (config_type, "0") == 0)) + if (preference->nvt_oid == NULL) return -4; value = g_string_new (preference->value); @@ -2366,32 +2359,18 @@ config_insert_preferences (config_t config, ? sql_quote (preference->default_value) : NULL; - if (config_type == NULL || strcmp (config_type, "0") == 0) - { - /* NVT preference */ - /* OID:PrefID:PrefType:PrefName value */ - sql ("INSERT INTO config_preferences" - " (config, type, name, value)" - " VALUES (%llu, 'PLUGINS_PREFS', '%s:%s:%s:%s', '%s');", - config, - quoted_nvt_oid, - quoted_preference_id, - quoted_type, - quoted_preference_name, - quoted_value); - } - else - { - /* OSP preference */ - sql ("INSERT into config_preferences" - " (config, type, name, value, default_value)" - " VALUES (%llu, '%s', '%s', '%s', '%s');", - config, - quoted_type, - quoted_preference_name, - quoted_value, - quoted_default); - } + /* NVT preference */ + /* OID:PrefID:PrefType:PrefName value */ + sql ("INSERT INTO config_preferences" + " (config, type, name, value)" + " VALUES (%llu, 'PLUGINS_PREFS', '%s:%s:%s:%s', '%s');", + config, + quoted_nvt_oid, + quoted_preference_id, + quoted_type, + quoted_preference_name, + quoted_value); + g_free (quoted_nvt_oid); g_free (quoted_preference_name); g_free (quoted_type); @@ -2433,7 +2412,6 @@ config_insert_preferences (config_t config, * @param[in] all_selector Whether to use "all" selector instead of selectors. * @param[in] selectors NVT selectors. * @param[in] preferences Preferences. - * @param[in] config_type Config type. * @param[in] usage_type The usage type ("scan" or "policy") * @param[in] allow_errors Whether certain errors are allowed. * @param[in] predefined Whether config is predefined. @@ -2451,7 +2429,7 @@ create_config_internal (int check_access, const char *config_id, int all_selector, const array_t *selectors /* nvt_selector_t. */, const array_t *preferences /* preference_t. */, - const char *config_type, const char *usage_type, + const char *usage_type, int allow_errors, int predefined, config_t *config, char **name) { @@ -2492,7 +2470,7 @@ create_config_internal (int check_access, const char *config_id, candidate_name = g_strdup (proposed_name); quoted_candidate_name = sql_quote (candidate_name); - quoted_type = config_type ? sql_quote (config_type) : g_strdup ("0"); + quoted_type = g_strdup ("0"); if (usage_type && strcasecmp (usage_type, "policy") == 0) actual_usage_type = "policy"; else @@ -2550,7 +2528,7 @@ create_config_internal (int check_access, const char *config_id, *config = sql_last_insert_id (); - if (selector_uuid && (config_type == NULL || strcmp (config_type, "0") == 0)) + if (selector_uuid) { if ((ret = insert_nvt_selectors (selector_uuid, selectors, allow_errors))) { @@ -2558,12 +2536,12 @@ create_config_internal (int check_access, const char *config_id, free (selector_uuid); return ret; } + free (selector_uuid); } - free (selector_uuid); /* Insert the preferences into the config_preferences table. */ - if ((ret = config_insert_preferences (*config, preferences, config_type))) + if ((ret = config_insert_preferences (*config, preferences))) { sql_rollback (); return ret; @@ -2591,7 +2569,6 @@ create_config_internal (int check_access, const char *config_id, * @param[in] all_selector Whether to use "all" selector instead of selectors. * @param[in] selectors NVT selectors. * @param[in] preferences Preferences. - * @param[in] config_type Config type. * @param[in] usage_type The usage type ("scan" or "policy") * @param[out] config On success the config. * @param[out] name On success the name of the config. @@ -2605,12 +2582,12 @@ create_config (const char *config_id, const char *proposed_name, int make_name_unique, const char *comment, int all_selector, const array_t *selectors /* nvt_selector_t. */, const array_t *preferences /* preference_t. */, - const char *config_type, const char *usage_type, + const char *usage_type, config_t *config, char **name) { return create_config_internal (1, config_id, proposed_name, make_name_unique, comment, all_selector, selectors, preferences, - config_type, usage_type, 1, + usage_type, 1, 0, /* Predefined. */ config, name); } @@ -2628,7 +2605,6 @@ create_config (const char *config_id, const char *proposed_name, * @param[in] all_selector Whether to use "all" selector instead of selectors. * @param[in] selectors NVT selectors. * @param[in] preferences Preferences. - * @param[in] config_type Config type. * @param[in] usage_type The usage type ("scan" or "policy") * @param[out] config On success the config. * @param[out] name On success the name of the config. @@ -2643,12 +2619,12 @@ create_config_no_acl (const char *config_id, const char *proposed_name, int all_selector, const array_t *selectors /* nvt_selector_t. */, const array_t *preferences /* preference_t. */, - const char *config_type, const char *usage_type, + const char *usage_type, config_t *config, char **name) { return create_config_internal (0, config_id, proposed_name, make_name_unique, comment, all_selector, selectors, preferences, - config_type, usage_type, 0, + usage_type, 0, 1, /* Predefined. */ config, name); } @@ -2688,26 +2664,6 @@ config_uuid (config_t config) return sql_string ("SELECT uuid FROM configs WHERE id = %llu;", config); } -/** - * @brief Return the type of a config. - * - * @param[in] config Config. - * - * @return Config type, -1 if not found. - */ -int -config_type (config_t config) -{ - int type; - char *str; - str = sql_string ("SELECT type FROM configs WHERE id = %llu;", config); - if (!str) - return -1; - type = atoi (str); - g_free (str); - return type; -} - /** * @brief Return whether a config is predefined. * @@ -2768,17 +2724,16 @@ config_nvt_timeout (config_t config, const char *oid) int create_task_check_config_scanner (config_t config, scanner_t scanner) { - int ctype, stype; + int stype; assert (config); assert (scanner); - ctype = config_type (config); stype = scanner_type (scanner); - if (ctype == 0 && stype == SCANNER_TYPE_OPENVAS) + if (stype == SCANNER_TYPE_OPENVAS) return 1; - if (ctype == 0 && stype == SCANNER_TYPE_OSP_SENSOR) + if (stype == SCANNER_TYPE_OSP_SENSOR) return 1; return 0; @@ -2800,7 +2755,7 @@ modify_task_check_config_scanner (task_t task, const char *config_id, { config_t config = 0; scanner_t scanner = 0; - int ctype, stype; + int stype; if (config_id == NULL) config_id = "0"; @@ -2841,19 +2796,16 @@ modify_task_check_config_scanner (task_t task, const char *config_id, * leave the config alone. */ : (config ? 1 : 0); - ctype = config_type (config); - /* OpenVAS Scanner with OpenVAS config. */ - if ((stype == SCANNER_TYPE_OPENVAS) - && ctype == 0) + if (stype == SCANNER_TYPE_OPENVAS) return 0; /* OSP Sensor with OpenVAS config. */ - if (stype == SCANNER_TYPE_OSP_SENSOR && ctype == 0) + if (stype == SCANNER_TYPE_OSP_SENSOR) return 0; /* Default Scanner with OpenVAS Config. */ - if (scanner == 0 && ctype == 0) + if (scanner == 0) return 0; return 1; @@ -2875,7 +2827,7 @@ int copy_config (const char* name, const char* comment, const char *config_id, const char* usage_type, config_t* new_config) { - int ret, type; + int ret; char *config_selector; gchar *quoted_config_selector; config_t new, old; @@ -2904,17 +2856,6 @@ copy_config (const char* name, const char* comment, const char *config_id, " FROM config_preferences" " WHERE config = %llu;", new, old); - type = config_type (new); - if (type > 0) - { - /* Don't create nvt_selector etc,. for non-standard configs - * (eg. OSP config.) Only config preferences are copied. - */ - sql_commit (); - if (new_config) *new_config = new; - return 0; - } - sql ("UPDATE configs SET nvt_selector = make_uuid () WHERE id = %llu;", new); @@ -3683,23 +3624,16 @@ modify_config_preference (config_t config, const char* nvt, quoted_value = sql_quote ((gchar*) value); g_free (value); - if (config_type (config) > 0) - sql ("UPDATE config_preferences SET value = '%s'" - " WHERE config = %llu AND name = '%s';", - quoted_value, config, quoted_name); - else - { - /* nvt prefs are not present on first modification. */ - sql ("DELETE FROM config_preferences" - " WHERE config = %llu AND type %s AND name = '%s'", - config, - nvt ? "= 'PLUGINS_PREFS'" : "= 'SERVER_PREFS'", - quoted_name); - sql ("INSERT INTO config_preferences" - " (config, type, name, value) VALUES (%llu, %s, '%s', '%s');", - config, nvt ? "'PLUGINS_PREFS'" : "'SERVER_PREFS'", quoted_name, - quoted_value); - } + /* nvt prefs are not present on first modification. */ + sql ("DELETE FROM config_preferences" + " WHERE config = %llu AND type %s AND name = '%s'", + config, + nvt ? "= 'PLUGINS_PREFS'" : "= 'SERVER_PREFS'", + quoted_name); + sql ("INSERT INTO config_preferences" + " (config, type, name, value) VALUES (%llu, %s, '%s', '%s');", + config, nvt ? "'PLUGINS_PREFS'" : "'SERVER_PREFS'", quoted_name, + quoted_value); return 0; } @@ -4559,7 +4493,7 @@ update_config (config_t config, const gchar *type, const gchar *name, /* Replace the preferences. */ sql ("DELETE FROM config_preferences WHERE config = %llu;", config); - if (config_insert_preferences (config, preferences, type)) + if (config_insert_preferences (config, preferences)) { g_warning ("%s: Error in feed config preference", __func__); sql_rollback (); diff --git a/src/manage_sql_configs.h b/src/manage_sql_configs.h index 27236d706..9ae45816c 100644 --- a/src/manage_sql_configs.h +++ b/src/manage_sql_configs.h @@ -73,7 +73,7 @@ configs_extra_where (const char *); int create_config_no_acl (const char *, const char *, int, const char *, int, const array_t *, const array_t *, const char *, - const char *, config_t *, char **); + config_t *, char **); gboolean find_config_no_acl (const char *, config_t *); From 9d95703aa510ebc74cf19df635bd231ccedd8f1f Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 1 Oct 2021 12:07:39 +0200 Subject: [PATCH 2/8] Deleted the code for the field scanner of table configs from gvmd. Since the field "scanner" of the database table "configs" was only used in connection with OSP scanners and OSP scanners are no longer supported the corresponding code is removed from the gvmd-sources. --- src/gmp.c | 29 +------------ src/gmp_configs.c | 19 +-------- src/manage.h | 5 +-- src/manage_configs.h | 5 +-- src/manage_migrators.c | 34 +++++++++++++++ src/manage_pg.c | 2 - src/manage_sql.c | 92 +++------------------------------------- src/manage_sql_configs.c | 67 +++-------------------------- src/manage_sql_configs.h | 2 - 9 files changed, 51 insertions(+), 204 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index 9c7be2fc9..084970891 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -2264,7 +2264,6 @@ typedef struct int family_selection_growing; ///< Whether families in selection grow. char *family_selection_growing_text; ///< Text version of above. char *name; ///< New name for config. - char *scanner_id; ///< New scanner UUID for config. array_t *nvt_selection; ///< OID array. New NVT set for config. char *nvt_selection_family; ///< Family of NVT selection. char *nvt_selection_nvt_oid; ///< OID during NVT_selection/NVT. @@ -15294,31 +15293,7 @@ handle_get_scanners (gmp_parser_t *gmp_parser, GError **error) count++; if (get_scanners_data->get.details) { - iterator_t configs, tasks; - - SEND_TO_CLIENT_OR_FAIL (""); - init_scanner_config_iterator (&configs, - get_iterator_resource (&scanners)); - while (next (&configs)) - { - if (scanner_task_iterator_readable (&configs) == 0) - /* Only show configs the user may see. */ - continue; - - SENDF_TO_CLIENT_OR_FAIL - ("" - "%s", - scanner_config_iterator_uuid (&configs), - scanner_config_iterator_name (&configs)); - - if (scanner_config_iterator_readable (&configs)) - SEND_TO_CLIENT_OR_FAIL (""); - else - SEND_TO_CLIENT_OR_FAIL ("" - ""); - } - cleanup_iterator (&configs); - SEND_TO_CLIENT_OR_FAIL (""); + iterator_t tasks; SEND_TO_CLIENT_OR_FAIL (""); init_scanner_task_iterator (&tasks, @@ -21841,7 +21816,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context, goto create_task_fail; } - if (!create_task_check_config_scanner (config, scanner)) + if (!create_task_check_config_scanner (scanner)) { SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX ("create_task", diff --git a/src/gmp_configs.c b/src/gmp_configs.c index d9f8b30cd..64aa75a81 100644 --- a/src/gmp_configs.c +++ b/src/gmp_configs.c @@ -701,7 +701,6 @@ modify_config_element_start (gmp_parser_t *gmp_parser, const gchar *name, * @param[in] config The config to modify. * @param[in] name The name to set or NULL to keep old value. * @param[in] comment The comment to set or NULL to keep old value. - * @param[in] scanner_id The scanner ID to set or NULL to keep old value. * @param[in] gmp_parser GMP parser. * @param[out] error GError output. * @@ -711,11 +710,10 @@ static int modify_config_handle_basic_fields (config_t config, const char *name, const char *comment, - const char *scanner_id, gmp_parser_t *gmp_parser, GError **error) { - switch (manage_set_config (config, name, comment, scanner_id)) + switch (manage_set_config (config, name, comment)) { case 0: return 0; @@ -723,20 +721,6 @@ modify_config_handle_basic_fields (config_t config, SENDF_TO_CLIENT_OR_FAIL_WITH_RETURN (-1, XML_ERROR_SYNTAX ("modify_config", "Name must be unique")); return -1; - case 2: - if (send_find_error_to_client ("modify_config", - "scanner", - scanner_id, - gmp_parser)) - { - error_send_to_client (error); - return -1; - } - return -1; - case 3: - SENDF_TO_CLIENT_OR_FAIL_WITH_RETURN - (-1, XML_ERROR_SYNTAX ("modify_config", "Config is in use")); - return -1; case -1: SENDF_TO_CLIENT_OR_FAIL_WITH_RETURN (-1, XML_INTERNAL_ERROR ("modify_config")); @@ -1072,7 +1056,6 @@ modify_config_run (gmp_parser_t *gmp_parser, GError **error) (config, text_or_null (entity_child (entity, "name")), text_or_null (entity_child (entity, "comment")), - text_or_null (entity_child (entity, "scanner")), gmp_parser, error)) { diff --git a/src/manage.h b/src/manage.h index 9feea1faa..600447a70 100644 --- a/src/manage.h +++ b/src/manage.h @@ -1754,11 +1754,8 @@ target_login_port (target_t, const char*); * * These are here because they need definitions that are still in manage.h. */ -scanner_t -config_iterator_scanner (iterator_t*); - int -create_task_check_config_scanner (config_t, scanner_t); +create_task_check_config_scanner (scanner_t); int modify_task_check_config_scanner (task_t, const char *, const char *); diff --git a/src/manage_configs.h b/src/manage_configs.h index b34aa2097..5af770ea1 100644 --- a/src/manage_configs.h +++ b/src/manage_configs.h @@ -89,9 +89,6 @@ config_iterator_type (iterator_t*); int config_iterator_families_growing (iterator_t*); -int -config_iterator_scanner_trash (iterator_t*); - const char* config_iterator_usage_type (iterator_t*); @@ -153,7 +150,7 @@ const char* config_preference_iterator_default (iterator_t *); int -manage_set_config (config_t, const char*, const char *, const char *); +manage_set_config (config_t, const char*, const char *); int manage_set_config_nvts (config_t, const char*, GPtrArray*); diff --git a/src/manage_migrators.c b/src/manage_migrators.c index f219a952c..ecb505115 100644 --- a/src/manage_migrators.c +++ b/src/manage_migrators.c @@ -2851,6 +2851,40 @@ migrate_247_to_248 () return 0; } +/** + * @brief Migrate the database from version 248 to version 249. + * + * @return 0 success, -1 error. + */ +int +migrate_248_to_249 () +{ + sql_begin_immediate (); + + /* Ensure that the database is currently version 248. */ + + if (manage_db_version () != 248) + { + sql_rollback (); + return -1; + } + + /* Update the database. */ + + /* Remove config data for OSP-Scanners */ + sql ("DELETE FROM config_preferences WHERE config IN" + " (SELECT id FROM configs WHERE usage_type = 'scan' AND type = 1);"); + sql (" DELETE FROM configs WHERE usage_type = 'scan' AND type = 1;"); + + /* Set the database version to 247. */ + + set_db_version (249); + + sql_commit (); + + return 0; +} + #undef UPDATE_DASHBOARD_SETTINGS diff --git a/src/manage_pg.c b/src/manage_pg.c index a7b662fd2..59d390dfa 100644 --- a/src/manage_pg.c +++ b/src/manage_pg.c @@ -2239,7 +2239,6 @@ create_tables () " families_growing integer," " nvts_growing integer," " type integer," - " scanner integer REFERENCES scanners (id) ON DELETE RESTRICT," " predefined integer," " creation_time integer," " modification_time integer," @@ -2257,7 +2256,6 @@ create_tables () " families_growing integer," " nvts_growing integer," " type integer," - " scanner integer," /* REFERENCES scanners (id) */ " predefined integer," " creation_time integer," " modification_time integer," diff --git a/src/manage_sql.c b/src/manage_sql.c index 5365446e7..ac5226ca7 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -39142,12 +39142,7 @@ delete_scanner (const char *scanner_id, int ultimate) if (sql_int ("SELECT count(*) FROM tasks" " WHERE scanner = %llu" " AND scanner_location = " G_STRINGIFY (LOCATION_TRASH) ";", - scanner) - || sql_int ("SELECT count(*) FROM configs_trash" - " WHERE scanner = %llu" - " AND scanner_location" - " = " G_STRINGIFY (LOCATION_TRASH) ";", - scanner)) + scanner)) { sql_rollback (); return 1; @@ -39169,10 +39164,7 @@ delete_scanner (const char *scanner_id, int ultimate) " WHERE scanner = %llu" " AND scanner_location = " G_STRINGIFY (LOCATION_TABLE) " AND hidden = 0;", - scanner) - || sql_int ("SELECT count(*) FROM configs" - " WHERE scanner = %llu;", - scanner)) + scanner)) { sql_rollback (); return 1; @@ -39189,14 +39181,6 @@ delete_scanner (const char *scanner_id, int ultimate) trash_scanner = sql_last_insert_id (); - /* Update the location of the scanner in any trashcan configs & tasks. */ - sql ("UPDATE configs_trash" - " SET scanner = %llu," - " scanner_location = " G_STRINGIFY (LOCATION_TRASH) - " WHERE scanner = %llu;", - trash_scanner, - scanner); - sql ("UPDATE tasks" " SET scanner = %llu," " scanner_location = " G_STRINGIFY (LOCATION_TRASH) @@ -39455,59 +39439,6 @@ scanner_iterator_key_priv (iterator_t* iterator) */ DEF_ACCESS (scanner_iterator_credential_type, GET_ITERATOR_COLUMN_COUNT + 10); -/** - * @brief Initialise a scanner config iterator. - * - * @param[in] iterator Iterator. - * @param[in] scanner Scanner. - */ -void -init_scanner_config_iterator (iterator_t* iterator, scanner_t scanner) -{ - gchar *available, *with_clause; - get_data_t get; - array_t *permissions; - - assert (scanner); - - get.trash = 0; - permissions = make_array (); - array_add (permissions, g_strdup ("get_configs")); - available = acl_where_owned ("config", &get, 1, "any", 0, permissions, 0, - &with_clause); - array_free (permissions); - - init_iterator (iterator, - "%s" - " SELECT id, uuid, name, %s FROM configs" - " WHERE scanner = %llu" - " ORDER BY name ASC;", - with_clause ? with_clause : "", - available, - scanner); - - g_free (with_clause); - g_free (available); -} - -/** - * @brief Get the UUID from a scanner config iterator. - * - * @param[in] iterator Iterator. - * - * @return UUID, or NULL if iteration is complete. Freed by cleanup_iterator. - */ -DEF_ACCESS (scanner_config_iterator_uuid, 1); - -/** - * @brief Get the name from a scanner config iterator. - * - * @param[in] iterator Iterator. - * - * @return Name, or NULL if iteration is complete. Freed by cleanup_iterator. - */ -DEF_ACCESS (scanner_config_iterator_name, 2); - /** * @brief Get the read permission status from a GET iterator. * @@ -39600,9 +39531,7 @@ int scanner_in_use (scanner_t scanner) { return !!(sql_int ("SELECT count(*) FROM tasks WHERE scanner = %llu" - " AND hidden = 0;", scanner) - || sql_int ("SELECT count(*) FROM configs WHERE scanner = %llu", - scanner)); + " AND hidden = 0;", scanner)); } /** @@ -39618,10 +39547,6 @@ trash_scanner_in_use (scanner_t scanner) return !!(sql_int ("SELECT count(*) FROM tasks" " WHERE scanner = %llu" " AND scanner_location = " G_STRINGIFY (LOCATION_TRASH), - scanner) - || sql_int ("SELECT count(*) FROM configs_trash" - " WHERE scanner = %llu" - " AND scanner_location = " G_STRINGIFY (LOCATION_TRASH), scanner)); } @@ -45972,10 +45897,10 @@ manage_restore (const char *id) sql ("INSERT INTO configs" " (uuid, owner, name, nvt_selector, comment, family_count," - " nvt_count, families_growing, nvts_growing, type, scanner," + " nvt_count, families_growing, nvts_growing, type," " predefined, creation_time, modification_time, usage_type)" " SELECT uuid, owner, name, nvt_selector, comment, family_count," - " nvt_count, families_growing, nvts_growing, type, scanner," + " nvt_count, families_growing, nvts_growing, type," " predefined, creation_time, modification_time, usage_type" " FROM configs_trash WHERE id = %llu;", resource); @@ -46574,13 +46499,6 @@ manage_restore (const char *id) /* Update the scanner in any trashcan configs and tasks. */ scanner = sql_last_insert_id (); - sql ("UPDATE configs_trash" - " SET scanner = %llu," - " scanner_location = " G_STRINGIFY (LOCATION_TABLE) - " WHERE scanner = %llu" - " AND scanner_location = " G_STRINGIFY (LOCATION_TRASH), - scanner, resource); - sql ("UPDATE tasks" " SET scanner = %llu," " scanner_location = " G_STRINGIFY (LOCATION_TABLE) diff --git a/src/manage_sql_configs.c b/src/manage_sql_configs.c index 85c44de8b..e4461a282 100644 --- a/src/manage_sql_configs.c +++ b/src/manage_sql_configs.c @@ -2716,17 +2716,15 @@ config_nvt_timeout (config_t config, const char *oid) /** * @brief Check scanner and config values match for a task. * - * @param[in] config Scan Config. * @param[in] scanner Scanner. * * @return 1 if config and scanner types match, 0 otherwise. */ int -create_task_check_config_scanner (config_t config, scanner_t scanner) +create_task_check_config_scanner (scanner_t scanner) { int stype; - assert (config); assert (scanner); stype = scanner_type (scanner); @@ -2840,7 +2838,7 @@ copy_config (const char* name, const char* comment, const char *config_id, ret = copy_resource_lock ("config", name, comment, config_id, " family_count, nvt_count, families_growing," - " nvts_growing, type, scanner, usage_type", + " nvts_growing, type, usage_type", 1, &new, &old); if (ret) { @@ -3005,11 +3003,11 @@ delete_config (const char *config_id, int ultimate) sql ("INSERT INTO configs_trash" " (uuid, owner, name, nvt_selector, comment, family_count," - " nvt_count, families_growing, nvts_growing, type, scanner," + " nvt_count, families_growing, nvts_growing, type," " predefined, creation_time, modification_time," " scanner_location, usage_type)" " SELECT uuid, owner, name, nvt_selector, comment, family_count," - " nvt_count, families_growing, nvts_growing, type, scanner," + " nvt_count, families_growing, nvts_growing, type," " predefined, creation_time, modification_time," " " G_STRINGIFY (LOCATION_TABLE) ", usage_type" " FROM configs WHERE id = %llu;", @@ -3240,38 +3238,6 @@ config_iterator_type (iterator_t* iterator) return ret; } -/** - * @brief Get the scanner from a config iterator. - * - * @param[in] iterator Iterator. - * - * @return Scanner. - */ -scanner_t -config_iterator_scanner (iterator_t* iterator) -{ - scanner_t ret = 0; - if (iterator->done) return 0; - ret = iterator_int64 (iterator, GET_ITERATOR_COLUMN_COUNT + 6); - return ret; -} - -/** - * @brief Get whether scanner is in trash from a config iterator. - * - * @param[in] iterator Iterator. - * - * @return Whether Scanner is in trash. - */ -int -config_iterator_scanner_trash (iterator_t* iterator) -{ - int ret = 0; - if (iterator->done) return 0; - ret = iterator_int (iterator, GET_ITERATOR_COLUMN_COUNT + 7); - return ret; -} - /** * @brief Get the usage type from a config iterator. * @@ -3707,19 +3673,16 @@ manage_set_config_preference (config_t config, const char* nvt, } /** - * @brief Set the name, comment and scanner of a config. + * @brief Set the name and comment of a config. * * @param[in] config Config to modify. * @param[in] name New name, not updated if NULL. * @param[in] comment New comment, not updated if NULL. - * @param[in] scanner_id UUID of new scanner, not updated if NULL. * - * @return 0 success, 1 config with new name exists already, 2 scanner doesn't - * exist, 3 modification not allowed while config is in use, -1 error. + * @return 0 success, 1 config with new name exists already. */ int -manage_set_config (config_t config, const char *name, const char *comment, - const char *scanner_id) +manage_set_config (config_t config, const char *name, const char *comment) { assert (current_credentials.uuid); @@ -3743,22 +3706,6 @@ manage_set_config (config_t config, const char *name, const char *comment, " WHERE id = %llu;", quoted_comment, config); g_free (quoted_comment); } - if (scanner_id) - { - if (config_in_use (config)) - { - return 3; - } - scanner_t scanner = 0; - - if (find_scanner_with_permission (scanner_id, &scanner, "get_scanners") - || scanner == 0) - { - return 2; - } - sql ("UPDATE configs SET scanner = %llu, modification_time = m_now ()" - " WHERE id = %llu;", scanner, config); - } return 0; } diff --git a/src/manage_sql_configs.h b/src/manage_sql_configs.h index 9ae45816c..2d3115987 100644 --- a/src/manage_sql_configs.h +++ b/src/manage_sql_configs.h @@ -41,7 +41,6 @@ { "families_growing", "families_trend", KEYWORD_TYPE_INTEGER}, \ { "nvts_growing", "nvts_trend", KEYWORD_TYPE_INTEGER }, \ { "type", NULL, KEYWORD_TYPE_INTEGER }, \ - { "scanner", NULL, KEYWORD_TYPE_INTEGER }, \ { "0", NULL, KEYWORD_TYPE_INTEGER }, \ { "usage_type", NULL, KEYWORD_TYPE_STRING }, \ { "predefined", NULL, KEYWORD_TYPE_INTEGER }, \ @@ -60,7 +59,6 @@ { "families_growing", "families_trend", KEYWORD_TYPE_INTEGER}, \ { "nvts_growing", "nvts_trend", KEYWORD_TYPE_INTEGER }, \ { "type", NULL, KEYWORD_TYPE_INTEGER }, \ - { "scanner", NULL, KEYWORD_TYPE_INTEGER }, \ { "scanner_location", NULL, KEYWORD_TYPE_INTEGER }, \ { "usage_type", NULL, KEYWORD_TYPE_STRING }, \ { "predefined", NULL, KEYWORD_TYPE_INTEGER }, \ From 60b46112f7072ee9ad1fd3b03e90bdfa53d0eaac Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 1 Oct 2021 11:58:05 +0200 Subject: [PATCH 3/8] Added documentation for hr_name in a function header. Added the documentation for the hr_name (human readable name) in the function header of function "preference_new (..)". --- src/manage_preferences.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/manage_preferences.c b/src/manage_preferences.c index 9d37831d5..018631dfb 100644 --- a/src/manage_preferences.c +++ b/src/manage_preferences.c @@ -36,6 +36,7 @@ * @param[in] nvt_oid OID of NVT of preference. * @param[in] alts Array of gchar's. Alternative values for type radio. * @param[in] default_value Default value of preference. + * @param[in] hr_name The hr_name of the nvt_preference. * @param[in] free_strings Whether string fields are freed by preference_free. * * @return Newly allocated preference. From 0523a7be2ab4fbe7c87e5df3895fe1f9b0442d03 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Mon, 4 Oct 2021 11:14:29 +0200 Subject: [PATCH 4/8] Deleted the code for the field type of table configs from gvmd. Since the field "type" of the database table "configs" was only used in connection with OSP scanners and OSP scanners are no longer supported the corresponding code is removed from the gvmd-sources. --- src/gmp_configs.c | 16 ++----- src/gmp_configs.h | 2 +- src/manage_configs.c | 10 ++-- src/manage_configs.h | 3 -- src/manage_pg.c | 2 - src/manage_sql.c | 4 +- src/manage_sql_configs.c | 101 ++++++++++++++------------------------- src/manage_sql_configs.h | 5 +- 8 files changed, 50 insertions(+), 93 deletions(-) diff --git a/src/gmp_configs.c b/src/gmp_configs.c index 64aa75a81..19413c70d 100644 --- a/src/gmp_configs.c +++ b/src/gmp_configs.c @@ -178,7 +178,6 @@ attr_or_null (entity_t entity, const gchar *name) * @param[out] config_id Address for config ID, or NULL. * @param[out] name Address for name. * @param[out] comment Address for comment. - * @param[out] type Address for type. * @param[out] usage_type Address for usage type. * @param[out] all_selector True if ALL_SELECTOR was present. * @param[out] import_nvt_selectors Address for selectors. @@ -188,14 +187,14 @@ attr_or_null (entity_t entity, const gchar *name) */ int parse_config_entity (entity_t config, const char **config_id, char **name, - char **comment, char **type, char **usage_type, + char **comment, char **usage_type, int *all_selector, array_t **import_nvt_selectors, array_t **import_preferences) { entity_t entity, preferences, nvt_selectors; - *name = *comment = *type = NULL; + *name = *comment = NULL; *all_selector = 0; if (config_id) @@ -209,10 +208,6 @@ parse_config_entity (entity_t config, const char **config_id, char **name, if (entity) *comment = entity_text (entity); - entity = entity_child (config, "type"); - if (entity) - *type = entity_text (entity); - if (usage_type) { entity = entity_child (config, "usage_type"); @@ -307,8 +302,7 @@ parse_config_entity (entity_t config, const char **config_id, char **name, preference_nvt_oid = attr_or_null (nvt, "oid"); - if ((*type == NULL || strcmp (*type, "0") == 0) - && preference_nvt_oid + if ( preference_nvt_oid && strcmp (preference_nvt_oid, "")) { /* Preference in an OpenVAS config: @@ -400,7 +394,7 @@ create_config_run (gmp_parser_t *gmp_parser, GError **error) { config_t new_config; const char *usage_type_text; - char *created_name, *comment, *type, *import_name; + char *created_name, *comment, *import_name; entity_t usage_type; array_t *import_nvt_selectors, *import_preferences; int all_selector; @@ -420,7 +414,7 @@ create_config_run (gmp_parser_t *gmp_parser, GError **error) /* Get the config data from the XML. */ - if (parse_config_entity (config, NULL, &import_name, &comment, &type, + if (parse_config_entity (config, NULL, &import_name, &comment, NULL, &all_selector, &import_nvt_selectors, &import_preferences)) { diff --git a/src/gmp_configs.h b/src/gmp_configs.h index 5fed069e0..ed667a642 100644 --- a/src/gmp_configs.h +++ b/src/gmp_configs.h @@ -40,7 +40,7 @@ void create_config_element_text (const gchar *, gsize); int -parse_config_entity (entity_t, const char **, char **, char **, char **, +parse_config_entity (entity_t, const char **, char **, char **, char **, int *, array_t **, array_t **); /* modify_config */ diff --git a/src/manage_configs.c b/src/manage_configs.c index baf9bc53b..6106c64c8 100644 --- a/src/manage_configs.c +++ b/src/manage_configs.c @@ -142,7 +142,7 @@ update_config_from_file (config_t config, const gchar *path) { entity_t entity; array_t *nvt_selectors, *preferences; - char *comment, *name, *type, *usage_type; + char *comment, *name, *usage_type; const char *config_id; int all_selector; @@ -155,7 +155,7 @@ update_config_from_file (config_t config, const gchar *path) /* Parse the data out of the entity. */ - switch (parse_config_entity (entity, &config_id, &name, &comment, &type, + switch (parse_config_entity (entity, &config_id, &name, &comment, &usage_type, &all_selector, &nvt_selectors, &preferences)) { @@ -174,7 +174,7 @@ update_config_from_file (config_t config, const gchar *path) /* Update the config. */ - update_config (config, type, name, comment, usage_type, all_selector, + update_config (config, name, comment, usage_type, all_selector, nvt_selectors, preferences); /* Cleanup. */ @@ -198,7 +198,7 @@ create_config_from_file (const gchar *path) { entity_t config; array_t *nvt_selectors, *preferences; - char *created_name, *comment, *name, *type, *usage_type; + char *created_name, *comment, *name, *usage_type; const char *config_id; config_t new_config; int all_selector; @@ -212,7 +212,7 @@ create_config_from_file (const gchar *path) /* Parse the data out of the entity. */ - switch (parse_config_entity (config, &config_id, &name, &comment, &type, + switch (parse_config_entity (config, &config_id, &name, &comment, &usage_type, &all_selector, &nvt_selectors, &preferences)) { diff --git a/src/manage_configs.h b/src/manage_configs.h index 5af770ea1..e97988ccc 100644 --- a/src/manage_configs.h +++ b/src/manage_configs.h @@ -83,9 +83,6 @@ config_iterator_family_count (iterator_t*); int config_iterator_nvts_growing (iterator_t*); -int -config_iterator_type (iterator_t*); - int config_iterator_families_growing (iterator_t*); diff --git a/src/manage_pg.c b/src/manage_pg.c index 59d390dfa..609e701aa 100644 --- a/src/manage_pg.c +++ b/src/manage_pg.c @@ -2238,7 +2238,6 @@ create_tables () " nvt_count integer," " families_growing integer," " nvts_growing integer," - " type integer," " predefined integer," " creation_time integer," " modification_time integer," @@ -2255,7 +2254,6 @@ create_tables () " nvt_count integer," " families_growing integer," " nvts_growing integer," - " type integer," " predefined integer," " creation_time integer," " modification_time integer," diff --git a/src/manage_sql.c b/src/manage_sql.c index ac5226ca7..e4134bf98 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -45897,10 +45897,10 @@ manage_restore (const char *id) sql ("INSERT INTO configs" " (uuid, owner, name, nvt_selector, comment, family_count," - " nvt_count, families_growing, nvts_growing, type," + " nvt_count, families_growing, nvts_growing," " predefined, creation_time, modification_time, usage_type)" " SELECT uuid, owner, name, nvt_selector, comment, family_count," - " nvt_count, families_growing, nvts_growing, type," + " nvt_count, families_growing, nvts_growing," " predefined, creation_time, modification_time, usage_type" " FROM configs_trash WHERE id = %llu;", resource); diff --git a/src/manage_sql_configs.c b/src/manage_sql_configs.c index e4461a282..876fb66e6 100644 --- a/src/manage_sql_configs.c +++ b/src/manage_sql_configs.c @@ -1646,7 +1646,7 @@ update_nvt_family (const char *oid, const char *old_family, iterator_t rows; ret = 0; - init_iterator (&rows, "SELECT id FROM configs WHERE type = 0;"); + init_iterator (&rows, "SELECT id FROM configs;"); while (next (&rows)) if (config_update_nvt_family (iterator_int64 (&rows, 0), oid, old_family, new_family)) @@ -2435,7 +2435,6 @@ create_config_internal (int check_access, const char *config_id, { int ret; gchar *quoted_comment, *candidate_name, *quoted_candidate_name; - gchar *quoted_type; const char *actual_usage_type; char *selector_uuid; unsigned int num = 1; @@ -2470,7 +2469,6 @@ create_config_internal (int check_access, const char *config_id, candidate_name = g_strdup (proposed_name); quoted_candidate_name = sql_quote (candidate_name); - quoted_type = g_strdup ("0"); if (usage_type && strcasecmp (usage_type, "policy") == 0) actual_usage_type = "policy"; else @@ -2490,7 +2488,7 @@ create_config_internal (int check_access, const char *config_id, { quoted_comment = sql_nquote (comment, strlen (comment)); sql ("INSERT INTO configs (uuid, name, owner, nvt_selector, comment," - " type, creation_time, modification_time, usage_type, predefined)" + " creation_time, modification_time, usage_type, predefined)" " VALUES (%s%s%s, '%s'," " (SELECT id FROM users WHERE users.uuid = '%s')," " '%s', '%s', '%s', m_now (), m_now (), '%s', %i);", @@ -2501,14 +2499,13 @@ create_config_internal (int check_access, const char *config_id, current_credentials.uuid, selector_uuid ? selector_uuid : MANAGE_NVT_SELECTOR_UUID_ALL, quoted_comment, - quoted_type, actual_usage_type, predefined); g_free (quoted_comment); } else sql ("INSERT INTO configs (uuid, name, owner, nvt_selector, comment," - " type, creation_time, modification_time, usage_type, predefined)" + " creation_time, modification_time, usage_type, predefined)" " VALUES (%s%s%s, '%s'," " (SELECT id FROM users WHERE users.uuid = '%s')," " '%s', '', '%s', m_now (), m_now (), '%s', %i);", @@ -2518,11 +2515,9 @@ create_config_internal (int check_access, const char *config_id, quoted_candidate_name, current_credentials.uuid, selector_uuid ? selector_uuid : MANAGE_NVT_SELECTOR_UUID_ALL, - quoted_type, actual_usage_type, predefined); g_free (quoted_candidate_name); - g_free (quoted_type); /* Insert the selectors into the nvt_selectors table. */ @@ -2838,7 +2833,7 @@ copy_config (const char* name, const char* comment, const char *config_id, ret = copy_resource_lock ("config", name, comment, config_id, " family_count, nvt_count, families_growing," - " nvts_growing, type, usage_type", + " nvts_growing, usage_type", 1, &new, &old); if (ret) { @@ -3003,11 +2998,11 @@ delete_config (const char *config_id, int ultimate) sql ("INSERT INTO configs_trash" " (uuid, owner, name, nvt_selector, comment, family_count," - " nvt_count, families_growing, nvts_growing, type," + " nvt_count, families_growing, nvts_growing," " predefined, creation_time, modification_time," " scanner_location, usage_type)" " SELECT uuid, owner, name, nvt_selector, comment, family_count," - " nvt_count, families_growing, nvts_growing, type," + " nvt_count, families_growing, nvts_growing," " predefined, creation_time, modification_time," " " G_STRINGIFY (LOCATION_TABLE) ", usage_type" " FROM configs WHERE id = %llu;", @@ -3222,22 +3217,6 @@ config_iterator_nvts_growing (iterator_t* iterator) return ret; } -/** - * @brief Get the type from a config iterator. - * - * @param[in] iterator Iterator. - * - * @return Config type. - */ -int -config_iterator_type (iterator_t* iterator) -{ - int ret; - if (iterator->done) return -1; - ret = iterator_int (iterator, GET_ITERATOR_COLUMN_COUNT + 5); - return ret; -} - /** * @brief Get the usage type from a config iterator. * @@ -4215,9 +4194,6 @@ update_config_cache (iterator_t *configs) gchar *quoted_selector, *quoted_name; int families_growing; - if (config_iterator_type (configs) > 0) - return; - quoted_name = sql_quote (get_iterator_name (configs)); selector = config_iterator_nvt_selector (configs); families_growing = nvt_selector_families_growing (selector); @@ -4357,7 +4333,6 @@ config_updated_in_feed (config_t config, const gchar *path) * @brief Update a config from an XML file. * * @param[in] config Existing config. - * @param[in] type New config type. * @param[in] name New name. * @param[in] comment New comment. * @param[in] usage_type New usage type. @@ -4366,13 +4341,13 @@ config_updated_in_feed (config_t config, const gchar *path) * @param[in] preferences New preferences. */ void -update_config (config_t config, const gchar *type, const gchar *name, +update_config (config_t config, const gchar *name, const gchar *comment, const gchar *usage_type, int all_selector, const array_t* selectors /* nvt_selector_t. */, const array_t* preferences /* preference_t. */) { - gchar *quoted_name, *quoted_comment, *quoted_type, *actual_usage_type; + gchar *quoted_name, *quoted_comment, *actual_usage_type; sql_begin_immediate (); @@ -4383,60 +4358,54 @@ update_config (config_t config, const gchar *type, const gchar *name, quoted_name = sql_quote (name); quoted_comment = sql_quote (comment ? comment : ""); - quoted_type = sql_quote (type); sql ("UPDATE configs" - " SET name = '%s', comment = '%s', type = '%s', usage_type = '%s'," + " SET name = '%s', comment = '%s', usage_type = '%s'," " predefined = 1, modification_time = m_now ()" " WHERE id = %llu;", quoted_name, quoted_comment, - quoted_type, actual_usage_type, config); g_free (quoted_name); g_free (quoted_comment); - g_free (quoted_type); /* Replace the NVT selectors. */ - if (type == NULL || strcmp (type, "0") == 0) - { - char *selector_uuid; - - if (all_selector) - selector_uuid = NULL; - else - { - selector_uuid = gvm_uuid_make (); - if (selector_uuid == NULL) - { - g_warning ("%s: failed to allocate UUID", __func__); - sql_rollback (); - return; - } - } - - sql ("DELETE FROM nvt_selectors" - " WHERE name != '" MANAGE_NVT_SELECTOR_UUID_ALL "'" - " AND name = (SELECT nvt_selector FROM configs" - " WHERE id = %llu);", - config); - - sql ("UPDATE configs SET nvt_selector = '%s' WHERE id = %llu;", - selector_uuid ? selector_uuid : MANAGE_NVT_SELECTOR_UUID_ALL, - config); + char *selector_uuid; - if (selector_uuid && insert_nvt_selectors (selector_uuid, selectors, 0)) + if (all_selector) + selector_uuid = NULL; + else + { + selector_uuid = gvm_uuid_make (); + if (selector_uuid == NULL) { - g_warning ("%s: Error in feed config NVT selector", __func__); - free (selector_uuid); + g_warning ("%s: failed to allocate UUID", __func__); sql_rollback (); return; } + } + + sql ("DELETE FROM nvt_selectors" + " WHERE name != '" MANAGE_NVT_SELECTOR_UUID_ALL "'" + " AND name = (SELECT nvt_selector FROM configs" + " WHERE id = %llu);", + config); + sql ("UPDATE configs SET nvt_selector = '%s' WHERE id = %llu;", + selector_uuid ? selector_uuid : MANAGE_NVT_SELECTOR_UUID_ALL, + config); + + if (selector_uuid && insert_nvt_selectors (selector_uuid, selectors, 0)) + { + g_warning ("%s: Error in feed config NVT selector", __func__); free (selector_uuid); + sql_rollback (); + return; } + free (selector_uuid); + /* Replace the preferences. */ sql ("DELETE FROM config_preferences WHERE config = %llu;", config); diff --git a/src/manage_sql_configs.h b/src/manage_sql_configs.h index 2d3115987..0a1f266ae 100644 --- a/src/manage_sql_configs.h +++ b/src/manage_sql_configs.h @@ -26,7 +26,7 @@ */ #define CONFIG_ITERATOR_FILTER_COLUMNS \ { GET_ITERATOR_FILTER_COLUMNS, "nvt_selector", "families_total", \ - "nvts_total", "families_trend", "nvts_trend", "type", "usage_type", \ + "nvts_total", "families_trend", "nvts_trend", "usage_type", \ "predefined", NULL } /** @@ -40,7 +40,6 @@ { "nvt_count", "nvts_total", KEYWORD_TYPE_INTEGER}, \ { "families_growing", "families_trend", KEYWORD_TYPE_INTEGER}, \ { "nvts_growing", "nvts_trend", KEYWORD_TYPE_INTEGER }, \ - { "type", NULL, KEYWORD_TYPE_INTEGER }, \ { "0", NULL, KEYWORD_TYPE_INTEGER }, \ { "usage_type", NULL, KEYWORD_TYPE_STRING }, \ { "predefined", NULL, KEYWORD_TYPE_INTEGER }, \ @@ -93,7 +92,7 @@ config_updated_in_feed (config_t, const gchar *); void update_config (config_t, const gchar *, const gchar *, const gchar *, - const gchar *, int, const array_t*, const array_t*); + int, const array_t*, const array_t*); void check_db_configs (); From 087031fd1b62f790def4a2e88be2586ea563135b Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Mon, 4 Oct 2021 14:43:41 +0200 Subject: [PATCH 5/8] Database adjustment for the removal of type, scanner from configs. Since the fields type and scanner of the database table configs were only used in connection with OSP scanners and OSP scanners are no longer supported, the corresponding code has been removed from the gvmd-sources. This is the corresponding database adjustment, where, amongs others, the fields type and scanner are dropped from the table configs. --- CMakeLists.txt | 2 +- src/manage_migrators.c | 13 +++++++++++-- src/manage_sql_configs.h | 1 - 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ccff68c1..47b62be9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ include (CPack) ## Variables -set (GVMD_DATABASE_VERSION 248) +set (GVMD_DATABASE_VERSION 249) set (GVMD_SCAP_DATABASE_VERSION 19) diff --git a/src/manage_migrators.c b/src/manage_migrators.c index ecb505115..5785c505b 100644 --- a/src/manage_migrators.c +++ b/src/manage_migrators.c @@ -2872,11 +2872,19 @@ migrate_248_to_249 () /* Update the database. */ /* Remove config data for OSP-Scanners */ + sql ("DELETE FROM config_preferences_trash WHERE config IN" + " (SELECT id FROM configs_trash WHERE usage_type = 'scan' AND type = 1);"); + sql ("DELETE FROM configs_trash WHERE usage_type = 'scan' AND type = 1;"); + sql ("ALTER TABLE configs_trash DROP COLUMN scanner;"); + sql ("ALTER TABLE configs_trash DROP COLUMN type;"); + sql ("DELETE FROM config_preferences WHERE config IN" " (SELECT id FROM configs WHERE usage_type = 'scan' AND type = 1);"); - sql (" DELETE FROM configs WHERE usage_type = 'scan' AND type = 1;"); + sql ("DELETE FROM configs WHERE usage_type = 'scan' AND type = 1;"); + sql ("ALTER TABLE configs DROP COLUMN scanner;"); + sql ("ALTER TABLE configs DROP COLUMN type;"); - /* Set the database version to 247. */ + /* Set the database version to 249. */ set_db_version (249); @@ -2940,6 +2948,7 @@ static migrator_t database_migrators[] = { {246, migrate_245_to_246}, {247, migrate_246_to_247}, {248, migrate_247_to_248}, + {249, migrate_248_to_249}, /* End marker. */ {-1, NULL}}; diff --git a/src/manage_sql_configs.h b/src/manage_sql_configs.h index 0a1f266ae..068d3f0f4 100644 --- a/src/manage_sql_configs.h +++ b/src/manage_sql_configs.h @@ -57,7 +57,6 @@ { "nvt_count", "nvts_total", KEYWORD_TYPE_INTEGER}, \ { "families_growing", "families_trend", KEYWORD_TYPE_INTEGER}, \ { "nvts_growing", "nvts_trend", KEYWORD_TYPE_INTEGER }, \ - { "type", NULL, KEYWORD_TYPE_INTEGER }, \ { "scanner_location", NULL, KEYWORD_TYPE_INTEGER }, \ { "usage_type", NULL, KEYWORD_TYPE_STRING }, \ { "predefined", NULL, KEYWORD_TYPE_INTEGER }, \ From 57a97e34946352e1c34a1f9ca9d764b5b8f55c35 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Tue, 5 Oct 2021 10:30:45 +0200 Subject: [PATCH 6/8] CHANGELOG entry for removal of scanner, type from configs. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c2a4cd54..46d7b992c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +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) +- Removed OSP scanners from gvmd [#1689](https://github.com/greenbone/gvmd/pull/1689) [#1691](https://github.com/greenbone/gvmd/pull/1691) [#1694](https://github.com/greenbone/gvmd/pull/1694) [Unreleased]: https://github.com/greenbone/gvmd/compare/gvmd-21.04...master From f6d66ca225eee85af17c21f3371d1d711c7e0755 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Wed, 6 Oct 2021 11:11:37 +0200 Subject: [PATCH 7/8] Adjustments regarding the removal of scanner, type, config_type. Minor changes to the source code regarding the removal of the fields scanner, type, config_type and hr_name. --- src/gmp.c | 6 +++--- src/manage.h | 11 +---------- src/manage_migrators.c | 8 ++++---- src/manage_sql_configs.c | 6 +++--- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index 084970891..cbfc029e7 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -8507,7 +8507,7 @@ buffer_config_preference_xml (GString *buffer, iterator_t *prefs, "" "%s" "%s" - "%s" + "%s" "%s" "%s", oid ? oid : "", @@ -11577,7 +11577,7 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error) "" "%i%i" "" - "0" + "0" "%s" "%i", config_iterator_family_count (&configs), @@ -21816,7 +21816,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context, goto create_task_fail; } - if (!create_task_check_config_scanner (scanner)) + if (!create_task_check_config_scanner_type (scanner)) { SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX ("create_task", diff --git a/src/manage.h b/src/manage.h index 600447a70..53af8766f 100644 --- a/src/manage.h +++ b/src/manage.h @@ -1755,7 +1755,7 @@ target_login_port (target_t, const char*); * These are here because they need definitions that are still in manage.h. */ int -create_task_check_config_scanner (scanner_t); +create_task_check_config_scanner_type (scanner_t); int modify_task_check_config_scanner (task_t, const char *, const char *); @@ -2582,15 +2582,6 @@ scanner_iterator_key_pub (iterator_t *); const char* scanner_iterator_credential_type (iterator_t *); -void -init_scanner_config_iterator (iterator_t*, scanner_t); - -const char* -scanner_config_iterator_uuid (iterator_t *); - -const char* -scanner_config_iterator_name (iterator_t *); - int scanner_config_iterator_readable (iterator_t *); diff --git a/src/manage_migrators.c b/src/manage_migrators.c index 5785c505b..d47edc84d 100644 --- a/src/manage_migrators.c +++ b/src/manage_migrators.c @@ -2873,14 +2873,14 @@ migrate_248_to_249 () /* Remove config data for OSP-Scanners */ sql ("DELETE FROM config_preferences_trash WHERE config IN" - " (SELECT id FROM configs_trash WHERE usage_type = 'scan' AND type = 1);"); - sql ("DELETE FROM configs_trash WHERE usage_type = 'scan' AND type = 1;"); + " (SELECT id FROM configs_trash WHERE type = 1);"); + sql ("DELETE FROM configs_trash WHERE type = 1;"); sql ("ALTER TABLE configs_trash DROP COLUMN scanner;"); sql ("ALTER TABLE configs_trash DROP COLUMN type;"); sql ("DELETE FROM config_preferences WHERE config IN" - " (SELECT id FROM configs WHERE usage_type = 'scan' AND type = 1);"); - sql ("DELETE FROM configs WHERE usage_type = 'scan' AND type = 1;"); + " (SELECT id FROM configs WHERE type = 1);"); + sql ("DELETE FROM configs WHERE type = 1;"); sql ("ALTER TABLE configs DROP COLUMN scanner;"); sql ("ALTER TABLE configs DROP COLUMN type;"); diff --git a/src/manage_sql_configs.c b/src/manage_sql_configs.c index 876fb66e6..2475fdc00 100644 --- a/src/manage_sql_configs.c +++ b/src/manage_sql_configs.c @@ -2709,14 +2709,14 @@ config_nvt_timeout (config_t config, const char *oid) } /** - * @brief Check scanner and config values match for a task. + * @brief Check if the scanner type is valid for a task. * * @param[in] scanner Scanner. * - * @return 1 if config and scanner types match, 0 otherwise. + * @return 1 if scanner type is valid, 0 otherwise. */ int -create_task_check_config_scanner (scanner_t scanner) +create_task_check_config_scanner_type (scanner_t scanner) { int stype; From c86141861ebf2a44ac73dd0cd08e269ede46c15e Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Wed, 6 Oct 2021 11:57:00 +0200 Subject: [PATCH 8/8] Changed name of function "create_task_check_config_scanner_type". Since in the function "create_task_check_config_scanner_type" the config type is no longer checked and only the scanner type is verified, the name of this function was changed to "create_task_check_scanner_type". --- src/gmp.c | 2 +- src/manage.h | 2 +- src/manage_sql_configs.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index cbfc029e7..6fb116b63 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -21816,7 +21816,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context, goto create_task_fail; } - if (!create_task_check_config_scanner_type (scanner)) + if (!create_task_check_scanner_type (scanner)) { SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX ("create_task", diff --git a/src/manage.h b/src/manage.h index 53af8766f..4d30ccca5 100644 --- a/src/manage.h +++ b/src/manage.h @@ -1755,7 +1755,7 @@ target_login_port (target_t, const char*); * These are here because they need definitions that are still in manage.h. */ int -create_task_check_config_scanner_type (scanner_t); +create_task_check_scanner_type (scanner_t); int modify_task_check_config_scanner (task_t, const char *, const char *); diff --git a/src/manage_sql_configs.c b/src/manage_sql_configs.c index 2475fdc00..8e23b013a 100644 --- a/src/manage_sql_configs.c +++ b/src/manage_sql_configs.c @@ -2716,7 +2716,7 @@ config_nvt_timeout (config_t config, const char *oid) * @return 1 if scanner type is valid, 0 otherwise. */ int -create_task_check_config_scanner_type (scanner_t scanner) +create_task_check_scanner_type (scanner_t scanner) { int stype;