From 88495e41d84fc525c27e799f2dcd1c77fe3f1dd7 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Tue, 29 Aug 2023 16:01:55 +0200 Subject: [PATCH 1/3] Add: GET_NVTS attribute skip_tags --- src/gmp.c | 21 ++++++++++++++++++--- src/manage.c | 30 +++++++++++++++++++----------- src/manage.h | 2 +- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index c4be583e7..8eea8242e 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -1825,6 +1825,7 @@ typedef struct int preference_count; ///< Boolean. Whether to include NVT preference count. int preferences; ///< Boolean. Whether to include NVT preferences. int skip_cert_refs; ///< Boolean. Whether to exclude CERT refs. + int skip_tags; ///< Boolean. Whether to exclude tags. char *sort_field; ///< Field to sort results on. int sort_order; ///< Result sort order: 0 descending, else ascending. int timeout; ///< Boolean. Whether to include timeout preference. @@ -5317,6 +5318,11 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context, get_nvts_data->skip_cert_refs = strcmp (attribute, "0"); else get_nvts_data->skip_cert_refs = 0; + if (find_attribute (attribute_names, attribute_values, + "skip_tags", &attribute)) + get_nvts_data->skip_tags = strcmp (attribute, "0"); + else + get_nvts_data->skip_tags = 0; if (find_attribute (attribute_names, attribute_values, "timeout", &attribute)) get_nvts_data->timeout = strcmp (attribute, "0"); @@ -7861,6 +7867,7 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context, * @param[in] timeout Timeout. Used if details is true. * @param[in] config Config, used if preferences is true. * @param[in] skip_cert_refs If true, exclude CERT refs. + * @param[in] skip_tags If true, exclude tags. * @param[in] write_to_client Function to write to client. * @param[in] write_to_client_data Argument to \p write_to_client. * @@ -7869,13 +7876,14 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context, static gboolean send_nvt (iterator_t *nvts, int details, int preferences, int pref_count, const char *timeout, config_t config, int skip_cert_refs, + int skip_tags, int (*write_to_client) (const char *, void*), void* write_to_client_data) { gchar *msg; msg = get_nvt_xml (nvts, details, pref_count, preferences, timeout, config, - 0, skip_cert_refs); + 0, skip_cert_refs, skip_cert_refs); if (send_to_client (msg, write_to_client, write_to_client_data)) { g_free (msg); @@ -13176,7 +13184,7 @@ handle_get_info (gmp_parser_t *gmp_parser, GError **error) dfn_cert_adv_info_iterator_cve_refs (&info)); else if (g_strcmp0 ("nvt", get_info_data->type) == 0) { - if (send_nvt (&info, 1, 1, -1, NULL, 0, 0, + if (send_nvt (&info, 1, 1, -1, NULL, 0, 0, 0, gmp_parser->client_writer, gmp_parser->client_writer_data)) { @@ -13391,6 +13399,12 @@ handle_get_nvts (gmp_parser_t *gmp_parser, GError **error) (XML_ERROR_SYNTAX ("get_nvts", "The skip_cert_refs attribute" " requires the details attribute")); + else if ((get_nvts_data->details == 0) + && get_nvts_data->skip_tags) + SEND_TO_CLIENT_OR_FAIL + (XML_ERROR_SYNTAX ("get_nvts", + "The skip_tags attribute" + " requires the details attribute")); else if (((get_nvts_data->details == 0) || ((get_nvts_data->config_id == NULL) && (get_nvts_data->preferences_config_id == NULL))) @@ -13500,6 +13514,7 @@ handle_get_nvts (gmp_parser_t *gmp_parser, GError **error) if (send_nvt (&nvts, 1, get_nvts_data->preferences, pref_count, timeout, config, get_nvts_data->skip_cert_refs, + get_nvts_data->skip_tags, gmp_parser->client_writer, gmp_parser->client_writer_data)) { @@ -13515,7 +13530,7 @@ handle_get_nvts (gmp_parser_t *gmp_parser, GError **error) else while (next (&nvts)) { - if (send_nvt (&nvts, 0, 0, -1, NULL, 0, 0, + if (send_nvt (&nvts, 0, 0, -1, NULL, 0, 0, 0, gmp_parser->client_writer, gmp_parser->client_writer_data)) { diff --git a/src/manage.c b/src/manage.c index 8a1bd2fe7..dcdd15714 100644 --- a/src/manage.c +++ b/src/manage.c @@ -5638,13 +5638,14 @@ xsl_transform (gchar *stylesheet, gchar *xmlfile, gchar **param_names, * @param[in] config Config, used if preferences is true. * @param[in] close_tag Whether to close the NVT tag or not. * @param[in] skip_cert_refs Whether to exclude the CERT REFs. + * @param[in] skip_tags Whether to exclude the tags. * * @return A dynamically allocated string containing the XML description. */ gchar * get_nvt_xml (iterator_t *nvts, int details, int pref_count, int preferences, const char *timeout, config_t config, - int close_tag, int skip_cert_refs) + int close_tag, int skip_cert_refs, int skip_tags) { const char* oid = nvt_iterator_oid (nvts); const char* name = nvt_iterator_name (nvts); @@ -5755,12 +5756,17 @@ get_nvt_xml (iterator_t *nvts, int details, int pref_count, xml_append_nvt_refs (refs_str, oid, NULL); - tags_str = g_string_new (""); - tag_count = resource_tag_count ("nvt", - get_iterator_resource (nvts), - 1); + if (skip_tags) + tags_str = NULL; + else + { + tags_str = g_string_new (""); + tag_count = resource_tag_count ("nvt", + get_iterator_resource (nvts), + 1); + } - if (tag_count) + if (tags_str && tag_count) { g_string_append_printf (tags_str, "" @@ -5820,7 +5826,7 @@ get_nvt_xml (iterator_t *nvts, int details, int pref_count, get_iterator_modification_time (nvts) ? get_iterator_modification_time (nvts) : "", - tags_str->str, + tags_str ? tags_str->str : "", nvt_iterator_category (nvts), family_text, nvt_iterator_cvss_base (nvts) @@ -5868,9 +5874,10 @@ get_nvt_xml (iterator_t *nvts, int details, int pref_count, timeout ? timeout : "", default_timeout ? default_timeout : ""); g_free (family_text); - g_string_free(nvt_tags, 1); - g_string_free(refs_str, 1); - g_string_free(tags_str, 1); + g_string_free (nvt_tags, 1); + g_string_free (refs_str, 1); + if (tags_str) + g_string_free (tags_str, 1); if (nvt_iterator_solution (nvts) || nvt_iterator_solution_type (nvts) || @@ -6047,7 +6054,8 @@ manage_read_info (gchar *type, gchar *uid, gchar *name, gchar **result) NULL, /* Timeout. */ 0, /* Config. */ 1, /* Close tag. */ - 0); /* Skip CERT refs. */ + 0, /* Skip CERT refs. */ + 0); /* Skip tags. */ cleanup_iterator (&nvts); } diff --git a/src/manage.h b/src/manage.h index 187b8a74d..2687a751b 100644 --- a/src/manage.h +++ b/src/manage.h @@ -1998,7 +1998,7 @@ void xml_append_nvt_refs (GString *, const char *, int *); gchar* -get_nvt_xml (iterator_t*, int, int, int, const char*, config_t, int, int); +get_nvt_xml (iterator_t*, int, int, int, const char*, config_t, int, int, int); char* task_preference_value (task_t, const char *); From 67d07e2618096039fde02c3b8b1d6997cc671717 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Tue, 5 Sep 2023 10:33:12 +0200 Subject: [PATCH 2/3] Correct variable in send_nvt --- src/gmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gmp.c b/src/gmp.c index 8eea8242e..4854475f7 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -7883,7 +7883,7 @@ send_nvt (iterator_t *nvts, int details, int preferences, int pref_count, gchar *msg; msg = get_nvt_xml (nvts, details, pref_count, preferences, timeout, config, - 0, skip_cert_refs, skip_cert_refs); + 0, skip_cert_refs, skip_tags); if (send_to_client (msg, write_to_client, write_to_client_data)) { g_free (msg); From f8ee926ea54fb7504b1a97d69b19dd62e0f6d42d Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Tue, 5 Sep 2023 10:53:54 +0200 Subject: [PATCH 3/3] Doc attribute skip_tags --- src/schema_formats/XML/GMP.xml.in | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/schema_formats/XML/GMP.xml.in b/src/schema_formats/XML/GMP.xml.in index 00dd89ae8..09cefc97e 100644 --- a/src/schema_formats/XML/GMP.xml.in +++ b/src/schema_formats/XML/GMP.xml.in @@ -13251,6 +13251,11 @@ END:VCALENDAR Whether to exclude refs of types cert-bund and dfn-cert boolean + + skip_tags + Whether to exclude user tags + boolean + timeout Whether to include the special timeout preference