1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) The Exim Maintainers 2020 - 2022 */
6 /* Copyright (c) University of Cambridge 1995 - 2020 */
7 /* See the file NOTICE for conditions of use and distribution. */
8 /* SPDX-License-Identifier: GPL-2.0-or-later */
10 /* This file is the header that is the only Exim header to be included in the
11 source for the local_scan.c() function. It contains definitions that are made
12 available for use in that function, and which are documented. That source
13 should first #define LOCAL_SCAN
15 Not every definition that becomes available to the compiler by the inclusion
16 of this file is part of the local_scan API. The "Adding a local scan function
17 to Exim" chapter in the documentation is definitive.
19 This API is also used for functions called by the ${dlfunc expansion item.
20 Source for those should first #define DLFUNC_IMPL and then include this file.
21 Coders of dlfunc routines should read the notes on tainting at the start of
26 /* Some basic types that make some things easier, the Exim configuration
27 settings, and the store functions. */
30 #include <sys/types.h>
36 /* Some people (Marc Merlin et al) are maintaining a patch that allows for
37 dynamic local_scan() libraries. This code is not yet in Exim proper, but it
38 helps the maintainers if we keep their ABI version numbers here. This may
39 mutate into more general support later. The major number is increased when the
40 ABI is changed in a non backward compatible way. The minor number is increased
41 each time a new feature is added (in a way that doesn't break backward
44 #define LOCAL_SCAN_ABI_VERSION_MAJOR 6
45 #define LOCAL_SCAN_ABI_VERSION_MINOR 0
46 #define LOCAL_SCAN_ABI_VERSION \
47 LOCAL_SCAN_ABI_VERSION_MAJOR.LOCAL_SCAN_ABI_VERSION_MINOR
51 /* The function and its return codes. */
53 extern int local_scan(int, uschar **);
56 LOCAL_SCAN_ACCEPT, /* Accept */
57 LOCAL_SCAN_ACCEPT_FREEZE, /* Accept, but freeze */
58 LOCAL_SCAN_ACCEPT_QUEUE, /* Accept, but no immediate delivery */
59 LOCAL_SCAN_REJECT, /* Permanent rejection */
60 LOCAL_SCAN_REJECT_NOLOGHDR, /* Permanent rejection, no log header */
61 LOCAL_SCAN_TEMPREJECT, /* Temporary rejection */
62 LOCAL_SCAN_TEMPREJECT_NOLOGHDR /* Temporary rejection, no log header */
66 /* Functions called by ${dlfunc{file}{func}{arg}...} return one of the five
67 status codes defined immediately below. The function's first argument is either
68 the result of expansion, or the error message in case of failure. The second
69 and third arguments are standard argument count and vector, comprising the
70 {arg} values specified in the expansion item. */
72 typedef int exim_dlfunc_t(uschar **yield, int argc, uschar *argv[]);
75 /* Return codes from the support functions lss_match_xxx(). These are also the
76 codes that dynamically-loaded ${dlfunc functions must return. */
78 #define OK 0 /* Successful match */
79 #define DEFER 1 /* Defer - some problem */
80 #define FAIL 2 /* Matching failed */
81 #define ERROR 3 /* Internal or config error */
83 /* Extra return code for ${dlfunc functions */
85 #define FAIL_FORCED 4 /* "Forced" failure */
88 /* Available logging destinations */
90 #define LOG_MAIN 1 /* Write to the main log */
91 #define LOG_PANIC 2 /* Write to the panic log */
92 #define LOG_REJECT 16 /* Write to the reject log, with headers */
95 /* Accessible debugging bits */
97 #define D_v 0x00000001
98 #define D_local_scan 0x00000002
101 /* Option types that can be used for local_scan_options. The boolean ones
102 MUST be last so that they are contiguous with the internal boolean specials. */
104 enum { opt_stringptr, opt_int, opt_octint, opt_mkint, opt_Kint, opt_fixed,
105 opt_time, opt_bool };
108 /* The length of message identification strings. This is the id used internally
109 by exim. The external version for use in Received: strings has a leading 'E'
110 added to ensure it starts with a letter. */
112 #define MESSAGE_ID_LENGTH 16
114 /* The offset to the start of the data in the data file - this allows for
115 the name of the data file to be present in the first line. */
117 #define SPOOL_DATA_START_OFFSET (MESSAGE_ID_LENGTH+3)
119 /* Structure definitions that are documented as visible in the function. */
121 typedef struct header_line {
122 struct header_line *next;
128 /* Entries in lists options are in this form. */
131 const char * name; /* should have been uschar but too late now */
136 void (* fn)(const uschar *, const uschar *, unsigned);
139 #define OPT_OFF(s, field) {.offset = offsetof(s, field)}
141 /* Structure for holding information about an envelope address. The errors_to
142 field is always NULL except for one_time aliases that had errors_to on the
143 routers that generated them. */
145 typedef struct recipient_item {
146 uschar *address; /* the recipient address */
147 int pno; /* parent number for "one_time" alias, or -1 */
148 uschar *errors_to; /* the errors_to address or NULL */
149 uschar *orcpt; /* DSN orcpt */
150 int dsn_flags; /* DSN flags */
151 #ifdef EXPERIMENTAL_BRIGHTMAIL
157 /* Global variables that are documented as visible in the function. */
159 extern unsigned int debug_selector; /* Debugging bits */
161 extern int body_linecount; /* Line count in body */
162 extern int body_zerocount; /* Binary zero count in body */
163 extern uschar *expand_string_message; /* Error info for failing expansion */
164 extern const uschar *headers_charset; /* Charset for RFC 2047 decoding */
165 extern header_line *header_last; /* Final header */
166 extern header_line *header_list; /* First header */
167 extern BOOL host_checking; /* Set when checking a host */
168 extern uschar *interface_address; /* Interface for incoming call */
169 extern int interface_port; /* Port number for incoming call */
170 extern uschar *message_id; /* Internal id of message being handled */
171 extern uschar *received_protocol; /* Name of incoming protocol */
172 extern int recipients_count; /* Number of recipients */
173 extern recipient_item *recipients_list;/* List of recipient addresses */
174 extern unsigned char *sender_address; /* Sender address */
175 extern uschar *sender_host_address; /* IP address of sender, as chars */
176 extern uschar *sender_host_authenticated; /* Name of authentication mechanism */
177 extern uschar *sender_host_name; /* Host name from lookup */
178 extern int sender_host_port; /* Port number of sender */
179 extern BOOL smtp_batched_input; /* TRUE if SMTP batch (no interaction) */
180 extern BOOL smtp_input; /* TRUE if input is via SMTP */
183 /* Functions that are documented as visible in local_scan(). */
185 extern int child_close(pid_t, int);
186 extern void debug_printf(const char *, ...) PRINTF_FUNCTION(1,2);
187 extern uschar *expand_string(uschar *);
188 extern void header_add(int, const char *, ...);
189 extern void header_add_at_position(BOOL, uschar *, BOOL, int, const char *, ...);
190 extern void header_remove(int, const uschar *);
191 extern BOOL header_testname(const header_line *, const uschar *, int, BOOL);
192 extern BOOL header_testname_incomplete(const header_line *, const uschar *, int, BOOL);
193 extern void log_write(unsigned int, int, const char *format, ...) PRINTF_FUNCTION(3,4);
194 extern int lss_b64decode(uschar *, uschar **);
195 extern uschar *lss_b64encode(uschar *, int);
196 extern int lss_match_domain(uschar *, uschar *);
197 extern int lss_match_local_part(uschar *, uschar *, BOOL);
198 extern int lss_match_address(uschar *, uschar *, BOOL);
199 extern int lss_match_host(uschar *, uschar *, uschar *);
200 extern void receive_add_recipient(uschar *, int);
201 extern BOOL receive_remove_recipient(uschar *);
202 extern uschar *rfc2047_decode(uschar *, BOOL, const uschar *, int, int *,
204 extern int smtp_fflush(void);
205 extern void smtp_printf(const char *, BOOL, ...) PRINTF_FUNCTION(1,3);
206 extern void smtp_vprintf(const char *, BOOL, va_list);
208 #define string_sprintf(fmt, ...) \
209 string_sprintf_trc(fmt, US __FUNCTION__, __LINE__, __VA_ARGS__)
210 extern uschar *string_sprintf_trc(const char *, const uschar *, unsigned, ...) ALMOST_PRINTF(1,4);
212 #define store_get(size, proto_mem) \
213 store_get_3((size), (proto_mem), __FUNCTION__, __LINE__)
214 extern void *store_get_3(int, const void *, const char *, int) ALLOC ALLOC_SIZE(1) WARN_UNUSED_RESULT;
215 #define store_get_perm(size, proto_mem) \
216 store_get_perm_3((size), (proto_mem), __FUNCTION__, __LINE__)
217 extern void *store_get_perm_3(int, const void *, const char *, int) ALLOC ALLOC_SIZE(1) WARN_UNUSED_RESULT;
220 #if defined(LOCAL_SCAN) || defined(DLFUNC_IMPL)
221 /* When compiling a local_scan() file we want to rename a published API, so that
222 we can use an inlined implementation in the compiles of the main Exim files,
223 with the original name. */
225 # define string_copy(s) string_copy_function(s)
226 # define string_copyn(s, n) string_copyn_function((s), (n))
227 # define string_copy_taint(s, t) string_copy_taint_function((s), (t))
228 # define child_open_exim(p) child_open_exim_function((p), US"from local_scan")
229 # define child_open_exim2(p, s, a) child_open_exim2_function((p), (s), (a), US"from local_scan")
230 # define child_open(a,e,u,i,o,l) child_open_function((a),(e),(u),(i),(o),(l),US"from local_scan")
232 extern uschar * string_copy_function(const uschar *);
233 extern uschar * string_copyn_function(const uschar *, int n);
234 extern uschar * string_copy_taint_function(const uschar *, const void * proto_mem);
235 extern pid_t child_open_exim_function(int *, const uschar *);
236 extern pid_t child_open_exim2_function(int *, uschar *, uschar *, const uschar *);
237 extern pid_t child_open_function(uschar **, uschar **, int, int *, int *, BOOL, const uschar *);
240 /* End of local_scan.h */