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