From 9ef9c3a0b94c99fa1a8993b70cb72840af599ad0 Mon Sep 17 00:00:00 2001 From: Ahmed Abdelsalam Date: Mon, 5 Feb 2024 17:01:59 +0100 Subject: [PATCH] Tags can now be used with audit tasks and compliance policies --- src/gmp.c | 40 ++++++++++++++++------ src/manage_sql.c | 88 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 112 insertions(+), 16 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index 7b07f68b1..50dbfe011 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -15326,7 +15326,17 @@ select_resource_iterator (get_resource_names_data_t *resource_names_data, else if (g_strcmp0 ("config", resource_names_data->type) == 0) { *iterator = (int (*) (iterator_t*, get_data_t *))init_config_iterator; - } + get_data_set_extra (&resource_names_data->get, + "usage_type", + g_strdup ("scan")); + } + else if (g_strcmp0 ("policy", resource_names_data->type) == 0) + { + *iterator = (int (*) (iterator_t*, get_data_t *))init_config_iterator; + get_data_set_extra (&resource_names_data->get, + "usage_type", + g_strdup ("policy")); + } else if (g_strcmp0 ("scanner", resource_names_data->type) == 0) { *iterator = (int (*) (iterator_t*, get_data_t *))init_scanner_iterator; @@ -15342,7 +15352,17 @@ select_resource_iterator (get_resource_names_data_t *resource_names_data, else if (g_strcmp0 ("task", resource_names_data->type) == 0) { *iterator = (int (*) (iterator_t*, get_data_t *))init_task_iterator; - } + get_data_set_extra (&resource_names_data->get, + "usage_type", + g_strdup ("scan")); + } + else if (g_strcmp0 ("audit", resource_names_data->type) == 0) + { + *iterator = (int (*) (iterator_t*, get_data_t *))init_task_iterator; + get_data_set_extra (&resource_names_data->get, + "usage_type", + g_strdup ("audit")); + } else if (g_strcmp0 ("tls_certificate", resource_names_data->type) == 0) { *iterator = (int (*) (iterator_t*, get_data_t *))init_tls_certificate_iterator; @@ -15394,7 +15414,13 @@ handle_get_resource_names (gmp_parser_t *gmp_parser, GError **error) || (g_strcmp0 ("nvt", get_resource_names_data->type) == 0) || (g_strcmp0 ("cert_bund_adv", get_resource_names_data->type) == 0) || (g_strcmp0 ("dfn_cert_adv", get_resource_names_data->type) == 0)) - && (acl_user_may ("get_info") == 0))) + && (acl_user_may ("get_info") == 0)) + || (((g_strcmp0 ("config", get_resource_names_data->type) == 0) + ||(g_strcmp0 ("policy", get_resource_names_data->type) == 0)) + && (acl_user_may ("get_configs") == 0)) + || (((g_strcmp0 ("task", get_resource_names_data->type) == 0) + ||(g_strcmp0 ("audit", get_resource_names_data->type) == 0)) + && (acl_user_may ("get_tasks") == 0))) { SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX ("get_resource_names", @@ -15478,14 +15504,6 @@ handle_get_resource_names (gmp_parser_t *gmp_parser, GError **error) while (next (&resource)) { - if ((g_strcmp0 ("task", get_resource_names_data->type) == 0 - && g_strcmp0 ("audit", task_iterator_usage_type(&resource)) == 0) - || (g_strcmp0 ("config", get_resource_names_data->type) == 0 - && g_strcmp0 ("policy", config_iterator_usage_type(&resource)) == 0)) - { - continue; - } - GString *result; result = g_string_new (""); diff --git a/src/manage_sql.c b/src/manage_sql.c index b1be36bb3..a85fc989e 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -3975,7 +3975,9 @@ valid_type (const char* type) int valid_subtype (const char* type) { - return (strcasecmp (type, "audit_report") == 0); + return (strcasecmp (type, "audit_report") == 0) + || (strcasecmp (type, "audit") == 0) + || (strcasecmp (type, "policy") == 0); } /** @@ -4085,6 +4087,32 @@ type_is_report_subtype (const char *type) return (strcasecmp (type, "audit_report") == 0); } +/** + * @brief Check whether a resource type is a task subtype. + * + * @param[in] type Type of resource. + * + * @return 1 yes, 0 no. + */ +static int +type_is_task_subtype (const char *type) +{ + return (strcasecmp (type, "audit") == 0); +} + +/** + * @brief Check whether a resource type is a config subtype. + * + * @param[in] type Type of resource. + * + * @return 1 yes, 0 no. + */ +static int +type_is_config_subtype (const char *type) +{ + return (strcasecmp (type, "policy") == 0); +} + /** * @brief Check whether a type has a name and comment. * @@ -56861,10 +56889,20 @@ tag_add_resources_list (tag_t tag, const char *type, array_t *uuids, else if (type_is_asset_subtype (type)) resource_permission = g_strdup ("get_assets"); else if (type_is_report_subtype (type)) - { - resource_permission = g_strdup ("get_reports"); - type = g_strdup("report"); - } + { + resource_permission = g_strdup ("get_reports"); + type = g_strdup("report"); + } + else if (type_is_task_subtype (type)) + { + resource_permission = g_strdup ("get_tasks"); + type = g_strdup("task"); + } + else if (type_is_config_subtype (type)) + { + resource_permission = g_strdup ("get_configs"); + type = g_strdup("config"); + } else resource_permission = g_strdup_printf ("get_%ss", type); @@ -56938,6 +56976,26 @@ tag_add_resources_filter (tag_t tag, const char *type, const char *filter) { get_data_set_extra (&resources_get, "usage_type", g_strdup ("scan")); } + else if (strcasecmp (type, "task") == 0) + { + get_data_set_extra (&resources_get, "usage_type", g_strdup ("scan")); + } + else if (strcasecmp (type, "audit") == 0) + { + type = g_strdup ("task"); + resources_get.type = g_strdup (type); + get_data_set_extra (&resources_get, "usage_type", g_strdup ("audit")); + } + else if (strcasecmp (type, "policy") == 0) + { + type = g_strdup ("config"); + resources_get.type = g_strdup (type); + get_data_set_extra (&resources_get, "usage_type", g_strdup ("policy")); + } + else if (strcasecmp (type, "config") == 0) + { + get_data_set_extra (&resources_get, "usage_type", g_strdup ("scan")); + } gchar *columns; @@ -57101,6 +57159,26 @@ tag_remove_resources_filter (tag_t tag, const char *type, const char *filter) { get_data_set_extra (&resources_get, "usage_type", g_strdup ("scan")); } + else if (strcasecmp (type, "task") == 0) + { + get_data_set_extra (&resources_get, "usage_type", g_strdup ("scan")); + } + else if (strcasecmp (type, "audit") == 0) + { + type = g_strdup ("task"); + resources_get.type = g_strdup (type); + get_data_set_extra (&resources_get, "usage_type", g_strdup ("audit")); + } + else if (strcasecmp (type, "policy") == 0) + { + type = g_strdup ("config"); + resources_get.type = g_strdup (type); + get_data_set_extra (&resources_get, "usage_type", g_strdup ("policy")); + } + else if (strcasecmp (type, "config") == 0) + { + get_data_set_extra (&resources_get, "usage_type", g_strdup ("scan")); + } gchar *columns;