From b73f1eaf4d7ef2a5e6c9e7cf2fd9826d7a0f048b Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Thu, 22 Aug 2019 12:11:29 +0200 Subject: [PATCH 1/2] Make bulk tagging work if resources already tagged If the the resource filter for modifying a tag includes only already tagged resources, no longer consider it as the filter returning no resources. --- src/manage_sql.c | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index 12fdb2179..71d4764a3 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -62151,13 +62151,12 @@ manage_slave_check_period () * @param[in] uuid The resource UUID. * @param[in] resource The resource row id. * @param[in] location Whether the resource is in the trashcan. - * @param[in] duplicates_check Whether to check if resource already has tag. - * + * * @return 0 success, -1 error */ static int tag_add_resource (tag_t tag, const char *type, const char *uuid, - resource_t resource, int location, int duplicates_check) + resource_t resource, int location) { int already_added, ret; gchar *quoted_resource_uuid; @@ -62166,9 +62165,7 @@ tag_add_resource (tag_t tag, const char *type, const char *uuid, quoted_resource_uuid = uuid ? sql_insert (uuid) : g_strdup ("''"); - if (duplicates_check == 0) - already_added = 0; - else if (type_is_info_subtype (type)) + if (type_is_info_subtype (type)) already_added = sql_int ("SELECT count(*) FROM tag_resources" " WHERE resource_type = '%s'" " AND resource_uuid = %s" @@ -62242,7 +62239,7 @@ tag_add_resource_uuid (tag_t tag, const char *type, const char *uuid, if (resource == 0) return 1; - return tag_add_resource (tag, type, uuid, resource, resource_location, 1); + return tag_add_resource (tag, type, uuid, resource, resource_location); } /** @@ -62340,30 +62337,9 @@ tag_add_resources_filter (tag_t tag, const char *type, const char *filter) return 2; } - if (type_is_info_subtype (type)) - init_iterator (&resources, - "SELECT id, uuid FROM (%s) AS filter_selection" - " WHERE NOT EXISTS" - " (SELECT * FROM tag_resources" - " WHERE resource_type = '%s'" - " AND resource_uuid = filter_selection.uuid" - " AND tag = %llu)", - filtered_select, - type, - tag); - else - init_iterator (&resources, - "SELECT id, uuid FROM (%s) AS filter_selection" - " WHERE NOT EXISTS" - " (SELECT * FROM tag_resources" - " WHERE resource_type = '%s'" - " AND resource = filter_selection.id" - " AND resource_location = %d" - " AND tag = %llu)", - filtered_select, - type, - LOCATION_TABLE, - tag); + init_iterator (&resources, + "%s", + filtered_select); break; default: @@ -62390,7 +62366,7 @@ tag_add_resources_filter (tag_t tag, const char *type, const char *filter) current_uuid = iterator_string (&resources, 1); add_ret = tag_add_resource (tag, type, current_uuid, resource, - LOCATION_TABLE, 0); + LOCATION_TABLE); if (add_ret) { ret = add_ret; From 65fd58e5d899f36303fb592ed5beb4a12a8875f2 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Thu, 22 Aug 2019 12:15:11 +0200 Subject: [PATCH 2/2] Add CHANGELOG entry for bulk tagging fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index daa284f57..4f7845a2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix ORPHAN calculations in GET_TICKETS [#684](https://github.com/greenbone/gvmd/pull/684) [#692](https://github.com/greenbone/gvmd/pull/692) - Fix assignment of orphaned tickets to the current user [#685](https://github.com/greenbone/gvmd/pull/685) - Fix response from GET_VULNS when given vuln_id does not exists [#696](https://github.com/greenbone/gvmd/pull/696) +- Make bulk tagging with a filter work if the resources are already tagged [#711](https://github.com/greenbone/gvmd/pull/711) ### Removed - The handling of NVT updates via OTP has been removed. [#575](https://github.com/greenbone/gvmd/pull/575)