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

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