From 0b1116b914bfe48090a3c82e35f00b7c615ec5d3 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Thu, 12 Dec 2019 22:39:39 +0200 Subject: [PATCH 01/12] Don't create an entity tree during read_string_c --- util/xmlutils.c | 96 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 11 deletions(-) diff --git a/util/xmlutils.c b/util/xmlutils.c index 29bf0eccb..7dfd256e0 100644 --- a/util/xmlutils.c +++ b/util/xmlutils.c @@ -263,6 +263,33 @@ add_attributes (entity_t entity, const gchar **names, const gchar **values) } } +/** + * @brief Handle the start of an OMP XML element. + * + * @param[in] context Parser context. + * @param[in] element_name XML element name. + * @param[in] attribute_names XML attribute name. + * @param[in] attribute_values XML attribute values. + * @param[in] user_data Dummy parameter. + * @param[in] error Error parameter. + */ +static void +ignore_start_element (GMarkupParseContext *context, const gchar *element_name, + const gchar **attribute_names, + const gchar **attribute_values, gpointer user_data, + GError **error) +{ + context_data_t *data = (context_data_t *) user_data; + + (void) context; + (void) element_name; + (void) attribute_names; + (void) attribute_values; + (void) error; + + data->current = GINT_TO_POINTER (GPOINTER_TO_INT (data->current) + 1); +} + /** * @brief Handle the start of an OMP XML element. * @@ -318,6 +345,29 @@ xml_handle_start_element (context_data_t *context, const gchar *element_name, attribute_values, context, NULL); } +/** + * @brief Handle the end of an XML element. + * + * @param[in] context Parser context. + * @param[in] element_name XML element name. + * @param[in] user_data Dummy parameter. + * @param[in] error Error parameter. + */ +static void +ignore_end_element (GMarkupParseContext *context, const gchar *element_name, + gpointer user_data, GError **error) +{ + context_data_t *data = (context_data_t *) user_data; + + (void) context; + (void) element_name; + (void) error; + + data->current = GINT_TO_POINTER (GPOINTER_TO_INT (data->current) - 1); + if (data->current == NULL) + data->done = TRUE; +} + /** * @brief Handle the end of an XML element. * @@ -368,6 +418,26 @@ xml_handle_end_element (context_data_t *context, const gchar *element_name) handle_end_element (NULL, element_name, context, NULL); } +/** + * @brief Handle additional text of an XML element. + * + * @param[in] context Parser context. + * @param[in] text The text. + * @param[in] text_len Length of the text. + * @param[in] user_data Dummy parameter. + * @param[in] error Error parameter. + */ +static void +ignore_text (GMarkupParseContext *context, const gchar *text, gsize text_len, + gpointer user_data, GError **error) +{ + (void) context; + (void) text; + (void) text_len; + (void) user_data; + (void) error; +} + /** * @brief Handle additional text of an XML element. * @@ -705,9 +775,18 @@ try_read_entity_and_string_s (int socket, int timeout, entity_t *entity, /* Create the XML parser. */ - xml_parser.start_element = handle_start_element; - xml_parser.end_element = handle_end_element; - xml_parser.text = handle_text; + if (entity) + { + xml_parser.start_element = handle_start_element; + xml_parser.end_element = handle_end_element; + xml_parser.text = handle_text; + } + else + { + xml_parser.start_element = ignore_start_element; + xml_parser.end_element = ignore_end_element; + xml_parser.text = ignore_text; + } xml_parser.passthrough = NULL; xml_parser.error = handle_error; @@ -840,7 +919,8 @@ try_read_entity_and_string_s (int socket, int timeout, entity_t *entity, g_free (buffer); return -2; } - *entity = (entity_t) context_data.first->data; + if (entity) + *entity = (entity_t) context_data.first->data; if (string) *string_return = string; if (timeout > 0) @@ -1003,13 +1083,7 @@ read_string (gnutls_session_t *session, GString **string) int read_string_c (gvm_connection_t *connection, GString **string) { - int ret = 0; - entity_t entity; - - if (!(ret = read_entity_and_string_c (connection, &entity, string))) - free_entity (entity); - - return ret; + return read_entity_and_string_c (connection, NULL, string); } /** From 5af997937906da51678b9d52bf54013b1ee8f383 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Fri, 13 Dec 2019 00:56:00 +0200 Subject: [PATCH 02/12] Add NULL entity handling to try_read_entity_and_string --- util/xmlutils.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/util/xmlutils.c b/util/xmlutils.c index 7dfd256e0..72317e43a 100644 --- a/util/xmlutils.c +++ b/util/xmlutils.c @@ -557,9 +557,18 @@ try_read_entity_and_string (gnutls_session_t *session, int timeout, /* Create the XML parser. */ - xml_parser.start_element = handle_start_element; - xml_parser.end_element = handle_end_element; - xml_parser.text = handle_text; + if (entity) + { + xml_parser.start_element = handle_start_element; + xml_parser.end_element = handle_end_element; + xml_parser.text = handle_text; + } + else + { + xml_parser.start_element = ignore_start_element; + xml_parser.end_element = ignore_end_element; + xml_parser.text = ignore_text; + } xml_parser.passthrough = NULL; xml_parser.error = handle_error; @@ -695,7 +704,8 @@ try_read_entity_and_string (gnutls_session_t *session, int timeout, g_free (buffer); return -2; } - *entity = (entity_t) context_data.first->data; + if (entity) + *entity = (entity_t) context_data.first->data; if (string) *string_return = string; if (timeout > 0) From 35319baec45f8cd18f45c162e969afb746502c78 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Fri, 13 Dec 2019 01:25:03 +0200 Subject: [PATCH 03/12] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c0f31238..70987acbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Make solution and solution_type explicit for nvti. [#255](https://github.com/greenbone/gvm-libs/pull/255) - Internalize struct nvtpref_t. [#260](https://github.com/greenbone/gvm-libs/pull/260) - Extend redis connection error msg with actual path. [#264](https://github.com/greenbone/gvm-libs/pull/264) +- Don't create an entity tree during read_string_c. [#305](https://github.com/greenbone/gvm-libs/pull/305) ### Fixed - Prevent g_strsplit to be called with NULL. [#238](https://github.com/greenbone/gvm-libs/pull/238) From d8f62b128ce73c3f9ea5eaf9f512fbdd9c6325d7 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Mon, 16 Dec 2019 18:08:20 +0200 Subject: [PATCH 04/12] Free string in all error exit cases --- util/xmlutils.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/util/xmlutils.c b/util/xmlutils.c index 72317e43a..4164294c0 100644 --- a/util/xmlutils.c +++ b/util/xmlutils.c @@ -837,6 +837,8 @@ try_read_entity_and_string_s (int socket, int timeout, entity_t *entity, __FUNCTION__, strerror (errno)); g_markup_parse_context_free (xml_context); g_free (buffer); + if (string && *string_return == NULL) + g_string_free (string, TRUE); return -4; } } @@ -927,6 +929,8 @@ try_read_entity_and_string_s (int socket, int timeout, entity_t *entity, fcntl (socket, F_SETFL, 0L); g_markup_parse_context_free (xml_context); g_free (buffer); + if (string && *string_return == NULL) + g_string_free (string, TRUE); return -2; } if (entity) @@ -950,6 +954,8 @@ try_read_entity_and_string_s (int socket, int timeout, entity_t *entity, strerror (errno)); g_markup_parse_context_free (xml_context); g_free (buffer); + if (string && *string_return == NULL) + g_string_free (string, TRUE); return -1; } } From df57853cef52105167178ea71c1b2e2729adf557 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Thu, 5 Dec 2019 14:57:01 +0100 Subject: [PATCH 05/12] Fix trust and file handling for S/MIME The certificates used for S/MIME encryption are now added to the GPG trust list automatically because users cannot always confirm trust. Also, a data buffer with custom I/O functions is used to write the encrypted data because gpgme_data_new_from_stream can cause problems when trying to write afterwards. --- util/gpgmeutils.c | 136 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 2 deletions(-) diff --git a/util/gpgmeutils.c b/util/gpgmeutils.c index 6955e46b5..1a82ff13d 100644 --- a/util/gpgmeutils.c +++ b/util/gpgmeutils.c @@ -358,6 +358,127 @@ find_email_encryption_key (gpgme_ctx_t ctx, const char *uid_email) } } +/** + * @brief Wrapper for fread for use as a GPGME callback. + * + * @param[in] handle The file handle. + * @param[out] buffer The data buffer to read data into. + * @param[in] size The size of the buffer. + * + * @return The number of bytes read or -1 on error. + */ +static ssize_t +gvm_gpgme_fread (void *handle, void *buffer, size_t size) +{ + int ret; + FILE *file = (FILE *)handle; + + ret = fread (buffer, 1, size, file); + if (ferror (file)) + return -1; + return ret; +} + +/** + * @brief Wrapper for fread for use as a GPGME callback. + * + * @param[in] handle The file handle. + * @param[in] buffer The data buffer to read data into. + * @param[in] size The amount of buffered data. + * + * @return The number of bytes written or -1 on error. + */ +static ssize_t +gvm_gpgme_fwrite (void *handle, const void *buffer, size_t size) +{ + int ret; + FILE *file = (FILE *)handle; + + ret = fwrite (buffer, 1, size, file); + if (ferror (file)) + return -1; + return ret; +} + +/** + * @brief Create a GPGME data buffer with custom read and write functions. + * + * This is neccessary as gpgme_data_new_from_stream may cause problems + * when trying to write to the stream after some operations. + * + * @param[out] new_data The new GPGME data buffer. + * @param[in] file The stream to read from and write to. + * + * @return The return value from gpgme_data_new_from_cbs. + */ +static gpgme_error_t +gvm_gpgme_data_new_from_stream (gpgme_data_t *new_data, FILE *file) +{ + struct gpgme_data_cbs *callbacks; + + callbacks = malloc (sizeof (struct gpgme_data_cbs)); + memset (callbacks, 0, sizeof (struct gpgme_data_cbs)); + callbacks->read = gvm_gpgme_fread; + callbacks->write = gvm_gpgme_fwrite; + + return gpgme_data_new_from_cbs (new_data, callbacks, file); +} + +/** + * @brief Adds a trust list of all current certificates to a GPG homedir. + * + * This will overwrite the existing trustlist, so it should only be used for + * temporary, automatically generated GPG home directories. + * + * TODO: This should use or be replaced by a trust model inside GVM. + * + * @param[in] ctx The GPGME context to get the keys from. + * @param[in] homedir The directory to write the trust list file to. + * + * @return 0 success, -1 error. + */ +static int +create_all_certificates_trustlist (gpgme_ctx_t ctx, const char *homedir) +{ + gpgme_key_t key; + gchar *trustlist_filename; + GString *trustlist_content; + GError *g_err; + + g_err = NULL; gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_CANCEL); + + trustlist_filename = g_build_filename (homedir, + "trustlist.txt", + NULL); + + trustlist_content = g_string_new (""); + + gpgme_op_keylist_start (ctx, NULL, 0); + gpgme_op_keylist_next (ctx, &key); + while (key) + { + g_string_append_printf (trustlist_content, "%s S\n", key->fpr); + gpgme_op_keylist_next (ctx, &key); + } + + if (g_file_set_contents (trustlist_filename, + trustlist_content->str, + trustlist_content->len, + &g_err) == FALSE) + { + g_warning ("%s: Could not write trust list: %s", + __func__, g_err->message); + g_free (trustlist_filename); + g_string_free (trustlist_content, TRUE); + return -1; + } + + g_free (trustlist_filename); + g_string_free (trustlist_content, TRUE); + + return 0; +} + /** * @brief Encrypt a stream for a PGP public key, writing to another stream. * @@ -441,10 +562,21 @@ encrypt_stream_internal (FILE *plain_file, FILE *encrypted_file, // Set up data objects for input and output streams gpgme_data_new_from_stream (&plain_data, plain_file); - gpgme_data_new_from_stream (&encrypted_data, encrypted_file); + gvm_gpgme_data_new_from_stream (&encrypted_data, encrypted_file); if (protocol == GPGME_PROTOCOL_CMS) - gpgme_data_set_encoding (encrypted_data, GPGME_DATA_ENCODING_BASE64); + { + gpgme_data_set_encoding (encrypted_data, GPGME_DATA_ENCODING_BASE64); + + if (create_all_certificates_trustlist (ctx, gpg_temp_dir)) + { + gpgme_data_release (plain_data); + gpgme_data_release (encrypted_data); + gpgme_release (ctx); + gvm_file_remove_recurse (gpg_temp_dir); + return -1; + } + } // Encrypt data err = gpgme_op_encrypt (ctx, keys, encrypt_flags, plain_data, encrypted_data); From 9f435ea953e0ffbeb134571e91da9fe8be6e7f70 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Wed, 18 Dec 2019 12:21:49 +0100 Subject: [PATCH 06/12] Add CHANGELOG entry for S/MIME trust fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70987acbd..e22497b46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - Fix sigsegv when no plugin_feed_info.inc file present. [#278](https://github.com/greenbone/gvm-libs/pull/278) - Fix missing linking to libgnutls in util/CMakeLists.txt. [#291](https://github.com/greenbone/gvm-libs/pull/291) +- Fix trust and file handling for S/MIME [#309](https://github.com/greenbone/gvm-libs/pull/309) [11.0.1]: https://github.com/greenbone/gvm-libs/compare/v11.0.0...gvm-libs-11.0 From 6f4400ce1565eca79ac29ee18289547168fe03ec Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Tue, 24 Dec 2019 14:20:02 +0200 Subject: [PATCH 07/12] Neaten formatting --- util/gpgmeutils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/gpgmeutils.c b/util/gpgmeutils.c index 1a82ff13d..ac94cfc46 100644 --- a/util/gpgmeutils.c +++ b/util/gpgmeutils.c @@ -445,7 +445,8 @@ create_all_certificates_trustlist (gpgme_ctx_t ctx, const char *homedir) GString *trustlist_content; GError *g_err; - g_err = NULL; gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_CANCEL); + g_err = NULL; + gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_CANCEL); trustlist_filename = g_build_filename (homedir, "trustlist.txt", From c126b8530453079494059f9001a289dbcaaeed41 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Tue, 24 Dec 2019 15:03:57 +0200 Subject: [PATCH 08/12] Use glib's malloc --- util/gpgmeutils.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util/gpgmeutils.c b/util/gpgmeutils.c index ac94cfc46..0444d3bc6 100644 --- a/util/gpgmeutils.c +++ b/util/gpgmeutils.c @@ -416,8 +416,7 @@ gvm_gpgme_data_new_from_stream (gpgme_data_t *new_data, FILE *file) { struct gpgme_data_cbs *callbacks; - callbacks = malloc (sizeof (struct gpgme_data_cbs)); - memset (callbacks, 0, sizeof (struct gpgme_data_cbs)); + callbacks = g_malloc0 (sizeof (struct gpgme_data_cbs)); callbacks->read = gvm_gpgme_fread; callbacks->write = gvm_gpgme_fwrite; From 8428f83c0308ca4a3795ff3acd4037faf6fff59f Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Tue, 24 Dec 2019 15:19:21 +0200 Subject: [PATCH 09/12] Move gvm_gpgme_data_new_from_stream into caller, to avoid allocation --- util/gpgmeutils.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/util/gpgmeutils.c b/util/gpgmeutils.c index 0444d3bc6..a89f2d938 100644 --- a/util/gpgmeutils.c +++ b/util/gpgmeutils.c @@ -400,29 +400,6 @@ gvm_gpgme_fwrite (void *handle, const void *buffer, size_t size) return ret; } -/** - * @brief Create a GPGME data buffer with custom read and write functions. - * - * This is neccessary as gpgme_data_new_from_stream may cause problems - * when trying to write to the stream after some operations. - * - * @param[out] new_data The new GPGME data buffer. - * @param[in] file The stream to read from and write to. - * - * @return The return value from gpgme_data_new_from_cbs. - */ -static gpgme_error_t -gvm_gpgme_data_new_from_stream (gpgme_data_t *new_data, FILE *file) -{ - struct gpgme_data_cbs *callbacks; - - callbacks = g_malloc0 (sizeof (struct gpgme_data_cbs)); - callbacks->read = gvm_gpgme_fread; - callbacks->write = gvm_gpgme_fwrite; - - return gpgme_data_new_from_cbs (new_data, callbacks, file); -} - /** * @brief Adds a trust list of all current certificates to a GPG homedir. * @@ -508,6 +485,7 @@ encrypt_stream_internal (FILE *plain_file, FILE *encrypted_file, gpgme_error_t err; gpgme_encrypt_flags_t encrypt_flags; const char *key_type_str; + struct gpgme_data_cbs callbacks; if (uid_email == NULL || strcmp (uid_email, "") == 0) { @@ -562,7 +540,15 @@ encrypt_stream_internal (FILE *plain_file, FILE *encrypted_file, // Set up data objects for input and output streams gpgme_data_new_from_stream (&plain_data, plain_file); - gvm_gpgme_data_new_from_stream (&encrypted_data, encrypted_file); + + /* Create a GPGME data buffer with custom read and write functions. + * + * This is neccessary as gpgme_data_new_from_stream may cause problems + * when trying to write to the stream after some operations. */ + memset (&callbacks, 0, sizeof (callbacks)); + callbacks.read = gvm_gpgme_fread; + callbacks.write = gvm_gpgme_fwrite; + gpgme_data_new_from_cbs (&encrypted_data, &callbacks, encrypted_file); if (protocol == GPGME_PROTOCOL_CMS) { From d083224ba46c204c62282e469916f1b661f1e609 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Mon, 30 Dec 2019 21:26:01 +0200 Subject: [PATCH 10/12] Make doc spacing more consistent --- util/kb.c | 80 +++++++++++++++++++++++++++++++++++++++++++--- util/nvticache.c | 1 + util/serverutils.c | 12 ++++++- 3 files changed, 88 insertions(+), 5 deletions(-) diff --git a/util/kb.c b/util/kb.c index 5b604df12..16f77d4e9 100644 --- a/util/kb.c +++ b/util/kb.c @@ -76,6 +76,7 @@ redis_cmd (struct kb_redis *kbr, const char *fmt, ...); /** * @brief Attempt to atomically acquire ownership of a database. + * * @return 0 on success, negative integer otherwise. */ static int @@ -104,7 +105,9 @@ try_database_index (struct kb_redis *kbr, int index) /** * @brief Set the number of databases have been configured * into kbr struct. + * * @param[in] kbr Subclass of struct kb where to save the max db index founded. + * * @return 0 on success, -1 on error. */ static int @@ -154,11 +157,13 @@ fetch_max_db_index (struct kb_redis *kbr) /** * @brief Select DB. - * @param[in] kbr Subclass of struct kb where to save the db index. - * @return 0 on success, -1 on error. * * WARNING: do not call redis_cmd in here, since our context is not fully * acquired yet! + * + * @param[in] kbr Subclass of struct kb where to save the db index. + * + * @return 0 on success, -1 on error. */ static int select_database (struct kb_redis *kbr) @@ -207,6 +212,7 @@ select_database (struct kb_redis *kbr) /** * @brief Release DB. + * * @param[in] kbr Subclass of struct kb. * * @return 0 on success, -1 on error. @@ -248,8 +254,10 @@ redis_release_db (struct kb_redis *kbr) /** * @brief Get redis context if it is already connected or do a * a connection. + * * @param[in] kbr Subclass of struct kb where to fetch the context. * or where it is saved in case of a new connection. + * * @return 0 on success, -1 on connection error, -2 on unavailable DB slot. */ static int @@ -286,7 +294,9 @@ get_redis_ctx (struct kb_redis *kbr) /** * @brief Test redis connection. + * * @param[in] kbr Subclass of struct kb to test. + * * @return 0 on success, negative integer on error. */ static int @@ -325,7 +335,9 @@ redis_test_connection (struct kb_redis *kbr) /** * @brief Delete all entries and release ownership on the namespace. + * * @param[in] kb KB handle to release. + * * @return 0 on success, non-null on error. */ static int @@ -350,7 +362,9 @@ redis_delete (kb_t kb) /** * @brief Return the kb index + * * @param[in] kb KB handle. + * * @return kb_index on success, null on error. */ static int @@ -365,8 +379,10 @@ redis_get_kb_index (kb_t kb) /** * @brief Initialize a new Knowledge Base object. + * * @param[in] kb Reference to a kb_t to initialize. * @param[in] kb_path Path to KB. + * * @return 0 on success, -1 on connection error, -2 when no DB is available. */ static int @@ -396,8 +412,10 @@ redis_new (kb_t *kb, const char *kb_path) /** * @brief Connect to a Knowledge Base object with the given kb_index. + * * @param[in] kb_path Path to KB. * @param[in] kb_index DB index + * * @return Knowledge Base object, NULL otherwise. */ static kb_t @@ -436,8 +454,10 @@ redis_direct_conn (const char *kb_path, const int kb_index) /** * @brief Find an existing Knowledge Base object with key. + * * @param[in] kb_path Path to KB. * @param[in] key Marker key to search for in KB objects. + * * @return Knowledge Base object, NULL otherwise. */ static kb_t @@ -510,6 +530,7 @@ redis_find (const char *kb_path, const char *key) /** * @brief Release a KB item (or a list). + * * @param[in] item Item or list to be release */ void @@ -529,9 +550,11 @@ kb_item_free (struct kb_item *item) /** * @brief Give a single KB item. + * * @param[in] name Name of the item. * @param[in] elt A redisReply element where to fetch the item. * @param[in] force_int To force string to integer conversion. + * * @return Single retrieve kb_item on success, NULL otherwise. */ static struct kb_item * @@ -572,8 +595,10 @@ redis2kbitem_single (const char *name, const redisReply *elt, int force_int) /** * @brief Fetch a KB item or list from a redis Reply. + * * @param[in] name Name of the item. * @param[in] rep A redisReply element where to fetch the item. + * * @return kb_item or list on success, NULL otherwise. */ static struct kb_item * @@ -623,8 +648,10 @@ redis2kbitem (const char *name, const redisReply *rep) /** * @brief Execute a redis command and get a redis reply. + * * @param[in] kbr Subclass of struct kb to connect to. * @param[in] fmt Formatted variable argument list with the cmd to be executed. + * * @return Redis reply on success, NULL otherwise. */ static redisReply * @@ -667,9 +694,11 @@ redis_cmd (struct kb_redis *kbr, const char *fmt, ...) /** * @brief Get a single KB element. + * * @param[in] kb KB handle where to fetch the item. * @param[in] name Name of the element to retrieve. * @param[in] type Desired element type. + * * @return A struct kb_item to be freed with kb_item_free() or NULL if no * element was found or on error. */ @@ -701,8 +730,10 @@ redis_get_single (kb_t kb, const char *name, enum kb_item_type type) /** * @brief Get a single KB string item. + * * @param[in] kb KB handle where to fetch the item. * @param[in] name Name of the element to retrieve. + * * @return A struct kb_item to be freed with kb_item_free() or NULL if no * element was found or on error. */ @@ -726,9 +757,11 @@ redis_get_str (kb_t kb, const char *name) /** * @brief Push a new entry under a given key. + * * @param[in] kb KB handle where to store the item. * @param[in] name Key to push to. * @param[in] value Value to push. + * * @return 0 on success, non-null on error. */ static int @@ -751,8 +784,10 @@ redis_push_str (kb_t kb, const char *name, const char *value) /** * @brief Pops a single KB string item. + * * @param[in] kb KB handle where to fetch the item. * @param[in] name Name of the key from where to retrieve. + * * @return A string to be freed or NULL if list is empty or on error. */ static char * @@ -776,8 +811,10 @@ redis_pop_str (kb_t kb, const char *name) /** * @brief Get a single KB integer item. + * * @param[in] kb KB handle where to fetch the item. * @param[in] name Name of the element to retrieve. + * * @return A struct kb_item to be freed with kb_item_free() or NULL if no * element was found or on error. */ @@ -800,9 +837,11 @@ redis_get_int (kb_t kb, const char *name) /** * @brief Get field of a NVT. + * * @param[in] kb KB handle where to store the nvt. * @param[in] oid OID of NVT to get from. * @param[in] position Position of field to get. + * * @return Value of field, NULL otherwise. */ static char * @@ -831,8 +870,10 @@ redis_get_nvt (kb_t kb, const char *oid, enum kb_nvt_pos position) /** * @brief Get a full NVT. + * * @param[in] kb KB handle where to store the nvt. * @param[in] oid OID of NVT to get. + * * @return nvti_t of NVT, NULL otherwise. */ static nvti_t * @@ -879,8 +920,10 @@ redis_get_nvt_all (kb_t kb, const char *oid) /** * @brief Get all items stored under a given name. + * * @param[in] kb KB handle where to fetch the items. * @param[in] name Name of the elements to retrieve. + * * @return Linked struct kb_item instances to be freed with kb_item_free() or * NULL if no element was found or on error. */ @@ -906,8 +949,10 @@ redis_get_all (kb_t kb, const char *name) /** * @brief Get all items stored under a given pattern. + * * @param[in] kb KB handle where to fetch the items. * @param[in] pattern '*' pattern of the elements to retrieve. + * * @return Linked struct kb_item instances to be freed with kb_item_free() or * NULL if no element was found or on error. */ @@ -970,7 +1015,9 @@ redis_get_pattern (kb_t kb, const char *pattern) /** * @brief Get all NVT OIDs. + * * @param[in] kb KB handle where to fetch the items. + * * @return Linked list of all OIDs or NULL. */ static GSList * @@ -1034,8 +1081,10 @@ redis_count (kb_t kb, const char *pattern) /** * @brief Delete all entries under a given name. + * * @param[in] kb KB handle where to store the item. * @param[in] name Item name. + * * @return 0 on success, non-null on error. */ static int @@ -1059,10 +1108,12 @@ redis_del_items (kb_t kb, const char *name) /** * @brief Insert (append) a new unique entry under a given name. + * * @param[in] kb KB handle where to store the item. * @param[in] name Item name. * @param[in] str Item value. * @param[in] len Value length. Used for blobs. + * * @return 0 on success, non-null on error. */ static int @@ -1113,10 +1164,12 @@ redis_add_str_unique (kb_t kb, const char *name, const char *str, size_t len) /** * @brief Insert (append) a new entry under a given name. + * * @param[in] kb KB handle where to store the item. * @param[in] name Item name. * @param[in] str Item value. * @param[in] len Value length. Used for blobs. + * * @return 0 on success, non-null on error. */ static int @@ -1141,10 +1194,12 @@ redis_add_str (kb_t kb, const char *name, const char *str, size_t len) /** * @brief Set (replace) a new entry under a given name. + * * @param[in] kb KB handle where to store the item. * @param[in] name Item name. * @param[in] val Item value. * @param[in] len Value length. Used for blobs. + * * @return 0 on success, non-null on error. */ static int @@ -1180,9 +1235,11 @@ redis_set_str (kb_t kb, const char *name, const char *val, size_t len) /** * @brief Insert (append) a new unique entry under a given name. + * * @param[in] kb KB handle where to store the item. * @param[in] name Item name. * @param[in] val Item value. + * * @return 0 on success, non-null on error. */ static int @@ -1219,9 +1276,11 @@ redis_add_int_unique (kb_t kb, const char *name, int val) /** * @brief Insert (append) a new entry under a given name. + * * @param[in] kb KB handle where to store the item. * @param[in] name Item name. * @param[in] val Item value. + * * @return 0 on success, non-null on error. */ static int @@ -1241,9 +1300,11 @@ redis_add_int (kb_t kb, const char *name, int val) /** * @brief Set (replace) a new entry under a given name. + * * @param[in] kb KB handle where to store the item. * @param[in] name Item name. * @param[in] val Item value. + * * @return 0 on success, non-null on error. */ static int @@ -1276,9 +1337,11 @@ redis_set_int (kb_t kb, const char *name, int val) /** * @brief Insert a new nvt. + * * @param[in] kb KB handle where to store the nvt. * @param[in] nvt nvt to store. * @param[in] filename Path to nvt to store. + * * @return 0 on success, non-null on error. */ static int @@ -1340,7 +1403,9 @@ redis_add_nvt (kb_t kb, const nvti_t *nvt, const char *filename) /** * @brief Reset connection to the KB. This is called after each fork() to make * sure connections aren't shared between concurrent processes. + * * @param[in] kb KB handle. + * * @return 0 on success, non-null on error. */ static int @@ -1361,8 +1426,10 @@ redis_lnk_reset (kb_t kb) /** * @brief Flush all the KB's content. Delete all namespaces. + * * @param[in] kb KB handle. * @param[in] except Don't flush DB with except key. + * * @return 0 on success, non-null on error. */ static int @@ -1437,7 +1504,9 @@ redis_flush_all (kb_t kb, const char *except) /** * @brief Save all the elements from the KB. + * * @param[in] kb KB handle. + * * @return 0 on success, -1 on error. */ int @@ -1467,7 +1536,9 @@ redis_save (kb_t kb) /** * @brief Delete all the KB's content. + * * @param[in] kbr Subclass of struct kb. + * * @return 0 on success, non-null on error. */ int @@ -1506,8 +1577,9 @@ redis_delete_all (struct kb_redis *kbr) /** * @brief Default KB operations. - * No selection mechanism is provided yet since there's only one - * implementation (redis-based). + * + * No selection mechanism is provided yet since there's only one + * implementation (redis-based). */ static const struct kb_operations KBRedisOperations = { .kb_new = redis_new, diff --git a/util/nvticache.c b/util/nvticache.c index 9a2b72879..05744ced3 100644 --- a/util/nvticache.c +++ b/util/nvticache.c @@ -581,6 +581,7 @@ nvticache_count () /** * @brief Delete NVT from the cache. + * * @param[in] oid OID to match. */ void diff --git a/util/serverutils.c b/util/serverutils.c index b309ac740..77c30448e 100644 --- a/util/serverutils.c +++ b/util/serverutils.c @@ -216,6 +216,7 @@ static char *cert_priv_mem = NULL; /** * @brief Save cert_pub_mem with public certificate. + * * @param[in] data The DER or PEM encoded certificate. */ static void @@ -228,6 +229,7 @@ set_cert_pub_mem (const char *data) /** * @brief Save cert_priv_mem with private certificate. + * * @param[in] data The DER or PEM encoded certificate. */ static void @@ -240,6 +242,7 @@ set_cert_priv_mem (const char *data) /** * @brief Get private certificate from @ref cert_priv_mem. + * * @return The DER or PEM encoded certificate. */ static const char * @@ -250,6 +253,7 @@ get_cert_priv_mem () /** * @brief Get public certificate from @ref cert_pub_mem. + * * @return The DER or PEM encoded certificate. */ static const char * @@ -260,7 +264,8 @@ get_cert_pub_mem () /** * @brief Callback function to be called in order to retrieve the - certificate to be used in the handshake. + * certificate to be used in the handshake. + * * @param[in] session Pointer to GNUTLS session. Not in used. Can be NULL. * @param[in] req_ca_rdn Contains a list with the CA names that * the server considers trusted. Not in used. Can be NULL. @@ -269,6 +274,7 @@ get_cert_pub_mem () * algorithms. Not in used. Can be NULL. * @param[in] sign_algos_length Algos list length. Not in used. Can be NULL. * @param[out] st Should contain the certificates and private keys + * * @return 0 on success, non-null otherwise. */ static int @@ -995,7 +1001,9 @@ gvm_connection_sendf_xml_quiet (gvm_connection_t *connection, /** * @brief Initialize a server session. + * * @param[in] server_credentials Credentials to be allocated. + * * @return 0 on success, -1 on error. */ static int @@ -1021,11 +1029,13 @@ server_new_gnutls_init (gnutls_certificate_credentials_t *server_credentials) /** * @brief Set the server credencials. + * * @param[in] end_type Connection end type. * @param[in] priority TLS priority to be set. If no one is given, NORMAL is * default. * @param[in] server_session GNUTLS session. * @param[in] server_credentials Credentials to be set. + * * @return 0 on success, -1 on error. */ static int From f905c55d8d1bf2bd8635a8b258227fe60a290846 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Tue, 21 Jan 2020 16:45:43 +0100 Subject: [PATCH 11/12] Get details with get_reports in gmp_get_report_ext To ensure the previous behavior of getting the results etc. the details attribute has been added to the sent GMP command. --- gmp/gmp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gmp/gmp.c b/gmp/gmp.c index 1b69dfaed..471e46c31 100644 --- a/gmp/gmp.c +++ b/gmp/gmp.c @@ -1355,6 +1355,7 @@ gmp_get_report_ext (gnutls_session_t *session, gmp_get_report_opts_t opts, if (gvm_server_sendf ( session, " Date: Tue, 21 Jan 2020 16:48:33 +0100 Subject: [PATCH 12/12] Add gmp_get_report_ext to CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e22497b46..1ed0bf9c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix sigsegv when no plugin_feed_info.inc file present. [#278](https://github.com/greenbone/gvm-libs/pull/278) - Fix missing linking to libgnutls in util/CMakeLists.txt. [#291](https://github.com/greenbone/gvm-libs/pull/291) - Fix trust and file handling for S/MIME [#309](https://github.com/greenbone/gvm-libs/pull/309) +- Get details with get_reports in gmp_get_report_ext [#313](https://github.com/greenbone/gvm-libs/pull/313) [11.0.1]: https://github.com/greenbone/gvm-libs/compare/v11.0.0...gvm-libs-11.0