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

Remove create report task creation #616

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
15 changes: 1 addition & 14 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,9 +1189,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_comment; ///< Comment for container task.
char *task_id; ///< ID of container task.
char *task_name; ///< Name for container task.
char *type; ///< Type of report.
int wrapper; ///< Whether there was a wrapper REPORT.
} create_report_data_t;
Expand Down Expand Up @@ -1285,9 +1283,7 @@ create_report_data_reset (create_report_data_t *data)
}
free (data->scan_end);
free (data->scan_start);
free (data->task_comment);
free (data->task_id);
free (data->task_name);
free (data->type);

memset (data, 0, sizeof (create_report_data_t));
Expand Down Expand Up @@ -23452,8 +23448,6 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
else switch (create_report
(create_report_data->results,
create_report_data->task_id,
create_report_data->task_name,
create_report_data->task_comment,
create_report_data->in_assets,
create_report_data->scan_start,
create_report_data->scan_end,
Expand All @@ -23477,7 +23471,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
case -3:
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("create_report",
"TASK_NAME is required"));
"A TASK id attribute is required"));
log_event_fail ("report", "Report", NULL, "created");
break;
case -4:
Expand Down Expand Up @@ -29631,13 +29625,6 @@ gmp_xml_handle_text (/* unused */ GMarkupParseContext* context,
&create_report_data->host_start);


APPEND (CLIENT_CREATE_REPORT_TASK_NAME,
&create_report_data->task_name);

APPEND (CLIENT_CREATE_REPORT_TASK_COMMENT,
&create_report_data->task_comment);


APPEND (CLIENT_CRF_GRFR_REPORT_FORMAT_CONTENT_TYPE,
&create_report_format_data->content_type);

Expand Down
3 changes: 1 addition & 2 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,7 @@ update_duration_schedule_periods (task_t);

int
create_report (array_t*, const char *, const char *, const char *, const char *,
const char *, const char *, array_t*, array_t*, array_t*,
char **);
array_t*, array_t*, array_t*, char **);

void
report_add_result (report_t, result_t);
Expand Down
58 changes: 20 additions & 38 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -22267,8 +22267,6 @@ insert_report_host_detail (report_t report, const char *host,
*
* @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_name Name for container task.
* @param[in] task_comment Comment for container task.
* @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.
Expand All @@ -22280,17 +22278,16 @@ insert_report_host_detail (report_t report, const char *host,
* @param[out] report_id Report ID.
*
* @return 0 success, 99 permission denied, -1 error, -2 failed to generate ID,
* -3 task_name is NULL, -4 failed to find task, -5 task must be
* -3 task_id is NULL, -4 failed to find task, -5 task must be
* container, -6 permission to create assets denied.
*/
int
create_report (array_t *results, const char *task_id, const char *task_name,
const char *task_comment, const char *in_assets,
create_report (array_t *results, const char *task_id, const char *in_assets,
const char *scan_start, const char *scan_end,
array_t *host_starts, array_t *host_ends, array_t *details,
char **report_id)
{
int index, in_assets_int, count, insert_count, first;
int index, in_assets_int, count, insert_count, first, rc;
create_report_result_t *result, *end, *start;
report_t report;
user_t owner;
Expand All @@ -22310,43 +22307,28 @@ create_report (array_t *results, const char *task_id, const char *task_name,
if (acl_user_may ("create_report") == 0)
return 99;

if (task_id == NULL && task_name == NULL)
if (task_id == NULL)
return -3;

/* Find or create the task. */

sql_begin_immediate ();
if (task_id)
{
int rc = 0;

/* It's important that the task is not in the trash, because we
* are inserting results below. This find function will fail if
* the task is in the trash. */
if (find_task_with_permission (task_id, &task, "modify_task"))
rc = -1;
else if (task == 0)
rc = -4;
else if (task_target (task))
rc = -5;
if (rc)
{
sql_rollback ();
return rc;
}
}
else
{
if (acl_user_may ("create_task") == 0)
{
sql_rollback ();
return 99;
}
/* Find the task. */

rc = 0;

task = make_task (g_strdup (task_name),
task_comment ? g_strdup (task_comment) : NULL,
1, /* Include in assets. */
1); /* Log and generate event. */
/* It's important that the task is not in the trash, because we
* are inserting results below. This find function will fail if
* the task is in the trash. */
if (find_task_with_permission (task_id, &task, "modify_task"))
rc = -1;
else if (task == 0)
rc = -4;
else if (task_target (task))
rc = -5;
if (rc)
{
sql_rollback ();
return rc;
}

/* Generate report UUID. */
Expand Down
30 changes: 17 additions & 13 deletions src/schema_formats/XML/GMP.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -4969,27 +4969,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
<ele>
<name>task</name>
<summary>
Task for report: id to use existing task, name to create new task
Existing task for report
</summary>
<pattern>
<attrib>
<name>id</name>
<type>uuid</type>
<required>0</required>
</attrib>
<o><e>name</e></o>
<o><e>comment</e></o>
</pattern>
<ele>
<name>name</name>
<summary>The name of the task</summary>
<pattern><t>name</t></pattern>
</ele>
<ele>
<name>comment</name>
<summary>Comment for the new task</summary>
<pattern>text</pattern>
</ele>
</ele>
<ele>
<name>in_assets</name>
Expand Down Expand Up @@ -26928,6 +26916,22 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

<!-- Compatibility changes between versions. -->

<change>
<command>CREATE_REPORT</command>
<summary>Remove elements TASK/NAME and TASK/COMMENT</summary>
<description>
<p>
The elements NAME and COMMENT of element TASK have been removed
from the command CREATE_REPORT. It is no longer possible to
create a task when uploading a report.
</p>
<p>
The alternate option, of specifying an existing task using the
TASK/@id attribute, is now required.
</p>
</description>
<version>9.0</version>
</change>
<change>
<command>GET_PREFERENCES, GET_CONFIGS</command>
<summary>Add NVT Preferences ID</summary>
Expand Down