1 diff -urN exim-4.94.org/src/config.h.defaults exim-4.94/src/config.h.defaults
2 --- exim-4.94.org/src/config.h.defaults 2020-05-30 22:35:38.000000000 +0200
3 +++ exim-4.94/src/config.h.defaults 2020-11-27 08:10:34.967732017 +0100
8 +#define DLOPEN_LOCAL_SCAN
12 #define CONFIGURE_FILE
13 diff -urN exim-4.94.org/src/EDITME exim-4.94/src/EDITME
14 --- exim-4.94.org/src/EDITME 2020-11-27 08:10:27.727507700 +0100
15 +++ exim-4.94/src/EDITME 2020-11-27 08:10:34.967732017 +0100
19 #------------------------------------------------------------------------------
20 +# On systems which support dynamic loading of shared libraries, Exim can
21 +# load a local_scan function specified in its config file instead of having
22 +# to be recompiled with the desired local_scan function. For a full
23 +# description of the API to this function, see the Exim specification.
25 +DLOPEN_LOCAL_SCAN=yes
27 +# If you set DLOPEN_LOCAL_SCAN, then you need to include -rdynamic in the
28 +# linker flags. Without it, the loaded .so won't be able to access any
29 +# functions from exim.
32 +CFLAGS += -fvisibility=hidden
34 +#------------------------------------------------------------------------------
35 # The default distribution of Exim contains only the plain text form of the
36 # documentation. Other forms are available separately. If you want to install
37 # the documentation in "info" format, first fetch the Texinfo documentation
38 diff -urN exim-4.94.org/src/globals.c exim-4.94/src/globals.c
39 --- exim-4.94.org/src/globals.c 2020-11-27 08:10:27.714173954 +0100
40 +++ exim-4.94/src/globals.c 2020-11-27 08:10:34.967732017 +0100
42 const pcre *regex_DSN = NULL;
43 uschar *dsn_advertise_hosts = NULL;
45 +#ifdef DLOPEN_LOCAL_SCAN
46 +uschar *local_scan_path = NULL;
50 BOOL gnutls_compat_mode = FALSE;
51 BOOL gnutls_allow_auto_pkcs11 = FALSE;
52 diff -urN exim-4.94.org/src/globals.h exim-4.94/src/globals.h
53 --- exim-4.94.org/src/globals.h 2020-11-27 08:10:27.714173954 +0100
54 +++ exim-4.94/src/globals.h 2020-11-27 08:10:34.967732017 +0100
56 extern const pcre *regex_DSN; /* For recognizing DSN settings */
57 extern uschar *dsn_advertise_hosts; /* host for which TLS is advertised */
59 +#ifdef DLOPEN_LOCAL_SCAN
60 +extern uschar *local_scan_path; /* Path to local_scan() library */
62 /* Input-reading functions for messages, so we can use special ones for
65 diff -urN exim-4.94.org/src/local_scan.c exim-4.94/src/local_scan.c
66 --- exim-4.94.org/src/local_scan.c 2020-05-30 22:35:38.000000000 +0200
67 +++ exim-4.94/src/local_scan.c 2020-11-27 08:10:34.967732017 +0100
69 /* See the file NOTICE for conditions of use and distribution. */
72 -/******************************************************************************
73 -This file contains a template local_scan() function that just returns ACCEPT.
74 -If you want to implement your own version, you should copy this file to, say
75 -Local/local_scan.c, and edit the copy. To use your version instead of the
76 -default, you must set
79 -LOCAL_SCAN_SOURCE=Local/local_scan.c
81 -in your Local/Makefile. This makes it easy to copy your version for use with
82 -subsequent Exim releases.
84 -For a full description of the API to this function, see the Exim specification.
85 -******************************************************************************/
88 /* This is the only Exim header that you should include. The effect of
89 including any other Exim header is not defined, and may change from release to
90 release. Use only the documented interface! */
92 #include "local_scan.h"
95 -/* This is a "do-nothing" version of a local_scan() function. The arguments
98 - fd The file descriptor of the open -D file, which contains the
99 - body of the message. The file is open for reading and
100 - writing, but modifying it is dangerous and not recommended.
102 - return_text A pointer to an unsigned char* variable which you can set in
103 - order to return a text string. It is initialized to NULL.
105 -The return values of this function are:
108 - The message is to be accepted. The return_text argument is
109 - saved in $local_scan_data.
112 - The message is to be rejected. The returned text is used
113 - in the rejection message.
115 - LOCAL_SCAN_TEMPREJECT
116 - This specifies a temporary rejection. The returned text
117 - is used in the rejection message.
119 +#ifdef DLOPEN_LOCAL_SCAN
122 +static int (*local_scan_fn)(int fd, uschar **return_text) = NULL;
123 +static int load_local_scan_library(void);
127 local_scan(int fd, uschar **return_text)
129 fd = fd; /* Keep picky compilers happy */
130 return_text = return_text;
131 -return LOCAL_SCAN_ACCEPT;
132 +#ifdef DLOPEN_LOCAL_SCAN
133 +/* local_scan_path is defined AND not the empty string */
134 +if (local_scan_path && *local_scan_path)
136 + if (!local_scan_fn)
138 + if (!load_local_scan_library())
140 + char *base_msg , *error_msg , *final_msg ;
141 + int final_length = -1 ;
143 + base_msg=US"Local configuration error - local_scan() library failure\n";
144 + error_msg = dlerror() ;
146 + final_length = strlen(base_msg) + strlen(error_msg) + 1 ;
147 + final_msg = (char*)malloc( final_length*sizeof(char) ) ;
148 + *final_msg = '\0' ;
150 + strcat( final_msg , base_msg ) ;
151 + strcat( final_msg , error_msg ) ;
153 + *return_text = final_msg ;
154 + return LOCAL_SCAN_TEMPREJECT;
157 + return local_scan_fn(fd, return_text);
161 + return LOCAL_SCAN_ACCEPT;
164 +#ifdef DLOPEN_LOCAL_SCAN
166 +static int load_local_scan_library(void)
168 +/* No point in keeping local_scan_lib since we'll never dlclose() anyway */
169 +void *local_scan_lib = NULL;
170 +int (*local_scan_version_fn)(void);
174 +local_scan_lib = dlopen(local_scan_path, RTLD_NOW);
175 +if (!local_scan_lib)
177 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library open failed - "
178 + "message temporarily rejected");
182 +local_scan_version_fn = dlsym(local_scan_lib, "local_scan_version_major");
183 +if (!local_scan_version_fn)
185 + dlclose(local_scan_lib);
186 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
187 + "local_scan_version_major() function - message temporarily rejected");
191 +/* The major number is increased when the ABI is changed in a non
192 + backward compatible way. */
193 +vers_maj = local_scan_version_fn();
195 +local_scan_version_fn = dlsym(local_scan_lib, "local_scan_version_minor");
196 +if (!local_scan_version_fn)
198 + dlclose(local_scan_lib);
199 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
200 + "local_scan_version_minor() function - message temporarily rejected");
204 +/* The minor number is increased each time a new feature is added (in a
205 + way that doesn't break backward compatibility) -- Marc */
206 +vers_min = local_scan_version_fn();
209 +if (vers_maj != LOCAL_SCAN_ABI_VERSION_MAJOR)
211 + dlclose(local_scan_lib);
212 + local_scan_lib = NULL;
213 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() has an incompatible major"
214 + "version number, you need to recompile your module for this version"
215 + "of exim (The module was compiled for version %d.%d and this exim provides"
216 + "ABI version %d.%d)", vers_maj, vers_min, LOCAL_SCAN_ABI_VERSION_MAJOR,
217 + LOCAL_SCAN_ABI_VERSION_MINOR);
220 +else if (vers_min > LOCAL_SCAN_ABI_VERSION_MINOR)
222 + dlclose(local_scan_lib);
223 + local_scan_lib = NULL;
224 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() has an incompatible minor"
225 + "version number, you need to recompile your module for this version"
226 + "of exim (The module was compiled for version %d.%d and this exim provides"
227 + "ABI version %d.%d)", vers_maj, vers_min, LOCAL_SCAN_ABI_VERSION_MAJOR,
228 + LOCAL_SCAN_ABI_VERSION_MINOR);
232 +local_scan_fn = dlsym(local_scan_lib, "local_scan");
235 + dlclose(local_scan_lib);
236 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
237 + "local_scan() function - message temporarily rejected");
243 +#endif /* DLOPEN_LOCAL_SCAN */
246 /* End of local_scan.c */
247 diff -urN exim-4.94.org/src/local_scan.h exim-4.94/src/local_scan.h
248 --- exim-4.94.org/src/local_scan.h 2020-05-30 22:35:38.000000000 +0200
249 +++ exim-4.94/src/local_scan.h 2020-11-27 08:10:34.967732017 +0100
253 #include <sys/types.h>
254 +#pragma GCC visibility push(default)
259 extern BOOL host_checking; /* Set when checking a host */
260 extern uschar *interface_address; /* Interface for incoming call */
261 extern int interface_port; /* Port number for incoming call */
262 +#ifdef DLOPEN_LOCAL_SCAN
263 +extern uschar *local_scan_path;
265 extern uschar *message_id; /* Internal id of message being handled */
266 extern uschar *received_protocol; /* Name of incoming protocol */
267 extern int recipients_count; /* Number of recipients */
269 extern pid_t child_open_function(uschar **, uschar **, int, int *, int *, BOOL, const uschar *);
272 +#pragma GCC visibility pop
274 /* End of local_scan.h */
275 diff -urN exim-4.94.org/src/readconf.c exim-4.94/src/readconf.c
276 --- exim-4.94.org/src/readconf.c 2020-11-27 08:10:27.704173644 +0100
277 +++ exim-4.94/src/readconf.c 2020-11-27 08:10:34.967732017 +0100
279 { "local_from_prefix", opt_stringptr, {&local_from_prefix} },
280 { "local_from_suffix", opt_stringptr, {&local_from_suffix} },
281 { "local_interfaces", opt_stringptr, {&local_interfaces} },
282 +#ifdef DLOPEN_LOCAL_SCAN
283 + { "local_scan_path", opt_stringptr, {&local_scan_path} },
285 #ifdef HAVE_LOCAL_SCAN
286 { "local_scan_timeout", opt_time, {&local_scan_timeout} },
288 diff -urN exim-4.94.org/src/string.c exim-4.94/src/string.c
289 --- exim-4.94.org/src/string.c 2020-11-27 08:10:27.704173644 +0100
290 +++ exim-4.94/src/string.c 2020-11-27 08:10:34.971065453 +0100
293 #if (defined(HAVE_LOCAL_SCAN) || defined(EXPAND_DLFUNC)) \
294 && !defined(MACRO_PREDEF) && !defined(COMPILE_UTILITY)
295 +#pragma GCC visibility push(default)
296 /*************************************************
297 * Copy and save string *
298 *************************************************/
303 +#pragma GCC visibility pop