Skip to content

Commit 9acacdb

Browse files
mattmundellbjoernricks
authored andcommitted
Change: move alert_secinfo_count out of manage_sql.c
It's only used by condition_met, so put it in manage_events.c.
1 parent cf9fca9 commit 9acacdb

File tree

3 files changed

+76
-74
lines changed

3 files changed

+76
-74
lines changed

src/manage_events.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,74 @@
3535
*/
3636
#define G_LOG_DOMAIN "md manage"
3737

38+
/**
39+
* @brief Return the SecInfo count.
40+
*
41+
* @param[in] alert Alert.
42+
* @param[in] filter_id Condition filter id.
43+
*
44+
* @return 1 if met, else 0.
45+
*/
46+
static time_t
47+
alert_secinfo_count (alert_t alert, char *filter_id)
48+
{
49+
get_data_t get;
50+
int db_count, uuid_was_null;
51+
event_t event;
52+
gboolean get_modified;
53+
time_t feed_version_epoch;
54+
char *secinfo_type;
55+
56+
event = alert_event (alert);
57+
get_modified = (event == EVENT_UPDATED_SECINFO);
58+
59+
if (current_credentials.uuid == NULL)
60+
{
61+
current_credentials.uuid = alert_owner_uuid (alert);
62+
uuid_was_null = 1;
63+
}
64+
else
65+
uuid_was_null = 0;
66+
67+
memset (&get, '\0', sizeof (get));
68+
if (filter_id && strlen (filter_id) && strcmp (filter_id, "0"))
69+
get.filt_id = filter_id;
70+
71+
secinfo_type = alert_data (alert, "event", "secinfo_type");
72+
73+
if (strcmp (secinfo_type, "nvt") == 0)
74+
{
75+
feed_version_epoch = nvts_feed_version_epoch ();
76+
db_count = nvt_info_count_after (&get,
77+
feed_version_epoch,
78+
get_modified);
79+
}
80+
else if (strcmp (secinfo_type, "cert_bund_adv") == 0
81+
|| strcmp (secinfo_type, "dfn_cert_adv") == 0)
82+
{
83+
feed_version_epoch = cert_check_time ();
84+
db_count = secinfo_count_after (&get,
85+
secinfo_type,
86+
feed_version_epoch,
87+
get_modified);
88+
}
89+
else // assume SCAP data
90+
{
91+
feed_version_epoch = scap_check_time ();
92+
db_count = secinfo_count_after (&get,
93+
secinfo_type,
94+
feed_version_epoch,
95+
get_modified);
96+
}
97+
98+
if (uuid_was_null)
99+
{
100+
free (current_credentials.uuid);
101+
current_credentials.uuid = NULL;
102+
}
103+
104+
return db_count;
105+
}
38106

39107
/**
40108
* @brief Return whether the condition of an alert is met by a task.

src/manage_sql.c

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ nvts_check_time ()
900900
*
901901
* @return Last time SCAP was checked.
902902
*/
903-
static int
903+
int
904904
scap_check_time ()
905905
{
906906
return sql_int ("SELECT"
@@ -918,7 +918,7 @@ scap_check_time ()
918918
*
919919
* @return Last time CERT was checked.
920920
*/
921-
static int
921+
int
922922
cert_check_time ()
923923
{
924924
return sql_int ("SELECT"
@@ -13507,75 +13507,6 @@ escalate_2 (alert_t alert, task_t task, report_t report, event_t event,
1350713507
"Name Title\n" \
1350813508
"------------------------------------------------------------------------------------------\n"
1350913509

13510-
/**
13511-
* @brief Return the SecInfo count.
13512-
*
13513-
* @param[in] alert Alert.
13514-
* @param[in] filter_id Condition filter id.
13515-
*
13516-
* @return 1 if met, else 0.
13517-
*/
13518-
time_t
13519-
alert_secinfo_count (alert_t alert, char *filter_id)
13520-
{
13521-
get_data_t get;
13522-
int db_count, uuid_was_null;
13523-
event_t event;
13524-
gboolean get_modified;
13525-
time_t feed_version_epoch;
13526-
char *secinfo_type;
13527-
13528-
event = alert_event (alert);
13529-
get_modified = (event == EVENT_UPDATED_SECINFO);
13530-
13531-
if (current_credentials.uuid == NULL)
13532-
{
13533-
current_credentials.uuid = alert_owner_uuid (alert);
13534-
uuid_was_null = 1;
13535-
}
13536-
else
13537-
uuid_was_null = 0;
13538-
13539-
memset (&get, '\0', sizeof (get));
13540-
if (filter_id && strlen (filter_id) && strcmp (filter_id, "0"))
13541-
get.filt_id = filter_id;
13542-
13543-
secinfo_type = alert_data (alert, "event", "secinfo_type");
13544-
13545-
if (strcmp (secinfo_type, "nvt") == 0)
13546-
{
13547-
feed_version_epoch = nvts_feed_version_epoch ();
13548-
db_count = nvt_info_count_after (&get,
13549-
feed_version_epoch,
13550-
get_modified);
13551-
}
13552-
else if (strcmp (secinfo_type, "cert_bund_adv") == 0
13553-
|| strcmp (secinfo_type, "dfn_cert_adv") == 0)
13554-
{
13555-
feed_version_epoch = cert_check_time ();
13556-
db_count = secinfo_count_after (&get,
13557-
secinfo_type,
13558-
feed_version_epoch,
13559-
get_modified);
13560-
}
13561-
else // assume SCAP data
13562-
{
13563-
feed_version_epoch = scap_check_time ();
13564-
db_count = secinfo_count_after (&get,
13565-
secinfo_type,
13566-
feed_version_epoch,
13567-
get_modified);
13568-
}
13569-
13570-
if (uuid_was_null)
13571-
{
13572-
free (current_credentials.uuid);
13573-
current_credentials.uuid = NULL;
13574-
}
13575-
13576-
return db_count;
13577-
}
13578-
1357913510

1358013511
/* Task functions. */
1358113512

src/manage_sql.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@ int manage_cert_db_exists ();
482482

483483
int manage_scap_db_exists ();
484484

485+
int
486+
cert_check_time ();
487+
488+
int
489+
scap_check_time ();
490+
485491
int
486492
count (const char *, const get_data_t *, column_t *, column_t *, const char **,
487493
int, const char *, const char *, int);
@@ -531,9 +537,6 @@ event_alert_iterator_active (iterator_t *);
531537
int
532538
alert_applies_to_task (alert_t, task_t);
533539

534-
time_t
535-
alert_secinfo_count (alert_t, char *);
536-
537540
int
538541
task_second_last_report (task_t, report_t *);
539542

0 commit comments

Comments
 (0)