Blame 0213-ccpp-add-AllowedUsers-and-AllowedGroups-feature.patch

69165ba
From 29e8577ae1d7252513883941cae1c576f30c2d75 Mon Sep 17 00:00:00 2001
69165ba
From: Matej Habrnal <mhabrnal@redhat.com>
69165ba
Date: Tue, 22 Mar 2016 12:35:55 +0100
69165ba
Subject: [PATCH] ccpp: add AllowedUsers and AllowedGroups feature
69165ba
69165ba
The feature allows dump core only for allowed users.
69165ba
69165ba
The logic is the following:
69165ba
 - if both options are not-defined or empty keep all core dumps
69165ba
 - else if crashed UID is in the list of users keep the core dump
69165ba
 - else if crashed UID belongs to a group in the list of groups keep the core dump
69165ba
69165ba
Related to rhbz#1277849
69165ba
69165ba
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
69165ba
---
69165ba
 doc/abrt-CCpp.conf.txt     | 10 ++++++++
69165ba
 src/hooks/CCpp.conf        |  7 ++++++
69165ba
 src/hooks/abrt-hook-ccpp.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++
69165ba
 3 files changed, 80 insertions(+)
69165ba
69165ba
diff --git a/doc/abrt-CCpp.conf.txt b/doc/abrt-CCpp.conf.txt
69165ba
index 4db4b54..dffa45d 100644
69165ba
--- a/doc/abrt-CCpp.conf.txt
69165ba
+++ b/doc/abrt-CCpp.conf.txt
69165ba
@@ -43,6 +43,16 @@ IgnoredPaths = /path/to/ignore/*, */another/ignored/path* ...::
69165ba
    ABRT will ignore crashes in executables whose absolute path matches one of
69165ba
    specified patterns.
69165ba
 
69165ba
+AllowedUsers = root, ...::
69165ba
+   ABRT will process only crashes of either allowed users 'AllowedUsers' or
69165ba
+   users who are members of allowed group 'AllowedGroups'. If no allowed users
69165ba
+   nor allowed group are specified ABRT will process crashes of all users.
69165ba
+
69165ba
+AllowedGroups = root, ...::
69165ba
+   ABRT will process only crashes of either allowed users 'AllowedUsers' or
69165ba
+   users who are members of allowed group 'AllowedGroups'. If no allowed users
69165ba
+   nor allowed group are specified ABRT will process crashes of all users.
69165ba
+
69165ba
 VerboseLog = NUM::
69165ba
    Used to make the hook more verbose
69165ba
 
69165ba
diff --git a/src/hooks/CCpp.conf b/src/hooks/CCpp.conf
69165ba
index be55e05..af31ed5 100644
69165ba
--- a/src/hooks/CCpp.conf
69165ba
+++ b/src/hooks/CCpp.conf
69165ba
@@ -37,3 +37,10 @@ SaveFullCore = yes
69165ba
 # specified patterns.
69165ba
 #
69165ba
 #IgnoredPaths =
69165ba
+
69165ba
+# ABRT will process only crashes of either allowed users or users who are
69165ba
+# members of allowed group. If no allowed users nor allowed group are specified
69165ba
+# ABRT will process crashes of all users.
69165ba
+#
69165ba
+#AllowedUsers =
69165ba
+#AllowedGroups =
69165ba
diff --git a/src/hooks/abrt-hook-ccpp.c b/src/hooks/abrt-hook-ccpp.c
69165ba
index 18cd608..c9fbf68 100644
69165ba
--- a/src/hooks/abrt-hook-ccpp.c
69165ba
+++ b/src/hooks/abrt-hook-ccpp.c
69165ba
@@ -645,6 +645,44 @@ static bool is_path_ignored(const GList *list, const char *path)
69165ba
     return false;
69165ba
 }
69165ba
 
