git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Uses git-credential for git-imap-send
@ 2014-04-26 17:50 Dan Albert
  2014-04-26 18:08 ` Jeff King
  0 siblings, 1 reply; 8+ messages in thread
From: Dan Albert @ 2014-04-26 17:50 UTC (permalink / raw)
  To: git

git-imap-send was directly prompting for a password rather than using
git-credential. git-send-email, on the other hand, supports git-credential.

This is a necessary improvement for users that use two factor authentication, as
they should not be expected to remember all of their app specific passwords.
---
 imap-send.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/imap-send.c b/imap-send.c
index 0bc6f7f..262fb9a 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -23,9 +23,9 @@
  */

 #include "cache.h"
+#include "credential.h"
 #include "exec_cmd.h"
 #include "run-command.h"
-#include "prompt.h"
 #ifdef NO_OPENSSL
 typedef void *SSL;
 #endif
@@ -946,6 +946,7 @@ static int auth_cram_md5(struct imap_store *ctx,
struct imap_cmd *cmd, const cha

 static struct imap_store *imap_open_store(struct imap_server_conf *srvc)
 {
+ struct credential cred = CREDENTIAL_INIT;
  struct imap_store *ctx;
  struct imap *imap;
  char *arg, *rsp;
@@ -1101,19 +1102,11 @@ static struct imap_store
*imap_open_store(struct imap_server_conf *srvc)
  goto bail;
  }
  if (!srvc->pass) {
- struct strbuf prompt = STRBUF_INIT;
- strbuf_addf(&prompt, "Password (%s@%s): ", srvc->user, srvc->host);
- arg = git_getpass(prompt.buf);
- strbuf_release(&prompt);
- if (!*arg) {
- fprintf(stderr, "Skipping account %s@%s, no password\n", srvc->user,
srvc->host);
- goto bail;
- }
- /*
- * getpass() returns a pointer to a static buffer.  make a copy
- * for long term storage.
- */
- srvc->pass = xstrdup(arg);
+ cred.username = xstrdup(srvc->user);
+ cred.protocol = xstrdup("imap");
+ cred.host = xstrdup(srvc->host);
+ credential_fill(&cred);
+ srvc->pass = xstrdup(cred.password);
  }
  if (CAP(NOLOGIN)) {
  fprintf(stderr, "Skipping account %s@%s, server forbids LOGIN\n",
srvc->user, srvc->host);
@@ -1153,10 +1146,18 @@ static struct imap_store
*imap_open_store(struct imap_server_conf *srvc)
  }
  } /* !preauth */

+ if (cred.username)
+ credential_approve(&cred);
+ credential_clear(&cred);
+
  ctx->prefix = "";
  return ctx;

 bail:
+ if (cred.username)
+ credential_reject(&cred);
+ credential_clear(&cred);
+
  imap_close_store(ctx);
  return NULL;
 }
-- 
2.0.0.rc1.1.gce060f5

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-04-29 17:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-26 17:50 [PATCH] Uses git-credential for git-imap-send Dan Albert
2014-04-26 18:08 ` Jeff King
     [not found]   ` <CAFVaGhuXvZhRCHRFurKNOC4tsiQ7WZnGb2CbRnoSSYg=XknJtg@mail.gmail.com>
2014-04-27  7:51     ` Jeff King
2014-04-27 17:58   ` Dan Albert
2014-04-28 19:23     ` Jeff King
2014-04-29  3:00       ` Dan Albert
2014-04-29  3:05         ` Jeff King
2014-04-29 17:19           ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).