Skip to content

Commit

Permalink
Tags can now be used with audit tasks and compliance policies
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h-abdelsalam committed Feb 5, 2024
1 parent 9d0bcfe commit 9ef9c3a
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 16 deletions.
40 changes: 29 additions & 11 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -15326,7 +15326,17 @@ select_resource_iterator (get_resource_names_data_t *resource_names_data,
else if (g_strcmp0 ("config", resource_names_data->type) == 0)
{
*iterator = (int (*) (iterator_t*, get_data_t *))init_config_iterator;
}
get_data_set_extra (&resource_names_data->get,
"usage_type",
g_strdup ("scan"));
}
else if (g_strcmp0 ("policy", resource_names_data->type) == 0)
{
*iterator = (int (*) (iterator_t*, get_data_t *))init_config_iterator;
get_data_set_extra (&resource_names_data->get,
"usage_type",
g_strdup ("policy"));
}
else if (g_strcmp0 ("scanner", resource_names_data->type) == 0)
{
*iterator = (int (*) (iterator_t*, get_data_t *))init_scanner_iterator;
Expand All @@ -15342,7 +15352,17 @@ select_resource_iterator (get_resource_names_data_t *resource_names_data,
else if (g_strcmp0 ("task", resource_names_data->type) == 0)
{
*iterator = (int (*) (iterator_t*, get_data_t *))init_task_iterator;
}
get_data_set_extra (&resource_names_data->get,
"usage_type",
g_strdup ("scan"));
}
else if (g_strcmp0 ("audit", resource_names_data->type) == 0)
{
*iterator = (int (*) (iterator_t*, get_data_t *))init_task_iterator;
get_data_set_extra (&resource_names_data->get,
"usage_type",
g_strdup ("audit"));
}
else if (g_strcmp0 ("tls_certificate", resource_names_data->type) == 0)
{
*iterator = (int (*) (iterator_t*, get_data_t *))init_tls_certificate_iterator;
Expand Down Expand Up @@ -15394,7 +15414,13 @@ handle_get_resource_names (gmp_parser_t *gmp_parser, GError **error)
|| (g_strcmp0 ("nvt", get_resource_names_data->type) == 0)
|| (g_strcmp0 ("cert_bund_adv", get_resource_names_data->type) == 0)
|| (g_strcmp0 ("dfn_cert_adv", get_resource_names_data->type) == 0))
&& (acl_user_may ("get_info") == 0)))
&& (acl_user_may ("get_info") == 0))
|| (((g_strcmp0 ("config", get_resource_names_data->type) == 0)
||(g_strcmp0 ("policy", get_resource_names_data->type) == 0))
&& (acl_user_may ("get_configs") == 0))
|| (((g_strcmp0 ("task", get_resource_names_data->type) == 0)
||(g_strcmp0 ("audit", get_resource_names_data->type) == 0))
&& (acl_user_may ("get_tasks") == 0)))
{
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("get_resource_names",
Expand Down Expand Up @@ -15478,14 +15504,6 @@ handle_get_resource_names (gmp_parser_t *gmp_parser, GError **error)

while (next (&resource))
{
if ((g_strcmp0 ("task", get_resource_names_data->type) == 0
&& g_strcmp0 ("audit", task_iterator_usage_type(&resource)) == 0)
|| (g_strcmp0 ("config", get_resource_names_data->type) == 0
&& g_strcmp0 ("policy", config_iterator_usage_type(&resource)) == 0))
{
continue;
}

GString *result;
result = g_string_new ("");

Expand Down
88 changes: 83 additions & 5 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -3975,7 +3975,9 @@ valid_type (const char* type)
int
valid_subtype (const char* type)
{
return (strcasecmp (type, "audit_report") == 0);
return (strcasecmp (type, "audit_report") == 0)
|| (strcasecmp (type, "audit") == 0)
|| (strcasecmp (type, "policy") == 0);
}

/**
Expand Down Expand Up @@ -4085,6 +4087,32 @@ type_is_report_subtype (const char *type)
return (strcasecmp (type, "audit_report") == 0);
}

/**
* @brief Check whether a resource type is a task subtype.
*
* @param[in] type Type of resource.
*
* @return 1 yes, 0 no.
*/
static int
type_is_task_subtype (const char *type)
{
return (strcasecmp (type, "audit") == 0);
}

/**
* @brief Check whether a resource type is a config subtype.
*
* @param[in] type Type of resource.
*
* @return 1 yes, 0 no.
*/
static int
type_is_config_subtype (const char *type)
{
return (strcasecmp (type, "policy") == 0);
}

/**
* @brief Check whether a type has a name and comment.
*
Expand Down Expand Up @@ -56861,10 +56889,20 @@ tag_add_resources_list (tag_t tag, const char *type, array_t *uuids,
else if (type_is_asset_subtype (type))
resource_permission = g_strdup ("get_assets");
else if (type_is_report_subtype (type))
{
resource_permission = g_strdup ("get_reports");
type = g_strdup("report");
}
{
resource_permission = g_strdup ("get_reports");
type = g_strdup("report");
}
else if (type_is_task_subtype (type))
{
resource_permission = g_strdup ("get_tasks");
type = g_strdup("task");
}
else if (type_is_config_subtype (type))
{
resource_permission = g_strdup ("get_configs");
type = g_strdup("config");
}
else
resource_permission = g_strdup_printf ("get_%ss", type);

Expand Down Expand Up @@ -56938,6 +56976,26 @@ tag_add_resources_filter (tag_t tag, const char *type, const char *filter)
{
get_data_set_extra (&resources_get, "usage_type", g_strdup ("scan"));
}
else if (strcasecmp (type, "task") == 0)
{
get_data_set_extra (&resources_get, "usage_type", g_strdup ("scan"));
}
else if (strcasecmp (type, "audit") == 0)
{
type = g_strdup ("task");
resources_get.type = g_strdup (type);
get_data_set_extra (&resources_get, "usage_type", g_strdup ("audit"));
}
else if (strcasecmp (type, "policy") == 0)
{
type = g_strdup ("config");
resources_get.type = g_strdup (type);
get_data_set_extra (&resources_get, "usage_type", g_strdup ("policy"));
}
else if (strcasecmp (type, "config") == 0)
{
get_data_set_extra (&resources_get, "usage_type", g_strdup ("scan"));
}

gchar *columns;

Expand Down Expand Up @@ -57101,6 +57159,26 @@ tag_remove_resources_filter (tag_t tag, const char *type, const char *filter)
{
get_data_set_extra (&resources_get, "usage_type", g_strdup ("scan"));
}
else if (strcasecmp (type, "task") == 0)
{
get_data_set_extra (&resources_get, "usage_type", g_strdup ("scan"));
}
else if (strcasecmp (type, "audit") == 0)
{
type = g_strdup ("task");
resources_get.type = g_strdup (type);
get_data_set_extra (&resources_get, "usage_type", g_strdup ("audit"));
}
else if (strcasecmp (type, "policy") == 0)
{
type = g_strdup ("config");
resources_get.type = g_strdup (type);
get_data_set_extra (&resources_get, "usage_type", g_strdup ("policy"));
}
else if (strcasecmp (type, "config") == 0)
{
get_data_set_extra (&resources_get, "usage_type", g_strdup ("scan"));
}

gchar *columns;

Expand Down

0 comments on commit 9ef9c3a

Please sign in to comment.