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

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