mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
security_util: Introduce virSecurityMoveRememberedLabel
A simple helper function that would be used from DAC and SELinux drivers. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Cole Robinson <crobinso@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
8b74cecbdf
commit
d73f3f5836
@ -256,3 +256,66 @@ virSecuritySetRememberedLabel(const char *name,
|
||||
VIR_FREE(ref_name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virSecurityMoveRememberedLabel(const char *name,
|
||||
const char *src,
|
||||
const char *dst)
|
||||
{
|
||||
VIR_AUTOFREE(char *) ref_name = NULL;
|
||||
VIR_AUTOFREE(char *) ref_value = NULL;
|
||||
VIR_AUTOFREE(char *) attr_name = NULL;
|
||||
VIR_AUTOFREE(char *) attr_value = NULL;
|
||||
|
||||
if (!(ref_name = virSecurityGetRefCountAttrName(name)) |
|
||||
!(attr_name = virSecurityGetAttrName(name)))
|
||||
return -1;
|
||||
|
||||
if (virFileGetXAttrQuiet(src, ref_name, &ref_value) < 0) {
|
||||
if (errno == ENOSYS || errno == ENOTSUP) {
|
||||
return -2;
|
||||
} else if (errno != ENODATA) {
|
||||
virReportSystemError(errno,
|
||||
_("Unable to get XATTR %s on %s"),
|
||||
ref_name, src);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (virFileGetXAttrQuiet(src, attr_name, &attr_value) < 0) {
|
||||
if (errno == ENOSYS || errno == ENOTSUP) {
|
||||
return -2;
|
||||
} else if (errno != ENODATA) {
|
||||
virReportSystemError(errno,
|
||||
_("Unable to get XATTR %s on %s"),
|
||||
attr_name, src);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (ref_value &&
|
||||
virFileRemoveXAttr(src, ref_name) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (attr_value &&
|
||||
virFileRemoveXAttr(src, attr_name) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dst) {
|
||||
if (ref_value &&
|
||||
virFileSetXAttr(dst, ref_name, ref_value) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (attr_value &&
|
||||
virFileSetXAttr(dst, attr_name, attr_value) < 0) {
|
||||
ignore_value(virFileRemoveXAttr(dst, ref_name));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -27,3 +27,8 @@ int
|
||||
virSecuritySetRememberedLabel(const char *name,
|
||||
const char *path,
|
||||
const char *label);
|
||||
|
||||
int
|
||||
virSecurityMoveRememberedLabel(const char *name,
|
||||
const char *src,
|
||||
const char *dst);
|
||||
|
Loading…
Reference in New Issue
Block a user