Skip to content

Commit 89080fc

Browse files
committed
Merge branch 'da/imap-send-use-credential-helper'
"git imap-send" learns to ask the credential helper for authentication material. * da/imap-send-use-credential-helper: imap-send: use git-credential
2 parents db6fbe3 + 791643a commit 89080fc

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

imap-send.c

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424

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

947947
static struct imap_store *imap_open_store(struct imap_server_conf *srvc)
948948
{
949+
struct credential cred = CREDENTIAL_INIT;
949950
struct imap_store *ctx;
950951
struct imap *imap;
951952
char *arg, *rsp;
@@ -1096,25 +1097,23 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc)
10961097
}
10971098
#endif
10981099
imap_info("Logging in...\n");
1099-
if (!srvc->user) {
1100-
fprintf(stderr, "Skipping server %s, no user\n", srvc->host);
1101-
goto bail;
1102-
}
1103-
if (!srvc->pass) {
1104-
struct strbuf prompt = STRBUF_INIT;
1105-
strbuf_addf(&prompt, "Password (%s@%s): ", srvc->user, srvc->host);
1106-
arg = git_getpass(prompt.buf);
1107-
strbuf_release(&prompt);
1108-
if (!*arg) {
1109-
fprintf(stderr, "Skipping account %s@%s, no password\n", srvc->user, srvc->host);
1110-
goto bail;
1111-
}
1112-
/*
1113-
* getpass() returns a pointer to a static buffer. make a copy
1114-
* for long term storage.
1115-
*/
1116-
srvc->pass = xstrdup(arg);
1100+
if (!srvc->user || !srvc->pass) {
1101+
cred.protocol = xstrdup(srvc->use_ssl ? "imaps" : "imap");
1102+
cred.host = xstrdup(srvc->host);
1103+
1104+
if (srvc->user)
1105+
cred.username = xstrdup(srvc->user);
1106+
if (srvc->pass)
1107+
cred.password = xstrdup(srvc->pass);
1108+
1109+
credential_fill(&cred);
1110+
1111+
if (!srvc->user)
1112+
srvc->user = xstrdup(cred.username);
1113+
if (!srvc->pass)
1114+
srvc->pass = xstrdup(cred.password);
11171115
}
1116+
11181117
if (CAP(NOLOGIN)) {
11191118
fprintf(stderr, "Skipping account %s@%s, server forbids LOGIN\n", srvc->user, srvc->host);
11201119
goto bail;
@@ -1153,10 +1152,18 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc)
11531152
}
11541153
} /* !preauth */
11551154

1155+
if (cred.username)
1156+
credential_approve(&cred);
1157+
credential_clear(&cred);
1158+
11561159
ctx->prefix = "";
11571160
return ctx;
11581161

11591162
bail:
1163+
if (cred.username)
1164+
credential_reject(&cred);
1165+
credential_clear(&cred);
1166+
11601167
imap_close_store(ctx);
11611168
return NULL;
11621169
}

0 commit comments

Comments
 (0)