Skip to content

Commit

Permalink
Merge pull request #1521 from greenbone/mergify/bp/master/pr-1517
Browse files Browse the repository at this point in the history
Fix whole-only config family selection (backport #1517)
  • Loading branch information
nichtsfrei authored May 14, 2021
2 parents b936dfc + 40354eb commit 15ddafe
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Fixed
- Improve VT version handling for CVE & OVAL results [#1496](https://github.com/greenbone/gvmd/pull/1496)
- Update subject alternative name in certificate generation [#1503](https://github.com/greenbone/gvmd/pull/1503)
- Fix whole-only config family selection [#1517](https://github.com/greenbone/gvmd/pull/1517)

[21.4.0]: https://github.com/greenbone/gvmd/compare/v21.4.0...gvmd-21.04

Expand Down
15 changes: 11 additions & 4 deletions src/gmp_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -904,12 +904,15 @@ modify_config_handle_family_selection (config_t config,
gmp_parser_t *gmp_parser,
GError **error)
{
gchar *rejected_family;

switch (manage_set_config_families
(config,
families_growing_all,
families_static_all,
families_growing_empty,
family_selection_growing))
family_selection_growing,
&rejected_family))
{
case 0:
return 0;
Expand All @@ -919,9 +922,13 @@ modify_config_handle_family_selection (config_t config,
return -1;
case 2:
SENDF_TO_CLIENT_OR_FAIL_WITH_RETURN
(-1, XML_ERROR_SYNTAX ("modify_config",
"Whole-only families must include entire"
" family and be growing"));
(-1,
XML_ERROR_SYNTAX ("modify_config",
"Family "%s" must be growing and"
" include all VTs or it must be static and"
" empty."),
rejected_family);
g_free (rejected_family);
return -1;
case -1:
SENDF_TO_CLIENT_OR_FAIL_WITH_RETURN
Expand Down
3 changes: 2 additions & 1 deletion src/manage_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ int
manage_set_config_nvts (config_t, const char*, GPtrArray*);

int
manage_set_config_families (config_t, GPtrArray*, GPtrArray*, GPtrArray*, int);
manage_set_config_families (config_t, GPtrArray*, GPtrArray*, GPtrArray*, int,
gchar **);

void
init_config_timeout_iterator (iterator_t*, config_t);
Expand Down
26 changes: 22 additions & 4 deletions src/manage_sql_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ manage_modify_config_commit ()
* @param[in] static_all_families Static families with all selection.
* @param[in] growing_families The rest of the growing families.
* @param[in] grow_families 1 if families should grow, else 0.
* @param[out] rejected_family Return of family if one was rejected.
*
* @return 0 success, 1 config in use, 2 whole-only families must be growing
* and include entire family, -1 error.
Expand All @@ -928,7 +929,8 @@ manage_set_config_families (config_t config,
GPtrArray* growing_all_families,
GPtrArray* static_all_families,
GPtrArray* growing_families,
int grow_families)
int grow_families,
gchar **rejected_family)
{
static const gchar *wholes[] = FAMILIES_WHOLE_ONLY;
iterator_t families;
Expand All @@ -938,10 +940,26 @@ manage_set_config_families (config_t config,

/* Ensure that whole-only families include all NVTs and are growing. */

if (rejected_family)
*rejected_family = NULL;

for (const gchar **whole = wholes; *whole; whole++)
if (member (growing_all_families, *whole)
|| member (static_all_families, *whole))
return 2;
{
if (member (static_all_families, *whole)
|| member (growing_families, *whole))
{
if (member (static_all_families, *whole))
g_debug ("%s rejected static/all whole-only family %s",
__func__, *whole);
else if (member (growing_families, *whole))
g_debug ("%s rejected growing/empty whole-only family %s",
__func__, *whole);

if (rejected_family)
*rejected_family = g_strdup (*whole);
return 2;
}
}

/* Check the args. */

Expand Down

0 comments on commit 15ddafe

Please sign in to comment.