1 The initial version of this patch was originally posted David Woodhouse, and
2 dman gets the credit for first integrating it with SA-Exim.
4 I have since then maintained it by first making a few minor changes, and
5 later switching it to a major/minor number scheme to support upgrades in
6 the exim API that don't affect backward compatibility (you can rely on
7 a feature denoted by the minor number and be compatible with future versions
8 of exim until Philip has to break the API and increase the major number)
10 Marc MERLIN <marc_soft@merlins.org>
12 diff -urN exim-4.14-0/src/EDITME exim-4.14-1/src/EDITME
13 --- exim-4.14-0/src/EDITME Tue Mar 11 04:20:18 2003
14 +++ exim-4.14-1/src/EDITME Sun Mar 23 15:34:15 2003
18 #------------------------------------------------------------------------------
19 +# On systems which support dynamic loading of shared libraries, Exim can
20 +# load a local_scan function specified in its config file instead of having
21 +# to be recompiled with the desired local_scan function. For a full
22 +# description of the API to this function, see the Exim specification.
24 +DLOPEN_LOCAL_SCAN=yes
26 +# If you set DLOPEN_LOCAL_SCAN, then you need to include -rdynamic in the
27 +# linker flags. Without it, the loaded .so won't be able to access any
28 +# functions from exim.
30 +LFLAGS=-rdynamic -ldl
32 +#------------------------------------------------------------------------------
33 # The default distribution of Exim contains only the plain text form of the
34 # documentation. Other forms are available separately. If you want to install
35 # the documentation in "info" format, first fetch the Texinfo documentation
36 diff -urNad 50_localscan_dlopen.tmp/src/config.h.defaults 50_localscan_dlopen/src/config.h.defaults
37 --- 50_localscan_dlopen.tmp/src/config.h.defaults Sun Dec 29 11:55:42 2002
38 +++ 50_localscan_dlopen/src/config.h.defaults Sun Dec 29 11:56:44 2002
40 #define AUTH_PLAINTEXT
43 +#define DLOPEN_LOCAL_SCAN
47 #define CONFIGURE_FILE
48 diff -urN exim-4.14-0/src/globals.c exim-4.14-1/src/globals.c
49 --- exim-4.14-0/src/globals.c Tue Mar 11 04:20:20 2003
50 +++ exim-4.14-1/src/globals.c Sun Mar 23 15:34:15 2003
52 uschar *tls_verify_hosts = NULL;
55 +#ifdef DLOPEN_LOCAL_SCAN
56 +uschar *local_scan_path = NULL;
59 /* Input-reading functions for messages, so we can use special ones for
60 incoming TCP/IP. The defaults use stdin. We never need these for any
61 diff -urN exim-4.14-0/src/globals.h exim-4.14-1/src/globals.h
62 --- exim-4.14-0/src/globals.h Tue Mar 11 04:20:20 2003
63 +++ exim-4.14-1/src/globals.h Sun Mar 23 15:34:15 2003
65 extern uschar *tls_verify_hosts; /* Mandatory client verification */
68 +#ifdef DLOPEN_LOCAL_SCAN
69 +extern uschar *local_scan_path; /* Path to local_scan() library */
72 /* Input-reading functions for messages, so we can use special ones for
74 diff -urN exim-4.14-0/src/local_scan.c exim-4.14-1/src/local_scan.c
75 --- exim-4.14-0/src/local_scan.c Tue Mar 11 04:20:20 2003
76 +++ exim-4.14-1/src/local_scan.c Sun Mar 23 15:34:15 2003
78 /* Copyright (c) University of Cambridge 1995 - 2003 */
79 /* See the file NOTICE for conditions of use and distribution. */
83 -/******************************************************************************
84 -This file contains a template local_scan() function that just returns ACCEPT.
85 -If you want to implement your own version, you should copy this file to, say
86 -Local/local_scan.c, and edit the copy. To use your version instead of the
87 -default, you must set
90 -LOCAL_SCAN_SOURCE=Local/local_scan.c
92 -in your Local/Makefile. This makes it easy to copy your version for use with
93 -subsequent Exim releases.
95 -For a full description of the API to this function, see the Exim specification.
96 -******************************************************************************/
99 -/* This is the only Exim header that you should include. The effect of
100 -including any other Exim header is not defined, and may change from release to
101 -release. Use only the documented interface! */
103 -#include "local_scan.h"
106 -/* This is a "do-nothing" version of a local_scan() function. The arguments
109 - fd The file descriptor of the open -D file, which contains the
110 - body of the message. The file is open for reading and
111 - writing, but modifying it is dangerous and not recommended.
113 - return_text A pointer to an unsigned char* variable which you can set in
114 - order to return a text string. It is initialized to NULL.
116 -The return values of this function are:
119 - The message is to be accepted. The return_text argument is
120 - saved in $local_scan_data.
123 - The message is to be rejected. The returned text is used
124 - in the rejection message.
126 - LOCAL_SCAN_TEMPREJECT
127 - This specifies a temporary rejection. The returned text
128 - is used in the rejection message.
130 +#ifdef DLOPEN_LOCAL_SCAN
132 +static int (*local_scan_fn)(int fd, uschar **return_text) = NULL;
133 +static int load_local_scan_library(void);
137 local_scan(int fd, uschar **return_text)
139 fd = fd; /* Keep picky compilers happy */
140 return_text = return_text;
141 -return LOCAL_SCAN_ACCEPT;
142 +#ifdef DLOPEN_LOCAL_SCAN
143 +/* local_scan_path is defined AND not the empty string */
144 +if (local_scan_path && *local_scan_path)
146 + if (!local_scan_fn)
148 + if (!load_local_scan_library())
150 + char *base_msg , *error_msg , *final_msg ;
151 + int final_length = -1 ;
153 + base_msg=US"Local configuration error - local_scan() library failure\n";
154 + error_msg = dlerror() ;
156 + final_length = strlen(base_msg) + strlen(error_msg) + 1 ;
157 + final_msg = (char*)malloc( final_length*sizeof(char) ) ;
158 + *final_msg = '\0' ;
160 + strcat( final_msg , base_msg ) ;
161 + strcat( final_msg , error_msg ) ;
163 + *return_text = final_msg ;
164 + return LOCAL_SCAN_TEMPREJECT;
167 + return local_scan_fn(fd, return_text);
171 + return LOCAL_SCAN_ACCEPT;
174 +#ifdef DLOPEN_LOCAL_SCAN
176 +static int load_local_scan_library(void)
178 +/* No point in keeping local_scan_lib since we'll never dlclose() anyway */
179 +void *local_scan_lib = NULL;
180 +int (*local_scan_version_fn)(void);
184 +local_scan_lib = dlopen(local_scan_path, RTLD_NOW);
185 +if (!local_scan_lib)
187 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library open failed - "
188 + "message temporarily rejected");
192 +local_scan_version_fn = dlsym(local_scan_lib, "local_scan_version_major");
193 +if (!local_scan_version_fn)
195 + dlclose(local_scan_lib);
196 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
197 + "local_scan_version_major() function - message temporarily rejected");
201 +/* The major number is increased when the ABI is changed in a non
202 + backward compatible way. */
203 +vers_maj = local_scan_version_fn();
205 +local_scan_version_fn = dlsym(local_scan_lib, "local_scan_version_minor");
206 +if (!local_scan_version_fn)
208 + dlclose(local_scan_lib);
209 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
210 + "local_scan_version_minor() function - message temporarily rejected");
214 +/* The minor number is increased each time a new feature is added (in a
215 + way that doesn't break backward compatibility) -- Marc */
216 +vers_min = local_scan_version_fn();
219 +if (vers_maj != LOCAL_SCAN_ABI_VERSION_MAJOR)
221 + dlclose(local_scan_lib);
222 + local_scan_lib = NULL;
223 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() has an incompatible major"
224 + "version number, you need to recompile your module for this version"
225 + "of exim (The module was compiled for version %d.%d and this exim provides"
226 + "ABI version %d.%d)", vers_maj, vers_min, LOCAL_SCAN_ABI_VERSION_MAJOR,
227 + LOCAL_SCAN_ABI_VERSION_MINOR);
230 +else if (vers_min > LOCAL_SCAN_ABI_VERSION_MINOR)
232 + dlclose(local_scan_lib);
233 + local_scan_lib = NULL;
234 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() has an incompatible minor"
235 + "version number, you need to recompile your module for this version"
236 + "of exim (The module was compiled for version %d.%d and this exim provides"
237 + "ABI version %d.%d)", vers_maj, vers_min, LOCAL_SCAN_ABI_VERSION_MAJOR,
238 + LOCAL_SCAN_ABI_VERSION_MINOR);
242 +local_scan_fn = dlsym(local_scan_lib, "local_scan");
245 + dlclose(local_scan_lib);
246 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
247 + "local_scan() function - message temporarily rejected");
254 +#endif /* DLOPEN_LOCAL_SCAN */
256 /* End of local_scan.c */
257 diff -urN exim-4.14-0/src/readconf.c exim-4.14-1/src/readconf.c
258 --- exim-4.14-0/src/readconf.c Tue Mar 11 04:20:22 2003
259 +++ exim-4.14-1/src/readconf.c Sun Mar 23 15:34:15 2003
261 { "local_from_prefix", opt_stringptr, &local_from_prefix },
262 { "local_from_suffix", opt_stringptr, &local_from_suffix },
263 { "local_interfaces", opt_stringptr, &local_interfaces },
264 +#ifdef DLOPEN_LOCAL_SCAN
265 + { "local_scan_path", opt_stringptr, &local_scan_path },
267 #ifdef HAVE_LOCAL_SCAN
268 { "local_scan_timeout", opt_time, &local_scan_timeout },