From 0ee655f5f5ade7cb33e1f93af18c6948591d0fba Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 24 Aug 2012 14:59:59 +0200 Subject: [PATCH] conf: Don't always require security/@model Only parse model, if static labelling, or a base label is set, or doing active XML. --- src/conf/domain_conf.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 419088cbcd..816a9c773f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3121,14 +3121,22 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, def->baselabel = p; } - /* Always parse model */ - p = virXPathStringLimit("string(./@model)", - VIR_SECURITY_MODEL_BUFLEN-1, ctxt); - if (p == NULL && def->type != VIR_DOMAIN_SECLABEL_NONE) { - virReportError(VIR_ERR_XML_ERROR, - "%s", _("missing security model")); + /* Only parse model, if static labelling, or a base + * label is set, or doing active XML + */ + if (def->type == VIR_DOMAIN_SECLABEL_STATIC || + def->baselabel || + (!(flags & VIR_DOMAIN_XML_INACTIVE) && + def->type != VIR_DOMAIN_SECLABEL_NONE)) { + + p = virXPathStringLimit("string(./@model)", + VIR_SECURITY_MODEL_BUFLEN-1, ctxt); + if (p == NULL && def->type != VIR_DOMAIN_SECLABEL_NONE) { + virReportError(VIR_ERR_XML_ERROR, + "%s", _("missing security model")); + } + def->model = p; } - def->model = p; return def; @@ -3225,12 +3233,8 @@ virSecurityDeviceLabelDefParseXML(virDomainDiskDefPtr def, for (i = 0; i < n; i++) { /* get model associated to this override */ model = virXMLPropString(list[i], "model"); - if (model == NULL) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("invalid security model")); - goto error; - } else { - /* find the security label that it's being overriden */ + if (model) { + /* find the security label that it's being overridden */ for (j = 0; j < nvmSeclabels; j++) { if (STREQ(vmSeclabels[j]->model, model)) { vmDef = vmSeclabels[j]; @@ -3275,7 +3279,7 @@ virSecurityDeviceLabelDefParseXML(virDomainDiskDefPtr def, virReportError(VIR_ERR_XML_ERROR, _("Cannot specify a label if relabelling is " "turned off. model=%s"), - def->seclabels[i]->model); + NULLSTR(def->seclabels[i]->model)); goto error; } } @@ -11271,8 +11275,13 @@ static void virSecurityDeviceLabelDefFormat(virBufferPtr buf, virSecurityDeviceLabelDefPtr def) { - virBufferAsprintf(buf, "model, def->norelabel ? "no" : "yes"); + virBufferAsprintf(buf, "model) + virBufferAsprintf(buf, " model='%s'", def->model); + + virBufferAsprintf(buf, " relabel='%s'", def->norelabel ? "no" : "yes"); + if (def->label) { virBufferAddLit(buf, ">\n"); virBufferEscapeString(buf, " \n", -- GitLab