From 20ca230a173daf10c0ede7df7fb76ef39535948f Mon Sep 17 00:00:00 2001 From: ozgen Date: Wed, 3 Dec 2025 14:45:04 +0100 Subject: [PATCH 1/6] Change: Refactor GMP errors for import task and extend filter_clause --- src/gmp.c | 8 ++++---- src/manage_sql_filters.c | 26 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index db1d42baa1..2212746ed6 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -23781,7 +23781,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context, case -5: SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX ("create_report", - "TASK must be a container")); + "TASK must be a import task")); log_event_fail ("report", "Report", NULL, "created"); break; case -6: @@ -24987,7 +24987,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context, && !is_agent_task && !is_container_scanning_task) { - /* Container task. */ + /* Import task. */ set_task_target (create_task_data->task, 0); set_task_usage_type (create_task_data->task, @@ -27997,7 +27997,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context, case 17: SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX ("modify_task", - "For container tasks only name, comment" + "For import tasks only name, comment" " and observers can be modified")); log_event_fail ("task", "Task", modify_task_data->task_id, @@ -28796,7 +28796,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context, "started"); break; case -2: - /* Task lacks target. This is true for container + /* Task lacks target. This is true for Import * tasks. */ SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX ("start_task", diff --git a/src/manage_sql_filters.c b/src/manage_sql_filters.c index 4cebc4c5f7..5eecfe880c 100644 --- a/src/manage_sql_filters.c +++ b/src/manage_sql_filters.c @@ -1188,7 +1188,13 @@ filter_clause (const char* type, const char* filter, g_string_append_printf (order, " ORDER BY" - " (CASE WHEN (SELECT target = 0 FROM tasks" + " (CASE WHEN (SELECT " + " ( " + " target = 0 " + " and COALESCE( agent_group, 0) = 0 " + " and COALESCE( oci_image_target, 0) = 0" + " ) " + " FROM tasks" " WHERE tasks.id = task)" " THEN 'Container'" " ELSE run_status_name (scan_run_status)" @@ -1204,7 +1210,10 @@ filter_clause (const char* type, const char* filter, g_string_append_printf (order, " ORDER BY" - " (CASE WHEN target = 0" + " (CASE WHEN ( target = 0 " + " and COALESCE( agent_group, 0) = 0 " + " and COALESCE( oci_image_target, 0) = 0" + " ) " " THEN 'Container'" " ELSE run_status_name (run_status)" " || (SELECT CAST (temp / 100 AS text)" @@ -1384,7 +1393,13 @@ filter_clause (const char* type, const char* filter, g_string_append_printf (order, " ORDER BY" - " (CASE WHEN (SELECT target = 0 FROM tasks" + " (CASE WHEN (SELECT " + " ( " + " target = 0 " + " and COALESCE( agent_group, 0) = 0 " + " and COALESCE( oci_image_target, 0) = 0" + " ) " + " FROM tasks" " WHERE tasks.id = task)" " THEN 'Container'" " ELSE run_status_name (scan_run_status)" @@ -1400,7 +1415,10 @@ filter_clause (const char* type, const char* filter, g_string_append_printf (order, " ORDER BY" - " (CASE WHEN target = 0" + " (CASE WHEN ( target = 0 " + " and COALESCE( agent_group, 0) = 0 " + " and COALESCE( oci_image_target, 0) = 0" + " ) " " THEN 'Container'" " ELSE run_status_name (run_status)" " || (SELECT CAST (temp / 100 AS text)" From 1495314b6f6916a5e68f7b007f6e4b4696c09715 Mon Sep 17 00:00:00 2001 From: ozgen Date: Thu, 4 Dec 2025 12:06:42 +0100 Subject: [PATCH 2/6] Applying review comments --- src/gmp.c | 4 ++-- src/manage_pg.c | 2 +- src/manage_sql.c | 6 +++--- src/manage_sql_filters.c | 8 ++++---- src/schema_formats/XML/GMP.xml.in | 14 +++++++------- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index 2212746ed6..f53160a3ab 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -759,7 +759,7 @@ typedef struct array_t *results; ///< All results. char *scan_end; ///< End time for a scan. char *scan_start; ///< Start time for a scan. - char *task_id; ///< ID of container task. + char *task_id; ///< ID of import task. char *type; ///< Type of report. int wrapper; ///< Whether there was a wrapper REPORT. } create_report_data_t; @@ -19859,7 +19859,7 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error) } else { - /* Container tasks have no associated scanner. */ + /* Import tasks have no associated scanner. */ task_scanner_uuid = g_strdup (""); task_scanner_name = g_strdup (""); task_scanner_type = 0; diff --git a/src/manage_pg.c b/src/manage_pg.c index 95695a3b4e..ea723e25ff 100644 --- a/src/manage_pg.c +++ b/src/manage_pg.c @@ -1513,7 +1513,7 @@ manage_create_sql_functions () /* Get trend only for authenticated users. */ " WHEN gvmd_user () = 0" " THEN RETURN ''::text;" - /* Skip running and container tasks. */ + /* Skip running and import tasks. */ " WHEN (SELECT run_status = %u OR target = 0" " FROM tasks WHERE id = $1)" " THEN RETURN ''::text;" diff --git a/src/manage_sql.c b/src/manage_sql.c index cef0e09b19..6dbd231b77 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -7828,7 +7828,7 @@ task_severity_double (task_t task, int overrides, int min_qod, int offset) report_t report; if (current_credentials.uuid == NULL - || task_target (task) == 0 /* Container task. */) + || task_target (task) == 0 /* import task. */) return SEVERITY_MISSING; report = sql_int64_0 ("SELECT id FROM reports" @@ -9927,7 +9927,7 @@ process_report_import (report_t report) * @brief Create a report from an array of results. * * @param[in] results Array of create_report_result_t pointers. - * @param[in] task_id UUID of container task, or NULL to create new one. + * @param[in] task_id UUID of import task, or NULL to create new one. * @param[in] in_assets Whether to create assets from the report. * @param[in] scan_start Scan start time text. * @param[in] scan_end Scan end time text. @@ -20820,7 +20820,7 @@ DEF_ACCESS (task_file_iterator_content, 1); * alterable state, 10 failed to find group, 11 failed to find schedule, * 12 failed to find target, 13 invalid auto_delete value, 14 auto * delete count out of range, 15 config and scanner types mismatch, - * 16 status must be new to edit target, 17 for container tasks only + * 16 status must be new to edit target, 17 for import tasks only * certain fields may be edited, 18 failed to find agent group, 19 failed to find OCI image target, -1 error. */ diff --git a/src/manage_sql_filters.c b/src/manage_sql_filters.c index 5eecfe880c..c90f7b21f4 100644 --- a/src/manage_sql_filters.c +++ b/src/manage_sql_filters.c @@ -1196,7 +1196,7 @@ filter_clause (const char* type, const char* filter, " ) " " FROM tasks" " WHERE tasks.id = task)" - " THEN 'Container'" + " THEN '0'" " ELSE run_status_name (scan_run_status)" " || (SELECT CAST (temp / 100 AS text)" " || CAST (temp / 10 AS text)" @@ -1214,7 +1214,7 @@ filter_clause (const char* type, const char* filter, " and COALESCE( agent_group, 0) = 0 " " and COALESCE( oci_image_target, 0) = 0" " ) " - " THEN 'Container'" + " THEN '0'" " ELSE run_status_name (run_status)" " || (SELECT CAST (temp / 100 AS text)" " || CAST (temp / 10 AS text)" @@ -1401,7 +1401,7 @@ filter_clause (const char* type, const char* filter, " ) " " FROM tasks" " WHERE tasks.id = task)" - " THEN 'Container'" + " THEN '0'" " ELSE run_status_name (scan_run_status)" " || (SELECT CAST (temp / 100 AS text)" " || CAST (temp / 10 AS text)" @@ -1419,7 +1419,7 @@ filter_clause (const char* type, const char* filter, " and COALESCE( agent_group, 0) = 0 " " and COALESCE( oci_image_target, 0) = 0" " ) " - " THEN 'Container'" + " THEN '0'" " ELSE run_status_name (run_status)" " || (SELECT CAST (temp / 100 AS text)" " || CAST (temp / 10 AS text)" diff --git a/src/schema_formats/XML/GMP.xml.in b/src/schema_formats/XML/GMP.xml.in index f6059099dd..4e179e44fe 100644 --- a/src/schema_formats/XML/GMP.xml.in +++ b/src/schema_formats/XML/GMP.xml.in @@ -6401,13 +6401,13 @@ END:VCALENDAR

When given a target with an id of 0, the command creates a - "container" task. This kind of task can not be run, but it + "import" task. This kind of task can not be run, but it is possible to import reports into the task. Importing is done using the create_report command. The report being imported must be in the XML format.

- When creating a container task, the elements config, hosts_ordering, + When creating a import task, the elements config, hosts_ordering, scanner, alert, schedule, schedule_periods, observers and preferences are ignored.

@@ -6644,7 +6644,7 @@ END:VCALENDAR - Create a container task, for importing reports + Create an import task, for importing reports Container Example @@ -25898,9 +25898,9 @@ END:VCALENDAR that the manager applied when selecting the tasks.

- A task may be a "container" task. This means the task may not be + A task may be a "import" task. This means the task may not be run, but reports may be uploaded to the task with the command - create_report. Container tasks are identified by having an empty + create_report. Import tasks are identified by having an empty id attribute in the target element.

@@ -26442,7 +26442,7 @@ END:VCALENDAR id uuid 1 - ID of target. Empty for container tasks + ID of target. Empty for import tasks name permissions @@ -27185,7 +27185,7 @@ END:VCALENDAR
- Get a single container task + Get a single import task From 34ff265d292960eb09ce23736405bd2fbe03bd62 Mon Sep 17 00:00:00 2001 From: ozgen mehmet Date: Thu, 4 Dec 2025 12:59:49 +0100 Subject: [PATCH 3/6] Update src/schema_formats/XML/GMP.xml.in Co-authored-by: Matt Mundell <32057441+mattmundell@users.noreply.github.com> --- src/schema_formats/XML/GMP.xml.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/schema_formats/XML/GMP.xml.in b/src/schema_formats/XML/GMP.xml.in index 4e179e44fe..52f0ff36d1 100644 --- a/src/schema_formats/XML/GMP.xml.in +++ b/src/schema_formats/XML/GMP.xml.in @@ -6407,7 +6407,7 @@ END:VCALENDAR imported must be in the XML format.

- When creating a import task, the elements config, hosts_ordering, + When creating an import task, the elements config, hosts_ordering, scanner, alert, schedule, schedule_periods, observers and preferences are ignored.

From d68abcf27380d4209179778dfda51c5ef3ff7581 Mon Sep 17 00:00:00 2001 From: ozgen mehmet Date: Thu, 4 Dec 2025 12:59:57 +0100 Subject: [PATCH 4/6] Update src/schema_formats/XML/GMP.xml.in Co-authored-by: Matt Mundell <32057441+mattmundell@users.noreply.github.com> --- src/gmp.c | 2 +- src/manage_sql.c | 2 +- src/schema_formats/XML/GMP.xml.in | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index f53160a3ab..88d577699a 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -23781,7 +23781,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context, case -5: SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX ("create_report", - "TASK must be a import task")); + "TASK must be an import task")); log_event_fail ("report", "Report", NULL, "created"); break; case -6: diff --git a/src/manage_sql.c b/src/manage_sql.c index 6dbd231b77..ce76a1334b 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -9940,7 +9940,7 @@ process_report_import (report_t report) * * @return 0 success, 99 permission denied, -1 error, -2 failed to generate ID, * -3 task_id is NULL, -4 failed to find task, -5 task must be - * container, -6 permission to create assets denied. + * import task, -6 permission to create assets denied. */ int create_report (array_t *results, const char *task_id, const char *in_assets, diff --git a/src/schema_formats/XML/GMP.xml.in b/src/schema_formats/XML/GMP.xml.in index 52f0ff36d1..6f90f6e482 100644 --- a/src/schema_formats/XML/GMP.xml.in +++ b/src/schema_formats/XML/GMP.xml.in @@ -6400,7 +6400,7 @@ END:VCALENDAR The client uses the create_task command to create a new task.

- When given a target with an id of 0, the command creates a + When given a target with an id of 0, the command creates an "import" task. This kind of task can not be run, but it is possible to import reports into the task. Importing is done using the create_report command. The report being @@ -25898,7 +25898,7 @@ END:VCALENDAR that the manager applied when selecting the tasks.

- A task may be a "import" task. This means the task may not be + A task may be an "import" task. This means the task may not be run, but reports may be uploaded to the task with the command create_report. Import tasks are identified by having an empty id attribute in the target element. From b7400acad6a57188d37a38218efb596c1dbc159a Mon Sep 17 00:00:00 2001 From: ozgen mehmet Date: Thu, 4 Dec 2025 13:41:02 +0100 Subject: [PATCH 5/6] Update src/schema_formats/XML/GMP.xml.in Co-authored-by: Matt Mundell <32057441+mattmundell@users.noreply.github.com> --- src/schema_formats/XML/GMP.xml.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/schema_formats/XML/GMP.xml.in b/src/schema_formats/XML/GMP.xml.in index 6f90f6e482..335bd4a84d 100644 --- a/src/schema_formats/XML/GMP.xml.in +++ b/src/schema_formats/XML/GMP.xml.in @@ -6647,7 +6647,7 @@ END:VCALENDAR

Create an import task, for importing reports - Container Example + Import Example This task provides for importing reports From c0fbfff3e928e720e9b0ebff389728bcc46c4986 Mon Sep 17 00:00:00 2001 From: ozgen mehmet Date: Thu, 4 Dec 2025 12:59:57 +0100 Subject: [PATCH 6/6] Update src/schema_formats/XML/GMP.xml.in Co-authored-by: Matt Mundell <32057441+mattmundell@users.noreply.github.com> --- src/gmp.c | 2 +- src/manage_sql.c | 2 +- src/schema_formats/XML/GMP.xml.in | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index f53160a3ab..88d577699a 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -23781,7 +23781,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context, case -5: SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX ("create_report", - "TASK must be a import task")); + "TASK must be an import task")); log_event_fail ("report", "Report", NULL, "created"); break; case -6: diff --git a/src/manage_sql.c b/src/manage_sql.c index 6dbd231b77..ce76a1334b 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -9940,7 +9940,7 @@ process_report_import (report_t report) * * @return 0 success, 99 permission denied, -1 error, -2 failed to generate ID, * -3 task_id is NULL, -4 failed to find task, -5 task must be - * container, -6 permission to create assets denied. + * import task, -6 permission to create assets denied. */ int create_report (array_t *results, const char *task_id, const char *in_assets, diff --git a/src/schema_formats/XML/GMP.xml.in b/src/schema_formats/XML/GMP.xml.in index 52f0ff36d1..e52672906b 100644 --- a/src/schema_formats/XML/GMP.xml.in +++ b/src/schema_formats/XML/GMP.xml.in @@ -6400,7 +6400,7 @@ END:VCALENDAR The client uses the create_task command to create a new task.

- When given a target with an id of 0, the command creates a + When given a target with an id of 0, the command creates an "import" task. This kind of task can not be run, but it is possible to import reports into the task. Importing is done using the create_report command. The report being @@ -25898,7 +25898,7 @@ END:VCALENDAR that the manager applied when selecting the tasks.

- A task may be a "import" task. This means the task may not be + A task may be an "import" task. This means the task may not be run, but reports may be uploaded to the task with the command create_report. Import tasks are identified by having an empty id attribute in the target element. @@ -27197,7 +27197,7 @@ END:VCALENDAR m - Container Example + Import Example This task provides for uploading reports 2019-08-13T12:28:43+02:00