Skip to content

Commit

Permalink
Collect hosts and operating systems during scanning, in a standalone
Browse files Browse the repository at this point in the history
	tables.  Also store a few "identifiers" used to recognise the host (ip,
	hostname, MAC-Ifaces, OS...).  Add OMP GET_ASSETS for these.

	* src/manage_sqlite3.c, src/manage_pg.c (create_tables): Add hosts,
	host_identifiers, oss and host_oss.

	* src/manage.c (finished_hosts_str, cve_scan_host): Rename
	init_host_iterator.

	* src/manage_sql.c (host_identify, host_notcie): New functions.
	(init_host_iterator): Remove.  Now init_report_host_iterator.
	(init_asset_iterator): Remove.  Now init_classic_asset_iterator.
	(asset_iterator_ip): Remove.  Now classic_asset_iterator_ip.
	(init_report_host_iterator, init_classic_asset_iterator)
	(classic_asset_iterator_ip): New.  Renamed.  Update callers.
	(identifiers, identifier_hosts): New variables.
	(identifier_t): New type.
	(identifier_free, hosts_set_identifiers): New functions.
	(manage_report_host_details): Rename "host" arg to "ip".  Add identifier
	information to global arrays.
	(init_host_identifier_iterator, host_identifier_iterator_value)
	(host_identifier_iterator_source_type)
	(host_identifier_iterator_source_id)
	(host_identifier_iterator_source_data, host_identifier_iterator_os_id)
	(host_identifier_iterator_os_title): New function.
	(HOST_ITERATOR_FILTER_COLUMNS, HOST_ITERATOR_COLUMNS)
	(OS_ITERATOR_FILTER_COLUMNS, OS_ITERATOR_COLUMNS): New define.
	(init_asset_host_iterator, asset_host_count, init_asset_os_iterator)
	(asset_os_iterator_title, asset_os_iterator_installs, asset_os_count)
	(total_asset_count): New functions.

	* src/manage.h: Update headers accordingly.
	(host_t): New type.

	* src/manage_sql.h: Add header accordingly.

	* src/otp.c (process_otp_scanner_input): Call host_notice when getting
	START_TIME, to store the host with IP identifier.  Call
	hosts_set_identifiers at the end of the scan to store the hosts and
	their identifiers from the global arrays.

	* src/omp.c (get_assets_data_t): New type.
	(get_assets_data_reset): New function.
	(command_data_t, client_state_t): Add GET_ASSETS entry.
	(get_assets_data): New variable.
	(omp_xml_handle_start_element, omp_xml_handle_end_element): Add
	GET_ASSETS.

git-svn-id: svn+ssh://scm.wald.intevation.org/openvas/trunk/openvas-manager@22973 423fd1db-d629-0410-8442-d21db03e70f4
  • Loading branch information
mattmundell committed Aug 5, 2015
1 parent 74a6556 commit aaceac7
Show file tree
Hide file tree
Showing 9 changed files with 1,224 additions and 33 deletions.
51 changes: 51 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
2015-08-05 Matthew Mundell <[email protected]>

Collect hosts and operating systems during scanning, in a standalone
tables. Also store a few "identifiers" used to recognise the host (ip,
hostname, MAC-Ifaces, OS...). Add OMP GET_ASSETS for these.

* src/manage_sqlite3.c, src/manage_pg.c (create_tables): Add hosts,
host_identifiers, oss and host_oss.

* src/manage.c (finished_hosts_str, cve_scan_host): Rename
init_host_iterator.

* src/manage_sql.c (host_identify, host_notcie): New functions.
(init_host_iterator): Remove. Now init_report_host_iterator.
(init_asset_iterator): Remove. Now init_classic_asset_iterator.
(asset_iterator_ip): Remove. Now classic_asset_iterator_ip.
(init_report_host_iterator, init_classic_asset_iterator)
(classic_asset_iterator_ip): New. Renamed. Update callers.
(identifiers, identifier_hosts): New variables.
(identifier_t): New type.
(identifier_free, hosts_set_identifiers): New functions.
(manage_report_host_details): Rename "host" arg to "ip". Add identifier
information to global arrays.
(init_host_identifier_iterator, host_identifier_iterator_value)
(host_identifier_iterator_source_type)
(host_identifier_iterator_source_id)
(host_identifier_iterator_source_data, host_identifier_iterator_os_id)
(host_identifier_iterator_os_title): New function.
(HOST_ITERATOR_FILTER_COLUMNS, HOST_ITERATOR_COLUMNS)
(OS_ITERATOR_FILTER_COLUMNS, OS_ITERATOR_COLUMNS): New define.
(init_asset_host_iterator, asset_host_count, init_asset_os_iterator)
(asset_os_iterator_title, asset_os_iterator_installs, asset_os_count)
(total_asset_count): New functions.

* src/manage.h: Update headers accordingly.
(host_t): New type.

* src/manage_sql.h: Add header accordingly.

* src/otp.c (process_otp_scanner_input): Call host_notice when getting
START_TIME, to store the host with IP identifier. Call
hosts_set_identifiers at the end of the scan to store the hosts and
their identifiers from the global arrays.

