Skip to content

Commit 912db98

Browse files
committed
Add: GET_NVTS attribute lean
1 parent a070849 commit 912db98

File tree

3 files changed

+104
-67
lines changed

3 files changed

+104
-67
lines changed

src/gmp.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,7 @@ typedef struct
18211821
char *preferences_config_id; ///< ID of config to get preference values from.
18221822
int details; ///< Boolean. Whether to include full NVT details.
18231823
char *family; ///< Name of family to which to limit NVT selection.
1824+
int lean; ///< Boolean. Whether to send fewer details.
18241825
char *nvt_oid; ///< Name of single NVT to get.
18251826
int preference_count; ///< Boolean. Whether to include NVT preference count.
18261827
int preferences; ///< Boolean. Whether to include NVT preferences.
@@ -5303,6 +5304,11 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context,
53035304
get_nvts_data->details = 0;
53045305
append_attribute (attribute_names, attribute_values, "family",
53055306
&get_nvts_data->family);
5307+
if (find_attribute (attribute_names, attribute_values,
5308+
"lean", &attribute))
5309+
get_nvts_data->lean = strcmp (attribute, "0");
5310+
else
5311+
get_nvts_data->lean = 0;
53065312
if (find_attribute (attribute_names, attribute_values,
53075313
"preferences", &attribute))
53085314
get_nvts_data->preferences = strcmp (attribute, "0");
@@ -7868,6 +7874,7 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context,
78687874
* @param[in] config Config, used if preferences is true.
78697875
* @param[in] skip_cert_refs If true, exclude CERT refs.
78707876
* @param[in] skip_tags If true, exclude tags.
7877+
* @param[in] lean If true, send fewer details.
78717878
* @param[in] write_to_client Function to write to client.
78727879
* @param[in] write_to_client_data Argument to \p write_to_client.
78737880
*
@@ -7876,14 +7883,14 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context,
78767883
static gboolean
78777884
send_nvt (iterator_t *nvts, int details, int preferences, int pref_count,
78787885
const char *timeout, config_t config, int skip_cert_refs,
7879-
int skip_tags,
7886+
int skip_tags, int lean,
78807887
int (*write_to_client) (const char *, void*),
78817888
void* write_to_client_data)
78827889
{
78837890
gchar *msg;
78847891

78857892
msg = get_nvt_xml (nvts, details, pref_count, preferences, timeout, config,
7886-
0, skip_cert_refs, skip_tags);
7893+
0, skip_cert_refs, skip_tags, lean);
78877894
if (send_to_client (msg, write_to_client, write_to_client_data))
78887895
{
78897896
g_free (msg);
@@ -13184,7 +13191,7 @@ handle_get_info (gmp_parser_t *gmp_parser, GError **error)
1318413191
dfn_cert_adv_info_iterator_cve_refs (&info));
1318513192
else if (g_strcmp0 ("nvt", get_info_data->type) == 0)
1318613193
{
13187-
if (send_nvt (&info, 1, 1, -1, NULL, 0, 0, 0,
13194+
if (send_nvt (&info, 1, 1, -1, NULL, 0, 0, 0, 0,
1318813195
gmp_parser->client_writer,
1318913196
gmp_parser->client_writer_data))
1319013197
{
@@ -13405,6 +13412,12 @@ handle_get_nvts (gmp_parser_t *gmp_parser, GError **error)
1340513412
(XML_ERROR_SYNTAX ("get_nvts",
1340613413
"The skip_tags attribute"
1340713414
" requires the details attribute"));
13415+
else if ((get_nvts_data->details == 0)
13416+
&& get_nvts_data->lean)
13417+
SEND_TO_CLIENT_OR_FAIL
13418+
(XML_ERROR_SYNTAX ("get_nvts",
13419+
"The lean attribute"
13420+
" requires the details attribute"));
1340813421
else if (((get_nvts_data->details == 0)
1340913422
|| ((get_nvts_data->config_id == NULL)
1341013423
&& (get_nvts_data->preferences_config_id == NULL)))
@@ -13515,6 +13528,7 @@ handle_get_nvts (gmp_parser_t *gmp_parser, GError **error)
1351513528
pref_count, timeout, config,
1351613529
get_nvts_data->skip_cert_refs,
1351713530
get_nvts_data->skip_tags,
13531+
get_nvts_data->lean,
1351813532
gmp_parser->client_writer,
1351913533
gmp_parser->client_writer_data))
1352013534
{
@@ -13530,7 +13544,7 @@ handle_get_nvts (gmp_parser_t *gmp_parser, GError **error)
1353013544
else
1353113545
while (next (&nvts))
1353213546
{
13533-
if (send_nvt (&nvts, 0, 0, -1, NULL, 0, 0, 0,
13547+
if (send_nvt (&nvts, 0, 0, -1, NULL, 0, 0, 0, 0,
1353413548
gmp_parser->client_writer,
1353513549
gmp_parser->client_writer_data))
1353613550
{
@@ -26803,6 +26817,7 @@ process_gmp_client_input ()
2680326817
return err;
2680426818
}
2680526819
from_client_end = from_client_start = 0;
26820+
2680626821
return 0;
2680726822
}
2680826823

src/manage.c

Lines changed: 84 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5639,13 +5639,14 @@ xsl_transform (gchar *stylesheet, gchar *xmlfile, gchar **param_names,
56395639
* @param[in] close_tag Whether to close the NVT tag or not.
56405640
* @param[in] skip_cert_refs Whether to exclude the CERT REFs.
56415641
* @param[in] skip_tags Whether to exclude the tags.
5642+
* @param[in] lean Whether to send fewer details.
56425643
*
56435644
* @return A dynamically allocated string containing the XML description.
56445645
*/
56455646
gchar *
56465647
get_nvt_xml (iterator_t *nvts, int details, int pref_count,
56475648
int preferences, const char *timeout, config_t config,
5648-
int close_tag, int skip_cert_refs, int skip_tags)
5649+
int close_tag, int skip_cert_refs, int skip_tags, int lean)
56495650
{
56505651
const char* oid = nvt_iterator_oid (nvts);
56515652
const char* name = nvt_iterator_name (nvts);
@@ -5658,9 +5659,8 @@ get_nvt_xml (iterator_t *nvts, int details, int pref_count,
56585659
{
56595660
int tag_count;
56605661
GString *refs_str, *tags_str, *buffer, *nvt_tags;
5661-
iterator_t cert_refs_iterator, tags, severities;
5662+
iterator_t cert_refs_iterator, tags;
56625663
gchar *tag_name_esc, *tag_value_esc, *tag_comment_esc;
5663-
char *default_timeout = nvt_default_timeout (oid);
56645664

56655665
DEF (family);
56665666
DEF (tag);
@@ -5811,77 +5811,95 @@ get_nvt_xml (iterator_t *nvts, int details, int pref_count,
58115811
g_string_append_printf (buffer,
58125812
"<nvt oid=\"%s\">"
58135813
"<name>%s</name>"
5814-
"<creation_time>%s</creation_time>"
5815-
"<modification_time>%s</modification_time>"
58165814
"%s" // user_tags
5817-
"<category>%d</category>"
5818-
"<family>%s</family>"
5819-
"<cvss_base>%s</cvss_base>"
5820-
"<severities score=\"%s\">",
5815+
"<preference_count>%i</preference_count>"
5816+
"<timeout>%s</timeout>",
58215817
oid,
58225818
name_text,
5823-
get_iterator_creation_time (nvts)
5824-
? get_iterator_creation_time (nvts)
5825-
: "",
5826-
get_iterator_modification_time (nvts)
5827-
? get_iterator_modification_time (nvts)
5828-
: "",
58295819
tags_str ? tags_str->str : "",
5830-
nvt_iterator_category (nvts),
5831-
family_text,
5832-
nvt_iterator_cvss_base (nvts)
5833-
? nvt_iterator_cvss_base (nvts)
5834-
: "",
5820+
pref_count,
5821+
timeout ? timeout : "");
5822+
5823+
if (lean == 0)
5824+
{
5825+
char *default_timeout;
5826+
5827+
default_timeout = nvt_default_timeout (oid);
5828+
g_string_append_printf (buffer,
5829+
"<default_timeout>%s</default_timeout>"
5830+
"<creation_time>%s</creation_time>"
5831+
"<modification_time>%s</modification_time>"
5832+
"<category>%d</category>"
5833+
"<family>%s</family>"
5834+
"<cvss_base>%s</cvss_base>"
5835+
"<qod>"
5836+
"<value>%s</value>"
5837+
"<type>%s</type>"
5838+
"</qod>"
5839+
"<refs>%s</refs>"
5840+
"<tags>%s</tags>",
5841+
default_timeout ? default_timeout : "",
5842+
get_iterator_creation_time (nvts)
5843+
? get_iterator_creation_time (nvts)
5844+
: "",
5845+
get_iterator_modification_time (nvts)
5846+
? get_iterator_modification_time (nvts)
5847+
: "",
5848+
nvt_iterator_category (nvts),
5849+
family_text,
5850+
nvt_iterator_cvss_base (nvts)
5851+
? nvt_iterator_cvss_base (nvts)
5852+
: "",
5853+
nvt_iterator_qod (nvts),
5854+
nvt_iterator_qod_type (nvts),
5855+
refs_str->str,
5856+
nvt_tags->str);
5857+
free (default_timeout);
5858+
}
5859+
5860+
g_string_append_printf (buffer,
5861+
"<severities score=\"%s\">",
58355862
nvt_iterator_cvss_base (nvts)
5836-
? nvt_iterator_cvss_base (nvts)
5837-
: "");
5863+
? nvt_iterator_cvss_base (nvts)
5864+
: "");
58385865

5839-
init_nvt_severity_iterator (&severities, oid);
5840-
while (next (&severities))
5866+
if (lean == 0)
58415867
{
5842-
buffer_xml_append_printf
5843-
(buffer,
5844-
"<severity type=\"%s\">"
5845-
"<origin>%s</origin>"
5846-
"<date>%s</date>"
5847-
"<score>%0.1f</score>"
5848-
"<value>%s</value>"
5849-
"</severity>",
5850-
nvt_severity_iterator_type (&severities),
5851-
nvt_severity_iterator_origin (&severities),
5852-
nvt_severity_iterator_date (&severities),
5853-
nvt_severity_iterator_score (&severities),
5854-
nvt_severity_iterator_value (&severities));
5868+
iterator_t severities;
5869+
5870+
init_nvt_severity_iterator (&severities, oid);
5871+
while (next (&severities))
5872+
{
5873+
buffer_xml_append_printf
5874+
(buffer,
5875+
"<severity type=\"%s\">"
5876+
"<origin>%s</origin>"
5877+
"<date>%s</date>"
5878+
"<score>%0.1f</score>"
5879+
"<value>%s</value>"
5880+
"</severity>",
5881+
nvt_severity_iterator_type (&severities),
5882+
nvt_severity_iterator_origin (&severities),
5883+
nvt_severity_iterator_date (&severities),
5884+
nvt_severity_iterator_score (&severities),
5885+
nvt_severity_iterator_value (&severities));
5886+
}
5887+
cleanup_iterator (&severities);
58555888
}
5856-
cleanup_iterator (&severities);
58575889

58585890
g_string_append_printf (buffer,
5859-
"</severities>"
5860-
"<qod>"
5861-
"<value>%s</value>"
5862-
"<type>%s</type>"
5863-
"</qod>"
5864-
"<refs>%s</refs>"
5865-
"<tags>%s</tags>"
5866-
"<preference_count>%i</preference_count>"
5867-
"<timeout>%s</timeout>"
5868-
"<default_timeout>%s</default_timeout>",
5869-
nvt_iterator_qod (nvts),
5870-
nvt_iterator_qod_type (nvts),
5871-
refs_str->str,
5872-
nvt_tags->str,
5873-
pref_count,
5874-
timeout ? timeout : "",
5875-
default_timeout ? default_timeout : "");
5891+
"</severities>");
5892+
58765893
g_free (family_text);
58775894
g_string_free (nvt_tags, 1);
58785895
g_string_free (refs_str, 1);
58795896
if (tags_str)
58805897
g_string_free (tags_str, 1);
58815898

5882-
if (nvt_iterator_solution (nvts) ||
5883-
nvt_iterator_solution_type (nvts) ||
5884-
nvt_iterator_solution_method (nvts))
5899+
if (lean == 0
5900+
&& (nvt_iterator_solution (nvts)
5901+
|| nvt_iterator_solution_type (nvts)
5902+
|| nvt_iterator_solution_method (nvts)))
58855903
{
58865904
buffer_xml_append_printf (buffer, "<solution");
58875905

@@ -5900,11 +5918,14 @@ get_nvt_xml (iterator_t *nvts, int details, int pref_count,
59005918
buffer_xml_append_printf (buffer, "/>");
59015919
}
59025920

5903-
59045921
if (preferences)
59055922
{
59065923
iterator_t prefs;
5907-
const char *nvt_oid = nvt_iterator_oid (nvts);
5924+
char *default_timeout;
5925+
const char *nvt_oid;
5926+
5927+
default_timeout = nvt_default_timeout (oid);
5928+
nvt_oid = nvt_iterator_oid (nvts);
59085929

59095930
/* Send the preferences for the NVT. */
59105931

@@ -5921,11 +5942,11 @@ get_nvt_xml (iterator_t *nvts, int details, int pref_count,
59215942
cleanup_iterator (&prefs);
59225943

59235944
xml_string_append (buffer, "</preferences>");
5945+
free (default_timeout);
59245946
}
59255947

59265948
xml_string_append (buffer, close_tag ? "</nvt>" : "");
59275949
msg = g_string_free (buffer, FALSE);
5928-
free (default_timeout);
59295950
}
59305951
else
59315952
{
@@ -6055,7 +6076,8 @@ manage_read_info (gchar *type, gchar *uid, gchar *name, gchar **result)
60556076
0, /* Config. */
60566077
1, /* Close tag. */
60576078
0, /* Skip CERT refs. */
6058-
0); /* Skip tags. */
6079+
0, /* Skip tags. */
6080+
0); /* Lean. */
60596081

60606082
cleanup_iterator (&nvts);
60616083
}

src/manage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,7 @@ void
19981998
xml_append_nvt_refs (GString *, const char *, int *);
19991999

20002000
gchar*
2001-
get_nvt_xml (iterator_t*, int, int, int, const char*, config_t, int, int, int);
2001+
get_nvt_xml (iterator_t*, int, int, int, const char*, config_t, int, int, int, int);
20022002

20032003
char*
20042004
task_preference_value (task_t, const char *);

0 commit comments

Comments
 (0)