{
/* TODO: verify DOI */
virSecurityLabelDef *secdef;
- char *scon = NULL;
- char *str = NULL;
- int rc = -1;
+ g_autofree char *scon = NULL;
+ g_autofree char *str = NULL;
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
if (!secdef || !secdef->label)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("security label driver mismatch: '%1$s' model configured for domain, but hypervisor driver is '%2$s'."),
secdef->model, SECURITY_SELINUX_NAME);
- goto done;
+ goto error;
}
if (getcon_raw(&scon) == -1) {
virReportSystemError(errno,
_("unable to get current process context '%1$s'"),
secdef->label);
- goto done;
+ goto error;
}
if (!(str = virSecuritySELinuxContextAddRange(secdef->label, scon)))
- goto done;
+ goto error;
VIR_DEBUG("Setting VM %s socket context %s", def->name, str);
if (setsockcreatecon_raw(str) == -1) {
virReportSystemError(errno,
_("unable to set socket security context '%1$s'"), str);
- goto done;
+ goto error;
}
- rc = 0;
- done:
+ return 0;
+ error:
if (security_getenforce() != 1)
- rc = 0;
- freecon(scon);
- VIR_FREE(str);
- return rc;
+ return 0;
+
+ return -1;
}
static int
virDomainDef *vm)
{
virSecurityLabelDef *secdef;
- int rc = -1;
secdef = virDomainDefGetSecurityLabelDef(vm, SECURITY_SELINUX_NAME);
if (!secdef || !secdef->label)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("security label driver mismatch: '%1$s' model configured for domain, but hypervisor driver is '%2$s'."),
secdef->model, SECURITY_SELINUX_NAME);
- goto done;
+ goto error;
}
VIR_DEBUG("Setting VM %s socket context %s",
virReportSystemError(errno,
_("unable to set socket security context '%1$s'"),
secdef->label);
- goto done;
+ goto error;
}
- rc = 0;
+ return 0;
- done:
+ error:
if (security_getenforce() != 1)
- rc = 0;
+ return 0;
- return rc;
+ return -1;
}
static int