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 #2112

Merged
merged 23 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d18e6c1
Change: move GET iterator time conversion out of SQL
mattmundell Nov 20, 2023
82b6b6d
Free returns from time accessors
mattmundell Nov 20, 2023
ab20369
Remove iso_time from iterators that use the GET accessors
mattmundell Nov 20, 2023
8f52e13
Move iso_time to C for result_iterator_delta_creation_time
mattmundell Nov 22, 2023
b10666a
Move iso_time to C for result_iterator_delta_modification_time
mattmundell Nov 22, 2023
f06311c
Fix column keyword types
mattmundell Nov 22, 2023
5d0dfe6
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Dec 1, 2023
0b1edec
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Dec 11, 2023
1e1e147
Return time from get_iterator_creation_time and get_iterator_modifica…
mattmundell Dec 12, 2023
c1aa6f2
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Dec 12, 2023
70ed2c2
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Dec 18, 2023
05ae3c9
Remove creation and modification iso_time from result iterator
mattmundell Dec 18, 2023
03a951d
Remove creation and modification iso_time from note and override iter…
mattmundell Dec 18, 2023
3472888
Use integer for creation and modification columns in iterators
mattmundell Dec 18, 2023
f62db89
Keep columns unique
mattmundell Dec 18, 2023
cb983df
Work around clang-format limitation
mattmundell Jan 2, 2024
7a3c7ae
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Jan 15, 2024
59e2ef4
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Jan 22, 2024
a018f55
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Jan 22, 2024
a2d065f
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Feb 26, 2024
7c4373a
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Feb 27, 2024
469a03d
In iso_if_time also return empty if iso_time returns NULL
mattmundell Feb 27, 2024
be66e2e
Move iso_time to C for report_config iterator
mattmundell Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 74 additions & 29 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);
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);
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);
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);
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 @@ -9212,7 +9237,7 @@ buffer_results_xml (GString *buffer, iterator_t *results, task_t task,
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;
Expand All @@ -9221,6 +9246,7 @@ buffer_results_xml (GString *buffer, iterator_t *results, task_t task,
result_t result;
report_t report;
task_t selected_task;
gchar *creation_time;

comment = get_iterator_comment (results);
name = get_iterator_name (results);
Expand Down Expand Up @@ -9323,9 +9349,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 +11565,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 +11575,9 @@ handle_get_assets (gmp_parser_t *gmp_parser, GError **error)
else
name = NULL;

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

xml_string_append (result,
"<identifier id=\"%s\">"
"<name>%s</name>"
Expand All @@ -11561,8 +11593,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 +11605,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 +14627,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);
modification = get_iterator_modification_time (&reports);

/* Send the standard elements. Should match send_get_common. */
buffer_xml_append_printf
Expand All @@ -14615,12 +14653,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 +17930,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);
modification = get_iterator_modification_time (&vulns);

count ++;
SENDF_TO_CLIENT_OR_FAIL ("<vuln id=\"%s\">"
Expand All @@ -17904,11 +17946,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);
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);
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
4 changes: 2 additions & 2 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1560,10 +1560,10 @@ result_iterator_delta_uuid (iterator_t*);
const char *
result_iterator_delta_qod_type (iterator_t*);

const char *
gchar *
result_iterator_delta_creation_time (iterator_t*);

const char *
gchar *
result_iterator_delta_modification_time (iterator_t*);

task_t
Expand Down
Loading