7d974ab260b82bf19b15dc8d22491b0390ae710e
[exim.git] / src / src / auths / get_data.c
1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
4
5 /* Copyright (c) University of Cambridge 1995 - 2018 */
6 /* See the file NOTICE for conditions of use and distribution. */
7
8 #include "../exim.h"
9
10
11 /*************************************************
12 * Issue a challenge and get a response *
13 *************************************************/
14
15 /* This function is used by authentication drivers to output a challenge
16 to the SMTP client and read the response line.
17
18 Arguments:
19 aptr set to point to the response (which is in big_buffer)
20 challenge the challenge text (unencoded, may be binary)
21 challen the length of the challenge text
22
23 Returns: OK on success
24 BAD64 if response too large for buffer
25 CANCELLED if response is "*"
26 */
27
28 int
29 auth_get_data(uschar **aptr, uschar *challenge, int challen)
30 {
31 int c;
32 int p = 0;
33 smtp_printf("334 %s\r\n", FALSE, b64encode(challenge, challen));
34 while ((c = receive_getc(GETC_BUFFER_UNLIMITED)) != '\n' && c != EOF)
35 {
36 if (p >= big_buffer_size - 1) return BAD64;
37 big_buffer[p++] = c;
38 }
39 if (p > 0 && big_buffer[p-1] == '\r') p--;
40 big_buffer[p] = 0;
41 DEBUG(D_receive) debug_printf("SMTP<< %s\n", big_buffer);
42 if (Ustrcmp(big_buffer, "*") == 0) return CANCELLED;
43 *aptr = big_buffer;
44 return OK;
45 }
46
47 /* End of get_data.c */