Commit 171acca8 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Andrei Vagin

lsm: Make get_type() switch-able call

This is to remove the function pointer and have only "type"
variable left.
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 09c131c8
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#endif #endif
static Lsmtype lsmtype; static Lsmtype lsmtype;
static int (*get_label)(pid_t, char **) = NULL;
static int apparmor_get_label(pid_t pid, char **profile_name) 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) ...@@ -109,7 +108,6 @@ static int selinux_get_label(pid_t pid, char **output)
void kerndat_lsm(void) void kerndat_lsm(void)
{ {
if (access(AA_SECURITYFS_PATH, F_OK) == 0) { if (access(AA_SECURITYFS_PATH, F_OK) == 0) {
get_label = apparmor_get_label;
lsmtype = LSMTYPE__APPARMOR; lsmtype = LSMTYPE__APPARMOR;
return; return;
} }
...@@ -121,13 +119,11 @@ void kerndat_lsm(void) ...@@ -121,13 +119,11 @@ void kerndat_lsm(void)
* well. * well.
*/ */
if (access("/sys/fs/selinux", F_OK) == 0) { if (access("/sys/fs/selinux", F_OK) == 0) {
get_label = selinux_get_label;
lsmtype = LSMTYPE__SELINUX; lsmtype = LSMTYPE__SELINUX;
return; return;
} }
#endif #endif
get_label = NULL;
lsmtype = LSMTYPE__NO_LSM; lsmtype = LSMTYPE__NO_LSM;
} }
...@@ -138,18 +134,32 @@ Lsmtype host_lsm_type(void) ...@@ -138,18 +134,32 @@ Lsmtype host_lsm_type(void)
int collect_lsm_profile(pid_t pid, CredsEntry *ce) int collect_lsm_profile(pid_t pid, CredsEntry *ce)
{ {
ce->lsm_profile = NULL; int ret;
if (lsmtype == LSMTYPE__NO_LSM) ce->lsm_profile = NULL;
return 0;
if (get_label(pid, &ce->lsm_profile) < 0) switch (lsmtype) {
return -1; 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) if (ce->lsm_profile)
pr_info("%d has lsm profile %s\n", pid, ce->lsm_profile); pr_info("%d has lsm profile %s\n", pid, ce->lsm_profile);
return 0; return ret;
} }
// in inventory.c // in inventory.c
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment