From a0ebe88cfa7692c6f390f6894824cb1e665e620c Mon Sep 17 00:00:00 2001 From: Emanuel Moss Date: Wed, 11 Mar 2020 10:46:01 +0100 Subject: [PATCH 1/4] Do not skip scan_config if preference was not found --- src/manage_configs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/manage_configs.c b/src/manage_configs.c index 0faa50850..4cef6ee5e 100644 --- a/src/manage_configs.c +++ b/src/manage_configs.c @@ -130,7 +130,7 @@ update_config_from_file (config_t config, const gchar *path) /* Parse the data out of the entity. */ - switch (parse_config_entity (entity, 1, &config_id, &name, &comment, &type, + switch (parse_config_entity (entity, 0, &config_id, &name, &comment, &type, &usage_type, &nvt_selectors, &preferences)) { case 0: @@ -185,7 +185,7 @@ create_config_from_file (const gchar *path) /* Parse the data out of the entity. */ - switch (parse_config_entity (config, 1, &config_id, &name, &comment, &type, + switch (parse_config_entity (config, 0, &config_id, &name, &comment, &type, &usage_type, &nvt_selectors, &preferences)) { case 0: From 6df96d2f89062450e28c99000281ab49fc16ed81 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Wed, 29 Jul 2020 15:01:22 +0200 Subject: [PATCH 2/4] Remove arg that is always zero --- src/gmp_configs.c | 19 ++++++------------- src/gmp_configs.h | 2 +- src/manage_configs.c | 4 ++-- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/gmp_configs.c b/src/gmp_configs.c index c8abd16b7..198006b4b 100644 --- a/src/gmp_configs.c +++ b/src/gmp_configs.c @@ -174,8 +174,6 @@ attr_or_null (entity_t entity, const gchar *name) * @brief Get creation data from a config entity. * * @param[in] config Config entity. - * @param[in] require_preferences Whether OpenVAS config preferences must - * exist. * @param[out] config_id Address for config ID, or NULL. * @param[out] name Address for name. * @param[out] comment Address for comment. @@ -188,8 +186,7 @@ attr_or_null (entity_t entity, const gchar *name) * @return 0 success, 1 preference did no exist, -1 preference without ID. */ int -parse_config_entity (entity_t config, int require_preferences, - const char **config_id, char **name, +parse_config_entity (entity_t config, const char **config_id, char **name, char **comment, char **type, char **usage_type, int *all_selector, array_t **import_nvt_selectors, @@ -347,14 +344,10 @@ parse_config_entity (entity_t config, int require_preferences, preference_type, preference_value ?: ""); if (new_preference == NULL) - { - g_warning ("%s: Preference %s:%s not found", - __func__, - preference_nvt_oid, - preference_id); - if (require_preferences) - return 1; - } + g_warning ("%s: Preference %s:%s not found", + __func__, + preference_nvt_oid, + preference_id); } else { @@ -442,7 +435,7 @@ create_config_run (gmp_parser_t *gmp_parser, GError **error) /* Get the config data from the XML. */ - if (parse_config_entity (config, 0, NULL, &import_name, &comment, &type, + if (parse_config_entity (config, NULL, &import_name, &comment, &type, NULL, &all_selector, &import_nvt_selectors, &import_preferences)) { diff --git a/src/gmp_configs.h b/src/gmp_configs.h index 3655daca7..ade43d886 100644 --- a/src/gmp_configs.h +++ b/src/gmp_configs.h @@ -38,7 +38,7 @@ void create_config_element_text (const gchar *, gsize); int -parse_config_entity (entity_t, int, const char **, char **, char **, char **, +parse_config_entity (entity_t, const char **, char **, char **, char **, char **, int *, array_t **, array_t **); #endif /* not _GVMD_GMP_CONFIGS_H */ diff --git a/src/manage_configs.c b/src/manage_configs.c index c2e03241d..18c70d88e 100644 --- a/src/manage_configs.c +++ b/src/manage_configs.c @@ -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, 0, &config_id, &name, &comment, &type, + switch (parse_config_entity (entity, &config_id, &name, &comment, &type, &usage_type, &all_selector, &nvt_selectors, &preferences)) { @@ -212,7 +212,7 @@ create_config_from_file (const gchar *path) /* Parse the data out of the entity. */ - switch (parse_config_entity (config, 0, &config_id, &name, &comment, &type, + switch (parse_config_entity (config, &config_id, &name, &comment, &type, &usage_type, &all_selector, &nvt_selectors, &preferences)) { From ed90c2fe48c1323b49865e3944fe9e4579f388d1 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Wed, 29 Jul 2020 16:39:47 +0200 Subject: [PATCH 3/4] Add config preferences even if they are not in nvt_preferences This ensures that the config preference is created even when the NVT or NVT preference has not arrived in the feed yet. It is required because syncing of configs no longer requires the NVT preferences to all be present (in order to speed up availability of feed defined configs during initial sync). --- src/gmp_configs.c | 5 ---- src/manage_sql_configs.c | 63 ++++++++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/gmp_configs.c b/src/gmp_configs.c index 198006b4b..be1bbe0ed 100644 --- a/src/gmp_configs.c +++ b/src/gmp_configs.c @@ -343,11 +343,6 @@ parse_config_entity (entity_t config, const char **config_id, char **name, preference_name, preference_type, preference_value ?: ""); - if (new_preference == NULL) - g_warning ("%s: Preference %s:%s not found", - __func__, - preference_nvt_oid, - preference_id); } else { diff --git a/src/manage_sql_configs.c b/src/manage_sql_configs.c index fc51b0ca2..9f071bf91 100644 --- a/src/manage_sql_configs.c +++ b/src/manage_sql_configs.c @@ -2050,7 +2050,6 @@ get_nvt_preference_by_id (const char *nvt_oid, char *full_name, *id, *name, *type, *nvt_name, *default_value, *hr_name; array_t *alts; gchar *quoted_oid, *quoted_id; - char **full_name_split; full_name = name = type = nvt_name = default_value = hr_name = NULL; @@ -2084,33 +2083,53 @@ get_nvt_preference_by_id (const char *nvt_oid, g_free (quoted_id); if (full_name == NULL) - return NULL; + { + if (check_name == NULL || strcmp (check_name, "") == 0) + { + g_warning ("%s: Preference not found and given name is missing/empty", + __func__); + return NULL; + } + if (check_type == NULL || strcmp (check_type, "") == 0) + { + g_warning ("%s: Preference not found and given name is missing/empty", + __func__); + return NULL; + } + id = strdup (find_id); + type = strdup (check_type); + name = strdup (check_name); + } + else + { + char **full_name_split; - /* Try to get components of the full name */ - full_name_split = g_strsplit (full_name, ":", 4); + /* Try to get components of the full name */ + full_name_split = g_strsplit (full_name, ":", 4); - if (g_strv_length (full_name_split) != 4) - { - g_warning ("%s: Preference name %s does not have 4 parts", - __func__, full_name); - g_strfreev (full_name_split); + if (g_strv_length (full_name_split) != 4) + { + g_warning ("%s: Preference name %s does not have 4 parts", + __func__, full_name); + g_strfreev (full_name_split); + free (full_name); + return NULL; + } free (full_name); - return NULL; - } - free (full_name); - id = strdup (full_name_split[1]); - type = strdup (full_name_split[2]); - name = strdup (full_name_split[3]); - g_strfreev (full_name_split); + id = strdup (full_name_split[1]); + type = strdup (full_name_split[2]); + name = strdup (full_name_split[3]); + g_strfreev (full_name_split); - if (check_type && strcmp (check_type, "") && strcmp (check_type, type)) - g_warning ("%s: type of preference %s:%s (%s) has changed from %s to %s.", - __func__, nvt_oid, find_id, name, check_type, type); + if (check_type && strcmp (check_type, "") && strcmp (check_type, type)) + g_warning ("%s: type of preference %s:%s (%s) has changed from %s to %s.", + __func__, nvt_oid, find_id, name, check_type, type); - if (check_name && strcmp (check_name, "") && strcmp (check_name, name)) - g_message ("%s: name of preference %s:%s has changed from '%s' to '%s'.", - __func__, nvt_oid, find_id, check_name, name); + if (check_name && strcmp (check_name, "") && strcmp (check_name, name)) + g_message ("%s: name of preference %s:%s has changed from '%s' to '%s'.", + __func__, nvt_oid, find_id, check_name, name); + } alts = make_array (); array_terminate (alts); From bd2e2ccafd3305652ea1044c2f8b8a509613bd4e Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Wed, 29 Jul 2020 19:16:17 +0200 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a17737b28..0fc011332 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Reduce the memory cache of NVTs [#1076](https://github.com/greenbone/gvmd/pull/1076) - Sync SCAP using a second schema [#1111](https://github.com/greenbone/gvmd/pull/1111) - Use error variable in osp_get_vts_version(). [#1159](https://github.com/greenbone/gvmd/pull/1159) +- Include unknown preferences when uploading or syncing configs [#1005](https://github.com/greenbone/gvmd/pull/1005) ### Fixed - Add NULL check in nvts_feed_version_epoch [#768](https://github.com/greenbone/gvmd/pull/768)