1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) University of Cambridge 1995 - 2019 */
6 /* See the file NOTICE for conditions of use and distribution. */
8 /* This file is the header that is the only Exim header to be included in the
9 source for the local_scan.c() function. It contains definitions that are made
10 available for use in that function, and which are documented. That source
11 should first #define LOCAL_SCAN
13 This API is also used for functions called by the ${dlfunc expansion item.
14 Source for those should first #define DLFUNC_IMPL and then include this file.
15 Coders of dlfunc routines should read the notes on tainting at the start of
20 /* Some basic types that make some things easier, the Exim configuration
21 settings, and the store functions. */
24 #include <sys/types.h>
30 /* The function and its return codes. */
32 extern int local_scan(int, uschar **);
35 LOCAL_SCAN_ACCEPT, /* Accept */
36 LOCAL_SCAN_ACCEPT_FREEZE, /* Accept, but freeze */
37 LOCAL_SCAN_ACCEPT_QUEUE, /* Accept, but no immediate delivery */
38 LOCAL_SCAN_REJECT, /* Permanent rejection */
39 LOCAL_SCAN_REJECT_NOLOGHDR, /* Permanent rejection, no log header */
40 LOCAL_SCAN_TEMPREJECT, /* Temporary rejection */
41 LOCAL_SCAN_TEMPREJECT_NOLOGHDR /* Temporary rejection, no log header */
45 /* Functions called by ${dlfunc{file}{func}{arg}...} return one of the five
46 status codes defined immediately below. The function's first argument is either
47 the result of expansion, or the error message in case of failure. The second
48 and third arguments are standard argument count and vector, comprising the
49 {arg} values specified in the expansion item. */
51 typedef int exim_dlfunc_t(uschar **yield, int argc, uschar *argv[]);
54 /* Return codes from the support functions lss_match_xxx(). These are also the
55 codes that dynamically-loaded ${dlfunc functions must return. */
57 #define OK 0 /* Successful match */
58 #define DEFER 1 /* Defer - some problem */
59 #define FAIL 2 /* Matching failed */
60 #define ERROR 3 /* Internal or config error */
62 /* Extra return code for ${dlfunc functions */
64 #define FAIL_FORCED 4 /* "Forced" failure */
67 /* Available logging destinations */
69 #define LOG_MAIN 1 /* Write to the main log */
70 #define LOG_PANIC 2 /* Write to the panic log */
71 #define LOG_REJECT 16 /* Write to the reject log, with headers */
74 /* Accessible debugging bits */
76 #define D_v 0x00000001
77 #define D_local_scan 0x00000002
80 /* Option types that can be used for local_scan_options. The boolean ones
81 MUST be last so that they are contiguous with the internal boolean specials. */
83 enum { opt_stringptr, opt_int, opt_octint, opt_mkint, opt_Kint, opt_fixed,
87 /* The length of message identification strings. This is the id used internally
88 by exim. The external version for use in Received: strings has a leading 'E'
89 added to ensure it starts with a letter. */
91 #define MESSAGE_ID_LENGTH 16
93 /* The offset to the start of the data in the data file - this allows for
94 the name of the data file to be present in the first line. */
96 #define SPOOL_DATA_START_OFFSET (MESSAGE_ID_LENGTH+3)
98 /* Some people (Marc Merlin et al) are maintaining a patch that allows for
99 dynamic local_scan() libraries. This code is not yet in Exim proper, but it
100 helps the maintainers if we keep their ABI version numbers here. This may
101 mutate into more general support later. The major number is increased when the
102 ABI is changed in a non backward compatible way. The minor number is increased
103 each time a new feature is added (in a way that doesn't break backward
106 #define LOCAL_SCAN_ABI_VERSION_MAJOR 3
107 #define LOCAL_SCAN_ABI_VERSION_MINOR 1
108 #define LOCAL_SCAN_ABI_VERSION \
109 LOCAL_SCAN_ABI_VERSION_MAJOR.LOCAL_SCAN_ABI_VERSION_MINOR
111 /* Structure definitions that are documented as visible in the function. */
113 typedef struct header_line {
114 struct header_line *next;
120 /* Entries in lists options are in this form. */
123 const char *name; /* should have been uschar but too late now */
128 /* Structure for holding information about an envelope address. The errors_to
129 field is always NULL except for one_time aliases that had errors_to on the
130 routers that generated them. */
132 typedef struct recipient_item {
133 uschar *address; /* the recipient address */
134 int pno; /* parent number for "one_time" alias, or -1 */
135 uschar *errors_to; /* the errors_to address or NULL */
136 uschar *orcpt; /* DSN orcpt */
137 int dsn_flags; /* DSN flags */
138 #ifdef EXPERIMENTAL_BRIGHTMAIL
144 /* Global variables that are documented as visible in the function. */
146 extern unsigned int debug_selector; /* Debugging bits */
148 extern int body_linecount; /* Line count in body */
149 extern int body_zerocount; /* Binary zero count in body */
150 extern uschar *expand_string_message; /* Error info for failing expansion */
151 extern uschar *headers_charset; /* Charset for RFC 2047 decoding */
152 extern header_line *header_last; /* Final header */
153 extern header_line *header_list; /* First header */
154 extern BOOL host_checking; /* Set when checking a host */
155 extern uschar *interface_address; /* Interface for incoming call */
156 extern int interface_port; /* Port number for incoming call */
157 extern uschar *message_id; /* Internal id of message being handled */
158 extern uschar *received_protocol; /* Name of incoming protocol */
159 extern int recipients_count; /* Number of recipients */
160 extern recipient_item *recipients_list;/* List of recipient addresses */
161 extern unsigned char *sender_address; /* Sender address */
162 extern uschar *sender_host_address; /* IP address of sender, as chars */
163 extern uschar *sender_host_authenticated; /* Name of authentication mechanism */
164 extern uschar *sender_host_name; /* Host name from lookup */
165 extern int sender_host_port; /* Port number of sender */
166 extern BOOL smtp_batched_input; /* TRUE if SMTP batch (no interaction) */
167 extern BOOL smtp_input; /* TRUE if input is via SMTP */
170 /* Functions that are documented as visible in local_scan(). */
172 extern int child_close(pid_t, int);
173 extern pid_t child_open(uschar **, uschar **, int, int *, int *, BOOL);
174 extern pid_t child_open_exim(int *);
175 extern pid_t child_open_exim2(int *, uschar *, uschar *);
176 extern void debug_printf(const char *, ...) PRINTF_FUNCTION(1,2);
177 extern uschar *expand_string(uschar *);
178 extern void header_add(int, const char *, ...);
179 extern void header_add_at_position(BOOL, uschar *, BOOL, int, const char *, ...);
180 extern void header_remove(int, const uschar *);
181 extern BOOL header_testname(header_line *, const uschar *, int, BOOL);
182 extern BOOL header_testname_incomplete(header_line *, const uschar *, int, BOOL);
183 extern void log_write(unsigned int, int, const char *format, ...) PRINTF_FUNCTION(3,4);
184 extern int lss_b64decode(uschar *, uschar **);
185 extern uschar *lss_b64encode(uschar *, int);
186 extern int lss_match_domain(uschar *, uschar *);
187 extern int lss_match_local_part(uschar *, uschar *, BOOL);
188 extern int lss_match_address(uschar *, uschar *, BOOL);
189 extern int lss_match_host(uschar *, uschar *, uschar *);
190 extern void receive_add_recipient(uschar *, int);
191 extern BOOL receive_remove_recipient(uschar *);
192 extern uschar *rfc2047_decode(uschar *, BOOL, uschar *, int, int *, uschar **);
193 extern int smtp_fflush(void);
194 extern void smtp_printf(const char *, BOOL, ...) PRINTF_FUNCTION(1,3);
195 extern void smtp_vprintf(const char *, BOOL, va_list);
197 #define string_sprintf(fmt, ...) \
198 string_sprintf_trc(fmt, US __FUNCTION__, __LINE__, __VA_ARGS__)
199 extern uschar *string_sprintf_trc(const char *, const uschar *, unsigned, ...) ALMOST_PRINTF(1,4);
201 #define store_get(size, tainted) \
202 store_get_3(size, tainted, __FUNCTION__, __LINE__)
203 extern void *store_get_3(int, BOOL, const char *, int) ALLOC ALLOC_SIZE(1) WARN_UNUSED_RESULT;
204 #define store_get_perm(size, tainted) \
205 store_get_perm_3(size, tainted, __FUNCTION__, __LINE__)
206 extern void *store_get_perm_3(int, BOOL, const char *, int) ALLOC ALLOC_SIZE(1) WARN_UNUSED_RESULT;
209 #if defined(LOCAL_SCAN) || defined(DLFUNC_IMPL)
210 /* When compiling a local_scan() file we want to rename a published API, so that
211 we can use an inlined implementation in the compiles of the main Exim files,
212 with the original name. */
214 # define string_copy(s) string_copy_function(s)
215 # define string_copyn(s, n) string_copyn_function((s), (n))
216 # define string_copy_taint(s, t) string_copy_taint_function((s), (t))
218 extern uschar * string_copy_function(const uschar *);
219 extern uschar * string_copyn_function(const uschar *, int n);
220 extern uschar * string_copy_taint_function(const uschar *, BOOL tainted);
223 /* End of local_scan.h */