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

Fix SecInfo alert filter conditions (master) #971

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
3 changes: 3 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3488,6 +3488,9 @@ nvt_dfn_cert_adv_iterator_name (iterator_t*);

/* All SecInfo Data */

int
secinfo_count_after (const get_data_t *, const char *, time_t, gboolean);

void
init_ovaldi_file_iterator (iterator_t*);

Expand Down
32 changes: 28 additions & 4 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -14188,6 +14188,7 @@ alert_secinfo_count (alert_t alert, char *filter_id)
event_t event;
gboolean get_modified;
time_t feed_version_epoch;
char *secinfo_type;

event = alert_event (alert);
get_modified = (event == EVENT_UPDATED_SECINFO);
Expand All @@ -14204,10 +14205,33 @@ alert_secinfo_count (alert_t alert, char *filter_id)
if (filter_id && strlen (filter_id) && strcmp (filter_id, "0"))
get.filt_id = filter_id;

feed_version_epoch = nvts_feed_version_epoch ();
db_count = nvt_info_count_after (&get,
feed_version_epoch,
get_modified);
secinfo_type = alert_data (alert, "event", "secinfo_type");
printf ("secinfo_type: %s\n", secinfo_type);
timopollmeier marked this conversation as resolved.
Show resolved Hide resolved

if (strcmp (secinfo_type, "nvt") == 0)
{
feed_version_epoch = nvts_feed_version_epoch ();
db_count = nvt_info_count_after (&get,
feed_version_epoch,
get_modified);
}
else if (strcmp (secinfo_type, "cert_bund_adv") == 0
|| strcmp (secinfo_type, "dfn_cert_adv") == 0)
{
feed_version_epoch = cert_check_time ();
db_count = secinfo_count_after (&get,
secinfo_type,
feed_version_epoch,
get_modified);
}
else // assume SCAP data
{
feed_version_epoch = scap_check_time ();
db_count = secinfo_count_after (&get,
secinfo_type,
feed_version_epoch,
get_modified);
}

