Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 magnus 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.
3
 
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)
9
 
10
Marc MERLIN <marc_soft@merlins.org>
11
 
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
15
@@ -388,6 +388,20 @@
16
 
17
 
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.
23
+
24
+DLOPEN_LOCAL_SCAN=yes
25
+
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.
29
+
30
+LFLAGS=-rdynamic -ldl
31
+
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
39
@@ -17,6 +17,8 @@
40
 #define AUTH_PLAINTEXT
41
 #define AUTH_SPA
42
 
43
+#define DLOPEN_LOCAL_SCAN
44
+
45
 #define BIN_DIRECTORY
46
 
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
51
@@ -103,6 +103,9 @@
52
 uschar *tls_verify_hosts       = NULL;
53
 #endif
54
 
55
+#ifdef DLOPEN_LOCAL_SCAN
56
+uschar *local_scan_path        = NULL;
57
+#endif
58
 
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
64
@@ -67,6 +67,9 @@
65
 extern uschar *tls_verify_hosts;       /* Mandatory client verification */
66
 #endif
67
 
68
+#ifdef DLOPEN_LOCAL_SCAN
69
+extern uschar *local_scan_path;        /* Path to local_scan() library */
70
+#endif
71
 
72
 /* Input-reading functions for messages, so we can use special ones for
73
 incoming TCP/IP. */
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
77
@@ -5,60 +5,131 @@
78
 /* Copyright (c) University of Cambridge 1995 - 2003 */
79
 /* See the file NOTICE for conditions of use and distribution. */
80
 
81
+#include "exim.h"
82
 
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
88
-
89
-LOCAL_SCAN_SOURCE=Local/local_scan.c
90
-
91
-in your Local/Makefile. This makes it easy to copy your version for use with
92
-subsequent Exim releases.
93
-
94
-For a full description of the API to this function, see the Exim specification.
95
-******************************************************************************/
96
-
97
-
98
-/* This is the only Exim header that you should include. The effect of
99
-including any other Exim header is not defined, and may change from release to
100
-release. Use only the documented interface! */
101
-
102
-#include "local_scan.h"
103
-
104
-
105
-/* This is a "do-nothing" version of a local_scan() function. The arguments
106
-are:
107
-
108
-  fd             The file descriptor of the open -D file, which contains the
109
-                   body of the message. The file is open for reading and
110
-                   writing, but modifying it is dangerous and not recommended.
111
-
112
-  return_text    A pointer to an unsigned char* variable which you can set in
113
-                   order to return a text string. It is initialized to NULL.
114
-
115
-The return values of this function are:
116
-
117
-  LOCAL_SCAN_ACCEPT
118
-                 The message is to be accepted. The return_text argument is
119
-                   saved in $local_scan_data.
120
-
121
-  LOCAL_SCAN_REJECT
122
-                 The message is to be rejected. The returned text is used
123
-                   in the rejection message.
124
-
125
-  LOCAL_SCAN_TEMPREJECT
126
-                 This specifies a temporary rejection. The returned text
127
-                   is used in the rejection message.
128
-*/
129
+#ifdef DLOPEN_LOCAL_SCAN
130
+#include <dlfcn.h>
131
+static int (*local_scan_fn)(int fd, uschar **return_text) = NULL;
132
+static int load_local_scan_library(void);
133
+#endif
134
 
135
 int
136
 local_scan(int fd, uschar **return_text)
