diff --git a/CHANGELOG.md b/CHANGELOG.md index 993276f951..d754e1b71a 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), 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)); }); diff --git a/gsad/src/gsad.c b/gsad/src/gsad.c index 89b6678054..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)" @@ -1920,15 +1921,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 +2059,14 @@ 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) + ELSE (get_config_nvt) ELSE (get_credential) ELSE (get_credentials) + ELSE (get_feeds) ELSE (get_filter) ELSE (get_filters) ELSE (get_group) @@ -2095,17 +2099,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) diff --git a/gsad/src/gsad_gmp.c b/gsad/src/gsad_gmp.c index 76efb173ae..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); @@ -18468,6 +18464,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 *);