Blame SOURCES/0061-ureport-enabled-inclusion-of-Authentication-data.patch

28bab8
From 1dc5d9f838b23451e74063c022e4c6291feb024a Mon Sep 17 00:00:00 2001
28bab8
From: Jakub Filak <jfilak@redhat.com>
28bab8
Date: Wed, 10 Sep 2014 12:08:40 +0200
28bab8
Subject: [LIBREPORT PATCH 61/93] ureport: enabled inclusion of Authentication
28bab8
 data
28bab8
28bab8
Resolves rhbz#1139557
28bab8
28bab8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
28bab8
28bab8
Conflicts:
28bab8
	src/plugins/ureport.c
28bab8
---
28bab8
 doc/reporter-ureport.txt | 17 +++++++++++++++++
28bab8
 src/lib/json.c           | 32 +++++++++++++++++++++++++++++++-
28bab8
 src/lib/ureport.h        | 14 ++++++++++++++
28bab8
 src/plugins/ureport.c    | 31 ++++++++++++++++++++++++++++++-
28bab8
 src/plugins/ureport.conf |  8 ++++++++
28bab8
 5 files changed, 100 insertions(+), 2 deletions(-)
28bab8
28bab8
diff --git a/doc/reporter-ureport.txt b/doc/reporter-ureport.txt
28bab8
index 54823ae..9264cda 100644
28bab8
--- a/doc/reporter-ureport.txt
28bab8
+++ b/doc/reporter-ureport.txt
28bab8
@@ -44,6 +44,14 @@ Configuration file lines should have 'PARAM = VALUE' format. The parameters are:
28bab8
 'ContactEmail'::
28bab8
    Email address attached to a bthash on the server.
28bab8
 
28bab8
+'IncludeAuthData'::
28bab8
+   If this option is set to 'yes', uploaded uReport will contain 'auth' object
28bab8
+   consisting from key value pairs made from CSV list stored in 'AuthDataItems'
28bab8
+   option. Keys are file names and values are bites of these files.
28bab8
+
28bab8
+'AuthDataItems'::
28bab8
+   CSV list of files included in the 'auth' uReport object.
28bab8
+
28bab8
 Parameters can be overridden via $uReport_PARAM environment variables.
28bab8
 
28bab8
 OPTIONS
28bab8
@@ -85,6 +93,9 @@ OPTIONS
28bab8
 -u, --url URL::
28bab8
    Specify server URL
28bab8
 
28bab8
+-i AUTH_DATA_ITEMS::
28bab8
+   List of dump dir files included in the 'auth' uReport object.
28bab8
+
28bab8
 ENVIRONMENT VARIABLES
28bab8
 ---------------------
28bab8
 Environment variables take precedence over values provided in
28bab8
@@ -99,6 +110,12 @@ the configuration file.
28bab8
 'uReport_ContactEmail'::
28bab8
    Email address attached to a bthash on the server.
28bab8
 
28bab8
+'uReport_IncludeAuthData'::
28bab8
+   See IncludeAuthData configuration option for details.
28bab8
+
28bab8
+'uReport_AuthDataItems'::
28bab8
+   See AuthDataItems configuration option for details.
28bab8
+
28bab8
 SEE ALSO
28bab8
 --------
28bab8
 ureport.conf(5)
28bab8
diff --git a/src/lib/json.c b/src/lib/json.c
28bab8
index 66db537..8935ef8 100644
28bab8
--- a/src/lib/json.c
28bab8
+++ b/src/lib/json.c
28bab8
@@ -37,7 +37,7 @@ static void ureport_add_str(struct json_object *ur, const char *key,
28bab8
     json_object_object_add(ur, key, jstring);
28bab8
 }
28bab8
 
28bab8
-char *ureport_from_dump_dir(const char *dump_dir_path)
28bab8
+char *ureport_from_dump_dir_ext(const char *dump_dir_path, const struct ureport_preferences *preferences)
28bab8
 {
28bab8
     char *error_message;
28bab8
     struct sr_report *report = sr_abrt_report_from_dir(dump_dir_path,
28bab8
@@ -46,12 +46,42 @@ char *ureport_from_dump_dir(const char *dump_dir_path)
28bab8
     if (!report)
28bab8
         error_msg_and_die("%s", error_message);
28bab8
 
28bab8
+    if (preferences != NULL && preferences->urp_auth_items != NULL)
28bab8
+    {
28bab8
+        struct dump_dir *dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY);
28bab8
+        if (!dd)
28bab8
+            xfunc_die(); /* dd_opendir() already printed an error message */
28bab8
+
28bab8
+        GList *iter = preferences->urp_auth_items;
28bab8
+        for ( ; iter != NULL; iter = g_list_next(iter))
28bab8
+        {
28bab8
+            const char *key = (const char *)iter->data;
28bab8
+            char *value = dd_load_text_ext(dd, key,
28bab8
+                    DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE | DD_FAIL_QUIETLY_ENOENT);
28bab8
+
28bab8
+            if (value == NULL)
28bab8
+            {
28bab8
+                perror_msg("Cannot include '%s' in 'auth'", key);
28bab8
+                continue;
28bab8
+            }
28bab8
+
28bab8
+            sr_report_add_auth(report, key, value);
28bab8
+        }
28bab8
+
28bab8
+        dd_close(dd);
28bab8
+    }
28bab8
+
28bab8
     char *json_ureport = sr_report_to_json(report);
28bab8
     sr_report_free(report);
28bab8
 
28bab8
     return json_ureport;
28bab8
 }
