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

Remove scanner, type from configs, re-add hr_name for nvt preferences #1694

Merged
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ include (CPack)

## Variables

set (GVMD_DATABASE_VERSION 248)
set (GVMD_DATABASE_VERSION 249)

set (GVMD_SCAP_DATABASE_VERSION 19)

Expand Down
100 changes: 8 additions & 92 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -8508,6 +8507,7 @@ buffer_config_preference_xml (GString *buffer, iterator_t *prefs,
"<preference>"
"<nvt oid=\"%s\"><name>%s</name></nvt>"
"<id>%s</id>"
"<hr_name>%s</hr_name>"
timopollmeier marked this conversation as resolved.
Show resolved Hide resolved
"<name>%s</name>"
"<type>%s</type>",
oid ? oid : "",
Expand Down Expand Up @@ -11546,7 +11546,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;

Expand All @@ -11565,7 +11565,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);
Expand All @@ -11578,19 +11577,17 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error)
"<nvt_count>"
"%i<growing>%i</growing>"
"</nvt_count>"
"<type>%i</type>"
"<type>0</type>"
timopollmeier marked this conversation as resolved.
Show resolved Hide resolved
"<usage_type>%s</usage_type>"
"<predefined>%i</predefined>",
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;
Expand Down Expand Up @@ -11656,62 +11653,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 ("<scanner id='%s'>"
"%s"
"<trash>%d</trash>"
"</scanner>",
s_uuid, s_name,
config_iterator_scanner_trash (&configs));

g_free (s_uuid);
g_free (s_name);
SEND_TO_CLIENT_OR_FAIL ("<preferences>");

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
("<preference>"
"<nvt oid=\"\"><name/></nvt>"
"<id/>"
"<name>%s</name>"
"<type>osp_%s</type>"
"<value>%s</value>"
"<default>%s</default>"
"</preference>",
name, type, value ?: "", def);
}
cleanup_iterator (&prefs);
SEND_TO_CLIENT_OR_FAIL ("</preferences>");
}
else if (get_configs_data->preferences
|| get_configs_data->get.details)
if (get_configs_data->preferences || get_configs_data->get.details)
{
iterator_t prefs;

Expand Down Expand Up @@ -11758,7 +11700,7 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error)
SEND_TO_CLIENT_OR_FAIL ("</preferences>");
}

if (config_type == 0 && get_configs_data->get.details)
if (get_configs_data->get.details)
{
iterator_t selectors;

Expand Down Expand Up @@ -15351,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 ("<configs>");
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
("<config id=\"%s\">"
"<name>%s</name>",
scanner_config_iterator_uuid (&configs),
scanner_config_iterator_name (&configs));

if (scanner_config_iterator_readable (&configs))
SEND_TO_CLIENT_OR_FAIL ("</config>");
else
SEND_TO_CLIENT_OR_FAIL ("<permissions/>"
"</config>");
}
cleanup_iterator (&configs);
SEND_TO_CLIENT_OR_FAIL ("</configs>");
iterator_t tasks;

SEND_TO_CLIENT_OR_FAIL ("<tasks>");
init_scanner_task_iterator (&tasks,
Expand Down Expand Up @@ -17181,7 +17099,6 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error)
"<usage_type>%s</usage_type>"
"<config id=\"%s\">"
"<name>%s</name>"
"<type>%i</type>"
"<trash>%i</trash>"
"%s"
"</config>"
Expand Down Expand Up @@ -17211,7 +17128,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 ? "" : "<permissions/>",
task_target_uuid ?: "",
Expand Down Expand Up @@ -21900,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",
Expand Down
37 changes: 7 additions & 30 deletions src/gmp_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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");
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -363,6 +357,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 */);
}

Expand Down Expand Up @@ -399,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;
Expand All @@ -419,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))
{
Expand All @@ -443,7 +438,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))
Expand Down Expand Up @@ -701,7 +695,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.
*
Expand All @@ -711,32 +704,17 @@ 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;
case 1:
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"));
Expand Down Expand Up @@ -1072,7 +1050,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))
{
Expand Down
2 changes: 1 addition & 1 deletion src/gmp_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 1 addition & 4 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
Loading