Skip to content

Commit 38de216

Browse files
a-h-abdelsalamtimopollmeier
authored andcommitted
Fix: Reject creating tags of the wrong subtype
1 parent c8cf045 commit 38de216

File tree

1 file changed

+55
-6
lines changed

1 file changed

+55
-6
lines changed

src/manage_sql.c

+55-6
Original file line numberDiff line numberDiff line change
@@ -57003,14 +57003,18 @@ tag_add_resource (tag_t tag, const char *type, const char *uuid,
5700357003
* @brief Find a resource by UUID and add it as a tag resource.
5700457004
*
5700557005
* @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.
5700757008
* @param[in] uuid The resource UUID.
5700857009
* @param[in] permission The permission required to get the resource.
5700957010
*
5701057011
* @return 0 success, -1 error, 1 resource not found.
5701157012
*/
5701257013
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,
5701457018
const char *permission)
5701557019
{
5701657020
int resource_location = LOCATION_TABLE;
@@ -57041,6 +57045,43 @@ tag_add_resource_uuid (tag_t tag, const char *type, const char *uuid,
5704157045
if (resource == 0)
5704257046
return 1;
5704357047

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+
5704457085
return tag_add_resource (tag, type, uuid, resource, resource_location);
5704557086
}
5704657087

@@ -57061,24 +57102,29 @@ tag_add_resources_list (tag_t tag, const char *type, array_t *uuids,
5706157102
gchar *resource_permission, *current_uuid;
5706257103
int index;
5706357104

57105+
gchar *resource_type = g_strdup (type);
57106+
5706457107
if (type_is_info_subtype (type))
5706557108
resource_permission = g_strdup ("get_info");
5706657109
else if (type_is_asset_subtype (type))
5706757110
resource_permission = g_strdup ("get_assets");
5706857111
else if (type_is_report_subtype (type))
5706957112
{
5707057113
resource_permission = g_strdup ("get_reports");
57071-
type = g_strdup("report");
57114+
g_free (resource_type);
57115+
resource_type = g_strdup("report");
5707257116
}
5707357117
else if (type_is_task_subtype (type))
5707457118
{
5707557119
resource_permission = g_strdup ("get_tasks");
57076-
type = g_strdup("task");
57120+
g_free (resource_type);
57121+
resource_type = g_strdup("task");
5707757122
}
5707857123
else if (type_is_config_subtype (type))
5707957124
{
5708057125
resource_permission = g_strdup ("get_configs");
57081-
type = g_strdup("config");
57126+
g_free (resource_type);
57127+
resource_type = g_strdup("config");
5708257128
}
5708357129
else
5708457130
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,
5708857134
{
5708957135
int ret;
5709057136

57091-
ret = tag_add_resource_uuid (tag, type, current_uuid,
57137+
ret = tag_add_resource_uuid (tag, resource_type, type, current_uuid,
5709257138
resource_permission);
5709357139
if (ret)
5709457140
{
5709557141
g_free (resource_permission);
57142+
g_free (resource_type);
5709657143
if (error_extra)
5709757144
*error_extra = g_strdup (current_uuid);
5709857145
return ret;
5709957146
}
5710057147
}
57148+
g_free (resource_permission);
57149+
g_free (resource_type);
5710157150

5710257151
return 0;
5710357152
}

0 commit comments

Comments
 (0)