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