]> diplodocus.org Git - nmh/blobdiff - uip/mhlogin.c
lock_file.c: close(2) file descriptor on failure, avoiding leak.
[nmh] / uip / mhlogin.c
index 4a42aea275ab07832326f0190e3c00024d8af883..e78ae68f263991a9d7faff77ac52be5ef33df461 100644 (file)
@@ -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
@@ -13,6 +12,7 @@
 #include <h/mh.h>
 #include <h/utils.h>
 #include <h/oauth.h>
+#include "sbr/lock_file.h"
 
 #define MHLOGIN_SWITCHES \
     X("user username", 0, USERSW) \
@@ -64,7 +64,7 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
     }
 
     if (!mh_oauth_new(&ctx, svc)) {
-        adios(NULL, mh_oauth_get_err_string(ctx));
+        adios(NULL, "%s", mh_oauth_get_err_string(ctx));
     }
 
     if (snoop) {
@@ -74,7 +74,7 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
     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));
+      adios(NULL, "%s", mh_oauth_get_err_string(ctx));
     }
 
     if (browser) {
@@ -109,8 +109,8 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
       code = geta();
     }
     if (cred == NULL) {
-      advise(NULL, "error exchanging code for OAuth2 token");
-      adios(NULL, mh_oauth_get_err_string(ctx));
+      inform("error exchanging code for OAuth2 token");
+      adios(NULL, "%s", mh_oauth_get_err_string(ctx));
     }
 
     cred_file = lkfopendata(fn, "r+", &failed_to_lock);
@@ -121,7 +121,7 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
       adios(fn, "oops");
     }
     if (!mh_oauth_cred_save(cred_file, cred, user)) {
-      adios(NULL, mh_oauth_get_err_string(ctx));
+      adios(NULL, "%s", mh_oauth_get_err_string(ctx));
     }
     if (lkfclosedata(cred_file, fn) != 0) {
       adios (fn, "oops");