1 /* $Cambridge: exim/src/src/tls.c,v 1.4 2007/01/08 10:50:18 ph10 Exp $ */
3 /*************************************************
4 * Exim - an Internet mail transport agent *
5 *************************************************/
7 /* Copyright (c) University of Cambridge 1995 - 2007 */
8 /* See the file NOTICE for conditions of use and distribution. */
10 /* This module provides TLS (aka SSL) support for Exim. The code for OpenSSL is
11 based on a patch that was originally contributed by Steve Haslam. It was
12 adapted from stunnel, a GPL program by Michal Trojnara. The code for GNU TLS is
13 based on a patch contributed by Nikos Mavroyanopoulos. Because these packages
14 are so very different, the functions for each are kept in separate files. The
15 relevant file is #included as required, after any any common functions.
17 No cryptographic code is included in Exim. All this module does is to call
18 functions from the OpenSSL or GNU TLS libraries. */
23 /* This module is compiled only when it is specifically requested in the
24 build-time configuration. However, some compilers don't like compiling empty
25 modules, so keep them happy with a dummy when skipping the rest. Make it
26 reference itself to stop picky compilers complaining that it is unused, and put
27 in a dummy argument to stop even pickier compilers complaining about infinite
31 static void dummy(int x) { dummy(x-1); }
34 /* Static variables that are used for buffering data by both sets of
35 functions and the common functions below. */
38 static uschar *ssl_xfer_buffer = NULL;
39 static int ssl_xfer_buffer_size = 4096;
40 static int ssl_xfer_buffer_lwm = 0;
41 static int ssl_xfer_buffer_hwm = 0;
42 static int ssl_xfer_eof = 0;
43 static int ssl_xfer_error = 0;
47 /*************************************************
48 * Expand string; give error on failure *
49 *************************************************/
51 /* If expansion is forced to fail, set the result NULL and return TRUE.
52 Other failures return FALSE. For a server, an SMTP response is given.
55 s the string to expand; if NULL just return TRUE
56 name name of string being expanded (for error)
57 result where to put the result
59 Returns: TRUE if OK; result may still be NULL after forced failure
63 expand_check(uschar *s, uschar *name, uschar **result)
65 if (s == NULL) *result = NULL; else
67 *result = expand_string(s);
68 if (*result == NULL && !expand_string_forcedfail)
70 log_write(0, LOG_MAIN|LOG_PANIC, "expansion of %s failed: %s", name,
71 expand_string_message);
79 /*************************************************
80 * Many functions are package-specific *
81 *************************************************/
86 #include "tls-openssl.c"
91 /*************************************************
92 * TLS version of ungetc *
93 *************************************************/
95 /* Puts a character back in the input buffer. Only ever
101 Returns: the character
107 ssl_xfer_buffer[--ssl_xfer_buffer_lwm] = ch;
113 /*************************************************
114 * TLS version of feof *
115 *************************************************/
117 /* Tests for a previous EOF
120 Returns: non-zero if the eof flag is set
131 /*************************************************
132 * TLS version of ferror *
133 *************************************************/
135 /* Tests for a previous read error, and returns with errno
136 restored to what it was when the error was detected.
138 >>>>> Hmm. Errno not handled yet. Where do we get it from? >>>>>
141 Returns: non-zero if the error flag is set
147 return ssl_xfer_error;
150 #endif /* SUPPORT_TLS */