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

Get capabilities #1538

Merged
merged 6 commits into from
Aug 5, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions gsa/src/gmp/commands/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down
20 changes: 11 additions & 9 deletions gsad/src/gsad.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ init_validator ()
"|(get_alerts)"
"|(get_asset)"
"|(get_assets)"
"|(get_capabilities)"
"|(get_config)"
"|(get_config_family)"
"|(get_config_nvt)"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
64 changes: 59 additions & 5 deletions gsad/src/gsad_gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,7 @@ envelope_gmp (gvm_connection_t *connection, credentials_t *credentials,
g_free (warning_elem);
}

g_string_append_printf (string,
"<capabilities>%s</capabilities>"
"%s"
"</envelope>",
user_get_capabilities (user), xml);
g_string_append_printf (string, "%s</envelope>", xml);
g_free (xml);

cmd_response_data_set_content_type (response_data, GSAD_CONTENT_TYPE_APP_XML);
Expand Down Expand Up @@ -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,
"<help format=\"XML\" type=\"brief\"/>"))
{
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, "<get_capabilities>");

/* 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, "</get_capabilities>");
return envelope_gmp (connection, credentials, params,
g_string_free (xml, FALSE), response_data);
}

/* Manager communication. */

/**
Expand Down
4 changes: 4 additions & 0 deletions gsad/src/gsad_gmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down