[CRIU] [PATCH 3/4] lsm: Make get_type() switch-able call
Pavel Emelyanov
xemul at virtuozzo.com
Mon Jun 26 16:20:20 MSK 2017
This is to remove the function pointer and have only "type"
variable left.
Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
criu/lsm.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/criu/lsm.c b/criu/lsm.c
index aef4397..266d98b 100644
--- a/criu/lsm.c
+++ b/criu/lsm.c
@@ -20,7 +20,6 @@
#endif
static Lsmtype lsmtype;
-static int (*get_label)(pid_t, char **) = NULL;
static int apparmor_get_label(pid_t pid, char **profile_name)
{
@@ -109,7 +108,6 @@ static int selinux_get_label(pid_t pid, char **output)
void kerndat_lsm(void)
{
if (access(AA_SECURITYFS_PATH, F_OK) == 0) {
- get_label = apparmor_get_label;
lsmtype = LSMTYPE__APPARMOR;
return;
}
@@ -121,13 +119,11 @@ void kerndat_lsm(void)
* well.
*/
if (access("/sys/fs/selinux", F_OK) == 0) {
- get_label = selinux_get_label;
lsmtype = LSMTYPE__SELINUX;
return;
}
#endif
- get_label = NULL;
lsmtype = LSMTYPE__NO_LSM;
}
@@ -138,18 +134,32 @@ Lsmtype host_lsm_type(void)
int collect_lsm_profile(pid_t pid, CredsEntry *ce)
{
- ce->lsm_profile = NULL;
+ int ret;
- if (lsmtype == LSMTYPE__NO_LSM)
- return 0;
+ ce->lsm_profile = NULL;
- if (get_label(pid, &ce->lsm_profile) < 0)
- return -1;
+ switch (lsmtype) {
+ case LSMTYPE__NO_LSM:
+ ret = 0;
+ break;
+ case LSMTYPE__APPARMOR:
+ ret = apparmor_get_label(pid, &ce->lsm_profile);
+ break;
+#ifdef CONFIG_HAS_SELINUX
+ case LSMTYPE__SELINUX:
+ ret = selinux_get_label(pid, &ce->lsm_profile);
+ break;
+#endif
+ default:
+ BUG();
+ ret = -1;
+ break;
+ }
if (ce->lsm_profile)
pr_info("%d has lsm profile %s\n", pid, ce->lsm_profile);
- return 0;
+ return ret;
}
// in inventory.c
--
2.1.4
More information about the CRIU
mailing list