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