[LIBREPORT PATCH] added options to create private bz tickets rhbz#803772

Jiri Moskovcak jmoskovc at redhat.com
Fri Jul 19 11:52:47 UTC 2013


Signed-off-by: Jiri Moskovcak <jmoskovc at redhat.com>
---
 src/include/internal_libreport.h   |  2 ++
 src/lib/Makefile.am                |  3 ++-
 src/lib/libreport_glib.c           | 45 ++++++++++++++++++++++++++++++++++++++
 src/plugins/bugzilla.conf          |  4 ++++
 src/plugins/report_Bugzilla.xml.in | 11 ++++++++++
 src/plugins/reporter-bugzilla.c    | 24 +++++++++++++++-----
 src/plugins/rhbz.c                 | 21 +++++++++++++-----
 src/plugins/rhbz.h                 |  1 +
 8 files changed, 98 insertions(+), 13 deletions(-)
 create mode 100644 src/lib/libreport_glib.c

diff --git a/src/include/internal_libreport.h b/src/include/internal_libreport.h
index 1d1d204..afedc73 100644
--- a/src/include/internal_libreport.h
+++ b/src/include/internal_libreport.h
@@ -709,6 +709,8 @@ file_obj_t *new_file_obj(const char* fullpath, const char* filename);
 void free_file_obj(file_obj_t *f);
 #define load_workflow_config_data libreport_load_workflow_config_data
 GHashTable *load_workflow_config_data(const char* path);
+#define parse_list libreport_parse_list
+GList *parse_list(const char* list);
 
 /* Connect to abrtd over unix domain socket, issue DELETE command */
 int delete_dump_dir_possibly_using_abrtd(const char *dump_dir_name);
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 92287bc..fd996de 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -53,7 +53,8 @@ libreport_la_SOURCES = \
     workflow.c \
     workflow_xml_parser.c \
     config_item_info.c \
-    xml_parser.c
+    xml_parser.c \
+    libreport_glib.c
 libreport_la_CPPFLAGS = \
     -I$(srcdir)/../include \
     -DLOCALSTATEDIR='"$(localstatedir)"' \
diff --git a/src/lib/libreport_glib.c b/src/lib/libreport_glib.c
new file mode 100644
index 0000000..525548d
--- /dev/null
+++ b/src/lib/libreport_glib.c
@@ -0,0 +1,45 @@
+/*
+    Copyright (C) 2013  ABRT team
+    Copyright (C) 2013  RedHat Inc
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "internal_libreport.h"
+
+#define LIST_DELIMITER ","
+
+/*
+ * Parser comma separated list of strings to Glist
+ *
+ * @param list comma separated list of strings
+ * @returns GList or null if the list is empty
+ */
+GList *parse_list(const char* list)
+{
+    GList *l = NULL;
+
+    char *saved_ptr = NULL;
+    char *tmp_list = xstrdup(list);
+    char *item = strtok_r(tmp_list, LIST_DELIMITER, &saved_ptr);
+    while (item)
+    {
+        l = g_list_append(l, strtrim(xstrdup(item)));
+        item = strtok_r(NULL, LIST_DELIMITER, &saved_ptr);
+    }
+
+    free(tmp_list);
+    return l;
+}
diff --git a/src/plugins/bugzilla.conf b/src/plugins/bugzilla.conf
index 7c15f62..0fb3794 100644
--- a/src/plugins/bugzilla.conf
+++ b/src/plugins/bugzilla.conf
@@ -15,3 +15,7 @@ Password =
 # (If you need to add more, the syntax is: "component[,component...]")
 #
 DontMatchComponents = selinux-policy
