提交 13adf1b2 编写于 作者: M Michal Privoznik

virSecurityLabelDef: substitute 'norelabel' with 'relabel'

This negation in names of boolean variables is driving me insane. The
code is much more readable if we drop the 'no-' prefix. Well, at least
for me.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 589c2ad9
...@@ -4576,9 +4576,9 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, ...@@ -4576,9 +4576,9 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
VIR_SECURITY_LABEL_BUFLEN-1, ctxt); VIR_SECURITY_LABEL_BUFLEN-1, ctxt);
if (p != NULL) { if (p != NULL) {
if (STREQ(p, "yes")) { if (STREQ(p, "yes")) {
def->norelabel = false; def->relabel = true;
} else if (STREQ(p, "no")) { } else if (STREQ(p, "no")) {
def->norelabel = true; def->relabel = false;
} else { } else {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("invalid security relabel value %s"), p); _("invalid security relabel value %s"), p);
...@@ -4587,13 +4587,13 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, ...@@ -4587,13 +4587,13 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
} }
VIR_FREE(p); VIR_FREE(p);
if (def->type == VIR_DOMAIN_SECLABEL_DYNAMIC && if (def->type == VIR_DOMAIN_SECLABEL_DYNAMIC &&
def->norelabel) { !def->relabel) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", _("dynamic label type must use resource relabeling")); "%s", _("dynamic label type must use resource relabeling"));
goto error; goto error;
} }
if (def->type == VIR_DOMAIN_SECLABEL_NONE && if (def->type == VIR_DOMAIN_SECLABEL_NONE &&
!def->norelabel) { def->relabel) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", _("resource relabeling is not compatible with 'none' label type")); "%s", _("resource relabeling is not compatible with 'none' label type"));
goto error; goto error;
...@@ -4601,9 +4601,9 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, ...@@ -4601,9 +4601,9 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
} else { } else {
if (def->type == VIR_DOMAIN_SECLABEL_STATIC || if (def->type == VIR_DOMAIN_SECLABEL_STATIC ||
def->type == VIR_DOMAIN_SECLABEL_NONE) def->type == VIR_DOMAIN_SECLABEL_NONE)
def->norelabel = true; def->relabel = false;
else else
def->norelabel = false; def->relabel = true;
} }
/* Always parse model */ /* Always parse model */
...@@ -4635,7 +4635,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, ...@@ -4635,7 +4635,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
} }
/* Only parse imagelabel, if requested live XML with relabeling */ /* Only parse imagelabel, if requested live XML with relabeling */
if (!def->norelabel && if (def->relabel &&
(!(flags & VIR_DOMAIN_XML_INACTIVE) && (!(flags & VIR_DOMAIN_XML_INACTIVE) &&
def->type != VIR_DOMAIN_SECLABEL_NONE)) { def->type != VIR_DOMAIN_SECLABEL_NONE)) {
p = virXPathStringLimit("string(./imagelabel[1])", p = virXPathStringLimit("string(./imagelabel[1])",
...@@ -4793,7 +4793,7 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn, ...@@ -4793,7 +4793,7 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn,
} }
/* Can't use overrides if top-level doesn't allow relabeling. */ /* Can't use overrides if top-level doesn't allow relabeling. */
if (vmDef && vmDef->norelabel) { if (vmDef && !vmDef->relabel) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("label overrides require relabeling to be " _("label overrides require relabeling to be "
"enabled at the domain level")); "enabled at the domain level"));
...@@ -14708,14 +14708,14 @@ virSecurityLabelDefFormat(virBufferPtr buf, ...@@ -14708,14 +14708,14 @@ virSecurityLabelDefFormat(virBufferPtr buf,
} }
virBufferAsprintf(buf, " relabel='%s'", virBufferAsprintf(buf, " relabel='%s'",
def->norelabel ? "no" : "yes"); def->relabel ? "yes" : "no");
if (def->label || def->imagelabel || def->baselabel) { if (def->label || def->imagelabel || def->baselabel) {
virBufferAddLit(buf, ">\n"); virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2); virBufferAdjustIndent(buf, 2);
virBufferEscapeString(buf, "<label>%s</label>\n", virBufferEscapeString(buf, "<label>%s</label>\n",
def->label); def->label);
if (!def->norelabel) if (def->relabel)
virBufferEscapeString(buf, "<imagelabel>%s</imagelabel>\n", virBufferEscapeString(buf, "<imagelabel>%s</imagelabel>\n",
def->imagelabel); def->imagelabel);
if (def->type == VIR_DOMAIN_SECLABEL_DYNAMIC) if (def->type == VIR_DOMAIN_SECLABEL_DYNAMIC)
......
...@@ -281,7 +281,7 @@ reload_profile(virSecurityManagerPtr mgr, ...@@ -281,7 +281,7 @@ reload_profile(virSecurityManagerPtr mgr,
if (!secdef) if (!secdef)
return rc; return rc;
if (secdef->norelabel) if (!secdef->relabel)
return 0; return 0;
if ((profile_name = get_profile_name(def)) == NULL) if ((profile_name = get_profile_name(def)) == NULL)
...@@ -481,7 +481,7 @@ AppArmorSetSecurityAllLabel(virSecurityManagerPtr mgr, ...@@ -481,7 +481,7 @@ AppArmorSetSecurityAllLabel(virSecurityManagerPtr mgr,
if (!secdef) if (!secdef)
return -1; return -1;
if (secdef->norelabel) if (!secdef->relabel)
return 0; return 0;
/* Reload the profile if stdin_path is specified. Note that /* Reload the profile if stdin_path is specified. Note that
...@@ -718,7 +718,7 @@ AppArmorSetSecurityImageLabel(virSecurityManagerPtr mgr, ...@@ -718,7 +718,7 @@ AppArmorSetSecurityImageLabel(virSecurityManagerPtr mgr,
if (!(secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_APPARMOR_NAME))) if (!(secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_APPARMOR_NAME)))
return -1; return -1;
if (secdef->norelabel) if (!secdef->relabel)
return 0; return 0;
if (secdef->imagelabel) { if (secdef->imagelabel) {
...@@ -805,7 +805,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr, ...@@ -805,7 +805,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
if (!secdef) if (!secdef)
return -1; return -1;
if (secdef->norelabel) if (!secdef->relabel)
return 0; return 0;
if (dev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) if (dev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
...@@ -904,7 +904,7 @@ AppArmorRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr, ...@@ -904,7 +904,7 @@ AppArmorRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr,
if (!secdef) if (!secdef)
return -1; return -1;
if (secdef->norelabel) if (!secdef->relabel)
return 0; return 0;
return reload_profile(mgr, def, NULL, false); return reload_profile(mgr, def, NULL, false);
......
...@@ -307,7 +307,7 @@ virSecurityDACSetSecurityImageLabel(virSecurityManagerPtr mgr, ...@@ -307,7 +307,7 @@ virSecurityDACSetSecurityImageLabel(virSecurityManagerPtr mgr,
return 0; return 0;
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME); secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
if (secdef && secdef->norelabel) if (secdef && !secdef->relabel)
return 0; return 0;
disk_seclabel = virStorageSourceGetSecurityLabelDef(src, disk_seclabel = virStorageSourceGetSecurityLabelDef(src,
...@@ -369,7 +369,7 @@ virSecurityDACRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr, ...@@ -369,7 +369,7 @@ virSecurityDACRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr,
return 0; return 0;
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME); secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
if (secdef && secdef->norelabel) if (secdef && !secdef->relabel)
return 0; return 0;
disk_seclabel = virStorageSourceGetSecurityLabelDef(src, disk_seclabel = virStorageSourceGetSecurityLabelDef(src,
...@@ -477,7 +477,7 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr, ...@@ -477,7 +477,7 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
cbdata.manager = mgr; cbdata.manager = mgr;
cbdata.secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME); cbdata.secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
if (cbdata.secdef && cbdata.secdef->norelabel) if (cbdata.secdef && !cbdata.secdef->relabel)
return 0; return 0;
switch ((virDomainHostdevSubsysType) dev->source.subsys.type) { switch ((virDomainHostdevSubsysType) dev->source.subsys.type) {
...@@ -601,7 +601,7 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr, ...@@ -601,7 +601,7 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr,
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME); secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
if (!priv->dynamicOwnership || (secdef && secdef->norelabel)) if (!priv->dynamicOwnership || (secdef && !secdef->relabel))
return 0; return 0;
if (dev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) if (dev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
...@@ -881,7 +881,7 @@ virSecurityDACRestoreSecurityAllLabel(virSecurityManagerPtr mgr, ...@@ -881,7 +881,7 @@ virSecurityDACRestoreSecurityAllLabel(virSecurityManagerPtr mgr,
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME); secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
if (!priv->dynamicOwnership || (secdef && secdef->norelabel)) if (!priv->dynamicOwnership || (secdef && !secdef->relabel))
return 0; return 0;
VIR_DEBUG("Restoring security label on %s migrated=%d", VIR_DEBUG("Restoring security label on %s migrated=%d",
...@@ -955,7 +955,7 @@ virSecurityDACSetSecurityAllLabel(virSecurityManagerPtr mgr, ...@@ -955,7 +955,7 @@ virSecurityDACSetSecurityAllLabel(virSecurityManagerPtr mgr,
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME); secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
if (!priv->dynamicOwnership || (secdef && secdef->norelabel)) if (!priv->dynamicOwnership || (secdef && !secdef->relabel))
return 0; return 0;
for (i = 0; i < def->ndisks; i++) { for (i = 0; i < def->ndisks; i++) {
...@@ -1157,7 +1157,7 @@ virSecurityDACGenLabel(virSecurityManagerPtr mgr, ...@@ -1157,7 +1157,7 @@ virSecurityDACGenLabel(virSecurityManagerPtr mgr,
return rc; return rc;
} }
if (!seclabel->norelabel && !seclabel->imagelabel && if (seclabel->relabel && !seclabel->imagelabel &&
VIR_STRDUP(seclabel->imagelabel, seclabel->label) < 0) { VIR_STRDUP(seclabel->imagelabel, seclabel->label) < 0) {
VIR_FREE(seclabel->label); VIR_FREE(seclabel->label);
return rc; return rc;
......
...@@ -616,7 +616,7 @@ virSecurityManagerGenLabel(virSecurityManagerPtr mgr, ...@@ -616,7 +616,7 @@ virSecurityManagerGenLabel(virSecurityManagerPtr mgr,
seclabel->type = VIR_DOMAIN_SECLABEL_DYNAMIC; seclabel->type = VIR_DOMAIN_SECLABEL_DYNAMIC;
} else { } else {
seclabel->type = VIR_DOMAIN_SECLABEL_NONE; seclabel->type = VIR_DOMAIN_SECLABEL_NONE;
seclabel->norelabel = true; seclabel->relabel = false;
} }
} }
......
...@@ -1130,7 +1130,7 @@ virSecuritySELinuxRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr, ...@@ -1130,7 +1130,7 @@ virSecuritySELinuxRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr,
disk_seclabel = virStorageSourceGetSecurityLabelDef(src, disk_seclabel = virStorageSourceGetSecurityLabelDef(src,
SECURITY_SELINUX_NAME); SECURITY_SELINUX_NAME);
if (seclabel->norelabel || (disk_seclabel && disk_seclabel->norelabel)) if (!seclabel->relabel || (disk_seclabel && disk_seclabel->norelabel))
return 0; return 0;
/* If labelskip is true and there are no backing files, then we /* If labelskip is true and there are no backing files, then we
...@@ -1202,7 +1202,7 @@ virSecuritySELinuxSetSecurityImageLabelInternal(virSecurityManagerPtr mgr, ...@@ -1202,7 +1202,7 @@ virSecuritySELinuxSetSecurityImageLabelInternal(virSecurityManagerPtr mgr,
return 0; return 0;
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
if (!secdef || secdef->norelabel) if (!secdef || !secdef->relabel)
return 0; return 0;
disk_seclabel = virStorageSourceGetSecurityLabelDef(src, disk_seclabel = virStorageSourceGetSecurityLabelDef(src,
...@@ -1456,7 +1456,7 @@ virSecuritySELinuxSetSecurityHostdevLabel(virSecurityManagerPtr mgr ATTRIBUTE_UN ...@@ -1456,7 +1456,7 @@ virSecuritySELinuxSetSecurityHostdevLabel(virSecurityManagerPtr mgr ATTRIBUTE_UN
virSecurityLabelDefPtr secdef; virSecurityLabelDefPtr secdef;
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
if (!secdef || secdef->norelabel) if (!secdef || !secdef->relabel)
return 0; return 0;
switch (dev->mode) { switch (dev->mode) {
...@@ -1641,7 +1641,7 @@ virSecuritySELinuxRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr, ...@@ -1641,7 +1641,7 @@ virSecuritySELinuxRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr,
virSecurityLabelDefPtr secdef; virSecurityLabelDefPtr secdef;
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
if (!secdef || secdef->norelabel) if (!secdef || !secdef->relabel)
return 0; return 0;
switch (dev->mode) { switch (dev->mode) {
...@@ -1670,7 +1670,7 @@ virSecuritySELinuxSetSecurityChardevLabel(virDomainDefPtr def, ...@@ -1670,7 +1670,7 @@ virSecuritySELinuxSetSecurityChardevLabel(virDomainDefPtr def,
int ret = -1; int ret = -1;
seclabel = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); seclabel = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
if (!seclabel || seclabel->norelabel) if (!seclabel || !seclabel->relabel)
return 0; return 0;
if (dev) if (dev)
...@@ -1741,7 +1741,7 @@ virSecuritySELinuxRestoreSecurityChardevLabel(virSecurityManagerPtr mgr, ...@@ -1741,7 +1741,7 @@ virSecuritySELinuxRestoreSecurityChardevLabel(virSecurityManagerPtr mgr,
int ret = -1; int ret = -1;
seclabel = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); seclabel = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
if (!seclabel || seclabel->norelabel) if (!seclabel || !seclabel->relabel)
return 0; return 0;
if (dev) if (dev)
...@@ -1866,10 +1866,8 @@ virSecuritySELinuxRestoreSecurityAllLabel(virSecurityManagerPtr mgr, ...@@ -1866,10 +1866,8 @@ virSecuritySELinuxRestoreSecurityAllLabel(virSecurityManagerPtr mgr,
VIR_DEBUG("Restoring security label on %s", def->name); VIR_DEBUG("Restoring security label on %s", def->name);
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
if (secdef == NULL)
return 0;
if (secdef->norelabel || data->skipAllLabel) if (!secdef || !secdef->relabel || data->skipAllLabel)
return 0; return 0;
if (def->tpm) { if (def->tpm) {
...@@ -1956,7 +1954,7 @@ virSecuritySELinuxSetSavedStateLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED, ...@@ -1956,7 +1954,7 @@ virSecuritySELinuxSetSavedStateLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
virSecurityLabelDefPtr secdef; virSecurityLabelDefPtr secdef;
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
if (!secdef || secdef->norelabel) if (!secdef || !secdef->relabel)
return 0; return 0;
return virSecuritySELinuxSetFilecon(savefile, secdef->imagelabel); return virSecuritySELinuxSetFilecon(savefile, secdef->imagelabel);
...@@ -1971,7 +1969,7 @@ virSecuritySELinuxRestoreSavedStateLabel(virSecurityManagerPtr mgr, ...@@ -1971,7 +1969,7 @@ virSecuritySELinuxRestoreSavedStateLabel(virSecurityManagerPtr mgr,
virSecurityLabelDefPtr secdef; virSecurityLabelDefPtr secdef;
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
if (!secdef || secdef->norelabel) if (!secdef || !secdef->relabel)
return 0; return 0;
return virSecuritySELinuxRestoreSecurityFileLabel(mgr, savefile); return virSecuritySELinuxRestoreSecurityFileLabel(mgr, savefile);
...@@ -2245,10 +2243,8 @@ virSecuritySELinuxSetSecurityAllLabel(virSecurityManagerPtr mgr, ...@@ -2245,10 +2243,8 @@ virSecuritySELinuxSetSecurityAllLabel(virSecurityManagerPtr mgr,
virSecurityLabelDefPtr secdef; virSecurityLabelDefPtr secdef;
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
if (secdef == NULL)
return 0;
if (secdef->norelabel || data->skipAllLabel) if (!secdef || !secdef->relabel || data->skipAllLabel)
return 0; return 0;
for (i = 0; i < def->ndisks; i++) { for (i = 0; i < def->ndisks; i++) {
......
...@@ -64,6 +64,8 @@ virSecurityLabelDefNew(const char *model) ...@@ -64,6 +64,8 @@ virSecurityLabelDefNew(const char *model)
seclabel = NULL; seclabel = NULL;
} }
seclabel->relabel = true;
return seclabel; return seclabel;
} }
......
...@@ -40,7 +40,7 @@ struct _virSecurityLabelDef { ...@@ -40,7 +40,7 @@ struct _virSecurityLabelDef {
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 */ int type; /* virDomainSeclabelType */
bool norelabel; bool relabel; /* true (default) for allowing relabels */
bool implicit; /* true if seclabel is auto-added */ bool implicit; /* true if seclabel is auto-added */
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册