1 diff -ur exim-4.92.orig/src/config.h.defaults exim-4.92/src/config.h.defaults
2 --- exim-4.92.orig/src/config.h.defaults 2019-01-30 14:59:52.000000000 +0100
3 +++ exim-4.92/src/config.h.defaults 2019-02-16 18:17:24.547216157 +0100
8 +#define DLOPEN_LOCAL_SCAN
12 #define CONFIGURE_FILE
13 Only in exim-4.92/src: config.h.defaults.orig
14 diff -ur exim-4.92.orig/src/EDITME exim-4.92/src/EDITME
15 --- exim-4.92.orig/src/EDITME 2019-01-30 14:59:52.000000000 +0100
16 +++ exim-4.92/src/EDITME 2019-02-16 18:17:24.547216157 +0100
20 #------------------------------------------------------------------------------
21 +# On systems which support dynamic loading of shared libraries, Exim can
22 +# load a local_scan function specified in its config file instead of having
23 +# to be recompiled with the desired local_scan function. For a full
24 +# description of the API to this function, see the Exim specification.
26 +#DLOPEN_LOCAL_SCAN=yes
28 +# If you set DLOPEN_LOCAL_SCAN, then you need to include -rdynamic in the
29 +# linker flags. Without it, the loaded .so won't be able to access any
30 +# functions from exim.
33 +ifeq ($(OSTYPE),Linux)
38 +#------------------------------------------------------------------------------
39 # The default distribution of Exim contains only the plain text form of the
40 # documentation. Other forms are available separately. If you want to install
41 # the documentation in "info" format, first fetch the Texinfo documentation
42 Only in exim-4.92/src: EDITME.orig
43 diff -ur exim-4.92.orig/src/globals.c exim-4.92/src/globals.c
44 --- exim-4.92.orig/src/globals.c 2019-01-30 14:59:52.000000000 +0100
45 +++ exim-4.92/src/globals.c 2019-02-16 18:17:24.549216150 +0100
48 uschar *no_aliases = NULL;
50 +#ifdef DLOPEN_LOCAL_SCAN
51 +uschar *local_scan_path = NULL;
55 /* For comments on these variables, see globals.h. I'm too idle to
56 duplicate them here... */
57 Only in exim-4.92/src: globals.c.orig
58 diff -ur exim-4.92.orig/src/globals.h exim-4.92/src/globals.h
59 --- exim-4.92.orig/src/globals.h 2019-01-30 14:59:52.000000000 +0100
60 +++ exim-4.92/src/globals.h 2019-02-16 18:17:24.549216150 +0100
62 extern int (*receive_ferror)(void);
63 extern BOOL (*receive_smtp_buffered)(void);
65 +#ifdef DLOPEN_LOCAL_SCAN
66 +extern uschar *local_scan_path; /* Path to local_scan() library */
69 /* For clearing, saving, restoring address expansion variables. We have to have
70 the size of this vector set explicitly, because it is referenced from more than
71 Only in exim-4.92/src: globals.h.orig
72 diff -ur exim-4.92.orig/src/local_scan.c exim-4.92/src/local_scan.c
73 --- exim-4.92.orig/src/local_scan.c 2019-01-30 14:59:52.000000000 +0100
74 +++ exim-4.92/src/local_scan.c 2019-02-16 18:29:56.832732592 +0100
76 /* Copyright (c) University of Cambridge 1995 - 2009 */
77 /* See the file NOTICE for conditions of use and distribution. */
79 +#include "local_scan.h"
81 -/******************************************************************************
82 -This file contains a template local_scan() function that just returns ACCEPT.
83 -If you want to implement your own version, you should copy this file to, say
84 -Local/local_scan.c, and edit the copy. To use your version instead of the
85 -default, you must set
88 -LOCAL_SCAN_SOURCE=Local/local_scan.c
90 -in your Local/Makefile. This makes it easy to copy your version for use with
91 -subsequent Exim releases.
93 -For a full description of the API to this function, see the Exim specification.
94 -******************************************************************************/
97 -/* This is the only Exim header that you should include. The effect of
98 -including any other Exim header is not defined, and may change from release to
99 -release. Use only the documented interface! */
101 -#include "local_scan.h"
104 -/* This is a "do-nothing" version of a local_scan() function. The arguments
107 - fd The file descriptor of the open -D file, which contains the
108 - body of the message. The file is open for reading and
109 - writing, but modifying it is dangerous and not recommended.
111 - return_text A pointer to an unsigned char* variable which you can set in
112 - order to return a text string. It is initialized to NULL.
114 -The return values of this function are:
117 - The message is to be accepted. The return_text argument is
118 - saved in $local_scan_data.
121 - The message is to be rejected. The returned text is used
122 - in the rejection message.
124 - LOCAL_SCAN_TEMPREJECT
125 - This specifies a temporary rejection. The returned text
126 - is used in the rejection message.
128 +#ifdef DLOPEN_LOCAL_SCAN
130 +static int (*local_scan_fn)(int fd, uschar **return_text) = NULL;
131 +static int load_local_scan_library(void);
135 local_scan(int fd, uschar **return_text)
137 fd = fd; /* Keep picky compilers happy */
138 return_text = return_text;
139 -return LOCAL_SCAN_ACCEPT;
140 +#ifdef DLOPEN_LOCAL_SCAN
141 +/* local_scan_path is defined AND not the empty string */
142 +if (local_scan_path && *local_scan_path)
144 + if (!local_scan_fn)
146 + if (!load_local_scan_library())
148 + char *base_msg , *error_msg , *final_msg ;
149 + int final_length = -1 ;
151 + base_msg=US"Local configuration error - local_scan() library failure\n";
152 + error_msg = dlerror() ;
154 + final_length = strlen(base_msg) + strlen(error_msg) + 1 ;
155 + final_msg = (char*)malloc( final_length*sizeof(char) ) ;
156 + *final_msg = '\0' ;
158 + strcat( final_msg , base_msg ) ;
159 + strcat( final_msg , error_msg ) ;
161 + *return_text = final_msg ;
162 + return LOCAL_SCAN_TEMPREJECT;
165 + return local_scan_fn(fd, return_text);
169 + return LOCAL_SCAN_ACCEPT;
172 +#ifdef DLOPEN_LOCAL_SCAN
174 +static int load_local_scan_library(void)
176 +/* No point in keeping local_scan_lib since we'll never dlclose() anyway */
177 +void *local_scan_lib = NULL;
178 +int (*local_scan_version_fn)(void);
182 +local_scan_lib = dlopen(local_scan_path, RTLD_NOW);
183 +if (!local_scan_lib)
185 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library open failed - "
186 + "message temporarily rejected");
190 +local_scan_version_fn = dlsym(local_scan_lib, "local_scan_version_major");
191 +if (!local_scan_version_fn)
193 + dlclose(local_scan_lib);
194 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
195 + "local_scan_version_major() function - message temporarily rejected");
199 +/* The major number is increased when the ABI is changed in a non
200 + backward compatible way. */
201 +vers_maj = local_scan_version_fn();
203 +local_scan_version_fn = dlsym(local_scan_lib, "local_scan_version_minor");
204 +if (!local_scan_version_fn)
206 + dlclose(local_scan_lib);
207 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
208 + "local_scan_version_minor() function - message temporarily rejected");
212 +/* The minor number is increased each time a new feature is added (in a
213 + way that doesn't break backward compatibility) -- Marc */
214 +vers_min = local_scan_version_fn();
217 +if (vers_maj != LOCAL_SCAN_ABI_VERSION_MAJOR)
219 + dlclose(local_scan_lib);
220 + local_scan_lib = NULL;
221 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() has an incompatible major"
222 + "version number, you need to recompile your module for this version"
223 + "of exim (The module was compiled for version %d.%d and this exim provides"
224 + "ABI version %d.%d)", vers_maj, vers_min, LOCAL_SCAN_ABI_VERSION_MAJOR,
225 + LOCAL_SCAN_ABI_VERSION_MINOR);
228 +else if (vers_min > LOCAL_SCAN_ABI_VERSION_MINOR)
230 + dlclose(local_scan_lib);
231 + local_scan_lib = NULL;
232 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() has an incompatible minor"
233 + "version number, you need to recompile your module for this version"
234 + "of exim (The module was compiled for version %d.%d and this exim provides"
235 + "ABI version %d.%d)", vers_maj, vers_min, LOCAL_SCAN_ABI_VERSION_MAJOR,
236 + LOCAL_SCAN_ABI_VERSION_MINOR);
240 +local_scan_fn = dlsym(local_scan_lib, "local_scan");
243 + dlclose(local_scan_lib);
244 + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
245 + "local_scan() function - message temporarily rejected");
252 +#endif /* DLOPEN_LOCAL_SCAN */
254 /* End of local_scan.c */
255 diff -ur exim-4.92.orig/src/readconf.c exim-4.92/src/readconf.c
256 --- exim-4.92.orig/src/readconf.c 2019-01-30 14:59:52.000000000 +0100
257 +++ exim-4.92/src/readconf.c 2019-02-16 18:18:46.013947455 +0100
259 { "local_from_prefix", opt_stringptr, &local_from_prefix },
260 { "local_from_suffix", opt_stringptr, &local_from_suffix },
261 { "local_interfaces", opt_stringptr, &local_interfaces },
262 +#ifdef DLOPEN_LOCAL_SCAN
263 + { "local_scan_path", opt_stringptr, &local_scan_path },
265 #ifdef HAVE_LOCAL_SCAN
266 { "local_scan_timeout", opt_time, &local_scan_timeout },