From d5f4ac41c21cb0487d7bce2c6a3ce221b939f696 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Mon, 19 Feb 2024 12:09:07 +0100 Subject: [PATCH] Address review comments for report configs This fixes several smaller issues found by @a-h-abdelsalam's review: - several "report format" vs. "report config" mix-ups / copy-paste errors - the "active" column in report format iterator - copying report format parameters - Some GMP attributes and elements --- src/manage_report_configs.h | 6 ++-- src/manage_sql_report_configs.c | 32 ++++++++++---------- src/manage_sql_report_configs.h | 7 +++++ src/manage_sql_report_formats.c | 6 ++-- src/schema_formats/XML/GMP.xml.in | 50 ++++++++++++++++++++++++++++++- 5 files changed, 79 insertions(+), 22 deletions(-) diff --git a/src/manage_report_configs.h b/src/manage_report_configs.h index 9011ffb5b..3a59604a3 100644 --- a/src/manage_report_configs.h +++ b/src/manage_report_configs.h @@ -17,10 +17,10 @@ */ /** - * @file manage_report_formats.c - * @brief GVM management layer: Report formats. + * @file manage_report_configs.h + * @brief GVM management layer: Report configs. * - * Non-SQL report format code for the GVM management layer. + * Non-SQL report config code for the GVM management layer. */ #ifndef _GVMD_MANAGE_REPORT_CONFIGS_H diff --git a/src/manage_sql_report_configs.c b/src/manage_sql_report_configs.c index 63dd97170..ed158db2f 100644 --- a/src/manage_sql_report_configs.c +++ b/src/manage_sql_report_configs.c @@ -17,7 +17,7 @@ */ /** - * @file manage_sql_report_formats.c + * @file manage_sql_report_configs.c * @brief GVM management layer: Report configs SQL. * * SQL report config code for the GVM management layer. @@ -45,14 +45,14 @@ * @param[in] name Name of new Report Config. NULL to copy * from existing. * @param[in] source_uuid UUID of existing Report Config. - * @param[out] new_report_format New Report Config. + * @param[out] new_report_config New Report Config. * * @return 0 success, 1 Report Config exists already, 2 failed to find existing * Report Config, 99 permission denied, -1 error. */ int copy_report_config (const char* name, const char* source_uuid, - report_config_t* new_report_format) + report_config_t* new_report_config) { report_format_t new, old; int ret; @@ -70,18 +70,18 @@ copy_report_config (const char* name, const char* source_uuid, return ret; } - /* Copy report format parameters. */ + /* Copy report config parameters. */ sql ("INSERT INTO report_config_params " " (report_config, name, value)" " SELECT %llu, name, value" - " FROM report_format_params WHERE report_format = %llu;", + " FROM report_config_params WHERE report_config = %llu;", new, old); sql_commit (); - if (new_report_format) *new_report_format = new; + if (new_report_config) *new_report_config = new; return 0; } @@ -268,10 +268,9 @@ create_report_config (const char *name, const char *comment, * @brief Modify a report config. * * @param[in] report_config_id UUID of report config to modify. - * @param[in] name Name of report config. - * @param[in] comment Comment of report config. + * @param[in] new_name Name of report config. + * @param[in] new_comment Comment of report config. * @param[in] params Array of params. - * @param[out] report_config Created report config. * @param[out] error_message Message for some errors like invalid params. * * @return 0 success, @@ -301,7 +300,7 @@ modify_report_config (const char *report_config_id, report_config = 0; if (find_report_config_with_permission (report_config_id, &report_config, - "modify_report_format")) + "modify_report_config")) { sql_rollback (); return -1; @@ -347,7 +346,7 @@ modify_report_config (const char *report_config_id, " FROM report_configs" " WHERE id = %llu)", report_config); - if (report_config == 0) + if (report_format == 0) { sql_rollback (); return 3; @@ -567,7 +566,8 @@ delete_report_configs_user (user_t user) * @param[in] report_config_id UUID of resource. * * @return 0 success, 1 fail because resource is in use, 2 failed to find - * resource, 4 fail because resource with UUID exists, -1 error. + * resource, 3 fail because resource with same name exists, + * 4 fail because resource with same UUID exists, -1 error. */ int restore_report_config (const char *report_config_id) @@ -643,7 +643,7 @@ restore_report_config (const char *report_config_id) } -/* GET_REPORT_FORMATS */ +/* GET_REPORT_CONFIGS */ /** * @brief Filter columns for Report Config iterator. @@ -681,7 +681,7 @@ restore_report_config (const char *report_config_id) { \ "(SELECT id FROM report_formats" \ " WHERE report_formats.uuid = report_format_id)", \ - "report_format", \ + "report_format_rowid", \ KEYWORD_TYPE_INTEGER, \ }, \ { NULL, NULL, KEYWORD_TYPE_UNKNOWN } \ @@ -716,7 +716,7 @@ restore_report_config (const char *report_config_id) { \ "(SELECT id FROM report_formats" \ " WHERE report_formats.uuid = report_format_id)", \ - "report_format", \ + "report_format_rowid", \ KEYWORD_TYPE_INTEGER, \ }, \ } @@ -1072,6 +1072,7 @@ report_config_report_format (report_config_t report_config) int report_config_in_use (report_config_t report_config) { + // TODO: Check for alerts using the report config return 0; } @@ -1085,6 +1086,7 @@ report_config_in_use (report_config_t report_config) int trash_report_config_in_use (report_config_t report_config) { + // TODO: Check for alerts using the report config return 0; } diff --git a/src/manage_sql_report_configs.h b/src/manage_sql_report_configs.h index a95d05ed7..065d4a8c1 100644 --- a/src/manage_sql_report_configs.h +++ b/src/manage_sql_report_configs.h @@ -16,6 +16,13 @@ * along with this program. If not, see . */ +/** + * @file manage_sql_report_configs.h + * @brief GVM management layer: Report configs SQL. + * + * SQL report config code for the GVM management layer. + */ + #ifndef _GVMD_MANAGE_SQL_REPORT_CONFIGS_H #define _GVMD_MANAGE_SQL_REPORT_CONFIGS_H diff --git a/src/manage_sql_report_formats.c b/src/manage_sql_report_formats.c index 0a0d51c7a..dd0f3da50 100644 --- a/src/manage_sql_report_formats.c +++ b/src/manage_sql_report_formats.c @@ -2902,7 +2902,7 @@ int report_format_iterator_active (iterator_t* iterator) { if (iterator->done) return -1; - return (iterator_int64 (iterator, GET_ITERATOR_COLUMN_COUNT + 7) + return (iterator_int64 (iterator, GET_ITERATOR_COLUMN_COUNT + 8) & REPORT_FORMAT_FLAG_ACTIVE) ? 1 : 0; } @@ -2981,9 +2981,9 @@ report_format_alert_iterator_readable (iterator_t* iterator) } /** - * @brief Initialise a Report Format alert iterator. + * @brief Initialise a Report Format config iterator. * - * Iterates over all alerts that use the Report Format. + * Iterates over all report configs that use the Report Format. * * @param[in] iterator Iterator. * @param[in] report_format Report Format. diff --git a/src/schema_formats/XML/GMP.xml.in b/src/schema_formats/XML/GMP.xml.in index d2465fe42..40998645a 100644 --- a/src/schema_formats/XML/GMP.xml.in +++ b/src/schema_formats/XML/GMP.xml.in @@ -16359,6 +16359,11 @@ END:VCALENDAR Whether to include report format parameters boolean + + report_configs + Whether to include report configs that use the report format + boolean + details Include report format file, signature and parameters @@ -16404,6 +16409,9 @@ END:VCALENDAR summary description alerts + invisible_alerts + report_configs + invisible_report_configs file @@ -16564,6 +16572,46 @@ END:VCALENDAR + + invisible_alerts + Number of alerts only visible to other users + integer + + + report_configs + Report configs using the report format + + report_config + + + report_config + + + id + uuid + UUID of the report config + 1 + + name + permissions + + + name + Name of the report config + name + + + permissions + Permissions the user has on the report config + + + + + + invisible_report_configs + Number of report configs only visible to other users + integer + param @@ -26518,7 +26566,7 @@ END:VCALENDAR Modify an existing report config

- The client uses the create_report_config command to change an existing + The client uses the modify_report_config command to change an existing report config.