* src/omp.c (get_assets_data_t): New type.
(get_assets_data_reset): New function.
(command_data_t, client_state_t): Add GET_ASSETS entry.
(get_assets_data): New variable.
(omp_xml_handle_start_element, omp_xml_handle_end_element): Add
GET_ASSETS.

2015-08-05 Hani Benhabiles <[email protected]>

* src/manage.c (parse_osp_report): Adjust to detect when test_id is an
Expand Down
4 changes: 2 additions & 2 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ finished_hosts_str (report_t stopped_report)

if (stopped_report == 0)
return NULL;
init_host_iterator (&hosts, stopped_report, NULL, 0);
init_report_host_iterator (&hosts, stopped_report, NULL, 0);
while (next (&hosts))
{
const char *end_time = host_iterator_end_time (&hosts);
Expand Down Expand Up @@ -3163,7 +3163,7 @@ cve_scan_host (task_t task, openvas_host_t *openvas_host)

/* Get the report_host for the host. */

init_host_iterator (&report_hosts, 0, NULL, report_host);
init_report_host_iterator (&report_hosts, 0, NULL, report_host);
if (next (&report_hosts))
{
iterator_t prognosis;
Expand Down
53 changes: 51 additions & 2 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ typedef long long int config_t;
typedef long long int alert_t;
typedef long long int filter_t;
typedef long long int group_t;
typedef long long int host_t;
typedef long long int slave_t;
typedef long long int tag_t;
typedef long long int target_t;
Expand Down Expand Up @@ -1249,9 +1250,8 @@ result_iterator_qod_type (iterator_t*);
const char*
result_iterator_date (iterator_t*);


void
init_host_iterator (iterator_t*, report_t, const char *, report_host_t);
init_report_host_iterator (iterator_t*, report_t, const char *, report_host_t);

const char*
host_iterator_host (iterator_t*);
Expand Down Expand Up @@ -2026,6 +2026,55 @@ agent_iterator_howto_install (iterator_t*);
const char*
agent_iterator_howto_use (iterator_t*);


/* Assets. */

host_t
host_notice (const char *, const char *, const char *, const char *,
const char *);

void
init_host_identifier_iterator (iterator_t*, host_t, int, const char*);

const char*
host_identifier_iterator_value (iterator_t *);

const char*
host_identifier_iterator_source_type (iterator_t *);

const char*
host_identifier_iterator_source_id (iterator_t *);

const char*
host_identifier_iterator_source_data (iterator_t *);

const char*
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 *);

int
asset_host_count (const get_data_t *);

int
init_asset_os_iterator (iterator_t *, const get_data_t *);

const char*
asset_os_iterator_title (iterator_t *);

int
asset_os_iterator_installs (iterator_t *);

int
asset_os_count (const get_data_t *);

int
total_asset_count (const get_data_t *);


/* Notes. */

Expand Down
46 changes: 46 additions & 0 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,52 @@ create_tables ()
" \"group\" integer REFERENCES groups_trash (id) ON DELETE RESTRICT,"
" \"user\" integer REFERENCES users (id) ON DELETE RESTRICT);");

sql ("CREATE TABLE IF NOT EXISTS hosts"
" (id SERIAL PRIMARY KEY,"
" uuid text UNIQUE NOT NULL,"
" owner integer REFERENCES users (id) ON DELETE RESTRICT,"
" name text NOT NULL,"
" comment text,"
" creation_time integer,"
" modification_time integer);");

sql ("CREATE TABLE IF NOT EXISTS host_identifiers"
" (id SERIAL PRIMARY KEY,"
" uuid text UNIQUE NOT NULL,"
" host integer REFERENCES hosts (id) ON DELETE RESTRICT,"
" owner integer REFERENCES users (id) ON DELETE RESTRICT,"
" name text NOT NULL,"
" comment text,"
" value text NOT NULL,"
" source_type text NOT NULL,"
" source_id text NOT NULL,"
" source_data text NOT NULL,"
" creation_time integer,"
" modification_time integer);");

sql ("CREATE TABLE IF NOT EXISTS oss"
" (id SERIAL PRIMARY KEY,"
" uuid text UNIQUE NOT NULL,"
" owner integer REFERENCES users (id) ON DELETE RESTRICT,"
" name text NOT NULL,"
" comment text,"
" creation_time integer,"
" modification_time integer);");

sql ("CREATE TABLE IF NOT EXISTS host_oss"
" (id SERIAL PRIMARY KEY,"
" uuid text UNIQUE NOT NULL,"
" host integer REFERENCES hosts (id) ON DELETE RESTRICT,"
" owner integer REFERENCES users (id) ON DELETE RESTRICT,"
" name text NOT NULL,"
" comment text,"
" os integer REFERENCES oss (id) ON DELETE RESTRICT,"
" source_type text NOT NULL,"
" source_id text NOT NULL,"
" source_data text NOT NULL,"
" creation_time integer,"
" modification_time integer);");

sql ("CREATE TABLE IF NOT EXISTS roles"
" (id SERIAL PRIMARY KEY,"
" uuid text UNIQUE NOT NULL,"
Expand Down
Loading

0 comments on commit aaceac7

Please sign in to comment.