69165ba
+static bool is_user_allowed(uid_t uid, const GList *list)
69165ba
+{
69165ba
+    const GList *li;
69165ba
+    for (li = list; li != NULL; li = g_list_next(li))
69165ba
+    {
69165ba
+        const char *username = (const char*)li->data;
69165ba
+        struct passwd *pw = getpwnam(username);
69165ba
+        if (pw == NULL)
69165ba
+        {
69165ba
+            log_warning("can't get uid of user '%s' (listed in 'AllowedUsers')", username);
69165ba
+            continue;
69165ba
+        }
69165ba
+
69165ba
+        if(pw->pw_uid == uid)
69165ba
+            return true;
69165ba
+    }
69165ba
+    return false;
69165ba
+}
69165ba
+
69165ba
+static bool is_user_in_allowed_group(uid_t uid, const GList *list)
69165ba
+{
69165ba
+    const GList *li;
69165ba
+    for (li = list; li != NULL; li = g_list_next(li))
69165ba
+    {
69165ba
+        const char *groupname = (const char*)li->data;
69165ba
+        struct group *gr = getgrnam(groupname);
69165ba
+        if (gr == NULL)
69165ba
+        {
69165ba
+            log_warning("can't get gid of group '%s' (listed in 'AllowedGroups')", groupname);
69165ba
+            continue;
69165ba
+        }
69165ba
+
69165ba
+        if(uid_in_group(uid, gr->gr_gid))
69165ba
+            return true;
69165ba
+    }
69165ba
+    return false;
69165ba
+}
69165ba
+
69165ba
 static int test_configuration(bool setting_SaveFullCore, bool setting_CreateCoreBacktrace)
69165ba
 {
69165ba
     if (!setting_SaveFullCore && !setting_CreateCoreBacktrace)
69165ba
@@ -701,6 +739,8 @@ int main(int argc, char** argv)
69165ba
     bool setting_SaveFullCore;
69165ba
     bool setting_CreateCoreBacktrace;
69165ba
     GList *setting_ignored_paths = NULL;
69165ba
+    GList *setting_allowed_users = NULL;
69165ba
+    GList *setting_allowed_groups = NULL;
69165ba
     {
69165ba
         map_string_t *settings = new_map_string();
69165ba
         load_abrt_plugin_conf_file("CCpp.conf", settings);
69165ba
@@ -716,6 +756,13 @@ int main(int argc, char** argv)
69165ba
         if (value)
69165ba
             setting_ignored_paths = parse_list(value);
69165ba
 
69165ba
+        value = get_map_string_item_or_NULL(settings, "AllowedUsers");
69165ba
+        if (value)
69165ba
+            setting_allowed_users = parse_list(value);
69165ba
+        value = get_map_string_item_or_NULL(settings, "AllowedGroups");
69165ba
+        if (value)
69165ba
+            setting_allowed_groups = parse_list(value);
69165ba
+
69165ba
         setting_CreateCoreBacktrace = value ? string_to_bool(value) : true;
69165ba
         value = get_map_string_item_or_NULL(settings, "VerboseLog");
69165ba
         if (value)
69165ba
@@ -803,6 +850,22 @@ int main(int argc, char** argv)
69165ba
         return 0;
69165ba
     }
69165ba
 
69165ba
+    /* dumping core for user, if allowed */
69165ba
+    if (setting_allowed_users || setting_allowed_groups)
69165ba
+    {
69165ba
+        if (setting_allowed_users && is_user_allowed(uid, setting_allowed_users))
69165ba
+            log_debug("User %lu is listed in 'AllowedUsers'", (long unsigned)uid);
69165ba
+        else if (setting_allowed_groups && is_user_in_allowed_group(uid, setting_allowed_groups))
69165ba
+            log_debug("User %lu is member of group listed in 'AllowedGroups'", (long unsigned)uid);
69165ba
+        else
69165ba
+        {
69165ba
+            error_msg_not_process_crash(pid_str, last_slash + 1, (long unsigned)uid, signal_no,
69165ba
+                signame, "ignoring (not allowed in 'AllowedUsers' nor 'AllowedGroups')");
69165ba
+
69165ba
+            xfunc_die();
69165ba
+        }
69165ba
+    }
69165ba
+
69165ba
     user_pwd = get_cwd(pid);
69165ba
     log_notice("user_pwd:'%s'", user_pwd);
69165ba
 
69165ba
-- 
69165ba
1.8.3.1
69165ba