Skip to content
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

Fix "Start Task" alerts by using alert owner #957

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Apply usage_type of tasks in get_aggregates (9.0) [#912](https://github.com/greenbone/gvmd/pull/912)
- Add target's alive test method before starting a scan. [#947](https://github.com/greenbone/gvmd/pull/947)
- Fix QoD handling in nvti cache and test_alert [#954](https://github.com/greenbone/gvmd/pull/954)
- Fix "Start Task" alerts by using alert owner [#957](https://github.com/greenbone/gvmd/pull/957)

### Removed
- Remove support for "All SecInfo": removal of "allinfo" for type in get_info [#790](https://github.com/greenbone/gvmd/pull/790)
Expand Down
39 changes: 35 additions & 4 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -13755,7 +13755,7 @@ escalate_2 (alert_t alert, task_t task, report_t report, event_t event,
case ALERT_METHOD_START_TASK:
{
gvm_connection_t connection;
char *task_id, *report_id;
char *task_id, *report_id, *owner_id, *owner_name;
gmp_authenticate_info_opts_t auth_opts;

if (event == EVENT_NEW_SECINFO || event == EVENT_UPDATED_SECINFO)
Expand All @@ -13776,8 +13776,31 @@ escalate_2 (alert_t alert, task_t task, report_t report, event_t event,
}

task_id = alert_data (alert, "method", "start_task_task");
if (task_id == NULL || strcmp (task_id, "") == 0)
{
g_warning ("%s: start_task_task missing or empty", __func__);
return -1;
}

switch (manage_fork_connection (&connection, current_credentials.uuid))
owner_id = sql_string ("SELECT uuid FROM users"
" WHERE id = (SELECT owner FROM alerts"
" WHERE id = %llu)",
alert);
owner_name = sql_string ("SELECT name FROM users"
" WHERE id = (SELECT owner FROM alerts"
" WHERE id = %llu)",
alert);

if (owner_id == NULL)
{
g_warning ("%s: could not find alert owner",
__func__);
free (owner_id);
free (owner_name);
return -1;
}

switch (manage_fork_connection (&connection, owner_id))
{
case 0:
/* Child. Break, stop task, exit. */
Expand All @@ -13793,30 +13816,38 @@ escalate_2 (alert_t alert, task_t task, report_t report, event_t event,
default:
/* Parent. Continue with whatever lead to this escalation. */
g_free (task_id);
free (owner_id);
free (owner_name);
return 0;
break;
}

/* Start the task. */

auth_opts = gmp_authenticate_info_opts_defaults;
auth_opts.username = current_credentials.username;
auth_opts.username = owner_name;
auth_opts.password = "dummy";
if (gmp_authenticate_info_ext_c (&connection, auth_opts))
{
g_free (task_id);
free (owner_id);
free (owner_name);
gvm_connection_free (&connection);
exit (EXIT_FAILURE);
}

if (gmp_start_task_report_c (&connection, task_id, &report_id))
{
g_free (task_id);
free (owner_id);
free (owner_name);
gvm_connection_free (&connection);
exit (EXIT_FAILURE);
}

g_free (task_id);
g_free (report_id);
free (owner_id);
free (owner_name);
gvm_connection_free (&connection);
exit (EXIT_SUCCESS);
}
Expand Down