Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: move GET iterator time conversion out of SQL #2111

Closed
Closed
110 changes: 77 additions & 33 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -8040,9 +8040,14 @@ buffer_notes_xml (GString *buffer, iterator_t *notes, int include_notes_details,

if (include_notes_details == 0)
{
const char *text = note_iterator_text (notes);
gchar *excerpt = utf8_substring (text, 0,
setting_excerpt_size_int ());
gchar *excerpt, *creation, *modification;
const char *text;

text = note_iterator_text (notes);
excerpt = utf8_substring (text, 0, setting_excerpt_size_int ());
creation = get_iterator_creation_time (notes, NULL);
modification = get_iterator_modification_time (notes);

/* This must match send_get_common. */
buffer_xml_append_printf (buffer,
"<owner><name>%s</name></owner>"
Expand All @@ -8063,15 +8068,17 @@ buffer_notes_xml (GString *buffer, iterator_t *notes, int include_notes_details,
note_iterator_nvt_oid (notes),
note_iterator_nvt_name (notes),
note_iterator_nvt_type (notes),
get_iterator_creation_time (notes),
get_iterator_modification_time (notes),
creation,
modification,
note_iterator_active (notes),
strlen (excerpt) < strlen (text),
excerpt,
((note_iterator_task (notes)
&& (uuid_task == NULL))
|| (note_iterator_result (notes)
&& (uuid_result == NULL))));
g_free (creation);
g_free (modification);

if (tag_count)
{
Expand All @@ -8092,6 +8099,7 @@ buffer_notes_xml (GString *buffer, iterator_t *notes, int include_notes_details,
int trash_task;
time_t end_time;
iterator_t tags;
gchar *creation, *modification;

if (uuid_task)
{
Expand All @@ -8105,6 +8113,8 @@ buffer_notes_xml (GString *buffer, iterator_t *notes, int include_notes_details,
}

end_time = note_iterator_end_time (notes);
creation = get_iterator_creation_time (notes, NULL);
modification = get_iterator_modification_time (notes);

/* This must match send_get_common. */
buffer_xml_append_printf
Expand Down Expand Up @@ -8132,8 +8142,8 @@ buffer_notes_xml (GString *buffer, iterator_t *notes, int include_notes_details,
note_iterator_nvt_oid (notes),
note_iterator_nvt_name (notes),
note_iterator_nvt_type (notes),
get_iterator_creation_time (notes),
get_iterator_modification_time (notes),
creation,
modification,
note_iterator_active (notes),
end_time > 1 ? iso_time (&end_time) : "",
note_iterator_text (notes),
Expand All @@ -8150,6 +8160,8 @@ buffer_notes_xml (GString *buffer, iterator_t *notes, int include_notes_details,
|| (note_iterator_result (notes) && (uuid_result == NULL))));

free (name_task);
g_free (creation);
g_free (modification);

if (include_result && uuid_result && note_iterator_result (notes))
{
Expand Down Expand Up @@ -8304,9 +8316,14 @@ buffer_overrides_xml (GString *buffer, iterator_t *overrides,

if (include_overrides_details == 0)
{
const char *text = override_iterator_text (overrides);
gchar *excerpt = utf8_substring (text, 0,
setting_excerpt_size_int ());
gchar *excerpt, *creation, *modification;
const char *text;

text = override_iterator_text (overrides);
excerpt = utf8_substring (text, 0, setting_excerpt_size_int ());
creation = get_iterator_creation_time (overrides, NULL);
modification = get_iterator_modification_time (overrides);

/* This must match send_get_common. */
buffer_xml_append_printf (buffer,
"<owner><name>%s</name></owner>"
Expand All @@ -8331,8 +8348,8 @@ buffer_overrides_xml (GString *buffer, iterator_t *overrides,
override_iterator_nvt_oid (overrides),
override_iterator_nvt_name (overrides),
override_iterator_nvt_type (overrides),
get_iterator_creation_time (overrides),
get_iterator_modification_time (overrides),
creation,
modification,
override_iterator_active (overrides),
strlen (excerpt) < strlen (text),
excerpt,
Expand All @@ -8349,6 +8366,9 @@ buffer_overrides_xml (GString *buffer, iterator_t *overrides,
|| (override_iterator_result (overrides)
&& (uuid_result == NULL))));

g_free (creation);
g_free (modification);

if (tag_count)
{
buffer_xml_append_printf (buffer,
Expand All @@ -8368,6 +8388,7 @@ buffer_overrides_xml (GString *buffer, iterator_t *overrides,
int trash_task;
time_t end_time;
iterator_t tags;
gchar *creation, *modification;

if (uuid_task)
{
Expand All @@ -8381,6 +8402,8 @@ buffer_overrides_xml (GString *buffer, iterator_t *overrides,
}

end_time = override_iterator_end_time (overrides);
creation = get_iterator_creation_time (overrides, NULL);
modification = get_iterator_modification_time (overrides);

/* This must match send_get_common. */
buffer_xml_append_printf
Expand Down Expand Up @@ -8411,8 +8434,8 @@ buffer_overrides_xml (GString *buffer, iterator_t *overrides,
override_iterator_nvt_oid (overrides),
override_iterator_nvt_name (overrides),
override_iterator_nvt_type (overrides),
get_iterator_creation_time (overrides),
get_iterator_modification_time (overrides),
creation,
modification,
override_iterator_active (overrides),
end_time > 1 ? iso_time (&end_time) : "",
override_iterator_text (overrides),
Expand All @@ -8433,6 +8456,8 @@ buffer_overrides_xml (GString *buffer, iterator_t *overrides,
|| (override_iterator_result (overrides) && (uuid_result == NULL))));

free (name_task);
g_free (creation);
g_free (modification);

if (include_result && uuid_result
&& override_iterator_result (overrides))
Expand Down Expand Up @@ -9211,13 +9236,12 @@ buffer_results_xml (GString *buffer, iterator_t *results, task_t task,
const char *delta_state, iterator_t *delta_results,
int changed, int cert_loaded, int lean, int use_delta_fields)
{

const char *descr, *name, *comment, *creation_time;
const char *descr, *name, *comment;
const char *severity, *original_severity, *original_level;
const char *host, *hostname, *result_id, *port, *path, *asset_id, *qod, *qod_type;
char *detect_oid, *detect_ref, *detect_cpe, *detect_loc, *detect_name;
double severity_double;
gchar *nl_descr, *nl_descr_escaped;
gchar *nl_descr, *nl_descr_escaped, *creation_time, *user_zone;
result_t result;
report_t report;
task_t selected_task;
Expand All @@ -9228,6 +9252,7 @@ buffer_results_xml (GString *buffer, iterator_t *results, task_t task,
port = result_iterator_port (results);
asset_id = NULL;

manage_current_user_info (&user_zone);
if (use_delta_fields)
{
descr = result_iterator_delta_description (results);
Expand Down Expand Up @@ -9256,15 +9281,15 @@ buffer_results_xml (GString *buffer, iterator_t *results, task_t task,
qod = result_iterator_qod (results);
qod_type = result_iterator_qod_type (results);
result = result_iterator_result (results);
creation_time = get_iterator_creation_time (results);
creation_time = get_iterator_creation_time (results, user_zone);
result_id = get_iterator_uuid (results);
path = result_iterator_path (results);
report = result_iterator_report (results);
hostname = result_iterator_hostname (results);
if (host)
asset_id = result_iterator_asset_host_id (results);
}

g_free (user_zone);

if (descr)
{
Expand Down Expand Up @@ -9323,9 +9348,12 @@ buffer_results_xml (GString *buffer, iterator_t *results, task_t task,
comment);

if (creation_time)
buffer_xml_append_printf (buffer,
"<creation_time>%s</creation_time>",
creation_time);
{
buffer_xml_append_printf (buffer,
"<creation_time>%s</creation_time>",
creation_time);
g_free (creation_time);
}

if (include_details)
{
Expand Down Expand Up @@ -11536,7 +11564,7 @@ handle_get_assets (gmp_parser_t *gmp_parser, GError **error)
while (next (&identifiers))
{
const char *source_type;
gchar *name;
gchar *name, *creation, *modification;

source_type = host_identifier_iterator_source_type
(&identifiers);
Expand All @@ -11546,6 +11574,9 @@ handle_get_assets (gmp_parser_t *gmp_parser, GError **error)
else
name = NULL;

creation = get_iterator_creation_time (&identifiers, NULL);
modification = get_iterator_modification_time (&identifiers);

xml_string_append (result,
"<identifier id=\"%s\">"
"<name>%s</name>"
Expand All @@ -11561,8 +11592,8 @@ handle_get_assets (gmp_parser_t *gmp_parser, GError **error)
get_iterator_uuid (&identifiers),
get_iterator_name (&identifiers),
host_identifier_iterator_value (&identifiers),
get_iterator_creation_time (&identifiers),
get_iterator_modification_time (&identifiers),
creation,
modification,
host_identifier_iterator_source_id
(&identifiers),
source_type,
Expand All @@ -11573,6 +11604,8 @@ handle_get_assets (gmp_parser_t *gmp_parser, GError **error)
name ? name : "");

g_free (name);
g_free (creation);
g_free (modification);

if (strcmp (get_iterator_name (&identifiers), "OS") == 0)
xml_string_append (result,
Expand Down Expand Up @@ -14593,6 +14626,10 @@ handle_get_reports (gmp_parser_t *gmp_parser, GError **error)
if (get_reports_data->alert_id == NULL)
{
task_t task;
gchar *creation, *modification;

creation = get_iterator_creation_time (&reports, NULL);
modification = get_iterator_modification_time (&reports);

/* Send the standard elements. Should match send_get_common. */
buffer_xml_append_printf
Expand All @@ -14615,12 +14652,12 @@ handle_get_reports (gmp_parser_t *gmp_parser, GError **error)
get_iterator_comment (&reports)
? get_iterator_comment (&reports)
: "",
get_iterator_creation_time (&reports)
? get_iterator_creation_time (&reports)
: "",
get_iterator_modification_time (&reports)
? get_iterator_modification_time (&reports)
: "");
creation ? creation : "",
modification ? creation : "");

g_free (creation);
g_free (modification);

/* Send short task and report format info */
report_task (report, &task);
if (task)
Expand Down Expand Up @@ -17892,6 +17929,10 @@ handle_get_vulns (gmp_parser_t *gmp_parser, GError **error)
while (next (&vulns))
{
time_t oldest, newest;
gchar *creation, *modification;

creation = get_iterator_creation_time (&vulns, NULL);
modification = get_iterator_modification_time (&vulns);

count ++;
SENDF_TO_CLIENT_OR_FAIL ("<vuln id=\"%s\">"
Expand All @@ -17904,11 +17945,14 @@ handle_get_vulns (gmp_parser_t *gmp_parser, GError **error)
get_iterator_uuid (&vulns),
get_iterator_name (&vulns),
vuln_iterator_type (&vulns),
get_iterator_creation_time (&vulns),
get_iterator_modification_time (&vulns),
creation,
modification,
vuln_iterator_severity (&vulns),
vuln_iterator_qod (&vulns));

g_free (creation);
g_free (modification);

// results for the vulnerability
oldest = vuln_iterator_oldest (&vulns);
SENDF_TO_CLIENT_OR_FAIL ("<results>"
Expand Down
15 changes: 9 additions & 6 deletions src/gmp_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,13 @@ send_get_common (const char *type, get_data_t *get, iterator_t *iterator,
const char *tag_type;
iterator_t tags;
int tag_count;
gchar *creation, *modification;

buffer = g_string_new ("");

creation = get_iterator_creation_time (iterator, NULL);
modification = get_iterator_modification_time (iterator);

buffer_xml_append_printf (buffer,
"<%s id=\"%s\">"
"<owner><name>%s</name></owner>"
Expand All @@ -342,15 +346,14 @@ send_get_common (const char *type, get_data_t *get, iterator_t *iterator,
get_iterator_comment (iterator)
? get_iterator_comment (iterator)
: "",
get_iterator_creation_time (iterator)
? get_iterator_creation_time (iterator)
: "",
get_iterator_modification_time (iterator)
? get_iterator_modification_time (iterator)
: "",
creation ? creation : "",
modification ? modification : "",
writable,
in_use);

g_free (creation);
g_free (modification);

if (/* The user is the owner. */
(current_credentials.username
&& get_iterator_owner_name (iterator)
Expand Down
15 changes: 9 additions & 6 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -5771,6 +5771,7 @@ get_nvt_xml (iterator_t *nvts, int details, int pref_count,
{
char *default_timeout;
GString *nvt_tags;
gchar *creation, *modification;

DEF (tag);

Expand Down Expand Up @@ -5830,6 +5831,9 @@ get_nvt_xml (iterator_t *nvts, int details, int pref_count,
}

default_timeout = nvt_default_timeout (oid);
creation = get_iterator_creation_time (nvts, NULL);
modification = get_iterator_modification_time (nvts);

g_string_append_printf (buffer,
"<default_timeout>%s</default_timeout>"
"<creation_time>%s</creation_time>"
Expand All @@ -5843,19 +5847,18 @@ get_nvt_xml (iterator_t *nvts, int details, int pref_count,
"<refs>%s</refs>"
"<tags>%s</tags>",
default_timeout ? default_timeout : "",
get_iterator_creation_time (nvts)
? get_iterator_creation_time (nvts)
: "",
get_iterator_modification_time (nvts)
? get_iterator_modification_time (nvts)
: "",
creation ? creation : "",
modification ? modification : "",
nvt_iterator_category (nvts),
family_text,
nvt_iterator_qod (nvts),
nvt_iterator_qod_type (nvts),
refs_str->str,
nvt_tags->str);

free (default_timeout);
g_free (creation);
g_free (modification);

g_string_free (nvt_tags, 1);
}
Expand Down
Loading