Skip to content

Commit c6d4d46

Browse files
a-h-abdelsalamtimopollmeier
authored andcommitted
Change: Differentiate report formats of scan and audit reports
1 parent 4bb16cc commit c6d4d46

11 files changed

+222
-50
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ include (CPack)
9696

9797
## Variables
9898

99-
set (GVMD_DATABASE_VERSION 256)
99+
set (GVMD_DATABASE_VERSION 257)
100100

101101
set (GVMD_SCAP_DATABASE_VERSION 22)
102102

src/gmp.c

+59-20
Original file line numberDiff line numberDiff line change
@@ -14978,29 +14978,66 @@ handle_get_reports (gmp_parser_t *gmp_parser, GError **error)
1497814978
no_report_format = (get_reports_data->format_id == NULL)
1497914979
|| (strcmp(get_reports_data->format_id, "") == 0);
1498014980

14981-
if ((!no_report_format)
14982-
&& find_report_format_with_permission (get_reports_data->format_id,
14983-
&report_format,
14984-
"get_report_formats"))
14981+
if (!no_report_format)
1498514982
{
14986-
get_reports_data_reset (get_reports_data);
14987-
SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("get_reports"));
14988-
set_client_state (CLIENT_AUTHENTIC);
14989-
return;
14990-
}
14983+
if (find_report_format_with_permission (get_reports_data->format_id,
14984+
&report_format,
14985+
"get_report_formats"))
14986+
{
14987+
get_reports_data_reset (get_reports_data);
14988+
SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("get_reports"));
14989+
set_client_state (CLIENT_AUTHENTIC);
14990+
return;
14991+
}
1499114992

14992-
if ((!no_report_format) && (report_format == 0))
14993-
{
14994-
if (send_find_error_to_client ("get_reports", "report format",
14995-
get_reports_data->format_id,
14996-
gmp_parser))
14993+
if (report_format == 0)
1499714994
{
14998-
error_send_to_client (error);
14995+
if (send_find_error_to_client ("get_reports", "report format",
14996+
get_reports_data->format_id,
14997+
gmp_parser))
14998+
{
14999+
error_send_to_client (error);
15000+
return;
15001+
}
15002+
get_reports_data_reset (get_reports_data);
15003+
set_client_state (CLIENT_AUTHENTIC);
1499915004
return;
1500015005
}
15001-
get_reports_data_reset (get_reports_data);
15002-
set_client_state (CLIENT_AUTHENTIC);
15003-
return;
15006+
15007+
task_t task;
15008+
gchar *usage_type, *report_type;
15009+
if(report_task (request_report, &task) || (task == 0))
15010+
{
15011+
get_reports_data_reset (get_reports_data);
15012+
SEND_TO_CLIENT_OR_FAIL
15013+
(XML_ERROR_SYNTAX ("get_reports",
15014+
"Failed to get report task"));
15015+
set_client_state (CLIENT_AUTHENTIC);
15016+
return;
15017+
}
15018+
if (task_usage_type(task, &usage_type))
15019+
{
15020+
get_reports_data_reset (get_reports_data);
15021+
SEND_TO_CLIENT_OR_FAIL
15022+
(XML_ERROR_SYNTAX ("get_reports",
15023+
"Failed to get usage type"));
15024+
set_client_state (CLIENT_AUTHENTIC);
15025+
return;
15026+
}
15027+
report_type = report_format_report_type (report_format);
15028+
if (report_type)
15029+
{
15030+
if (strcmp(report_type, usage_type) && strcmp(report_type, "all"))
15031+
{
15032+
get_reports_data_reset (get_reports_data);
15033+
SEND_TO_CLIENT_OR_FAIL
15034+
(XML_ERROR_SYNTAX ("get_reports",
15035+
"Report format is not compatible with"
15036+
" the report type"));
15037+
set_client_state (CLIENT_AUTHENTIC);
15038+
return;
15039+
}
15040+
}
1500415041
}
1500515042

1500615043
if (!no_report_config)
@@ -15896,7 +15933,8 @@ handle_get_report_formats (gmp_parser_t *gmp_parser, GError **error)
1589615933
"<summary>%s</summary>"
1589715934
"<description>%s</description>"
1589815935
"<predefined>%i</predefined>"
15899-
"<configurable>%i</configurable>",
15936+
"<configurable>%i</configurable>"
15937+
"<report_type>%s</report_type>",
1590015938
report_format_iterator_extension (&report_formats),
1590115939
report_format_iterator_content_type (&report_formats),
1590215940
report_format_iterator_summary (&report_formats),
@@ -15906,7 +15944,8 @@ handle_get_report_formats (gmp_parser_t *gmp_parser, GError **error)
1590615944
(get_iterator_resource (&report_formats))
1590715945
: report_format_predefined
1590815946
(get_iterator_resource (&report_formats)),
15909-
report_format_iterator_configurable (&report_formats));
15947+
report_format_iterator_configurable (&report_formats),
15948+
report_format_iterator_report_type (&report_formats) ?: "");
1591015949

