Blame SOURCES/0190-bugzilla-don-t-report-private-problem-as-comment.patch

562801
From 6e11121e7ec10cd63e6bbaa8e996b883e9fe1ac2 Mon Sep 17 00:00:00 2001
562801
From: Matej Habrnal <mhabrnal@redhat.com>
562801
Date: Wed, 23 Mar 2016 17:11:56 +0100
562801
Subject: [PATCH] bugzilla: don't report private problem as comment
562801
562801
Before this patch reporter-bugzilla ignored the Private report request
562801
and added a public comment to a duplicate bug because it was assumed
562801
that the duplicate comment cannot contain anything security sensitive.
562801
562801
There are two problems with it. The assumption is invalid because the
562801
comment contains all one-line files including 'cmdline' and the reporter
562801
might added something private to the bug description.
562801
562801
Bugzilla comments can be made private but not all users have rights to
562801
do so. On the contrary, all users can set a group to a bug report.
562801
Hence, this commit teaches reporter-bugzilla to ask the user if he/she
562801
wants to open a new, private bug report and immediately close it as a
562801
duplicate of the original or terminate the reporting. The tool will ask
562801
the question only if the users wants to open a private report and a
562801
duplicate bug report is found.
562801
562801
Resolves: #1279453
562801
562801
Signed-off-by: Jakub Filak <jfilak@redhat.com>
562801
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
562801
---
562801
 src/plugins/reporter-bugzilla.c | 44 +++++++++++++++++++++++++++++++++++++++--
562801
 src/plugins/rhbz.c              | 23 +++++++++++++++++++++
562801
 src/plugins/rhbz.h              |  4 ++++
562801
 3 files changed, 69 insertions(+), 2 deletions(-)
562801
562801
diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c
562801
index 941c91f..fbe7873 100644
562801
--- a/src/plugins/reporter-bugzilla.c
562801
+++ b/src/plugins/reporter-bugzilla.c
562801
@@ -907,6 +907,7 @@ int main(int argc, char **argv)
562801
     unsigned opts = parse_opts(argc, argv, program_options, program_usage_string);
562801
     argv += optind;
562801
 
562801
+    load_global_configuration();
562801
     export_abrt_envvars(0);
562801
 
562801
     map_string_t *settings = new_map_string();
562801
@@ -928,6 +929,8 @@ int main(int argc, char **argv)
562801
          */
562801
         /*free_map_string(settings);*/
562801
     }
562801
+    /* either we got Bugzilla_CreatePrivate from settings or -g was specified on cmdline */
562801
+    rhbz.b_create_private |= (opts & OPT_g);
562801
 
562801
     log_notice("Initializing XML-RPC library");
562801
     xmlrpc_env env;
562801
@@ -1189,8 +1192,38 @@ int main(int argc, char **argv)
562801
             }
562801
         }
562801
 
