Signed-off-by: Jakub Filak jfilak@redhat.com --- src/lib/client.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/lib/client.c b/src/lib/client.c index 9b2ee5c..d1ada22 100644 --- a/src/lib/client.c +++ b/src/lib/client.c @@ -129,7 +129,10 @@ char *ask(const char *question)
fflush(stdout);
- return xmalloc_fgets(stdin); + char *result = xmalloc_fgets(stdin); + strtrimch(result, '\n'); + + return result; }
char *ask_password(const char *question) @@ -142,7 +145,10 @@ char *ask_password(const char *question) fflush(stdout);
bool changed = set_echo(false); + char *result = xmalloc_fgets(stdin); + strtrimch(result, '\n'); + if (changed) set_echo(true);
Signed-off-by: Jakub Filak jfilak@redhat.com --- src/plugins/reporter-bugzilla.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-)
diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c index a61b2d4..0c321ea 100644 --- a/src/plugins/reporter-bugzilla.c +++ b/src/plugins/reporter-bugzilla.c @@ -669,8 +669,8 @@ int attach_files(struct abrt_xmlrpc *ax, const char *bug_id, /* Main */
struct bugzilla_struct { - const char *b_login; - const char *b_password; + char *b_login; + char *b_password; const char *b_bugzilla_url; const char *b_bugzilla_xmlrpc; const char *b_os_release; @@ -683,10 +683,10 @@ static void set_settings(struct bugzilla_struct *b, map_string_h *settings) const char *environ;
environ = getenv("Bugzilla_Login"); - b->b_login = environ ? environ : get_map_string_item_or_empty(settings, "Login"); + b->b_login = xstrdup(environ ? environ : get_map_string_item_or_empty(settings, "Login"));
environ = getenv("Bugzilla_Password"); - b->b_password = environ ? environ : get_map_string_item_or_empty(settings, "Password"); + b->b_password = xstrdup(environ ? environ : get_map_string_item_or_empty(settings, "Password"));
environ = getenv("Bugzilla_BugzillaURL"); b->b_bugzilla_url = environ ? environ : get_map_string_item_or_empty(settings, "BugzillaURL"); @@ -712,6 +712,26 @@ static void set_settings(struct bugzilla_struct *b, map_string_h *settings) }
static +char *ask_bz_login(const char *message) +{ + char *login = ask(message); + if (login == NULL || login[0] == '\0') + error_msg_and_die(_("Exiting due to not provided login")); + + return login; +} + +static +char *ask_bz_password(const char *message) +{ + char *password = ask_password(message); + if (password == NULL || password[0] == '\0') + error_msg_and_die(_("Exiting due to not provided password")); + + return password; +} + +static xmlrpc_value *rhbz_search_duphash(struct abrt_xmlrpc *ax, const char *product, const char *version, @@ -896,8 +916,17 @@ int main(int argc, char **argv) return EXIT_SUCCESS; }
- if (!rhbz.b_login[0] || !rhbz.b_password[0]) - error_msg_and_die(_("Empty login or password, please check your configuration")); + if (rhbz.b_login[0] == '\0') + { + free(rhbz.b_login); + rhbz.b_login = ask_bz_login(_("Login is not provided by configuration. Please provide Bugzilla login:")); + } + + if (rhbz.b_password[0] == '\0') + { + free(rhbz.b_password); + rhbz.b_password = ask_bz_password(_("Password is not provided by configuration. Please provide Bugzilla pasword:")); + }
if (opts & OPT_t) {
On 12/06/2012 09:25 AM, Jakub Filak wrote:
Signed-off-by: Jakub Filak jfilak@redhat.com
src/plugins/reporter-bugzilla.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-)
diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c index a61b2d4..0c321ea 100644 --- a/src/plugins/reporter-bugzilla.c +++ b/src/plugins/reporter-bugzilla.c @@ -669,8 +669,8 @@ int attach_files(struct abrt_xmlrpc *ax, const char *bug_id, /* Main */
struct bugzilla_struct {
- const char *b_login;
- const char *b_password;
- char *b_login;
- char *b_password; const char *b_bugzilla_url; const char *b_bugzilla_xmlrpc; const char *b_os_release;
@@ -683,10 +683,10 @@ static void set_settings(struct bugzilla_struct *b, map_string_h *settings) const char *environ;
environ = getenv("Bugzilla_Login");
- b->b_login = environ ? environ : get_map_string_item_or_empty(settings, "Login");
b->b_login = xstrdup(environ ? environ : get_map_string_item_or_empty(settings, "Login"));
environ = getenv("Bugzilla_Password");
- b->b_password = environ ? environ : get_map_string_item_or_empty(settings, "Password");
b->b_password = xstrdup(environ ? environ : get_map_string_item_or_empty(settings, "Password"));
environ = getenv("Bugzilla_BugzillaURL"); b->b_bugzilla_url = environ ? environ : get_map_string_item_or_empty(settings, "BugzillaURL");
@@ -712,6 +712,26 @@ static void set_settings(struct bugzilla_struct *b, map_string_h *settings) }
static +char *ask_bz_login(const char *message) +{
- char *login = ask(message);
- if (login == NULL || login[0] == '\0')
error_msg_and_die(_("Exiting due to not provided login"));
- return login;
+}
+static +char *ask_bz_password(const char *message) +{
- char *password = ask_password(message);
- if (password == NULL || password[0] == '\0')
error_msg_and_die(_("Exiting due to not provided password"));
- return password;
+}
+static xmlrpc_value *rhbz_search_duphash(struct abrt_xmlrpc *ax, const char *product, const char *version, @@ -896,8 +916,17 @@ int main(int argc, char **argv) return EXIT_SUCCESS; }
- if (!rhbz.b_login[0] || !rhbz.b_password[0])
error_msg_and_die(_("Empty login or password, please check your configuration"));
- if (rhbz.b_login[0] == '\0')
- {
free(rhbz.b_login);
rhbz.b_login = ask_bz_login(_("Login is not provided by configuration. Please provide Bugzilla login:"));
- how about just _("Please enter your bz login")
- }
- if (rhbz.b_password[0] == '\0')
- {
free(rhbz.b_password);
rhbz.b_password = ask_bz_password(_("Password is not provided by configuration. Please provide Bugzilla pasword:"));
- and here: _("Please enter the password for '%s'"), rhbz.b_login
}
if (opts & OPT_t) {
- closes rhbz#861899
Signed-off-by: Jakub Filak jfilak@redhat.com --- src/lib/abrt_xmlrpc.c | 52 ++++++++++++++++++++++++++++++----------- src/lib/abrt_xmlrpc.h | 3 +++ src/plugins/reporter-bugzilla.c | 24 ++++++++++++++----- src/plugins/rhbz.c | 18 +++++++++++--- src/plugins/rhbz.h | 2 +- 5 files changed, 75 insertions(+), 24 deletions(-)
diff --git a/src/lib/abrt_xmlrpc.c b/src/lib/abrt_xmlrpc.c index 74e473e..75dff14 100644 --- a/src/lib/abrt_xmlrpc.c +++ b/src/lib/abrt_xmlrpc.c @@ -108,37 +108,61 @@ void abrt_xmlrpc_free_client(struct abrt_xmlrpc *ax) free(ax); }
-/* die or return expected results */ -xmlrpc_value *abrt_xmlrpc_call(struct abrt_xmlrpc *ax, - const char* method, const char* format, ...) +/* internall helper function */ +static +xmlrpc_value *abrt_xmlrpc_call_full_va(xmlrpc_env *env, struct abrt_xmlrpc *ax, + const char *method, const char *format, + va_list args) { - xmlrpc_env env; - xmlrpc_env_init(&env); + xmlrpc_env_init(env);
xmlrpc_value* param = NULL; const char* suffix; - va_list args;
- va_start(args, format); - xmlrpc_build_value_va(&env, format, args, ¶m, &suffix); - va_end(args); - if (env.fault_occurred) - abrt_xmlrpc_die(&env); + xmlrpc_build_value_va(env, format, args, ¶m, &suffix); + if (env->fault_occurred) + abrt_xmlrpc_die(env);
- xmlrpc_value* result = NULL; + xmlrpc_value *result = NULL; if (*suffix != '\0') { xmlrpc_env_set_fault_formatted( - &env, XMLRPC_INTERNAL_ERROR, "Junk after the argument " + env, XMLRPC_INTERNAL_ERROR, "Junk after the argument " "specifier: '%s'. There must be exactly one argument.", suffix); } else { - xmlrpc_client_call2(&env, ax->ax_client, ax->ax_server_info, method, + xmlrpc_client_call2(env, ax->ax_client, ax->ax_server_info, method, param, &result); } xmlrpc_DECREF(param); + + return result; +} + +xmlrpc_value *abrt_xmlrpc_call_full(xmlrpc_env *env, struct abrt_xmlrpc *ax, + const char *method, const char *format, ...) +{ + va_list args; + va_start(args, format); + xmlrpc_value *result = abrt_xmlrpc_call_full_va(env, ax, method, format, args); + va_end(args); + + return result; +} + +/* die or return expected results */ +xmlrpc_value *abrt_xmlrpc_call(struct abrt_xmlrpc *ax, + const char *method, const char *format, ...) +{ + xmlrpc_env env; + + va_list args; + va_start(args, format); + xmlrpc_value *result = abrt_xmlrpc_call_full_va(&env, ax, method, format, args); + va_end(args); + if (env.fault_occurred) abrt_xmlrpc_die(&env);
diff --git a/src/lib/abrt_xmlrpc.h b/src/lib/abrt_xmlrpc.h index 5c94360..1e1070c 100644 --- a/src/lib/abrt_xmlrpc.h +++ b/src/lib/abrt_xmlrpc.h @@ -44,6 +44,9 @@ void abrt_xmlrpc_error(xmlrpc_env *env); xmlrpc_value *abrt_xmlrpc_call(struct abrt_xmlrpc *ax, const char *method, const char *format, ...);
+xmlrpc_value *abrt_xmlrpc_call_full(xmlrpc_env *enf, struct abrt_xmlrpc *ax, + const char *method, const char *format, ...); + #ifdef __cplusplus } #endif diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c index 0c321ea..03a6721 100644 --- a/src/plugins/reporter-bugzilla.c +++ b/src/plugins/reporter-bugzilla.c @@ -716,7 +716,7 @@ char *ask_bz_login(const char *message) { char *login = ask(message); if (login == NULL || login[0] == '\0') - error_msg_and_die(_("Exiting due to not provided login")); + error_msg_and_die(_("Exiting because of empty login"));
return login; } @@ -726,12 +726,26 @@ char *ask_bz_password(const char *message) { char *password = ask_password(message); if (password == NULL || password[0] == '\0') - error_msg_and_die(_("Exiting due to not provided password")); + error_msg_and_die(_("Exiting because of empty password"));
return password; }
static +void login(struct abrt_xmlrpc *client, struct bugzilla_struct *rhbz) +{ + log(_("Logging into Bugzilla at %s"), rhbz->b_bugzilla_url); + while (!rhbz_login(client, rhbz->b_login, rhbz->b_password)) + { + free(rhbz->b_login); + rhbz->b_login = ask_bz_login(_("Invalid password or login. Please provide Bugzilla login:")); + + free(rhbz->b_password); + rhbz->b_password = ask_bz_password(_("Invalid password or login. Please provide Bugzilla password:")); + } +} + +static xmlrpc_value *rhbz_search_duphash(struct abrt_xmlrpc *ax, const char *product, const char *version, @@ -960,8 +974,7 @@ int main(int argc, char **argv) log(_("Using Bugzilla ID '%s'"), ticket_no); }
- log(_("Logging into Bugzilla at %s"), rhbz.b_bugzilla_url); - rhbz_login(client, rhbz.b_login, rhbz.b_password); + login(client, &rhbz);
if (opts & OPT_w) rhbz_mail_to_cc(client, xatoi_positive(ticket_no), rhbz.b_login, /* require mail notify */ 0); @@ -1057,8 +1070,7 @@ int main(int argc, char **argv) exit(0); }
- log(_("Logging into Bugzilla at %s"), rhbz.b_bugzilla_url); - rhbz_login(client, rhbz.b_login, rhbz.b_password); + login(client, &rhbz);
char *product = NULL; char *version = NULL; diff --git a/src/plugins/rhbz.c b/src/plugins/rhbz.c index ae061f3..33fafa4 100644 --- a/src/plugins/rhbz.c +++ b/src/plugins/rhbz.c @@ -174,12 +174,23 @@ static unsigned find_best_bt_rating_in_comments(GList *comments) return best_bt_rating; }
-void rhbz_login(struct abrt_xmlrpc *ax, const char *login, const char *password) +bool rhbz_login(struct abrt_xmlrpc *ax, const char *login, const char *password) { func_entry();
- xmlrpc_value* result = abrt_xmlrpc_call(ax, "User.login", "({s:s,s:s})", - "login", login, "password", password); + xmlrpc_env env; + xmlrpc_value *result = abrt_xmlrpc_call_full(&env, ax, "User.login", "({s:s,s:s})", + "login", login, "password", password); + + if (env.fault_occurred) + { + /* 300 (Invalid Username or Password) - https://wiki.mozilla.org/Bugzilla:WebServices:Errors */ + if (env.fault_code != 300) + abrt_xmlrpc_die(&env); + + VERB1 log("xmlrpc fault: (%d) %s", env.fault_code, env.fault_string); + return false; + }
//TODO: with URL like http://bugzilla.redhat.com (that is, with http: instead of https:) //we are getting this error: @@ -187,6 +198,7 @@ void rhbz_login(struct abrt_xmlrpc *ax, const char *login, const char *password) //Can't login. Server said: HTTP response code is 301, not 200 //But this is a 301 redirect! We _can_ follow it if we configure curl to understand that! xmlrpc_DECREF(result); + return true; }
xmlrpc_value *rhbz_get_member(const char *member, xmlrpc_value *xml) diff --git a/src/plugins/rhbz.h b/src/plugins/rhbz.h index d919056..a6f7204 100644 --- a/src/plugins/rhbz.h +++ b/src/plugins/rhbz.h @@ -65,7 +65,7 @@ struct bug_info { struct bug_info *new_bug_info(); void free_bug_info(struct bug_info *bz);
-void rhbz_login(struct abrt_xmlrpc *ax, const char *login, const char *password); +bool rhbz_login(struct abrt_xmlrpc *ax, const char *login, const char *password);
void rhbz_mail_to_cc(struct abrt_xmlrpc *ax, int bug_id, const char *mail, int flags);
On 12/06/2012 09:26 AM, Jakub Filak wrote:
- closes rhbz#861899
Signed-off-by: Jakub Filak jfilak@redhat.com
src/lib/abrt_xmlrpc.c | 52 ++++++++++++++++++++++++++++++----------- src/lib/abrt_xmlrpc.h | 3 +++ src/plugins/reporter-bugzilla.c | 24 ++++++++++++++----- src/plugins/rhbz.c | 18 +++++++++++--- src/plugins/rhbz.h | 2 +- 5 files changed, 75 insertions(+), 24 deletions(-)
diff --git a/src/lib/abrt_xmlrpc.c b/src/lib/abrt_xmlrpc.c index 74e473e..75dff14 100644 --- a/src/lib/abrt_xmlrpc.c +++ b/src/lib/abrt_xmlrpc.c @@ -108,37 +108,61 @@ void abrt_xmlrpc_free_client(struct abrt_xmlrpc *ax) free(ax); }
-/* die or return expected results */ -xmlrpc_value *abrt_xmlrpc_call(struct abrt_xmlrpc *ax,
const char* method, const char* format, ...)
+/* internall helper function */ +static +xmlrpc_value *abrt_xmlrpc_call_full_va(xmlrpc_env *env, struct abrt_xmlrpc *ax,
const char *method, const char *format,
{va_list args)
- xmlrpc_env env;
- xmlrpc_env_init(&env);
xmlrpc_env_init(env);
xmlrpc_value* param = NULL; const char* suffix;
va_list args;
va_start(args, format);
xmlrpc_build_value_va(&env, format, args, ¶m, &suffix);
va_end(args);
if (env.fault_occurred)
abrt_xmlrpc_die(&env);
- xmlrpc_build_value_va(env, format, args, ¶m, &suffix);
- if (env->fault_occurred)
abrt_xmlrpc_die(env);
- xmlrpc_value* result = NULL;
- xmlrpc_value *result = NULL; if (*suffix != '\0') { xmlrpc_env_set_fault_formatted(
&env, XMLRPC_INTERNAL_ERROR, "Junk after the argument "
env, XMLRPC_INTERNAL_ERROR, "Junk after the argument " "specifier: '%s'. There must be exactly one argument.", suffix); } else {
xmlrpc_client_call2(&env, ax->ax_client, ax->ax_server_info, method,
xmlrpc_client_call2(env, ax->ax_client, ax->ax_server_info, method, param, &result); } xmlrpc_DECREF(param);
- return result;
+}
+xmlrpc_value *abrt_xmlrpc_call_full(xmlrpc_env *env, struct abrt_xmlrpc *ax,
const char *method, const char *format, ...)
+{
- va_list args;
- va_start(args, format);
- xmlrpc_value *result = abrt_xmlrpc_call_full_va(env, ax, method, format, args);
- va_end(args);
- return result;
+}
+/* die or return expected results */ +xmlrpc_value *abrt_xmlrpc_call(struct abrt_xmlrpc *ax,
const char *method, const char *format, ...)
+{
- xmlrpc_env env;
- va_list args;
- va_start(args, format);
- xmlrpc_value *result = abrt_xmlrpc_call_full_va(&env, ax, method, format, args);
- va_end(args);
if (env.fault_occurred) abrt_xmlrpc_die(&env);
diff --git a/src/lib/abrt_xmlrpc.h b/src/lib/abrt_xmlrpc.h index 5c94360..1e1070c 100644 --- a/src/lib/abrt_xmlrpc.h +++ b/src/lib/abrt_xmlrpc.h @@ -44,6 +44,9 @@ void abrt_xmlrpc_error(xmlrpc_env *env); xmlrpc_value *abrt_xmlrpc_call(struct abrt_xmlrpc *ax, const char *method, const char *format, ...);
+xmlrpc_value *abrt_xmlrpc_call_full(xmlrpc_env *enf, struct abrt_xmlrpc *ax,
const char *method, const char *format, ...);
- #ifdef __cplusplus } #endif
diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c index 0c321ea..03a6721 100644 --- a/src/plugins/reporter-bugzilla.c +++ b/src/plugins/reporter-bugzilla.c @@ -716,7 +716,7 @@ char *ask_bz_login(const char *message) { char *login = ask(message); if (login == NULL || login[0] == '\0')
error_msg_and_die(_("Exiting due to not provided login"));
error_msg_and_die(_("Exiting because of empty login")); return login;
}
@@ -726,12 +726,26 @@ char *ask_bz_password(const char *message) { char *password = ask_password(message); if (password == NULL || password[0] == '\0')
error_msg_and_die(_("Exiting due to not provided password"));
error_msg_and_die(_("Exiting because of empty password"));
- how about _("Can't continue without password")
return password;
}
static +void login(struct abrt_xmlrpc *client, struct bugzilla_struct *rhbz) +{
- log(_("Logging into Bugzilla at %s"), rhbz->b_bugzilla_url);
- while (!rhbz_login(client, rhbz->b_login, rhbz->b_password))
- {
free(rhbz->b_login);
rhbz->b_login = ask_bz_login(_("Invalid password or login. Please provide Bugzilla login:"));
free(rhbz->b_password);
rhbz->b_password = ask_bz_password(_("Invalid password or login. Please provide Bugzilla password:"));
- ...Please provide password for '%s'"), rhbz.b_login - so users actually can see what he entered as the login name
- }
+}
+static xmlrpc_value *rhbz_search_duphash(struct abrt_xmlrpc *ax, const char *product, const char *version, @@ -960,8 +974,7 @@ int main(int argc, char **argv) log(_("Using Bugzilla ID '%s'"), ticket_no); }
log(_("Logging into Bugzilla at %s"), rhbz.b_bugzilla_url);
rhbz_login(client, rhbz.b_login, rhbz.b_password);
login(client, &rhbz); if (opts & OPT_w) rhbz_mail_to_cc(client, xatoi_positive(ticket_no), rhbz.b_login, /* require mail notify */ 0);
@@ -1057,8 +1070,7 @@ int main(int argc, char **argv) exit(0); }
- log(_("Logging into Bugzilla at %s"), rhbz.b_bugzilla_url);
- rhbz_login(client, rhbz.b_login, rhbz.b_password);
login(client, &rhbz);
char *product = NULL; char *version = NULL;
diff --git a/src/plugins/rhbz.c b/src/plugins/rhbz.c index ae061f3..33fafa4 100644 --- a/src/plugins/rhbz.c +++ b/src/plugins/rhbz.c @@ -174,12 +174,23 @@ static unsigned find_best_bt_rating_in_comments(GList *comments) return best_bt_rating; }
-void rhbz_login(struct abrt_xmlrpc *ax, const char *login, const char *password) +bool rhbz_login(struct abrt_xmlrpc *ax, const char *login, const char *password) { func_entry();
- xmlrpc_value* result = abrt_xmlrpc_call(ax, "User.login", "({s:s,s:s})",
"login", login, "password", password);
xmlrpc_env env;
xmlrpc_value *result = abrt_xmlrpc_call_full(&env, ax, "User.login", "({s:s,s:s})",
"login", login, "password", password);
if (env.fault_occurred)
{
/* 300 (Invalid Username or Password) - https://wiki.mozilla.org/Bugzilla:WebServices:Errors */
if (env.fault_code != 300)
abrt_xmlrpc_die(&env);
VERB1 log("xmlrpc fault: (%d) %s", env.fault_code, env.fault_string);
return false;
}
//TODO: with URL like http://bugzilla.redhat.com (that is, with http: instead of https:) //we are getting this error:
@@ -187,6 +198,7 @@ void rhbz_login(struct abrt_xmlrpc *ax, const char *login, const char *password) //Can't login. Server said: HTTP response code is 301, not 200 //But this is a 301 redirect! We _can_ follow it if we configure curl to understand that! xmlrpc_DECREF(result);
return true; }
xmlrpc_value *rhbz_get_member(const char *member, xmlrpc_value *xml)
diff --git a/src/plugins/rhbz.h b/src/plugins/rhbz.h index d919056..a6f7204 100644 --- a/src/plugins/rhbz.h +++ b/src/plugins/rhbz.h @@ -65,7 +65,7 @@ struct bug_info { struct bug_info *new_bug_info(); void free_bug_info(struct bug_info *bz);
-void rhbz_login(struct abrt_xmlrpc *ax, const char *login, const char *password); +bool rhbz_login(struct abrt_xmlrpc *ax, const char *login, const char *password);
void rhbz_mail_to_cc(struct abrt_xmlrpc *ax, int bug_id, const char *mail, int flags);
- the rest seems ok
crash-catcher@lists.fedorahosted.org