apparmor: refactor AppArmorSetSecurityImageLabel

A lot of the code in AppArmorSetSecurityImageLabel is a duplicate of
what is in reload_profile, this refactors AppArmorSetSecurityImageLabel
to use reload_profile instead.
Reviewed-by: NCole Robinson <crobinso@redhat.com>
Acked-by: NJamie Strandboge <jamie@canonical.com>
Signed-off-by: NChristian Ehrhardt <christian.ehrhardt@canonical.com>
上级 70cf0af7
...@@ -778,8 +778,6 @@ AppArmorSetSecurityImageLabel(virSecurityManagerPtr mgr, ...@@ -778,8 +778,6 @@ AppArmorSetSecurityImageLabel(virSecurityManagerPtr mgr,
virStorageSourcePtr src, virStorageSourcePtr src,
virSecurityDomainImageLabelFlags flags G_GNUC_UNUSED) virSecurityDomainImageLabelFlags flags G_GNUC_UNUSED)
{ {
int rc = -1;
char *profile_name = NULL;
virSecurityLabelDefPtr secdef; virSecurityLabelDefPtr secdef;
if (!src->path || !virStorageSourceIsLocalStorage(src)) if (!src->path || !virStorageSourceIsLocalStorage(src))
...@@ -789,36 +787,18 @@ AppArmorSetSecurityImageLabel(virSecurityManagerPtr mgr, ...@@ -789,36 +787,18 @@ AppArmorSetSecurityImageLabel(virSecurityManagerPtr mgr,
if (!secdef || !secdef->relabel) if (!secdef || !secdef->relabel)
return 0; return 0;
if (secdef->imagelabel) { if (!secdef->imagelabel)
/* if the device doesn't exist, error out */ return 0;
if (!virFileExists(src->path)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("\'%s\' does not exist"),
src->path);
return -1;
}
if ((profile_name = get_profile_name(def)) == NULL)
return -1;
/* update the profile only if it is loaded */ /* if the device doesn't exist, error out */
if (profile_loaded(secdef->imagelabel) >= 0) { if (!virFileExists(src->path)) {
if (load_profile(mgr, secdef->imagelabel, def, virReportError(VIR_ERR_INTERNAL_ERROR,
src->path, false) < 0) { _("\'%s\' does not exist"),
virReportError(VIR_ERR_INTERNAL_ERROR, src->path);
_("cannot update AppArmor profile " return -1;
"\'%s\'"),
secdef->imagelabel);
goto cleanup;
}
}
} }
rc = 0;
cleanup: return reload_profile(mgr, def, src->path, false);
VIR_FREE(profile_name);
return rc;
} }
static int static int
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册