From f7ff8556ad9ba8d81408e31649071941a6a849a3 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 22 Nov 2021 16:31:44 +0100 Subject: [PATCH] virSecurityLabelDef: Declare 'type' as 'virDomainSeclabelType' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko --- src/conf/domain_conf.c | 14 +++++--------- src/security/security_selinux.c | 3 ++- src/util/virseclabel.h | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 552d43b845..ba38d510dd 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7813,15 +7813,11 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, /* set default value */ seclabel->type = VIR_DOMAIN_SECLABEL_DYNAMIC; - p = virXMLPropString(ctxt->node, "type"); - if (p) { - seclabel->type = virDomainSeclabelTypeFromString(p); - if (seclabel->type <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid security type '%s'"), p); - goto error; - } - } + if (virXMLPropEnum(ctxt->node, "type", + virDomainSeclabelTypeFromString, + VIR_XML_PROP_NONZERO, + &seclabel->type) < 0) + goto error; if (seclabel->type == VIR_DOMAIN_SECLABEL_STATIC || seclabel->type == VIR_DOMAIN_SECLABEL_NONE) diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 840a05844e..5682d2bb9d 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -899,7 +899,8 @@ virSecuritySELinuxGenLabel(virSecurityManager *mgr, mcs = g_strdup(sens); break; - + case VIR_DOMAIN_SECLABEL_DEFAULT: + case VIR_DOMAIN_SECLABEL_LAST: default: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected security label type '%s'"), diff --git a/src/util/virseclabel.h b/src/util/virseclabel.h index 77bf6da2c3..eca4d09d24 100644 --- a/src/util/virseclabel.h +++ b/src/util/virseclabel.h @@ -37,7 +37,7 @@ struct _virSecurityLabelDef { char *label; /* security label string */ char *imagelabel; /* security image label string */ char *baselabel; /* base name of label string */ - int type; /* virDomainSeclabelType */ + virDomainSeclabelType type; /* virDomainSeclabelType */ bool relabel; /* true (default) for allowing relabels */ bool implicit; /* true if seclabel is auto-added */ };