Skip to content

Commit 183e11b

Browse files
ozgengreenbonebot
authored andcommitted
add: Add GSAD wrapper for GET_REPORT_VULNS
Add the GSAD-side GET_REPORT_VULNS request handling to send the command to gvmd and wrap the returned GMP response.
1 parent c149b12 commit 183e11b

4 files changed

Lines changed: 99 additions & 0 deletions

File tree

src/gsad.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ exec_gmp_get (gsad_http_connection_t *con, gsad_connection_info_t *con_info,
10301030
ELSE (get_report_operating_systems)
10311031
ELSE (get_report_ports)
10321032
ELSE (get_report_tls_certificates)
1033+
ELSE (get_report_vulns)
10331034
ELSE (get_reports)
10341035
ELSE (get_report_config)
10351036
ELSE (get_report_configs)

src/gsad_gmp.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10169,6 +10169,100 @@ get_report_tls_certificates_gmp (gvm_connection_t *connection,
1016910169
g_string_free (xml, FALSE), response_data);
1017010170
}
1017110171

10172+
/**
10173+
* @brief Get report vulnerabilities and return the result.
10174+
*
10175+
* @param[in] connection Connection to manager.
10176+
* @param[in] credentials Username and password for authentication.
10177+
* @param[in] params Request parameters.
10178+
* @param[out] response_data Extra data return for the HTTP response.
10179+
*
10180+
* @return Report vulnerabilities XML.
10181+
*/
10182+
char *
10183+
get_report_vulns_gmp (gvm_connection_t *connection,
10184+
gsad_credentials_t *credentials, params_t *params,
10185+
gsad_command_response_data_t *response_data)
10186+
{
10187+
GString *xml;
10188+
entity_t entity;
10189+
const char *report_id;
10190+
const char *filter;
10191+
const char *filter_id;
10192+
gboolean details, ignore_pagination;
10193+
int ret;
10194+
10195+
details = params_value_bool (params, "details");
10196+
ignore_pagination = params_value_bool (params, "ignore_pagination");
10197+
10198+
report_id = params_value (params, "report_id");
10199+
filter = params_value (params, "filter");
10200+
filter_id = params_value (params, "filter_id");
10201+
10202+
CHECK_VARIABLE_INVALID (report_id, "Get Report Vulnerabilities");
10203+
10204+
if (filter == NULL || filter_id)
10205+
filter = "";
10206+
10207+
ret = gvm_connection_sendf_xml (connection,
10208+
"<get_report_vulns"
10209+
" report_id=\"%s\""
10210+
" details=\"%d\""
10211+
" ignore_pagination=\"%d\""
10212+
" filter=\"%s\""
10213+
" filt_id=\"%s\"/>",
10214+
report_id, details, ignore_pagination, filter,
10215+
filter_id ? filter_id : FILT_ID_NONE);
10216+
10217+
if (ret == -1)
10218+
{
10219+
gsad_command_response_data_set_status_code (
10220+
response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
10221+
return gsad_http_create_gsad_message (
10222+
credentials,
10223+
"An internal error occurred while getting report vulnerabilities. "
10224+
"The report vulnerabilities could not be delivered. "
10225+
"Diagnostics: Failure to send command to manager daemon.",
10226+
response_data);
10227+
}
10228+
10229+
xml = g_string_new ("<get_report_vulns>");
10230+
10231+
entity = NULL;
10232+
if (read_entity_and_string_c (connection, &entity, &xml))
10233+
{
10234+
gsad_command_response_data_set_status_code (
10235+
response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
10236+
return gsad_http_create_gsad_message (
10237+
credentials,
10238+
"An internal error occurred while getting report vulnerabilities. "
10239+
"The report vulnerabilities could not be delivered. "
10240+
"Diagnostics: Failure to receive response from manager daemon.",
10241+
response_data);
10242+
}
10243+
10244+
if (gmp_success (entity) != 1)
10245+
{
10246+
gchar *message;
10247+
10248+
set_http_status_from_entity (entity, response_data);
10249+
10250+
message = gsad_http_create_gsad_message (
10251+
credentials, entity_attribute (entity, "status_text"), response_data);
10252+
10253+
g_string_free (xml, TRUE);
10254+
free_entity (entity);
10255+
return message;
10256+
}
10257+
10258+
free_entity (entity);
10259+
10260+
g_string_append (xml, "</get_report_vulns>");
10261+
10262+
return envelope_gmp (connection, credentials, params,
10263+
g_string_free (xml, FALSE), response_data);
10264+
}
10265+
1017210266
/**
1017310267
* @brief Run alert for a report.
1017410268
*

src/gsad_gmp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ char *
9797
get_report_tls_certificates_gmp (gvm_connection_t *, gsad_credentials_t *,
9898
params_t *, gsad_command_response_data_t *);
9999
char *
100+
get_report_vulns_gmp (gvm_connection_t *, gsad_credentials_t *, params_t *,
101+
gsad_command_response_data_t *);
102+
char *
100103
get_reports_gmp (gvm_connection_t *, gsad_credentials_t *, params_t *,
101104
gsad_command_response_data_t *);
102105

src/gsad_validator.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ gsad_init_validator ()
180180
"|(get_report_operating_systems)"
181181
"|(get_report_ports)"
182182
"|(get_report_tls_certificates)"
183+
"|(get_report_vulns)"
183184
"|(get_reports)"
184185
"|(get_report_config)"
185186
"|(get_report_configs)"

0 commit comments

Comments
 (0)