]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virSecurityLabelDef: Declare 'type' as 'virDomainSeclabelType'
authorPeter Krempa <pkrempa@redhat.com>
Mon, 22 Nov 2021 15:31:44 +0000 (16:31 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 24 Nov 2021 08:20:38 +0000 (09:20 +0100)
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>
src/conf/domain_conf.c
src/security/security_selinux.c
src/util/virseclabel.h

index 552d43b845d75e45b8c4f6d42f1a4ad191fe5fa0..ba38d510dd4d96359722c79ddd0e17976f8fa17f 100644 (file)
@@ -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)
index 840a05844e4ff914cd2f31ef506ab3dcce51cc3c..5682d2bb9daea1c1013132201c2838f4edb85a81 100644 (file)
@@ -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'"),
index 77bf6da2c32795fd3e257f7d75c9b64f89c401d0..eca4d09d240bbbc3eb6f69b4b341c73c1d1ea185 100644 (file)
@@ -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 */
 };