-
Notifications
You must be signed in to change notification settings - Fork 176
Add/get report hosts command #2861
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
Open
ozgen
wants to merge
14
commits into
main
Choose a base branch
from
add/get-report-hosts-command
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
83d24a8
change: extract report hosts logic into dedicated management files
ozgen 68cbd16
Add management-layer support for report hosts responses
ozgen eb14c63
Add: add get_report_hosts GMP command
ozgen 2f4f5d5
docs: add GMP documentation for get_report_hosts
ozgen 0407b08
fix: initialize host ports table for report host output in manage_sen…
ozgen d9d9049
add missing log context in gmp_report_hosts.c
ozgen 55d8c58
Simplify manage_send_report_hosts function arguments
ozgen 45d7914
fix formatting and sort C source files alphabetically in CMakeLists.txt
ozgen 9e12480
Merge branch 'main' into add/get-report-hosts-command
ozgen 36fa26d
simplify report host XML flow and container flag handling
ozgen f5c2980
Update manage_report_hosts.c
ozgen 2c9c7f4
change: share filter setup and clean up temp dir handling
ozgen d3dc449
docs: add lean option and remove unimplemented GET_REPORT_HOSTS options
ozgen 51c7b6c
remove unused host summary buffer allocation
ozgen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| 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 (); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* 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 *, GError **); | ||
|
|
||
| #endif //_GVM_GMP_REPORT_HOSTS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate init
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed: 2c9c7f4