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

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