[Openvas-commits] r11561 - in trunk/openvas-manager: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Sep 5 21:15:43 CEST 2011
Author: mattm
Date: 2011-09-05 21:15:40 +0200 (Mon, 05 Sep 2011)
New Revision: 11561
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/manage.h
trunk/openvas-manager/src/manage_sql.c
trunk/openvas-manager/src/omp.c
Log:
Add host and pos args to GET_REPORTS.
* src/manage_sql.c (host_last_report_host): Remove for rename.
(host_nthlast_report_host): New function. Was host_last_report_host.
Add pos arg.
(print_report_xml): Add host and pos host args, for getting single host
and for specifying which report to use. Update callers.
(manage_send_report): Add host and pos host args.
* src/manage.h: Update header accordingly.
* src/omp.c (get_reports_data_t, get_reports_data_reset): Add host and
pos.
(omp_xml_handle_start_element, omp_xml_handle_end_element): Add host and
pos to GET_REPORTS.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2011-09-05 17:14:52 UTC (rev 11560)
+++ trunk/openvas-manager/ChangeLog 2011-09-05 19:15:40 UTC (rev 11561)
@@ -1,3 +1,21 @@
+2011-09-05 Matthew Mundell <matthew.mundell at greenbone.net>
+
+ Add host and pos args to GET_REPORTS.
+
+ * src/manage_sql.c (host_last_report_host): Remove for rename.
+ (host_nthlast_report_host): New function. Was host_last_report_host.
+ Add pos arg.
+ (print_report_xml): Add host and pos host args, for getting single host
+ and for specifying which report to use. Update callers.
+ (manage_send_report): Add host and pos host args.
+
+ * src/manage.h: Update header accordingly.
+
+ * src/omp.c (get_reports_data_t, get_reports_data_reset): Add host and
+ pos.
+ (omp_xml_handle_start_element, omp_xml_handle_end_element): Add host and
+ pos to GET_REPORTS.
+
2011-09-05 Henri Doreau <henri.doreau at greenbone.net>
Generate the openvas-scapdata-sync script at compile time, with the
Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h 2011-09-05 17:14:52 UTC (rev 11560)
+++ trunk/openvas-manager/src/manage.h 2011-09-05 19:15:40 UTC (rev 11561)
@@ -810,7 +810,8 @@
const char *, const char *, const char *, int,
const char *, int, int, int, int, int, int, int,
gboolean (*) (const char *, int (*) (void*), void*),
- int (*) (void*), void *, const char *, const char *);
+ int (*) (void*), void *, const char *, const char *,
+ const char *, int);
/* RC's. */
Modified: trunk/openvas-manager/src/manage_sql.c
===================================================================
--- trunk/openvas-manager/src/manage_sql.c 2011-09-05 17:14:52 UTC (rev 11560)
+++ trunk/openvas-manager/src/manage_sql.c 2011-09-05 19:15:40 UTC (rev 11561)
@@ -14258,20 +14258,28 @@
}
/**
- * @brief Free delta host ports.
+ * @brief Get N'th last report_host given a host.
*
+ * The last report_host is at position 1, the second last at position 2, and
+ * so on.
+ *
* @param[in] host Host.
* @param[in] report_host Report host.
+ * @param[in] position Position from end.
*/
static gboolean
-host_last_report_host (const char *host, report_host_t *report_host)
+host_nthlast_report_host (const char *host, report_host_t *report_host,
+ int position)
{
gchar *quoted_host;
assert (current_credentials.uuid);
+ if (position == 0)
+ position = 1;
+
quoted_host = sql_quote (host);
- switch (sql_int64 (report_host, 0, 0,
+ switch (sql_int64 (report_host, 0, position - 1,
"SELECT ROWID FROM report_hosts WHERE host = '%s'"
" AND (SELECT reports.owner FROM reports"
" WHERE reports.ROWID = report_hosts.report)"
@@ -14284,10 +14292,11 @@
" AND (SELECT reports.scan_run_status FROM reports"
" WHERE reports.ROWID = report_hosts.report)"
" = %u"
- " ORDER BY ROWID DESC LIMIT 1;",
- host,
+ " ORDER BY ROWID DESC LIMIT %i;",
+ quoted_host,
current_credentials.uuid,
- TASK_STATUS_DONE))
+ TASK_STATUS_DONE,
+ position))
{
case 0:
break;
@@ -14516,6 +14525,9 @@
* indexed.
* @param[in] max_results The maximum number of results returned.
* @param[in] type Type of report, NULL, "scan" or "assets".
+ * @param[in] host Host or NULL, when type "assets".
+ * @param[in] pos Position of report from end, when type
+ * "assets".
*
* @return 0 on success, -1 error.
*/
@@ -14526,7 +14538,8 @@
const char *levels, const char *delta_states,
int apply_overrides, const char *search_phrase, int notes,
int notes_details, int overrides, int overrides_details,
- int first_result, int max_results, const char *type)
+ int first_result, int max_results, const char *type,
+ const char *host, int pos)
{
FILE *out;
char *uuid, *tsk_uuid = NULL, *start_time, *end_time;
@@ -14727,32 +14740,46 @@
if (type && (strcmp (type, "assets") == 0))
{
iterator_t hosts;
- init_asset_iterator (&hosts, first_result, max_results, levels,
- search_phrase);
- PRINT (out,
- "<host_count>"
- "<full>%i</full>"
- "<filtered>%i</filtered>"
- "</host_count>",
- host_count (),
- filtered_host_count (levels, search_phrase));
- PRINT (out,
- "<hosts start=\"%i\" max=\"%i\"/>",
- /* Add 1 for 1 indexing. */
- first_result + 1,
- max_results);
- while (next (&hosts))
+ if (host)
{
+ PRINT (out,
+ "<host_count>"
+ "<full>1</full>"
+ "<filtered>1</filtered>"
+ "</host_count>"
+ "<hosts start=\"1\" max=\"1\"/>");
+ }
+ else
+ {
+ init_asset_iterator (&hosts, first_result, max_results, levels,
+ search_phrase);
+ PRINT (out,
+ "<host_count>"
+ "<full>%i</full>"
+ "<filtered>%i</filtered>"
+ "</host_count>",
+ host_count (),
+ filtered_host_count (levels, search_phrase));
+ PRINT (out,
+ "<hosts start=\"%i\" max=\"%i\"/>",
+ /* Add 1 for 1 indexing. */
+ first_result + 1,
+ max_results);
+ }
+
+ while (host || next (&hosts))
+ {
iterator_t report_hosts;
report_host_t report_host;
const char *ip;
- ip = asset_iterator_ip (&hosts);
+ ip = host ? host : asset_iterator_ip (&hosts);
- if (host_last_report_host (ip, &report_host))
+ if (host_nthlast_report_host (ip, &report_host, pos))
{
- cleanup_iterator (&hosts);
+ if (host == NULL)
+ cleanup_iterator (&hosts);
return -1;
}
@@ -14781,7 +14808,7 @@
"<source>"
"<type></type>"
"<name>openvasmd</name>"
- "<description>UUID of latest report</description>"
+ "<description>UUID of current report</description>"
"</source>"
"</detail>",
host_iterator_report_uuid (&report_hosts));
@@ -14859,13 +14886,29 @@
report_host_details_iterator_source_name (&details),
report_host_details_iterator_source_desc (&details));
cleanup_iterator (&details);
+
+ PRINT (out,
+ "<detail>"
+ "<name>report/pos</name>"
+ "<value>%i</value>"
+ "<source>"
+ "<type></type>"
+ "<name>openvasmd</name>"
+ "<description>Position of report from end</description>"
+ "</source>"
+ "</detail>",
+ pos);
}
+
+ PRINT (out,
+ "</host>");
}
- PRINT (out,
- "</host>");
+ if (host)
+ break;
}
- cleanup_iterator (&hosts);
+ if (host == NULL)
+ cleanup_iterator (&hosts);
PRINT (out, "</report>");
@@ -16008,7 +16051,7 @@
result_hosts_only, min_cvss_base, report_format,
levels, NULL, apply_overrides, search_phrase, notes,
notes_details, overrides, overrides_details,
- first_result, max_results, type))
+ first_result, max_results, type, NULL, 0))
{
g_free (xml_file);
return NULL;
@@ -16415,6 +16458,9 @@
* instead of getting report. NULL to get
* report.
* @param[in] type Type of report: NULL, "scan" or "assets".
+ * @param[in] host Host or NULL, when type "assets".
+ * @param[in] pos Position of report from end, when host. 1 for
+ * last.
*
* @return 0 success, -1 error, 1 failed to find escalator.
*/
@@ -16430,7 +16476,8 @@
int base64,
gboolean (*send) (const char *, int (*) (void*), void*),
int (*send_data_1) (void*), void *send_data_2,
- const char *escalator_id, const char *type)
+ const char *escalator_id, const char *type,
+ const char *host, int pos)
{
task_t task;
gchar *xml_file;
@@ -16486,7 +16533,8 @@
sort_field, result_hosts_only, min_cvss_base,
report_format, levels, delta_states, apply_overrides,
search_phrase, notes, notes_details, overrides,
- overrides_details, first_result, max_results, type))
+ overrides_details, first_result, max_results, type,
+ host, pos))
{
g_free (xml_file);
return -1;
Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c 2011-09-05 17:14:52 UTC (rev 11560)
+++ trunk/openvas-manager/src/omp.c 2011-09-05 19:15:40 UTC (rev 11561)
@@ -1795,6 +1795,8 @@
int overrides_details; ///< Boolean. Whether to include details of above.
int result_hosts_only; ///< Boolean. Whether to include only resulted hosts.
char *type; ///< Type of report.
+ char *host; ///< Host for asset report.
+ char *pos; ///< Position of report from end.
} get_reports_data_t;
/**
@@ -1815,6 +1817,8 @@
free (data->search_phrase);
free (data->min_cvss_base);
free (data->type);
+ free (data->host);
+ free (data->pos);
memset (data, 0, sizeof (get_reports_data_t));
}
@@ -4299,6 +4303,16 @@
else
get_reports_data->type = g_strdup ("scan");
+ append_attribute (attribute_names,
+ attribute_values,
+ "host",
+ &get_reports_data->host);
+
+ append_attribute (attribute_names,
+ attribute_values,
+ "pos",
+ &get_reports_data->pos);
+
set_client_state (CLIENT_GET_REPORTS);
}
else if (strcasecmp ("GET_REPORT_FORMATS", element_name) == 0)
@@ -9844,7 +9858,7 @@
if (strcmp (get_reports_data->type, "assets") == 0)
{
gchar *extension, *content_type;
- int ret;
+ int ret, pos;
/* An asset report. */
@@ -9864,6 +9878,7 @@
g_free (extension);
g_free (content_type);
+ pos = get_reports_data->pos ? atoi (get_reports_data->pos) : 1;
ret = manage_send_report (0,
0,
report_format,
@@ -9889,7 +9904,9 @@
write_to_client,
write_to_client_data,
get_reports_data->escalator_id,
- "assets");
+ "assets",
+ get_reports_data->host,
+ pos);
if (ret)
{
@@ -9960,7 +9977,9 @@
write_to_client,
write_to_client_data,
get_reports_data->escalator_id,
- get_reports_data->type);
+ get_reports_data->type,
+ NULL,
+ 0);
if (ret)
{
if (get_reports_data->escalator_id)
More information about the Openvas-commits
mailing list