Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
c46b4bb
added initial migration document for `target_type` in tasks table
rdttmr Jun 29, 2026
edb3467
sorted code migrations into categories
rdttmr Jun 30, 2026
63282c4
* added task_update_[delete|restore]_target ()
rdttmr Jun 30, 2026
3cc6fbd
cleaned up Web application code migration section
rdttmr Jun 30, 2026
1124daa
formatting
rdttmr Jun 30, 2026
1f248b1
fixed DROP COLUMN migration step
rdttmr Jun 30, 2026
3b0c03e
formatting
rdttmr Jul 1, 2026
2edad7e
added data migration from 281 => 282
rdttmr Jul 3, 2026
a88da34
use enum instead of define for tasks_target_type
rdttmr Jul 3, 2026
06c87b7
add target_type and remove *_target columns from create_tables() in t…
rdttmr Jul 6, 2026
cfb7c77
migrated agent_group/oci_image/web_application target common function…
rdttmr Jul 6, 2026
1eebe8c
fixed function calls: too few arguments; due to migration
rdttmr Jul 6, 2026
877a551
added `target_type` to propopsed update functions
rdttmr Jul 6, 2026
ec725a0
removed "drop column" part of database migration to version 281
rdttmr Jul 6, 2026
274374b
updated sql filters to check `target_type` for import task
rdttmr Jul 7, 2026
df1d49f
updated parameter order in task_update_delete_target() function
rdttmr Jul 7, 2026
45470be
generalized task_target_in_use() functionality
rdttmr Jul 7, 2026
5fcaa01
adapted oci_image_targets functionality to new column `target_types` …
rdttmr Jul 7, 2026
80fe73a
updated migration document
rdttmr Jul 8, 2026
7dbe4c6
migrated web_application_target to new target_type column
rdttmr Jul 8, 2026
dc6b160
migrated agent_group to new target_type column
rdttmr Jul 8, 2026
8af7226
removed target_type from some functions again, since task_t was used …
rdttmr Jul 8, 2026
f82c748
updated DROP COLUMN statements in migration document
rdttmr Jul 10, 2026
e14beb7
migrated <get_tasks/> GMP command
rdttmr Jul 13, 2026
ac2d043
added missing "," in sql command
rdttmr Jul 13, 2026
67d2891
migrated target_in_use and trash_target_in_use functions to target_type
rdttmr Jul 13, 2026
7cea9cb
fixed some agent group queries to adapt target_type
rdttmr Jul 14, 2026
07fccdb
Accommodating for `target_type` when using `target`
rdttmr Jul 14, 2026
73108cc
fix: Introduce target type for better internal handling of different …
rdttmr Jul 29, 2026
00750db
removed migration document
rdttmr Aug 5, 2026
4a20cc7
fix: bump database version
rdttmr Aug 14, 2026
1ed8942
bump database version on migration correctly
rdttmr Aug 14, 2026
b1d2762
fix comment
rdttmr Aug 14, 2026
410e997
aligned checks for db version 282
rdttmr Aug 14, 2026
6766981
fixed wrong check for import task
rdttmr Aug 14, 2026
a249d6d
utilize new helper functions for target_type_regular
rdttmr Aug 14, 2026
e2e1c3a
g_error() => g_critical(), since g_error aborts
rdttmr Aug 14, 2026
d94b52e
update migration to set target_type column NOT NULL and add default v…
rdttmr Aug 14, 2026
70feb5f
fixed query still referencing the now dropped column `agent_group`
rdttmr Aug 14, 2026
3e222b1
fill_network_target_reference() now has an early exit, if task type i…
rdttmr Aug 14, 2026
d61688d
unify set_task_target() and set_task_target_and_location()
rdttmr Aug 14, 2026
34169a5
Migration to 282 now prints the tasks with multiple targets specified…
rdttmr Aug 14, 2026
e072fb4
fixed count not incrementing
rdttmr Aug 14, 2026
3de3fc2
cleanup iterator properly
rdttmr Aug 14, 2026
cafb443
CREATE TABLE tasks now complies with the state after migration to 282
rdttmr Aug 14, 2026
30fbe46
task_target_type() now returns `TASKS_TARGET_TYPE_UNDEFINED` in case …
rdttmr Aug 14, 2026
108bd17
modify_task() now throws an error if multiple target fields are set (…
rdttmr Aug 14, 2026
6b09dc8
added missing NULL terminator in prepared statement call
rdttmr Aug 14, 2026
040fc9c
target_type: keep new instances in sync with migrated ones
rdttmr Aug 14, 2026
ef0b9f0
fixed db version in comments
rdttmr Aug 14, 2026
b61f0bb
fixed condition in create_report(), since target_type was introduced
rdttmr Aug 17, 2026
7a9ebd3
handle_get_tasks(): target_in_trash is now correctly handled based on…
rdttmr Aug 17, 2026
a6faa47
handle_get_tasks(): fixed dead if branch, utilizing new target_type
rdttmr Aug 17, 2026
d134da0
print_report_xml_start(): utilizing new target_type for more clarity …
rdttmr Aug 17, 2026
c5f1c76
migrated tasks.target column to NOT NULL DEFAULT 0
rdttmr Aug 17, 2026
bc0b0c9
interrupt task when no regular target is available
rdttmr Aug 17, 2026
0bfeaf2
removed `target = 0` checks, when `target_type` is available
rdttmr Aug 17, 2026
0d4331a
handle_get_tasks(): reduced SQL queries, since `target` is now polymo…
rdttmr Aug 17, 2026
5963b09
gmp `CREATE_TASK` now checks for multiple target types provided
rdttmr Aug 17, 2026
341f8a0
create index on target_type, target and target_location
rdttmr Aug 17, 2026
245ae04
get_report_task_progress() is now target_type aware
rdttmr Aug 17, 2026
9b70677
added some comments to sql numeric literals
rdttmr Aug 17, 2026
e78284c
renamed `tasks_target_type_t` => `task_target_type_t`
rdttmr Aug 19, 2026
2a5dede
added explanatory comments for db version checks
rdttmr Aug 19, 2026
d831ae8
added migration path for tasks with multiple target columns set
rdttmr Aug 20, 2026
b9c7af6
fixed migration logic + formatting
rdttmr Aug 20, 2026
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ include(CPack)

## Variables

set(GVMD_DATABASE_VERSION 281)
set(GVMD_DATABASE_VERSION 282)

set(GVMD_SCAP_DATABASE_VERSION 22)

Expand Down
172 changes: 109 additions & 63 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,17 @@
*/
#define G_LOG_DOMAIN "md gmp"




/* Static headers. */

/** @todo Exported for manage_sql.c. */
void
buffer_results_xml (GString *, iterator_t *, task_t, int, int, int, int, int,
int, int, const char *, iterator_t *, int, int, int, int);




/* Helper functions. */

/**
Expand Down Expand Up @@ -394,7 +396,8 @@ check_public_key (const char *key_str)
return ret;
}




/* GMP parser. */

static int
Expand Down Expand Up @@ -457,7 +460,8 @@ command_disabled (gmp_parser_t *gmp_parser, const gchar *name)
return 0;
}




