Skip to content

Commit

Permalink
Fix: Fix missing tags in compliance reports, audits and policies
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h-abdelsalam authored and timopollmeier committed Jan 14, 2025
1 parent 6a35aa9 commit e155756
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
12 changes: 11 additions & 1 deletion src/gmp_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,17 @@ send_get_common (const char *type, get_data_t *get, iterator_t *iterator,
buffer_xml_append_printf (buffer, "</permissions>");
}

tag_type = get->subtype ? get->subtype : get->type;
if (strcmp (type, "config") == 0)
tag_type = (strcmp (config_iterator_usage_type (iterator), "policy") == 0)
? "policy"
: "config";
else if (strcmp (type, "task") == 0)
tag_type = (strcmp (task_iterator_usage_type (iterator), "audit") == 0)
? "audit"
: "task";
else
tag_type = get->subtype ? get->subtype : get->type;

tag_count = resource_tag_count (tag_type,
get_iterator_resource (iterator),
1);
Expand Down
48 changes: 33 additions & 15 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -29673,7 +29673,10 @@ print_report_xml_start (report_t report, report_t delta, task_t task,

if (report)
{
int tag_count = resource_tag_count ("report", report, 1);
const char *report_type = (strcmp (tsk_usage_type, "audit") == 0)
? "audit_report"
: "report";
int tag_count = resource_tag_count (report_type, report, 1);

if (tag_count)
{
Expand Down Expand Up @@ -29751,7 +29754,11 @@ print_report_xml_start (report_t report, report_t delta, task_t task,
target_t target;
gchar *progress_xml;
iterator_t tags;
int task_tag_count = resource_tag_count ("task", task, 1);

const char *task_type = (strcmp (tsk_usage_type, "audit") == 0)
? "audit"
: "task";
int task_tag_count = resource_tag_count (task_type, task, 1);

tsk_name = task_name (task);

Expand Down Expand Up @@ -58183,24 +58190,35 @@ int
resource_tag_count (const char* type, resource_t resource, int active_only)
{
int ret;
const char *parent_type;

assert (type);
assert (resource);

if (type_is_report_subtype (type))
parent_type = "report";
else if (type_is_task_subtype (type))
parent_type = "task";
else if (type_is_config_subtype (type))
parent_type = "config";
else
parent_type = type;

ret = sql_int ("SELECT count (id)"
" FROM tags"
" WHERE resource_type = '%s'"
" AND EXISTS"
" (SELECT * FROM tag_resources"
" WHERE tag = tags.id"
" AND resource = %llu"
" AND resource_location = %d"
" AND tags.resource_type = tag_resources.resource_type)"
" %s;",
type,
resource,
LOCATION_TABLE,
active_only ? "AND active=1": "");
" FROM tags"
" WHERE resource_type = '%s'"
" AND EXISTS"
" (SELECT * FROM tag_resources"
" WHERE tag = tags.id"
" AND resource = %llu"
" AND resource_location = %d"
" AND tag_resources.resource_type = '%s')"
" %s;",
type,
resource,
LOCATION_TABLE,
parent_type,
active_only ? "AND active=1": "");

return ret;
}
Expand Down

0 comments on commit e155756

Please sign in to comment.