From 3422366349a1ade5ac0c735e2ed5ef0b88b5895d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Thu, 1 Aug 2019 16:27:04 +0200 Subject: [PATCH 1/5] Sort calling gmp functions in gsad --- gsad/src/gsad.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/gsad/src/gsad.c b/gsad/src/gsad.c index 89b6678054..eba1c3a08a 100644 --- a/gsad/src/gsad.c +++ b/gsad/src/gsad.c @@ -1920,15 +1920,12 @@ exec_gmp_get (http_connection_t *con, gsad_connection_info_t *con_info, if (!strcmp (cmd, "cvss_calculator")) res = cvss_calculator (&connection, credentials, params, response_data); - ELSE (new_alert) - ELSE (get_task) - ELSE (get_tasks) + ELSE (auth_settings) ELSE (edit_alert) ELSE (edit_config) ELSE (edit_config_family) ELSE (edit_config_nvt) ELSE (edit_role) - ELSE (auth_settings) ELSE (export_agent) ELSE (export_agents) ELSE (export_alert) @@ -2061,8 +2058,13 @@ exec_gmp_get (http_connection_t *con, gsad_connection_info_t *con_info, ELSE (get_aggregate) ELSE (get_alert) ELSE (get_alerts) + ELSE (get_config) + ELSE (get_configs) + ELSE (get_config_family) + ELSE (get_config_nvt) ELSE (get_credential) ELSE (get_credentials) + ELSE (get_feeds) ELSE (get_filter) ELSE (get_filters) ELSE (get_group) @@ -2095,17 +2097,15 @@ exec_gmp_get (http_connection_t *con, gsad_connection_info_t *con_info, ELSE (get_tags) ELSE (get_target) ELSE (get_targets) + ELSE (get_task) + ELSE (get_tasks) ELSE (get_ticket) ELSE (get_tickets) ELSE (get_trash) ELSE (get_user) ELSE (get_users) ELSE (get_vulns) - ELSE (get_feeds) - ELSE (get_config) - ELSE (get_configs) - ELSE (get_config_family) - ELSE (get_config_nvt) + ELSE (new_alert) ELSE (ping) ELSE (sync_config) ELSE (wizard) From 09fe6f9bbe7fcf8a338d38d150dea4c8d8c7d10a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Fri, 2 Aug 2019 09:19:28 +0200 Subject: [PATCH 2/5] Add an explicit http command for getting capabilities Allow GSA to request the user's capabilities explicitly. --- gsad/src/gsad.c | 2 ++ gsad/src/gsad_gmp.c | 58 +++++++++++++++++++++++++++++++++++++++++++++ gsad/src/gsad_gmp.h | 4 ++++ 3 files changed, 64 insertions(+) diff --git a/gsad/src/gsad.c b/gsad/src/gsad.c index eba1c3a08a..d25db0f90a 100644 --- a/gsad/src/gsad.c +++ b/gsad/src/gsad.c @@ -359,6 +359,7 @@ init_validator () "|(get_alerts)" "|(get_asset)" "|(get_assets)" + "|(get_capabilities)" "|(get_config)" "|(get_config_family)" "|(get_config_nvt)" @@ -2058,6 +2059,7 @@ exec_gmp_get (http_connection_t *con, gsad_connection_info_t *con_info, ELSE (get_aggregate) ELSE (get_alert) ELSE (get_alerts) + ELSE (get_capabilities) ELSE (get_config) ELSE (get_configs) ELSE (get_config_family) diff --git a/gsad/src/gsad_gmp.c b/gsad/src/gsad_gmp.c index 76efb173ae..448b79c2cf 100644 --- a/gsad/src/gsad_gmp.c +++ b/gsad/src/gsad_gmp.c @@ -18468,6 +18468,64 @@ ping_gmp (gvm_connection_t *connection, credentials_t *credentials, "pong", NULL, NULL); } +char * +get_capabilities_gmp (gvm_connection_t *connection, credentials_t *credentials, + params_t *params, cmd_response_data_t *response_data) +{ + entity_t entity = NULL; + GString *xml; + + if (gvm_connection_sendf (connection, + "")) + { + cmd_response_data_set_status_code (response_data, + MHD_HTTP_INTERNAL_SERVER_ERROR); + return gsad_message ( + credentials, "Internal error", __FUNCTION__, __LINE__, + "An internal error occurred while getting the user credentials. " + "Diagnostics: Failure to send command to manager daemon.", + response_data); + } + + xml = g_string_new (""); + g_string_append (xml, ""); + + /* Read the response. */ + if (read_entity_and_string_c (connection, &entity, &xml)) + { + g_string_free (xml, TRUE); + cmd_response_data_set_status_code (response_data, + MHD_HTTP_INTERNAL_SERVER_ERROR); + return gsad_message ( + credentials, "Internal error", __FUNCTION__, __LINE__, + "An internal error occurred while getting the user credentials. " + "Diagnostics: Failure to receive response from manager daemon.", + response_data); + } + + if (gmp_success (entity) != 1) + { + gchar *message; + + set_http_status_from_entity (entity, response_data); + + message = + gsad_message (credentials, "Error", __FUNCTION__, __LINE__, + entity_attribute (entity, "status_text"), response_data); + + g_string_free (xml, TRUE); + free_entity (entity); + return message; + } + + /* Cleanup, and return transformed XML. */ + free_entity (entity); + + g_string_append (xml, ""); + return envelope_gmp (connection, credentials, params, + g_string_free (xml, FALSE), response_data); +} + /* Manager communication. */ /** diff --git a/gsad/src/gsad_gmp.h b/gsad/src/gsad_gmp.h index e002f26f4a..a08f9341b5 100644 --- a/gsad/src/gsad_gmp.h +++ b/gsad/src/gsad_gmp.h @@ -733,6 +733,10 @@ char * delete_ticket_gmp (gvm_connection_t *, credentials_t *, params_t *, cmd_response_data_t *); +char * +get_capabilities_gmp (gvm_connection_t *, credentials_t *, params_t *, + cmd_response_data_t *); + char * renew_session_gmp (gvm_connection_t *, credentials_t *, params_t *, cmd_response_data_t *); From 00f9eda96e117cf7857b707058c8ebe286f159e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Fri, 2 Aug 2019 10:38:23 +0200 Subject: [PATCH 3/5] Use new get_capabilities command to request user capabilities --- gsa/src/gmp/commands/users.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gsa/src/gmp/commands/users.js b/gsa/src/gmp/commands/users.js index ce3fa63622..2e2d68aac1 100644 --- a/gsa/src/gmp/commands/users.js +++ b/gsa/src/gmp/commands/users.js @@ -161,12 +161,12 @@ export class UserCommand extends EntityCommand { currentCapabilities(options = {}) { return this.httpGet( { - cmd: 'get_settings', + cmd: 'get_capabilities', }, options, ).then(response => { const {data} = response; - const {command: commands} = data.capabilities.help_response.schema; + const {command: commands} = data.get_capabilities.help_response.schema; const caps = map(commands, command => command.name); return response.setData(new Capabilities(caps)); }); From b4538655844e71e2e123a17a71ac2ab714ef76ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Fri, 2 Aug 2019 10:59:19 +0200 Subject: [PATCH 4/5] Drop the capabilities from the envelope The capabilities can now be requested by GSA in a separate command. --- gsad/src/gsad_gmp.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/gsad/src/gsad_gmp.c b/gsad/src/gsad_gmp.c index 448b79c2cf..75630d4e69 100644 --- a/gsad/src/gsad_gmp.c +++ b/gsad/src/gsad_gmp.c @@ -473,11 +473,7 @@ envelope_gmp (gvm_connection_t *connection, credentials_t *credentials, g_free (warning_elem); } - g_string_append_printf (string, - "%s" - "%s" - "", - user_get_capabilities (user), xml); + g_string_append_printf (string, "%s", xml); g_free (xml); cmd_response_data_set_content_type (response_data, GSAD_CONTENT_TYPE_APP_XML); From d1cd67040eb5b0b89f71315c7e97f1511ced102a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Fri, 2 Aug 2019 11:12:28 +0200 Subject: [PATCH 5/5] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02d45aed79..80c8ba56b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [8.0.2] - unreleased ### Added +- Added an explicit get_capabilities command to gsad [#1538](https://github.com/greenbone/gsa/pull/1538) - Highlight result diffs at delta reports [#1513](https://github.com/greenbone/gsa/pull/1513) - Added HorizontalSep component for horizontal lists [#1506](https://github.com/greenbone/gsa/pull/1506),