if (uuid_was_null)
{
Expand Down
187 changes: 187 additions & 0 deletions src/manage_sql_secinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,30 @@ inserts_run (inserts_t *inserts)

/* CPE data. */

/**
* @brief Gets the SELECT columns for CPE iterators and counts.
*
* @return The SELECT columns.
*/
static const column_t*
cpe_info_select_columns ()
{
static column_t columns[] = CPE_INFO_ITERATOR_COLUMNS;
return columns;
}

/**
* @brief Gets the filter columns for CPE iterators and counts.
*
* @return The filter columns.
*/
static const char **
cpe_info_filter_columns ()
{
static const char *filter_columns[] = CPE_INFO_ITERATOR_FILTER_COLUMNS;
return filter_columns;
}

/**
* @brief Count number of cpe.
*
Expand Down Expand Up @@ -547,6 +571,30 @@ DEF_ACCESS (cpe_info_iterator_nvd_id, GET_ITERATOR_COLUMN_COUNT + 5);

/* CVE data. */

/**
* @brief Gets the SELECT columns for CVE iterators and counts.
*
* @return The SELECT columns.
*/
static const column_t*
cve_info_select_columns ()
{
static column_t columns[] = CVE_INFO_ITERATOR_COLUMNS;
return columns;
}

/**
* @brief Gets the filter columns for CVE iterators and counts.
*
* @return The filter columns.
*/
static const char **
cve_info_filter_columns ()
{
static const char *filter_columns[] = CVE_INFO_ITERATOR_FILTER_COLUMNS;
return filter_columns;
}

/**
* @brief Initialise an CVE iterator, for CVEs reported for a certain CPE.
*
Expand Down Expand Up @@ -771,6 +819,30 @@ DEF_ACCESS (cve_info_iterator_description, GET_ITERATOR_COLUMN_COUNT + 8);

/* OVAL data. */

/**
* @brief Gets the SELECT columns for OVAL definition iterators and counts.
*
* @return The SELECT columns.
*/
static const column_t*
ovaldef_info_select_columns ()
{
static column_t columns[] = OVALDEF_INFO_ITERATOR_COLUMNS;
return columns;
}

/**
* @brief Gets the filter columns for OVAL definition iterators and counts.
*
* @return The filter columns.
*/
static const char **
ovaldef_info_filter_columns ()
{
static const char *filter_columns[] = OVALDEF_INFO_ITERATOR_FILTER_COLUMNS;
return filter_columns;
}

/**
* @brief Initialise an OVAL definition (ovaldef) info iterator.
*
Expand Down Expand Up @@ -1053,6 +1125,31 @@ ovaldef_cves (const char *id)

/* CERT-Bund data. */

/**
* @brief Gets the SELECT columns for CERT-Bund advisory iterators and counts.
*
* @return The SELECT columns.
*/
static const column_t*
cert_bund_adv_info_select_columns ()
{
static column_t columns[] = CERT_BUND_ADV_INFO_ITERATOR_COLUMNS;
return columns;
}

/**
* @brief Gets the filter columns for CERT-Bund advisory iterators and counts.
*
* @return The filter columns.
*/
static const char **
cert_bund_adv_info_filter_columns ()
{
static const char *filter_columns[]
= CERT_BUND_ADV_INFO_ITERATOR_FILTER_COLUMNS;
return filter_columns;
}

/**
* @brief Initialise an CERT-Bund advisory (cert_bund_adv) info iterator.
*
Expand Down Expand Up @@ -1236,6 +1333,31 @@ DEF_ACCESS (nvt_cert_bund_adv_iterator_name, 0);

/* DFN-CERT data. */

/**
* @brief Gets the SELECT columns for DFN-CERT advisory iterators and counts.
*
* @return The SELECT columns.
*/
static const column_t*
dfn_cert_adv_info_select_columns ()
{
static column_t columns[] = DFN_CERT_ADV_INFO_ITERATOR_COLUMNS;
return columns;
}

/**
* @brief Gets the filter columns for DFN-CERT advisory iterators and counts.
*
* @return The filter columns.
*/
static const char **
dfn_cert_adv_info_filter_columns ()
{
static const char *filter_columns[]
= DFN_CERT_ADV_INFO_ITERATOR_FILTER_COLUMNS;
return filter_columns;
}

/**
* @brief Initialise an DFN-CERT advisory (dfn_cert_adv) info iterator.
*
Expand Down Expand Up @@ -1415,6 +1537,71 @@ DEF_ACCESS (nvt_dfn_cert_adv_iterator_name, 0);

/* All SecInfo data. */

/**
* @brief Count number of SecInfo items created or modified after a given time.
*
* @param[in] get GET params.
* @param[in] count_time Time SecInfo must be created or modified after.
* @param[in] get_modified Whether to get the modification time.
*
* @return Total number of items in filtered set.
*/
int
secinfo_count_after (const get_data_t *get,
const char *type,
time_t count_time,
gboolean get_modified)
{
const char **filter_columns;
const column_t *columns;
gchar *extra_where;
int ret;

if (strcmp (type, "cpe") == 0)
{
columns = cpe_info_select_columns ();
filter_columns = cpe_info_filter_columns ();
}
else if (strcmp (type, "cve") == 0)
{
columns = cve_info_select_columns ();
filter_columns = cve_info_filter_columns ();
}
else if (strcmp (type, "ovaldef") == 0)
{
columns = ovaldef_info_select_columns ();
filter_columns = ovaldef_info_filter_columns ();
}
else if (strcmp (type, "cert_bund_adv") == 0)
{
columns = cert_bund_adv_info_select_columns ();
filter_columns = cert_bund_adv_info_filter_columns ();
}
else if (strcmp (type, "dfn_cert_adv") == 0)
{
columns = dfn_cert_adv_info_select_columns ();
filter_columns = dfn_cert_adv_info_filter_columns ();
}
else
{
g_warning ("%s: Unexpected type %s", __func__, type);
return 0;
}

if (get_modified)
extra_where = g_strdup_printf (" AND modification_time > %ld",
count_time);
else
extra_where = g_strdup_printf (" AND creation_time > %ld",
count_time);

ret = count (type, get, (column_t*)columns, NULL, filter_columns,
timopollmeier marked this conversation as resolved.
Show resolved Hide resolved
0, 0, extra_where, FALSE);

g_free (extra_where);
return ret;
}

/**
* @brief Initialise an ovaldi file iterator.
*
Expand Down