]>
Commit | Line | Data |
---|---|---|
0473fda3 AM |
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 | |
4 | @@ -33,6 +33,8 @@ | |
5 | ||
6 | #define AUTH_VARS 3 | |
7 | ||
8 | +#define DLOPEN_LOCAL_SCAN | |
9 | + | |
10 | #define BIN_DIRECTORY | |
11 | ||
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 | |
16 | @@ -878,6 +878,21 @@ | |
4d241ba7 AM |
17 | |
18 | ||
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 | |
96e93d3d | 22 | +# to be recompiled with the desired local_scan function. For a full |
4d241ba7 AM |
23 | +# description of the API to this function, see the Exim specification. |
24 | + | |
25 | +DLOPEN_LOCAL_SCAN=yes | |
26 | + | |
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. | |
30 | + | |
96e93d3d AM |
31 | +LDFLAGS += -rdynamic |
32 | +CFLAGS += -fvisibility=hidden | |
4d241ba7 AM |
33 | + |
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 | |
0473fda3 AM |
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 | |
41 | @@ -117,6 +117,10 @@ | |
96e93d3d AM |
42 | const pcre *regex_DSN = NULL; |
43 | uschar *dsn_advertise_hosts = NULL; | |
4d241ba7 AM |
44 | |
45 | +#ifdef DLOPEN_LOCAL_SCAN | |
46 | +uschar *local_scan_path = NULL; | |
47 | +#endif | |
96e93d3d AM |
48 | + |
49 | #ifndef DISABLE_TLS | |
50 | BOOL gnutls_compat_mode = FALSE; | |
51 | BOOL gnutls_allow_auto_pkcs11 = FALSE; | |
0473fda3 AM |
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 | |
55 | @@ -148,6 +148,9 @@ | |
96e93d3d AM |
56 | extern const pcre *regex_DSN; /* For recognizing DSN settings */ |
57 | extern uschar *dsn_advertise_hosts; /* host for which TLS is advertised */ | |
4d241ba7 AM |
58 | |
59 | +#ifdef DLOPEN_LOCAL_SCAN | |
60 | +extern uschar *local_scan_path; /* Path to local_scan() library */ | |
61 | +#endif | |
4d241ba7 AM |
62 | /* Input-reading functions for messages, so we can use special ones for |
63 | incoming TCP/IP. */ | |
96e93d3d | 64 | |
0473fda3 AM |
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 | |
96e93d3d | 68 | @@ -6,22 +6,6 @@ |
4d241ba7 AM |
69 | /* See the file NOTICE for conditions of use and distribution. */ |
70 | ||
4d241ba7 AM |
71 | |
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 | |
77 | - | |
048ec4ef | 78 | -HAVE_LOCAL_SCAN=yes |
4d241ba7 AM |
79 | -LOCAL_SCAN_SOURCE=Local/local_scan.c |
80 | - | |
81 | -in your Local/Makefile. This makes it easy to copy your version for use with | |
82 | -subsequent Exim releases. | |
83 | - | |
84 | -For a full description of the API to this function, see the Exim specification. | |
85 | -******************************************************************************/ | |
86 | - | |
87 | - | |
96e93d3d AM |
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! */ | |
0473fda3 | 91 | @@ -29,37 +13,130 @@ |
96e93d3d AM |
92 | #include "local_scan.h" |
93 | ||
94 | ||
4d241ba7 AM |
95 | -/* This is a "do-nothing" version of a local_scan() function. The arguments |
96 | -are: | |
97 | - | |
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. | |
101 | - | |
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. | |
104 | - | |
105 | -The return values of this function are: | |
106 | - | |
107 | - LOCAL_SCAN_ACCEPT | |
108 | - The message is to be accepted. The return_text argument is | |
109 | - saved in $local_scan_data. | |
110 | - | |
111 | - LOCAL_SCAN_REJECT | |
112 | - The message is to be rejected. The returned text is used | |
113 | - in the rejection message. | |
114 | - | |
115 | - LOCAL_SCAN_TEMPREJECT | |
116 | - This specifies a temporary rejection. The returned text | |
117 | - is used in the rejection message. | |
118 | -*/ | |
119 | +#ifdef DLOPEN_LOCAL_SCAN | |
120 | +#include <dlfcn.h> | |
c3c03586 | 121 | +#include <stdlib.h> |
4d241ba7 AM |
122 | +static int (*local_scan_fn)(int fd, uschar **return_text) = NULL; |
123 | +static int load_local_scan_library(void); | |
124 | +#endif | |
125 | ||
126 | int | |
127 | local_scan(int fd, uschar **return_text) | |
128 | { | |
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) | |
135 | + { | |
136 | + if (!local_scan_fn) | |
137 | + { | |
138 | + if (!load_local_scan_library()) | |
139 | + { | |
140 | + char *base_msg , *error_msg , *final_msg ; | |
141 | + int final_length = -1 ; | |
142 | + | |
143 | + base_msg=US"Local configuration error - local_scan() library failure\n"; | |
144 | + error_msg = dlerror() ; | |
145 | + | |
146 | + final_length = strlen(base_msg) + strlen(error_msg) + 1 ; | |
147 | + final_msg = (char*)malloc( final_length*sizeof(char) ) ; | |
148 | + *final_msg = '\0' ; | |
149 | + | |
150 | + strcat( final_msg , base_msg ) ; | |
151 | + strcat( final_msg , error_msg ) ; | |
152 | + | |
153 | + *return_text = final_msg ; | |
154 | + return LOCAL_SCAN_TEMPREJECT; | |
155 | + } | |
156 | + } | |
157 | + return local_scan_fn(fd, return_text); | |
158 | + } | |
159 | +else | |
160 | +#endif | |
161 | + return LOCAL_SCAN_ACCEPT; | |
96e93d3d AM |
162 | } |
163 | ||
4d241ba7 AM |
164 | +#ifdef DLOPEN_LOCAL_SCAN |
165 | + | |
166 | +static int load_local_scan_library(void) | |
167 | +{ | |
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); | |
171 | +int vers_maj; | |
172 | +int vers_min; | |
173 | + | |
174 | +local_scan_lib = dlopen(local_scan_path, RTLD_NOW); | |
175 | +if (!local_scan_lib) | |
176 | + { | |
177 | + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library open failed - " | |
178 | + "message temporarily rejected"); | |
179 | + return FALSE; | |
180 | + } | |
181 | + | |
182 | +local_scan_version_fn = dlsym(local_scan_lib, "local_scan_version_major"); | |
183 | +if (!local_scan_version_fn) | |
184 | + { | |
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"); | |
188 | + return FALSE; | |
189 | + } | |
190 | + | |
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(); | |
194 | + | |
195 | +local_scan_version_fn = dlsym(local_scan_lib, "local_scan_version_minor"); | |
196 | +if (!local_scan_version_fn) | |
197 | + { | |
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"); | |
201 | + return FALSE; | |
202 | + } | |
203 | + | |
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(); | |
207 | + | |
208 | + | |
209 | +if (vers_maj != LOCAL_SCAN_ABI_VERSION_MAJOR) | |
210 | + { | |
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); | |
218 | + return FALSE; | |
219 | + } | |
220 | +else if (vers_min > LOCAL_SCAN_ABI_VERSION_MINOR) | |
221 | + { | |
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); | |
229 | + return FALSE; | |
230 | + } | |
231 | + | |
232 | +local_scan_fn = dlsym(local_scan_lib, "local_scan"); | |
233 | +if (!local_scan_fn) | |
234 | + { | |
235 | + dlclose(local_scan_lib); | |
236 | + log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain " | |
96e93d3d | 237 | + "local_scan() function - message temporarily rejected"); |
4d241ba7 AM |
238 | + return FALSE; |
239 | + } | |
4d241ba7 | 240 | +return TRUE; |
96e93d3d | 241 | +} |
4d241ba7 AM |
242 | + |
243 | +#endif /* DLOPEN_LOCAL_SCAN */ | |
96e93d3d AM |
244 | + |
245 | + | |
4d241ba7 | 246 | /* End of local_scan.c */ |
0473fda3 AM |
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 | |
250 | @@ -27,6 +27,7 @@ | |
96e93d3d AM |
251 | |
252 | #include <stdarg.h> | |
253 | #include <sys/types.h> | |
254 | +#pragma GCC visibility push(default) | |
255 | #include "config.h" | |
256 | #include "mytypes.h" | |
257 | #include "store.h" | |
0473fda3 | 258 | @@ -166,6 +167,9 @@ |
96e93d3d AM |
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; | |
264 | +#endif | |
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 */ | |
0473fda3 AM |
268 | @@ -235,4 +239,6 @@ |
269 | extern pid_t child_open_function(uschar **, uschar **, int, int *, int *, BOOL, const uschar *); | |
96e93d3d AM |
270 | #endif |
271 | ||
272 | +#pragma GCC visibility pop | |
273 | + | |
274 | /* End of local_scan.h */ | |
0473fda3 AM |
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 | |
278 | @@ -205,6 +205,9 @@ | |
bc62d876 AM |
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} }, | |
4d241ba7 | 282 | +#ifdef DLOPEN_LOCAL_SCAN |
bc62d876 | 283 | + { "local_scan_path", opt_stringptr, {&local_scan_path} }, |
4d241ba7 | 284 | +#endif |
906bd90b | 285 | #ifdef HAVE_LOCAL_SCAN |
bc62d876 | 286 | { "local_scan_timeout", opt_time, {&local_scan_timeout} }, |
906bd90b | 287 | #endif |
0473fda3 AM |
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 | |
291 | @@ -418,6 +418,7 @@ | |
96e93d3d AM |
292 | |
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 | *************************************************/ | |
0473fda3 | 299 | @@ -470,6 +471,7 @@ |
96e93d3d AM |
300 | ss[n] = 0; |
301 | return ss; | |
302 | } | |
303 | +#pragma GCC visibility pop | |
304 | #endif | |
305 | ||
306 |