@@ -57003,14 +57003,18 @@ tag_add_resource (tag_t tag, const char *type, const char *uuid,
57003
57003
* @brief Find a resource by UUID and add it as a tag resource.
57004
57004
*
57005
57005
* @param[in] tag Tag to attach to the resource.
57006
- * @param[in] type The resource Type.
57006
+ * @param[in] type The resource type.
57007
+ * @param[in] tag_type The tag type. Could be a sub-type.
57007
57008
* @param[in] uuid The resource UUID.
57008
57009
* @param[in] permission The permission required to get the resource.
57009
57010
*
57010
57011
* @return 0 success, -1 error, 1 resource not found.
57011
57012
*/
57012
57013
static int
57013
- tag_add_resource_uuid (tag_t tag, const char *type, const char *uuid,
57014
+ tag_add_resource_uuid (tag_t tag,
57015
+ const char *type,
57016
+ const char *tag_type,
57017
+ const char *uuid,
57014
57018
const char *permission)
57015
57019
{
57016
57020
int resource_location = LOCATION_TABLE;
@@ -57041,6 +57045,43 @@ tag_add_resource_uuid (tag_t tag, const char *type, const char *uuid,
57041
57045
if (resource == 0)
57042
57046
return 1;
57043
57047
57048
+ if ((strcmp (type, "task") == 0)
57049
+ || (strcmp (type, "config") == 0)
57050
+ || (strcmp (type, "report") == 0))
57051
+ {
57052
+ gchar *usage_type;
57053
+ if (strcmp (type, "report"))
57054
+ usage_type = sql_string("SELECT usage_type FROM %ss WHERE id = %llu",
57055
+ type, resource);
57056
+ else
57057
+ {
57058
+ task_t task;
57059
+ if (report_task (resource, &task))
57060
+ return -1;
57061
+
57062
+ usage_type = sql_string("SELECT usage_type FROM tasks WHERE id = %llu",
57063
+ task);
57064
+ }
57065
+
57066
+ if (usage_type == NULL)
57067
+ return -1;
57068
+
57069
+ int same_type = (strcmp (tag_type, type) == 0);
57070
+
57071
+ if (same_type && ((strcmp (usage_type, "audit") == 0)
57072
+ || (strcmp (usage_type, "policy") == 0)))
57073
+ {
57074
+ g_free (usage_type);
57075
+ return 1;
57076
+ }
57077
+ if (!same_type && (strcmp (usage_type, "scan") == 0))
57078
+ {
57079
+ g_free (usage_type);
57080
+ return 1;
57081
+ }
57082
+ g_free (usage_type);
57083
+ }
57084
+
57044
57085
return tag_add_resource (tag, type, uuid, resource, resource_location);
57045
57086
}
57046
57087
@@ -57061,24 +57102,29 @@ tag_add_resources_list (tag_t tag, const char *type, array_t *uuids,
57061
57102
gchar *resource_permission, *current_uuid;
57062
57103
int index;
57063
57104
57105
+ gchar *resource_type = g_strdup (type);
57106
+
57064
57107
if (type_is_info_subtype (type))
57065
57108
resource_permission = g_strdup ("get_info");
57066
57109
else if (type_is_asset_subtype (type))
57067
57110
resource_permission = g_strdup ("get_assets");
57068
57111
else if (type_is_report_subtype (type))
57069
57112
{
57070
57113
resource_permission = g_strdup ("get_reports");
57071
- type = g_strdup("report");
57114
+ g_free (resource_type);
57115
+ resource_type = g_strdup("report");
57072
57116
}
57073
57117
else if (type_is_task_subtype (type))
57074
57118
{
57075
57119
resource_permission = g_strdup ("get_tasks");
57076
- type = g_strdup("task");
57120
+ g_free (resource_type);
57121
+ resource_type = g_strdup("task");
57077
57122
}
57078
57123
else if (type_is_config_subtype (type))
57079
57124
{
57080
57125
resource_permission = g_strdup ("get_configs");
57081
- type = g_strdup("config");
57126
+ g_free (resource_type);
57127
+ resource_type = g_strdup("config");
57082
57128
}
57083
57129
else
57084
57130
resource_permission = g_strdup_printf ("get_%ss", type);
@@ -57088,16 +57134,19 @@ tag_add_resources_list (tag_t tag, const char *type, array_t *uuids,
57088
57134
{
57089
57135
int ret;
57090
57136
57091
- ret = tag_add_resource_uuid (tag, type, current_uuid,
57137
+ ret = tag_add_resource_uuid (tag, resource_type, type, current_uuid,
57092
57138
resource_permission);
57093
57139
if (ret)
57094
57140
{
57095
57141
g_free (resource_permission);
57142
+ g_free (resource_type);
57096
57143
if (error_extra)
57097
57144
*error_extra = g_strdup (current_uuid);
57098
57145
return ret;
57099
57146
}
57100
57147
}
57148
+ g_free (resource_permission);
57149
+ g_free (resource_type);
57101
57150
57102
57151
return 0;
57103
57152
}
0 commit comments