mail-mta/exim-4.93: version bump
[gentoo.git] / mail-mta / exim / files / exim-4.93-localscan_dlopen.patch
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
4 @@ -32,6 +32,8 @@
5  
6  #define AUTH_VARS                     3
7  
8 +#define DLOPEN_LOCAL_SCAN
9 +
10  #define BIN_DIRECTORY
11  
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
17 @@ -824,6 +824,24 @@
18  
19  
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.
25 +
26 +#DLOPEN_LOCAL_SCAN=yes
27 +
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.
31 +
32 +LFLAGS = -rdynamic
33 +ifeq ($(OSTYPE),Linux)
34 +LFLAGS += -ldl
35 +endif
36 +
37 +
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
46 @@ -41,6 +41,10 @@
47  
48  uschar *no_aliases             = NULL;
49  
50 +#ifdef DLOPEN_LOCAL_SCAN
51 +uschar *local_scan_path        = NULL;
52 +#endif
53 +
54  
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
61 @@ -152,6 +152,9 @@
62  extern int (*receive_ferror)(void);
63  extern BOOL (*receive_smtp_buffered)(void);
64  
65 +#ifdef DLOPEN_LOCAL_SCAN
66 +extern uschar *local_scan_path;        /* Path to local_scan() library */
67 +#endif
68  
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
75 @@ -5,61 +5,131 @@
76  /* Copyright (c) University of Cambridge 1995 - 2009 */
77  /* See the file NOTICE for conditions of use and distribution. */
78  
79 +#include "local_scan.h"
80  
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
86 -
87 -HAVE_LOCAL_SCAN=yes
88 -LOCAL_SCAN_SOURCE=Local/local_scan.c
89 -
90 -in your Local/Makefile. This makes it easy to copy your version for use with
91 -subsequent Exim releases.
92 -
93 -For a full description of the API to this function, see the Exim specification.
94 -******************************************************************************/
95 -
96 -
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! */
100 -
101 -#include "local_scan.h"
102 -
103 -
104 -/* This is a "do-nothing" version of a local_scan() function. The arguments
105 -are:
106 -
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.
110 -
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.
113 -
114 -The return values of this function are:
115 -
116 -  LOCAL_SCAN_ACCEPT
117 -                 The message is to be accepted. The return_text argument is
118 -                   saved in $local_scan_data.
119 -
120 -  LOCAL_SCAN_REJECT
121 -                 The message is to be rejected. The returned text is used
122 -                   in the rejection message.
123 -
124 -  LOCAL_SCAN_TEMPREJECT
125 -                 This specifies a temporary rejection. The returned text
126 -                   is used in the rejection message.
127 -*/
128 +#ifdef DLOPEN_LOCAL_SCAN
129 +#include <dlfcn.h>
130 +static int (*local_scan_fn)(int fd, uschar **return_text) = NULL;
131 +static int load_local_scan_library(void);
132 +#endif
133  
134  int
135  local_scan(int fd, uschar **return_text)
136  {
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)
143 +  {
144 +  if (!local_scan_fn)
145 +    {
146 +    if (!load_local_scan_library())
147 +      {
148 +        char *base_msg , *error_msg , *final_msg ;
149 +        int final_length = -1 ;
150 +
151 +        base_msg=US"Local configuration error - local_scan() library failure\n";
152 +        error_msg = dlerror() ;
153 +
154 +        final_length = strlen(base_msg) + strlen(error_msg) + 1 ;
155 +        final_msg = (char*)malloc( final_length*sizeof(char) ) ;
156 +        *final_msg = '\0' ;
157 +
158 +        strcat( final_msg , base_msg ) ;
159 +        strcat( final_msg , error_msg ) ;
160 +
161 +        *return_text = final_msg ;
162 +      return LOCAL_SCAN_TEMPREJECT;
163 +      }
164 +    }
165 +    return local_scan_fn(fd, return_text);
166 +  }
167 +else
168 +#endif
169 +  return LOCAL_SCAN_ACCEPT;
170 +}
171 +
172 +#ifdef DLOPEN_LOCAL_SCAN
173 +
174 +static int load_local_scan_library(void)
175 +{
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);
179 +int vers_maj;
180 +int vers_min;
181 +
182 +local_scan_lib = dlopen(local_scan_path, RTLD_NOW);
183 +if (!local_scan_lib)
184 +  {
185 +  log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library open failed - "
186 +    "message temporarily rejected");
187 +  return FALSE;
188 +  }
189 +
190 +local_scan_version_fn = dlsym(local_scan_lib, "local_scan_version_major");
191 +if (!local_scan_version_fn)
192 +  {
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");
196 +  return FALSE;
197 +  }
198 +
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();
202 +
203 +local_scan_version_fn = dlsym(local_scan_lib, "local_scan_version_minor");
204 +if (!local_scan_version_fn)
205 +  {
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");
209 +  return FALSE;
210 +  }
211 +
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();
215 +
216 +
217 +if (vers_maj != LOCAL_SCAN_ABI_VERSION_MAJOR)
218 +  {
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);
226 +  return FALSE;
227 +  }
228 +else if (vers_min > LOCAL_SCAN_ABI_VERSION_MINOR)
229 +  {
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);
237 +  return FALSE;
238 +  }
239 +
240 +local_scan_fn = dlsym(local_scan_lib, "local_scan");
241 +if (!local_scan_fn)
242 +  {
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");
246 +  return FALSE;
247 +  }
248 +
249 +return TRUE;
250  }
251  
252 +#endif /* DLOPEN_LOCAL_SCAN */
253 +
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
258 @@ -199,6 +199,9 @@
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 },
264 +#endif
265  #ifdef HAVE_LOCAL_SCAN
266    { "local_scan_timeout",       opt_time,        &local_scan_timeout },
267  #endif