Blame SOURCES/0264-cli-introduce-unsafe-reporting-for-not-reporable-pro.patch

a60cd7
From b14396f9f86b6694471a9418024ffb39cf7abd47 Mon Sep 17 00:00:00 2001
a60cd7
From: Matej Habrnal <mhabrnal@redhat.com>
a60cd7
Date: Wed, 3 Aug 2016 12:43:51 +0200
a60cd7
Subject: [PATCH] cli: introduce unsafe reporting for not-reporable problems
a60cd7
a60cd7
Parameter unsafe ignores security checks and allows to report
a60cd7
not-reportable problems.
a60cd7
a60cd7
What makes the problem not reportable:
a60cd7
a60cd7
- A kernel problem occurred, but your kernel has been tainted
a60cd7
(flags:%s).
a60cd7
a60cd7
- A kernel problem occurred because of broken BIOS. Unfortunately, such
a60cd7
  problems are not fixable by kernel maintainers."
a60cd7
a60cd7
- The problem data are incomplete.
a60cd7
a60cd7
- Crashed application has locked memory regions
a60cd7
a60cd7
We have decided to call the new command line argument "unsafe" because
a60cd7
- either the reporter can leak some private data
a60cd7
- or the reporter could be facing anger from maintainers when they get
a60cd7
to the report
a60cd7
a60cd7
Related to #1257159
a60cd7
Related to abrt/abrt#1166
a60cd7
a60cd7
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
a60cd7
---
a60cd7
 doc/abrt-cli.txt      |  7 +++++--
a60cd7
 src/cli/builtin-cmd.h |  8 +++++++-
a60cd7
 src/cli/process.c     | 34 ++++++++++++++++++++++++----------
a60cd7
 src/cli/report.c      | 27 ++++++++++++++++++++-------
a60cd7
 4 files changed, 56 insertions(+), 20 deletions(-)
a60cd7
a60cd7
diff --git a/doc/abrt-cli.txt b/doc/abrt-cli.txt
a60cd7
index 0f18784..87a74ad 100644
a60cd7
--- a/doc/abrt-cli.txt
a60cd7
+++ b/doc/abrt-cli.txt
a60cd7
@@ -13,13 +13,13 @@ SYNOPSIS
a60cd7
 
a60cd7
 'abrt-cli' remove  [-v]  DIR...
a60cd7
 
a60cd7
-'abrt-cli' report  [-v]  [--delete]  DIR...
a60cd7
+'abrt-cli' report  [-v]  [--delete] [--unsafe] DIR...
a60cd7
 
a60cd7
 'abrt-cli' info    [-v]  [--detailed] [-s SIZE] DIR...
a60cd7
 
a60cd7
 'abrt-cli' status  [-vb] [--since NUM]
a60cd7
 
a60cd7
-'abrt-cli' process [-v]  [--since NUM] DIR...
a60cd7
+'abrt-cli' process [-v]  [--since NUM] [--unsafe] DIR...
a60cd7
 
a60cd7
 GLOBAL OPTIONS
a60cd7
 --------------
a60cd7
@@ -49,6 +49,9 @@ COMMAND OPTIONS
a60cd7
 --since NUM::
a60cd7
     Selects only problems detected after timestamp
a60cd7
 
a60cd7
+-u, --unsafe::
a60cd7
+   Ignore security checks to be able to report all problems
a60cd7
+
a60cd7
 --until NUM::
a60cd7
     Selects only the problems older than specified timestamp
a60cd7
 
a60cd7
diff --git a/src/cli/builtin-cmd.h b/src/cli/builtin-cmd.h
a60cd7
index c6cd691..9773f13 100644
a60cd7
--- a/src/cli/builtin-cmd.h
a60cd7
+++ b/src/cli/builtin-cmd.h
a60cd7
@@ -24,7 +24,13 @@ extern int cmd_list(int argc, const char **argv);
a60cd7
 extern int cmd_remove(int argc, const char **argv);
a60cd7
 extern int _cmd_remove(const char **dirs_strv);
a60cd7
 extern int cmd_report(int argc, const char **argv);
a60cd7
-extern int _cmd_report(const char **dirs_strv, int remove);
a60cd7
+enum {
a60cd7
+    /* Remove successfully reported */
a60cd7
+    CMD_REPORT_REMOVE = 1 << 0,
a60cd7
+    /* Ignore security checks - i.e not-repotable */
a60cd7
+    CMD_REPORT_UNSAFE = 1 << 1,
a60cd7
+};
a60cd7
+extern int _cmd_report(const char **dirs_strv, int flags);
a60cd7
 extern int cmd_info(int argc, const char **argv);
a60cd7
 extern int _cmd_info(problem_data_t *problem_data, int detailed, int text_size);
a60cd7
 extern int cmd_status(int argc, const char **argv);
