X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/29ff4f879ba9eea142df4e8caf436d0dd933218c..29db9a64a:/uip/mhlogin.c?ds=sidebyside diff --git a/uip/mhlogin.c b/uip/mhlogin.c index 88912b5c..1cc1c23c 100644 --- a/uip/mhlogin.c +++ b/uip/mhlogin.c @@ -1,5 +1,4 @@ -/* - * mhlogin.c -- login to external (OAuth) services +/* mhlogin.c -- login to external (OAuth) services * * This code is Copyright (c) 2014, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -11,7 +10,9 @@ #include #include +#include #include +#include "../sbr/lock_file.h" #define MHLOGIN_SWITCHES \ X("user username", 0, USERSW) \ @@ -35,13 +36,12 @@ DEFINE_SWITCH_ARRAY(MHLOGIN, switches); static char * geta (void) { - char *cp; static char line[BUFSIZ]; if (fgets(line, sizeof(line), stdin) == NULL) done (1); - if ((cp = strchr(line, '\n'))) - *cp = 0; + trim_suffix_c(line, '\n'); + return line; } @@ -71,7 +71,7 @@ do_login(const char *svc, const char *user, const char *browser, int snoop) mh_oauth_log_to(stderr, ctx); } - fn = getcpy(mh_oauth_cred_fn(ctx)); + fn = mh_xstrdup(mh_oauth_cred_fn(svc)); if ((url = mh_oauth_get_authorize_url(ctx)) == NULL) { adios(NULL, mh_oauth_get_err_string(ctx)); @@ -101,14 +101,15 @@ do_login(const char *svc, const char *user, const char *browser, int snoop) fflush(stdout); code = geta(); - while ((cred = mh_oauth_authorize(code, ctx)) == NULL - && mh_oauth_get_err_code(ctx) == MH_OAUTH_BAD_GRANT) { - printf("Code rejected; try again? "); + while (!*code || + ((cred = mh_oauth_authorize(code, ctx)) == NULL + && mh_oauth_get_err_code(ctx) == MH_OAUTH_BAD_GRANT)) { + printf(!*code ? "Empty code; try again? " : "Code rejected; try again? "); fflush(stdout); code = geta(); } if (cred == NULL) { - advise(NULL, "error exchanging code for OAuth2 token"); + inform("error exchanging code for OAuth2 token"); adios(NULL, mh_oauth_get_err_string(ctx)); }