Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 0 additions & 6 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2275,9 +2275,6 @@ host_t
host_notice (const char *, const char *, const char *, const char *,
const char *, int, int);

int
init_asset_host_iterator (iterator_t *, const get_data_t *);

int
init_resource_names_host_iterator (iterator_t *iterator, get_data_t *get);

Expand All @@ -2287,9 +2284,6 @@ asset_iterator_writable (iterator_t *);
int
asset_iterator_in_use (iterator_t *);

const char*
asset_host_iterator_severity (iterator_t *);

int
asset_host_count (const get_data_t *);

Expand Down
8 changes: 8 additions & 0 deletions src/manage_assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef _GVMD_MANAGE_ASSETS_H
#define _GVMD_MANAGE_ASSETS_H

#include "manage_get.h"

char*
host_uuid (resource_t);

Expand Down Expand Up @@ -67,4 +69,10 @@ host_identifier_iterator_os_id (iterator_t *);
const char*
host_identifier_iterator_os_title (iterator_t *);

int
init_asset_host_iterator (iterator_t *, const get_data_t *);

const char *
asset_host_iterator_severity (iterator_t *);

#endif /* not _GVMD_MANAGE_ASSETS_H */
232 changes: 1 addition & 231 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -3911,7 +3911,7 @@ init_get_iterator2_with (iterator_t* iterator, const char *type,
* @return 0 success, 1 failed to find resource, 2 failed to find filter, -1
* error.
*/
static int
int
init_get_iterator2 (iterator_t* iterator, const char *type,
const get_data_t *get, column_t *select_columns,
column_t *trash_select_columns,
Expand Down Expand Up @@ -40917,226 +40917,6 @@ host_routes_xml (host_t host)
return g_string_free (buffer, FALSE);
}

/**
* @brief Filter columns for host iterator.
*/
#define HOST_ITERATOR_FILTER_COLUMNS \
{ GET_ITERATOR_FILTER_COLUMNS, "severity", "os", "oss", "hostname", "ip", \
"severity_level", "updated", "best_os_cpe", NULL }

/**
* @brief Host iterator columns.
*/
#define HOST_ITERATOR_COLUMNS \
{ \
GET_ITERATOR_COLUMNS (hosts), \
{ \
"1", \
"writable", \
KEYWORD_TYPE_INTEGER \
}, \
{ \
"0", \
"in_use", \
KEYWORD_TYPE_INTEGER \
}, \
{ \
"(SELECT round (CAST (severity AS numeric), 1)" \
" FROM host_max_severities" \
" WHERE host = hosts.id" \
" ORDER by creation_time DESC" \
" LIMIT 1)", \
"severity", \
KEYWORD_TYPE_DOUBLE \
}, \
{ \
"(SELECT CASE" \
" WHEN best_os_text LIKE '%[possible conflict]%'" \
" THEN best_os_text" \
" WHEN best_os_cpe IS NULL" \
" THEN '[unknown]'" \
" ELSE best_os_cpe" \
" END" \
" FROM (SELECT (SELECT value" \
" FROM (SELECT max (id) AS id" \
" FROM host_details" \
" WHERE host = hosts.id" \
" AND name = 'best_os_cpe')" \
" AS sub," \
" host_details" \
" WHERE sub.id = host_details.id)" \
" AS best_os_cpe," \
" (SELECT value" \
" FROM (SELECT max (id) AS id" \
" FROM host_details" \
" WHERE host = hosts.id" \
" AND name = 'best_os_text')" \
" AS sub," \
" host_details" \
" WHERE sub.id = host_details.id)" \
" AS best_os_text)" \
" AS vars)", \
"os", \
KEYWORD_TYPE_STRING \
}, \
{ \
"(SELECT group_concat (name, ', ') FROM oss" \
" WHERE id IN (SELECT distinct os FROM host_oss" \
" WHERE host = hosts.id))", \
"oss", \
KEYWORD_TYPE_INTEGER \
}, \
{ \
"(SELECT value" \
" FROM host_identifiers" \
" WHERE host = hosts.id" \
" AND name = 'hostname'" \
" ORDER by creation_time DESC" \
" LIMIT 1)", \
"hostname", \
KEYWORD_TYPE_STRING \
}, \
{ \
"(SELECT value" \
" FROM host_identifiers" \
" WHERE host = hosts.id" \
" AND name = 'ip'" \
" ORDER by creation_time DESC" \
" LIMIT 1)", \
"ip", \
KEYWORD_TYPE_STRING \
}, \
{ NULL, NULL, KEYWORD_TYPE_UNKNOWN } \
}

/**
* @brief Host iterator WHERE columns.
*/
#define HOST_ITERATOR_WHERE_COLUMNS \
{ \
{ \
"(SELECT severity_to_level (CAST (severity AS numeric), 0)" \
" FROM host_max_severities" \
" WHERE host = hosts.id" \
" ORDER by creation_time DESC" \
" LIMIT 1)", \
"severity_level", \
KEYWORD_TYPE_STRING \
}, \
{ \
"modification_time", "updated", KEYWORD_TYPE_INTEGER \
}, \
{ \
"(SELECT value" \
" FROM (SELECT max (id) AS id" \
" FROM host_details" \
" WHERE host = hosts.id" \
" AND name = 'best_os_cpe')" \
" AS sub, host_details" \
" WHERE sub.id = host_details.id)", \
"best_os_cpe", \
KEYWORD_TYPE_STRING \
}, \
{ NULL, NULL, KEYWORD_TYPE_UNKNOWN } \
}

/**
* @brief Extra WHERE clause for host assets.
*
* @param[in] filter Filter term.
*
* @return WHERE clause.
*/
static gchar*
asset_host_extra_where (const char *filter)
{
gchar *ret, *os_id;

os_id = filter_term_value (filter, "os_id");

if (os_id)
{
gchar *quoted_os_id = os_id ? sql_quote (os_id) : NULL;
ret = g_strdup_printf (" AND EXISTS"
" (SELECT * FROM host_oss"
" WHERE os = (SELECT id FROM oss"
" WHERE uuid = '%s')"
" AND host = hosts.id)",
quoted_os_id);
g_free (quoted_os_id);
}
else
ret = g_strdup ("");

g_free (os_id);

return ret;
}

/**
* @brief Initialise a host iterator.
*
* @param[in] iterator Iterator.
* @param[in] get GET data.
*
* @return 0 success, 1 failed to find host, 2 failed to find filter,
* -1 error.
*/
int
init_asset_host_iterator (iterator_t *iterator, const get_data_t *get)
{
static const char *filter_columns[] = HOST_ITERATOR_FILTER_COLUMNS;
static column_t columns[] = HOST_ITERATOR_COLUMNS;
static column_t where_columns[] = HOST_ITERATOR_WHERE_COLUMNS;

int ret;
gchar *filter, *extra_where;

// Get filter
if (get->filt_id && strcmp (get->filt_id, FILT_ID_NONE))
{
if (get->filter_replacement)
/* Replace the filter term with one given by the caller. This is
* used by GET_REPORTS to use the default filter with any task (when
* given the special value of -3 in filt_id). */
filter = g_strdup (get->filter_replacement);
else
filter = filter_term (get->filt_id);
if (filter == NULL)
{
return 1;
}
}
else
filter = NULL;

extra_where = asset_host_extra_where (filter ? filter : get->filter);

ret = init_get_iterator2 (iterator,
"host",
get,
/* Columns. */
columns,
/* Columns for trashcan. */
NULL,
/* WHERE Columns. */
where_columns,
/* WHERE Columns for trashcan. */
NULL,
filter_columns,
0,
NULL,
extra_where,
NULL,
TRUE,
FALSE,
NULL);

g_free (filter);
g_free (extra_where);
return ret;
}

/**
* @brief Initialise a host iterator for GET_RESOURCE_NAMES.
*
Expand Down Expand Up @@ -41204,16 +40984,6 @@ asset_iterator_in_use (iterator_t* iterator)
return iterator_int64 (iterator, GET_ITERATOR_COLUMN_COUNT + 1);
}

/**
* @brief Get the max severity from an asset host iterator.
*
* @param[in] iterator Iterator.
*
* @return The maximum severity of the host, or NULL if iteration is
* complete. Freed by cleanup_iterator.
*/
DEF_ACCESS (asset_host_iterator_severity, GET_ITERATOR_COLUMN_COUNT + 2);

/**
* @brief Count number of hosts.
*
Expand Down
6 changes: 6 additions & 0 deletions src/manage_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,12 @@ init_get_iterator (iterator_t*, const char *, const get_data_t *, column_t *,
column_t *, const char **, int, const char *, const char *,
int);

int
init_get_iterator2 (iterator_t *, const char *, const get_data_t *, column_t *,
column_t *, column_t *, column_t *, const char **, int,
const char *, const char *, const char *, int, int,
const char *);

int
openvasd_get_details_from_iterator (iterator_t *, char **, GSList **);

Expand Down
Loading
Loading