virSecurityLabelDef: Declare 'type' as 'virDomainSeclabelType'

Use the appropriate enum type instead of an int and fix the XML parser
and one missing fully populated switch.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-11-22 16:31:44 +01:00
parent 396ce0b568
commit f7ff8556ad
3 changed files with 8 additions and 11 deletions

View File

@ -7813,15 +7813,11 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
/* set default value */ /* set default value */
seclabel->type = VIR_DOMAIN_SECLABEL_DYNAMIC; seclabel->type = VIR_DOMAIN_SECLABEL_DYNAMIC;
p = virXMLPropString(ctxt->node, "type"); if (virXMLPropEnum(ctxt->node, "type",
if (p) { virDomainSeclabelTypeFromString,
seclabel->type = virDomainSeclabelTypeFromString(p); VIR_XML_PROP_NONZERO,
if (seclabel->type <= 0) { &seclabel->type) < 0)
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, goto error;
_("invalid security type '%s'"), p);
goto error;
}
}
if (seclabel->type == VIR_DOMAIN_SECLABEL_STATIC || if (seclabel->type == VIR_DOMAIN_SECLABEL_STATIC ||
seclabel->type == VIR_DOMAIN_SECLABEL_NONE) seclabel->type == VIR_DOMAIN_SECLABEL_NONE)

View File

@ -899,7 +899,8 @@ virSecuritySELinuxGenLabel(virSecurityManager *mgr,
mcs = g_strdup(sens); mcs = g_strdup(sens);
break; break;
case VIR_DOMAIN_SECLABEL_DEFAULT:
case VIR_DOMAIN_SECLABEL_LAST:
default: default:
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected security label type '%s'"), _("unexpected security label type '%s'"),

View File

@ -37,7 +37,7 @@ struct _virSecurityLabelDef {
char *label; /* security label string */ char *label; /* security label string */
char *imagelabel; /* security image label string */ char *imagelabel; /* security image label string */
char *baselabel; /* base name of label string */ char *baselabel; /* base name of label string */
int type; /* virDomainSeclabelType */ virDomainSeclabelType type; /* virDomainSeclabelType */
bool relabel; /* true (default) for allowing relabels */ bool relabel; /* true (default) for allowing relabels */
bool implicit; /* true if seclabel is auto-added */ bool implicit; /* true if seclabel is auto-added */
}; };