Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fix missing tags in compliance reports, audits and policies #2339

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading