Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ set(
manage_resources.c
manage_report_configs.c
manage_report_formats.c
manage_report_hosts.c
manage_roles.c
manage_runtime_flags.c
manage_authentication.c
Expand Down Expand Up @@ -244,6 +245,7 @@ set(
manage_sql_report_configs.c
manage_sql_report_formats.c
manage_sql_resources.c
manage_sql_report_hosts.c
manage_sql_roles.c
manage_sql_settings.c
manage_sql_tags.c
Expand Down Expand Up @@ -287,6 +289,7 @@ set(
gmp_tls_certificates.c
gmp_oci_image_targets.c
gmp_integration_configs.c
gmp_report_hosts.c
)

if(ENABLE_AGENTS)
Expand Down
7 changes: 7 additions & 0 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
#include "gmp_port_lists.h"
#include "gmp_report_configs.h"
#include "gmp_report_formats.h"
#include "gmp_report_hosts.h"
#include "gmp_tickets.h"
#include "gmp_tls_certificates.h"
#include "manage.h"
Expand Down Expand Up @@ -4549,6 +4550,7 @@ typedef enum
CLIENT_GET_REPORTS,
CLIENT_GET_REPORT_CONFIGS,
CLIENT_GET_REPORT_FORMATS,
CLIENT_GET_REPORT_HOSTS,
CLIENT_GET_RESOURCE_NAMES,
CLIENT_GET_RESULTS,
CLIENT_GET_ROLES,
Expand Down Expand Up @@ -5876,6 +5878,9 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context,

set_client_state (CLIENT_GET_REPORT_FORMATS);
}

ELSE_GET_START (report_hosts, REPORT_HOSTS)

else if (strcasecmp ("GET_RESOURCE_NAMES", element_name) == 0)
{
const gchar* typebuf;
Expand Down Expand Up @@ -22111,6 +22116,8 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
handle_get_report_formats (gmp_parser, error);
break;

CASE_GET_END (REPORT_HOSTS, report_hosts);

case CLIENT_GET_RESOURCE_NAMES:
handle_get_resource_names (gmp_parser, error);
break;
Expand Down
3 changes: 3 additions & 0 deletions src/gmp_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ send_get_end_internal (const char *type, get_data_t *get, int get_counts,
g_free (filter);
if ((strcmp (type, "task") == 0)
|| (strcmp (type, "report") == 0)
|| (strcmp (type, "report_host") == 0)
|| (strcmp (type, "result") == 0)
|| (strcmp (type, "vuln") == 0))
{
Expand All @@ -618,6 +619,7 @@ send_get_end_internal (const char *type, get_data_t *get, int get_counts,

if ((strcmp (type, "task") == 0)
|| (strcmp (type, "report") == 0)
|| (strcmp (type, "report_host") == 0)
|| (strcmp (type, "result") == 0))
{
value = filter_term_value (new_filter, "apply_overrides");
Expand All @@ -638,6 +640,7 @@ send_get_end_internal (const char *type, get_data_t *get, int get_counts,
{
if ((strcmp (type, "task") == 0)
|| (strcmp (type, "report") == 0)
|| (strcmp (type, "report_host") == 0)
|| (strcmp (type, "result") == 0))
filter = manage_clean_filter("apply_overrides="
G_STRINGIFY (APPLY_OVERRIDES_DEFAULT)
Expand Down
205 changes: 205 additions & 0 deletions src/gmp_report_hosts.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/* Copyright (C) 2026 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

#include "gmp_report_hosts.h"

#include "gmp_get.h"
#include "manage.h"
#include "manage_acl.h"

#undef G_LOG_DOMAIN
/**
* @brief GLib log domain.
*/
#define G_LOG_DOMAIN "md gmp"

/**
* @brief Command data for the get_report_hosts command.
*/
typedef struct
{
get_data_t get; ///< Get args with host/result filtering.
char *report_id; ///< ID of single report to get.
int lean; ///< Boolean. Whether to return lean host data.
} get_report_hosts_data_t;

/**
* @brief Parser callback data.
*
* This is initially 0 because it's a global variable.
*/
static get_report_hosts_data_t get_report_hosts_data;


/**
* @brief Reset the internal state of the <get_report_hosts> command.
*/
static void
get_report_hosts_reset ()
{
get_data_reset (&get_report_hosts_data.get);
g_free (get_report_hosts_data.report_id);
memset (&get_report_hosts_data, 0, sizeof (get_report_hosts_data));
}

/**
* @brief Initialize the <get_report_hosts> GMP command by parsing attributes.
*
* @param[in] attribute_names Null-terminated array of attribute names.
* @param[in] attribute_values Null-terminated array of corresponding attribute values.
*/
void
get_report_hosts_start (const gchar **attribute_names,
const gchar **attribute_values)
{
const gchar *attribute;

get_data_parse_attributes (&get_report_hosts_data.get,
"report_host",
attribute_names,
attribute_values);

if (find_attribute (attribute_names, attribute_values,
"report_id", &attribute))
{
get_report_hosts_data.report_id = g_strdup (attribute);

get_data_set_extra (&get_report_hosts_data.get, "report_id",
g_strdup (attribute));
}
if (find_attribute (attribute_names, attribute_values,
"lean", &attribute))
get_report_hosts_data.lean = strcmp (attribute, "0");
else
get_report_hosts_data.lean = 0;
}

/**
* @brief Execute the <get_report_hosts> GMP command.
*
* @param[in] gmp_parser Pointer to the GMP parser handling the current session.
* @param[in] error Location to store error information, if any occurs.
*/
void
get_report_hosts_run (gmp_parser_t *gmp_parser, GError **error)
{
report_t report;
task_t task;
gchar *usage_type;
gboolean is_container_scanning_report = FALSE;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate init

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed: 2c9c7f4

int ret, filtered, count;

count = 0;
usage_type = NULL;
is_container_scanning_report = FALSE;

if (get_report_hosts_data.report_id == NULL)
{
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("get_report_hosts",
"Missing report_id attribute"));
get_report_hosts_reset ();
return;
}

ret = init_get ("get_report_hosts",
&get_report_hosts_data.get,
"Report Hosts",
NULL);
if (ret)
{
switch (ret)
{
case 99:
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("get_report_hosts",
"Permission denied"));
break;
default:
internal_error_send_to_client (error);
get_report_hosts_reset ();
return;
}
get_report_hosts_reset ();
return;
}

if (find_report_with_permission (get_report_hosts_data.report_id,
&report,
"get_reports"))
{
internal_error_send_to_client (error);
get_report_hosts_reset ();
return;
}

if (report == 0)
{
if (send_find_error_to_client ("get_report_hosts",
"report",
get_report_hosts_data.report_id,
gmp_parser))
error_send_to_client (error);
get_report_hosts_reset ();
return;
}

if (report_task (report, &task))
{
internal_error_send_to_client (error);
get_report_hosts_reset ();
return;
}

task_usage_type (task, &usage_type);
if (usage_type == NULL)
usage_type = g_strdup ("");

#if ENABLE_CONTAINER_SCANNING
oci_image_target_t oci_image_target = task_oci_image_target (task);
if (oci_image_target)
{
is_container_scanning_report = TRUE;
}
#endif

SEND_GET_START ("report_host");

ret = manage_send_report_hosts (
report,
&get_report_hosts_data.get,
usage_type,
is_container_scanning_report,
get_report_hosts_data.lean,
gmp_parser);

g_free (usage_type);

if (ret)
{
switch (ret)
{
case 2:
if (send_find_error_to_client ("get_report_hosts",
"filter",
get_report_hosts_data.get.filt_id,
gmp_parser))
error_send_to_client (error);
break;
default:
internal_error_send_to_client (error);
break;
}
get_report_hosts_reset ();
return;
}

filtered = get_report_hosts_data.get.id
? 1
: report_host_count (report);
SEND_GET_END ("report_host", &get_report_hosts_data.get, count, filtered);

get_report_hosts_reset ();
}
23 changes: 23 additions & 0 deletions src/gmp_report_hosts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright (C) 2026 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

#ifndef _GVM_GMP_REPORT_HOSTS_H
#define _GVM_GMP_REPORT_HOSTS_H

#include "gmp_base.h"

#include <gvm/base/array.h>
#include <gvm/util/xmlutils.h>

/* GET_REPORT_HOSTS. */

void
get_report_hosts_start (const gchar **,
const gchar **);

void
get_report_hosts_run (gmp_parser_t *gmp_parser, GError **error);

#endif //_GVM_GMP_REPORT_HOSTS_H
1 change: 1 addition & 0 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "manage_settings.h"
#include "manage_oci_image_targets.h"
#include "manage_http_scanner.h"
#include "manage_report_hosts.h"
#include "manage_runtime_flags.h"
#include "manage_sql.h"
#include "manage_sql_assets.h"
Expand Down
23 changes: 1 addition & 22 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "manage_events.h"
#include "manage_get.h"
#include "manage_integration_configs.h"
#include "manage_report_hosts.h"
#include "manage_tasks.h"
#include "sql.h"
#include "utils.h"
Expand Down Expand Up @@ -1446,28 +1447,6 @@ result_iterator_delta_hostname (iterator_t*);
int
cleanup_result_nvts ();

void
init_report_host_iterator (iterator_t*, report_t, const char *, report_host_t);

void
init_report_host_iterator_hostname (iterator_t*, report_t, const char *,
const char *);

const char*
host_iterator_host (iterator_t*);

const char*
host_iterator_start_time (iterator_t*);

const char*
host_iterator_end_time (iterator_t*);

int
host_iterator_current_port (iterator_t*);

int
host_iterator_max_port (iterator_t*);

int
collate_message_type (void* data, int, const void*, int, const void*);

Expand Down
1 change: 1 addition & 0 deletions src/manage_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ command_t gmp_commands[]
{"GET_REPORTS", "Get all reports."},
{"GET_REPORT_CONFIGS", "Get all report configs."},
{"GET_REPORT_FORMATS", "Get all report formats."},
{"GET_REPORT_HOSTS", "Get all report hosts for specific report."},
{"GET_RESULTS", "Get results."},
{"GET_ROLES", "Get all roles."},
{"GET_SCANNERS", "Get all scanners."},
Expand Down
Loading
Loading