char *path;
char *tcon;
bool optional;
+ bool remember; /* Whether owner remembering should be done for @path/@src */
bool restore; /* Whether current operation is 'set' or 'restore' */
};
const char *path,
const char *tcon,
bool optional,
+ bool remember,
bool restore)
{
int ret = -1;
goto cleanup;
item->optional = optional;
+ item->remember = remember;
item->restore = restore;
if (VIR_APPEND_ELEMENT(list->items, list->nItems, item) < 0)
* @path: Path to chown
* @tcon: target context
* @optional: true if setting @tcon is optional
+ * @remember: if the original owner should be recorded/recalled
* @restore: if current operation is set or restore
*
* Appends an entry onto transaction list.
+ * The @remember should be true if caller wishes to record/recall
+ * the original owner of @path/@src.
* The @restore should be true if the operation is restoring
* seclabel and false otherwise.
*
virSecuritySELinuxTransactionAppend(const char *path,
const char *tcon,
bool optional,
+ bool remember,
bool restore)
{
virSecuritySELinuxContextListPtr list;
if (!list)
return 0;
- if (virSecuritySELinuxContextListAppend(list, path, tcon, optional, restore) < 0)
+ if (virSecuritySELinuxContextListAppend(list, path, tcon,
+ optional, remember, restore) < 0)
return -1;
return 1;
rv = 0;
for (i = 0; i < list->nItems; i++) {
virSecuritySELinuxContextItemPtr item = list->items[i];
+ const bool remember = item->remember && list->lock;
if (!item->restore) {
rv = virSecuritySELinuxSetFileconHelper(list->manager,
item->path,
item->tcon,
item->optional,
- list->lock);
+ remember);
} else {
rv = virSecuritySELinuxRestoreFileLabel(list->manager,
item->path,
- list->lock);
+ remember);
}
if (rv < 0)
for (; rv < 0 && i > 0; i--) {
virSecuritySELinuxContextItemPtr item = list->items[i - 1];
+ const bool remember = item->remember && list->lock;
if (!item->restore) {
virSecuritySELinuxRestoreFileLabel(list->manager,
item->path,
- list->lock);
+ remember);
} else {
VIR_WARN("Ignoring failed restore attempt on %s", item->path);
}
int rc;
int ret = -1;
- if ((rc = virSecuritySELinuxTransactionAppend(path, tcon, optional, false)) < 0)
+ if ((rc = virSecuritySELinuxTransactionAppend(path, tcon,
+ optional, remember, false)) < 0)
return -1;
else if (rc > 0)
return 0;
static int
virSecuritySELinuxSetFileconOptional(virSecurityManagerPtr mgr,
- const char *path, const char *tcon)
+ const char *path,
+ const char *tcon,
+ bool remember)
{
- return virSecuritySELinuxSetFileconHelper(mgr, path, tcon, true, false);
+ return virSecuritySELinuxSetFileconHelper(mgr, path, tcon, true, remember);
}
static int
virSecuritySELinuxSetFilecon(virSecurityManagerPtr mgr,
- const char *path, const char *tcon)
+ const char *path,
+ const char *tcon,
+ bool remember)
{
- return virSecuritySELinuxSetFileconHelper(mgr, path, tcon, false, false);
+ return virSecuritySELinuxSetFileconHelper(mgr, path, tcon, false, remember);
}
static int
goto cleanup;
}
- if ((rc = virSecuritySELinuxTransactionAppend(path, NULL, false, true)) < 0) {
+ if ((rc = virSecuritySELinuxTransactionAppend(path, NULL,
+ false, recall, true)) < 0) {
goto cleanup;
} else if (rc > 0) {
ret = 0;
switch ((virDomainInputType)input->type) {
case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
if (virSecuritySELinuxSetFilecon(mgr, input->source.evdev,
- seclabel->imagelabel) < 0)
+ seclabel->imagelabel, true) < 0)
return -1;
break;
switch ((virDomainInputType)input->type) {
case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
- rc = virSecuritySELinuxRestoreFileLabel(mgr, input->source.evdev, false);
+ rc = virSecuritySELinuxRestoreFileLabel(mgr, input->source.evdev, true);
break;
case VIR_DOMAIN_INPUT_TYPE_MOUSE:
return 0;
if (virSecuritySELinuxSetFilecon(mgr, mem->nvdimmPath,
- seclabel->imagelabel) < 0)
+ seclabel->imagelabel, true) < 0)
return -1;
break;
if (!seclabel || !seclabel->relabel)
return 0;
- ret = virSecuritySELinuxRestoreFileLabel(mgr, mem->nvdimmPath, false);
+ ret = virSecuritySELinuxRestoreFileLabel(mgr, mem->nvdimmPath, true);
break;
case VIR_DOMAIN_MEMORY_MODEL_DIMM:
switch (tpm->type) {
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
tpmdev = tpm->data.passthrough.source.data.file.path;
- rc = virSecuritySELinuxSetFilecon(mgr, tpmdev, seclabel->imagelabel);
+ rc = virSecuritySELinuxSetFilecon(mgr, tpmdev, seclabel->imagelabel, true);
if (rc < 0)
return -1;
if ((cancel_path = virTPMCreateCancelPath(tpmdev)) != NULL) {
rc = virSecuritySELinuxSetFilecon(mgr,
cancel_path,
- seclabel->imagelabel);
+ seclabel->imagelabel, true);
VIR_FREE(cancel_path);
if (rc < 0) {
virSecuritySELinuxRestoreTPMFileLabelInt(mgr, def, tpm);
break;
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
tpmdev = tpm->data.emulator.source.data.nix.path;
- rc = virSecuritySELinuxSetFilecon(mgr, tpmdev, seclabel->imagelabel);
+ rc = virSecuritySELinuxSetFilecon(mgr, tpmdev, seclabel->imagelabel, true);
if (rc < 0)
return -1;
break;
switch (tpm->type) {
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
tpmdev = tpm->data.passthrough.source.data.file.path;
- rc = virSecuritySELinuxRestoreFileLabel(mgr, tpmdev, false);
+ rc = virSecuritySELinuxRestoreFileLabel(mgr, tpmdev, true);
if ((cancel_path = virTPMCreateCancelPath(tpmdev)) != NULL) {
- if (virSecuritySELinuxRestoreFileLabel(mgr, cancel_path, false) < 0)
+ if (virSecuritySELinuxRestoreFileLabel(mgr, cancel_path, true) < 0)
rc = -1;
VIR_FREE(cancel_path);
}
}
}
- return virSecuritySELinuxRestoreFileLabel(mgr, src->path, false);
+ return virSecuritySELinuxRestoreFileLabel(mgr, src->path, true);
}
if (!disk_seclabel->relabel)
return 0;
- ret = virSecuritySELinuxSetFilecon(mgr, src->path, disk_seclabel->label);
+ ret = virSecuritySELinuxSetFilecon(mgr, src->path,
+ disk_seclabel->label, true);
} else if (parent_seclabel && (!parent_seclabel->relabel || parent_seclabel->label)) {
if (!parent_seclabel->relabel)
return 0;
- ret = virSecuritySELinuxSetFilecon(mgr, src->path, parent_seclabel->label);
+ ret = virSecuritySELinuxSetFilecon(mgr, src->path,
+ parent_seclabel->label, true);
} else if (!parent || parent == src) {
if (src->shared) {
ret = virSecuritySELinuxSetFileconOptional(mgr,
src->path,
- data->file_context);
+ data->file_context,
+ true);
} else if (src->readonly) {
ret = virSecuritySELinuxSetFileconOptional(mgr,
src->path,
- data->content_context);
+ data->content_context,
+ true);
} else if (secdef->imagelabel) {
ret = virSecuritySELinuxSetFileconOptional(mgr,
src->path,
- secdef->imagelabel);
+ secdef->imagelabel,
+ true);
} else {
ret = 0;
}
} else {
ret = virSecuritySELinuxSetFileconOptional(mgr,
src->path,
- data->content_context);
+ data->content_context,
+ true);
}
if (ret == 1 && !disk_seclabel) {
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
if (secdef == NULL)
return 0;
- return virSecuritySELinuxSetFilecon(mgr, file, secdef->imagelabel);
+ return virSecuritySELinuxSetFilecon(mgr, file, secdef->imagelabel, true);
}
static int
if (virSCSIDeviceGetShareable(dev))
return virSecuritySELinuxSetFileconOptional(mgr, file,
- data->file_context);
+ data->file_context, true);
else if (virSCSIDeviceGetReadonly(dev))
return virSecuritySELinuxSetFileconOptional(mgr, file,
- data->content_context);
+ data->content_context, true);
else
return virSecuritySELinuxSetFileconOptional(mgr, file,
- secdef->imagelabel);
+ secdef->imagelabel, true);
}
static int
if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0)
return -1;
}
- ret = virSecuritySELinuxSetFilecon(mgr, path, secdef->imagelabel);
+ ret = virSecuritySELinuxSetFilecon(mgr, path, secdef->imagelabel, true);
VIR_FREE(path);
break;
}
if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0)
return -1;
}
- ret = virSecuritySELinuxSetFilecon(mgr, path, secdef->imagelabel);
+ ret = virSecuritySELinuxSetFilecon(mgr, path, secdef->imagelabel, true);
VIR_FREE(path);
break;
}
{
virSecurityManagerPtr mgr = opaque;
- return virSecuritySELinuxRestoreFileLabel(mgr, file, false);
+ return virSecuritySELinuxRestoreFileLabel(mgr, file, true);
}
static int
{
virSecurityManagerPtr mgr = opaque;
- return virSecuritySELinuxRestoreFileLabel(mgr, file, false);
+ return virSecuritySELinuxRestoreFileLabel(mgr, file, true);
}
if (virSCSIDeviceGetShareable(dev) || virSCSIDeviceGetReadonly(dev))
return 0;
- return virSecuritySELinuxRestoreFileLabel(mgr, file, false);
+ return virSecuritySELinuxRestoreFileLabel(mgr, file, true);
}
static int
{
virSecurityManagerPtr mgr = opaque;
- return virSecuritySELinuxRestoreFileLabel(mgr, file, false);
+ return virSecuritySELinuxRestoreFileLabel(mgr, file, true);
}
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
goto done;
- ret = virSecuritySELinuxRestoreFileLabel(mgr, vfiodev, false);
+ ret = virSecuritySELinuxRestoreFileLabel(mgr, vfiodev, true);
VIR_FREE(vfiodev);
break;
if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0)
return -1;
}
- ret = virSecuritySELinuxRestoreFileLabel(mgr, path, false);
+ ret = virSecuritySELinuxRestoreFileLabel(mgr, path, true);
VIR_FREE(path);
break;
}
if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0)
return -1;
}
- ret = virSecuritySELinuxRestoreFileLabel(mgr, path, false);
+ ret = virSecuritySELinuxRestoreFileLabel(mgr, path, true);
VIR_FREE(path);
break;
}
case VIR_DOMAIN_CHR_TYPE_FILE:
ret = virSecuritySELinuxSetFilecon(mgr,
dev_source->data.file.path,
- imagelabel);
+ imagelabel,
+ true);
break;
case VIR_DOMAIN_CHR_TYPE_UNIX:
if (!dev_source->data.nix.listen) {
if (virSecuritySELinuxSetFilecon(mgr,
dev_source->data.nix.path,
- imagelabel) < 0)
+ imagelabel,
+ true) < 0)
goto done;
}
ret = 0;
(virAsprintf(&out, "%s.out", dev_source->data.file.path) < 0))
goto done;
if (virFileExists(in) && virFileExists(out)) {
- if ((virSecuritySELinuxSetFilecon(mgr, in, imagelabel) < 0) ||
- (virSecuritySELinuxSetFilecon(mgr, out, imagelabel) < 0)) {
+ if ((virSecuritySELinuxSetFilecon(mgr, in, imagelabel, true) < 0) ||
+ (virSecuritySELinuxSetFilecon(mgr, out, imagelabel, true) < 0)) {
goto done;
}
} else if (virSecuritySELinuxSetFilecon(mgr,
dev_source->data.file.path,
- imagelabel) < 0) {
+ imagelabel,
+ true) < 0) {
goto done;
}
ret = 0;
case VIR_DOMAIN_CHR_TYPE_FILE:
if (virSecuritySELinuxRestoreFileLabel(mgr,
dev_source->data.file.path,
- false) < 0)
+ true) < 0)
goto done;
ret = 0;
break;
if (!dev_source->data.nix.listen) {
if (virSecuritySELinuxRestoreFileLabel(mgr,
dev_source->data.file.path,
- false) < 0)
+ true) < 0)
goto done;
}
ret = 0;
(virAsprintf(&in, "%s.in", dev_source->data.file.path) < 0))
goto done;
if (virFileExists(in) && virFileExists(out)) {
- if ((virSecuritySELinuxRestoreFileLabel(mgr, out, false) < 0) ||
- (virSecuritySELinuxRestoreFileLabel(mgr, in, false) < 0)) {
+ if ((virSecuritySELinuxRestoreFileLabel(mgr, out, true) < 0) ||
+ (virSecuritySELinuxRestoreFileLabel(mgr, in, true) < 0)) {
goto done;
}
} else if (virSecuritySELinuxRestoreFileLabel(mgr,
dev_source->data.file.path,
- false) < 0) {
+ true) < 0) {
goto done;
}
ret = 0;
database = dev->data.cert.database;
if (!database)
database = VIR_DOMAIN_SMARTCARD_DEFAULT_DATABASE;
- return virSecuritySELinuxRestoreFileLabel(mgr, database, false);
+ return virSecuritySELinuxRestoreFileLabel(mgr, database, true);
case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH:
return virSecuritySELinuxRestoreChardevLabel(mgr, def,
rc = -1;
if (def->os.loader && def->os.loader->nvram &&
- virSecuritySELinuxRestoreFileLabel(mgr, def->os.loader->nvram, false) < 0)
+ virSecuritySELinuxRestoreFileLabel(mgr, def->os.loader->nvram, true) < 0)
rc = -1;
if (def->os.kernel &&
- virSecuritySELinuxRestoreFileLabel(mgr, def->os.kernel, false) < 0)
+ virSecuritySELinuxRestoreFileLabel(mgr, def->os.kernel, true) < 0)
rc = -1;
if (def->os.initrd &&
- virSecuritySELinuxRestoreFileLabel(mgr, def->os.initrd, false) < 0)
+ virSecuritySELinuxRestoreFileLabel(mgr, def->os.initrd, true) < 0)
rc = -1;
if (def->os.dtb &&
- virSecuritySELinuxRestoreFileLabel(mgr, def->os.dtb, false) < 0)
+ virSecuritySELinuxRestoreFileLabel(mgr, def->os.dtb, true) < 0)
rc = -1;
if (def->os.slic_table &&
- virSecuritySELinuxRestoreFileLabel(mgr, def->os.slic_table, false) < 0)
+ virSecuritySELinuxRestoreFileLabel(mgr, def->os.slic_table, true) < 0)
rc = -1;
return rc;
if (!secdef || !secdef->relabel)
return 0;
- return virSecuritySELinuxSetFilecon(mgr, savefile, secdef->imagelabel);
+ return virSecuritySELinuxSetFilecon(mgr, savefile, secdef->imagelabel, true);
}
if (!secdef || !secdef->relabel)
return 0;
- return virSecuritySELinuxRestoreFileLabel(mgr, savefile, false);
+ return virSecuritySELinuxRestoreFileLabel(mgr, savefile, true);
}
database = dev->data.cert.database;
if (!database)
database = VIR_DOMAIN_SMARTCARD_DEFAULT_DATABASE;
- return virSecuritySELinuxSetFilecon(mgr, database, data->content_context);
+ return virSecuritySELinuxSetFilecon(mgr, database, data->content_context, true);
case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH:
return virSecuritySELinuxSetChardevLabel(mgr, def,
if (def->os.loader && def->os.loader->nvram &&
secdef && secdef->imagelabel &&
virSecuritySELinuxSetFilecon(mgr, def->os.loader->nvram,
- secdef->imagelabel) < 0)
+ secdef->imagelabel, true) < 0)
return -1;
if (def->os.kernel &&
virSecuritySELinuxSetFilecon(mgr, def->os.kernel,
- data->content_context) < 0)
+ data->content_context, true) < 0)
return -1;
if (def->os.initrd &&
virSecuritySELinuxSetFilecon(mgr, def->os.initrd,
- data->content_context) < 0)
+ data->content_context, true) < 0)
return -1;
if (def->os.dtb &&
virSecuritySELinuxSetFilecon(mgr, def->os.dtb,
- data->content_context) < 0)
+ data->content_context, true) < 0)
return -1;
if (def->os.slic_table &&
virSecuritySELinuxSetFilecon(mgr, def->os.slic_table,
- data->content_context) < 0)
+ data->content_context, true) < 0)
return -1;
if (stdin_path &&
virSecuritySELinuxSetFilecon(mgr, stdin_path,
- data->content_context) < 0)
+ data->content_context, true) < 0)
return -1;
return 0;
if (!seclabel || !seclabel->relabel)
return 0;
- return virSecuritySELinuxSetFilecon(mgr, path, seclabel->imagelabel);
+ return virSecuritySELinuxSetFilecon(mgr, path, seclabel->imagelabel, true);
}
char *filename = NULL;
DIR *dir;
- if ((ret = virSecuritySELinuxSetFilecon(mgr, path, seclabel->imagelabel)))
+ if ((ret = virSecuritySELinuxSetFilecon(mgr, path, seclabel->imagelabel, true)))
return ret;
if (!virFileIsDir(path))
break;
}
ret = virSecuritySELinuxSetFilecon(mgr, filename,
- seclabel->imagelabel);
+ seclabel->imagelabel, true);
VIR_FREE(filename);
if (ret < 0)
break;
char *filename = NULL;
DIR *dir;
- if ((ret = virSecuritySELinuxRestoreFileLabel(mgr, path, false)))
+ if ((ret = virSecuritySELinuxRestoreFileLabel(mgr, path, true)))
return ret;
if (!virFileIsDir(path))
ret = -1;
break;
}
- ret = virSecuritySELinuxRestoreFileLabel(mgr, filename, false);
+ ret = virSecuritySELinuxRestoreFileLabel(mgr, filename, true);
VIR_FREE(filename);
if (ret < 0)
break;