diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:01:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:01:24 +0000 |
commit | 1e2ccef73c5ca96f7884a452b65cdbbff51c43ca (patch) | |
tree | 15afec6ee566d7919e0e640816faeebc777e3911 /src/selinux.cpp | |
parent | Initial commit. (diff) | |
download | gnome-system-monitor-1e2ccef73c5ca96f7884a452b65cdbbff51c43ca.tar.xz gnome-system-monitor-1e2ccef73c5ca96f7884a452b65cdbbff51c43ca.zip |
Adding upstream version 3.38.0.upstream/3.38.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/selinux.cpp')
-rw-r--r-- | src/selinux.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/selinux.cpp b/src/selinux.cpp new file mode 100644 index 0000000..a9596d5 --- /dev/null +++ b/src/selinux.cpp @@ -0,0 +1,66 @@ +/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +#include <config.h> + +#include <glib.h> + +#include "selinux.h" +#include "application.h" +#include "util.h" + + +static int (*getpidcon)(pid_t, char**); +static void (*freecon)(char*); +static int (*is_selinux_enabled)(void); + +static gboolean has_selinux; + +static gboolean load_selinux(void) +{ + return load_symbols("libselinux.so.1", + "getpidcon", &getpidcon, + "freecon", &freecon, + "is_selinux_enabled", &is_selinux_enabled, + NULL); +} + + + +void +get_process_selinux_context (ProcInfo *info) +{ + char *con; + + if (has_selinux && !getpidcon (info->pid, &con)) { + info->security_context = g_strdup (con); + freecon (con); + } +} + + + +gboolean +can_show_security_context_column (void) +{ + if (!(has_selinux = load_selinux())) + return FALSE; + + switch (is_selinux_enabled()) { + case 1: + /* We're running on an SELinux kernel */ + return TRUE; + + case -1: + /* Error; hide the security context column */ + + case 0: + /* We're not running on an SELinux kernel: + hide the security context column */ + + default: + procman_debug("SELinux was found but is not enabled.\n"); + return FALSE; + } +} + + + |