/* Command data passed between parser callbacks. */

/**
Expand Down Expand Up @@ -3635,7 +3639,8 @@ command_data_init (command_data_t *data)
memset (data, 0, sizeof (command_data_t));
}




/* Global variables. */

/**
Expand Down Expand Up @@ -4248,7 +4253,8 @@ xml_context = NULL;
*/
static GMarkupParser xml_parser;




/* Client state. */

/**
Expand Down Expand Up @@ -4904,7 +4910,8 @@ set_client_state (client_state_t state)
g_debug (" client state set: %i", client_state);
}




/* XML parser handlers. */

/**
Expand Down Expand Up @@ -20006,6 +20013,7 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error)
task_t index;
gchar *progress_xml;
target_t target;
task_target_type_t target_type;
scanner_t scanner;
const char *first_report_id, *last_report_id;
char *config_name, *config_uuid;
Expand All @@ -20021,6 +20029,7 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error)
report_t running_report;
char *owner, *observers;
int target_in_trash, scanner_in_trash;
int target_location_trash;
int holes = 0, infos = 0, logs = 0, warnings = 0;
int holes_2 = 0, infos_2 = 0, warnings_2 = 0;
int criticals = 0, criticals_2 = 0;
Expand Down Expand Up @@ -20051,6 +20060,7 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error)

index = get_iterator_resource (&tasks);
target = task_target (index);
target_type = task_target_type (index);

task_schedule_xml = get_task_schedule_xml (index);

Expand All @@ -20069,10 +20079,17 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error)
else
{
SEND_GET_COMMON (task, &get_tasks_data->get, &tasks);
target_in_trash = task_target_in_trash (index);
if (target && (target == 0)
&& (task_iterator_run_status (&tasks)
== TASK_STATUS_RUNNING))

target_location_trash
= (target_type == TASK_TARGET_TYPE_IMPORT_TASK)
? 0
: task_target_in_trash (index);

target_in_trash = (target_type == TASK_TARGET_TYPE_REGULAR)
? target_location_trash
: 0;
if (target_type == TASK_TARGET_TYPE_IMPORT_TASK
&& (task_iterator_run_status (&tasks) == TASK_STATUS_RUNNING))
{
progress_xml = g_strdup_printf
("%i",
Expand Down Expand Up @@ -20314,24 +20331,33 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error)
config_name = task_config_name (index);
config_uuid = task_config_uuid (index);
target_available = 1;
if (target_in_trash)
{
task_target_uuid = trash_target_uuid (target);
task_target_name = trash_target_name (target);
target_available = trash_target_readable (target);
}
else if (target)

if (target_type == TASK_TARGET_TYPE_REGULAR)
{
target_t found;
task_target_uuid = target_uuid (target);
task_target_name = target_name (target);
if (find_target_with_permission (task_target_uuid,
&found,
"get_targets"))
g_error ("%s: GET_TASKS: error finding task target,"
" aborting",
__func__);
target_available = (found > 0);
if (target_in_trash)
{
task_target_uuid = trash_target_uuid (target);
task_target_name = trash_target_name (target);
target_available = trash_target_readable (target);
}
else if (target)
{
target_t found;
task_target_uuid = target_uuid (target);
task_target_name = target_name (target);
if (find_target_with_permission (task_target_uuid,
&found,
"get_targets"))
g_error ("%s: GET_TASKS: error finding task target,"
" aborting",
__func__);
target_available = (found > 0);
}
else
{
task_target_uuid = NULL;
task_target_name = NULL;
}
}
else
{
Expand All @@ -20340,17 +20366,14 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error)
}

#if ENABLE_CONTAINER_SCANNING
oci_image_target_t oci_image_target;
int oci_image_target_in_trash, oci_image_target_available;
char *task_oci_image_target_uuid, *task_oci_image_target_name;
gchar *task_oci_image_target_name_escaped;

oci_image_target = task_oci_image_target (index);
oci_image_target_in_trash = task_oci_image_target_in_trash (index);

if (oci_image_target || oci_image_target_in_trash)
if (target_type == TASK_TARGET_TYPE_OCI_IMAGE)
{
oci_image_target_available = 1;
oci_image_target_t oci_image_target = target;
int oci_image_target_in_trash = target_location_trash;
int oci_image_target_available = 1;
char *task_oci_image_target_uuid, *task_oci_image_target_name;
gchar *task_oci_image_target_name_escaped;

if (oci_image_target_in_trash)
{
task_oci_image_target_uuid
Expand Down Expand Up @@ -20403,15 +20426,14 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error)
}
#endif
#if ENABLE_AGENTS
agent_group_t agent_group = 0;
int group_readable = 0;
char *task_agent_group_uuid = NULL;
char *task_agent_group_name = NULL;
agent_group =task_agent_group (index); /* row id or 0 */
int agent_group_in_trash = task_agent_group_in_trash (index);

if (agent_group)
if (target_type == TASK_TARGET_TYPE_AGENT_GROUP)
{
agent_group_t agent_group = target;
int agent_group_in_trash = target_location_trash;
int group_readable = 0;
char *task_agent_group_uuid = NULL;
char *task_agent_group_name = NULL;

if (agent_group_in_trash)
{
task_agent_group_uuid = trash_agent_group_uuid (agent_group);
Expand Down Expand Up @@ -20442,17 +20464,15 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error)
}
#endif /* ENABLE_AGENT_GROUPS */
#if ENABLE_WEB_APPLICATION_SCANNING
web_application_target_t web_application_target;
int web_application_target_in_trash, web_application_target_available;
char *task_web_application_target_uuid, *task_web_application_target_name;
gchar *task_web_application_target_name_escaped;

web_application_target = task_web_application_target (index);
web_application_target_in_trash = task_web_application_target_in_trash (index);

if (web_application_target || web_application_target_in_trash)
if (target_type == TASK_TARGET_TYPE_WEB_APPLICATION)
{
web_application_target_available = 1;
web_application_target_t web_application_target = target;
int web_application_target_in_trash = target_location_trash;
int web_application_target_available = 1;
char *task_web_application_target_uuid;
char *task_web_application_target_name;
gchar *task_web_application_target_name_escaped;

if (web_application_target_in_trash)
{
task_web_application_target_uuid
Expand Down Expand Up @@ -25589,6 +25609,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
gboolean is_agent_task = FALSE;
gboolean is_container_scanning_task = FALSE;
gboolean is_web_application_scanning_task = FALSE;
int targets_given;
guint index;

/* @todo Buffer the entire task creation and pass everything to a
Expand Down Expand Up @@ -25758,11 +25779,23 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
goto create_task_fail;
}

if (create_task_data->target_id && create_task_data->agent_group_id)
targets_given = 0;
if (create_task_data->target_id)
targets_given++;
if (create_task_data->agent_group_id)
targets_given++;
if (create_task_data->oci_image_target_id)
targets_given++;
if (create_task_data->web_application_target_id)
targets_given++;

if (targets_given > 1)
{
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("create_task",
"Only one of target_id or agent_group_id must be provided"));
"Only one of target_id, agent_group_id,"
" oci_image_target_id or"
" web_application_target_id may be given"));
goto create_task_fail;
}
if (create_task_data->target_id && is_container_scanning_task)
Expand Down Expand Up @@ -25818,8 +25851,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
goto create_task_fail;
}

set_task_agent_group_and_location (create_task_data->task,
agent_group);
set_task_agent_group (create_task_data->task, agent_group);
}
#endif /* ENABLE_AGENTS */

Expand Down Expand Up @@ -25887,7 +25919,8 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
{
/* Import task. */

set_task_target (create_task_data->task, 0);
set_task_target (create_task_data->task, 0,
TASK_TARGET_TYPE_IMPORT_TASK);
set_task_usage_type (create_task_data->task,
create_task_data->usage_type);
SENDF_TO_CLIENT_OR_FAIL (XML_OK_CREATED_ID ("create_task"),
Expand Down Expand Up @@ -26060,7 +26093,8 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
error_send_to_client (error);
goto create_task_fail;
}
set_task_target (create_task_data->task, target);
set_task_target (create_task_data->task, target,
TASK_TARGET_TYPE_REGULAR);
}

set_task_scanner (create_task_data->task, scanner);
Expand Down Expand Up @@ -29021,6 +29055,17 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
modify_task_data->task_id,
"modified");
break;
case MODIFY_TASK_MULTIPLE_TARGETS:
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("modify_task",
"Only one of target, agent_group,"
" oci_image_target or"
" web_application_target"
" must be provided"));
log_event_fail ("task", "Task",
modify_task_data->task_id,
"modified");
break;
default:
case MODIFY_TASK_ERROR:
SEND_TO_CLIENT_OR_FAIL
Expand Down Expand Up @@ -31140,7 +31185,8 @@ gmp_xml_handle_error (/* unused */ GMarkupParseContext* context,
g_debug (" XML ERROR %s", error->message);
}




/* GMP input processor. */

/** @todo Most likely the client should get these from init_gmp_process
Expand Down
12 changes: 9 additions & 3 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,9 @@ run_osp_task (task_t task, int from, char **report_id)
{
target_t target;

target = task_target (task);
if (task_regular_target (task, &target))
return -1;

if (target)
{
char *uuid;
Expand Down Expand Up @@ -1917,7 +1919,9 @@ run_cve_task (task_t task)
{
target_t target;

target = task_target (task);
if (task_regular_target (task, &target))
return -1;

if (target)
{
char *uuid;
Expand Down Expand Up @@ -7095,7 +7099,9 @@ run_openvasd_task (task_t task, int from, char **report_id)
}
target_t target;

target = task_target (task);
if (task_regular_target (task, &target))
return -1;

if (target)
{
char *uuid;
Expand Down
Loading
Loading