a60cd7
diff --git a/src/cli/process.c b/src/cli/process.c
a60cd7
index 401ef60..9ccc271 100644
a60cd7
--- a/src/cli/process.c
a60cd7
+++ b/src/cli/process.c
a60cd7
@@ -32,7 +32,7 @@ enum {
a60cd7
     ACT_SKIP
a60cd7
 };
a60cd7
 
a60cd7
-static int process_one_crash(problem_data_t *problem_data)
a60cd7
+static int process_one_crash(problem_data_t *problem_data, int report_flags)
a60cd7
 {
a60cd7
     if (problem_data == NULL)
a60cd7
         return ACT_ERR;
a60cd7
@@ -60,10 +60,10 @@ static int process_one_crash(problem_data_t *problem_data)
a60cd7
         const char *not_reportable = problem_data_get_content_or_NULL(problem_data, FILENAME_NOT_REPORTABLE);
a60cd7
 
a60cd7
         /* if the problem is not-reportable then ask does not contain option report(e) */
a60cd7
-        if (not_reportable != NULL)
a60cd7
-            action = ask(_("Actions: remove(rm), info(i), skip(s):"));
a60cd7
-        else
a60cd7
+        if ((report_flags & CMD_REPORT_UNSAFE) || not_reportable == NULL)
a60cd7
             action = ask(_("Actions: remove(rm), report(e), info(i), skip(s):"));
a60cd7
+        else
a60cd7
+            action = ask(_("Actions: remove(rm), info(i), skip(s):"));
a60cd7
 
a60cd7
         if(strcmp(action, "rm") == 0 || strcmp(action, "remove") == 0 )
a60cd7
         {
a60cd7
@@ -73,11 +73,12 @@ static int process_one_crash(problem_data_t *problem_data)
a60cd7
 
a60cd7
             ret_val = ACT_REMOVE;
a60cd7
         }
a60cd7
-        else if (not_reportable == NULL && (strcmp(action, "e") == 0 || strcmp(action, "report") == 0))
a60cd7
+        else if (((report_flags & CMD_REPORT_UNSAFE) || not_reportable == NULL)
a60cd7
+             && (strcmp(action, "e") == 0 || strcmp(action, "report") == 0))
a60cd7
         {
a60cd7
             log(_("Reporting '%s'"), dir_name);
a60cd7
             const char *dirs_strv[] = {dir_name, NULL};
a60cd7
-            _cmd_report(dirs_strv, /*do not delete*/0);
a60cd7
+            _cmd_report(dirs_strv, report_flags);
a60cd7
 
a60cd7
             ret_val = ACT_REPORT;
a60cd7
         }
a60cd7
@@ -98,7 +99,7 @@ static int process_one_crash(problem_data_t *problem_data)
a60cd7
     return ret_val;
a60cd7
 }
a60cd7
 
