mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
security: selinux: Simplify SetImageLabelInternal
All the SetFileCon calls only differ by the label they pass in. Rework the conditionals to track what label we need, and use a single SetFileCon call Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
efe3575e60
commit
6f1cd0a54e
@ -1824,6 +1824,7 @@ virSecuritySELinuxSetImageLabelInternal(virSecurityManagerPtr mgr,
|
|||||||
virSecurityLabelDefPtr secdef;
|
virSecurityLabelDefPtr secdef;
|
||||||
virSecurityDeviceLabelDefPtr disk_seclabel;
|
virSecurityDeviceLabelDefPtr disk_seclabel;
|
||||||
virSecurityDeviceLabelDefPtr parent_seclabel = NULL;
|
virSecurityDeviceLabelDefPtr parent_seclabel = NULL;
|
||||||
|
char *use_label = NULL;
|
||||||
bool remember;
|
bool remember;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -1858,40 +1859,28 @@ virSecuritySELinuxSetImageLabelInternal(virSecurityManagerPtr mgr,
|
|||||||
if (!disk_seclabel->relabel)
|
if (!disk_seclabel->relabel)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ret = virSecuritySELinuxSetFilecon(mgr, src->path,
|
use_label = disk_seclabel->label;
|
||||||
disk_seclabel->label, remember);
|
|
||||||
} else if (parent_seclabel && (!parent_seclabel->relabel || parent_seclabel->label)) {
|
} else if (parent_seclabel && (!parent_seclabel->relabel || parent_seclabel->label)) {
|
||||||
if (!parent_seclabel->relabel)
|
if (!parent_seclabel->relabel)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ret = virSecuritySELinuxSetFilecon(mgr, src->path,
|
use_label = parent_seclabel->label;
|
||||||
parent_seclabel->label, remember);
|
|
||||||
} else if (!parent || parent == src) {
|
} else if (!parent || parent == src) {
|
||||||
if (src->shared) {
|
if (src->shared) {
|
||||||
ret = virSecuritySELinuxSetFilecon(mgr,
|
use_label = data->file_context;
|
||||||
src->path,
|
|
||||||
data->file_context,
|
|
||||||
remember);
|
|
||||||
} else if (src->readonly) {
|
} else if (src->readonly) {
|
||||||
ret = virSecuritySELinuxSetFilecon(mgr,
|
use_label = data->content_context;
|
||||||
src->path,
|
|
||||||
data->content_context,
|
|
||||||
remember);
|
|
||||||
} else if (secdef->imagelabel) {
|
} else if (secdef->imagelabel) {
|
||||||
ret = virSecuritySELinuxSetFilecon(mgr,
|
use_label = secdef->imagelabel;
|
||||||
src->path,
|
|
||||||
secdef->imagelabel,
|
|
||||||
remember);
|
|
||||||
} else {
|
} else {
|
||||||
ret = 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ret = virSecuritySELinuxSetFilecon(mgr,
|
use_label = data->content_context;
|
||||||
src->path,
|
|
||||||
data->content_context,
|
|
||||||
remember);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = virSecuritySELinuxSetFilecon(mgr, src->path, use_label, remember);
|
||||||
|
|
||||||
if (ret == 1 && !disk_seclabel) {
|
if (ret == 1 && !disk_seclabel) {
|
||||||
/* If we failed to set a label, but virt_use_nfs let us
|
/* If we failed to set a label, but virt_use_nfs let us
|
||||||
* proceed anyway, then we don't need to relabel later. */
|
* proceed anyway, then we don't need to relabel later. */
|
||||||
|
Loading…
Reference in New Issue
Block a user