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

Add: Feed data objects can now be deprecated #2101

Merged
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
18 changes: 18 additions & 0 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -11773,6 +11773,12 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error)
}
SEND_GET_COMMON (config, &get_configs_data->get, &configs);

if (resource_id_deprecated ("config",
get_iterator_uuid (&configs)))
{
SENDF_TO_CLIENT_OR_FAIL ("<deprecated>1</deprecated>");
}

/** @todo This should really be an nvt_selector_t. */
selector = config_iterator_nvt_selector (&configs);
config = get_iterator_resource (&configs);
Expand Down Expand Up @@ -14046,6 +14052,12 @@ handle_get_port_lists (gmp_parser_t *gmp_parser, GError **error)
SEND_GET_COMMON (port_list, &get_port_lists_data->get,
&port_lists);

if (resource_id_deprecated ("port_list",
get_iterator_uuid (&port_lists)))
{
SENDF_TO_CLIENT_OR_FAIL ("<deprecated>1</deprecated>");
}

SENDF_TO_CLIENT_OR_FAIL ("<port_count>"
"<all>%i</all>"
"<tcp>%i</tcp>"
Expand Down Expand Up @@ -14926,6 +14938,12 @@ handle_get_report_formats (gmp_parser_t *gmp_parser, GError **error)
: report_format_predefined
(get_iterator_resource (&report_formats)));

if (resource_id_deprecated ("report_format",
get_iterator_uuid (&report_formats)))
{
SENDF_TO_CLIENT_OR_FAIL ("<deprecated>1</deprecated>");
}

if (get_report_formats_data->alerts)
{
iterator_t alerts;
Expand Down
14 changes: 12 additions & 2 deletions src/gmp_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ attr_or_null (entity_t entity, const gchar *name)
* @param[out] all_selector True if ALL_SELECTOR was present.
* @param[out] import_nvt_selectors Address for selectors.
* @param[out] import_preferences Address for preferences.
* @param[out] deprecated Address for deprecation status.
*
* @return 0 success, 1 preference did no exist, -1 preference without ID.
*/
Expand All @@ -190,7 +191,8 @@ parse_config_entity (entity_t config, const char **config_id, char **name,
char **comment, char **usage_type,
int *all_selector,
array_t **import_nvt_selectors,
array_t **import_preferences)
array_t **import_preferences,
char **deprecated)
{
entity_t entity, preferences, nvt_selectors;

Expand All @@ -217,6 +219,14 @@ parse_config_entity (entity_t config, const char **config_id, char **name,
*usage_type = NULL;
}

if (deprecated)
{
*deprecated = NULL;
entity = entity_child (config, "deprecated");
if (entity)
*deprecated = entity_text (entity);
}

/* Collect NVT selectors. */

*import_nvt_selectors = NULL;
Expand Down Expand Up @@ -416,7 +426,7 @@ create_config_run (gmp_parser_t *gmp_parser, GError **error)

if (parse_config_entity (config, NULL, &import_name, &comment,
NULL, &all_selector, &import_nvt_selectors,
&import_preferences))
&import_preferences, NULL))
{
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("create_config",
Expand Down
2 changes: 1 addition & 1 deletion src/gmp_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ create_config_element_text (const gchar *, gsize);

int
parse_config_entity (entity_t, const char **, char **, char **,
char **, int *, array_t **, array_t **);
char **, int *, array_t **, array_t **, char **);

/* modify_config */

Expand Down
14 changes: 12 additions & 2 deletions src/gmp_port_lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ create_port_list_element_start (gmp_parser_t *gmp_parser, const gchar *name,
* @param[out] name Address for name.
* @param[out] comment Address for comment.
* @param[out] ranges Address for port ranges.
* @param[out] deprecated Address for deprecation status.
*/
void
parse_port_list_entity (entity_t port_list, const char **port_list_id,
char **name, char **comment, array_t **ranges)
char **name, char **comment, array_t **ranges,
char **deprecated)
{
entity_t entity, port_ranges;

Expand All @@ -129,6 +131,14 @@ parse_port_list_entity (entity_t port_list, const char **port_list_id,
if (entity)
*comment = entity_text (entity);

if (deprecated)
{
*deprecated = NULL;
entity = entity_child (port_list, "deprecated");
if (entity)
*deprecated = entity_text (entity);
}

/* Collect port ranges. */

*ranges = NULL;
Expand Down Expand Up @@ -207,7 +217,7 @@ create_port_list_run (gmp_parser_t *gmp_parser, GError **error)
/* Get the port_list data from the XML. */

parse_port_list_entity (port_list, &port_list_id, &import_name,
&comment, &ranges);
&comment, &ranges, NULL);

/* Check data, then create port list. */

Expand Down
3 changes: 2 additions & 1 deletion src/gmp_port_lists.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void
create_port_list_element_text (const gchar *, gsize);

void
parse_port_list_entity (entity_t, const char **, char **, char **, array_t **);
parse_port_list_entity (entity_t, const char **, char **, char **, array_t **,
char **);

#endif /* not _GVMD_GMP_PORT_LISTS_H */
8 changes: 6 additions & 2 deletions src/gmp_report_formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,16 @@ params_options_free (array_t *params_options)
* @param[out] files Address for files.
* @param[out] params Address for params.
* @param[out] params_options Address for param options.
* @param[out] deprecated Address for deprecation status.
*/
void
parse_report_format_entity (entity_t report_format,
const char **report_format_id, char **name,
char **content_type, char **extension,
char **summary, char **description,
char **signature, array_t **files,
array_t **params, array_t **params_options)
array_t **params, array_t **params_options,
char **deprecated)
{
entity_t file, param_entity;
entities_t children;
Expand All @@ -177,6 +179,8 @@ parse_report_format_entity (entity_t report_format,
*summary = child_or_null (report_format, "summary");
*description = child_or_null (report_format, "description");
*signature = child_or_null (report_format, "signature");
if (deprecated)
*deprecated = child_or_null (report_format, "deprecated");

*files = make_array ();
*params = make_array ();
Expand Down Expand Up @@ -367,7 +371,7 @@ create_report_format_run (gmp_parser_t *gmp_parser, GError **error)
parse_report_format_entity (report_format, &report_format_id,
&import_name, &content_type, &extension,
&summary, &description, &signature, &files,
&params, &params_options);
&params, &params_options, NULL);

/* Check data, then create report format. */

Expand Down
2 changes: 1 addition & 1 deletion src/gmp_report_formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ params_options_free (array_t *);
void
parse_report_format_entity (entity_t, const char **, char **, char **,
char **, char **, char **, char **,
array_t **, array_t **, array_t **);
array_t **, array_t **, array_t **, char **);

#endif /* not _GVMD_GMP_REPORT_FORMATS_H */
6 changes: 6 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ type_is_scap (const char*);
int
delete_resource (const char *, const char *, int);

int
resource_id_deprecated (const char *, const char *);

void
set_resource_id_deprecated (const char *, const char *, gboolean);


/* Events and Alerts. */

Expand Down
49 changes: 43 additions & 6 deletions src/manage_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ update_config_from_file (config_t config, const gchar *path)
{
entity_t entity;
array_t *nvt_selectors, *preferences;
char *comment, *name, *usage_type;
char *comment, *name, *usage_type, *deprecated;
const char *config_id;
int all_selector;

Expand All @@ -156,7 +156,7 @@ update_config_from_file (config_t config, const gchar *path)

switch (parse_config_entity (entity, &config_id, &name, &comment,
&usage_type, &all_selector, &nvt_selectors,
&preferences))
&preferences, &deprecated))
{
case 0:
break;
Expand All @@ -174,7 +174,7 @@ update_config_from_file (config_t config, const gchar *path)
/* Update the config. */

update_config (config, name, comment, usage_type, all_selector,
nvt_selectors, preferences);
nvt_selectors, preferences, deprecated);