1591115950
if (resource_id_deprecated ("report_format",
1591215951
get_iterator_uuid (&report_formats)))

src/gmp_report_formats.c

+18-3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ params_options_free (array_t *params_options)
157157
* @param[out] params Address for params.
158158
* @param[out] params_options Address for param options.
159159
* @param[out] deprecated Address for deprecation status.
160+
* @param[out] report_type Address for report type.
160161
*/
161162
void
162163
parse_report_format_entity (entity_t report_format,
@@ -165,7 +166,7 @@ parse_report_format_entity (entity_t report_format,
165166
char **summary, char **description,
166167
char **signature, array_t **files,
167168
array_t **params, array_t **params_options,
168-
char **deprecated)
169+
char **deprecated, char **report_type)
169170
{
170171
entity_t file, param_entity;
171172
entities_t children;
@@ -181,6 +182,18 @@ parse_report_format_entity (entity_t report_format,
181182
*signature = child_or_null (report_format, "signature");
182183
if (deprecated)
183184
*deprecated = child_or_null (report_format, "deprecated");
185+
if (report_type)
186+
*report_type = child_or_null (report_format, "report_type");
187+
188+
if (*report_type == NULL)
189+
*report_type = "scan";
190+
else if (strcmp (*report_type, "scan") && strcmp (*report_type, "audit")
191+
&& strcmp (*report_type, "all"))
192+
{
193+
g_warning ("report_type for report format %s is invalid.",
194+
*report_format_id);
195+
*report_type = "scan";
196+
}
184197

185198
*files = make_array ();
186199
*params = make_array ();
@@ -362,7 +375,7 @@ create_report_format_run (gmp_parser_t *gmp_parser, GError **error)
362375
&& (report_format = entity_child (get_report_formats_response, "report_format")))
363376
{
364377
char *import_name, *content_type, *extension, *summary, *description;
365-
char *signature;
378+
char *signature, *report_type;
366379
const char *report_format_id;
367380
array_t *files, *params, *params_options;
368381

@@ -371,7 +384,8 @@ create_report_format_run (gmp_parser_t *gmp_parser, GError **error)
371384
parse_report_format_entity (report_format, &report_format_id,
372385
&import_name, &content_type, &extension,
373386
&summary, &description, &signature, &files,
374-
&params, &params_options, NULL);
387+
&params, &params_options, NULL,
388+
&report_type);
375389

376390
/* Check data, then create report format. */
377391

@@ -410,6 +424,7 @@ create_report_format_run (gmp_parser_t *gmp_parser, GError **error)
410424
params,
411425
params_options,
412426
signature,
427+
report_type,
413428
&new_report_format))
414429
{
415430
case -1:

src/gmp_report_formats.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ params_options_free (array_t *);
4343
void
4444
parse_report_format_entity (entity_t, const char **, char **, char **,
4545
char **, char **, char **, char **,
46-
array_t **, array_t **, array_t **, char **);
46+
array_t **, array_t **, array_t **, char **,
47+
char **);
4748

4849
#endif /* not _GVMD_GMP_REPORT_FORMATS_H */

src/manage_migrators.c

+38
Original file line numberDiff line numberDiff line change
@@ -3218,6 +3218,43 @@ migrate_255_to_256 ()
32183218
return 0;
32193219
}
32203220

3221+
/**
3222+
* @brief Migrate the database from version 256 to version 257.
3223+
*
3224+
* @return 0 success, -1 error.
3225+
*/
3226+
int
3227+
migrate_256_to_257 ()
3228+
{
3229+
sql_begin_immediate ();
3230+
3231+
/* Ensure that the database is currently version 256. */
3232+
3233+
if (manage_db_version () != 256)
3234+
{
3235+
sql_rollback ();
3236+
return -1;
3237+
}
3238+
3239+
/* Update the database. */
3240+
3241+
// Add new columns
3242+
3243+
sql ("ALTER TABLE report_formats ADD COLUMN"
3244+
" report_type text DEFAULT 'scan';");
3245+
3246+
sql ("ALTER TABLE report_formats_trash ADD COLUMN"
3247+
" report_type text DEFAULT 'scan';");
3248+
3249+
/* Set the database version to 257. */
3250+
3251+
set_db_version (257);
3252+
3253+
sql_commit ();
3254+
3255+
return 0;
3256+
}
3257+
32213258
#undef UPDATE_DASHBOARD_SETTINGS
32223259