562801
-        if (existing_id < 0)
562801
+        if (existing_id < 0 || rhbz.b_create_private)
562801
         {
562801
+
562801
+            if (existing_id >= 0)
562801
+            {
562801
+                char *msg = xasprintf(_(
562801
+                "You have requested to make your data accessible only to a "
562801
+                "specific group and this bug is a duplicate of bug: "
562801
+                "%s/%u"
562801
+                " "
562801
+                "In case of bug duplicates a new comment is added to the "
562801
+                "original bug report but access to the comments cannot be "
562801
+                "restricted to a specific group."
562801
+                " "
562801
+                "Would you like to open a new bug report and close it as "
562801
+                "DUPLICATE of the original one?"
562801
+                " "
562801
+                "Otherwise, the bug reporting procedure will be terminated."),
562801
+                rhbz.b_bugzilla_url, existing_id);
562801
+
562801
+                int r = ask_yes_no(msg);
562801
+                free(msg);
562801
+
562801
+                if (r == 0)
562801
+                {
562801
+                    log(_("Logging out"));
562801
+                    rhbz_logout(client);
562801
+
562801
+                    exit(EXIT_CANCEL_BY_USER);
562801
+                }
562801
+            }
562801
+
562801
             /* Create new bug */
562801
             log(_("Creating a new bug"));
562801
 
562801
@@ -1205,7 +1238,7 @@ int main(int argc, char **argv)
562801
             int new_id = rhbz_new_bug(client,
562801
                     problem_data, rhbz.b_product, rhbz.b_product_version,
562801
                     summary, bzcomment,
562801
-                    (rhbz.b_create_private | (opts & OPT_g)), // either we got Bugzilla_CreatePrivate from settings or -g was specified on cmdline
562801
+                    rhbz.b_create_private,
562801
                     rhbz.b_private_groups
562801
                     );
562801
             free(bzcomment);
562801
@@ -1241,6 +1274,13 @@ int main(int argc, char **argv)
562801
             bz = new_bug_info();
562801
             bz->bi_status = xstrdup("NEW");
562801
             bz->bi_id = new_id;
562801
+
562801
+            if (existing_id >= 0)
562801
+            {
562801
+                log(_("Closing bug %i as duplicate of bug %i"), new_id, existing_id);
562801
+                rhbz_close_as_duplicate(client, new_id, existing_id, RHBZ_NOMAIL_NOTIFY);
562801
+            }
562801
+
562801
             goto log_out;
562801
         }
562801
 
562801
diff --git a/src/plugins/rhbz.c b/src/plugins/rhbz.c
562801
index bad9ed4..a227c62 100644
562801
--- a/src/plugins/rhbz.c
562801
+++ b/src/plugins/rhbz.c
562801
@@ -862,6 +862,29 @@ void rhbz_set_url(struct abrt_xmlrpc *ax, int bug_id, const char *url, int flags
562801
         xmlrpc_DECREF(result);
562801
 }
562801
 
562801
+void rhbz_close_as_duplicate(struct abrt_xmlrpc *ax, int bug_id,
562801
+                        int duplicate_bug,
562801
+                        int flags)
562801
+{
562801
+    func_entry();
562801
+
562801
+    const int nomail_notify = !!IS_NOMAIL_NOTIFY(flags);
562801
+    xmlrpc_value *result = abrt_xmlrpc_call(ax, "Bug.update", "{s:i,s:s,s:s,s:i,s:i}",
562801
+                              "ids", bug_id,
562801
+                              "status", "CLOSED",
562801
+                              "resolution", "DUPLICATE",
562801
+                              "dupe_of", duplicate_bug,
562801
+
562801
+                /* Undocumented argument but it works with Red Hat Bugzilla version 4.2.4-7
562801
+                 * and version 4.4.rc1.b02
562801
+                 */
562801
+                              "nomail", nomail_notify
562801
+    );
562801
+
562801
+    if (result)
562801
+        xmlrpc_DECREF(result);
562801
+}
562801
+
562801
 xmlrpc_value *rhbz_search_duphash(struct abrt_xmlrpc *ax,
562801
                         const char *product,
562801
                         const char *version,
562801
diff --git a/src/plugins/rhbz.h b/src/plugins/rhbz.h
562801
index 976d333..15e7699 100644
562801
--- a/src/plugins/rhbz.h
562801
+++ b/src/plugins/rhbz.h
562801
@@ -74,6 +74,10 @@ void rhbz_add_comment(struct abrt_xmlrpc *ax, int bug_id, const char *comment,
562801
 
562801
 void rhbz_set_url(struct abrt_xmlrpc *ax, int bug_id, const char *url, int flags);
562801
 
562801
+void rhbz_close_as_duplicate(struct abrt_xmlrpc *ax, int bug_id,
562801
+                             int duplicate_bug,
562801
+                             int flags);
562801
+
562801
 void *rhbz_bug_read_item(const char *memb, xmlrpc_value *xml, int flags);
562801
 
562801
 void rhbz_logout(struct abrt_xmlrpc *ax);
562801
-- 
562801
1.8.3.1
562801