137
 {
138
 fd = fd;                      /* Keep picky compilers happy */
139
 return_text = return_text;
140
-return LOCAL_SCAN_ACCEPT;
141
+#ifdef DLOPEN_LOCAL_SCAN
142
+/* local_scan_path is defined AND not the empty string */
143
+if (local_scan_path && *local_scan_path)
144
+  {
145
+  if (!local_scan_fn)
146
+    {
147
+    if (!load_local_scan_library())
148
+      {
149
+        char *base_msg , *error_msg , *final_msg ;
150
+        int final_length = -1 ;
151
+
152
+        base_msg=US"Local configuration error - local_scan() library failure\n";
153
+        error_msg = dlerror() ;
154
+
155
+        final_length = strlen(base_msg) + strlen(error_msg) + 1 ;
156
+        final_msg = (char*)malloc( final_length*sizeof(char) ) ;
157
+        *final_msg = '\0' ;
158
+
159
+        strcat( final_msg , base_msg ) ;
160
+        strcat( final_msg , error_msg ) ;
161
+
162
+        *return_text = final_msg ;
163
+      return LOCAL_SCAN_TEMPREJECT;
164
+      }
165
+    }
166
+    return local_scan_fn(fd, return_text);
167
+  }
168
+else
169
+#endif
170
+  return LOCAL_SCAN_ACCEPT;
171
+}
172
+
173
+#ifdef DLOPEN_LOCAL_SCAN
174
+
175
+static int load_local_scan_library(void)
176
+{
177
+/* No point in keeping local_scan_lib since we'll never dlclose() anyway */
178
+void *local_scan_lib = NULL;
179
+int (*local_scan_version_fn)(void);
180
+int vers_maj;
181
+int vers_min;
182
+
183
+local_scan_lib = dlopen(local_scan_path, RTLD_NOW);
184
+if (!local_scan_lib)
185
+  {
186
+  log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library open failed - "
187
+    "message temporarily rejected");
188
+  return FALSE;
189
+  }
190
+
191
+local_scan_version_fn = dlsym(local_scan_lib, "local_scan_version_major");
192
+if (!local_scan_version_fn)
193
+  {
194
+  dlclose(local_scan_lib);
195
+  log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
196
+    "local_scan_version_major() function - message temporarily rejected");
197
+  return FALSE;
198
+  }
199
+
200
+/* The major number is increased when the ABI is changed in a non
201
+   backward compatible way. */
202
+vers_maj = local_scan_version_fn();
203
+
204
+local_scan_version_fn = dlsym(local_scan_lib, "local_scan_version_minor");
205
+if (!local_scan_version_fn)
206
+  {
207
+  dlclose(local_scan_lib);
208
+  log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
209
+    "local_scan_version_minor() function - message temporarily rejected");
210
+  return FALSE;
211
+  }
212
+
213
+/* The minor number is increased each time a new feature is added (in a
214
+   way that doesn't break backward compatibility) -- Marc */
215
+vers_min = local_scan_version_fn();
216
+
217
+
218
+if (vers_maj != LOCAL_SCAN_ABI_VERSION_MAJOR)
219
+  {
220
+  dlclose(local_scan_lib);
221
+  local_scan_lib = NULL;
222
+  log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() has an incompatible major"
223
+    "version number, you need to recompile your module for this version"
224
+    "of exim (The module was compiled for version %d.%d and this exim provides"
225
+    "ABI version %d.%d)", vers_maj, vers_min, LOCAL_SCAN_ABI_VERSION_MAJOR,
226
+    LOCAL_SCAN_ABI_VERSION_MINOR);
227
+  return FALSE;
228
+  }
229
+else if (vers_min > LOCAL_SCAN_ABI_VERSION_MINOR)
230
+  {
231
+  dlclose(local_scan_lib);
232
+  local_scan_lib = NULL;
233
+  log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() has an incompatible minor"
234
+    "version number, you need to recompile your module for this version"
235
+    "of exim (The module was compiled for version %d.%d and this exim provides"
236
+    "ABI version %d.%d)", vers_maj, vers_min, LOCAL_SCAN_ABI_VERSION_MAJOR,
237
+    LOCAL_SCAN_ABI_VERSION_MINOR);
238
+  return FALSE;
239
+  }
240
+
241
+local_scan_fn = dlsym(local_scan_lib, "local_scan");
242
+if (!local_scan_fn)
243
+  {
244
+  dlclose(local_scan_lib);
245
+  log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
246
+    "local_scan() function - message temporarily rejected");      
247
+  return FALSE;
248
+  }
249
+
250
+return TRUE;
251
 }
252
+
253
+#endif /* DLOPEN_LOCAL_SCAN */
254
 
255
 /* End of local_scan.c */
256
diff -urN exim-4.14-0/src/readconf.c exim-4.14-1/src/readconf.c
257
--- exim-4.14-0/src/readconf.c  Tue Mar 11 04:20:22 2003
258
+++ exim-4.14-1/src/readconf.c  Sun Mar 23 15:34:15 2003
259
@@ -182,6 +182,9 @@
260
   { "local_from_prefix",        opt_stringptr,   &local_from_prefix },
261
   { "local_from_suffix",        opt_stringptr,   &local_from_suffix },
262
   { "local_interfaces",         opt_stringptr,   &local_interfaces },
263
+#ifdef DLOPEN_LOCAL_SCAN
264
+  { "local_scan_path",          opt_stringptr,   &local_scan_path },
265
+#endif
266
   { "local_scan_timeout",       opt_time,        &local_scan_timeout },
267
   { "local_sender_retain",      opt_bool,        &local_sender_retain },
268
   { "localhost_number",         opt_stringptr,   &host_number_string },