28bab8
 
28bab8
+char *ureport_from_dump_dir(const char *dump_dir_path)
28bab8
+{
28bab8
+    return ureport_from_dump_dir_ext(dump_dir_path, /*no preferences*/NULL);
28bab8
+}
28bab8
+
28bab8
 char *new_json_attachment(const char *bthash, const char *type, const char *data)
28bab8
 {
28bab8
     struct json_object *attachment = json_object_new_object();
28bab8
diff --git a/src/lib/ureport.h b/src/lib/ureport.h
28bab8
index 16f40f1..ca1d538 100644
28bab8
--- a/src/lib/ureport.h
28bab8
+++ b/src/lib/ureport.h
28bab8
@@ -26,6 +26,14 @@ extern "C" {
28bab8
 #endif
28bab8
 
28bab8
 /*
28bab8
+ * uReport generation configuration
28bab8
+ */
28bab8
+struct ureport_preferences
28bab8
+{
28bab8
+    GList *urp_auth_items;  ///< list of file names included in 'auth' key
28bab8
+};
28bab8
+
28bab8
+/*
28bab8
  * uReport server configuration
28bab8
  */
28bab8
 struct ureport_server_config
28bab8
@@ -35,6 +43,8 @@ struct ureport_server_config
28bab8
     char *ur_client_cert; ///< Path to certificate used for client
28bab8
                           ///< authentication (or NULL)
28bab8
     char *ur_client_key;  ///< Private key for the certificate
28bab8
+
28bab8
+    struct ureport_preferences ur_prefs; ///< configuration for uReport generation
28bab8
 };
28bab8
 
28bab8
 struct abrt_post_state;
28bab8
@@ -54,6 +64,10 @@ struct post_state *ureport_attach_email(const char *bthash, const char *email,
28bab8
 #define ureport_from_dump_dir libreport_ureport_from_dump_dir
28bab8
 char *ureport_from_dump_dir(const char *dump_dir_path);
28bab8
 
28bab8
+#define ureport_from_dump_dir_ext libreport_ureport_from_dump_dir_ext
28bab8
+char *ureport_from_dump_dir_ext(const char *dump_dir_path,
28bab8
+                                const struct ureport_preferences *preferences);
28bab8
+
28bab8
 #ifdef __cplusplus
28bab8
 }
28bab8
 #endif
28bab8
diff --git a/src/plugins/ureport.c b/src/plugins/ureport.c
28bab8
index 59554f4..d23cc79 100644
28bab8
--- a/src/plugins/ureport.c
28bab8
+++ b/src/plugins/ureport.c
28bab8
@@ -108,6 +108,19 @@ static void load_ureport_server_config(struct ureport_server_config *config, map
28bab8
     VALUE_FROM_CONF("URL", config->ur_url, (const char *));
28bab8
     VALUE_FROM_CONF("SSLVerify", config->ur_ssl_verify, string_to_bool);
28bab8
 
28bab8
+    bool include_auth = false;
28bab8
+    VALUE_FROM_CONF("IncludeAuthData", include_auth, string_to_bool);
28bab8
+
28bab8
+    if (include_auth)
28bab8
+    {
28bab8
+        const char *auth_items = NULL;
28bab8
+        VALUE_FROM_CONF("AuthDataItems", auth_items, (const char *));
28bab8
+        config->ur_prefs.urp_auth_items = parse_list(auth_items);
28bab8
+
28bab8
+        if (config->ur_prefs.urp_auth_items == NULL)
28bab8
+            log_warning("IncludeAuthData set to 'yes' but AuthDataItems is empty.");
28bab8
+    }
28bab8
+
28bab8
     const char *client_auth = NULL;
28bab8
     VALUE_FROM_CONF("SSLClientAuth", client_auth, (const char *));
28bab8
     parse_client_auth_paths(config, client_auth);
28bab8
@@ -413,6 +426,9 @@ int main(int argc, char **argv)
28bab8
         .ur_ssl_verify = true,
28bab8
         .ur_client_cert = NULL,
28bab8
         .ur_client_key = NULL,
28bab8
+        {
28bab8
+            .urp_auth_items = NULL,
28bab8
+        },
28bab8
     };
28bab8
 
28bab8
     enum {
28bab8
@@ -421,6 +437,7 @@ int main(int argc, char **argv)
28bab8
         OPT_u = 1 << 2,
28bab8
         OPT_k = 1 << 3,
28bab8
         OPT_t = 1 << 4,
28bab8
+        OPT_i = 1 << 5,
28bab8
     };
28bab8
 
28bab8
     int ret = 1; /* "failure" (for now) */
28bab8
@@ -428,6 +445,7 @@ int main(int argc, char **argv)
28bab8
     const char *conf_file = CONF_FILE_PATH;
28bab8
     const char *arg_server_url = NULL;
28bab8
     const char *client_auth = NULL;
28bab8
+    GList *auth_items = NULL;
28bab8
     const char *dump_dir_path = ".";
28bab8
     const char *ureport_hash = NULL;
28bab8
     bool ureport_hash_from_rt = false;
28bab8
@@ -443,6 +461,7 @@ int main(int argc, char **argv)
28bab8
         OPT_BOOL('k', "insecure", &insecure,
28bab8
                           _("Allow insecure connection to ureport server")),
28bab8
         OPT_STRING('t', "auth", &client_auth, "SOURCE", _("Use client authentication")),
28bab8
+        OPT_LIST('i', "auth_items", &auth_items, "AUTH_ITEMS", _("Additional files included in 'auth' key")),
28bab8
         OPT_STRING('c', NULL, &conf_file, "FILE", _("Configuration file")),
28bab8
         OPT_STRING('a', "attach", &ureport_hash, "BTHASH",
28bab8
                           _("bthash of uReport to attach (conflicts with -A)")),
28bab8
@@ -461,6 +480,8 @@ int main(int argc, char **argv)
28bab8
 
28bab8
     const char *program_usage_string = _(
28bab8
         "& [-v] [-c FILE] [-u URL] [-k] [-t SOURCE] [-A -a bthash -B -b bug-id -E -e email] [-d DIR]\n"
28bab8
+        "& [-v] [-c FILE] [-u URL] [-k] [-t SOURCE] [-i AUTH_ITEMS]\\\n"
28bab8
+        "  [-A -a bthash -B -b bug-id -E -e email] [-d DIR]\n"
28bab8
         "\n"
28bab8
         "Upload micro report or add an attachment to a micro report\n"
28bab8
         "\n"
28bab8
@@ -480,6 +501,11 @@ int main(int argc, char **argv)
28bab8
         config.ur_ssl_verify = !insecure;
28bab8
     if (opts & OPT_t)
28bab8
         parse_client_auth_paths(&config, client_auth);
28bab8
+    if (opts & OPT_i)
28bab8
+    {
28bab8
+        g_list_free_full(config.ur_prefs.urp_auth_items, free);
28bab8
+        config.ur_prefs.urp_auth_items = auth_items;
28bab8
+    }
28bab8
 
28bab8
     if (!config.ur_url)
28bab8
         error_msg_and_die("You need to specify server URL");
28bab8
@@ -572,7 +598,7 @@ int main(int argc, char **argv)
28bab8
     char *dest_url = concat_path_file(config.ur_url, REPORT_URL_SFX);
28bab8
     config.ur_url = dest_url;
28bab8
 
28bab8
-    char *json_ureport = ureport_from_dump_dir(dump_dir_path);
28bab8
+    char *json_ureport = ureport_from_dump_dir_ext(dump_dir_path, &(config.ur_prefs));
28bab8
     if (!json_ureport)
28bab8
     {
28bab8
         error_msg(_("Not uploading an empty uReport"));
28bab8
@@ -648,6 +674,9 @@ format_err:
28bab8
     free(dest_url);
28bab8
 
28bab8
 finalize:
28bab8
+    if (config.ur_prefs.urp_auth_items != auth_items)
28bab8
+        g_list_free_full(config.ur_prefs.urp_auth_items, free);
28bab8
+
28bab8
     free_map_string(settings);
28bab8
     free(config.ur_client_cert);
28bab8
     free(config.ur_client_key);
28bab8
diff --git a/src/plugins/ureport.conf b/src/plugins/ureport.conf
28bab8
index 407fbca..8abeb26 100644
28bab8
--- a/src/plugins/ureport.conf
28bab8
+++ b/src/plugins/ureport.conf
28bab8
@@ -7,6 +7,14 @@ URL = http://bug-report.itos.redhat.com
28bab8
 # Contact email attached to an uploaded uReport if required
28bab8
 # ContactEmail = foo@example.com
28bab8
 
28bab8
+# yes means that uReport will contain 'auth' object consisting
28bab8
+# from key value pairs made from AuthDataItems
28bab8
+# IncludeAuthData = yes
28bab8
+
28bab8
+# If IncludeAuthData is set to yes, these fields will be included
28bab8
+# in 'auth' object
28bab8
+AuthDataItems = hostname, machineid
28bab8
+
28bab8
 # Client-side authentication
28bab8
 # None (default):
28bab8
 # SSLClientAuth =
28bab8
-- 
28bab8
1.8.3.1
28bab8