1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) University of Cambridge 1995 - 2012 */
6 /* See the file NOTICE for conditions of use and distribution. */
8 /* This module provides TLS (aka SSL) support for Exim. The code for OpenSSL is
9 based on a patch that was originally contributed by Steve Haslam. It was
10 adapted from stunnel, a GPL program by Michal Trojnara. The code for GNU TLS is
11 based on a patch contributed by Nikos Mavroyanopoulos. Because these packages
12 are so very different, the functions for each are kept in separate files. The
13 relevant file is #included as required, after any any common functions.
15 No cryptographic code is included in Exim. All this module does is to call
16 functions from the OpenSSL or GNU TLS libraries. */
21 /* This module is compiled only when it is specifically requested in the
22 build-time configuration. However, some compilers don't like compiling empty
23 modules, so keep them happy with a dummy when skipping the rest. Make it
24 reference itself to stop picky compilers complaining that it is unused, and put
25 in a dummy argument to stop even pickier compilers complaining about infinite
29 static void dummy(int x) { dummy(x-1); }
32 /* Static variables that are used for buffering data by both sets of
33 functions and the common functions below. */
36 static uschar *ssl_xfer_buffer = NULL;
37 static const int ssl_xfer_buffer_size = 4096;
38 static int ssl_xfer_buffer_lwm = 0;
39 static int ssl_xfer_buffer_hwm = 0;
40 static int ssl_xfer_eof = 0;
41 static int ssl_xfer_error = 0;
43 uschar *tls_channelbinding_b64 = NULL;
46 /*************************************************
47 * Expand string; give error on failure *
48 *************************************************/
50 /* If expansion is forced to fail, set the result NULL and return TRUE.
51 Other failures return FALSE. For a server, an SMTP response is given.
54 s the string to expand; if NULL just return TRUE
55 name name of string being expanded (for error)
56 result where to put the result
58 Returns: TRUE if OK; result may still be NULL after forced failure
62 expand_check(const uschar *s, const uschar *name, uschar **result)
64 if (s == NULL) *result = NULL; else
66 *result = expand_string(US s); /* need to clean up const some more */
67 if (*result == NULL && !expand_string_forcedfail)
69 log_write(0, LOG_MAIN|LOG_PANIC, "expansion of %s failed: %s", name,
70 expand_string_message);
78 /*************************************************
79 * Many functions are package-specific *
80 *************************************************/
85 #include "tls-openssl.c"
90 /*************************************************
91 * TLS version of ungetc *
92 *************************************************/
94 /* Puts a character back in the input buffer. Only ever
100 Returns: the character
106 ssl_xfer_buffer[--ssl_xfer_buffer_lwm] = ch;
112 /*************************************************
113 * TLS version of feof *
114 *************************************************/
116 /* Tests for a previous EOF
119 Returns: non-zero if the eof flag is set
130 /*************************************************
131 * TLS version of ferror *
132 *************************************************/
134 /* Tests for a previous read error, and returns with errno
135 restored to what it was when the error was detected.
137 >>>>> Hmm. Errno not handled yet. Where do we get it from? >>>>>
140 Returns: non-zero if the error flag is set
146 return ssl_xfer_error;
150 /*************************************************
151 * TLS version of smtp_buffered *
152 *************************************************/
154 /* Tests for unused chars in the TLS input buffer.
161 tls_smtp_buffered(void)
163 return ssl_xfer_buffer_lwm < ssl_xfer_buffer_hwm;
167 #endif /* SUPPORT_TLS */