From 2ccab23fa49b5bbf101fff8185078fda2310747e Mon Sep 17 00:00:00 2001 From: Jakub Filak Date: Oct 13 2014 08:14:18 +0000 Subject: fix bugs in ureport response parser & uploader --- diff --git a/0002-upload-don-t-ask-for-password-if-the-env-var-is-empt.patch b/0002-upload-don-t-ask-for-password-if-the-env-var-is-empt.patch new file mode 100644 index 0000000..d6d73b3 --- /dev/null +++ b/0002-upload-don-t-ask-for-password-if-the-env-var-is-empt.patch @@ -0,0 +1,29 @@ +From c7eaedb85aa65b53e2a874592007b1242abbcfa6 Mon Sep 17 00:00:00 2001 +From: Jakub Filak +Date: Wed, 8 Oct 2014 12:26:29 +0200 +Subject: [PATCH 2/7] upload: don't ask for password if the env var is empty + string + +Related to rhbz#1066486 + +Signed-off-by: Jakub Filak +--- + src/plugins/reporter-upload.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/plugins/reporter-upload.c b/src/plugins/reporter-upload.c +index 1ccfd65..42ec271 100644 +--- a/src/plugins/reporter-upload.c ++++ b/src/plugins/reporter-upload.c +@@ -156,7 +156,7 @@ static int create_and_upload_archive( + /* Load Password only if Username is configured, it doesn't make */ + /* much sense to load Password without Username. */ + state->password = getenv("Upload_Password"); +- if (state->password == NULL && state->password[0] == '\0') ++ if (state->password == NULL) + { + /* Be permissive and nice, ask only once and don't check */ + /* the result. User can dismiss this prompt but the upload */ +-- +2.1.0 + diff --git a/0003-lib-fix-a-bug-in-ureport-response-parser.patch b/0003-lib-fix-a-bug-in-ureport-response-parser.patch new file mode 100644 index 0000000..c651775 --- /dev/null +++ b/0003-lib-fix-a-bug-in-ureport-response-parser.patch @@ -0,0 +1,29 @@ +From 28d979c3824d0e90e14ba7f7be679e66fb53c851 Mon Sep 17 00:00:00 2001 +From: Jakub Filak +Date: Wed, 8 Oct 2014 12:37:24 +0200 +Subject: [PATCH 3/7] lib: fix a bug in ureport response parser + +Revealed by coverity + +Related to rhbz1139987 + +Signed-off-by: Jakub Filak +--- + src/lib/ureport.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/lib/ureport.c b/src/lib/ureport.c +index dd79054..3ac859d 100644 +--- a/src/lib/ureport.c ++++ b/src/lib/ureport.c +@@ -339,6 +339,7 @@ parse_solution_from_json_list(struct json_object *list, + continue; + + cause = json_object_get_string(struct_elem); ++ if (!cause) + continue; + + if (!json_object_object_get_ex(list_elem, "note", &struct_elem)) +-- +2.1.0 + diff --git a/0004-rhtsupport-re-prompt-for-credentials.patch b/0004-rhtsupport-re-prompt-for-credentials.patch new file mode 100644 index 0000000..38c2206 --- /dev/null +++ b/0004-rhtsupport-re-prompt-for-credentials.patch @@ -0,0 +1,250 @@ +From f2a0d8fc954afef291c0989c756bbe455c1ccc92 Mon Sep 17 00:00:00 2001 +From: Jakub Filak +Date: Fri, 26 Sep 2014 18:40:46 +0200 +Subject: [PATCH 4/7] rhtsupport: re-prompt for credentials + +Related to rhbz#1104313 + +Signed-off-by: Jakub Filak +--- + src/include/ureport.h | 11 ++++ + src/lib/ureport.c | 2 +- + src/plugins/reporter-rhtsupport.c | 117 ++++++++++++++++++++++++++++++-------- + 3 files changed, 106 insertions(+), 24 deletions(-) + +diff --git a/src/include/ureport.h b/src/include/ureport.h +index 8bb1f6c..104e8d0 100644 +--- a/src/include/ureport.h ++++ b/src/include/ureport.h +@@ -216,6 +216,17 @@ struct ureport_server_response * + ureport_submit(const char *json_ureport, struct ureport_server_config *config); + + /* ++ * Build a new uReport attachement from give arguments ++ * ++ * @param bthash ID of uReport ++ * @param type Type of attachement recognized by uReport Server ++ * @param data Attached data ++ * @returm Malloced JSON string ++ */ ++char * ++ureport_json_attachment_new(const char *bthash, const char *type, const char *data); ++ ++/* + * Attach given string to uReport + * + * @param bthash uReport identifier +diff --git a/src/lib/ureport.c b/src/lib/ureport.c +index 3ac859d..731b96c 100644 +--- a/src/lib/ureport.c ++++ b/src/lib/ureport.c +@@ -742,7 +742,7 @@ ureport_submit(const char *json, struct ureport_server_config *config) + return resp; + } + +-static char * ++char * + ureport_json_attachment_new(const char *bthash, const char *type, const char *data) + { + struct json_object *attachment = json_object_new_object(); +diff --git a/src/plugins/reporter-rhtsupport.c b/src/plugins/reporter-rhtsupport.c +index 7f5c62b..9704c3c 100644 +--- a/src/plugins/reporter-rhtsupport.c ++++ b/src/plugins/reporter-rhtsupport.c +@@ -26,6 +26,22 @@ + + #define QUERY_HINTS_IF_SMALLER_THAN (8*1024*1024) + ++static void ask_rh_credentials(char **login, char **password); ++ ++#define INVALID_CREDENTIALS_LOOP(l, p, r, fncall) \ ++ do {\ ++ r = fncall;\ ++ if (r->error == 0 || r->http_resp_code != 401 ) { break; }\ ++ ask_rh_credentials(&l, &p);\ ++ free_rhts_result(r);\ ++ } while (1) ++ ++#define STRCPY_IF_NOT_EQUAL(dest, src) \ ++ do { if (strcmp(dest, src) != 0 ) { \ ++ free(dest); \ ++ dest = xstrdup(src); \ ++ } } while (0) ++ + static report_result_t *get_reported_to(const char *dump_dir_name) + { + struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); +@@ -170,6 +186,38 @@ ret_clean: + } + + static ++struct ureport_server_response *ureport_do_post_credentials(const char *json, struct ureport_server_config *config, const char *action) ++{ ++ struct post_state *post_state = NULL; ++ while (1) ++ { ++ post_state = ureport_do_post(json, config, action); ++ ++ if (post_state == NULL) ++ { ++ error_msg(_("Failed on submitting the problem")); ++ return NULL; ++ } ++ ++ if (post_state->http_resp_code != 401) ++ break; ++ ++ free_post_state(post_state); ++ ++ char *login = NULL; ++ char *password = NULL; ++ ask_rh_credentials(&login, &password); ++ ureport_server_config_set_basic_auth(config, login, password); ++ free(password); ++ free(login); ++ } ++ ++ struct ureport_server_response *resp = ureport_server_response_from_reply(post_state, config); ++ free(post_state); ++ return resp; ++} ++ ++static + char *submit_ureport(const char *dump_dir_name, struct ureport_server_config *conf) + { + struct dump_dir *dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY); +@@ -191,7 +239,7 @@ char *submit_ureport(const char *dump_dir_name, struct ureport_server_config *co + if (json == NULL) + return NULL; + +- struct ureport_server_response *resp = ureport_submit(json, conf); ++ struct ureport_server_response *resp = ureport_do_post_credentials(json, conf, UREPORT_SUBMIT_ACTION); + free(json); + if (resp == NULL) + return NULL; +@@ -215,9 +263,14 @@ char *submit_ureport(const char *dump_dir_name, struct ureport_server_config *co + } + + static +-bool check_for_hints(const char *url, const char *login, const char *password, bool ssl_verify, const char *tempfile) ++bool check_for_hints(const char *url, char **login, char **password, bool ssl_verify, const char *tempfile) + { +- rhts_result_t *result = get_rhts_hints(url, login, password, ssl_verify, tempfile); ++ rhts_result_t *result = NULL; ++ ++ INVALID_CREDENTIALS_LOOP((*login), (*password), ++ result, get_rhts_hints(url, *login, *password, ssl_verify, tempfile) ++ ); ++ + #if 0 /* testing */ + log("ERR:%d", result->error); + log("MSG:'%s'", result->msg); +@@ -291,6 +344,19 @@ char *ask_rh_password(const char *message) + } + + static ++void ask_rh_credentials(char **login, char **password) ++{ ++ free(*login); ++ free(*password); ++ ++ *login = ask_rh_login(_("Invalid password or login. Please enter your Red Hat login:")); ++ ++ char *question = xasprintf(_("Invalid password or login. Please enter the password for '%s':"), *login); ++ *password = ask_rh_password(question); ++ free(question); ++} ++ ++static + char *get_param_string(const char *name, map_string_t *settings, const char *dflt) + { + char *envname = xasprintf("RHTSupport_%s", name); +@@ -584,13 +650,17 @@ int main(int argc, char **argv) + log(_("Sending ABRT crash statistics data")); + + bthash = submit_ureport(dump_dir_name, &urconf); ++ ++ /* Ensure that we will use the updated credentials */ ++ STRCPY_IF_NOT_EQUAL(login, urconf.ur_username); ++ STRCPY_IF_NOT_EQUAL(password, urconf.ur_password); + } + + if (tempfile_size <= QUERY_HINTS_IF_SMALLER_THAN) + { + /* Check for hints and show them if we have something */ + log(_("Checking for hints")); +- if (check_for_hints(base_api_url, login, password, ssl_verify, tempfile)) ++ if (check_for_hints(base_api_url, &login, &password, ssl_verify, tempfile)) + { + ureport_server_config_destroy(&urconf); + free_map_string(ursettings); +@@ -613,15 +683,9 @@ int main(int argc, char **argv) + error_msg_and_die(_("Can't determine RH Support Product from problem data.")); + } + +- result = create_new_case(url, +- login, +- password, +- ssl_verify, +- product, +- version, +- summary, +- dsc, +- package ++ INVALID_CREDENTIALS_LOOP(login, password, ++ result, create_new_case(url, login, password, ssl_verify, ++ product, version, summary, dsc, package) + ); + + free(version); +@@ -673,7 +737,19 @@ int main(int argc, char **argv) + if (bthash) + { + log(_("Linking ABRT crash statistics record with the case")); +- ureport_attach_string(bthash, "RHCID", result->url, &urconf); ++ ++ /* Make sure we use the current credentials */ ++ ureport_server_config_set_basic_auth(&urconf, login, password); ++ ++ /* Do attach */ ++ char *json = ureport_json_attachment_new(bthash, "RHCID", result->url); ++ struct ureport_server_response *resp = ureport_do_post_credentials(json, &urconf, UREPORT_ATTACH_ACTION); ++ ureport_server_response_free(resp); ++ free(json); ++ ++ /* Update the credentials */ ++ STRCPY_IF_NOT_EQUAL(login, urconf.ur_username); ++ STRCPY_IF_NOT_EQUAL(password, urconf.ur_password); + } + + url = result->url; +@@ -705,10 +781,8 @@ int main(int argc, char **argv) + remote_filename + ); + free(remote_filename); +- result_atch = add_comment_to_case(url, +- login, password, +- ssl_verify, +- comment_text ++ INVALID_CREDENTIALS_LOOP(login, password, ++ result_atch, add_comment_to_case(url, login, password, ssl_verify, comment_text) + ); + free(comment_text); + } +@@ -716,11 +790,8 @@ int main(int argc, char **argv) + { + /* Attach the tarball of -d DIR */ + log(_("Attaching problem data to case '%s'"), url); +- result_atch = attach_file_to_case(url, +- login, password, +- ssl_verify, +- tempfile +- ++ INVALID_CREDENTIALS_LOOP(login, password, ++ result_atch, attach_file_to_case(url, login, password, ssl_verify, tempfile) + ); + } + if (result_atch->error) +-- +2.1.0 + diff --git a/0005-rhtsupport-attach-the-contact-email-to-bthash.patch b/0005-rhtsupport-attach-the-contact-email-to-bthash.patch new file mode 100644 index 0000000..c6328e7 --- /dev/null +++ b/0005-rhtsupport-attach-the-contact-email-to-bthash.patch @@ -0,0 +1,59 @@ +From e71aebba83efe673bfb554a9fbf1533b7a96bde8 Mon Sep 17 00:00:00 2001 +From: Jakub Filak +Date: Wed, 8 Oct 2014 12:10:10 +0200 +Subject: [PATCH 5/7] rhtsupport: attach the contact email to bthash + +Related to rhbz#1150388 + +Signed-off-by: Jakub Filak +--- + src/plugins/reporter-rhtsupport.c | 26 +++++++++++++++++++++----- + 1 file changed, 21 insertions(+), 5 deletions(-) + +diff --git a/src/plugins/reporter-rhtsupport.c b/src/plugins/reporter-rhtsupport.c +index 9704c3c..9e463a8 100644 +--- a/src/plugins/reporter-rhtsupport.c ++++ b/src/plugins/reporter-rhtsupport.c +@@ -263,6 +263,16 @@ char *submit_ureport(const char *dump_dir_name, struct ureport_server_config *co + } + + static ++void attach_to_ureport(struct ureport_server_config *conf, ++ const char *bthash, const char *attach_id, const char *data) ++{ ++ char *json = ureport_json_attachment_new(bthash, attach_id, data); ++ struct ureport_server_response *resp = ureport_do_post_credentials(json, conf, UREPORT_ATTACH_ACTION); ++ ureport_server_response_free(resp); ++ free(json); ++} ++ ++static + bool check_for_hints(const char *url, char **login, char **password, bool ssl_verify, const char *tempfile) + { + rhts_result_t *result = NULL; +@@ -741,11 +751,17 @@ int main(int argc, char **argv) + /* Make sure we use the current credentials */ + ureport_server_config_set_basic_auth(&urconf, login, password); + +- /* Do attach */ +- char *json = ureport_json_attachment_new(bthash, "RHCID", result->url); +- struct ureport_server_response *resp = ureport_do_post_credentials(json, &urconf, UREPORT_ATTACH_ACTION); +- ureport_server_response_free(resp); +- free(json); ++ /* Attach Customer Case ID*/ ++ attach_to_ureport(&urconf, bthash, "RHCID", result->url); ++ ++ /* Attach Contact e-mail if configured */ ++ const char *email = NULL; ++ UREPORT_OPTION_VALUE_FROM_CONF(ursettings, "ContactEmail", email, (const char *)); ++ if (email != NULL) ++ { ++ log(_("Linking ABRT crash statistics record with contact email: '%s'"), email); ++ attach_to_ureport(&urconf, bthash, "email", email); ++ } + + /* Update the credentials */ + STRCPY_IF_NOT_EQUAL(login, urconf.ur_username); +-- +2.1.0 + diff --git a/0006-ureport-document-rhsm-entitlement-in-the-man-page.patch b/0006-ureport-document-rhsm-entitlement-in-the-man-page.patch new file mode 100644 index 0000000..072cffe --- /dev/null +++ b/0006-ureport-document-rhsm-entitlement-in-the-man-page.patch @@ -0,0 +1,29 @@ +From 8f350e29a97311e620aa915e4fb977cae615dfb9 Mon Sep 17 00:00:00 2001 +From: Jakub Filak +Date: Thu, 9 Oct 2014 13:16:00 +0200 +Subject: [PATCH 6/7] ureport: document rhsm-entitlement in the man page + +Related: #1140224 + +Signed-off-by: Jakub Filak +--- + doc/reporter-ureport.txt | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/doc/reporter-ureport.txt b/doc/reporter-ureport.txt +index 4ce11a0..f31dd45 100644 +--- a/doc/reporter-ureport.txt ++++ b/doc/reporter-ureport.txt +@@ -37,6 +37,9 @@ Configuration file lines should have 'PARAM = VALUE' format. The parameters are: + 'rhsm';; + Uses the system certificate that is used for Red Hat subscription management. + ++ 'rhsm-entitlement';; ++ Same as 'rhsm' but uses the V3 RHSM entitlement certificates. ++ + 'puppet';; + Uses the certificate that is used by the Puppet configuration management tool. + +-- +2.1.0 + diff --git a/0007-rhtsupport-send-ureport-before-creating-description.patch b/0007-rhtsupport-send-ureport-before-creating-description.patch new file mode 100644 index 0000000..549f0ef --- /dev/null +++ b/0007-rhtsupport-send-ureport-before-creating-description.patch @@ -0,0 +1,102 @@ +From 0f59cec364a05aa8b1137739ecb4076f16a0406a Mon Sep 17 00:00:00 2001 +From: Jakub Filak +Date: Thu, 9 Oct 2014 14:02:11 +0200 +Subject: [PATCH 7/7] rhtsupport: send ureport before creating description + +Because we want to include the URL to uReport stored in 'reported_to' +file in the description. + +Related: #1139987 + +Signed-off-by: Jakub Filak +--- + src/plugins/reporter-rhtsupport.c | 45 +++++++++++++++++++-------------------- + 1 file changed, 22 insertions(+), 23 deletions(-) + +diff --git a/src/plugins/reporter-rhtsupport.c b/src/plugins/reporter-rhtsupport.c +index 9e463a8..9a1f392 100644 +--- a/src/plugins/reporter-rhtsupport.c ++++ b/src/plugins/reporter-rhtsupport.c +@@ -526,6 +526,13 @@ int main(int argc, char **argv) + free_map_string(settings); + + char *base_api_url = xstrdup(url); ++ char *bthash = NULL; ++ ++ map_string_t *ursettings = new_map_string(); ++ struct ureport_server_config urconf; ++ ++ prepare_ureport_configuration(urconf_file, ursettings, &urconf, ++ url, login, password, ssl_verify); + + if (opts & OPT_t) + { +@@ -592,6 +599,17 @@ int main(int argc, char **argv) + return 0; + } + free_report_result(reported_to); ++ ++ if (submit_ur) ++ { ++ log(_("Sending ABRT crash statistics data")); ++ ++ bthash = submit_ureport(dump_dir_name, &urconf); ++ ++ /* Ensure that we will use the updated credentials */ ++ STRCPY_IF_NOT_EQUAL(login, urconf.ur_username); ++ STRCPY_IF_NOT_EQUAL(password, urconf.ur_password); ++ } + } + + /* Gzipping e.g. 0.5gig coredump takes a while. Let user know what we are doing */ +@@ -647,25 +665,6 @@ int main(int argc, char **argv) + + if (!(opts & OPT_t)) + { +- char *bthash = NULL; +- +- map_string_t *ursettings = new_map_string(); +- struct ureport_server_config urconf; +- +- prepare_ureport_configuration(urconf_file, ursettings, &urconf, +- url, login, password, ssl_verify); +- +- if (submit_ur) +- { +- log(_("Sending ABRT crash statistics data")); +- +- bthash = submit_ureport(dump_dir_name, &urconf); +- +- /* Ensure that we will use the updated credentials */ +- STRCPY_IF_NOT_EQUAL(login, urconf.ur_username); +- STRCPY_IF_NOT_EQUAL(password, urconf.ur_password); +- } +- + if (tempfile_size <= QUERY_HINTS_IF_SMALLER_THAN) + { + /* Check for hints and show them if we have something */ +@@ -772,10 +771,6 @@ int main(int argc, char **argv) + result->url = NULL; + free_rhts_result(result); + result = NULL; +- +- ureport_server_config_destroy(&urconf); +- free_map_string(ursettings); +- free(bthash); + } + + char *remote_filename = NULL; +@@ -842,6 +837,10 @@ int main(int argc, char **argv) + free_rhts_result(result_atch); + free_rhts_result(result); + ++ ureport_server_config_destroy(&urconf); ++ free_map_string(ursettings); ++ free(bthash); ++ + free(base_api_url); + free(url); + free(login); +-- +2.1.0 + diff --git a/libreport.spec b/libreport.spec index bafe7ee..69d83f8 100644 --- a/libreport.spec +++ b/libreport.spec @@ -7,7 +7,7 @@ Summary: Generic library for reporting various problems Name: libreport Version: 2.3.0 -Release: 2%{?dist} +Release: 3%{?dist} License: GPLv2+ Group: System Environment/Libraries URL: https://fedorahosted.org/abrt/ @@ -15,6 +15,12 @@ Source: https://fedorahosted.org/released/abrt/%{name}-%{version}.tar.gz Source1: autogen.sh Patch0001: 0001-Translation-updates.patch +Patch0002: 0002-upload-don-t-ask-for-password-if-the-env-var-is-empt.patch +Patch0003: 0003-lib-fix-a-bug-in-ureport-response-parser.patch +Patch0004: 0004-rhtsupport-re-prompt-for-credentials.patch +Patch0005: 0005-rhtsupport-attach-the-contact-email-to-bthash.patch +Patch0006: 0006-ureport-document-rhsm-entitlement-in-the-man-page.patch +Patch0007: 0007-rhtsupport-send-ureport-before-creating-description.patch # git is need for '%%autosetup -S git' which automatically applies all the # patches above. Please, be aware that the patches must be generated @@ -671,6 +677,10 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || : %changelog +* Mon Oct 13 2014 Jakub Filak 2.3.0-3 +- ureport: fix a bug in the response parser +- upload: don't ask for password if the env var is empty string + * Wed Oct 08 2014 Jakub Filak 2.3.0-2 - Require satyr-0.15