+
+# for more info about these settings see: https://github.com/abrt/abrt/wiki/FAQ#creating-private-bugzilla-tickets
+# CreatePrivate = no
+# PrivateGroups = group_218
diff --git a/src/plugins/report_Bugzilla.xml.in b/src/plugins/report_Bugzilla.xml.in
index 18382d4..d1516ba 100644
--- a/src/plugins/report_Bugzilla.xml.in
+++ b/src/plugins/report_Bugzilla.xml.in
@@ -34,6 +34,11 @@
             <_description>Check SSL key validity</_description>
             <default-value>yes</default-value>
         </option>
+        <option type="bool" name="Bugzilla_CreatePrivate">
+            <_label>Restrict access</_label>
+            <_description>Restrict access to the created bugzilla ticket allowing only users from specified groups to view it (see advanced settings for more details)</_description>
+            <default-value>no</default-value>
+        </option>
         <advanced-options>
             <option type="text" name="Bugzilla_Product">
                 <_label>Bugzilla product</_label>
@@ -55,6 +60,12 @@
                 <allow-empty>yes</allow-empty>
                 <_note-html>Sets the proxy server to use for HTTPS</_note-html>
             </option>
+            <option type="text" name="Bugzilla_PrivateGroups">
+                <_label>Groups</_label>
+                <allow-empty>yes</allow-empty>
+                <default-value>group_218</default-value>
+                <_note-html>Restrict the access to specified groups &lt;a href="https://github.com/abrt/abrt/wiki/FAQ#creating-private-bugzilla-tickets"&gt;?&lt;/a&gt;</_note-html>
+            </option>
         </advanced-options>
     </options>
 </event>
diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c
index 972a1f0..965faf4 100644
--- a/src/plugins/reporter-bugzilla.c
+++ b/src/plugins/reporter-bugzilla.c
@@ -679,6 +679,8 @@ struct bugzilla_struct {
     char *b_product_version;
     const char *b_DontMatchComponents;
     int         b_ssl_verify;
+    int         b_create_private;
+    GList       *b_private_groups;
 };
 
 static void set_settings(struct bugzilla_struct *b, map_string_t *settings)
@@ -734,6 +736,14 @@ static void set_settings(struct bugzilla_struct *b, map_string_t *settings)
 
     environ = getenv("Bugzilla_DontMatchComponents");
     b->b_DontMatchComponents = environ ? environ : get_map_string_item_or_empty(settings, "DontMatchComponents");
+
+    environ = getenv("Bugzilla_CreatePrivate");
+    b->b_create_private = string_to_bool(environ ? environ : get_map_string_item_or_empty(settings, "Bugzilla_CreatePrivate"));
+    VERB1 log("create private bz ticket: '%s'", b->b_create_private ? "YES": "NO");
+
+    environ = getenv("Bugzilla_PrivateGroups");
+    b->b_private_groups = parse_list(environ ? environ : get_map_string_item_or_empty(settings, "Bugzilla_CreatePrivate"));
+    VERB1 log("groups: '%p'", b->b_private_groups);
 }
 
 static
@@ -887,7 +897,7 @@ int main(int argc, char **argv)
     char *abrt_hash = NULL;
     char *ticket_no = NULL;
     char *debug_str = NULL;
-    GList *group = NULL;
+    struct bugzilla_struct rhbz = { 0 };
     /* Keep enum above and order of options below in sync! */
     struct options program_options[] = {
         OPT__VERBOSE(&g_verbose),
@@ -900,7 +910,7 @@ int main(int argc, char **argv)
         OPT_BOOL(     'f', NULL, NULL,                       _("Force reporting even if this problem is already reported")),
         OPT_BOOL(     'w', NULL, NULL,                       _("Add bugzilla user to CC list [of bug with this ID]")),
         OPT_STRING(   'h', "duphash", &abrt_hash, "DUPHASH", _("Print BUG_ID which has given DUPHASH")),
-        OPT_LIST(     'g', "group", &group      , "GROUP"  , _("Restrict access to this group only")),
+        OPT_LIST(     'g', "group", &rhbz.b_private_groups , "GROUP"  , _("Restrict access to this group only")),
         OPT_OPTSTRING('D', "debug", &debug_str  , "STR"    , _("Debug")),
         OPT_END()
     };