32233260
/**
@@ -3280,6 +3317,7 @@ static migrator_t database_migrators[] = {
32803317
{254, migrate_253_to_254},
32813318
{255, migrate_254_to_255},
32823319
{256, migrate_255_to_256},
3320+
{257, migrate_256_to_257},
32833321
/* End marker. */
32843322
{-1, NULL}};
32853323

src/manage_pg.c

+2
Original file line numberDiff line numberDiff line change
@@ -2979,6 +2979,7 @@ create_tables ()
29792979
" trust_time integer,"
29802980
" flags integer,"
29812981
" predefined integer,"
2982+
" report_type text,"
29822983
" creation_time integer,"
29832984
" modification_time integer);");
29842985

@@ -3005,6 +3006,7 @@ create_tables ()
30053006
* Feed ("predefined") report formats are not given a new UUID because
30063007
* they are not created if they already exist in the trash. */
30073008
" original_uuid text,"
3009+
" report_type text,"
30083010
" creation_time integer,"
30093011
" modification_time integer);");
30103012

src/manage_report_formats.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ update_report_format_from_file (report_format_t report_format,
395395
entity_t entity;
396396
array_t *files, *params, *params_options;
397397
char *name, *content_type, *extension, *summary, *description, *signature;
398-
char *deprecated;
398+
char *deprecated, *report_type;
399399
const char *report_format_id;
400400

401401
g_debug ("%s: updating %s", __func__, path);
@@ -410,13 +410,13 @@ update_report_format_from_file (report_format_t report_format,
410410
parse_report_format_entity (entity, &report_format_id, &name,
411411
&content_type, &extension, &summary,
412412
&description, &signature, &files, &params,
413-
&params_options, &deprecated);
413+
&params_options, &deprecated, &report_type);
414414

415415
/* Update the report format. */
416416

417417
update_report_format (report_format, report_format_id, name, content_type,
418418
extension, summary, description, signature, files,
419-
params, params_options, deprecated);
419+
params, params_options, deprecated, report_type);
420420

421421
/* Cleanup. */
422422

@@ -487,7 +487,7 @@ create_report_format_from_file (const gchar *path)
487487
entity_t report_format;
488488
array_t *files, *params, *params_options;
489489
char *name, *content_type, *extension, *summary, *description, *signature;
490-
char *deprecated;
490+
char *deprecated, *report_type;
491491
const char *report_format_id;
492492
report_format_t new_report_format;
493493

@@ -503,7 +503,7 @@ create_report_format_from_file (const gchar *path)
503503
parse_report_format_entity (report_format, &report_format_id, &name,
504504
&content_type, &extension, &summary,
505505
&description, &signature, &files, &params,
506-
&params_options, &deprecated);
506+
&params_options, &deprecated, &report_type);
507507

508508
/* Handle deprecation status */
509509

@@ -528,6 +528,7 @@ create_report_format_from_file (const gchar *path)
528528
params_options,
529529
signature,
530530
1,
531+
report_type,
531532
&new_report_format))
532533
{
533534
case 0:

src/manage_report_formats.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ typedef struct
4343
int
4444
create_report_format (const char *, const char *, const char *, const char *,
4545
const char *, const char *, array_t *, array_t *,
46-
array_t *, const char *, report_format_t *);
46+
array_t *, const char *, const char *,
47+
report_format_t *);
4748

4849
int
4950
copy_report_format (const char *, const char *, report_format_t*);
@@ -73,6 +74,9 @@ report_format_content_type (report_format_t);
7374
char *
7475
report_format_extension (report_format_t);
7576

77+
char *
78+
report_format_report_type (report_format_t);
79+
7680
int
7781
report_format_global (report_format_t);
7882

@@ -119,6 +123,9 @@ report_format_iterator_extension (iterator_t *);
119123
const char*
120124
report_format_iterator_content_type (iterator_t *);
121125

126+
const char*
127+
report_format_iterator_report_type (iterator_t *);
128+
122129
const char*
123130
report_format_iterator_description (iterator_t *);
124131

0 commit comments

Comments
 (0)