diff --git a/src/gmp.c b/src/gmp.c index 6e8840e2e..e8230922e 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -5555,6 +5555,14 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context, else get_reports_data->ignore_pagination = 0; + if (find_attribute (attribute_names, attribute_values, + "usage_type", &attribute)) + { + get_data_set_extra (&get_reports_data->report_get, + "usage_type", + attribute); + } + set_client_state (CLIENT_GET_REPORTS); } else if (strcasecmp ("GET_REPORT_CONFIGS", element_name) == 0) @@ -14818,7 +14826,7 @@ handle_get_reports (gmp_parser_t *gmp_parser, GError **error) || (strlen (get_reports_data->report_get.id) == 0)) { int overrides, min_qod; - gchar *filter, *levels; + gchar *filter, *levels, *compliance_levels; get_data_t * get; /* For simplicity, use a fixed result filter when filtering @@ -14840,13 +14848,22 @@ handle_get_reports (gmp_parser_t *gmp_parser, GError **error) overrides = filter_term_apply_overrides (filter ? filter : get->filter); min_qod = filter_term_min_qod (filter ? filter : get->filter); levels = filter_term_value (filter ? filter : get->filter, "levels"); + compliance_levels = filter_term_value (filter + ? filter + : get->filter, + "compliance_levels"); g_free (filter); /* Setup result filter from overrides. */ get_reports_data->get.filter - = g_strdup_printf ("apply_overrides=%i min_qod=%i levels=%s", - overrides, min_qod, levels ? levels : "hmlgdf"); + = g_strdup_printf + ("apply_overrides=%i min_qod=%i levels=%s compliance_levels=%s", + overrides, + min_qod, + levels ? levels : "hmlgdf", + compliance_levels ? compliance_levels : "yniu"); g_free (levels); + g_free (compliance_levels); } ret = init_report_iterator (&reports, &get_reports_data->report_get); @@ -16252,6 +16269,7 @@ handle_get_results (gmp_parser_t *gmp_parser, GError **error) NULL, /* result_hosts_only */ NULL, /* min_qod */ NULL, /* levels */ + NULL, /* compliance_levels */ NULL, /* delta_states */ NULL, /* search_phrase */ NULL, /* search_phrase_exact */ @@ -18266,7 +18284,8 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error) report_compliance_by_uuid (last_report_id, &compliance_yes, &compliance_no, - &compliance_incomplete); + &compliance_incomplete, + NULL); last_report = g_strdup_printf ("" diff --git a/src/manage.h b/src/manage.h index 891b3a0c7..dfa832808 100644 --- a/src/manage.h +++ b/src/manage.h @@ -838,6 +838,9 @@ set_task_hosts_ordering (task_t, const char *); void set_task_scanner (task_t, scanner_t); +int +task_usage_type (task_t, char**); + void set_task_usage_type (task_t, const char *); @@ -1328,7 +1331,7 @@ gboolean report_task (report_t, task_t*); void -report_compliance_by_uuid (const char *, int *, int *, int *); +report_compliance_by_uuid (const char *, int *, int *, int *, int *); int report_scan_result_count (report_t, const char*, const char*, int, const char*, @@ -1724,8 +1727,8 @@ manage_filter_controls (const gchar *, int *, int *, gchar **, int *); void manage_report_filter_controls (const gchar *, int *, int *, gchar **, int *, - int *, gchar **, gchar **, gchar **, gchar **, - int *, int *, int *, int *, gchar **); + int *, gchar **, gchar **, gchar **, gchar **, + gchar **, int *, int *, int *, int *, gchar **); gchar * manage_clean_filter (const gchar *); diff --git a/src/manage_pg.c b/src/manage_pg.c index 1f513344e..b9d008142 100644 --- a/src/manage_pg.c +++ b/src/manage_pg.c @@ -895,7 +895,44 @@ manage_create_sql_functions () "$$ LANGUAGE plpgsql" " IMMUTABLE;"); - /* Functions in SQL. */ + sql ("CREATE OR REPLACE FUNCTION compliance_status (" + " report_id integer)" + "RETURNS text AS $$ " + "BEGIN" + " CASE" + " WHEN (SELECT count(*) FROM results" + " WHERE report = report_id" + " AND description LIKE 'Compliant:%%NO%%') > 0" + " THEN RETURN 'no';" + " WHEN (SELECT count(*) FROM results" + " WHERE report = report_id" + " AND description LIKE 'Compliant:%%INCOMPLETE%%') > 0" + " THEN RETURN 'incomplete';" + " WHEN (SELECT count(*) FROM results" + " WHERE report = report_id" + " AND description LIKE 'Compliant:%%YES%%') > 0" + " THEN RETURN 'yes';" + " ELSE RETURN 'undefined';" + " END CASE;" + "END;" + "$$ LANGUAGE plpgsql" + " IMMUTABLE;"); + + sql ("CREATE OR REPLACE FUNCTION compliance_count (report_id integer, compliance text)" + " RETURNS integer AS $$" + " DECLARE count integer := 0;" + " BEGIN" + " WITH compliance_count AS" + " (SELECT count(*) AS total FROM results WHERE report = report_id" + " AND description LIKE 'Compliant:%%' || compliance || '%%')" + " SELECT total FROM compliance_count" + " INTO count;" + " RETURN count;" + " END;" + " $$ LANGUAGE plpgsql" + " IMMUTABLE;"); + + /* Functions in SQL. */ if (sql_int ("SELECT (EXISTS (SELECT * FROM information_schema.tables" " WHERE table_catalog = '%s'" diff --git a/src/manage_sql.c b/src/manage_sql.c index 5c1e760eb..d498e8fbe 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -294,6 +294,9 @@ cache_all_permissions_for_users (GArray*); static void report_cache_counts (report_t, int, int, const char*); +static gchar * +reports_extra_where (int, const char *, const char *); + static int report_host_dead (report_host_t); @@ -2033,7 +2036,13 @@ filter_control_str (keyword_t **point, const char *column, gchar **string) * results if NULL. * @param[out] levels String describing threat levels (message types) * to include in count (for example, "hmlg" for - * High, Medium, Low and loG). All levels if NULL. + * High, Medium, Low and loG). All levels if NULL. + * @param[out] comliance_levels String describing compliance levels + * to include in count (for example, "yniu" for + * "yes" (compliant), "n" for "no" (not compliant), + * "i" for "incomplete" and "u" for "undefined" + * (without compliance information). + * All levels if NULL. * @param[out] delta_states String describing delta states to include in count * (for example, "sngc" Same, New, Gone and Changed). * All levels if NULL. @@ -2049,10 +2058,11 @@ void manage_report_filter_controls (const gchar *filter, int *first, int *max, gchar **sort_field, int *sort_order, int *result_hosts_only, gchar **min_qod, - gchar **levels, gchar **delta_states, - gchar **search_phrase, int *search_phrase_exact, - int *notes, int *overrides, - int *apply_overrides, gchar **zone) + gchar **levels, gchar **compliance_levels, + gchar **delta_states, gchar **search_phrase, + int *search_phrase_exact, int *notes, + int *overrides, int *apply_overrides, + gchar **zone) { keyword_t **point; array_t *split; @@ -2211,6 +2221,16 @@ manage_report_filter_controls (const gchar *filter, int *first, int *max, else *apply_overrides = val; } + + if (compliance_levels) + { + if (filter_control_str ((keyword_t **) split->pdata, + "compliance_levels", + &string)) + *compliance_levels = NULL; + else + *compliance_levels = string; + } if (delta_states) { @@ -17781,9 +17801,8 @@ resource_count (const char *type, const get_data_t *get) } else if (strcmp (type, "report") == 0) { - extra_where = g_strdup (" AND (SELECT hidden FROM tasks" - " WHERE tasks.id = task)" - " = 0"); + const gchar *usage_type = get_data_get_extra (get, "usage_type"); + extra_where = reports_extra_where (0, NULL, usage_type); } else if (strcmp (type, "result") == 0) { @@ -18242,6 +18261,25 @@ task_scanner_in_trash (task_t task) " FROM tasks WHERE id = %llu;", task); } +/** + * @brief Return the usage type of a task. + * + * @param[in] task Task. + * @param[out] usage_type Pointer to a newly allocated string. + * + * @return 0 if successful, -1 otherwise. + */ +int +task_usage_type (task_t task, char ** usage_type) +{ + *usage_type = sql_string ("SELECT usage_type FROM tasks WHERE id = %llu;", + task); + if (usage_type == NULL) + return -1; + + return 0; +} + /** * @brief Set the usage_type of a task. * @@ -21483,12 +21521,14 @@ report_task (report_t report, task_t *task) * @param[out] compliance_yes Number of "YES" results. * @param[out] compliance_no Number of "NO" results. * @param[out] compliance_incomplete Number of "INCOMPLETE" results. + * @param[out] compliance_undefined Number of "UNDEFINED" results. */ void report_compliance_by_uuid (const char *report_id, int *compliance_yes, int *compliance_no, - int *compliance_incomplete) + int *compliance_incomplete, + int *compliance_undefined) { report_t report; gchar *quoted_uuid = sql_quote (report_id); @@ -21522,6 +21562,14 @@ report_compliance_by_uuid (const char *report_id, " AND description LIKE 'Compliant:%%INCOMPLETE%%';", report); } + if (compliance_undefined) + { + *compliance_undefined + = sql_int ("SELECT count(*) FROM results" + " WHERE report = %llu" + " AND description NOT LIKE 'Compliant:%%';", + report); + } g_free (quoted_uuid); } @@ -21750,7 +21798,8 @@ report_add_results_array (report_t report, GArray *results) "medium", "high", "hosts", "result_hosts", "fp_per_host", "log_per_host", \ "low_per_host", "medium_per_host", "high_per_host", "duration", \ "duration_per_host", "start_time", "end_time", "scan_start", "scan_end", \ - NULL } + "compliance_yes", "compliance_no", "compliance_incomplete", \ + "compliance_status", NULL } /** * @brief Report iterator columns. @@ -21888,6 +21937,26 @@ report_add_results_array (report_t report, GArray *results) "duration_per_host", \ KEYWORD_TYPE_INTEGER \ }, \ + { \ + "compliance_count (id, 'YES')", \ + "compliance_yes", \ + KEYWORD_TYPE_INTEGER \ + }, \ + { \ + "compliance_count (id, 'NO')", \ + "compliance_no", \ + KEYWORD_TYPE_INTEGER \ + }, \ + { \ + "compliance_count (id, 'INCOMPLETE')", \ + "compliance_incomplete", \ + KEYWORD_TYPE_INTEGER \ + }, \ + { \ + "compliance_status (id)", \ + "compliance_status", \ + KEYWORD_TYPE_STRING \ + }, \ { NULL, NULL, KEYWORD_TYPE_UNKNOWN } \ } @@ -21910,6 +21979,126 @@ report_iterator_opts_table (int override, int min_qod) min_qod); } +/** + * @brief Return SQL WHERE for restricting a SELECT to compliance statuses. + * + * @param[in] compliance String describing compliance statuses of reports + * to include (for example, "yniu" for yes (compliant), + * no (not compliant), i (incomplete) and u (undefined)) + * All compliance statuses if NULL. + * + * @return WHERE clause for compliance if one is required, else NULL. + */ + +static gchar* +where_compliance_status (const char *compliance) +{ + int count; + GString *compliance_sql; + + /* Generate SQL for constraints on compliance status, according to compliance. */ + + compliance_sql = g_string_new (""); + count = 0; + + g_string_append_printf (compliance_sql, " AND compliance_status(reports.id) IN ("); + + if (strchr (compliance, 'y')) + { + g_string_append (compliance_sql, "'yes'"); + count++; + } + if (strchr (compliance, 'n')) + { + g_string_append (compliance_sql, count ? ", 'no'" : "'no'"); + count++; + } + if (strchr (compliance, 'i')) + { + g_string_append (compliance_sql, count ? ", 'incomplete'" : "'incomplete'"); + count++; + } + if (strchr (compliance, 'u')) + { + g_string_append (compliance_sql, count ? ", 'undefined'" : "'undefined'"); + count++; + } + + g_string_append (compliance_sql, ")"); + + if (count == 4) + { + /* All compliance levels selected. */ + g_string_free (compliance_sql, TRUE); + return NULL; + } + + return g_string_free (compliance_sql, FALSE);; +} + + +/** + * @brief Generate an extra WHERE clause for selecting reports + * + * @param[in] trash Whether to get results from trashcan. + * @param[in] filter Filter string. + * @param[in] usage_type The usage type to limit the selection to. + * + * @return Newly allocated where clause string. + */ +static gchar * +reports_extra_where (int trash, const gchar *filter, const char *usage_type) +{ + gchar *extra_where = NULL; + gchar *usage_type_clause, *trash_clause, *compliance_clause = NULL; + gchar *compliance_filter = NULL; + + if (trash) + { + trash_clause = g_strdup_printf (" AND (SELECT hidden FROM tasks" + " WHERE tasks.id = task)" + " = 2"); + } + else + { + trash_clause = g_strdup_printf (" AND (SELECT hidden FROM tasks" + " WHERE tasks.id = task)" + " = 0"); + } + + + if (usage_type && strcmp (usage_type, "")) + { + gchar *quoted_usage_type; + quoted_usage_type = sql_quote (usage_type); + usage_type_clause = g_strdup_printf (" AND task in (SELECT id from tasks" + " WHERE usage_type='%s')", + quoted_usage_type); + + g_free (quoted_usage_type); + } + else + usage_type_clause = NULL; + + if (filter) + compliance_filter = filter_term_value(filter, "compliant"); + + compliance_clause = where_compliance_status (compliance_filter ?: "yniu"); + + + extra_where = g_strdup_printf("%s%s%s", + trash_clause, + usage_type_clause ?: "", + compliance_clause ?: ""); + + g_free (compliance_filter); + g_free (trash_clause); + g_free (compliance_clause); + g_free (usage_type_clause); + + return extra_where; +} + /** * @brief Count number of reports. * @@ -21923,21 +22112,18 @@ report_count (const get_data_t *get) static const char *filter_columns[] = REPORT_ITERATOR_FILTER_COLUMNS; static column_t columns[] = REPORT_ITERATOR_COLUMNS; static column_t where_columns[] = REPORT_ITERATOR_WHERE_COLUMNS; - gchar *extra_tables; + gchar *extra_tables, *extra_where; int ret; extra_tables = report_iterator_opts_table (0, MIN_QOD_DEFAULT); + + const gchar *usage_type = get_data_get_extra (get, "usage_type"); + extra_where = reports_extra_where(get->trash, get->filter, usage_type); ret = count2 ("report", get, columns, NULL, where_columns, NULL, filter_columns, 0, extra_tables, - get->trash - ? " AND (SELECT hidden FROM tasks" - " WHERE tasks.id = task)" - " = 2" - : " AND (SELECT hidden FROM tasks" - " WHERE tasks.id = task)" - " = 0", + extra_where, NULL, TRUE); @@ -21962,7 +22148,8 @@ init_report_iterator (iterator_t* iterator, const get_data_t *get) static column_t where_columns[] = REPORT_ITERATOR_WHERE_COLUMNS; char *filter; int overrides, min_qod; - gchar *extra_tables; + const char *usage_type; + gchar *extra_tables, *extra_where; int ret; if (get->filt_id && strcmp (get->filt_id, FILT_ID_NONE)) @@ -21980,6 +22167,8 @@ init_report_iterator (iterator_t* iterator, const get_data_t *get) free (filter); extra_tables = report_iterator_opts_table (overrides, min_qod); + usage_type = get_data_get_extra (get, "usage_type"); + extra_where = reports_extra_where (get->trash, get->filter, usage_type); ret = init_get_iterator2 (iterator, "report", @@ -21993,13 +22182,7 @@ init_report_iterator (iterator_t* iterator, const get_data_t *get) filter_columns, 0, extra_tables, - get->trash - ? " AND (SELECT hidden FROM tasks" - " WHERE tasks.id = task)" - " = 2" - : " AND (SELECT hidden FROM tasks" - " WHERE tasks.id = task)" - " = 0", + extra_where, NULL, TRUE, FALSE, @@ -23819,6 +24002,20 @@ DEF_ACCESS (result_iterator_nvt_family, GET_ITERATOR_COLUMN_COUNT + 33); */ DEF_ACCESS (result_iterator_nvt_tag, GET_ITERATOR_COLUMN_COUNT + 34); +/** + * @brief Get compliance status from a result iterator. + * + * @param[in] iterator Iterator. + * + * @return The compliance status (yes, no, incomplete or undefined). + */ +const char * +result_iterator_compliance (iterator_t* iterator) +{ + if (iterator->done) return 0; + return iterator_string (iterator, GET_ITERATOR_COLUMN_COUNT + 35); +} + /** * @brief Get EPSS score of highest severity CVE from a result iterator. * @@ -25693,6 +25890,158 @@ report_counts_id_full (report_t report, int* holes, int* infos, return 0; } + +/** + * @brief Get the compliance filtered counts for a report. + * + * @param[in] report Report. + * @param[in] get Get data. + * @param[out] f_compliance_yes Compliant results count after filtering. + * @param[out] f_compliance_no Incompliant results count after filtering. + * @param[out] f_compliance_incomplete Incomplete results count + * after filtering. + * @param[out] f_compliance_undefined Undefined results count + * after filtering. + * @param[out] f_compliance Compliance state after filtering + * + * @return 0 on success, -1 on error. + */ +static int +report_compliance_f_counts (report_t report, + const get_data_t* get, + int* f_compliance_yes, + int* f_compliance_no, + int* f_compliance_incomplete, + int* f_compliance_undefined, + char** f_compliance_status) +{ + if (report == 0) + return -1; + + get_data_t get_filtered; + iterator_t results; + int yes_count, no_count, incomplete_count, undefined_count; + + yes_count = no_count = incomplete_count = undefined_count = 0; + + memset (&get_filtered, 0, sizeof (get_data_t)); + get_filtered.filt_id = get->filt_id; + get_filtered.filter = get->filter; + get_filtered.type = get->type; + get_filtered.ignore_pagination = 1; + + ignore_max_rows_per_page = 1; + init_result_get_iterator (&results, &get_filtered, report, NULL, + NULL); + ignore_max_rows_per_page = 0; + while (next (&results)) + { + const char* compliance; + + compliance = result_iterator_compliance (&results); + + if (strcasecmp (compliance, "yes") == 0) + { + yes_count++; + } + else if (strcasecmp (compliance, "no") == 0) + { + no_count++; + } + else if (strcasecmp (compliance, "incomplete") == 0) + { + incomplete_count++; + } + else if (strcasecmp (compliance, "undefined") == 0) + { + undefined_count++; + } + + } + + if (f_compliance_yes) + *f_compliance_yes = yes_count; + if (f_compliance_no) + *f_compliance_no = no_count; + if (f_compliance_incomplete) + *f_compliance_incomplete = incomplete_count; + if (f_compliance_undefined) + *f_compliance_undefined = undefined_count; + + cleanup_iterator (&results); + + if (f_compliance_status) + { + if (no_count > 0) + { + *f_compliance_status = "not compliant"; + } + else if (incomplete_count > 0) + { + *f_compliance_status = "incomplete"; + } + else if (yes_count > 0) + { + *f_compliance_status = "compliant"; + } + else + { + *f_compliance_status = "undefined"; + } + } + + return 0; +} + +/** + * @brief Get the compliance counts for a report. + * + * @param[in] report Report. + * @param[in] get Get data. + * @param[out] compliance_yes Compliant results count. + * @param[out] compliance_no Incompliant results count. + * @param[out] compliance_incomplete Incomplete results count. + * @param[out] compliance_undefined Undefined results count. + * @param[out] f_compliance Compliance state. + * + * @return 0 on success, -1 on error. + */ +static int +report_compliance_counts (report_t report, + const get_data_t* get, + int* compliance_yes, + int* compliance_no, + int* compliance_incomplete, + int* compliance_undefined, + char** compliance_status) +{ + if (report == 0) + return -1; + + report_compliance_by_uuid (report_uuid(report), + compliance_yes, + compliance_no, + compliance_incomplete, + compliance_undefined); + + if (compliance_status) + { + if (compliance_no && *compliance_no > 0) { + *compliance_status = "not compliant"; + } else if (compliance_incomplete && *compliance_incomplete > 0) { + *compliance_status = "incomplete"; + } else if (compliance_yes && *compliance_yes > 0) { + *compliance_status = "compliant"; + } else { + *compliance_status = "undefined"; + } + } + + return 0; +} + + + /** * @brief Get only the filtered message counts for a report. * @@ -29010,6 +29359,11 @@ print_report_delta_xml (FILE *out, iterator_t *results, * @param[in] f_warnings Result count. * @param[in] orig_f_false_positives Result count. * @param[in] f_false_positives Result count. + * @param[in] f_compliance_yes filtered compliant count. + * @param[in] f_compliance_no filtered incompliant count. + * @param[in] f_compliance_incomplete filtered incomplete count. + * @param[in] f_compliance_undefined filtered undefined count. + * @param[in] f_compliance_count total filtered compliance count. * @param[in] result_hosts Result hosts. * * @return 0 on success, -1 error. @@ -29028,6 +29382,9 @@ print_v2_report_delta_xml (FILE *out, iterator_t *results, int *orig_f_logs, int *f_logs, int *orig_f_warnings, int *f_warnings, int *orig_f_false_positives, int *f_false_positives, + int *f_compliance_yes, int *f_compliance_no, + int *f_compliance_incomplete, + int *f_compliance_undefined, int *f_compliance_count, array_t *result_hosts) { GString *buffer = g_string_new (""); @@ -29039,6 +29396,9 @@ print_v2_report_delta_xml (FILE *out, iterator_t *results, *orig_f_warnings = *f_warnings; *orig_f_false_positives = *f_false_positives; *orig_filtered_result_count = *filtered_result_count; + gchar *usage_type = NULL; + + if (task && task_usage_type(task, &usage_type)) return -1; ports = g_tree_new_full ((GCompareDataFunc) strcmp, NULL, g_free, (GDestroyNotify) free_host_ports); @@ -29049,38 +29409,62 @@ print_v2_report_delta_xml (FILE *out, iterator_t *results, if (strchr (delta_states, state[0]) == NULL) continue; - const char *level; - /* Increase the result count. */ - level = result_iterator_level (results); - (*orig_filtered_result_count)++; - (*filtered_result_count)++; - if (strcmp (level, "High") == 0) - { - (*orig_f_holes)++; - (*f_holes)++; - } - else if (strcmp (level, "Medium") == 0) - { - (*orig_f_warnings)++; - (*f_warnings)++; - } - else if (strcmp (level, "Low") == 0) + if (strcmp (usage_type, "audit")) { - (*orig_f_infos)++; - (*f_infos)++; - } - else if (strcmp (level, "Log") == 0) - { - (*orig_f_logs)++; - (*f_logs)++; + const char *level; + /* Increase the result count. */ + level = result_iterator_level (results); + (*orig_filtered_result_count)++; + (*filtered_result_count)++; + if (strcmp (level, "High") == 0) + { + (*orig_f_holes)++; + (*f_holes)++; + } + else if (strcmp (level, "Medium") == 0) + { + (*orig_f_warnings)++; + (*f_warnings)++; + } + else if (strcmp (level, "Low") == 0) + { + (*orig_f_infos)++; + (*f_infos)++; + } + else if (strcmp (level, "Log") == 0) + { + (*orig_f_logs)++; + (*f_logs)++; + } + else if (strcmp (level, "False Positive") == 0) + { + (*orig_f_false_positives)++; + (*f_false_positives)++; + } } - else if (strcmp (level, "False Positive") == 0) + else { - (*orig_f_false_positives)++; - (*f_false_positives)++; + const char* compliance; + compliance = result_iterator_compliance (results); + (*f_compliance_count)++; + if (strcasecmp (compliance, "yes") == 0) + { + (*f_compliance_yes)++; + } + else if (strcasecmp (compliance, "no") == 0) + { + (*f_compliance_no)++; + } + else if (strcasecmp (compliance, "incomplete") == 0) + { + (*f_compliance_incomplete)++; + } + else if (strcasecmp (compliance, "undefined") == 0) + { + (*f_compliance_undefined)++; + } } - buffer_results_xml (buffer, results, task, @@ -29111,6 +29495,8 @@ print_v2_report_delta_xml (FILE *out, iterator_t *results, g_string_truncate (buffer, 0); } g_string_free (buffer, TRUE); + g_free (usage_type); + if (fprintf (out, "") < 0) { g_tree_destroy (ports); @@ -29185,7 +29571,7 @@ print_report_xml_start (report_t report, report_t delta, task_t task, FILE *out; gchar *clean, *term, *sort_field, *levels, *search_phrase; - gchar *min_qod; + gchar *min_qod, *compliance_levels; gchar *delta_states, *timestamp; int min_qod_int; char *uuid, *tsk_uuid = NULL, *start_time, *end_time; @@ -29206,18 +29592,29 @@ print_report_xml_start (report_t report, report_t delta, task_t task, GHashTable *f_host_ports; GHashTable *f_host_holes, *f_host_warnings, *f_host_infos; GHashTable *f_host_logs, *f_host_false_positives; + GHashTable *f_host_compliant, *f_host_notcompliant; + GHashTable *f_host_incomplete, *f_host_undefined; task_status_t run_status; + gchar *tsk_usage_type = NULL; + int compliance_yes, compliance_no; + int compliance_incomplete, compliance_undefined; + int f_compliance_yes, f_compliance_no; + int f_compliance_incomplete, f_compliance_undefined; + char *compliance_status, *f_compliance_status; + int total_compliance_count, f_compliance_count; int delta_reports_version = 0; /* Init some vars to prevent warnings from older compilers. */ max_results = -1; levels = NULL; + compliance_levels = NULL; zone = NULL; delta_states = NULL; min_qod = NULL; search_phrase = NULL; total_result_count = filtered_result_count = 0; + total_compliance_count = f_compliance_count = 0; orig_filtered_result_count = 0; orig_f_false_positives = orig_f_warnings = orig_f_logs = orig_f_infos = 0; orig_f_holes = 0; @@ -29227,6 +29624,10 @@ print_report_xml_start (report_t report, report_t delta, task_t task, f_host_infos = NULL; f_host_logs = NULL; f_host_false_positives = NULL; + f_host_compliant = NULL; + f_host_notcompliant = NULL; + f_host_incomplete = NULL; + f_host_undefined = NULL; /** @todo Leaks on error in PRINT and PRINT_XML. The process normally exits * then anyway. */ @@ -29277,10 +29678,10 @@ print_report_xml_start (report_t report, report_t delta, task_t task, manage_report_filter_controls (term ? term : get->filter, &first_result, &max_results, &sort_field, &sort_order, &result_hosts_only, - &min_qod, &levels, &delta_states, - &search_phrase, &search_phrase_exact, - ¬es, &overrides, - &apply_overrides, &zone); + &min_qod, &levels, &compliance_levels, + &delta_states, &search_phrase, + &search_phrase_exact, ¬es, + &overrides, &apply_overrides, &zone); } else { @@ -29289,9 +29690,9 @@ print_report_xml_start (report_t report, report_t delta, task_t task, manage_report_filter_controls (term, &first_result, &max_results, &sort_field, &sort_order, &result_hosts_only, - &min_qod, &levels, &delta_states, - &search_phrase, &search_phrase_exact, - ¬es, &overrides, + &min_qod, &levels, &compliance_levels, + &delta_states, &search_phrase, + &search_phrase_exact, ¬es, &overrides, &apply_overrides, &zone); } @@ -29304,11 +29705,14 @@ print_report_xml_start (report_t report, report_t delta, task_t task, levels = levels ? levels : g_strdup ("hmlgdf"); - if (task && task_uuid (task, &tsk_uuid)) + compliance_levels = compliance_levels ? compliance_levels : g_strdup ("yniu"); + + if (task && (task_uuid (task, &tsk_uuid) || task_usage_type(task, &tsk_usage_type))) { fclose (out); g_free (term); g_free (levels); + g_free (compliance_levels); g_free (search_phrase); g_free (min_qod); g_free (delta_states); @@ -29381,6 +29785,7 @@ print_report_xml_start (report_t report, report_t delta, task_t task, { free (uuid); g_free (levels); + g_free (compliance_levels); g_free (search_phrase); g_free (min_qod); g_free (delta_states); @@ -29415,45 +29820,47 @@ print_report_xml_start (report_t report, report_t delta, task_t task, if (report) { /* Get total counts of full results. */ + if (strcmp (tsk_usage_type, "audit")) + { + if (delta == 0) + { + int total_holes, total_infos, total_logs; + int total_warnings, total_false_positives; + get_data_t *all_results_get; + + all_results_get = report_results_get_data (1, -1, 0, 0); + report_counts_id (report, &total_holes, &total_infos, + &total_logs, &total_warnings, + &total_false_positives, NULL, all_results_get, + NULL); + total_result_count = total_holes + total_infos + + total_logs + total_warnings + + total_false_positives; + get_data_reset (all_results_get); + free (all_results_get); + } - if (delta == 0) - { - int total_holes, total_infos, total_logs; - int total_warnings, total_false_positives; - get_data_t *all_results_get; - - all_results_get = report_results_get_data (1, -1, 0, 0); - report_counts_id (report, &total_holes, &total_infos, - &total_logs, &total_warnings, - &total_false_positives, NULL, all_results_get, - NULL); - total_result_count = total_holes + total_infos - + total_logs + total_warnings - + total_false_positives; - get_data_reset (all_results_get); - free (all_results_get); - } + /* Get total counts of filtered results. */ - /* Get total counts of filtered results. */ + if (count_filtered) + { + /* We're getting all the filtered results, so we can count them as we + * print them, to save time. */ - if (count_filtered) - { - /* We're getting all the filtered results, so we can count them as we - * print them, to save time. */ + filtered_result_count = 0; + } + else + { + /* Beware, we're using the full variables temporarily here, but + * report_counts_id counts the filtered results. */ + report_counts_id (report, &holes, &infos, &logs, &warnings, + &false_positives, NULL, get, NULL); - filtered_result_count = 0; - } - else - { - /* Beware, we're using the full variables temporarily here, but - * report_counts_id counts the filtered results. */ - report_counts_id (report, &holes, &infos, &logs, &warnings, - &false_positives, NULL, get, NULL); + filtered_result_count = holes + infos + logs + warnings + + false_positives; - filtered_result_count = holes + infos + logs + warnings - + false_positives; + } } - /* Get report run status. */ report_scan_run_status (report, &run_status); @@ -29551,16 +29958,30 @@ print_report_xml_start (report_t report, report_t delta, task_t task, filters_extra_buffer = g_string_new (""); - if (strchr (levels, 'h')) - g_string_append (filters_extra_buffer, "High"); - if (strchr (levels, 'm')) - g_string_append (filters_extra_buffer, "Medium"); - if (strchr (levels, 'l')) - g_string_append (filters_extra_buffer, "Low"); - if (strchr (levels, 'g')) - g_string_append (filters_extra_buffer, "Log"); - if (strchr (levels, 'f')) - g_string_append (filters_extra_buffer, "False Positive"); + if (strcmp (tsk_usage_type, "audit")) + { + if (strchr (levels, 'h')) + g_string_append (filters_extra_buffer, "High"); + if (strchr (levels, 'm')) + g_string_append (filters_extra_buffer, "Medium"); + if (strchr (levels, 'l')) + g_string_append (filters_extra_buffer, "Low"); + if (strchr (levels, 'g')) + g_string_append (filters_extra_buffer, "Log"); + if (strchr (levels, 'f')) + g_string_append (filters_extra_buffer, "False Positive"); + } + else + { + if (strchr (compliance_levels, 'y')) + g_string_append (filters_extra_buffer, "Yes"); + if (strchr (compliance_levels, 'n')) + g_string_append (filters_extra_buffer, "No"); + if (strchr (compliance_levels, 'i')) + g_string_append (filters_extra_buffer, "Incomplete"); + if (strchr (compliance_levels, 'u')) + g_string_append (filters_extra_buffer, "Undefined"); + } if (delta) { @@ -29826,24 +30247,57 @@ print_report_xml_start (report_t report, report_t delta, task_t task, /* Prepare result counts. */ - if (count_filtered) + if (strcmp (tsk_usage_type, "audit") == 0) { - /* We're getting all the filtered results, so we can count them as we - * print them, to save time. */ + report_compliance_counts (report, get, &compliance_yes, &compliance_no, + &compliance_incomplete, &compliance_undefined, + &compliance_status); - report_counts_id_full (report, &holes, &infos, &logs, - &warnings, &false_positives, &severity, - get, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + total_compliance_count = compliance_yes + + compliance_no + + compliance_incomplete + + compliance_undefined; - f_holes = f_infos = f_logs = f_warnings = 0; - f_false_positives = f_severity = 0; + f_compliance_yes = f_compliance_no = 0; + f_compliance_incomplete = f_compliance_undefined = 0; + + if (count_filtered == 0) + { + report_compliance_f_counts (report, + get, + &f_compliance_yes, + &f_compliance_no, + &f_compliance_incomplete, + &f_compliance_undefined, + &f_compliance_status); + + f_compliance_count = f_compliance_yes + + f_compliance_no + + f_compliance_incomplete + + f_compliance_undefined; + } } else - report_counts_id_full (report, &holes, &infos, &logs, - &warnings, &false_positives, &severity, - get, NULL, - &f_holes, &f_infos, &f_logs, &f_warnings, - &f_false_positives, &f_severity); + { + if (count_filtered) + { + /* We're getting all the filtered results, so we can count them as we + * print them, to save time. */ + + report_counts_id_full (report, &holes, &infos, &logs, + &warnings, &false_positives, &severity, + get, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + + f_holes = f_infos = f_logs = f_warnings = 0; + f_false_positives = f_severity = 0; + } + else + report_counts_id_full (report, &holes, &infos, &logs, + &warnings, &false_positives, &severity, + get, NULL, + &f_holes, &f_infos, &f_logs, &f_warnings, + &f_false_positives, &f_severity); + } /* Results. */ @@ -29908,16 +30362,31 @@ print_report_xml_start (report_t report, report_t delta, task_t task, /* Quiet erroneous compiler warning. */ result_hosts = NULL; - f_host_holes = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); - f_host_warnings = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); - f_host_infos = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); - f_host_logs = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); - f_host_false_positives = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); + if (strcmp (tsk_usage_type, "audit")) + { + f_host_holes = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + f_host_warnings = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + f_host_infos = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + f_host_logs = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + f_host_false_positives = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + } + else + { + f_host_compliant = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + f_host_notcompliant = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + f_host_incomplete = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + f_host_undefined = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + } + if (delta && get->details) { @@ -29944,6 +30413,7 @@ print_report_xml_start (report_t report, report_t delta, task_t task, fclose (out); g_free (sort_field); g_free (levels); + g_free (compliance_levels); g_free (search_phrase); g_free (min_qod); g_free (delta_states); @@ -29951,11 +30421,22 @@ print_report_xml_start (report_t report, report_t delta, task_t task, cleanup_iterator (&delta_results); tz_revert (zone, tz, old_tz_override); g_hash_table_destroy (f_host_ports); - g_hash_table_destroy (f_host_holes); - g_hash_table_destroy (f_host_warnings); - g_hash_table_destroy (f_host_infos); - g_hash_table_destroy (f_host_logs); - g_hash_table_destroy (f_host_false_positives); + if (strcmp (tsk_usage_type, "audit")) + { + g_hash_table_destroy (f_host_holes); + g_hash_table_destroy (f_host_warnings); + g_hash_table_destroy (f_host_infos); + g_hash_table_destroy (f_host_logs); + g_hash_table_destroy (f_host_false_positives); + + } + else + { + g_hash_table_destroy (f_host_compliant); + g_hash_table_destroy (f_host_notcompliant); + g_hash_table_destroy (f_host_incomplete); + g_hash_table_destroy (f_host_undefined); + } return -1; } } @@ -29976,11 +30457,17 @@ print_report_xml_start (report_t report, report_t delta, task_t task, &orig_f_warnings, &f_warnings, &orig_f_false_positives, &f_false_positives, + &f_compliance_yes, + &f_compliance_no, + &f_compliance_incomplete, + &f_compliance_undefined, + &f_compliance_count, result_hosts)) { fclose (out); g_free (sort_field); g_free (levels); + g_free (compliance_levels); g_free (search_phrase); g_free (min_qod); g_free (delta_states); @@ -29988,11 +30475,21 @@ print_report_xml_start (report_t report, report_t delta, task_t task, cleanup_iterator (&delta_results); tz_revert (zone, tz, old_tz_override); g_hash_table_destroy (f_host_ports); - g_hash_table_destroy (f_host_holes); - g_hash_table_destroy (f_host_warnings); - g_hash_table_destroy (f_host_infos); - g_hash_table_destroy (f_host_logs); - g_hash_table_destroy (f_host_false_positives); + if (strcmp (tsk_usage_type, "audit")) + { + g_hash_table_destroy (f_host_holes); + g_hash_table_destroy (f_host_warnings); + g_hash_table_destroy (f_host_infos); + g_hash_table_destroy (f_host_logs); + g_hash_table_destroy (f_host_false_positives); + } + else + { + g_hash_table_destroy (f_host_compliant); + g_hash_table_destroy (f_host_notcompliant); + g_hash_table_destroy (f_host_incomplete); + g_hash_table_destroy (f_host_undefined); + } return -1; } } @@ -30007,7 +30504,6 @@ print_report_xml_start (report_t report, report_t delta, task_t task, const char* level; GHashTable *f_host_result_counts; GString *buffer = g_string_new (""); - double result_severity; buffer_results_xml (buffer, &results, @@ -30031,54 +30527,106 @@ print_report_xml_start (report_t report, report_t delta, task_t task, array_add_new_string (result_hosts, result_iterator_host (&results)); - result_severity = result_iterator_severity_double (&results); - if (result_severity > f_severity) - f_severity = result_severity; - - level = result_iterator_level (&results); - if (strcasecmp (level, "log") == 0) - { - f_host_result_counts = f_host_logs; - if (count_filtered) - f_logs++; - } - else if (strcasecmp (level, "high") == 0) - { - f_host_result_counts = f_host_holes; - if (count_filtered) - f_holes++; - } - else if (strcasecmp (level, "medium") == 0) + if (strcmp (tsk_usage_type, "audit")) { - f_host_result_counts = f_host_warnings; - if (count_filtered) - f_warnings++; - } - else if (strcasecmp (level, "low") == 0) - { - f_host_result_counts = f_host_infos; - if (count_filtered) - f_infos++; - } - else if (strcasecmp (level, "false positive") == 0) - { - f_host_result_counts = f_host_false_positives; - if (count_filtered) - f_false_positives++; + double result_severity; + result_severity = result_iterator_severity_double (&results); + if (result_severity > f_severity) + f_severity = result_severity; + + level = result_iterator_level (&results); + + if (strcasecmp (level, "log") == 0) + { + f_host_result_counts = f_host_logs; + if (count_filtered) + f_logs++; + } + else if (strcasecmp (level, "high") == 0) + { + f_host_result_counts = f_host_holes; + if (count_filtered) + f_holes++; + } + else if (strcasecmp (level, "medium") == 0) + { + f_host_result_counts = f_host_warnings; + if (count_filtered) + f_warnings++; + } + else if (strcasecmp (level, "low") == 0) + { + f_host_result_counts = f_host_infos; + if (count_filtered) + f_infos++; + } + else if (strcasecmp (level, "false positive") == 0) + { + f_host_result_counts = f_host_false_positives; + if (count_filtered) + f_false_positives++; + } + else + f_host_result_counts = NULL; + + if (f_host_result_counts) + { + const char *result_host = result_iterator_host (&results); + int result_count + = GPOINTER_TO_INT + (g_hash_table_lookup (f_host_result_counts, result_host)); + + g_hash_table_replace (f_host_result_counts, + g_strdup (result_host), + GINT_TO_POINTER (result_count + 1)); + } } else - f_host_result_counts = NULL; - - if (f_host_result_counts) { - const char *result_host = result_iterator_host (&results); - int result_count - = GPOINTER_TO_INT - (g_hash_table_lookup (f_host_result_counts, result_host)); + const char* compliance; + compliance = result_iterator_compliance (&results); + + if (strcasecmp (compliance, "yes") == 0) + { + f_host_result_counts = f_host_compliant; + if (count_filtered) + f_compliance_yes++; + } + else if (strcasecmp (compliance, "no") == 0) + { + f_host_result_counts = f_host_notcompliant; + if (count_filtered) + f_compliance_no++; + } + else if (strcasecmp (compliance, "incomplete") == 0) + { + f_host_result_counts = f_host_incomplete; + if (count_filtered) + f_compliance_incomplete++; + } + else if (strcasecmp (compliance, "undefined") == 0) + { + f_host_result_counts = f_host_undefined; + if (count_filtered) + f_compliance_undefined++; + } + else + { + f_host_result_counts = NULL; + } - g_hash_table_replace (f_host_result_counts, - g_strdup (result_host), - GINT_TO_POINTER (result_count + 1)); + if (f_host_result_counts) + { + const char *result_host = result_iterator_host (&results); + int result_count + = GPOINTER_TO_INT + (g_hash_table_lookup (f_host_result_counts, + result_host)); + + g_hash_table_replace (f_host_result_counts, + g_strdup (result_host), + GINT_TO_POINTER (result_count + 1)); + } } } @@ -30091,68 +30639,146 @@ print_report_xml_start (report_t report, report_t delta, task_t task, /* Print result counts and severity. */ - if (delta) - /** @todo The f_holes, etc. vars are setup to give the page count. */ - PRINT (out, - "" - "%i" - "%i" - "%i" - "%i" - "%i" - "" - "%i" - "" - "", - orig_filtered_result_count, - (strchr (levels, 'h') ? orig_f_holes : 0), - (strchr (levels, 'l') ? orig_f_infos : 0), - (strchr (levels, 'g') ? orig_f_logs : 0), - (strchr (levels, 'm') ? orig_f_warnings : 0), - (strchr (levels, 'f') ? orig_f_false_positives : 0)); + if (strcmp (tsk_usage_type, "audit")) + { + if (delta) + /** @todo The f_holes, etc. vars are setup to give the page count. */ + PRINT (out, + "" + "%i" + "%i" + "%i" + "%i" + "%i" + "" + "%i" + "" + "", + orig_filtered_result_count, + (strchr (levels, 'h') ? orig_f_holes : 0), + (strchr (levels, 'l') ? orig_f_infos : 0), + (strchr (levels, 'g') ? orig_f_logs : 0), + (strchr (levels, 'm') ? orig_f_warnings : 0), + (strchr (levels, 'f') ? orig_f_false_positives : 0)); + else + { + if (count_filtered) + filtered_result_count = f_holes + f_infos + f_logs + + f_warnings + false_positives; + + PRINT (out, + "" + "%i" + "%i" + "%i" + "%i%i" + "%i%i" + "%i%i" + "%i%i" + "" + "%i" + "%i" + "" + "", + total_result_count, + total_result_count, + filtered_result_count, + holes, + (strchr (levels, 'h') ? f_holes : 0), + infos, + (strchr (levels, 'l') ? f_infos : 0), + logs, + (strchr (levels, 'g') ? f_logs : 0), + warnings, + (strchr (levels, 'm') ? f_warnings : 0), + false_positives, + (strchr (levels, 'f') ? f_false_positives : 0)); + + PRINT (out, + "" + "%1.1f" + "%1.1f" + "", + severity, + f_severity); + } + } else { - if (count_filtered) - filtered_result_count = f_holes + f_infos + f_logs - + f_warnings + false_positives; + if (delta) + PRINT (out, + "" + "%i" + "%i" + "%i" + "%i" + "%i" + "", + f_compliance_count, + (strchr (compliance_levels, 'y') ? f_compliance_yes : 0), + (strchr (compliance_levels, 'n') ? f_compliance_no : 0), + (strchr (compliance_levels, 'i') ? f_compliance_incomplete : 0), + (strchr (compliance_levels, 'u') ? f_compliance_undefined : 0)); + else + { + if (count_filtered) + { + f_compliance_count = f_compliance_yes + + f_compliance_no + + f_compliance_incomplete + + f_compliance_undefined; + + if (f_compliance_no > 0) + { + f_compliance_status = "not compliant"; + } + else if (f_compliance_incomplete > 0) + { + f_compliance_status = "incomplete"; + } + else if (f_compliance_yes > 0) + { + f_compliance_status = "compliant"; + } + else + { + f_compliance_status = "undefined"; + } + } - PRINT (out, - "" - "%i" - "%i" - "%i" - "%i%i" - "%i%i" - "%i%i" - "%i%i" - "" - "%i" - "%i" - "" - "", - total_result_count, - total_result_count, - filtered_result_count, - holes, - (strchr (levels, 'h') ? f_holes : 0), - infos, - (strchr (levels, 'l') ? f_infos : 0), - logs, - (strchr (levels, 'g') ? f_logs : 0), - warnings, - (strchr (levels, 'm') ? f_warnings : 0), - false_positives, - (strchr (levels, 'f') ? f_false_positives : 0)); + PRINT (out, + "" + "%i" + "%i" + "%i" + "%i%i" + "%i%i" + "%i%i" + "%i%i" + "", + total_compliance_count, + total_compliance_count, + f_compliance_count, + compliance_yes, + (strchr (compliance_levels, 'y') ? f_compliance_yes : 0), + compliance_no, + (strchr (compliance_levels, 'n') ? f_compliance_no : 0), + compliance_incomplete, + (strchr (compliance_levels, 'i') ? f_compliance_incomplete : 0), + compliance_undefined, + (strchr (compliance_levels, 'i') ? f_compliance_undefined : 0)); - PRINT (out, - "" - "%1.1f" - "%1.1f" - "", - severity, - f_severity); + PRINT (out, + "" + "%s" + "%s" + "", + compliance_status, + f_compliance_status); + } } + if (host_summary) { host_summary_buffer = g_string_new (""); @@ -30184,29 +30810,13 @@ print_report_xml_start (report_t report, report_t delta, task_t task, { const char *current_host; int ports_count; - int holes_count, warnings_count, infos_count; - int logs_count, false_positives_count; - + current_host = host_iterator_host (&hosts); ports_count = GPOINTER_TO_INT (g_hash_table_lookup (f_host_ports, current_host)); - holes_count - = GPOINTER_TO_INT - (g_hash_table_lookup ( f_host_holes, current_host)); - warnings_count - = GPOINTER_TO_INT - (g_hash_table_lookup ( f_host_warnings, current_host)); - infos_count - = GPOINTER_TO_INT - (g_hash_table_lookup ( f_host_infos, current_host)); - logs_count - = GPOINTER_TO_INT - (g_hash_table_lookup ( f_host_logs, current_host)); - false_positives_count - = GPOINTER_TO_INT - (g_hash_table_lookup ( f_host_false_positives, current_host)); + host_summary_append (host_summary_buffer, result_host, @@ -30226,30 +30836,97 @@ print_report_xml_start (report_t report, report_t delta, task_t task, PRINT (out, ""); - PRINT (out, - "%s" - "%s" - "%d" - "" - "%d" - "%d" - "%d" - "%d" - "%d" - "%d" - "", - host_iterator_start_time (&hosts), - host_iterator_end_time (&hosts) - ? host_iterator_end_time (&hosts) - : "", - ports_count, - (holes_count + warnings_count + infos_count - + logs_count + false_positives_count), - holes_count, - warnings_count, - infos_count, - logs_count, - false_positives_count); + if (strcmp (tsk_usage_type, "audit")) + { + int holes_count, warnings_count, infos_count; + int logs_count, false_positives_count; + + holes_count + = GPOINTER_TO_INT + (g_hash_table_lookup ( f_host_holes, current_host)); + warnings_count + = GPOINTER_TO_INT + (g_hash_table_lookup ( f_host_warnings, current_host)); + infos_count + = GPOINTER_TO_INT + (g_hash_table_lookup ( f_host_infos, current_host)); + logs_count + = GPOINTER_TO_INT + (g_hash_table_lookup ( f_host_logs, current_host)); + false_positives_count + = GPOINTER_TO_INT + (g_hash_table_lookup ( f_host_false_positives, + current_host)); + + PRINT (out, + "%s" + "%s" + "%d" + "" + "%d" + "%d" + "%d" + "%d" + "%d" + "%d" + "", + host_iterator_start_time (&hosts), + host_iterator_end_time (&hosts) + ? host_iterator_end_time (&hosts) + : "", + ports_count, + (holes_count + warnings_count + infos_count + + logs_count + false_positives_count), + holes_count, + warnings_count, + infos_count, + logs_count, + false_positives_count); + } + else + { + int yes_count, no_count, incomplete_count, undefined_count; + + yes_count + = GPOINTER_TO_INT + (g_hash_table_lookup ( f_host_compliant, + current_host)); + no_count + = GPOINTER_TO_INT + (g_hash_table_lookup ( f_host_notcompliant, + current_host)); + incomplete_count + = GPOINTER_TO_INT + (g_hash_table_lookup ( f_host_incomplete, + current_host)); + undefined_count + = GPOINTER_TO_INT + (g_hash_table_lookup ( f_host_undefined, + current_host)); + + PRINT (out, + "%s" + "%s" + "%d" + "" + "%d" + "%d" + "%d" + "%d" + "%d" + "", + host_iterator_start_time (&hosts), + host_iterator_end_time (&hosts) + ? host_iterator_end_time (&hosts) + : "", + ports_count, + (yes_count + no_count + + incomplete_count + undefined_count), + yes_count, + no_count, + incomplete_count, + undefined_count); + } if (print_report_host_details_xml (host_iterator_report_host (&hosts), out, lean)) @@ -30258,11 +30935,22 @@ print_report_xml_start (report_t report, report_t delta, task_t task, if (host_summary_buffer) g_string_free (host_summary_buffer, TRUE); g_hash_table_destroy (f_host_ports); - g_hash_table_destroy (f_host_holes); - g_hash_table_destroy (f_host_warnings); - g_hash_table_destroy (f_host_infos); - g_hash_table_destroy (f_host_logs); - g_hash_table_destroy (f_host_false_positives); + if (strcmp (tsk_usage_type, "audit")) + { + g_hash_table_destroy (f_host_holes); + g_hash_table_destroy (f_host_warnings); + g_hash_table_destroy (f_host_infos); + g_hash_table_destroy (f_host_logs); + g_hash_table_destroy (f_host_false_positives); + + } + else + { + g_hash_table_destroy (f_host_compliant); + g_hash_table_destroy (f_host_notcompliant); + g_hash_table_destroy (f_host_incomplete); + g_hash_table_destroy (f_host_undefined); + } return -1; } @@ -30280,29 +30968,12 @@ print_report_xml_start (report_t report, report_t delta, task_t task, { const char *current_host; int ports_count; - int holes_count, warnings_count, infos_count; - int logs_count, false_positives_count; current_host = host_iterator_host (&hosts); ports_count = GPOINTER_TO_INT (g_hash_table_lookup (f_host_ports, current_host)); - holes_count - = GPOINTER_TO_INT - (g_hash_table_lookup (f_host_holes, current_host)); - warnings_count - = GPOINTER_TO_INT - (g_hash_table_lookup (f_host_warnings, current_host)); - infos_count - = GPOINTER_TO_INT - (g_hash_table_lookup (f_host_infos, current_host)); - logs_count - = GPOINTER_TO_INT - (g_hash_table_lookup (f_host_logs, current_host)); - false_positives_count - = GPOINTER_TO_INT - (g_hash_table_lookup (f_host_false_positives, current_host)); host_summary_append (host_summary_buffer, host_iterator_host (&hosts), @@ -30322,30 +30993,92 @@ print_report_xml_start (report_t report, report_t delta, task_t task, PRINT (out, ""); - PRINT (out, - "%s" - "%s" - "%d" - "" - "%d" - "%d" - "%d" - "%d" - "%d" - "%d" - "", - host_iterator_start_time (&hosts), - host_iterator_end_time (&hosts) - ? host_iterator_end_time (&hosts) - : "", - ports_count, - (holes_count + warnings_count + infos_count - + logs_count + false_positives_count), - holes_count, - warnings_count, - infos_count, - logs_count, - false_positives_count); + if (strcmp (tsk_usage_type, "audit")) + { + int holes_count, warnings_count, infos_count; + int logs_count, false_positives_count; + + holes_count + = GPOINTER_TO_INT + (g_hash_table_lookup (f_host_holes, current_host)); + warnings_count + = GPOINTER_TO_INT + (g_hash_table_lookup (f_host_warnings, current_host)); + infos_count + = GPOINTER_TO_INT + (g_hash_table_lookup (f_host_infos, current_host)); + logs_count + = GPOINTER_TO_INT + (g_hash_table_lookup (f_host_logs, current_host)); + false_positives_count + = GPOINTER_TO_INT + (g_hash_table_lookup (f_host_false_positives, current_host)); + + PRINT (out, + "%s" + "%s" + "%d" + "" + "%d" + "%d" + "%d" + "%d" + "%d" + "%d" + "", + host_iterator_start_time (&hosts), + host_iterator_end_time (&hosts) + ? host_iterator_end_time (&hosts) + : "", + ports_count, + (holes_count + warnings_count + infos_count + + logs_count + false_positives_count), + holes_count, + warnings_count, + infos_count, + logs_count, + false_positives_count); + } + else + { + int yes_count, no_count, incomplete_count, undefined_count; + + yes_count + = GPOINTER_TO_INT + (g_hash_table_lookup (f_host_compliant, current_host)); + no_count + = GPOINTER_TO_INT + (g_hash_table_lookup (f_host_notcompliant, current_host)); + incomplete_count + = GPOINTER_TO_INT + (g_hash_table_lookup (f_host_incomplete, current_host)); + undefined_count + = GPOINTER_TO_INT + (g_hash_table_lookup (f_host_undefined, current_host)); + + PRINT (out, + "%s" + "%s" + "%d" + "" + "%d" + "%d" + "%d" + "%d" + "%d" + "", + host_iterator_start_time (&hosts), + host_iterator_end_time (&hosts) + ? host_iterator_end_time (&hosts) + : "", + ports_count, + (yes_count + no_count + + incomplete_count + undefined_count), + yes_count, + no_count, + incomplete_count, + undefined_count); + } if (print_report_host_details_xml (host_iterator_report_host (&hosts), out, lean)) @@ -30354,11 +31087,22 @@ print_report_xml_start (report_t report, report_t delta, task_t task, if (host_summary_buffer) g_string_free (host_summary_buffer, TRUE); g_hash_table_destroy (f_host_ports); - g_hash_table_destroy (f_host_holes); - g_hash_table_destroy (f_host_warnings); - g_hash_table_destroy (f_host_infos); - g_hash_table_destroy (f_host_logs); - g_hash_table_destroy (f_host_false_positives); + if (strcmp (tsk_usage_type, "audit")) + { + g_hash_table_destroy (f_host_holes); + g_hash_table_destroy (f_host_warnings); + g_hash_table_destroy (f_host_infos); + g_hash_table_destroy (f_host_logs); + g_hash_table_destroy (f_host_false_positives); + + } + else + { + g_hash_table_destroy (f_host_compliant); + g_hash_table_destroy (f_host_notcompliant); + g_hash_table_destroy (f_host_incomplete); + g_hash_table_destroy (f_host_undefined); + } return -1; } @@ -30368,13 +31112,23 @@ print_report_xml_start (report_t report, report_t delta, task_t task, cleanup_iterator (&hosts); } - g_hash_table_destroy (f_host_ports); - g_hash_table_destroy (f_host_holes); - g_hash_table_destroy (f_host_warnings); - g_hash_table_destroy (f_host_infos); - g_hash_table_destroy (f_host_logs); - g_hash_table_destroy (f_host_false_positives); + if (strcmp (tsk_usage_type, "audit")) + { + g_hash_table_destroy (f_host_holes); + g_hash_table_destroy (f_host_warnings); + g_hash_table_destroy (f_host_infos); + g_hash_table_destroy (f_host_logs); + g_hash_table_destroy (f_host_false_positives); + } + else + { + g_hash_table_destroy (f_host_compliant); + g_hash_table_destroy (f_host_notcompliant); + g_hash_table_destroy (f_host_incomplete); + g_hash_table_destroy (f_host_undefined); + } + g_hash_table_destroy (f_host_ports); /* Print TLS certificates */ @@ -30454,6 +31208,8 @@ print_report_xml_start (report_t report, report_t delta, task_t task, g_free (search_phrase); g_free (min_qod); g_free (delta_states); + g_free (compliance_levels); + g_free (tsk_usage_type); if (host_summary && host_summary_buffer) *host_summary = g_string_free (host_summary_buffer, FALSE); @@ -58100,14 +58856,13 @@ type_extra_where (const char *type, int trash, const char *filter, } else if (strcasecmp (type, "REPORT") == 0) { - if (trash) - extra_where = g_strdup (" AND (SELECT hidden FROM tasks" - " WHERE tasks.id = task)" - " = 2"); + gchar *usage_type; + if (extra_params) + usage_type = g_hash_table_lookup (extra_params, "usage_type"); else - extra_where = g_strdup (" AND (SELECT hidden FROM tasks" - " WHERE tasks.id = task)" - " = 0"); + usage_type = NULL; + + extra_where = reports_extra_where (trash, NULL, usage_type); } else if (strcasecmp (type, "RESULT") == 0) {