@@ -910,7 +920,7 @@ int main(int argc, char **argv)
     export_abrt_envvars(0);
 
     map_string_t *settings = new_map_string();
-    struct bugzilla_struct rhbz = { 0 };
+
     {
         if (!conf_file)
             conf_file = g_list_append(conf_file, (char*) CONF_DIR"/plugins/bugzilla.conf");
@@ -1202,10 +1212,12 @@ int main(int argc, char **argv)
                 strbuf_append_strf(bzcomment_buf, "\nPotential duplicate: bug %u\n", crossver_id);
             char *bzcomment = strbuf_free_nobuf(bzcomment_buf);
             char *summary = create_summary_string(problem_data, comment_fmt_spec);
-            int new_id = rhbz_new_bug(client, problem_data, rhbz.b_product, rhbz.b_product_version,
+            int new_id = rhbz_new_bug(client,
+                    problem_data, rhbz.b_product, rhbz.b_product_version,
                     summary, bzcomment,
-                    group
-            );
+                    (rhbz.b_create_private | (opts & OPT_g)), // either we got Bugzilla_CreatePrivate from settings or -g was specified on cmdline
+                    rhbz.b_private_groups
+                    );
             free(bzcomment);
             free(summary);
 
diff --git a/src/plugins/rhbz.c b/src/plugins/rhbz.c
index 2138c5f..90c390b 100644
--- a/src/plugins/rhbz.c
+++ b/src/plugins/rhbz.c
@@ -527,6 +527,7 @@ int rhbz_new_bug(struct abrt_xmlrpc *ax,
                 const char *version,
                 const char *bzsummary,
                 const char *bzcomment,
+                bool private,
                 GList *group)
 {
     func_entry();
@@ -602,16 +603,24 @@ int rhbz_new_bug(struct abrt_xmlrpc *ax,
     if(arch)
         abrt_xmlrpc_params_add_string(&env, params, "platform", arch);
 
-    if (group)
+    if (private)
     {
-        xmlrpc_value *xmlrpc_groups = abrt_xmlrpc_array_new(&env);
+        if (group)
+        {
+            xmlrpc_value *xmlrpc_groups = abrt_xmlrpc_array_new(&env);
 
-        for (GList *l = group; l; l = l->next)
-            abrt_xmlrpc_array_append_string(&env, xmlrpc_groups, l->data);
+            for (GList *l = group; l; l = l->next)
+                abrt_xmlrpc_array_append_string(&env, xmlrpc_groups, l->data);
 
-        abrt_xmlrpc_params_add_array(&env, params, "groups", xmlrpc_groups);
+            abrt_xmlrpc_params_add_array(&env, params, "groups", xmlrpc_groups);
 
-        xmlrpc_DECREF(xmlrpc_groups);
+            xmlrpc_DECREF(xmlrpc_groups);
+        }
+        else
+        {
+            error_msg(_("A private ticket creation has been requested, but no groups were specified, please see https://github.com/abrt/abrt/wiki/FAQ#creating-private-bugzilla-tickets for more info"));
+            return -1;
+        }
     }
 
     xmlrpc_value* result = abrt_xmlrpc_call_params(&env, ax, "Bug.create", params);
diff --git a/src/plugins/rhbz.h b/src/plugins/rhbz.h
index fc99740..0e811ba 100644
--- a/src/plugins/rhbz.h
+++ b/src/plugins/rhbz.h
@@ -90,6 +90,7 @@ int rhbz_new_bug(struct abrt_xmlrpc *ax,
                 const char *version,
                 const char *bzsummary,
                 const char *bzcomment,
+                bool private,
                 GList *group);
 
 int rhbz_attach_blob(struct abrt_xmlrpc *ax, const char *bug_id,
-- 
1.8.3.1



More information about the Crash-catcher mailing list