Skip to content

Commit 979b563

Browse files
AdityaGarg8gitster
authored andcommitted
imap-send: gracefully fail if CRAM-MD5 authentication is requested without OpenSSL
Unlike PLAIN, XOAUTH2 and OAUTHBEARER, CRAM-MD5 authentication is not supported by libcurl and requires OpenSSL. If the user tries to use CRAM-MD5 authentication without OpenSSL, the previous behaviour was to attempt to authenticate and fail with a die(error). Handle this in a better way by first checking if OpenSSL is available and then attempting to authenticate. If OpenSSL is not available, print an error message and exit gracefully. Signed-off-by: Aditya Garg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3eb83e8 commit 979b563

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

imap-send.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,24 @@ static int auth_plain(struct imap_store *ctx, const char *prompt UNUSED)
10081008
return 0;
10091009
}
10101010

1011+
static int auth_cram_md5(struct imap_store *ctx, const char *prompt)
1012+
{
1013+
int ret;
1014+
char *response;
1015+
1016+
response = cram(prompt, ctx->cfg->user, ctx->cfg->pass);
1017+
1018+
ret = socket_write(&ctx->imap->buf.sock, response, strlen(response));
1019+
if (ret != strlen(response)) {
1020+
free(response);
1021+
return error("IMAP error: sending response failed");
1022+
}
1023+
1024+
free(response);
1025+
1026+
return 0;
1027+
}
1028+
10111029
static int auth_oauthbearer(struct imap_store *ctx, const char *prompt UNUSED)
10121030
{
10131031
int ret;
@@ -1050,38 +1068,13 @@ static int auth_xoauth2(struct imap_store *ctx, const char *prompt UNUSED)
10501068

10511069
#else
10521070

1053-
static char *cram(const char *challenge_64 UNUSED,
1054-
const char *user UNUSED,
1055-
const char *pass UNUSED)
1056-
{
1057-
die("If you want to use CRAM-MD5 authenticate method, "
1058-
"you have to build git-imap-send with OpenSSL library.");
1059-
}
1060-
10611071
#define auth_plain NULL
1072+
#define auth_cram_md5 NULL
10621073
#define auth_oauthbearer NULL
10631074
#define auth_xoauth2 NULL
10641075

10651076
#endif
10661077

1067-
static int auth_cram_md5(struct imap_store *ctx, const char *prompt)
1068-
{
1069-
int ret;
1070-
char *response;
1071-
1072-
response = cram(prompt, ctx->cfg->user, ctx->cfg->pass);
1073-
1074-
ret = socket_write(&ctx->imap->buf.sock, response, strlen(response));
1075-
if (ret != strlen(response)) {
1076-
free(response);
1077-
return error("IMAP error: sending response failed");
1078-
}
1079-
1080-
free(response);
1081-
1082-
return 0;
1083-
}
1084-
10851078
static void server_fill_credential(struct imap_server_conf *srvc, struct credential *cred)
10861079
{
10871080
if (srvc->user && srvc->pass)
@@ -1287,6 +1280,13 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c
12871280
"but %s doesn't support it.\n", srvc->host);
12881281
goto bail;
12891282
}
1283+
1284+
#ifdef NO_OPENSSL
1285+
fprintf(stderr, "If you want to use CRAM-MD5 authentication mechanism, "
1286+
"you have to build git-imap-send with OpenSSL library.");
1287+
goto bail;
1288+
#endif
1289+
12901290
/* CRAM-MD5 */
12911291

12921292
memset(&cb, 0, sizeof(cb));

0 commit comments

Comments
 (0)