Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not skip scan_config if preference was not found #1005

Merged
merged 5 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 2 additions & 14 deletions src/gmp_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -346,15 +343,6 @@ parse_config_entity (entity_t config, int require_preferences,
preference_name,
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;
}
}
else
{
Expand Down Expand Up @@ -442,7 +430,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))
{
Expand Down
2 changes: 1 addition & 1 deletion src/gmp_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
4 changes: 2 additions & 2 deletions src/manage_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, 1, &config_id, &name, &comment, &type,
switch (parse_config_entity (entity, &config_id, &name, &comment, &type,
&usage_type, &all_selector, &nvt_selectors,
&preferences))
{
Expand Down Expand Up @@ -212,7 +212,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, &config_id, &name, &comment, &type,
&usage_type, &all_selector, &nvt_selectors,
&preferences))
{
Expand Down
63 changes: 41 additions & 22 deletions src/manage_sql_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down