|
23 | 23 | */
|
24 | 24 |
|
25 | 25 | #include "cache.h"
|
| 26 | +#include "credential.h" |
26 | 27 | #include "exec_cmd.h"
|
27 | 28 | #include "run-command.h"
|
28 |
| -#include "prompt.h" |
29 | 29 | #ifdef NO_OPENSSL
|
30 | 30 | typedef void *SSL;
|
31 | 31 | #endif
|
@@ -946,6 +946,7 @@ static int auth_cram_md5(struct imap_store *ctx, struct imap_cmd *cmd, const cha
|
946 | 946 |
|
947 | 947 | static struct imap_store *imap_open_store(struct imap_server_conf *srvc)
|
948 | 948 | {
|
| 949 | + struct credential cred = CREDENTIAL_INIT; |
949 | 950 | struct imap_store *ctx;
|
950 | 951 | struct imap *imap;
|
951 | 952 | char *arg, *rsp;
|
@@ -1096,25 +1097,23 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc)
|
1096 | 1097 | }
|
1097 | 1098 | #endif
|
1098 | 1099 | 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); |
1117 | 1115 | }
|
| 1116 | + |
1118 | 1117 | if (CAP(NOLOGIN)) {
|
1119 | 1118 | fprintf(stderr, "Skipping account %s@%s, server forbids LOGIN\n", srvc->user, srvc->host);
|
1120 | 1119 | goto bail;
|
@@ -1153,10 +1152,18 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc)
|
1153 | 1152 | }
|
1154 | 1153 | } /* !preauth */
|
1155 | 1154 |
|
| 1155 | + if (cred.username) |
| 1156 | + credential_approve(&cred); |
| 1157 | + credential_clear(&cred); |
| 1158 | + |
1156 | 1159 | ctx->prefix = "";
|
1157 | 1160 | return ctx;
|
1158 | 1161 |
|
1159 | 1162 | bail:
|
| 1163 | + if (cred.username) |
| 1164 | + credential_reject(&cred); |
| 1165 | + credential_clear(&cred); |
| 1166 | + |
1160 | 1167 | imap_close_store(ctx);
|
1161 | 1168 | return NULL;
|
1162 | 1169 | }
|
|
0 commit comments