a60cd7
-static void process_crashes(vector_of_problem_data_t *crash_list, long since)
a60cd7
+static void process_crashes(vector_of_problem_data_t *crash_list, long since, int report_flags)
a60cd7
 {
a60cd7
 
a60cd7
     for (unsigned i = 0; i < crash_list->len; ++i)
a60cd7
@@ -117,7 +118,7 @@ static void process_crashes(vector_of_problem_data_t *crash_list, long since)
a60cd7
         if(i != 0)
a60cd7
             printf("\n");
a60cd7
 
a60cd7
-        int action = process_one_crash(crash);
a60cd7
+        int action = process_one_crash(crash, report_flags);
a60cd7
 
a60cd7
         if (i != crash_list->len - 1)
a60cd7
         {
a60cd7
@@ -135,23 +136,36 @@ static void process_crashes(vector_of_problem_data_t *crash_list, long since)
a60cd7
 int cmd_process(int argc, const char **argv)
a60cd7
 {
a60cd7
     const char *program_usage_string = _(
a60cd7
+        "& process [options]\n"
a60cd7
+        "\n"
a60cd7
         "Without --since argument, iterates over all detected problems."
a60cd7
     );
a60cd7
 
a60cd7
+    enum {
a60cd7
+        OPT_v = 1 << 0,
a60cd7
+        OPT_s = 1 << 1,
a60cd7
+        OPT_u = 1 << 2,
a60cd7
+    };
a60cd7
+
a60cd7
     int opt_since = 0;
a60cd7
     struct options program_options[] = {
a60cd7
         OPT__VERBOSE(&g_verbose),
a60cd7
         OPT_INTEGER('s', "since" , &opt_since,  _("Selects only problems detected after timestamp")),
a60cd7
+        OPT_BOOL(   'u', "unsafe", NULL,        _("Ignore security checks to be able to "
a60cd7
+                                                  "report all problems")),
a60cd7
         OPT_END()
a60cd7
     };
a60cd7
 
a60cd7
-    parse_opts(argc, (char **)argv, program_options, program_usage_string);
a60cd7
+    unsigned opts = parse_opts(argc, (char **)argv, program_options, program_usage_string);
a60cd7
 
a60cd7
     vector_of_problem_data_t *ci = fetch_crash_infos();
a60cd7
 
a60cd7
     g_ptr_array_sort_with_data(ci, &cmp_problem_data, (char *) FILENAME_LAST_OCCURRENCE);
a60cd7
 
a60cd7
-    process_crashes(ci, opt_since);
a60cd7
+    int report_flags = 0;
a60cd7
+    if (opts & OPT_u)
a60cd7
+        report_flags |= CMD_REPORT_UNSAFE;
a60cd7
+    process_crashes(ci, opt_since, report_flags);
a60cd7
 
a60cd7
     free_vector_of_problem_data(ci);
a60cd7
 
a60cd7
diff --git a/src/cli/report.c b/src/cli/report.c
a60cd7
index cc4035e..1e9067b 100644
a60cd7
--- a/src/cli/report.c
a60cd7
+++ b/src/cli/report.c
a60cd7
@@ -22,7 +22,7 @@
a60cd7
 #include "abrt-cli-core.h"
a60cd7
 #include "builtin-cmd.h"
a60cd7
 
a60cd7
-int _cmd_report(const char **dirs_strv, int remove)
a60cd7
+int _cmd_report(const char **dirs_strv, int flags)
a60cd7
 {
a60cd7
     int ret = 0;
a60cd7
     while (*dirs_strv)
a60cd7
@@ -39,10 +39,14 @@ int _cmd_report(const char **dirs_strv, int remove)
a60cd7
         const int not_reportable = test_exist_over_dbus(real_problem_id, FILENAME_NOT_REPORTABLE);
a60cd7
         if (not_reportable != 0)
a60cd7
         {
a60cd7
-            error_msg(_("Problem '%s' cannot be reported"), real_problem_id);
a60cd7
-            free(real_problem_id);
a60cd7
-            ++ret;
a60cd7
-            continue;
a60cd7
+            if (!(flags & CMD_REPORT_UNSAFE))
a60cd7
+            {
a60cd7
+                error_msg(_("Problem '%s' cannot be reported"), real_problem_id);
a60cd7
+                free(real_problem_id);
a60cd7
+                ++ret;
a60cd7
+                continue;
a60cd7
+            }
a60cd7
+            log_info(_("Problem '%s' is labeled as 'not-reportable'?"), real_problem_id);
a60cd7
         }
a60cd7
 
a60cd7
         const int res = chown_dir_over_dbus(real_problem_id);
a60cd7
@@ -58,7 +62,7 @@ int _cmd_report(const char **dirs_strv, int remove)
a60cd7
                                            | LIBREPORT_RUN_CLI);
a60cd7
 
a60cd7
         /* the problem was successfully reported and option is -d */
a60cd7
-        if(remove && (status == 0 || status == EXIT_STOP_EVENT_RUN))
a60cd7
+        if((flags & CMD_REPORT_REMOVE) && (status == 0 || status == EXIT_STOP_EVENT_RUN))
a60cd7
         {
a60cd7
             log(_("Deleting '%s'"), real_problem_id);
a60cd7
             delete_dump_dir_possibly_using_abrtd(real_problem_id);
a60cd7
@@ -82,11 +86,14 @@ int cmd_report(int argc, const char **argv)
a60cd7
     enum {
a60cd7
         OPT_v = 1 << 0,
a60cd7
         OPT_d = 1 << 1,
a60cd7
+        OPT_u = 1 << 2,
a60cd7
     };
a60cd7
 
a60cd7
     struct options program_options[] = {
a60cd7
         OPT__VERBOSE(&g_verbose),
a60cd7
         OPT_BOOL('d', "delete", NULL, _("Remove PROBLEM_DIR after reporting")),
a60cd7
+        OPT_BOOL('u', "unsafe", NULL, _("Ignore security checks to be able to "
a60cd7
+                                        "report all problems")),
a60cd7
         OPT_END()
a60cd7
     };
a60cd7
 
a60cd7
@@ -101,5 +108,11 @@ int cmd_report(int argc, const char **argv)
a60cd7
     load_abrt_conf();
a60cd7
     free_abrt_conf_data();
a60cd7
 
a60cd7
-    return _cmd_report(argv, opts & OPT_d);
a60cd7
+    int report_flags = 0;
a60cd7
+    if (opts & OPT_d)
a60cd7
+        report_flags |= CMD_REPORT_REMOVE;
a60cd7
+    if (opts & OPT_u)
a60cd7
+        report_flags |= CMD_REPORT_UNSAFE;
a60cd7
+
a60cd7
+    return _cmd_report(argv, report_flags);
a60cd7
 }
a60cd7
-- 
a60cd7
1.8.3.1
a60cd7