Skip to content

Commit

Permalink
Add feature toggle for compliance reports
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h-abdelsalam committed Aug 22, 2024
1 parent 79bbf68 commit d6a267c
Show file tree
Hide file tree
Showing 5 changed files with 611 additions and 593 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,25 @@ if (NOT CVSS3_RATINGS)
endif (NOT CVSS3_RATINGS)
add_definitions (-DCVSS3_RATINGS=${CVSS3_RATINGS})

if (NOT COMPLIANCE_REPORTS)
set (COMPLIANCE_REPORTS 0)
endif (NOT COMPLIANCE_REPORTS)
add_definitions (-DCOMPLIANCE_REPORTS=${COMPLIANCE_REPORTS})

message ("-- Install prefix: ${CMAKE_INSTALL_PREFIX}")

## Version

set (GVMD_VERSION "${PROJECT_VERSION_STRING}")

if (COMPLIANCE_REPORTS EQUAL 1)
set(IF_COMPLIANCE_REPORTS "")
set(ENDIF_COMPLIANCE_REPORTS "")
elseif (COMPLIANCE_REPORTS EQUAL 0)
set(IF_COMPLIANCE_REPORTS "<!--")
set(ENDIF_COMPLIANCE_REPORTS "-->")
endif()

# Configure Doxyfile with version number
configure_file (doc/Doxyfile.in doc/Doxyfile)
configure_file (doc/Doxyfile_full.in doc/Doxyfile_full)
Expand Down
48 changes: 33 additions & 15 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12955,6 +12955,11 @@ handle_get_features (gmp_parser_t *gmp_parser, GError **error)
" status=\"" STATUS_OK "\""
" status_text=\"" STATUS_OK_TEXT "\">");

SENDF_TO_CLIENT_OR_FAIL ("<feature enabled=\"%d\">"

Check warning on line 12958 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L12958

Added line #L12958 was not covered by tests
"<name>COMPLIANCE_REPORTS</name>"
"</feature>",
COMPLIANCE_REPORTS ? 1 : 0);

SENDF_TO_CLIENT_OR_FAIL ("<feature enabled=\"%d\">"
"<name>CVSS3_RATINGS</name>"
"</feature>",
Expand Down Expand Up @@ -14831,7 +14836,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, *compliance_levels;
gchar *filter, *levels;
get_data_t * get;

/* For simplicity, use a fixed result filter when filtering
Expand All @@ -14853,22 +14858,33 @@ 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");
#if COMPLIANCE_REPORTS == 1
gchar *compliance_levels;
compliance_levels = filter_term_value (filter
? filter
: get->filter,
"compliance_levels");

/* Setup result filter from overrides. */
get_reports_data->get.filter
= 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 (compliance_levels);
#else
/* Setup result filter from overrides. */
get_reports_data->get.filter
= g_strdup_printf

Check warning on line 14880 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L14879-L14880

Added lines #L14879 - L14880 were not covered by tests
("apply_overrides=%i min_qod=%i levels=%s",
overrides,
min_qod,
levels ? levels : "hmlgdf");
#endif
g_free (filter);

/* Setup result filter from overrides. */
get_reports_data->get.filter
= 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);
Expand Down Expand Up @@ -15914,6 +15930,7 @@ select_resource_iterator (get_resource_names_data_t *resource_names_data,
else if (g_strcmp0 ("report", resource_names_data->type) == 0)
{
*iterator = (int (*) (iterator_t*, get_data_t *))init_report_iterator;
#if COMPLIANCE_REPORTS == 1
get_data_set_extra (&resource_names_data->get,
"usage_type",
g_strdup ("scan"));
Expand All @@ -15924,6 +15941,7 @@ select_resource_iterator (get_resource_names_data_t *resource_names_data,
get_data_set_extra (&resource_names_data->get,
"usage_type",
g_strdup ("audit"));
#endif
}
else if (g_strcmp0 ("report_config", resource_names_data->type) == 0)
{
Expand Down
3 changes: 3 additions & 0 deletions src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,9 @@ gvmd (int argc, char** argv, char *env[])
#endif
#if CVSS3_RATINGS == 1
printf ("CVSS3 severity ratings enabled\n");
#endif
#if COMPLIANCE_REPORTS == 1
printf ("Compliance reports enabled\n");
#endif
printf ("Copyright (C) 2009-2021 Greenbone AG\n");
printf ("License: AGPL-3.0-or-later\n");
Expand Down
Loading

0 comments on commit d6a267c

Please sign in to comment.