From fc01f50458f9c45c5cf8569eb81ef7bd939a9ccc Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Wed, 20 Jan 2021 15:15:14 +0100 Subject: [PATCH 1/5] Improve get_info "Failed to find..." message If a SecInfo entry cannot be found by ID or name, the error message will say it cannot find the given ID or name instead of a misleading message that the type could not be found. --- src/gmp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index 6da24ff76..e3011651d 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -13112,8 +13112,13 @@ handle_get_info (gmp_parser_t *gmp_parser, GError **error) switch (ret) { case 1: - if (send_find_error_to_client ("get_info", "type", - get_info_data->type, + if (send_find_error_to_client ("get_info", + get_info_data->name + ? "name" + : "ID", + get_info_data->name + ? get_info_data->name + : get_info_data->get.id, gmp_parser)) { error_send_to_client (error); From b34580e130604a27f4549a80bea94a5a6cf8491a Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Wed, 20 Jan 2021 15:19:09 +0100 Subject: [PATCH 2/5] Add improved get_info error message to CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67ccc822f..a693fb6b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Allow config to sync even if NVT family is not available [#1366](https://github.com/greenbone/gvmd/pull/1366) - Delete report format dirs last when deleting a user [#1368](https://github.com/greenbone/gvmd/pull/1368) - Fix sorting in get_aggregates and its documentation [#1375](https://github.com/greenbone/gvmd/pull/1375) +- Improve get_info "Failed to find..." message [#1395](https://github.com/greenbone/gvmd/pull/1395) ### Removed - Remove DROP from vulns creation [#1281](http://github.com/greenbone/gvmd/pull/1281) From 9504567cace8d4f3eaecf7cc0a3dd2934cf2c277 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Thu, 21 Jan 2021 09:39:41 +0100 Subject: [PATCH 3/5] Use XML-escaping in send_find_error_to_client This ensures the error messages work if reserved characters are used in the requested id or name. --- src/gmp_base.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gmp_base.c b/src/gmp_base.c index db04c0e56..e589dce36 100644 --- a/src/gmp_base.c +++ b/src/gmp_base.c @@ -151,10 +151,10 @@ send_find_error_to_client (const char* command, const char* type, gchar *msg; gboolean ret; - msg = g_strdup_printf ("<%s_response status=\"" - STATUS_ERROR_MISSING - "\" status_text=\"Failed to find %s '%s'\"/>", - command, type, id); + msg = g_markup_printf_escaped ("<%s_response status=\"" + STATUS_ERROR_MISSING + "\" status_text=\"Failed to find %s '%s'\"/>", + command, type, id); ret = send_to_client (msg, gmp_parser->client_writer, gmp_parser->client_writer_data); g_free (msg); From 50adcc9900bd8a8be17d00c78a42619b277fe8c3 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Thu, 21 Jan 2021 09:52:48 +0100 Subject: [PATCH 4/5] Update CHANGELOG for "Failed to find" messages --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a693fb6b3..dcc72164c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,7 +56,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Allow config to sync even if NVT family is not available [#1366](https://github.com/greenbone/gvmd/pull/1366) - Delete report format dirs last when deleting a user [#1368](https://github.com/greenbone/gvmd/pull/1368) - Fix sorting in get_aggregates and its documentation [#1375](https://github.com/greenbone/gvmd/pull/1375) -- Improve get_info "Failed to find..." message [#1395](https://github.com/greenbone/gvmd/pull/1395) +- Improve "Failed to find..." messages [#1395](https://github.com/greenbone/gvmd/pull/1395) ### Removed - Remove DROP from vulns creation [#1281](http://github.com/greenbone/gvmd/pull/1281) From d522fec59abf169d4bbc8a8c3ad908b5c166d300 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Thu, 21 Jan 2021 10:32:11 +0100 Subject: [PATCH 5/5] Fix filt_id "Failed to find filter" messages Some of the messages used the type of the get_... command instead of "filter" when the filter given by filt_id could not be found. --- src/gmp.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index e3011651d..eb385dd2b 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -11133,7 +11133,7 @@ handle_get_alerts (gmp_parser_t *gmp_parser, GError **error) break; case 2: if (send_find_error_to_client - ("get_alerts", "alert", get_alerts_data->get.filt_id, + ("get_alerts", "filter", get_alerts_data->get.filt_id, gmp_parser)) { error_send_to_client (error); @@ -11697,7 +11697,7 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error) break; case 2: if (send_find_error_to_client - ("get_configs", "config", get_configs_data->get.filt_id, + ("get_configs", "filter", get_configs_data->get.filt_id, gmp_parser)) { error_send_to_client (error); @@ -12067,7 +12067,7 @@ handle_get_credentials (gmp_parser_t *gmp_parser, GError **error) break; case 2: if (send_find_error_to_client ("get_credentials", - "credential", + "filter", get_credentials_data->get.filt_id, gmp_parser)) { @@ -12856,7 +12856,7 @@ handle_get_groups (gmp_parser_t *gmp_parser, GError **error) break; case 2: if (send_find_error_to_client - ("get_groups", "group", get_groups_data->get.filt_id, + ("get_groups", "filter", get_groups_data->get.filt_id, gmp_parser)) { error_send_to_client (error); @@ -14032,7 +14032,7 @@ handle_get_port_lists (gmp_parser_t *gmp_parser, GError **error) break; case 2: if (send_find_error_to_client - ("get_port_lists", "port_list", + ("get_port_lists", "filter", get_port_lists_data->get.filt_id, gmp_parser)) { error_send_to_client (error); @@ -15365,7 +15365,7 @@ handle_get_roles (gmp_parser_t *gmp_parser, GError **error) break; case 2: if (send_find_error_to_client - ("get_roles", "role", get_roles_data->get.filt_id, + ("get_roles", "filter", get_roles_data->get.filt_id, gmp_parser)) { error_send_to_client (error); @@ -16945,7 +16945,7 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error) break; case 2: if (send_find_error_to_client - ("get_tasks", "task", get_tasks_data->get.filt_id, + ("get_tasks", "filter", get_tasks_data->get.filt_id, gmp_parser)) { error_send_to_client (error); @@ -17663,7 +17663,7 @@ handle_get_users (gmp_parser_t *gmp_parser, GError **error) break; case 2: if (send_find_error_to_client - ("get_users", "user", get_users_data->get.filt_id, + ("get_users", "filter", get_users_data->get.filt_id, gmp_parser)) { error_send_to_client (error);