/* Cleanup. */

Expand All @@ -197,7 +197,7 @@ create_config_from_file (const gchar *path)
{
entity_t config;
array_t *nvt_selectors, *preferences;
char *created_name, *comment, *name, *usage_type;
char *created_name, *comment, *name, *usage_type, *deprecated;
const char *config_id;
config_t new_config;
int all_selector;
Expand All @@ -213,7 +213,7 @@ create_config_from_file (const gchar *path)

switch (parse_config_entity (config, &config_id, &name, &comment,
&usage_type, &all_selector, &nvt_selectors,
&preferences))
&preferences, &deprecated))
{
case 0:
break;
Expand All @@ -228,6 +228,16 @@ create_config_from_file (const gchar *path)
return -1;
}

/* Handle deprecation status */

if (deprecated && atoi (deprecated))
{
g_debug ("Skipping import of deprecated config %s.",
config_id);
set_resource_id_deprecated ("config", config_id, TRUE);
return 0;
}

/* Create the config. */

switch (create_config_no_acl (config_id,
Expand Down Expand Up @@ -329,11 +339,37 @@ should_sync_config_from_path (const char *path, gboolean rebuild,
uuid = g_strdup_printf ("%s-%s-%s-%s-%s",
split[1], split[2], split[3], split[4], split[5]);
g_strfreev (split);

if (resource_id_deprecated ("config", uuid))
{
find_config_no_acl (uuid, config);
timopollmeier marked this conversation as resolved.
Show resolved Hide resolved

if (rebuild)
{
g_free (uuid);
return 1;
}

full_path = g_build_filename (feed_dir_configs (), path, NULL);
if (deprecated_config_id_updated_in_feed (uuid, full_path))
{
g_free (uuid);
g_free (full_path);
return 1;
timopollmeier marked this conversation as resolved.
Show resolved Hide resolved
}
g_free (uuid);
g_free (full_path);
return 0;
timopollmeier marked this conversation as resolved.
Show resolved Hide resolved
}

if (find_config_no_acl (uuid, config) == 0
&& *config)
{
if (rebuild)
return 1;
{
g_free (uuid);
return 1;
}

full_path = g_build_filename (feed_dir_configs (), path, NULL);

Expand All @@ -343,6 +379,7 @@ should_sync_config_from_path (const char *path, gboolean rebuild,

if (config_updated_in_feed (*config, full_path))
{
g_free (full_path);
return 1;
}

Expand Down
7 changes: 7 additions & 0 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1993,6 +1993,13 @@ create_tables ()
" type TEXT,"
" value TEXT);");

sql ("CREATE TABLE IF NOT EXISTS deprecated_feed_data"
" (id SERIAL PRIMARY KEY,"
" type TEXT,"
" uuid TEXT,"
" modification_time INTEGER,"
" UNIQUE (type, uuid));");

sql ("CREATE TABLE IF NOT EXISTS filters"
" (id SERIAL PRIMARY KEY,"
" uuid text UNIQUE NOT NULL,"
Expand Down
Loading