Skip to content

Commit

Permalink
Add: Add GET_NVTS attribute skip_cert_refs
Browse files Browse the repository at this point in the history
  • Loading branch information
timopollmeier authored Jul 4, 2023
2 parents 5e1f2c4 + ed13f58 commit 78cca9b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
22 changes: 18 additions & 4 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,7 @@ typedef struct
char *nvt_oid; ///< Name of single NVT to get.
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.
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.
Expand Down Expand Up @@ -5311,6 +5312,11 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context,
get_nvts_data->preference_count = strcmp (attribute, "0");
else
get_nvts_data->preference_count = 0;
if (find_attribute (attribute_names, attribute_values,
"skip_cert_refs", &attribute))
get_nvts_data->skip_cert_refs = strcmp (attribute, "0");
else
get_nvts_data->skip_cert_refs = 0;
if (find_attribute (attribute_names, attribute_values,
"timeout", &attribute))
get_nvts_data->timeout = strcmp (attribute, "0");
Expand Down Expand Up @@ -7854,21 +7860,22 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context,
* @param[in] pref_count Preference count. Used if details is true.
* @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] write_to_client Function to write to client.
* @param[in] write_to_client_data Argument to \p write_to_client.
*
* @return TRUE if out of space in to_client buffer, else FALSE.
*/
static gboolean
send_nvt (iterator_t *nvts, int details, int preferences, int pref_count,
const char *timeout, config_t config,
const char *timeout, config_t config, int skip_cert_refs,
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);
0, skip_cert_refs);
if (send_to_client (msg, write_to_client, write_to_client_data))
{
g_free (msg);
Expand Down Expand Up @@ -13167,7 +13174,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,
if (send_nvt (&info, 1, 1, -1, NULL, 0, 0,
gmp_parser->client_writer,
gmp_parser->client_writer_data))
{
Expand Down Expand Up @@ -13376,6 +13383,12 @@ handle_get_nvts (gmp_parser_t *gmp_parser, GError **error)
(XML_ERROR_SYNTAX ("get_nvts",
"The preferences attribute"
" requires the details attribute"));
else if ((get_nvts_data->details == 0)
&& get_nvts_data->skip_cert_refs)
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("get_nvts",
"The skip_cert_refs 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)))
Expand Down Expand Up @@ -13484,6 +13497,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,
gmp_parser->client_writer,
gmp_parser->client_writer_data))
{
Expand All @@ -13499,7 +13513,7 @@ handle_get_nvts (gmp_parser_t *gmp_parser, GError **error)
else
while (next (&nvts))
{
if (send_nvt (&nvts, 0, 0, -1, NULL, 0,
if (send_nvt (&nvts, 0, 0, -1, NULL, 0, 0,
gmp_parser->client_writer,
gmp_parser->client_writer_data))
{
Expand Down
12 changes: 9 additions & 3 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -5529,13 +5529,14 @@ xsl_transform (gchar *stylesheet, gchar *xmlfile, gchar **param_names,
* @param[in] timeout Timeout. Used if details is true.
* @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.
*
* @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 close_tag, int skip_cert_refs)
{
const char* oid = nvt_iterator_oid (nvts);
const char* name = nvt_iterator_name (nvts);
Expand Down Expand Up @@ -5612,7 +5613,11 @@ get_nvt_xml (iterator_t *nvts, int details, int pref_count,

refs_str = g_string_new ("");

if (manage_cert_loaded())
if (skip_cert_refs)
{
// Faster.
}
else if (manage_cert_loaded())
{
init_nvt_cert_bund_adv_iterator (&cert_refs_iterator, oid);
while (next (&cert_refs_iterator))
Expand Down Expand Up @@ -5933,7 +5938,8 @@ manage_read_info (gchar *type, gchar *uid, gchar *name, gchar **result)
1, /* Include preferences. */
NULL, /* Timeout. */
0, /* Config. */
1); /* Close tag. */
1, /* Close tag. */
0); /* Skip CERT refs. */

cleanup_iterator (&nvts);
}
Expand Down
2 changes: 1 addition & 1 deletion src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,7 @@ void
xml_append_nvt_refs (GString *, const char *, int *);

gchar*
get_nvt_xml (iterator_t*, int, int, int, const char*, config_t, int);
get_nvt_xml (iterator_t*, int, int, int, const char*, config_t, int, int);

char*
task_preference_value (task_t, const char *);
Expand Down
5 changes: 5 additions & 0 deletions src/schema_formats/XML/GMP.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -12910,6 +12910,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<summary>Whether to include preference count</summary>
<type>boolean</type>
</attrib>
<attrib>
<name>skip_cert_refs</name>
<summary>Whether to exclude refs of types cert-bund and dfn-cert</summary>
<type>boolean</type>
</attrib>
<attrib>
<name>timeout</name>
<summary>Whether to include the special timeout preference</summary>
Expand Down

0 comments on commit 78cca9b

Please sign in to comment.