mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
conf: seclabel: Parse booleans using virXMLPropTristateBool instead of virStringParseYesNo
Reduce the extent of custom logic and custom error messages by using virXMLPropTristateBool. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
7489b5e37e
commit
9220413480
@ -7801,7 +7801,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
g_autofree char *model = NULL;
|
g_autofree char *model = NULL;
|
||||||
g_autofree char *relabel = NULL;
|
virTristateBool relabel = VIR_TRISTATE_BOOL_ABSENT;
|
||||||
g_autoptr(virSecurityLabelDef) seclabel = NULL;
|
g_autoptr(virSecurityLabelDef) seclabel = NULL;
|
||||||
|
|
||||||
if ((model = virXMLPropString(ctxt->node, "model")) &&
|
if ((model = virXMLPropString(ctxt->node, "model")) &&
|
||||||
@ -7824,13 +7824,10 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
|
|||||||
seclabel->type == VIR_DOMAIN_SECLABEL_NONE)
|
seclabel->type == VIR_DOMAIN_SECLABEL_NONE)
|
||||||
seclabel->relabel = false;
|
seclabel->relabel = false;
|
||||||
|
|
||||||
if ((relabel = virXMLPropString(ctxt->node, "relabel"))) {
|
if (virXMLPropTristateBool(ctxt->node, "relabel", VIR_XML_PROP_NONZERO, &relabel) < 0)
|
||||||
if (virStringParseYesNo(relabel, &seclabel->relabel) < 0) {
|
return NULL;
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("invalid security relabel value '%s'"), relabel);
|
virTristateBoolToBool(relabel, &seclabel->relabel);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (seclabel->type == VIR_DOMAIN_SECLABEL_DYNAMIC &&
|
if (seclabel->type == VIR_DOMAIN_SECLABEL_DYNAMIC &&
|
||||||
!seclabel->relabel) {
|
!seclabel->relabel) {
|
||||||
@ -8029,9 +8026,8 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDef ***seclabels_rtn,
|
|||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
g_autofree char *model = NULL;
|
g_autofree char *model = NULL;
|
||||||
g_autofree char *relabel = NULL;
|
|
||||||
g_autofree char *label = NULL;
|
g_autofree char *label = NULL;
|
||||||
g_autofree char *labelskip = NULL;
|
virTristateBool t;
|
||||||
|
|
||||||
/* get model associated to this override */
|
/* get model associated to this override */
|
||||||
model = virXMLPropString(list[i], "model");
|
model = virXMLPropString(list[i], "model");
|
||||||
@ -8047,23 +8043,20 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDef ***seclabels_rtn,
|
|||||||
seclabels[i]->model = g_steal_pointer(&model);
|
seclabels[i]->model = g_steal_pointer(&model);
|
||||||
}
|
}
|
||||||
|
|
||||||
relabel = virXMLPropString(list[i], "relabel");
|
if (virXMLPropTristateBool(list[i], "relabel", VIR_XML_PROP_NONZERO, &t) < 0)
|
||||||
if (relabel != NULL) {
|
goto error;
|
||||||
if (virStringParseYesNo(relabel, &seclabels[i]->relabel) < 0) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
seclabels[i]->relabel = true;
|
||||||
_("invalid security relabel value %s"),
|
virTristateBoolToBool(t, &seclabels[i]->relabel);
|
||||||
relabel);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
seclabels[i]->relabel = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* labelskip is only parsed on live images */
|
/* labelskip is only parsed on live images */
|
||||||
labelskip = virXMLPropString(list[i], "labelskip");
|
|
||||||
seclabels[i]->labelskip = false;
|
seclabels[i]->labelskip = false;
|
||||||
if (labelskip && !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))
|
if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) {
|
||||||
ignore_value(virStringParseYesNo(labelskip, &seclabels[i]->labelskip));
|
if (virXMLPropTristateBool(list[i], "labelskip", VIR_XML_PROP_NONZERO, &t) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
virTristateBoolToBool(t, &seclabels[i]->labelskip);
|
||||||
|
}
|
||||||
|
|
||||||
ctxt->node = list[i];
|
ctxt->node = list[i];
|
||||||
label = virXPathString("string(./label)", ctxt);
|
label = virXPathString("string(./label)", ctxt);
|
||||||
|
Loading…
Reference in New Issue
Block a user